0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / TopOpeBRep / TopOpeBRep_VPointInterClassifier.cxx
CommitLineData
7fd59977 1// File: TopOpeBRep_VPointInterClassifier.cxx
2// Created: Thu Nov 18 10:35:11 1993
3// Author: Jean Yves LEBEY
4// <jyl@phobox>
5
6#include <TopOpeBRep_VPointInterClassifier.ixx>
7
8#include <gp_Pnt2d.hxx>
9#include <Precision.hxx>
10#include <TopoDS.hxx>
11#include <TopOpeBRepTool_ShapeTool.hxx>
12#include <Standard_ProgramError.hxx>
13#include <BRepAdaptor_Surface.hxx>
14//modified by NIZHNY-MKK Fri Jun 16 15:04:09 2000.BEGIN
15#include <Geom_Curve.hxx>
16#include <Geom2d_Curve.hxx>
17#include <BRep_Tool.hxx>
18#include <GeomAPI_ProjectPointOnCurve.hxx>
19#include <TopoDS_Vertex.hxx>
20//modified by NIZHNY-MKK Fri Jun 16 15:04:09 2000.END
21
22
23//modified by NIZHNY-MKK Mon Jun 19 11:47:48 2000.BEGIN
24static TopAbs_State SlowClassifyOnBoundary(const gp_Pnt& thePointToClassify,
25 const gp_Pnt2d& thePoint2dToClassify,
26 BRepClass_FaceClassifier& theSlowClassifier,
27 const TopoDS_Face& theFace);
28//modified by NIZHNY-MKK Mon Jun 19 11:47:51 2000.END
29
30//=======================================================================
31//function : TopOpeBRep_VPointInterClassifier
32//purpose :
33//=======================================================================
34
35TopOpeBRep_VPointInterClassifier::TopOpeBRep_VPointInterClassifier() :
36myState(TopAbs_UNKNOWN)
37{
38}
39
40//=======================================================================
41//function : VPointPosition
42//purpose :
43//=======================================================================
44
45TopAbs_State TopOpeBRep_VPointInterClassifier::VPointPosition
46(const TopoDS_Shape& F,
47 TopOpeBRep_VPointInter& VP,
48 const Standard_Integer FaceClassifyIndex,
49 TopOpeBRep_PointClassifier& PC,
50 const Standard_Boolean AssumeINON,
51 const Standard_Real Tol)
52{
53 myState = TopAbs_UNKNOWN;
54
55 Standard_Real u,v;
56 switch (FaceClassifyIndex) {
57 case 1 : {
58 VP.ParametersOnS1(u,v);
59 if(VP.IsOnDomS1()) {
60 VP.State(TopAbs_ON,1);
61 const TopoDS_Edge& E = TopoDS::Edge(VP.ArcOnS1());
62 const Standard_Real pE = VP.ParameterOnArc1();
63 VP.EdgeON(E,pE,1);
64 myState = TopAbs_ON;
65 return myState;
66 }
67 break;
68 }
69 case 2 : {
70 VP.ParametersOnS2(u,v);
71 if(VP.IsOnDomS2()) {
72 VP.State(TopAbs_ON,2);
73 const TopoDS_Edge& E = TopoDS::Edge(VP.ArcOnS2());
74 const Standard_Real pE = VP.ParameterOnArc2();
75 VP.EdgeON(E,pE,2);
76 myState = TopAbs_ON;
77 return myState;
78 }
79 break;
80 }
81 default : Standard_ProgramError::Raise("VPointClassifier : wrong Index");
82 }
83
84 if (myState == TopAbs_ON) {
85 return myState;
86 }
87
7fd59977 88 TopoDS_Face FF = TopoDS::Face(F);
89 TopOpeBRepTool_ShapeTool::AdjustOnPeriodic(FF,u,v);
90 gp_Pnt2d p2d(u,v);
91 TopAbs_State statefast = PC.Classify(FF,p2d,Tol);
92 myState = statefast;
93 VP.State(myState,FaceClassifyIndex);
94
95 // AssumeINON = True <=> on considere que tout VP rendu par les
96 // intersections est sur une frontiere de la face FF (ON)ou dans la face FF (IN)
97 Standard_Integer VPSI = VP.ShapeIndex();
98 if (AssumeINON && FaceClassifyIndex == VPSI) {
99 mySlowFaceClassifier.Perform(FF,p2d,Tol);
100 myState = mySlowFaceClassifier.State();
101 if (myState == TopAbs_ON) {
102//modified by NIZHNY-MKK Mon Jun 19 11:45:36 2000.BEGIN
103 myState = SlowClassifyOnBoundary(VP.Value(), p2d, mySlowFaceClassifier, FF);
104 if(myState == TopAbs_ON) {
105//modified by NIZHNY-MKK Mon Jun 19 11:45:36 2000.END
106 VP.EdgeON(mySlowFaceClassifier.Edge().Edge(),
107 mySlowFaceClassifier.EdgeParameter(),
108 FaceClassifyIndex);
109 }
110 }
111 else if ( myState == TopAbs_OUT) {
112 myState = TopAbs_IN;
113 // ou biwn myState = TopAbs_OUT ce qui va entrainer VP.UnKeep()
114 // si on privilegie le classifieur / donnees d'intersection.
115 }
116 } // (AssumeINON && FaceClassifyIndex == VPSI)
117
118 else if (!AssumeINON) {
119 if (statefast == TopAbs_OUT || statefast == TopAbs_ON) {
120 mySlowFaceClassifier.Perform(FF,p2d,Tol);
121 myState = mySlowFaceClassifier.State();
122 if (myState == TopAbs_ON) {
123//modified by NIZHNY-MKK Mon Jun 19 11:45:36 2000.BEGIN
124 myState = SlowClassifyOnBoundary(VP.Value(), p2d, mySlowFaceClassifier, FF);
125 if(myState == TopAbs_ON) {
126//modified by NIZHNY-MKK Mon Jun 19 11:45:36 2000.END
127 VP.EdgeON(mySlowFaceClassifier.Edge().Edge(),
128 mySlowFaceClassifier.EdgeParameter(),
129 FaceClassifyIndex);
130 }
131 }
132 }
133 }
134
135 else if (FaceClassifyIndex != VPSI) {
136 // AssumeINON = True
137 //modified by NIZNHY-PKV Mon Feb 5 19:04:01 2001 f
138 if (statefast == TopAbs_ON || statefast == TopAbs_OUT) {
139 //if (statefast == TopAbs_ON) {
140 mySlowFaceClassifier.Perform(FF, p2d, Tol);
141 myState = mySlowFaceClassifier.State();
142
143 if (myState == TopAbs_ON || myState == TopAbs_OUT) {
144 //if (myState == TopAbs_ON) {
145 //modified by NIZNHY-PKV Mon Feb 5 19:04:49 2001 t
146 myState = SlowClassifyOnBoundary(VP.Value(), p2d, mySlowFaceClassifier, FF);
147 if(myState==TopAbs_ON) {
148 VP.EdgeON(mySlowFaceClassifier.Edge().Edge(),
149 mySlowFaceClassifier.EdgeParameter(),
150 FaceClassifyIndex);
151 }
152 }
153 }
154 }
155
156 VP.State(myState,FaceClassifyIndex);
157 return myState;
158}
159
160
161//=======================================================================
162//function : Edge
163//purpose :
164//=======================================================================
165
166const TopoDS_Shape& TopOpeBRep_VPointInterClassifier::Edge() const
167{
168 if (myState == TopAbs_ON) {
169 const TopoDS_Shape& S = mySlowFaceClassifier.Edge().Edge();
170 return S;
171 }
172 else {
173 return myNullShape;
174 }
175}
176
177
178//=======================================================================
179//function : EdgeParameter
180//purpose :
181//=======================================================================
182
183Standard_Real TopOpeBRep_VPointInterClassifier::EdgeParameter() const
184{
185 if (myState == TopAbs_ON) return mySlowFaceClassifier.EdgeParameter();
186 else return 0;
187}
188
189//modified by NIZHNY-MKK Mon Jun 19 11:47:23 2000.BEGIN
190//=======================================================================
191//static function : SlowClassifyOnBoundary
192//purpose :
193//=======================================================================
194static TopAbs_State SlowClassifyOnBoundary(const gp_Pnt& thePointToClassify,
195 const gp_Pnt2d& thePoint2dToClassify,
196 BRepClass_FaceClassifier& theSlowClassifier,
197 const TopoDS_Face& theFace) {
198
199 Standard_Real aParameterOnEdge = theSlowClassifier.EdgeParameter();
200 const TopoDS_Edge& anEdge = theSlowClassifier.Edge().Edge();
201
202 Standard_Real parf, parl;
203 Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(anEdge, parf, parl);
204
205 if(!anEdgeCurve.IsNull()) {
206 Standard_Real minparameterdiff = parl - parf;
207 Standard_Real aDistanceToCompare = 0;
208 Standard_Boolean samewithvertex = Standard_False;
209 TopExp_Explorer anExp(anEdge, TopAbs_VERTEX);
210 for(;anExp.More() && !samewithvertex; anExp.Next()) {
211 TopoDS_Vertex aVertex = TopoDS::Vertex(anExp.Current());
212 Standard_Real aVertexTolerance = BRep_Tool::Tolerance(aVertex);
213 gp_Pnt anEdgeVertexPoint = BRep_Tool::Pnt(aVertex);
214 if(thePointToClassify.IsEqual(anEdgeVertexPoint, aVertexTolerance))
215 samewithvertex = Standard_True;
216 }
217 if(samewithvertex)
218 return TopAbs_ON;
219
220 GeomAPI_ProjectPointOnCurve aProjTool(thePointToClassify, anEdgeCurve);
221
222 for(Standard_Integer i=1; i<=aProjTool.NbPoints(); i++) {
223 Standard_Real curparamdiff = Abs(aProjTool.Parameter(i) - aParameterOnEdge);
224 if(curparamdiff < minparameterdiff) {
225 minparameterdiff = curparamdiff;
226 aDistanceToCompare = aProjTool.Distance(i);
227 }
228 }
229
230 Standard_Real anEdgeTolerance = BRep_Tool::Tolerance(anEdge);
231
232 if((aProjTool.NbPoints()==0) || (aDistanceToCompare >= anEdgeTolerance)) {
233 Handle(Geom2d_Curve) anEdgePCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, parf, parl);
234
235 if(!anEdgePCurve.IsNull()) {
236 gp_Pnt2d aPoint2dOnEdge = anEdgePCurve->Value(aParameterOnEdge);
237 Standard_Real aTol2d = thePoint2dToClassify.Distance(aPoint2dOnEdge) / 3;
238 theSlowClassifier.Perform(theFace, thePoint2dToClassify, aTol2d);
239 if(theSlowClassifier.State() == TopAbs_IN)
240 return TopAbs_IN;
241 else
242 return TopAbs_OUT;
243 }
244 else {
245 return TopAbs_OUT;
246 }
247 }
248 } //end if(!anEdgeCurve.IsNull())
249
250 return TopAbs_ON;
251}
252//modified by NIZHNY-MKK Mon Jun 19 11:47:26 2000.END
253