fc9b36d6 |
1 | // Copyright (c) 2013 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #ifndef _BRepMesh_VertexTool_HeaderFile |
15 | #define _BRepMesh_VertexTool_HeaderFile |
16 | |
50bc8f96 |
17 | #include <NCollection_Array1.hxx> |
7bd071ed |
18 | #include <Standard_Transient.hxx> |
fc9b36d6 |
19 | #include <BRepMesh_VertexInspector.hxx> |
fc9b36d6 |
20 | #include <Standard_OStream.hxx> |
fc9b36d6 |
21 | #include <gp_XY.hxx> |
7bd071ed |
22 | #include <IMeshData_Types.hxx> |
fc9b36d6 |
23 | |
24 | class BRepMesh_Vertex; |
25 | |
26 | //! Describes data structure intended to keep mesh nodes |
27 | //! defined in UV space and implements functionality |
7bd071ed |
28 | //! providing their uniqueness regarding their position. |
29 | class BRepMesh_VertexTool : public Standard_Transient |
fc9b36d6 |
30 | { |
31 | public: |
32 | |
fc9b36d6 |
33 | //! Constructor. |
848fa7e3 |
34 | //! @param theAllocator memory allocator to be used by internal collections. |
35 | Standard_EXPORT BRepMesh_VertexTool( |
848fa7e3 |
36 | const Handle(NCollection_IncAllocator)& theAllocator); |
fc9b36d6 |
37 | |
38 | //! Sets new size of cell for cellfilter equal in both directions. |
be5c3602 |
39 | void SetCellSize(const Standard_Real theSize) |
fc9b36d6 |
40 | { |
41 | myCellFilter.Reset(theSize, myAllocator); |
42 | mySelector.Clear(); |
43 | } |
44 | |
45 | //! Sets new size of cell for cellfilter. |
848fa7e3 |
46 | //! @param theSizeX size for X dimension. |
47 | //! @param theSizeY size for Y dimension. |
be5c3602 |
48 | void SetCellSize(const Standard_Real theSizeX, |
49 | const Standard_Real theSizeY) |
fc9b36d6 |
50 | { |
50bc8f96 |
51 | Standard_Real aCellSizeC[2] = { theSizeX, theSizeY }; |
52 | NCollection_Array1<Standard_Real> aCellSize(aCellSizeC[0], 1, 2); |
fc9b36d6 |
53 | myCellFilter.Reset(aCellSize, myAllocator); |
54 | mySelector.Clear(); |
55 | } |
56 | |
57 | //! Sets the tolerance to be used for identification of |
58 | //! coincident vertices equal for both dimensions. |
be5c3602 |
59 | void SetTolerance(const Standard_Real theTolerance) |
fc9b36d6 |
60 | { |
61 | mySelector.SetTolerance( theTolerance ); |
62 | myTolerance[0] = theTolerance; |
63 | myTolerance[1] = theTolerance; |
64 | } |
65 | |
66 | //! Sets the tolerance to be used for identification of |
67 | //! coincident vertices. |
848fa7e3 |
68 | //! @param theToleranceX tolerance for X dimension. |
69 | //! @param theToleranceY tolerance for Y dimension. |
be5c3602 |
70 | void SetTolerance(const Standard_Real theToleranceX, |
71 | const Standard_Real theToleranceY) |
fc9b36d6 |
72 | { |
73 | mySelector.SetTolerance( theToleranceX, theToleranceY ); |
74 | myTolerance[0] = theToleranceX; |
75 | myTolerance[1] = theToleranceY; |
76 | } |
77 | |
71316196 |
78 | //! Gets the tolerance to be used for identification of |
79 | //! coincident vertices. |
80 | //! @param theToleranceX tolerance for X dimension. |
81 | //! @param theToleranceY tolerance for Y dimension. |
be5c3602 |
82 | void GetTolerance(Standard_Real& theToleranceX, |
83 | Standard_Real& theToleranceY) |
71316196 |
84 | { |
85 | theToleranceX = myTolerance[0]; |
86 | theToleranceY = myTolerance[1]; |
87 | } |
88 | |
fc9b36d6 |
89 | //! Adds vertex with empty data to the tool. |
2caff0b3 |
90 | //! @param theVertex node to be added to the mesh. |
91 | //! @param isForceAdd adds the given node to structure without |
92 | //! checking on coincidence with other nodes. |
93 | //! @return index of the node in the structure. |
94 | Standard_EXPORT Standard_Integer Add( |
95 | const BRepMesh_Vertex& theVertex, |
96 | const Standard_Boolean isForceAdd); |
fc9b36d6 |
97 | |
98 | //! Deletes vertex with the given index from the tool. |
7bd071ed |
99 | Standard_EXPORT void DeleteVertex(const Standard_Integer theIndex); |
fc9b36d6 |
100 | |
2caff0b3 |
101 | //! Returns set of mesh vertices. |
7bd071ed |
102 | inline const Handle(IMeshData::VectorOfVertex)& Vertices() const |
fc9b36d6 |
103 | { |
2caff0b3 |
104 | return mySelector.Vertices(); |
fc9b36d6 |
105 | } |
106 | |
2caff0b3 |
107 | //! Returns set of mesh vertices. |
7bd071ed |
108 | inline Handle(IMeshData::VectorOfVertex)& ChangeVertices() |
fc9b36d6 |
109 | { |
2caff0b3 |
110 | return mySelector.ChangeVertices(); |
fc9b36d6 |
111 | } |
112 | |
113 | //! Returns vertex by the given index. |
114 | inline const BRepMesh_Vertex& FindKey(const Standard_Integer theIndex) |
115 | { |
116 | return mySelector.GetVertex(theIndex); |
117 | } |
118 | |
119 | //! Returns index of the given vertex. |
be5c3602 |
120 | Standard_Integer FindIndex(const BRepMesh_Vertex& theVertex) |
fc9b36d6 |
121 | { |
122 | mySelector.SetPoint(theVertex.Coord()); |
123 | myCellFilter.Inspect (theVertex.Coord(), mySelector); |
124 | return mySelector.GetCoincidentPoint(); |
125 | } |
126 | |
127 | //! Returns a number of vertices. |
128 | inline Standard_Integer Extent() const |
129 | { |
130 | return mySelector.NbVertices(); |
131 | } |
132 | |
133 | //! Returns True when the map contains no keys. <br> |
134 | inline Standard_Boolean IsEmpty() const |
135 | { |
136 | return (Extent() == 0); |
137 | } |
138 | |
139 | //! Substitutes vertex with the given by the given vertex with attributes. |
848fa7e3 |
140 | //! @param theIndex index of vertex to be substituted. |
141 | //! @param theVertex replacement vertex. |
2caff0b3 |
142 | Standard_EXPORT void Substitute(const Standard_Integer theIndex, |
143 | const BRepMesh_Vertex& theVertex); |
fc9b36d6 |
144 | |
145 | //! Remove last node from the structure. |
146 | inline void RemoveLast() |
147 | { |
7bd071ed |
148 | DeleteVertex(Extent()); |
fc9b36d6 |
149 | } |
150 | |
151 | //! Returns the list with indexes of vertices that have movability attribute |
152 | //! equal to BRepMesh_Deleted and can be replaced with another node. |
7bd071ed |
153 | inline const IMeshData::ListOfInteger& GetListOfDelNodes() const |
fc9b36d6 |
154 | { |
155 | return mySelector.GetListOfDelPoints(); |
156 | } |
157 | |
158 | //! Prints statistics. |
159 | Standard_EXPORT void Statistics(Standard_OStream& theStream) const; |
160 | |
7bd071ed |
161 | DEFINE_STANDARD_RTTI_INLINE(BRepMesh_VertexTool, Standard_Transient) |
162 | |
fc9b36d6 |
163 | private: |
164 | |
165 | //! Expands the given point according to specified tolerance. |
848fa7e3 |
166 | //! @param thePoint point to be expanded. |
167 | //! @param[out] theMinPoint bottom left corner of area defined by expanded point. |
168 | //! @param[out] theMaxPoint top right corner of area defined by expanded point. |
fc9b36d6 |
169 | inline void expandPoint(const gp_XY& thePoint, |
170 | gp_XY& theMinPoint, |
171 | gp_XY& theMaxPoint) |
172 | { |
173 | theMinPoint.SetX(thePoint.X() - myTolerance[0]); |
174 | theMinPoint.SetY(thePoint.Y() - myTolerance[1]); |
175 | theMaxPoint.SetX(thePoint.X() + myTolerance[0]); |
176 | theMaxPoint.SetY(thePoint.Y() + myTolerance[1]); |
177 | } |
178 | |
179 | private: |
180 | |
7bd071ed |
181 | Handle(NCollection_IncAllocator) myAllocator; |
182 | IMeshData::VertexCellFilter myCellFilter; |
183 | BRepMesh_VertexInspector mySelector; |
184 | Standard_Real myTolerance[2]; |
fc9b36d6 |
185 | }; |
186 | |
187 | #endif |