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