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