Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1993-05-11 |
2 | // Created by: Didier PIFFAULT | |
3 | // Copyright (c) 1993-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
0d88155b | 16 | |
fc9b36d6 | 17 | #include <BRepMesh_DataStructureOfDelaun.hxx> |
fc9b36d6 | 18 | #include <BRepBuilderAPI_MakeEdge.hxx> |
2caff0b3 | 19 | #include <BRepBuilderAPI_MakeVertex.hxx> |
7bd071ed | 20 | #include <BRepMesh_Edge.hxx> |
fc9b36d6 | 21 | |
22 | #include <TopoDS_Compound.hxx> | |
23 | #include <BRep_Builder.hxx> | |
24 | #include <BRepTools.hxx> | |
25 | #include <Standard_ErrorHandler.hxx> | |
26 | ||
0d88155b O |
27 | //======================================================================= |
28 | //function : BRepMesh_DataStructureOfDelaun | |
29 | //purpose : | |
30 | //======================================================================= | |
fc9b36d6 | 31 | BRepMesh_DataStructureOfDelaun::BRepMesh_DataStructureOfDelaun( |
848fa7e3 | 32 | const Handle(NCollection_IncAllocator)& theAllocator, |
33 | const Standard_Integer theReservedNodeSize) | |
2caff0b3 | 34 | : myAllocator (theAllocator), |
e1c1b6b9 | 35 | myNodes (new BRepMesh_VertexTool(myAllocator)), |
36 | myNodeLinks (theReservedNodeSize * 3, myAllocator), | |
2caff0b3 | 37 | myLinks (theReservedNodeSize * 3, myAllocator), |
38 | myDelLinks (myAllocator), | |
7bd071ed | 39 | myElements (theReservedNodeSize * 2, myAllocator) |
0d88155b | 40 | { |
0d88155b O |
41 | } |
42 | ||
2caff0b3 | 43 | //======================================================================= |
44 | //function : SubstituteNode | |
45 | //purpose : | |
46 | //======================================================================= | |
47 | Standard_Integer BRepMesh_DataStructureOfDelaun::AddNode( | |
48 | const BRepMesh_Vertex& theNode, | |
49 | const Standard_Boolean isForceAdd) | |
50 | { | |
51 | const Standard_Integer aNodeId = myNodes->Add(theNode, isForceAdd); | |
52 | if (!myNodeLinks.IsBound(aNodeId)) | |
7bd071ed | 53 | myNodeLinks.Bind(aNodeId, IMeshData::ListOfInteger(myAllocator)); |
2caff0b3 | 54 | |
55 | return aNodeId; | |
56 | } | |
57 | ||
0d88155b | 58 | //======================================================================= |
fc9b36d6 | 59 | //function : SubstituteNode |
0d88155b O |
60 | //purpose : |
61 | //======================================================================= | |
fc9b36d6 | 62 | Standard_Boolean BRepMesh_DataStructureOfDelaun::SubstituteNode( |
63 | const Standard_Integer theIndex, | |
64 | const BRepMesh_Vertex& theNewNode) | |
0d88155b | 65 | { |
2caff0b3 | 66 | if (myNodes->FindIndex(theNewNode) != 0) |
fc9b36d6 | 67 | return Standard_False; |
0d88155b | 68 | |
2caff0b3 | 69 | myNodes->Substitute(theIndex, theNewNode); |
fc9b36d6 | 70 | return Standard_True; |
0d88155b O |
71 | } |
72 | ||
73 | //======================================================================= | |
fc9b36d6 | 74 | //function : AddLink |
0d88155b O |
75 | //purpose : |
76 | //======================================================================= | |
fc9b36d6 | 77 | Standard_Integer BRepMesh_DataStructureOfDelaun::AddLink( |
78 | const BRepMesh_Edge& theLink) | |
0d88155b | 79 | { |
fc9b36d6 | 80 | Standard_Integer aLinkIndex = IndexOf(theLink); |
81 | if (aLinkIndex > 0) | |
82 | { | |
83 | return theLink.IsSameOrientation(GetLink(aLinkIndex)) ? | |
84 | aLinkIndex : -aLinkIndex; | |
85 | } | |
0d88155b | 86 | |
fc9b36d6 | 87 | BRepMesh_PairOfIndex aPair; |
88 | if (!myDelLinks.IsEmpty()) | |
89 | { | |
90 | aLinkIndex = myDelLinks.First(); | |
91 | myLinks.Substitute(aLinkIndex, theLink, aPair); | |
92 | myDelLinks.RemoveFirst(); | |
0d88155b | 93 | } |
fc9b36d6 | 94 | else |
95 | aLinkIndex = myLinks.Add(theLink, aPair); | |
0d88155b | 96 | |
fc9b36d6 | 97 | const Standard_Integer aLinkId = Abs(aLinkIndex); |
2caff0b3 | 98 | linksConnectedTo(theLink.FirstNode()).Append(aLinkId); |
99 | linksConnectedTo(theLink.LastNode() ).Append(aLinkId); | |
fc9b36d6 | 100 | myLinksOfDomain.Add(aLinkIndex); |
0d88155b | 101 | |
fc9b36d6 | 102 | return aLinkIndex; |
0d88155b O |
103 | } |
104 | ||
105 | //======================================================================= | |
fc9b36d6 | 106 | //function : SubstituteLink |
0d88155b O |
107 | //purpose : |
108 | //======================================================================= | |
fc9b36d6 | 109 | Standard_Boolean BRepMesh_DataStructureOfDelaun::SubstituteLink( |
110 | const Standard_Integer theIndex, | |
111 | const BRepMesh_Edge& theNewLink) | |
0d88155b | 112 | { |
fc9b36d6 | 113 | BRepMesh_PairOfIndex aPair; |
114 | BRepMesh_Edge aLink = GetLink(theIndex); | |
115 | if (aLink.Movability() == BRepMesh_Deleted) | |
116 | { | |
117 | myLinks.Substitute(theIndex, theNewLink, aPair); | |
118 | return Standard_True; | |
0d88155b | 119 | } |
0d88155b | 120 | |
fc9b36d6 | 121 | if (IndexOf(theNewLink) != 0) |
122 | return Standard_False; | |
0d88155b | 123 | |
fc9b36d6 | 124 | aLink.SetMovability(BRepMesh_Deleted); |
125 | myLinks.Substitute(theIndex, aLink, aPair); | |
126 | cleanLink(theIndex, aLink); | |
0d88155b | 127 | |
fc9b36d6 | 128 | const Standard_Integer aLinkId = Abs(theIndex); |
2caff0b3 | 129 | linksConnectedTo(theNewLink.FirstNode()).Append(aLinkId); |
130 | linksConnectedTo(theNewLink.LastNode() ).Append(aLinkId); | |
fc9b36d6 | 131 | myLinks.Substitute(theIndex, theNewLink, aPair); |
132 | ||
133 | return Standard_True; | |
0d88155b O |
134 | } |
135 | ||
136 | //======================================================================= | |
fc9b36d6 | 137 | //function : ForceRemoveLink |
0d88155b O |
138 | //purpose : |
139 | //======================================================================= | |
fc9b36d6 | 140 | void BRepMesh_DataStructureOfDelaun::RemoveLink( |
141 | const Standard_Integer theIndex, | |
142 | const Standard_Boolean isForce) | |
0d88155b | 143 | { |
fc9b36d6 | 144 | BRepMesh_Edge& aLink = (BRepMesh_Edge&)GetLink(theIndex); |
145 | if (aLink.Movability() == BRepMesh_Deleted || | |
146 | (!isForce && aLink.Movability() != BRepMesh_Free) || | |
147 | ElementsConnectedTo(theIndex).Extent() != 0) | |
148 | { | |
149 | return; | |
0d88155b | 150 | } |
0d88155b | 151 | |
fc9b36d6 | 152 | cleanLink(theIndex, aLink); |
153 | aLink.SetMovability(BRepMesh_Deleted); | |
0d88155b | 154 | |
fc9b36d6 | 155 | myLinksOfDomain.Remove(theIndex); |
156 | myDelLinks.Append (theIndex); | |
0d88155b O |
157 | } |
158 | ||
159 | //======================================================================= | |
fc9b36d6 | 160 | //function : cleanLink |
0d88155b O |
161 | //purpose : |
162 | //======================================================================= | |
fc9b36d6 | 163 | void BRepMesh_DataStructureOfDelaun::cleanLink( |
164 | const Standard_Integer theIndex, | |
165 | const BRepMesh_Edge& theLink) | |
0d88155b | 166 | { |
fc9b36d6 | 167 | for (Standard_Integer i = 0; i < 2; ++i) |
168 | { | |
169 | const Standard_Integer aNodeId = (i == 0) ? | |
170 | theLink.FirstNode() : theLink.LastNode(); | |
0d88155b | 171 | |
7bd071ed | 172 | IMeshData::ListOfInteger& aLinkList = linksConnectedTo(aNodeId); |
173 | IMeshData::ListOfInteger::Iterator aLinkIt(aLinkList); | |
fc9b36d6 | 174 | for(; aLinkIt.More(); aLinkIt.Next()) |
175 | { | |
176 | if (aLinkIt.Value() == theIndex) | |
177 | { | |
178 | aLinkList.Remove(aLinkIt); | |
0d88155b O |
179 | break; |
180 | } | |
181 | } | |
0d88155b | 182 | } |
0d88155b O |
183 | } |
184 | ||
185 | //======================================================================= | |
186 | //function : AddElement | |
187 | //purpose : | |
188 | //======================================================================= | |
fc9b36d6 | 189 | Standard_Integer BRepMesh_DataStructureOfDelaun::AddElement( |
190 | const BRepMesh_Triangle& theElement) | |
0d88155b | 191 | { |
7bd071ed | 192 | myElements.Append(theElement); |
193 | Standard_Integer aElementIndex = myElements.Size(); | |
fc9b36d6 | 194 | myElementsOfDomain.Add(aElementIndex); |
0d88155b | 195 | |
7bd071ed | 196 | const Standard_Integer (&e)[3] = theElement.myEdges; |
fc9b36d6 | 197 | for (Standard_Integer i = 0; i < 3; ++i) |
198 | myLinks(e[i]).Append(aElementIndex); | |
0d88155b | 199 | |
fc9b36d6 | 200 | return aElementIndex; |
0d88155b O |
201 | } |
202 | ||
203 | //======================================================================= | |
fc9b36d6 | 204 | //function : RemoveElement |
0d88155b O |
205 | //purpose : |
206 | //======================================================================= | |
fc9b36d6 | 207 | void BRepMesh_DataStructureOfDelaun::RemoveElement( |
208 | const Standard_Integer theIndex) | |
0d88155b | 209 | { |
fc9b36d6 | 210 | BRepMesh_Triangle& aElement = (BRepMesh_Triangle&)GetElement(theIndex); |
211 | if (aElement.Movability() == BRepMesh_Deleted) | |
212 | return; | |
213 | ||
214 | cleanElement(theIndex, aElement); | |
215 | aElement.SetMovability(BRepMesh_Deleted); | |
216 | myElementsOfDomain.Remove(theIndex); | |
0d88155b O |
217 | } |
218 | ||
219 | //======================================================================= | |
fc9b36d6 | 220 | //function : cleanElement |
0d88155b O |
221 | //purpose : |
222 | //======================================================================= | |
fc9b36d6 | 223 | void BRepMesh_DataStructureOfDelaun::cleanElement( |
224 | const Standard_Integer theIndex, | |
225 | const BRepMesh_Triangle& theElement) | |
0d88155b | 226 | { |
fc9b36d6 | 227 | if (theElement.Movability() != BRepMesh_Free) |
228 | return; | |
0d88155b | 229 | |
7bd071ed | 230 | const Standard_Integer(&e)[3] = theElement.myEdges; |
fc9b36d6 | 231 | for (Standard_Integer i = 0; i < 3; ++i) |
232 | removeElementIndex(theIndex, myLinks(e[i])); | |
0d88155b O |
233 | } |
234 | ||
235 | //======================================================================= | |
fc9b36d6 | 236 | //function : removeElementIndex |
0d88155b O |
237 | //purpose : |
238 | //======================================================================= | |
fc9b36d6 | 239 | void BRepMesh_DataStructureOfDelaun::removeElementIndex( |
240 | const Standard_Integer theIndex, | |
241 | BRepMesh_PairOfIndex& thePair) | |
0d88155b | 242 | { |
fc9b36d6 | 243 | for (Standard_Integer i = 1, n = thePair.Extent(); i <= n; ++i) |
244 | { | |
245 | if (thePair.Index(i) == theIndex) | |
246 | { | |
247 | thePair.RemoveIndex(i); | |
248 | return; | |
0d88155b | 249 | } |
0d88155b | 250 | } |
0d88155b O |
251 | } |
252 | ||
253 | //======================================================================= | |
fc9b36d6 | 254 | //function : SubstituteElement |
0d88155b O |
255 | //purpose : |
256 | //======================================================================= | |
fc9b36d6 | 257 | Standard_Boolean BRepMesh_DataStructureOfDelaun::SubstituteElement( |
258 | const Standard_Integer theIndex, | |
259 | const BRepMesh_Triangle& theNewElement) | |
0d88155b | 260 | { |
fc9b36d6 | 261 | const BRepMesh_Triangle& aElement = GetElement(theIndex); |
262 | if (aElement.Movability() == BRepMesh_Deleted) | |
263 | { | |
7bd071ed | 264 | myElements(theIndex) = theNewElement; |
fc9b36d6 | 265 | return Standard_True; |
0d88155b | 266 | } |
0d88155b | 267 | |
fc9b36d6 | 268 | cleanElement(theIndex, aElement); |
269 | // Warning: here new element and old element should have different Hash code | |
7bd071ed | 270 | myElements(theIndex) = theNewElement; |
0d88155b | 271 | |
7bd071ed | 272 | const Standard_Integer(&e)[3] = theNewElement.myEdges; |
fc9b36d6 | 273 | for (Standard_Integer i = 0; i < 3; ++i) |
274 | myLinks(e[i]).Append(theIndex); | |
0d88155b | 275 | |
fc9b36d6 | 276 | return Standard_True; |
0d88155b O |
277 | } |
278 | ||
279 | //======================================================================= | |
fc9b36d6 | 280 | //function : ElementNodes |
281 | //purpose : | |
0d88155b | 282 | //======================================================================= |
fc9b36d6 | 283 | void BRepMesh_DataStructureOfDelaun::ElementNodes( |
284 | const BRepMesh_Triangle& theElement, | |
285 | Standard_Integer (&theNodes)[3]) | |
0d88155b | 286 | { |
7bd071ed | 287 | const Standard_Integer(&e)[3] = theElement.myEdges; |
288 | const Standard_Boolean(&o)[3] = theElement.myOrientations; | |
0d88155b | 289 | |
fc9b36d6 | 290 | const BRepMesh_Edge& aLink1 = GetLink(e[0]); |
291 | if (o[0]) | |
292 | { | |
293 | theNodes[0] = aLink1.FirstNode(); | |
294 | theNodes[1] = aLink1.LastNode(); | |
295 | } | |
296 | else | |
297 | { | |
298 | theNodes[1] = aLink1.FirstNode(); | |
299 | theNodes[0] = aLink1.LastNode(); | |
300 | } | |
301 | ||
302 | const BRepMesh_Edge& aLink2 = GetLink(e[2]); | |
303 | if (o[2]) | |
304 | theNodes[2] = aLink2.FirstNode(); | |
305 | else | |
306 | theNodes[2] = aLink2.LastNode(); | |
0d88155b O |
307 | } |
308 | ||
309 | //======================================================================= | |
fc9b36d6 | 310 | //function : ClearDomain |
0d88155b O |
311 | //purpose : |
312 | //======================================================================= | |
fc9b36d6 | 313 | void BRepMesh_DataStructureOfDelaun::ClearDomain() |
0d88155b | 314 | { |
7bd071ed | 315 | IMeshData::MapOfInteger aFreeEdges; |
316 | IMeshData::IteratorOfMapOfInteger aElementIt(myElementsOfDomain); | |
fc9b36d6 | 317 | for (; aElementIt.More(); aElementIt.Next()) |
318 | { | |
319 | const Standard_Integer aElementId = aElementIt.Key(); | |
320 | BRepMesh_Triangle& aElement = (BRepMesh_Triangle&)GetElement(aElementId); | |
0d88155b | 321 | |
7bd071ed | 322 | const Standard_Integer(&e)[3] = aElement.myEdges; |
fc9b36d6 | 323 | |
324 | for (Standard_Integer i = 0; i < 3; ++i) | |
325 | aFreeEdges.Add(e[i]); | |
326 | ||
327 | cleanElement(aElementId, aElement); | |
328 | aElement.SetMovability(BRepMesh_Deleted); | |
329 | } | |
330 | myElementsOfDomain.Clear(); | |
331 | ||
7bd071ed | 332 | IMeshData::IteratorOfMapOfInteger aEdgeIt(aFreeEdges); |
fc9b36d6 | 333 | for (; aEdgeIt.More(); aEdgeIt.Next()) |
334 | RemoveLink(aEdgeIt.Key()); | |
0d88155b O |
335 | } |
336 | ||
337 | //======================================================================= | |
fc9b36d6 | 338 | //function : clearDeletedLinks |
0d88155b O |
339 | //purpose : |
340 | //======================================================================= | |
fc9b36d6 | 341 | void BRepMesh_DataStructureOfDelaun::clearDeletedLinks() |
0d88155b | 342 | { |
fc9b36d6 | 343 | Standard_Integer aLastLiveItem = NbLinks(); |
344 | while (!myDelLinks.IsEmpty()) | |
345 | { | |
346 | while (aLastLiveItem > 0) | |
347 | { | |
348 | if (GetLink(aLastLiveItem).Movability() != BRepMesh_Deleted) | |
0d88155b | 349 | break; |
fc9b36d6 | 350 | |
0d88155b | 351 | myLinks.RemoveLast(); |
fc9b36d6 | 352 | --aLastLiveItem; |
0d88155b O |
353 | } |
354 | ||
fc9b36d6 | 355 | Standard_Integer aDelItem = myDelLinks.First(); |
0d88155b O |
356 | myDelLinks.RemoveFirst(); |
357 | ||
fc9b36d6 | 358 | if (aDelItem > aLastLiveItem) |
359 | continue; | |
360 | ||
361 | BRepMesh_Edge aLink = GetLink(aLastLiveItem); | |
362 | BRepMesh_PairOfIndex& aPair = myLinks(aLastLiveItem); | |
363 | ||
364 | myLinks.RemoveLast(); | |
365 | myLinks.Substitute(aDelItem, aLink, aPair); | |
366 | ||
367 | myLinksOfDomain.Remove(aLastLiveItem); | |
368 | myLinksOfDomain.Add(aDelItem); | |
369 | --aLastLiveItem; | |
370 | ||
371 | const Standard_Integer aLastLiveItemId = aLastLiveItem + 1; | |
7bd071ed | 372 | IMeshData::ListOfInteger::Iterator aLinkIt; |
fc9b36d6 | 373 | // update link references |
374 | for (Standard_Integer i = 0; i < 2; ++i) | |
375 | { | |
376 | const Standard_Integer aCurNodeId = (i == 0) ? | |
377 | aLink.FirstNode() : aLink.LastNode(); | |
378 | ||
2caff0b3 | 379 | for (aLinkIt.Init(linksConnectedTo(aCurNodeId)); aLinkIt.More(); aLinkIt.Next()) |
fc9b36d6 | 380 | { |
381 | Standard_Integer& aLinkId = aLinkIt.ChangeValue(); | |
382 | if (aLinkId == aLastLiveItemId) | |
383 | { | |
384 | aLinkId = aDelItem; | |
385 | break; | |
0d88155b O |
386 | } |
387 | } | |
fc9b36d6 | 388 | } |
389 | ||
390 | // update elements references | |
391 | for(Standard_Integer j = 1, jn = aPair.Extent(); j <= jn; ++j) | |
392 | { | |
fc9b36d6 | 393 | Standard_Integer e[3]; |
394 | Standard_Boolean o[3]; | |
7bd071ed | 395 | const BRepMesh_Triangle& aElement = GetElement(aPair.Index(j)); |
fc9b36d6 | 396 | aElement.Edges(e, o); |
397 | for (Standard_Integer i = 0; i < 3; ++i) | |
398 | { | |
399 | if (e[i] == aLastLiveItemId) | |
400 | { | |
401 | e[i] = aDelItem; | |
402 | break; | |
0d88155b | 403 | } |
0d88155b | 404 | } |
fc9b36d6 | 405 | |
7bd071ed | 406 | myElements(aLinkIt.Value()) = BRepMesh_Triangle(e, o, aElement.Movability()); |
0d88155b O |
407 | } |
408 | } | |
fc9b36d6 | 409 | } |
0d88155b | 410 | |
fc9b36d6 | 411 | //======================================================================= |
412 | //function : clearDeletedNodes | |
413 | //purpose : | |
414 | //======================================================================= | |
415 | void BRepMesh_DataStructureOfDelaun::clearDeletedNodes() | |
416 | { | |
7bd071ed | 417 | IMeshData::ListOfInteger& aDelNodes = |
418 | (IMeshData::ListOfInteger&)myNodes->GetListOfDelNodes(); | |
0d88155b | 419 | |
fc9b36d6 | 420 | Standard_Integer aLastLiveItem = NbNodes(); |
421 | while (!aDelNodes.IsEmpty()) | |
422 | { | |
423 | while (aLastLiveItem > 0) | |
424 | { | |
425 | if (GetNode(aLastLiveItem).Movability() != BRepMesh_Deleted) | |
0d88155b | 426 | break; |
fc9b36d6 | 427 | |
2caff0b3 | 428 | myNodes->RemoveLast(); |
fc9b36d6 | 429 | --aLastLiveItem; |
0d88155b | 430 | } |
fc9b36d6 | 431 | |
432 | Standard_Integer aDelItem = aDelNodes.First(); | |
51c3cc5f | 433 | aDelNodes.RemoveFirst(); |
0d88155b | 434 | |
fc9b36d6 | 435 | if (aDelItem > aLastLiveItem) |
436 | continue; | |
437 | ||
438 | BRepMesh_Vertex aNode = GetNode(aLastLiveItem); | |
7bd071ed | 439 | IMeshData::ListOfInteger& aLinkList = linksConnectedTo(aLastLiveItem); |
fc9b36d6 | 440 | |
2caff0b3 | 441 | myNodes->RemoveLast(); |
fc9b36d6 | 442 | --aLastLiveItem; |
443 | ||
2caff0b3 | 444 | myNodes->Substitute(aDelItem, aNode); |
445 | myNodeLinks.ChangeFind(aDelItem) = aLinkList; | |
fc9b36d6 | 446 | |
447 | const Standard_Integer aLastLiveItemId = aLastLiveItem + 1; | |
7bd071ed | 448 | IMeshData::ListOfInteger::Iterator aLinkIt(aLinkList); |
fc9b36d6 | 449 | for (; aLinkIt.More(); aLinkIt.Next()) |
450 | { | |
451 | const Standard_Integer aLinkId = aLinkIt.Value(); | |
452 | const BRepMesh_Edge& aLink = GetLink(aLinkId); | |
453 | BRepMesh_PairOfIndex& aPair = myLinks(aLinkId); | |
454 | ||
455 | Standard_Integer v[2] = { aLink.FirstNode(), aLink.LastNode() }; | |
456 | if (v[0] == aLastLiveItemId) | |
457 | v[0] = aDelItem; | |
458 | else if (v[1] == aLastLiveItemId) | |
459 | v[1] = aDelItem; | |
460 | ||
461 | myLinks.Substitute(aLinkId, | |
462 | BRepMesh_Edge(v[0], v[1], aLink.Movability()), aPair); | |
0d88155b O |
463 | } |
464 | } | |
465 | } | |
466 | ||
467 | //======================================================================= | |
468 | //function : Statistics | |
469 | //purpose : | |
470 | //======================================================================= | |
fc9b36d6 | 471 | void BRepMesh_DataStructureOfDelaun::Statistics(Standard_OStream& theStream) const |
0d88155b | 472 | { |
fc9b36d6 | 473 | theStream << " Map of nodes : \n"; |
2caff0b3 | 474 | myNodes->Statistics(theStream); |
04232180 | 475 | theStream << "\n Deleted nodes : " << myNodes->GetListOfDelNodes().Extent() << std::endl; |
0d88155b | 476 | |
fc9b36d6 | 477 | theStream << "\n\n Map of Links : \n"; |
478 | myLinks.Statistics(theStream); | |
04232180 | 479 | theStream << "\n Deleted links : " << myDelLinks.Extent() << std::endl; |
0d88155b | 480 | |
fc9b36d6 | 481 | theStream << "\n\n Map of elements : \n"; |
04232180 | 482 | theStream << "\n Elements : " << myElements.Size() << std::endl; |
0d88155b O |
483 | } |
484 | ||
485 | //======================================================================= | |
fc9b36d6 | 486 | //function : BRepMesh_Write |
0d88155b | 487 | //purpose : |
fc9b36d6 | 488 | // Global function not declared in any public header, intended for use |
489 | // from debugger prompt (Command Window in Visual Studio). | |
490 | // | |
491 | // Stores the mesh data structure to BRep file with the given name. | |
0d88155b | 492 | //======================================================================= |
fc9b36d6 | 493 | Standard_CString BRepMesh_Dump(void* theMeshHandlePtr, |
494 | Standard_CString theFileNameStr) | |
0d88155b | 495 | { |
fc9b36d6 | 496 | if (theMeshHandlePtr == 0 || theFileNameStr == 0) |
497 | { | |
498 | return "Error: file name or mesh data is null"; | |
499 | } | |
51c3cc5f | 500 | |
7bd071ed | 501 | Handle(BRepMesh_DataStructureOfDelaun) aMeshData = |
fc9b36d6 | 502 | *(Handle(BRepMesh_DataStructureOfDelaun)*)theMeshHandlePtr; |
503 | ||
504 | if (aMeshData.IsNull()) | |
505 | return "Error: mesh data is empty"; | |
506 | ||
507 | TopoDS_Compound aMesh; | |
508 | BRep_Builder aBuilder; | |
509 | aBuilder.MakeCompound(aMesh); | |
510 | ||
511 | try | |
512 | { | |
513 | OCC_CATCH_SIGNALS | |
514 | ||
2caff0b3 | 515 | if (aMeshData->LinksOfDomain().IsEmpty()) |
fc9b36d6 | 516 | { |
2caff0b3 | 517 | const Standard_Integer aNodesNb = aMeshData->NbNodes(); |
518 | for (Standard_Integer i = 1; i <= aNodesNb; ++i) | |
fc9b36d6 | 519 | { |
2caff0b3 | 520 | const gp_XY& aNode = aMeshData->GetNode(i).Coord(); |
521 | gp_Pnt aPnt(aNode.X(), aNode.Y(), 0.); | |
522 | aBuilder.Add(aMesh, BRepBuilderAPI_MakeVertex(aPnt)); | |
fc9b36d6 | 523 | } |
2caff0b3 | 524 | } |
525 | else | |
526 | { | |
7bd071ed | 527 | IMeshData::IteratorOfMapOfInteger aLinksIt(aMeshData->LinksOfDomain()); |
2caff0b3 | 528 | for (; aLinksIt.More(); aLinksIt.Next()) |
529 | { | |
7bd071ed | 530 | const BRepMesh_Edge& aLink = aMeshData->GetLink(aLinksIt.Key()); |
2caff0b3 | 531 | gp_Pnt aPnt[2]; |
532 | for (Standard_Integer i = 0; i < 2; ++i) | |
533 | { | |
534 | const Standard_Integer aNodeId = | |
535 | (i == 0) ? aLink.FirstNode() : aLink.LastNode(); | |
536 | ||
537 | const gp_XY& aNode = aMeshData->GetNode(aNodeId).Coord(); | |
538 | aPnt[i] = gp_Pnt(aNode.X(), aNode.Y(), 0.); | |
539 | } | |
fc9b36d6 | 540 | |
2caff0b3 | 541 | if (aPnt[0].SquareDistance(aPnt[1]) < Precision::SquareConfusion()) |
542 | continue; | |
fc9b36d6 | 543 | |
2caff0b3 | 544 | aBuilder.Add(aMesh, BRepBuilderAPI_MakeEdge(aPnt[0], aPnt[1])); |
545 | } | |
fc9b36d6 | 546 | } |
547 | ||
548 | if (!BRepTools::Write(aMesh, theFileNameStr)) | |
549 | return "Error: write failed"; | |
550 | } | |
9775fa61 | 551 | catch (Standard_Failure const& anException) |
fc9b36d6 | 552 | { |
9775fa61 | 553 | return anException.GetMessageString(); |
fc9b36d6 | 554 | } |
555 | ||
556 | return theFileNameStr; | |
51c3cc5f | 557 | } |
7bd071ed | 558 | |
559 | void BRepMesh_DataStructureOfDelaun::Dump(Standard_CString theFileNameStr) | |
560 | { | |
561 | Handle(BRepMesh_DataStructureOfDelaun) aMeshData (this); | |
562 | BRepMesh_Dump((void*)&aMeshData, theFileNameStr); | |
563 | } |