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_Transient.hxx>
18 #include <BRepMesh_VertexTool.hxx>
22 //! Describes the data structure necessary for the mesh algorithms in
23 //! two dimensions plane or on surface by meshing in UV space.
24 class BRepMesh_DataStructureOfDelaun : public Standard_Transient
29 //! @param theAllocator memory allocator to be used by internal structures.
30 //! @param theReservedNodeSize presumed number of nodes in this mesh.
31 Standard_EXPORT BRepMesh_DataStructureOfDelaun(
32 const Handle(NCollection_IncAllocator)& theAllocator,
33 const Standard_Integer theReservedNodeSize = 100);
37 public: //! @name API for accessing mesh nodes.
39 //! Returns number of nodes.
40 Standard_Integer NbNodes() const
42 return myNodes->Extent();
46 //! Adds node to the mesh if it is not already in the mesh.
47 //! @param theNode node to be added to the mesh.
48 //! @param isForceAdd adds the given node to structure without
49 //! checking on coincidence with other nodes.
50 //! @return index of the node in the structure.
51 Standard_EXPORT Standard_Integer AddNode(
52 const BRepMesh_Vertex& theNode,
53 const Standard_Boolean isForceAdd = Standard_False);
55 //! Finds the index of the given node.
56 //! @param theNode node to find.
57 //! @return index of the given element of zero if node is not in the mesh.
58 Standard_Integer IndexOf(const BRepMesh_Vertex& theNode)
60 return myNodes->FindIndex(theNode);
63 //! Get node by the index.
64 //! @param theIndex index of a node.
65 //! @return node with the given index.
66 const BRepMesh_Vertex& GetNode(const Standard_Integer theIndex)
68 return myNodes->FindKey(theIndex);
71 //! Alias for GetNode.
72 const BRepMesh_Vertex& operator ()(const Standard_Integer theIndex)
74 return GetNode(theIndex);
77 //! Substitutes the node with the given index by new one.
78 //! @param theIndex index of node to be substituted.
79 //! @param theNewNode substituting node.
80 //! @return FALSE in case if new node is already in the structure, TRUE elsewhere.
81 Standard_EXPORT Standard_Boolean SubstituteNode(
82 const Standard_Integer theIndex,
83 const BRepMesh_Vertex& theNewNode);
85 //! Removes node from the mesh in case if it has no connected links
86 //! and its type is Free.
87 //! @param theIndex index of node to be removed.
88 //! @param isForce if TRUE node will be removed even if movability
90 void RemoveNode(const Standard_Integer theIndex,
91 const Standard_Boolean isForce = Standard_False)
93 if (isForce || myNodes->FindKey(theIndex).Movability() == BRepMesh_Free)
95 if (LinksConnectedTo(theIndex).Extent()==0)
96 myNodes->DeleteVertex(theIndex);
100 //! Get list of links attached to the node with the given index.
101 //! @param theIndex index of node whose links should be retrieved.
102 //! @return list of links attached to the node.
103 const IMeshData::ListOfInteger& LinksConnectedTo(
104 const Standard_Integer theIndex) const
106 return linksConnectedTo(theIndex);
110 public: //! @name API for accessing mesh links.
112 //! Returns number of links.
113 Standard_Integer NbLinks() const
115 return myLinks.Extent();
118 //! Adds link to the mesh if it is not already in the mesh.
119 //! @param theLink link to be added to the mesh.
120 //! @return index of the link in the structure.
121 Standard_EXPORT Standard_Integer AddLink(const BRepMesh_Edge& theLink);
123 //! Finds the index of the given link.
124 //! @param theLink link to find.
125 //! @return index of the given element of zero if link is not in the mesh.
126 Standard_Integer IndexOf(const BRepMesh_Edge& theLink) const
128 return myLinks.FindIndex(theLink);
131 //! Get link by the index.
132 //! @param theIndex index of a link.
133 //! @return link with the given index.
134 const BRepMesh_Edge& GetLink(const Standard_Integer theIndex)
136 return myLinks.FindKey(theIndex);
139 //! Returns map of indices of links registered in mesh.
140 const IMeshData::MapOfInteger& LinksOfDomain() const
142 return myLinksOfDomain;
145 //! Substitutes the link with the given index by new one.
146 //! @param theIndex index of link to be substituted.
147 //! @param theNewLink substituting link.
148 //! @return FALSE in case if new link is already in the structure, TRUE elsewhere.
149 Standard_EXPORT Standard_Boolean SubstituteLink(const Standard_Integer theIndex,
150 const BRepMesh_Edge& theNewLink);
152 //! Removes link from the mesh in case if it has no connected elements
153 //! and its type is Free.
154 //! @param theIndex index of link to be removed.
155 //! @param isForce if TRUE link will be removed even if movability
157 Standard_EXPORT void RemoveLink(const Standard_Integer theIndex,
158 const Standard_Boolean isForce = Standard_False);
160 //! Returns indices of elements connected to the link with the given index.
161 //! @param theLinkIndex index of link whose data should be retrieved.
162 //! @return indices of elements connected to the link.
163 const BRepMesh_PairOfIndex& ElementsConnectedTo(
164 const Standard_Integer theLinkIndex) const
166 return myLinks.FindFromIndex(theLinkIndex);
171 public: //! @name API for accessing mesh elements.
173 //! Returns number of links.
174 Standard_Integer NbElements() const
176 return myElements.Size();
179 //! Adds element to the mesh if it is not already in the mesh.
180 //! @param theElement element to be added to the mesh.
181 //! @return index of the element in the structure.
182 Standard_EXPORT Standard_Integer AddElement(const BRepMesh_Triangle& theElement);
184 //! Get element by the index.
185 //! @param theIndex index of an element.
186 //! @return element with the given index.
187 const BRepMesh_Triangle& GetElement(const Standard_Integer theIndex)
189 return myElements.ChangeValue(theIndex - 1);
192 //! Returns map of indices of elements registered in mesh.
193 const IMeshData::MapOfInteger& ElementsOfDomain() const
195 return myElementsOfDomain;
198 //! Substitutes the element with the given index by new one.
199 //! @param theIndex index of element to be substituted.
200 //! @param theNewLink substituting element.
201 //! @return FALSE in case if new element is already in the structure, TRUE elsewhere.
202 Standard_EXPORT Standard_Boolean SubstituteElement(const Standard_Integer theIndex,
203 const BRepMesh_Triangle& theNewElement);
205 //! Removes element from the mesh.
206 //! @param theIndex index of element to be removed.
207 Standard_EXPORT void RemoveElement(const Standard_Integer theIndex);
209 //! Returns indices of nodes forming the given element.
210 //! @param theElement element which nodes should be retrieved.
211 //! @param[out] theNodes nodes of the given element.
212 Standard_EXPORT void ElementNodes(
213 const BRepMesh_Triangle& theElement,
214 Standard_Integer (&theNodes)[3]);
216 Standard_EXPORT void Dump(Standard_CString theFileNameStr);
220 public: //! @name Auxiliary API
222 //! Dumps information about this structure.
223 //! @param theStream stream to be used for dump.
224 Standard_EXPORT void Statistics(Standard_OStream& theStream) const;
226 //! Returns memory allocator used by the structure.
227 const Handle(NCollection_IncAllocator)& Allocator() const
232 //! Gives the data structure for initialization of cell size and tolerance.
233 const Handle(BRepMesh_VertexTool)& Data()
238 //! Removes all elements.
239 Standard_EXPORT void ClearDomain();
241 //! Substitutes deleted items by the last one from corresponding map
242 //! to have only non-deleted elements, links or nodes in the structure.
249 DEFINE_STANDARD_RTTIEXT(BRepMesh_DataStructureOfDelaun, Standard_Transient)
253 //! Get list of links attached to the node with the given index.
254 //! @param theIndex index of node whose links should be retrieved.
255 //! @return list of links attached to the node.
256 IMeshData::ListOfInteger& linksConnectedTo(
257 const Standard_Integer theIndex) const
259 return (IMeshData::ListOfInteger&)myNodeLinks.Find(theIndex);
262 //! Substitutes deleted links by the last one from corresponding map
263 //! to have only non-deleted links in the structure.
264 Standard_EXPORT void clearDeletedLinks();
266 //! Substitutes deleted nodes by the last one from corresponding map
267 //! to have only non-deleted nodes in the structure.
268 Standard_EXPORT void clearDeletedNodes();
270 //! Cleans dependent structures from the given link.
271 //! @param theIndex index of link in the data structure.
272 //! @param theLink reference to the link to avoid double accessing
274 void cleanLink(const Standard_Integer theIndex,
275 const BRepMesh_Edge& theLink);
277 //! Cleans dependent structures from the given element.
278 //! @param theIndex index of element in the data structure.
279 //! @param theElement reference to the element to avoid double accessing
280 //! to map of elements.
281 void cleanElement(const Standard_Integer theIndex,
282 const BRepMesh_Triangle& theElement);
284 //! Removes element index from the given pair. Used by cleanElement.
285 //! @param theIndex index of element to be removed.
286 //! @param thePair pair of elements to be cleaned.
287 void removeElementIndex(const Standard_Integer theIndex,
288 BRepMesh_PairOfIndex& thePair);
293 Handle(NCollection_IncAllocator) myAllocator;
294 Handle(BRepMesh_VertexTool) myNodes;
295 IMeshData::DMapOfIntegerListOfInteger myNodeLinks;
296 IMeshData::IDMapOfLink myLinks;
297 IMeshData::ListOfInteger myDelLinks;
298 IMeshData::VectorOfElements myElements;
299 IMeshData::MapOfInteger myElementsOfDomain;
300 IMeshData::MapOfInteger myLinksOfDomain;