7fd59977 |
1 | //-- TopClass_SolidClassifier.gxx |
2 | |
3 | #ifdef DEB |
4 | Standard_EXPORT Standard_Boolean TopClass_GettraceFC(); |
5 | #endif |
6 | |
7 | #include <gp_Lin.hxx> |
8 | |
9 | //extern void DrawSegment(const gp_Pnt& P1,const gp_Lin& L,const Standard_Real par); |
10 | //extern Standard_Boolean DebugDrawSegment; |
11 | |
12 | TopClass_SolidClassifier::TopClass_SolidClassifier() |
13 | { |
14 | } |
15 | |
16 | |
17 | TopClass_SolidClassifier::TopClass_SolidClassifier(TheSolidExplorer& S, |
18 | const gp_Pnt& P, |
19 | const Standard_Real Tol) { |
20 | Perform(S,P,Tol); |
21 | } |
22 | |
23 | |
24 | void TopClass_SolidClassifier::Perform(TheSolidExplorer& SolidExplorer, |
25 | const gp_Pnt& P, |
26 | const Standard_Real Tol) { |
27 | #ifdef DEB |
28 | Standard_Boolean trace = TopClass_GettraceFC(); |
29 | #endif |
30 | |
31 | myState = 0; |
32 | if(SolidExplorer.Reject(P) == Standard_False) { |
33 | |
34 | //-- There is no rejection between the Shape loaded in the SolidExplorer |
35 | //-- and the point P. |
36 | |
37 | gp_Lin L; |
38 | Standard_Real Par; |
39 | //-- We compute the intersection betwwen the line builded in the Solid Explorer |
40 | //-- and the shape. |
41 | |
42 | SolidExplorer.Segment(P,L,Par); |
43 | |
44 | TheIntersection3d Intersector; |
45 | |
46 | Standard_Real parmin = RealLast(); |
47 | |
48 | for(SolidExplorer.InitShell(); |
49 | SolidExplorer.MoreShell(); |
50 | SolidExplorer.NextShell()) { |
51 | |
52 | if(SolidExplorer.RejectShell(L) == Standard_False) { |
53 | |
54 | for(SolidExplorer.InitFace(); |
55 | SolidExplorer.MoreFace(); |
56 | SolidExplorer.NextFace()) { |
57 | |
58 | if(SolidExplorer.RejectFace(L) == Standard_False) { |
59 | |
60 | Intersector.Perform(L,Par,Tol,SolidExplorer.CurrentFace()); |
61 | |
62 | if(Intersector.IsDone()) { |
63 | if(Intersector.HasAPoint()) { |
64 | if(Intersector.WParameter() < parmin) { |
65 | |
66 | parmin = Intersector.WParameter(); |
67 | if(Abs(parmin)<=Tol) { |
68 | #ifdef DEB |
69 | if (trace) { |
70 | //-- ######################################### |
71 | cout<<" parmin = "<<parmin<< " avec Par = "<<Par; |
72 | cout<<" ds TopClass_SolidClassifier.gxx "<<endl; |
73 | //-- ######################################### |
74 | } |
75 | #endif |
76 | myState = 2; |
77 | myFace = Intersector.Face(); |
78 | } |
79 | else if(Intersector.State()==TopAbs_IN) { |
80 | |
81 | //-- The intersection point between the line and a face F |
82 | // -- of the solid is in the face F |
83 | |
84 | if(Intersector.Transition() == IntCurveSurface_Out) { |
85 | //-- The line is going from inside the solid to outside |
86 | //-- the solid. |
87 | myState = 3; //-- IN -- |
88 | } |
89 | else if(Intersector.Transition() == IntCurveSurface_In) { |
90 | myState = 4; //-- OUT -- |
91 | } |
92 | else { |
93 | #ifdef DEB |
94 | cout<<"*Probleme ds TopClass_SolidClassifier.gxx"<<endl; |
95 | #endif |
96 | } |
97 | myFace = Intersector.Face(); |
98 | } |
99 | else if(Intersector.State()==TopAbs_ON) { |
100 | //-- The intersection point between the line and a face F |
101 | //-- of the solid is in the face F |
102 | |
103 | if(Intersector.Transition() == IntCurveSurface_Out) { |
104 | //-- The line is going from inside the solid to outside |
105 | //-- the solid. |
106 | myState = 3; //-- IN -- |
107 | } |
108 | else if(Intersector.Transition() == IntCurveSurface_In) { |
109 | myState = 4; //-- OUT -- |
110 | } |
111 | else { |
112 | #ifdef DEB |
113 | cout<<"*Probleme ds TopClass_SolidClassifier.gxx "<<endl; |
114 | #endif |
115 | } |
116 | #ifdef DEB |
117 | //-- ######################################### |
118 | // cout<<" Intersector.State() == TopAbs_ON"; |
119 | // cout<<" ds TopClass_SolidClassifier.gxx "<<endl; |
120 | // cout<<" Transition : "; |
121 | // if(myState==3) { cout<<" IN "; } |
122 | // else if(myState==4) { cout<<" OUT "; } |
123 | // else { cout<<" PB "; } |
124 | // cout<<endl; |
125 | //-- ######################################### |
126 | #endif |
127 | //-- myState = 2; |
128 | myFace = Intersector.Face(); |
129 | } |
130 | } |
131 | else { |
132 | //-- No point has been found by the intersector. |
133 | //-- Or a Point has been found with a greater parameter. |
134 | } |
135 | } //-- Intersector Has a point |
136 | else { |
137 | //-- The intersector failed. |
138 | } |
139 | } //-- Face has not been rejected |
140 | else { |
141 | myState = 1; |
142 | } |
143 | } |
144 | } //-- Exploration of the faces |
145 | } //-- Shell has not been rejected |
146 | else { |
147 | myState=1; |
148 | } |
149 | } //-- Exploration of the shells |
150 | |
151 | #ifdef DEB |
152 | //################################################# |
153 | SolidExplorer.DumpSegment(P,L,parmin,State()); |
154 | //################################################# |
155 | #endif |
156 | |
157 | } //-- Solid has not been rejected |
158 | else { |
159 | myState = 1; |
160 | } |
161 | } |
162 | |
163 | |
164 | TopAbs_State TopClass_SolidClassifier::State() const { |
165 | if(myState==2) return(TopAbs_ON); |
166 | if(myState==4) return(TopAbs_OUT); //-- |
167 | else if(myState==3) return(TopAbs_IN); //-- |
168 | return(TopAbs_OUT); |
169 | } |
170 | |
171 | TopoDS_Face TopClass_SolidClassifier::Face() const { |
172 | return(myFace); |
173 | } |
174 | |
175 | Standard_Boolean TopClass_SolidClassifier::Rejected() const { |
176 | return(myState==1); |
177 | } |
178 | |
179 | |
180 | Standard_Boolean TopClass_SolidClassifier::IsOnAFace() const { |
181 | return(myState==2); |
182 | } |