1 // Copyright (c) 2013 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _BRepMesh_DataStructureOfDelaun_HeaderFile
15 #define _BRepMesh_DataStructureOfDelaun_HeaderFile
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>
24 #include <BRepMesh.hxx>
26 class BRepMesh_Vertex;
27 class BRepMesh_VertexTool;
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
37 //! @param theAllocator memory allocator to be used by internal structures.
38 //! @param theReservedNodeSize presumed number of nodes in this mesh.
39 Standard_EXPORT BRepMesh_DataStructureOfDelaun(
40 const Handle(NCollection_IncAllocator)& theAllocator,
41 const Standard_Integer theReservedNodeSize = 100);
45 public: //! @name API for accessing mesh nodes.
47 //! Returns number of nodes.
48 inline Standard_Integer NbNodes() const
50 return myNodes->Extent();
54 //! Adds node to the mesh if it is not already in the mesh.
55 //! @param theNode node to be added to the mesh.
56 //! @param isForceAdd adds the given node to structure without
57 //! checking on coincidence with other nodes.
58 //! @return index of the node in the structure.
59 Standard_EXPORT Standard_Integer AddNode(
60 const BRepMesh_Vertex& theNode,
61 const Standard_Boolean isForceAdd = Standard_False);
63 //! Finds the index of the given node.
64 //! @param theNode node to find.
65 //! @return index of the given element of zero if node is not in the mesh.
66 Standard_EXPORT Standard_Integer IndexOf(const BRepMesh_Vertex& theNode)
68 return myNodes->FindIndex(theNode);
71 //! Get node by the index.
72 //! @param theIndex index of a node.
73 //! @return node with the given index.
74 inline const BRepMesh_Vertex& GetNode(const Standard_Integer theIndex)
76 return myNodes->FindKey(theIndex);
79 //! Alias for GetNode.
80 const BRepMesh_Vertex& operator ()(const Standard_Integer theIndex)
82 return GetNode(theIndex);
85 //! Substitutes the node with the given index by new one.
86 //! @param theIndex index of node to be substituted.
87 //! @param theNewNode substituting node.
88 //! @return FALSE in case if new node is already in the structure, TRUE elsewhere.
89 Standard_EXPORT Standard_Boolean SubstituteNode(
90 const Standard_Integer theIndex,
91 const BRepMesh_Vertex& theNewNode);
93 //! Removes node from the mesh in case if it has no connected links
94 //! and its type is Free.
95 //! @param theIndex index of node to be removed.
96 //! @param isForce if TRUE node will be removed even if movability
98 Standard_EXPORT void RemoveNode(const Standard_Integer theIndex,
99 const Standard_Boolean isForce = Standard_False)
101 if (isForce || myNodes->FindKey(theIndex).Movability() == BRepMesh_Free)
103 if (LinksConnectedTo(theIndex).Extent()==0)
104 myNodes->Delete(theIndex);
108 //! Get list of links attached to the node with the given index.
109 //! @param theIndex index of node whose links should be retrieved.
110 //! @return list of links attached to the node.
111 inline const BRepMesh::ListOfInteger& LinksConnectedTo(
112 const Standard_Integer theIndex) const
114 return linksConnectedTo(theIndex);
118 public: //! @name API for accessing mesh links.
120 //! Returns number of links.
121 inline Standard_Integer NbLinks() const
123 return myLinks.Extent();
126 //! Adds link to the mesh if it is not already in the mesh.
127 //! @param theLink link to be added to the mesh.
128 //! @return index of the link in the structure.
129 Standard_EXPORT Standard_Integer AddLink(const BRepMesh_Edge& theLink);
131 //! Finds the index of the given link.
132 //! @param theLink link to find.
133 //! @return index of the given element of zero if link is not in the mesh.
134 Standard_EXPORT Standard_Integer IndexOf(const BRepMesh_Edge& theLink) const
136 return myLinks.FindIndex(theLink);
139 //! Get link by the index.
140 //! @param theIndex index of a link.
141 //! @return link with the given index.
142 Standard_EXPORT const BRepMesh_Edge& GetLink(const Standard_Integer theIndex)
144 return myLinks.FindKey(theIndex);
147 //! Returns map of indices of links registered in mesh.
148 inline const BRepMesh::MapOfInteger& LinksOfDomain() const
150 return myLinksOfDomain;
153 //! Substitutes the link with the given index by new one.
154 //! @param theIndex index of link to be substituted.
155 //! @param theNewLink substituting link.
156 //! @return FALSE in case if new link is already in the structure, TRUE elsewhere.
157 Standard_EXPORT Standard_Boolean SubstituteLink(const Standard_Integer theIndex,
158 const BRepMesh_Edge& theNewLink);
160 //! Removes link from the mesh in case if it has no connected elements
161 //! and its type is Free.
162 //! @param theIndex index of link to be removed.
163 //! @param isForce if TRUE link will be removed even if movability
165 Standard_EXPORT void RemoveLink(const Standard_Integer theIndex,
166 const Standard_Boolean isForce = Standard_False);
168 //! Returns indices of elements conected to the link with the given index.
169 //! @param theLinkIndex index of link whose data should be retrieved.
170 //! @return indices of elements conected to the link.
171 Standard_EXPORT const BRepMesh_PairOfIndex& ElementsConnectedTo(
172 const Standard_Integer theLinkIndex) const
174 return myLinks.FindFromIndex(theLinkIndex);
179 public: //! @name API for accessing mesh elements.
181 //! Returns number of links.
182 inline Standard_Integer NbElements() const
184 return myElements.Extent();
187 //! Adds element to the mesh if it is not already in the mesh.
188 //! @param theElement element to be added to the mesh.
189 //! @return index of the element in the structure.
190 Standard_EXPORT Standard_Integer AddElement(const BRepMesh_Triangle& theElement);
192 //! Finds the index of the given element.
193 //! @param theElement element to find.
194 //! @return index of the given element of zero if element is not in the mesh.
195 Standard_EXPORT Standard_Integer IndexOf(const BRepMesh_Triangle& theElement) const
197 return myElements.FindIndex(theElement);
200 //! Get element by the index.
201 //! @param theIndex index of an element.
202 //! @return element with the given index.
203 Standard_EXPORT const BRepMesh_Triangle& GetElement(const Standard_Integer theIndex)
205 return myElements.FindKey(theIndex);
208 //! Returns map of indices of elements registered in mesh.
209 inline const BRepMesh::MapOfInteger& ElementsOfDomain() const
211 return myElementsOfDomain;
214 //! Substitutes the element with the given index by new one.
215 //! @param theIndex index of element to be substituted.
216 //! @param theNewLink substituting element.
217 //! @return FALSE in case if new element is already in the structure, TRUE elsewhere.
218 Standard_EXPORT Standard_Boolean SubstituteElement(const Standard_Integer theIndex,
219 const BRepMesh_Triangle& theNewElement);
221 //! Removes element from the mesh.
222 //! @param theIndex index of element to be removed.
223 Standard_EXPORT void RemoveElement(const Standard_Integer theIndex);
225 //! Returns indices of nodes forming the given element.
226 //! @param theElement element which nodes should be retrieved.
227 //! @param[out] theNodes nodes of the given element.
228 Standard_EXPORT void ElementNodes(
229 const BRepMesh_Triangle& theElement,
230 Standard_Integer (&theNodes)[3]);
234 public: //! @name Auxilary API
236 //! Dumps information about this structure.
237 //! @param theStream stream to be used for dump.
238 Standard_EXPORT void Statistics(Standard_OStream& theStream) const;
240 //! Returns memory allocator used by the structure.
241 inline const Handle(NCollection_IncAllocator)& Allocator() const
246 //! Gives the data structure for initialization of cell size and tolerance.
247 inline BRepMesh::HVertexTool& Data()
252 //! Removes all elements.
253 Standard_EXPORT void ClearDomain();
255 //! Substitutes deleted items by the last one from corresponding map
256 //! to have only non-deleted elements, links or nodes in the structure.
257 Standard_EXPORT void ClearDeleted()
263 DEFINE_STANDARD_RTTI(BRepMesh_DataStructureOfDelaun)
267 //! Get list of links attached to the node with the given index.
268 //! @param theIndex index of node whose links should be retrieved.
269 //! @return list of links attached to the node.
270 inline BRepMesh::ListOfInteger& linksConnectedTo(
271 const Standard_Integer theIndex) const
273 return (BRepMesh::ListOfInteger&)myNodeLinks.Find(theIndex);
276 //! Substitutes deleted links by the last one from corresponding map
277 //! to have only non-deleted links in the structure.
278 Standard_EXPORT void clearDeletedLinks();
280 //! Substitutes deleted nodes by the last one from corresponding map
281 //! to have only non-deleted nodes in the structure.
282 Standard_EXPORT void clearDeletedNodes();
284 //! Cleans dependent structures from the given link.
285 //! @param theIndex index of link in the data structure.
286 //! @param theLink reference to the link to avoid double accessing
288 void cleanLink(const Standard_Integer theIndex,
289 const BRepMesh_Edge& theLink);
291 //! Cleans dependent structures from the given element.
292 //! @param theIndex index of element in the data structure.
293 //! @param theElement reference to the element to avoid double accessing
294 //! to map of elements.
295 void cleanElement(const Standard_Integer theIndex,
296 const BRepMesh_Triangle& theElement);
298 //! Removes element index from the given pair. Used by cleanElement.
299 //! @param theIndex index of element to be removed.
300 //! @param thePair pair of elements to be cleaned.
301 void removeElementIndex(const Standard_Integer theIndex,
302 BRepMesh_PairOfIndex& thePair);
307 Handle(NCollection_IncAllocator) myAllocator;
308 BRepMesh::HVertexTool myNodes;
309 BRepMesh::DMapOfIntegerListOfInteger myNodeLinks;
310 BRepMesh::IDMapOfLink myLinks;
311 BRepMesh::ListOfInteger myDelLinks;
312 BRepMesh::IMapOfElement myElements;
313 BRepMesh::MapOfInteger myElementsOfDomain;
314 BRepMesh::MapOfInteger myLinksOfDomain;
317 DEFINE_STANDARD_HANDLE(BRepMesh_DataStructureOfDelaun,Standard_Transient)