0025364: BRepMesh is not able to triangulate the shape with fine deflection
[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 <BRepMesh.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 theReservedSize size to be reserved for vector of vertices.
34   //! @param theAllocator memory allocator to be used by internal collections.
35   Standard_EXPORT BRepMesh_VertexInspector (
36     const Standard_Integer                  theReservedSize,
37     const Handle(NCollection_IncAllocator)& theAllocator)
38     : myResIndices(theAllocator),
39       myVertices  (new BRepMesh::VectorOfVertex(theReservedSize)),
40       myDelNodes  (theAllocator)
41   {
42     SetTolerance( Precision::Confusion() );
43   }
44
45   //! Registers the given vertex.
46   //! @param theVertex vertex to be registered.
47   Standard_EXPORT Standard_Integer Add(const BRepMesh_Vertex& theVertex)
48   {
49     if( myDelNodes.IsEmpty() )
50     {
51       myVertices->Append(theVertex);
52       return myVertices->Length();
53     }
54     
55     Standard_Integer aNodeIndex = myDelNodes.First();
56     myVertices->ChangeValue(aNodeIndex - 1) = theVertex;
57     myDelNodes.RemoveFirst();
58     return aNodeIndex;
59   }
60   
61
62   //! Sets the tolerance to be used for identification of 
63   //! coincident vertices equal for both dimensions.
64   inline void SetTolerance(const Standard_Real theTolerance)
65   {
66     myTolerance[0] = theTolerance * theTolerance;
67     myTolerance[1] = 0.;
68   }
69   
70   //! Sets the tolerance to be used for identification of 
71   //! coincident vertices.
72   //! @param theToleranceX tolerance for X dimension.
73   //! @param theToleranceY tolerance for Y dimension.
74   inline void SetTolerance(const Standard_Real theToleranceX,
75                            const Standard_Real theToleranceY)
76   {
77     myTolerance[0] = theToleranceX * theToleranceX;
78     myTolerance[1] = theToleranceY * theToleranceY;
79   }
80   
81   //! Clear inspector's internal data structures.
82   inline void Clear()
83   {
84     myVertices->Clear();
85     myDelNodes.Clear();
86   }
87
88   //! Deletes vertex with the given index.
89   //! @param theIndex index of vertex to be removed.
90   inline void Delete(const Standard_Integer theIndex)
91   {
92     myVertices->ChangeValue(theIndex - 1).SetMovability(BRepMesh_Deleted);
93     myDelNodes.Append(theIndex);
94   }
95   
96   //! Returns number of registered vertices.
97   inline Standard_Integer NbVertices() const
98   {
99     return myVertices->Length(); 
100   }
101
102   //! Returns vertex with the given index.
103   inline BRepMesh_Vertex& GetVertex(Standard_Integer theIndex)
104   {
105     return myVertices->ChangeValue(theIndex - 1);
106   }
107   
108   //! Set reference point to be checked.
109   inline void SetPoint(const gp_XY& thePoint) 
110   { 
111     myResIndices.Clear();
112     myPoint = thePoint;
113   }
114
115   //! Returns index of point coinciding with regerence one.
116   inline const Standard_Integer GetCoincidentPoint() const
117   {
118     if ( myResIndices.Size() > 0 )
119     {
120       return myResIndices.First();
121     }
122     return 0;
123   }
124   
125   //! Returns list with indexes of vertices that have movability attribute 
126   //! equal to BRepMesh_Deleted and can be replaced with another node.
127   inline const BRepMesh::ListOfInteger& GetListOfDelPoints() const
128   {
129     return myDelNodes;
130   }
131
132   //! Returns set of mesh vertices.
133   inline const BRepMesh::HVectorOfVertex& Vertices() const
134   {
135     return myVertices;
136   }
137
138   //! Returns set of mesh vertices for modification.
139   inline BRepMesh::HVectorOfVertex& ChangeVertices()
140   {
141     return myVertices;
142   }
143
144   //! Performs inspection of a point with the given index.
145   //! @param theTargetIndex index of a circle to be checked.
146   //! @return status of the check.
147   Standard_EXPORT NCollection_CellFilter_Action Inspect(const Standard_Integer theTargetIndex);
148
149   //! Checks indices for equlity.
150   Standard_EXPORT static Standard_Boolean IsEqual(const Standard_Integer theIndex,
151                                                   const Standard_Integer theTargetIndex)
152   {
153     return (theIndex == theTargetIndex);
154   }
155
156 private:
157
158   Standard_Real             myTolerance[2];
159   BRepMesh::ListOfInteger   myResIndices;
160   BRepMesh::HVectorOfVertex myVertices;
161   BRepMesh::ListOfInteger   myDelNodes;
162   gp_XY                     myPoint;
163 };
164
165 #endif