1 // Created on: 2016-07-07
2 // Copyright (c) 2016 OPEN CASCADE SAS
3 // Created by: Oleg AGASHIN
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <BRepMesh_Classifier.hxx>
18 #include <Precision.hxx>
19 #include <gp_Pnt2d.hxx>
20 #include <CSLib_Class2d.hxx>
21 #include <TColgp_Array1OfPnt2d.hxx>
23 //=======================================================================
24 //function : Constructor
26 //=======================================================================
27 BRepMesh_Classifier::BRepMesh_Classifier()
31 //=======================================================================
32 //function : Destructor
34 //=======================================================================
35 BRepMesh_Classifier::~BRepMesh_Classifier()
39 //=======================================================================
42 //=======================================================================
43 TopAbs_State BRepMesh_Classifier::Perform(const gp_Pnt2d& thePoint) const
45 Standard_Boolean isOut = Standard_False;
46 Standard_Integer aNb = myTabClass.Length();
48 for (Standard_Integer i = 0; i < aNb; i++)
50 const Standard_Integer aCur = myTabClass(i)->SiDans(thePoint);
53 // Point is ON, but mark it as OUT
54 isOut = Standard_True;
58 isOut = myTabOrient(i) ? (aCur == -1) : (aCur == 1);
70 //=======================================================================
71 //function : RegisterWire
73 //=======================================================================
74 void BRepMesh_Classifier::RegisterWire(
75 const NCollection_Sequence<const gp_Pnt2d*>& theWire,
76 const std::pair<Standard_Real, Standard_Real>& theTolUV,
77 const std::pair<Standard_Real, Standard_Real>& theRangeU,
78 const std::pair<Standard_Real, Standard_Real>& theRangeV)
80 const Standard_Integer aNbPnts = theWire.Length();
87 TColgp_Array1OfPnt2d aPClass(1, aNbPnts);
88 Standard_Real anAngle = 0.0;
89 const gp_Pnt2d *p1 = theWire(1), *p2 = theWire(2), *p3;
93 const Standard_Real aAngTol = Precision::Angular();
94 const Standard_Real aSqConfusion =
95 Precision::PConfusion() * Precision::PConfusion();
97 for (Standard_Integer i = 1; i <= aNbPnts; i++)
99 Standard_Integer ii = i + 2;
102 p3 = &aPClass(ii - aNbPnts);
106 p3 = theWire.Value(ii);
110 const gp_Vec2d A(*p1,*p2), B(*p2,*p3);
111 if (A.SquareMagnitude() > aSqConfusion &&
112 B.SquareMagnitude() > aSqConfusion)
114 const Standard_Real aCurAngle = A.Angle(B);
115 const Standard_Real aCurAngleAbs = Abs(aCurAngle);
116 // Check if vectors are opposite
117 if (aCurAngleAbs > aAngTol && (M_PI - aCurAngleAbs) > aAngTol)
119 anAngle += aCurAngle;
125 // Check for zero angle - treat self intersecting wire as outer
126 if (Abs(anAngle) < aAngTol)
129 myTabClass.Append(new CSLib_Class2d(
130 aPClass, theTolUV.first, theTolUV.second,
131 theRangeU.first, theRangeV.first,
132 theRangeU.second, theRangeV.second));
134 myTabOrient.Append( !(anAngle < 0.0) );