0030345: Mesh, BRepMesh_CurveTessellator - GCPnts_TangentialDeflection throws Standar...
[occt.git] / src / BRepMesh / BRepMesh_VertexInspector.hxx
1 // Created on: 2011-06-01
2 // Created by: Oleg AGASHIN
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _BRepMesh_VertexInspector_HeaderFile
17 #define _BRepMesh_VertexInspector_HeaderFile
18
19 #include <Precision.hxx>
20 #include <gp_XY.hxx>
21 #include <gp_XYZ.hxx>
22 #include <IMeshData_Types.hxx>
23 #include <NCollection_CellFilter.hxx>
24 #include <BRepMesh_Vertex.hxx>
25
26 //! Class intended for fast searching of the coincidence points.
27 class BRepMesh_VertexInspector : public NCollection_CellFilter_InspectorXY
28 {
29 public:
30   typedef Standard_Integer Target;
31
32   //! Constructor.
33   //! @param theAllocator memory allocator to be used by internal collections.
34   BRepMesh_VertexInspector(
35     const Handle(NCollection_IncAllocator)& theAllocator)
36     : myIndex(0),
37       myMinSqDist(RealLast()),
38       myVertices(new IMeshData::VectorOfVertex),
39       myDelNodes(theAllocator)
40   {
41     SetTolerance(Precision::Confusion());
42   }
43
44   //! Registers the given vertex.
45   //! @param theVertex vertex to be registered.
46   Standard_Integer Add(const BRepMesh_Vertex& theVertex)
47   {
48     if( myDelNodes.IsEmpty() )
49     {
50       myVertices->Append(theVertex);
51       return myVertices->Length();
52     }
53     
54     Standard_Integer aNodeIndex = myDelNodes.First();
55     myVertices->ChangeValue(aNodeIndex - 1) = theVertex;
56     myDelNodes.RemoveFirst();
57     return aNodeIndex;
58   }
59   
60
61   //! Sets the tolerance to be used for identification of 
62   //! coincident vertices equal for both dimensions.
63   inline void SetTolerance(const Standard_Real theTolerance)
64   {
65     myTolerance[0] = theTolerance * theTolerance;
66     myTolerance[1] = 0.;
67   }
68   
69   //! Sets the tolerance to be used for identification of 
70   //! coincident vertices.
71   //! @param theToleranceX tolerance for X dimension.
72   //! @param theToleranceY tolerance for Y dimension.
73   inline void SetTolerance(const Standard_Real theToleranceX,
74                            const Standard_Real theToleranceY)
75   {
76     myTolerance[0] = theToleranceX * theToleranceX;
77     myTolerance[1] = theToleranceY * theToleranceY;
78   }
79   
80   //! Clear inspector's internal data structures.
81   inline void Clear()
82   {
83     myVertices->Clear();
84     myDelNodes.Clear();
85   }
86
87   //! Deletes vertex with the given index.
88   //! @param theIndex index of vertex to be removed.
89   inline void Delete(const Standard_Integer theIndex)
90   {
91     myVertices->ChangeValue(theIndex - 1).SetMovability(BRepMesh_Deleted);
92     myDelNodes.Append(theIndex);
93   }
94   
95   //! Returns number of registered vertices.
96   inline Standard_Integer NbVertices() const
97   {
98     return myVertices->Length(); 
99   }
100
101   //! Returns vertex with the given index.
102   inline BRepMesh_Vertex& GetVertex(Standard_Integer theIndex)
103   {
104     return myVertices->ChangeValue(theIndex - 1);
105   }
106   
107   //! Set reference point to be checked.
108   inline void SetPoint(const gp_XY& thePoint) 
109   { 
110     myIndex     = 0;
111     myMinSqDist = RealLast();
112     myPoint     = thePoint;
113   }
114
115   //! Returns index of point coinciding with regerence one.
116   inline Standard_Integer GetCoincidentPoint() const
117   {
118     return myIndex;
119   }
120   
121   //! Returns list with indexes of vertices that have movability attribute 
122   //! equal to BRepMesh_Deleted and can be replaced with another node.
123   inline const IMeshData::ListOfInteger& GetListOfDelPoints() const
124   {
125     return myDelNodes;
126   }
127
128   //! Returns set of mesh vertices.
129   inline const Handle(IMeshData::VectorOfVertex)& Vertices() const
130   {
131     return myVertices;
132   }
133
134   //! Returns set of mesh vertices for modification.
135   inline Handle(IMeshData::VectorOfVertex)& ChangeVertices()
136   {
137     return myVertices;
138   }
139
140   //! Performs inspection of a point with the given index.
141   //! @param theTargetIndex index of a circle to be checked.
142   //! @return status of the check.
143   Standard_EXPORT NCollection_CellFilter_Action Inspect(const Standard_Integer theTargetIndex);
144
145   //! Checks indices for equlity.
146   static Standard_Boolean IsEqual(const Standard_Integer theIndex,
147                                                   const Standard_Integer theTargetIndex)
148   {
149     return (theIndex == theTargetIndex);
150   }
151
152 private:
153
154   Standard_Integer                  myIndex;
155   Standard_Real                     myMinSqDist;
156   Standard_Real                     myTolerance[2];
157   Handle(IMeshData::VectorOfVertex) myVertices;
158   IMeshData::ListOfInteger          myDelNodes;
159   gp_XY                             myPoint;
160 };
161
162 #endif