7fd59977 |
1 | // File: TopClass_FaceClassifier.gxx |
2 | // Created: Wed Nov 18 12:21:14 1992 |
3 | // Author: Remi LEQUETTE |
4 | // <rle@phylox> |
5 | |
6 | // Modified by skv - Thu Jul 13 18:00:34 2006 OCC12627 |
7 | // The method Perform is totally rewroted. |
8 | |
9 | #include <IntRes2d_IntersectionSegment.hxx> |
10 | #include <IntRes2d_IntersectionPoint.hxx> |
11 | |
12 | //======================================================================= |
13 | //function : TopClass_FaceClassifier |
14 | //purpose : |
15 | //======================================================================= |
16 | |
17 | TopClass_FaceClassifier::TopClass_FaceClassifier() |
18 | { |
19 | } |
20 | |
21 | //======================================================================= |
22 | //function : TopClass_FaceClassifier |
23 | //purpose : |
24 | //======================================================================= |
25 | |
26 | TopClass_FaceClassifier::TopClass_FaceClassifier(TheFaceExplorer& FExp, |
27 | const gp_Pnt2d& P, |
28 | const Standard_Real Tol) |
29 | { |
30 | Perform(FExp,P,Tol); |
31 | } |
32 | |
33 | //======================================================================= |
34 | //function : Perform |
35 | //purpose : |
36 | //======================================================================= |
37 | |
38 | void TopClass_FaceClassifier::Perform(TheFaceExplorer& Fexp, |
39 | const gp_Pnt2d& P, |
40 | const Standard_Real Tol) |
41 | { |
42 | // Test for rejection. |
43 | rejected = Fexp.Reject(P); |
44 | |
45 | if (rejected) |
46 | return; |
47 | |
48 | gp_Lin2d aLine; |
49 | Standard_Real aParam; |
50 | Standard_Boolean IsValidSegment = Fexp.Segment(P, aLine, aParam); |
51 | TheEdge anEdge; |
52 | TopAbs_Orientation anEdgeOri; |
53 | Standard_Integer aClosestInd; |
54 | IntRes2d_IntersectionPoint aPInter; |
55 | TopAbs_State aState; |
56 | Standard_Boolean IsWReject; |
57 | Standard_Boolean IsEReject; |
58 | |
59 | nowires = Standard_True; |
60 | |
61 | while (IsValidSegment) { |
62 | myClassifier.Reset(aLine, aParam, Tol); |
63 | |
64 | for (Fexp.InitWires(); Fexp.MoreWires(); Fexp.NextWire()) { |
65 | nowires = Standard_False; |
66 | IsWReject = Fexp.RejectWire(aLine, myClassifier.Parameter()); |
67 | |
68 | if (!IsWReject) { |
69 | // test this wire |
70 | for (Fexp.InitEdges(); Fexp.MoreEdges(); Fexp.NextEdge()) { |
71 | IsEReject = Fexp.RejectEdge(aLine, myClassifier.Parameter()); |
72 | |
73 | if (!IsEReject) { |
74 | // test this edge |
75 | Fexp.CurrentEdge(anEdge, anEdgeOri); |
76 | |
77 | if (anEdgeOri == TopAbs_FORWARD || anEdgeOri == TopAbs_REVERSED) { |
78 | myClassifier.Compare(anEdge, anEdgeOri); |
79 | aClosestInd = myClassifier.ClosestIntersection(); |
80 | |
81 | if (aClosestInd != 0) { |
82 | // save the closest edge |
83 | TheIntersection2d &anIntersector = myClassifier.Intersector(); |
84 | Standard_Integer aNbPnts = anIntersector.NbPoints(); |
85 | |
86 | myEdge = anEdge; |
87 | |
88 | if (aClosestInd <= aNbPnts) { |
89 | aPInter = anIntersector.Point(aClosestInd); |
90 | } else { |
91 | aClosestInd -= aNbPnts; |
92 | |
93 | if (aClosestInd&1) { |
94 | aPInter = anIntersector. |
95 | Segment((aClosestInd + 1)/2).FirstPoint(); |
96 | } else { |
97 | aPInter = anIntersector. |
98 | Segment((aClosestInd + 1)/2).LastPoint(); |
99 | } |
100 | } |
101 | |
102 | myPosition = aPInter. |
103 | TransitionOfSecond().PositionOnCurve(); |
104 | myEdgeParameter = aPInter.ParamOnSecond(); |
105 | } |
106 | // if we are ON, we stop |
107 | aState = myClassifier.State(); |
108 | |
109 | if (aState == TopAbs_ON) |
110 | return; |
111 | } |
112 | } |
113 | } |
114 | |
115 | // if we are out of the wire we stop |
116 | aState = myClassifier.State(); |
117 | |
118 | if (aState == TopAbs_OUT) |
119 | return; |
120 | } |
121 | } |
122 | |
123 | if (!myClassifier.IsHeadOrEnd()) |
124 | break; |
125 | |
126 | // Bad case for classification. Trying to get another segment. |
127 | IsValidSegment = Fexp.OtherSegment(P, aLine, aParam); |
128 | } |
129 | } |
130 | |
131 | //======================================================================= |
132 | //function : State |
133 | //purpose : |
134 | //======================================================================= |
135 | |
136 | TopAbs_State TopClass_FaceClassifier::State() const |
137 | { |
138 | if (rejected) return TopAbs_OUT; |
139 | else if (nowires) return TopAbs_IN; |
140 | else return myClassifier.State(); |
141 | } |
142 | |
143 | //======================================================================= |
144 | //function : Edge |
145 | //purpose : |
146 | //======================================================================= |
147 | |
148 | const TheEdge& TopClass_FaceClassifier::Edge() const |
149 | { |
150 | Standard_DomainError_Raise_if(rejected, |
151 | "TopClass_FaceClassifier::Edge:rejected"); |
152 | return myEdge; |
153 | } |
154 | |
155 | |
156 | //======================================================================= |
157 | //function : EdgeParameter |
158 | //purpose : |
159 | //======================================================================= |
160 | |
161 | Standard_Real TopClass_FaceClassifier::EdgeParameter() const |
162 | { |
163 | Standard_DomainError_Raise_if(rejected, |
164 | "TopClass_FaceClassifier::EdgeParameter:rejected"); |
165 | return myEdgeParameter; |
166 | } |
167 | |