b311480e |
1 | // Created on: 1992-11-18 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1992-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | // Modified by skv - Thu Jul 13 18:00:34 2006 OCC12627 |
18 | // The method Perform is totally rewroted. |
19 | |
20 | #include <IntRes2d_IntersectionSegment.hxx> |
21 | #include <IntRes2d_IntersectionPoint.hxx> |
22 | |
23 | //======================================================================= |
24 | //function : TopClass_FaceClassifier |
25 | //purpose : |
26 | //======================================================================= |
27 | |
28 | TopClass_FaceClassifier::TopClass_FaceClassifier() |
29 | { |
30 | } |
31 | |
32 | //======================================================================= |
33 | //function : TopClass_FaceClassifier |
34 | //purpose : |
35 | //======================================================================= |
36 | |
37 | TopClass_FaceClassifier::TopClass_FaceClassifier(TheFaceExplorer& FExp, |
38 | const gp_Pnt2d& P, |
39 | const Standard_Real Tol) |
40 | { |
41 | Perform(FExp,P,Tol); |
42 | } |
43 | |
44 | //======================================================================= |
45 | //function : Perform |
46 | //purpose : |
47 | //======================================================================= |
48 | |
49 | void TopClass_FaceClassifier::Perform(TheFaceExplorer& Fexp, |
50 | const gp_Pnt2d& P, |
51 | const Standard_Real Tol) |
52 | { |
53 | // Test for rejection. |
54 | rejected = Fexp.Reject(P); |
55 | |
56 | if (rejected) |
57 | return; |
58 | |
59 | gp_Lin2d aLine; |
60 | Standard_Real aParam; |
61 | Standard_Boolean IsValidSegment = Fexp.Segment(P, aLine, aParam); |
62 | TheEdge anEdge; |
63 | TopAbs_Orientation anEdgeOri; |
64 | Standard_Integer aClosestInd; |
65 | IntRes2d_IntersectionPoint aPInter; |
1d47d8d0 |
66 | TopAbs_State aState = TopAbs_UNKNOWN; |
7fd59977 |
67 | Standard_Boolean IsWReject; |
68 | Standard_Boolean IsEReject; |
69 | |
70 | nowires = Standard_True; |
71 | |
72 | while (IsValidSegment) { |
73 | myClassifier.Reset(aLine, aParam, Tol); |
74 | |
75 | for (Fexp.InitWires(); Fexp.MoreWires(); Fexp.NextWire()) { |
76 | nowires = Standard_False; |
77 | IsWReject = Fexp.RejectWire(aLine, myClassifier.Parameter()); |
78 | |
79 | if (!IsWReject) { |
80 | // test this wire |
81 | for (Fexp.InitEdges(); Fexp.MoreEdges(); Fexp.NextEdge()) { |
82 | IsEReject = Fexp.RejectEdge(aLine, myClassifier.Parameter()); |
83 | |
84 | if (!IsEReject) { |
85 | // test this edge |
86 | Fexp.CurrentEdge(anEdge, anEdgeOri); |
87 | |
88 | if (anEdgeOri == TopAbs_FORWARD || anEdgeOri == TopAbs_REVERSED) { |
89 | myClassifier.Compare(anEdge, anEdgeOri); |
90 | aClosestInd = myClassifier.ClosestIntersection(); |
91 | |
92 | if (aClosestInd != 0) { |
93 | // save the closest edge |
94 | TheIntersection2d &anIntersector = myClassifier.Intersector(); |
95 | Standard_Integer aNbPnts = anIntersector.NbPoints(); |
96 | |
97 | myEdge = anEdge; |
98 | |
99 | if (aClosestInd <= aNbPnts) { |
100 | aPInter = anIntersector.Point(aClosestInd); |
101 | } else { |
102 | aClosestInd -= aNbPnts; |
103 | |
104 | if (aClosestInd&1) { |
105 | aPInter = anIntersector. |
106 | Segment((aClosestInd + 1)/2).FirstPoint(); |
107 | } else { |
108 | aPInter = anIntersector. |
109 | Segment((aClosestInd + 1)/2).LastPoint(); |
110 | } |
111 | } |
112 | |
113 | myPosition = aPInter. |
114 | TransitionOfSecond().PositionOnCurve(); |
115 | myEdgeParameter = aPInter.ParamOnSecond(); |
116 | } |
117 | // if we are ON, we stop |
118 | aState = myClassifier.State(); |
119 | |
120 | if (aState == TopAbs_ON) |
121 | return; |
122 | } |
123 | } |
124 | } |
125 | |
126 | // if we are out of the wire we stop |
127 | aState = myClassifier.State(); |
128 | |
129 | if (aState == TopAbs_OUT) |
130 | return; |
131 | } |
132 | } |
133 | |
cf836671 |
134 | if (!myClassifier.IsHeadOrEnd() && aState != TopAbs_UNKNOWN) |
7fd59977 |
135 | break; |
136 | |
137 | // Bad case for classification. Trying to get another segment. |
138 | IsValidSegment = Fexp.OtherSegment(P, aLine, aParam); |
139 | } |
140 | } |
141 | |
142 | //======================================================================= |
143 | //function : State |
144 | //purpose : |
145 | //======================================================================= |
146 | |
147 | TopAbs_State TopClass_FaceClassifier::State() const |
148 | { |
149 | if (rejected) return TopAbs_OUT; |
150 | else if (nowires) return TopAbs_IN; |
151 | else return myClassifier.State(); |
152 | } |
153 | |
154 | //======================================================================= |
155 | //function : Edge |
156 | //purpose : |
157 | //======================================================================= |
158 | |
159 | const TheEdge& TopClass_FaceClassifier::Edge() const |
160 | { |
161 | Standard_DomainError_Raise_if(rejected, |
162 | "TopClass_FaceClassifier::Edge:rejected"); |
163 | return myEdge; |
164 | } |
165 | |
166 | |
167 | //======================================================================= |
168 | //function : EdgeParameter |
169 | //purpose : |
170 | //======================================================================= |
171 | |
172 | Standard_Real TopClass_FaceClassifier::EdgeParameter() const |
173 | { |
174 | Standard_DomainError_Raise_if(rejected, |
175 | "TopClass_FaceClassifier::EdgeParameter:rejected"); |
176 | return myEdgeParameter; |
177 | } |
178 | |