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_DataStructureOfDelaun_HeaderFile |
15 | #define _BRepMesh_DataStructureOfDelaun_HeaderFile |
16 | |
17 | #include <Standard.hxx> |
18 | #include <Standard_DefineHandle.hxx> |
19 | #include <BRepMesh_VertexTool.hxx> |
20 | #include <Standard_Transient.hxx> |
21 | #include <BRepMesh_Triangle.hxx> |
22 | #include <BRepMesh_PairOfIndex.hxx> |
23 | #include <Standard_OStream.hxx> |
848fa7e3 |
24 | #include <BRepMesh.hxx> |
fc9b36d6 |
25 | |
26 | class BRepMesh_Vertex; |
27 | class BRepMesh_VertexTool; |
28 | class BRepMesh_Edge; |
29 | |
30 | //! Describes the data structure necessary for the mesh algorithms in |
31 | //! two dimensions plane or on surface by meshing in UV space. |
32 | class BRepMesh_DataStructureOfDelaun : public Standard_Transient |
33 | { |
34 | public: |
35 | |
36 | //! Constructor. |
848fa7e3 |
37 | //! @param theAllocator memory allocator to be used by internal structures. |
38 | //! @param theReservedNodeSize presumed number of nodes in this mesh. |
fc9b36d6 |
39 | Standard_EXPORT BRepMesh_DataStructureOfDelaun( |
848fa7e3 |
40 | const Handle(NCollection_IncAllocator)& theAllocator, |
41 | const Standard_Integer theReservedNodeSize = 100); |
fc9b36d6 |
42 | |
43 | |
44 | |
848fa7e3 |
45 | public: //! @name API for accessing mesh nodes. |
fc9b36d6 |
46 | |
47 | //! Returns number of nodes. |
48 | inline Standard_Integer NbNodes() const |
49 | { |
50 | return myNodes.Extent(); |
51 | } |
52 | |
53 | |
54 | //! Adds node to the mesh if it is not already in the mesh. |
848fa7e3 |
55 | //! @param theNode node to be added to the mesh. |
56 | //! @return index of the node in the structure. |
fc9b36d6 |
57 | inline Standard_Integer AddNode(const BRepMesh_Vertex& theNode) |
58 | { |
59 | return myNodes.Add(theNode); |
60 | } |
61 | |
62 | //! Finds the index of the given node. |
848fa7e3 |
63 | //! @param theNode node to find. |
64 | //! @return index of the given element of zero if node is not in the mesh. |
fc9b36d6 |
65 | Standard_EXPORT Standard_Integer IndexOf(const BRepMesh_Vertex& theNode) |
66 | { |
67 | return myNodes.FindIndex(theNode); |
68 | } |
69 | |
70 | //! Get node by the index. |
848fa7e3 |
71 | //! @param theIndex index of a node. |
72 | //! @return node with the given index. |
fc9b36d6 |
73 | inline const BRepMesh_Vertex& GetNode(const Standard_Integer theIndex) |
74 | { |
75 | return myNodes.FindKey(theIndex); |
76 | } |
77 | |
78 | //! Alias for GetNode. |
79 | const BRepMesh_Vertex& operator ()(const Standard_Integer theIndex) |
80 | { |
81 | return GetNode(theIndex); |
82 | } |
83 | |
84 | //! Replaces nodes of mesh by the given ones. |
848fa7e3 |
85 | //! @param theNewNodes nodes to be set instead of existing ones. |
fc9b36d6 |
86 | Standard_EXPORT void ReplaceNodes(const BRepMesh_VertexTool& theNewNodes) |
87 | { |
88 | if (theNewNodes.IsEmpty()) |
89 | return; |
90 | |
91 | myNodes = theNewNodes; |
92 | } |
93 | |
94 | //! Substitutes the node with the given index by new one. |
848fa7e3 |
95 | //! @param theIndex index of node to be substituted. |
96 | //! @param theNewNode substituting node. |
97 | //! @return FALSE in case if new node is already in the structure, TRUE elsewhere. |
fc9b36d6 |
98 | Standard_EXPORT Standard_Boolean SubstituteNode( |
99 | const Standard_Integer theIndex, |
100 | const BRepMesh_Vertex& theNewNode); |
101 | |
102 | //! Removes node from the mesh in case if it has no connected links |
103 | //! and its type is Free. |
848fa7e3 |
104 | //! @param theIndex index of node to be removed. |
105 | //! @param isForce if TRUE node will be removed even if movability |
fc9b36d6 |
106 | //! is not Free. |
107 | Standard_EXPORT void RemoveNode(const Standard_Integer theIndex, |
108 | const Standard_Boolean isForce = Standard_False) |
109 | { |
110 | if (isForce || myNodes.FindKey(theIndex).Movability() == BRepMesh_Free) |
111 | { |
112 | if (myNodes.FindFromIndex(theIndex).Extent()==0) |
113 | myNodes.Delete(theIndex); |
114 | } |
115 | } |
116 | |
117 | //! Get list of links attached to the node with the given index. |
848fa7e3 |
118 | //! @param theIndex index of node whose links should be retrieved. |
119 | //! @return list of links attached to the node. |
120 | inline const BRepMesh::ListOfInteger& LinksConnectedTo( |
fc9b36d6 |
121 | const Standard_Integer theIndex) const |
122 | { |
123 | return myNodes.FindFromIndex(theIndex); |
124 | } |
125 | |
126 | |
127 | |
848fa7e3 |
128 | public: //! @name API for accessing mesh links. |
fc9b36d6 |
129 | |
130 | //! Returns number of links. |
131 | inline Standard_Integer NbLinks() const |
132 | { |
133 | return myLinks.Extent(); |
134 | } |
135 | |
136 | //! Adds link to the mesh if it is not already in the mesh. |
848fa7e3 |
137 | //! @param theLink link to be added to the mesh. |
138 | //! @return index of the link in the structure. |
fc9b36d6 |
139 | Standard_EXPORT Standard_Integer AddLink(const BRepMesh_Edge& theLink); |
140 | |
141 | //! Finds the index of the given link. |
848fa7e3 |
142 | //! @param theLink link to find. |
143 | //! @return index of the given element of zero if link is not in the mesh. |
fc9b36d6 |
144 | Standard_EXPORT Standard_Integer IndexOf(const BRepMesh_Edge& theLink) const |
145 | { |
146 | return myLinks.FindIndex(theLink); |
147 | } |
148 | |
149 | //! Get link by the index. |
848fa7e3 |
150 | //! @param theIndex index of a link. |
151 | //! @return link with the given index. |
fc9b36d6 |
152 | Standard_EXPORT const BRepMesh_Edge& GetLink(const Standard_Integer theIndex) |
153 | { |
154 | return myLinks.FindKey(theIndex); |
155 | } |
156 | |
157 | //! Returns map of indices of links registered in mesh. |
848fa7e3 |
158 | inline const BRepMesh::MapOfInteger& LinksOfDomain() const |
fc9b36d6 |
159 | { |
160 | return myLinksOfDomain; |
161 | } |
162 | |
163 | //! Substitutes the link with the given index by new one. |
848fa7e3 |
164 | //! @param theIndex index of link to be substituted. |
165 | //! @param theNewLink substituting link. |
166 | //! @return FALSE in case if new link is already in the structure, TRUE elsewhere. |
fc9b36d6 |
167 | Standard_EXPORT Standard_Boolean SubstituteLink(const Standard_Integer theIndex, |
168 | const BRepMesh_Edge& theNewLink); |
169 | |
170 | //! Removes link from the mesh in case if it has no connected elements |
171 | //! and its type is Free. |
848fa7e3 |
172 | //! @param theIndex index of link to be removed. |
173 | //! @param isForce if TRUE link will be removed even if movability |
fc9b36d6 |
174 | //! is not Free. |
175 | Standard_EXPORT void RemoveLink(const Standard_Integer theIndex, |
176 | const Standard_Boolean isForce = Standard_False); |
177 | |
178 | //! Returns indices of elements conected to the link with the given index. |
848fa7e3 |
179 | //! @param theLinkIndex index of link whose data should be retrieved. |
180 | //! @return indices of elements conected to the link. |
fc9b36d6 |
181 | Standard_EXPORT const BRepMesh_PairOfIndex& ElementsConnectedTo( |
182 | const Standard_Integer theLinkIndex) const |
183 | { |
184 | return myLinks.FindFromIndex(theLinkIndex); |
185 | } |
186 | |
187 | |
188 | |
848fa7e3 |
189 | public: //! @name API for accessing mesh elements. |
fc9b36d6 |
190 | |
191 | //! Returns number of links. |
192 | inline Standard_Integer NbElements() const |
193 | { |
194 | return myElements.Extent(); |
195 | } |
196 | |
197 | //! Adds element to the mesh if it is not already in the mesh. |
848fa7e3 |
198 | //! @param theElement element to be added to the mesh. |
199 | //! @return index of the element in the structure. |
fc9b36d6 |
200 | Standard_EXPORT Standard_Integer AddElement(const BRepMesh_Triangle& theElement); |
201 | |
202 | //! Finds the index of the given element. |
848fa7e3 |
203 | //! @param theElement element to find. |
204 | //! @return index of the given element of zero if element is not in the mesh. |
fc9b36d6 |
205 | Standard_EXPORT Standard_Integer IndexOf(const BRepMesh_Triangle& theElement) const |
206 | { |
207 | return myElements.FindIndex(theElement); |
208 | } |
209 | |
210 | //! Get element by the index. |
848fa7e3 |
211 | //! @param theIndex index of an element. |
212 | //! @return element with the given index. |
fc9b36d6 |
213 | Standard_EXPORT const BRepMesh_Triangle& GetElement(const Standard_Integer theIndex) |
214 | { |
215 | return myElements.FindKey(theIndex); |
216 | } |
217 | |
218 | //! Returns map of indices of elements registered in mesh. |
848fa7e3 |
219 | inline const BRepMesh::MapOfInteger& ElementsOfDomain() const |
fc9b36d6 |
220 | { |
221 | return myElementsOfDomain; |
222 | } |
223 | |
224 | //! Substitutes the element with the given index by new one. |
848fa7e3 |
225 | //! @param theIndex index of element to be substituted. |
226 | //! @param theNewLink substituting element. |
227 | //! @return FALSE in case if new element is already in the structure, TRUE elsewhere. |
fc9b36d6 |
228 | Standard_EXPORT Standard_Boolean SubstituteElement(const Standard_Integer theIndex, |
229 | const BRepMesh_Triangle& theNewElement); |
230 | |
231 | //! Removes element from the mesh. |
848fa7e3 |
232 | //! @param theIndex index of element to be removed. |
fc9b36d6 |
233 | Standard_EXPORT void RemoveElement(const Standard_Integer theIndex); |
234 | |
235 | //! Returns indices of nodes forming the given element. |
848fa7e3 |
236 | //! @param theElement element which nodes should be retrieved. |
237 | //! @param[out] theNodes nodes of the given element. |
fc9b36d6 |
238 | Standard_EXPORT void ElementNodes( |
239 | const BRepMesh_Triangle& theElement, |
240 | Standard_Integer (&theNodes)[3]); |
241 | |
242 | |
243 | |
848fa7e3 |
244 | public: //! @name Auxilary API |
fc9b36d6 |
245 | |
246 | //! Dumps information about this structure. |
848fa7e3 |
247 | //! @param theStream stream to be used for dump. |
fc9b36d6 |
248 | Standard_EXPORT void Statistics(Standard_OStream& theStream) const; |
249 | |
250 | //! Returns memory allocator used by the structure. |
848fa7e3 |
251 | inline const Handle(NCollection_IncAllocator)& Allocator() const |
fc9b36d6 |
252 | { |
253 | return myAllocator; |
254 | } |
255 | |
256 | //! Gives the data structure for initialization of cell size and tolerance. |
257 | inline BRepMesh_VertexTool& Data() |
258 | { |
259 | return myNodes; |
260 | } |
261 | |
262 | //! Removes all elements. |
263 | Standard_EXPORT void ClearDomain(); |
264 | |
265 | //! Substitutes deleted items by the last one from corresponding map |
266 | //! to have only non-deleted elements, links or nodes in the structure. |
267 | Standard_EXPORT void ClearDeleted() |
268 | { |
269 | clearDeletedLinks(); |
270 | clearDeletedNodes(); |
271 | } |
272 | |
273 | DEFINE_STANDARD_RTTI(BRepMesh_DataStructureOfDelaun) |
274 | |
275 | private: |
276 | |
277 | //! Substitutes deleted links by the last one from corresponding map |
278 | //! to have only non-deleted links in the structure. |
279 | Standard_EXPORT void clearDeletedLinks(); |
280 | |
281 | //! Substitutes deleted nodes by the last one from corresponding map |
282 | //! to have only non-deleted nodes in the structure. |
283 | Standard_EXPORT void clearDeletedNodes(); |
284 | |
285 | //! Cleans dependent structures from the given link. |
848fa7e3 |
286 | //! @param theIndex index of link in the data structure. |
287 | //! @param theLink reference to the link to avoid double accessing |
fc9b36d6 |
288 | //! to map of links. |
289 | void cleanLink(const Standard_Integer theIndex, |
290 | const BRepMesh_Edge& theLink); |
291 | |
292 | //! Cleans dependent structures from the given element. |
848fa7e3 |
293 | //! @param theIndex index of element in the data structure. |
294 | //! @param theElement reference to the element to avoid double accessing |
fc9b36d6 |
295 | //! to map of elements. |
296 | void cleanElement(const Standard_Integer theIndex, |
297 | const BRepMesh_Triangle& theElement); |
298 | |
299 | //! Removes element index from the given pair. Used by cleanElement. |
848fa7e3 |
300 | //! @param theIndex index of element to be removed. |
301 | //! @param thePair pair of elements to be cleaned. |
fc9b36d6 |
302 | void removeElementIndex(const Standard_Integer theIndex, |
303 | BRepMesh_PairOfIndex& thePair); |
304 | |
305 | |
306 | private: |
307 | |
848fa7e3 |
308 | BRepMesh_VertexTool myNodes; |
309 | BRepMesh::IDMapOfLink myLinks; |
310 | BRepMesh::ListOfInteger myDelLinks; |
311 | BRepMesh::IMapOfElement myElements; |
312 | BRepMesh::MapOfInteger myElementsOfDomain; |
313 | BRepMesh::MapOfInteger myLinksOfDomain; |
314 | Handle(NCollection_IncAllocator) myAllocator; |
fc9b36d6 |
315 | }; |
316 | |
317 | DEFINE_STANDARD_HANDLE(BRepMesh_DataStructureOfDelaun,Standard_Transient) |
318 | |
319 | #endif |