0022484: UNICODE characters support
[occt.git] / src / BRepMesh / BRepMesh_DataStructureOfDelaun.hxx
CommitLineData
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>
24#include <BRepMesh_Collections.hxx>
25
26class BRepMesh_Vertex;
27class BRepMesh_VertexTool;
28class 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.
32class BRepMesh_DataStructureOfDelaun : public Standard_Transient
33{
34public:
35
36 //! Constructor.
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 BRepMeshCol::Allocator& theAllocator,
41 const Standard_Integer theReservedNodeSize = 100);
42
43
44
45public: //! \name API for accessing mesh nodes.
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.
55 //! \param theNode node to be added to the mesh.
56 //! \return index of the node in the structure.
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.
63 //! \param theNode node to find.
64 //! \return index of the given element of zero if node is not in the mesh.
65 Standard_EXPORT Standard_Integer IndexOf(const BRepMesh_Vertex& theNode)
66 {
67 return myNodes.FindIndex(theNode);
68 }
69
70 //! Get node by the index.
71 //! \param theIndex index of a node.
72 //! \return node with the given index.
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.
85 //! \param theNewNodes nodes to be set instead of existing ones.
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.
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.
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.
104 //! \param theIndex index of node to be removed.
105 //! \param isForce if TRUE node will be removed even if movability
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.
118 //! \param theIndex index of node whose links should be retrieved.
119 //! \return list of links attached to the node.
120 inline const BRepMeshCol::ListOfInteger& LinksConnectedTo(
121 const Standard_Integer theIndex) const
122 {
123 return myNodes.FindFromIndex(theIndex);
124 }
125
126
127
128public: //! \name API for accessing mesh links.
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.
137 //! \param theLink link to be added to the mesh.
138 //! \return index of the link in the structure.
139 Standard_EXPORT Standard_Integer AddLink(const BRepMesh_Edge& theLink);
140
141 //! Finds the index of the given link.
142 //! \param theLink link to find.
143 //! \return index of the given element of zero if link is not in the mesh.
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.
150 //! \param theIndex index of a link.
151 //! \return link with the given index.
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.
158 inline const BRepMeshCol::MapOfInteger& LinksOfDomain() const
159 {
160 return myLinksOfDomain;
161 }
162
163 //! Substitutes the link with the given index by new one.
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.
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.
172 //! \param theIndex index of link to be removed.
173 //! \param isForce if TRUE link will be removed even if movability
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.
179 //! \param theLinkIndex index of link whose data should be retrieved.
180 //! \return indices of elements conected to the link.
181 Standard_EXPORT const BRepMesh_PairOfIndex& ElementsConnectedTo(
182 const Standard_Integer theLinkIndex) const
183 {
184 return myLinks.FindFromIndex(theLinkIndex);
185 }
186
187
188
189public: //! \name API for accessing mesh elements.
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.
198 //! \param theElement element to be added to the mesh.
199 //! \return index of the element in the structure.
200 Standard_EXPORT Standard_Integer AddElement(const BRepMesh_Triangle& theElement);
201
202 //! Finds the index of the given element.
203 //! \param theElement element to find.
204 //! \return index of the given element of zero if element is not in the mesh.
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.
211 //! \param theIndex index of an element.
212 //! \return element with the given index.
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.
219 inline const BRepMeshCol::MapOfInteger& ElementsOfDomain() const
220 {
221 return myElementsOfDomain;
222 }
223
224 //! Substitutes the element with the given index by new one.
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.
228 Standard_EXPORT Standard_Boolean SubstituteElement(const Standard_Integer theIndex,
229 const BRepMesh_Triangle& theNewElement);
230
231 //! Removes element from the mesh.
232 //! \param theIndex index of element to be removed.
233 Standard_EXPORT void RemoveElement(const Standard_Integer theIndex);
234
235 //! Returns indices of nodes forming the given element.
236 //! \param theElement element which nodes should be retrieved.
237 //! \param[out] theNodes nodes of the given element.
238 Standard_EXPORT void ElementNodes(
239 const BRepMesh_Triangle& theElement,
240 Standard_Integer (&theNodes)[3]);
241
242
243
244public: //! \name Auxilary API
245
246 //! Dumps information about this structure.
247 //! \param theStream stream to be used for dump.
248 Standard_EXPORT void Statistics(Standard_OStream& theStream) const;
249
250 //! Returns memory allocator used by the structure.
251 inline const BRepMeshCol::Allocator& Allocator() const
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
275private:
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.
286 //! \param theIndex index of link in the data structure.
287 //! \param theLink reference to the link to avoid double accessing
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.
293 //! \param theIndex index of element in the data structure.
294 //! \param theElement reference to the element to avoid double accessing
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.
300 //! \param theIndex index of element to be removed.
301 //! \param thePair pair of elements to be cleaned.
302 void removeElementIndex(const Standard_Integer theIndex,
303 BRepMesh_PairOfIndex& thePair);
304
305
306private:
307
308 BRepMesh_VertexTool myNodes;
309 BRepMeshCol::IDMapOfLink myLinks;
310 BRepMeshCol::ListOfInteger myDelLinks;
311 BRepMeshCol::IMapOfElement myElements;
312 BRepMeshCol::MapOfInteger myElementsOfDomain;
313 BRepMeshCol::MapOfInteger myLinksOfDomain;
314 BRepMeshCol::Allocator myAllocator;
315};
316
317DEFINE_STANDARD_HANDLE(BRepMesh_DataStructureOfDelaun,Standard_Transient)
318
319#endif