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