summaryrefslogtreecommitdiff
path: root/src/BOP/BOP_SolidClassifier.cxx
blob: 6c255c89ac8cd8e8e8195284da4d8bfab8682dea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// File:	BOP_SolidClassifier.cxx
// NIZNHY-PKV Thu Apr 11 10:42:14 2002

#include <BOP_SolidClassifier.ixx>

#include <BRepClass3d_SolidClassifier.hxx>

//=======================================================================
//function : 
//purpose  : 
//=======================================================================
  BOP_SolidClassifier::BOP_SolidClassifier()
{
  Clear();
}

//=======================================================================
//function : Clear
//purpose  : 
//=======================================================================
  void BOP_SolidClassifier::Clear() 
{
  myPClassifier = NULL;
  myClassifierMap.Clear();
  myState = TopAbs_UNKNOWN;
  myShell.Nullify();
  mySolid.Nullify();
}

//=======================================================================
//function : LoadSolid
//purpose  : 
//=======================================================================
  void BOP_SolidClassifier::LoadSolid(const TopoDS_Solid& SOL) 
{
  Standard_Boolean found;

  found = myClassifierMap.Contains(SOL);
  if ( !found ) {
    myPClassifier = new BRepClass3d_SolidClassifier(SOL);
    myClassifierMap.Add(SOL, myPClassifier);
  }
  else {
    myPClassifier = myClassifierMap.ChangeFromKey(SOL);
  }
}

//=======================================================================
//function : Classify
//purpose  : 
//=======================================================================
  TopAbs_State BOP_SolidClassifier::Classify (const TopoDS_Solid& SOL, 
					      const gp_Pnt& P, 
					      const Standard_Real Tol)
{
  myPClassifier = NULL;
  myState = TopAbs_UNKNOWN;

  LoadSolid(SOL);

  if (myPClassifier == NULL) {
    return myState;
  }  

  myPClassifier->Perform(P,Tol);
  myState = myPClassifier->State();
  const TopoDS_Shape& fres = myPClassifier->Face();
  if (fres.IsNull()) {
    // NYI : in case of removal of EXTERNAL and INTERNAL faces by the
    // classifier BRepClass3d_SolidClassifier, process these faces
    // to generate state ON/Solid when the point is IN/face INTERNAL or EXTERNAL 
    return myState;
  }
  
  TopAbs_Orientation ofres;
  
  ofres = fres.Orientation();

  if      ( ofres == TopAbs_EXTERNAL ) {
    if      ( myState == TopAbs_IN ) {
      myState = TopAbs_OUT;
    }    
    else if ( myState == TopAbs_OUT ){
      myState = TopAbs_OUT;
    }    
    else if ( myState == TopAbs_ON ){
      myState = TopAbs_ON;
    }    
    else if ( myState == TopAbs_UNKNOWN ){
      myState = TopAbs_OUT;
    }
  }

  else if ( ofres == TopAbs_INTERNAL ) {
    if      ( myState == TopAbs_IN ) {
      myState = TopAbs_IN;
    }
    else if ( myState == TopAbs_OUT) {
      myState = TopAbs_IN;
    }
    else if ( myState == TopAbs_ON ) {
      myState = TopAbs_ON;
    }    
    else if ( myState == TopAbs_UNKNOWN ) {
      myState = TopAbs_IN;
    }
  }
  return myState;
}


//=======================================================================
//function : LoadShell
//purpose  : 
//=======================================================================
  void BOP_SolidClassifier::LoadShell(const TopoDS_Shell& SHE) 
{
  Standard_Boolean found;

  found = myClassifierMap.Contains (SHE);
  
  if ( !found ) {
    myBuilder.MakeSolid(mySolid);
    myBuilder.Add(mySolid,SHE);
    TopoDS_Shell* pshe = (TopoDS_Shell*)&SHE; 
    (*pshe).Free(Standard_True);  
    
    myPClassifier = new BRepClass3d_SolidClassifier(mySolid);
    myClassifierMap.Add(SHE, myPClassifier);
  }
  else {
    myPClassifier = myClassifierMap.ChangeFromKey(SHE);
  }
}

//=======================================================================
//function : Classify
//purpose  : 
//=======================================================================
  TopAbs_State BOP_SolidClassifier::Classify (const TopoDS_Shell& SHE, 
					      const gp_Pnt& P,
					      const Standard_Real Tol)
{
  myPClassifier = NULL;
  myState = TopAbs_UNKNOWN;

  LoadShell(SHE);
  //
  if (myPClassifier == NULL) {
    return myState;
  }
  
  myPClassifier->Perform(P,Tol);
  myState = myPClassifier->State();
  return myState;
}

//=======================================================================
//function : State
//purpose  : 
//=======================================================================
  TopAbs_State BOP_SolidClassifier::State() const
{
  return myState;
}

//=======================================================================
//function : Destroy
//purpose  : 
//=======================================================================
  void BOP_SolidClassifier::Destroy()
{
  Standard_Integer i, aNb;
  
  aNb=myClassifierMap.Extent();
  for (i=1; i<=aNb; ++i) {
    BRepClass3d_SolidClassifier* pC=myClassifierMap(i);
    delete pC;
  }
  myClassifierMap.Clear();
}