1 // Created on: 1992-11-19
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by skv - Thu Jul 13 17:42:58 2006 OCC12627
18 // Total rewriting of the method Segment; add the method OtherSegment.
20 #include <BRepClass_FaceExplorer.ixx>
21 #include <Precision.hxx>
22 #include <Geom2d_Curve.hxx>
24 #include <BRep_Tool.hxx>
26 static const Standard_Real Probing_Start = 0.123;
27 static const Standard_Real Probing_End = 0.7;
28 static const Standard_Real Probing_Step = 0.2111;
30 //=======================================================================
31 //function : BRepClass_FaceExplorer
33 //=======================================================================
35 BRepClass_FaceExplorer::BRepClass_FaceExplorer(const TopoDS_Face& F) :
38 myCurEdgePar(Probing_Start)
40 myFace.Orientation(TopAbs_FORWARD);
43 //=======================================================================
46 //=======================================================================
48 Standard_Boolean BRepClass_FaceExplorer::Reject(const gp_Pnt2d&)const
50 return Standard_False;
53 //=======================================================================
56 //=======================================================================
58 Standard_Boolean BRepClass_FaceExplorer::Segment(const gp_Pnt2d& P,
63 myCurEdgePar = Probing_Start;
65 return OtherSegment(P, L, Par);
68 //=======================================================================
69 //function : OtherSegment
71 //=======================================================================
73 Standard_Boolean BRepClass_FaceExplorer::OtherSegment(const gp_Pnt2d& P,
77 TopExp_Explorer anExpF(myFace,TopAbs_EDGE);
81 Handle(Geom2d_Curve) aC2d;
82 Standard_Real aTolParConf2 = Precision::PConfusion() * Precision::PConfusion();
84 Standard_Real aParamIn;
86 for (i = 1; anExpF.More(); anExpF.Next(), i++) {
87 if (i != myCurEdgeInd)
90 const TopoDS_Shape &aLocalShape = anExpF.Current();
91 const TopAbs_Orientation anOrientation = aLocalShape.Orientation();
93 if (anOrientation == TopAbs_FORWARD || anOrientation == TopAbs_REVERSED) {
94 const TopoDS_Edge &anEdge = TopoDS::Edge(aLocalShape);
96 aC2d = BRep_Tool::CurveOnSurface(anEdge, myFace, aFPar, aLPar);
99 // Treatment of infinite cases.
100 if (Precision::IsNegativeInfinite(aFPar)) {
101 if (Precision::IsPositiveInfinite(aLPar)) {
107 } else if (Precision::IsPositiveInfinite(aLPar))
110 for (; myCurEdgePar < Probing_End ;myCurEdgePar += Probing_Step) {
111 aParamIn = myCurEdgePar*aFPar + (1. - myCurEdgePar)*aLPar;
114 aC2d->D1(aParamIn, aPOnC, aTanVec);
115 Par = aPOnC.SquareDistance(P);
117 if (Par > aTolParConf2) {
118 gp_Vec2d aLinVec(P, aPOnC);
119 gp_Dir2d aLinDir(aLinVec);
121 Standard_Real aTanMod = aTanVec.SquareMagnitude();
122 if (aTanMod < aTolParConf2)
124 aTanVec /= Sqrt(aTanMod);
125 Standard_Real aSinA = aTanVec.Crossed(aLinDir.XY());
126 const Standard_Real SmallAngle = 0.001;
127 if (Abs(aSinA) < SmallAngle)
129 // The line from the input point P to the current point on edge
130 // is tangent to the edge curve. This condition is bad for classification.
131 // Therefore try to go to another point in the hope that there will be
132 // no tangent. If there tangent is preserved then leave the last point in
133 // order to get this edge chanse to participate in classification.
134 if (myCurEdgePar + Probing_Step < Probing_End)
138 L = gp_Lin2d(P, aLinDir);
140 // Check if ends of a curve lie on a line.
141 aC2d->D0(aFPar, aPOnC);
143 if (L.SquareDistance(aPOnC) > aTolParConf2) {
144 aC2d->D0(aLPar, aPOnC);
146 if (L.SquareDistance(aPOnC) > aTolParConf2) {
147 myCurEdgePar += Probing_Step;
149 if (myCurEdgePar >= Probing_End) {
151 myCurEdgePar = Probing_Start;
155 return Standard_True;
160 } // if (!aC2d.IsNull()) {
161 } // if (anOrientation == TopAbs_FORWARD ...
163 // This curve is not valid for line construction. Go to another edge.
165 myCurEdgePar = Probing_Start;
168 // nothing found, return an horizontal line
170 L = gp_Lin2d(P,gp_Dir2d(1,0));
172 return Standard_False;
175 //=======================================================================
176 //function : InitWires
178 //=======================================================================
180 void BRepClass_FaceExplorer::InitWires()
182 myWExplorer.Init(myFace,TopAbs_WIRE);
185 //=======================================================================
186 //function : RejectWire NYI
188 //=======================================================================
190 Standard_Boolean BRepClass_FaceExplorer::RejectWire
192 const Standard_Real)const
194 return Standard_False;
197 //=======================================================================
198 //function : InitEdges
200 //=======================================================================
202 void BRepClass_FaceExplorer::InitEdges()
204 myEExplorer.Init(myWExplorer.Current(),TopAbs_EDGE);
207 //=======================================================================
208 //function : RejectEdge NYI
210 //=======================================================================
212 Standard_Boolean BRepClass_FaceExplorer::RejectEdge
214 const Standard_Real )const
216 return Standard_False;
220 //=======================================================================
221 //function : CurrentEdge
223 //=======================================================================
225 void BRepClass_FaceExplorer::CurrentEdge(BRepClass_Edge& E,
226 TopAbs_Orientation& Or) const
228 E.Edge() = TopoDS::Edge(myEExplorer.Current());
230 Or = E.Edge().Orientation();