0032781: Coding - get rid of unused headers [BRepCheck to ChFiKPart]
[occt.git] / src / BRepMesh / BRepMesh_DataStructureOfDelaun.hxx
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_Transient.hxx>
18 #include <BRepMesh_VertexTool.hxx>
19
20 class BRepMesh_Edge;
21
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
25 {
26 public:
27
28   //! Constructor.
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);
34
35
36
37 public: //! @name API for accessing mesh nodes.
38
39   //! Returns number of nodes.
40   Standard_Integer NbNodes() const
41   {
42     return myNodes->Extent();
43   }
44
45
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);
54
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)
59   {
60     return myNodes->FindIndex(theNode);
61   }
62
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)
67   {
68     return myNodes->FindKey(theIndex);
69   }
70
71   //! Alias for GetNode.
72   const BRepMesh_Vertex& operator ()(const Standard_Integer theIndex)
73   {
74     return GetNode(theIndex);
75   }
76
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);
84
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
89   //! is not Free.
90   void RemoveNode(const Standard_Integer theIndex,
91                   const Standard_Boolean isForce = Standard_False)
92   {
93     if (isForce || myNodes->FindKey(theIndex).Movability() == BRepMesh_Free)
94     {
95       if (LinksConnectedTo(theIndex).Extent()==0)
96         myNodes->DeleteVertex(theIndex);
97     }
98   }
99
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
105   {
106     return linksConnectedTo(theIndex);
107   }
108
109
110 public: //! @name API for accessing mesh links.
111
112   //! Returns number of links.
113   Standard_Integer NbLinks() const
114   {
115     return myLinks.Extent();
116   }
117
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);
122
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
127   {
128     return myLinks.FindIndex(theLink);
129   }
130
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)
135   {
136     return myLinks.FindKey(theIndex);
137   }
138
139   //! Returns map of indices of links registered in mesh.
140   const IMeshData::MapOfInteger& LinksOfDomain() const
141   {
142     return myLinksOfDomain;
143   }
144
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);
151
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
156   //! is not Free.
157   Standard_EXPORT void RemoveLink(const Standard_Integer theIndex,
158                                   const Standard_Boolean isForce = Standard_False);
159
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
165   {
166     return myLinks.FindFromIndex(theLinkIndex);
167   }
168
169
170
171 public: //! @name API for accessing mesh elements.
172
173   //! Returns number of links.
174   Standard_Integer NbElements() const
175   {
176     return myElements.Size();
177   }
178
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);
183
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)
188   {
189     return myElements.ChangeValue(theIndex - 1);
190   }
191
192   //! Returns map of indices of elements registered in mesh.
193   const IMeshData::MapOfInteger& ElementsOfDomain() const
194   {
195     return myElementsOfDomain;
196   }
197
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);
204
205   //! Removes element from the mesh.
206   //! @param theIndex index of element to be removed.
207   Standard_EXPORT void RemoveElement(const Standard_Integer theIndex);
208
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]);
215
216   Standard_EXPORT void Dump(Standard_CString theFileNameStr);
217
218
219
220 public: //! @name Auxiliary API
221
222   //! Dumps information about this structure.
223   //! @param theStream stream to be used for dump.
224   Standard_EXPORT void Statistics(Standard_OStream& theStream) const;
225   
226   //! Returns memory allocator used by the structure.
227   const Handle(NCollection_IncAllocator)& Allocator() const
228   {
229     return myAllocator;
230   }
231
232   //! Gives the data structure for initialization of cell size and tolerance.
233   const Handle(BRepMesh_VertexTool)& Data()
234   {
235     return myNodes;
236   }
237
238   //! Removes all elements.
239   Standard_EXPORT void ClearDomain();
240
241   //! Substitutes deleted items by the last one from corresponding map 
242   //! to have only non-deleted elements, links or nodes in the structure.
243   void ClearDeleted()
244   {
245     clearDeletedLinks();
246     clearDeletedNodes();
247   }
248
249   DEFINE_STANDARD_RTTIEXT(BRepMesh_DataStructureOfDelaun, Standard_Transient)
250
251 private: 
252
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
258   {
259     return (IMeshData::ListOfInteger&)myNodeLinks.Find(theIndex);
260   }
261
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();
265
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();
269
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 
273   //! to map of links.
274   void cleanLink(const Standard_Integer theIndex,
275                  const BRepMesh_Edge&   theLink);
276
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);
283
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);
289
290
291 private:
292
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;
301 };
302
303 #endif