1 // Created on: 1997-06-26
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1997-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 #include <BRepMesh_Classifier.hxx>
19 #include <Precision.hxx>
20 #include <gp_Pnt2d.hxx>
21 #include <CSLib_Class2d.hxx>
22 #include <TColgp_Array1OfPnt2d.hxx>
24 //=======================================================================
25 //function : Constructor
27 //=======================================================================
28 BRepMesh_Classifier::BRepMesh_Classifier()
32 //=======================================================================
35 //=======================================================================
36 TopAbs_State BRepMesh_Classifier::Perform(const gp_Pnt2d& thePoint) const
38 Standard_Boolean isOut = Standard_False;
39 Standard_Integer aNb = myTabClass.Length();
41 for (Standard_Integer i = 1; i <= aNb; i++)
43 Standard_Integer aCur = ((CSLib_Class2d*)myTabClass(i))->SiDans(thePoint);
46 // Point is ON, but mark it as OUT
47 isOut = Standard_True;
50 isOut = myTabOrient(i) ? (aCur == -1) : (aCur == 1);
59 //=======================================================================
60 //function : RegisterWire
62 //=======================================================================
63 void BRepMesh_Classifier::RegisterWire(
64 const NCollection_Sequence<gp_Pnt2d>& theWire,
65 const Standard_Real theTolUV,
66 const Standard_Real theUmin,
67 const Standard_Real theUmax,
68 const Standard_Real theVmin,
69 const Standard_Real theVmax)
71 const Standard_Integer aNbPnts = theWire.Length();
76 TColgp_Array1OfPnt2d aPClass(1, aNbPnts);
77 Standard_Real anAngle = 0.0;
78 gp_Pnt2d p1 = theWire(1), p2 = theWire(2), p3;
82 const Standard_Real aAngTol = Precision::Angular();
83 const Standard_Real aSqConfusion =
84 Precision::PConfusion() * Precision::PConfusion();
86 for (Standard_Integer i = 1; i <= aNbPnts; i++)
88 Standard_Integer ii = i + 2;
91 p3 = aPClass(ii - aNbPnts);
95 p3 = theWire.Value(ii);
99 gp_Vec2d A(p1,p2), B(p2,p3);
100 if (A.SquareMagnitude() > aSqConfusion &&
101 B.SquareMagnitude() > aSqConfusion)
103 const Standard_Real aCurAngle = A.Angle(B);
104 const Standard_Real aCurAngleAbs = Abs(aCurAngle);
105 // Check if vectors are opposite
106 if (aCurAngleAbs > aAngTol && (M_PI - aCurAngleAbs) > aAngTol)
108 anAngle += aCurAngle;
114 // Check for zero angle - treat self intersecting wire as outer
115 if (Abs(anAngle) < aAngTol)
118 myTabClass.Append( (void *)new CSLib_Class2d(aPClass,
119 theTolUV, theTolUV, theUmin, theVmin, theUmax, theVmax) );
120 myTabOrient.Append( !(anAngle < 0.0) );
123 //=======================================================================
126 //=======================================================================
127 void BRepMesh_Classifier::Destroy()
129 Standard_Integer aNb = myTabClass.Length();
130 for (Standard_Integer i = 1; i <= aNb; i++)
134 delete ((CSLib_Class2d*)myTabClass(i));
135 myTabClass(i) = NULL;