Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1995-06-20 |
2 | // Created by: Stagiaire Alain JOURDAIN | |
3 | // Copyright (c) 1995-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. | |
7fd59977 | 16 | |
9bdafcbe | 17 | #include <BRepMesh_IncrementalMesh.hxx> |
7fd59977 | 18 | |
fc9b36d6 | 19 | #include <Precision.hxx> |
ceb418e1 | 20 | #include <Standard_ErrorHandler.hxx> |
fc9b36d6 | 21 | |
22 | #include <BRepMesh_FaceChecker.hxx> | |
23 | #include <BRepMesh_ShapeTool.hxx> | |
7fd59977 | 24 | #include <BRepMesh_Edge.hxx> |
0b97567d | 25 | #include <BRepMesh_PluginMacro.hxx> |
7fd59977 | 26 | |
27 | #include <Bnd_Box.hxx> | |
28 | #include <BRep_Builder.hxx> | |
29 | #include <BRep_Tool.hxx> | |
9bdafcbe | 30 | #include <BRepTools.hxx> |
7fd59977 | 31 | #include <BRepLib.hxx> |
32 | #include <BRepBndLib.hxx> | |
33 | #include <BRepAdaptor_Curve.hxx> | |
fc9b36d6 | 34 | |
35 | #include <Poly_Triangulation.hxx> | |
36 | #include <Poly_Polygon3D.hxx> | |
37 | #include <Poly_PolygonOnTriangulation.hxx> | |
38 | ||
39 | #include <TopoDS.hxx> | |
40 | #include <TopoDS_Edge.hxx> | |
41 | #include <TopoDS_Face.hxx> | |
42 | #include <TopoDS_Shape.hxx> | |
43 | #include <TopAbs.hxx> | |
7fd59977 | 44 | #include <TopExp.hxx> |
45 | #include <TopExp_Explorer.hxx> | |
fc9b36d6 | 46 | |
7fd59977 | 47 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
48 | #include <TColgp_Array1OfPnt.hxx> | |
ceb418e1 | 49 | #include <TColgp_Array1OfPnt2d.hxx> |
7fd59977 | 50 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 | 51 | #include <TopTools_HArray1OfShape.hxx> |
ceb418e1 | 52 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
fc9b36d6 | 53 | |
54 | #include <GCPnts_TangentialDeflection.hxx> | |
7fd59977 | 55 | |
7fd59977 | 56 | #ifdef HAVE_TBB |
0b97567d K |
57 | // paralleling using Intel TBB |
58 | #include <tbb/parallel_for_each.h> | |
7fd59977 | 59 | #endif |
60 | ||
0b97567d K |
61 | namespace |
62 | { | |
63 | //! Default flag to control parallelization for BRepMesh_IncrementalMesh | |
64 | //! tool returned for Mesh Factory | |
65 | static Standard_Boolean IS_IN_PARALLEL = Standard_False; | |
66 | }; | |
67 | ||
9bdafcbe | 68 | IMPLEMENT_STANDARD_HANDLE (BRepMesh_IncrementalMesh, BRepMesh_DiscretRoot) |
69 | IMPLEMENT_STANDARD_RTTIEXT(BRepMesh_IncrementalMesh, BRepMesh_DiscretRoot) | |
70 | ||
71 | //======================================================================= | |
fc9b36d6 | 72 | //function : Default constructor |
9bdafcbe | 73 | //purpose : |
74 | //======================================================================= | |
fc9b36d6 | 75 | BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh() |
0b97567d | 76 | : myRelative (Standard_False), |
9bdafcbe | 77 | myInParallel (Standard_False) |
7fd59977 | 78 | { |
7fd59977 | 79 | } |
80 | ||
81 | //======================================================================= | |
fc9b36d6 | 82 | //function : Constructor |
7fd59977 | 83 | //purpose : |
84 | //======================================================================= | |
fc9b36d6 | 85 | BRepMesh_IncrementalMesh::BRepMesh_IncrementalMesh( |
86 | const TopoDS_Shape& theShape, | |
14434f3e | 87 | const Standard_Real theLinDeflection, |
88 | const Standard_Boolean isRelative, | |
89 | const Standard_Real theAngDeflection, | |
90 | const Standard_Boolean isInParallel) | |
91 | : myRelative (isRelative), | |
92 | myInParallel(isInParallel) | |
7fd59977 | 93 | { |
ceb418e1 | 94 | myDeflection = theLinDeflection; |
95 | myAngle = theAngDeflection; | |
96 | myShape = theShape; | |
97 | ||
0b97567d | 98 | Perform(); |
7fd59977 | 99 | } |
100 | ||
101 | //======================================================================= | |
fc9b36d6 | 102 | //function : Destructor |
7fd59977 | 103 | //purpose : |
104 | //======================================================================= | |
fc9b36d6 | 105 | BRepMesh_IncrementalMesh::~BRepMesh_IncrementalMesh() |
7fd59977 | 106 | { |
107 | } | |
108 | ||
2caff0b3 | 109 | //======================================================================= |
110 | //function : clear | |
111 | //purpose : | |
112 | //======================================================================= | |
113 | void BRepMesh_IncrementalMesh::clear() | |
114 | { | |
115 | myEmptyEdges.Clear(); | |
116 | myEdgeDeflection.Clear(); | |
117 | myFaces.Clear(); | |
118 | myMesh.Nullify(); | |
119 | } | |
120 | ||
0b97567d | 121 | //======================================================================= |
fc9b36d6 | 122 | //function : init |
7fd59977 | 123 | //purpose : |
124 | //======================================================================= | |
fc9b36d6 | 125 | void BRepMesh_IncrementalMesh::init() |
7fd59977 | 126 | { |
fc9b36d6 | 127 | myStatus = 0; |
9bdafcbe | 128 | myModified = Standard_False; |
7fd59977 | 129 | |
fc9b36d6 | 130 | setDone(); |
2caff0b3 | 131 | clear(); |
9bdafcbe | 132 | |
133 | if (!isCorrectPolyData()) | |
134 | BRepTools::Clean(myShape); | |
135 | ||
7fd59977 | 136 | Bnd_Box aBox; |
fc9b36d6 | 137 | BRepBndLib::Add(myShape, aBox, Standard_False); |
138 | ||
139 | if (aBox.IsVoid()) | |
140 | { | |
141 | // Nothing to mesh. | |
fc9b36d6 | 142 | return; |
8e3006e4 | 143 | } |
fc9b36d6 | 144 | |
145 | BRepMesh_ShapeTool::BoxMaxDimension(aBox, myMaxShapeSize); | |
fc9b36d6 | 146 | |
ceb418e1 | 147 | myMesh = new BRepMesh_FastDiscret(myDeflection, myAngle, aBox, |
fc9b36d6 | 148 | Standard_True, Standard_True, myRelative, Standard_True, myInParallel); |
ceb418e1 | 149 | |
150 | myMesh->InitSharedFaces(myShape); | |
7fd59977 | 151 | } |
152 | ||
8e3006e4 | 153 | //======================================================================= |
fc9b36d6 | 154 | //function : isCorrectPolyData |
8e3006e4 O |
155 | //purpose : |
156 | //======================================================================= | |
fc9b36d6 | 157 | Standard_Boolean BRepMesh_IncrementalMesh::isCorrectPolyData() |
8e3006e4 | 158 | { |
fc9b36d6 | 159 | collectFaces(); |
160 | ||
161 | BRepMesh_FaceChecker aFaceChecker(myInParallel); | |
162 | ||
163 | #ifdef HAVE_TBB | |
164 | if (myInParallel) | |
165 | { | |
166 | // check faces in parallel threads using TBB | |
167 | tbb::parallel_for_each(myFaces.begin(), myFaces.end(), aFaceChecker); | |
168 | } | |
169 | else | |
170 | { | |
171 | #endif | |
2caff0b3 | 172 | NCollection_Vector<TopoDS_Face>::Iterator aFaceIt(myFaces); |
173 | for (; aFaceIt.More(); aFaceIt.Next()) | |
174 | aFaceChecker(aFaceIt.Value()); | |
fc9b36d6 | 175 | #ifdef HAVE_TBB |
176 | } | |
177 | #endif | |
178 | ||
179 | return aFaceChecker.IsValid(); | |
8e3006e4 | 180 | } |
7fd59977 | 181 | |
9bdafcbe | 182 | //======================================================================= |
183 | //function : collectFaces | |
184 | //purpose : | |
185 | //======================================================================= | |
186 | void BRepMesh_IncrementalMesh::collectFaces() | |
187 | { | |
188 | TopTools_ListOfShape aFaceList; | |
189 | BRepLib::ReverseSortFaces(myShape, aFaceList); | |
190 | TopTools_MapOfShape aFaceMap; | |
9bdafcbe | 191 | |
192 | // make array of faces suitable for processing (excluding faces without surface) | |
193 | TopLoc_Location aDummyLoc; | |
194 | const TopLoc_Location aEmptyLoc; | |
195 | TopTools_ListIteratorOfListOfShape aFaceIter(aFaceList); | |
196 | for (; aFaceIter.More(); aFaceIter.Next()) | |
197 | { | |
198 | TopoDS_Shape aFaceNoLoc = aFaceIter.Value(); | |
199 | aFaceNoLoc.Location(aEmptyLoc); | |
200 | if (!aFaceMap.Add (aFaceNoLoc)) | |
201 | continue; // already processed | |
202 | ||
203 | TopoDS_Face aFace = TopoDS::Face(aFaceIter.Value()); | |
204 | const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(aFace, aDummyLoc); | |
205 | if (aSurf.IsNull()) | |
206 | continue; | |
207 | ||
2caff0b3 | 208 | myFaces.Append(aFace); |
9bdafcbe | 209 | } |
210 | } | |
211 | ||
7fd59977 | 212 | //======================================================================= |
fc9b36d6 | 213 | //function : Perform |
214 | //purpose : | |
7fd59977 | 215 | //======================================================================= |
fc9b36d6 | 216 | void BRepMesh_IncrementalMesh::Perform() |
7fd59977 | 217 | { |
fc9b36d6 | 218 | init(); |
7fd59977 | 219 | |
ceb418e1 | 220 | if (myMesh.IsNull()) |
7fd59977 | 221 | return; |
0d36f7e4 | 222 | |
fc9b36d6 | 223 | update(); |
224 | } | |
225 | ||
226 | //======================================================================= | |
227 | //function : update() | |
228 | //purpose : | |
229 | //======================================================================= | |
230 | void BRepMesh_IncrementalMesh::update() | |
231 | { | |
232 | // Update edges data | |
233 | TopExp_Explorer aExplorer(myShape, TopAbs_EDGE); | |
234 | for (; aExplorer.More(); aExplorer.Next()) | |
235 | { | |
236 | const TopoDS_Edge& aEdge = TopoDS::Edge(aExplorer.Current()); | |
237 | if(!BRep_Tool::IsGeometric(aEdge)) | |
238 | continue; | |
239 | ||
240 | update(aEdge); | |
7fd59977 | 241 | } |
242 | ||
fc9b36d6 | 243 | // Update faces data |
2caff0b3 | 244 | NCollection_Vector<TopoDS_Face>::Iterator aFaceIt(myFaces); |
245 | for (; aFaceIt.More(); aFaceIt.Next()) | |
246 | update(aFaceIt.Value()); | |
7fd59977 | 247 | |
fc9b36d6 | 248 | // Mesh faces |
249 | #ifdef HAVE_TBB | |
0b97567d K |
250 | if (myInParallel) |
251 | { | |
ceb418e1 | 252 | tbb::parallel_for_each(myFaces.begin(), myFaces.end(), *myMesh); |
0b97567d | 253 | } |
7fd59977 | 254 | else |
0b97567d | 255 | { |
fc9b36d6 | 256 | #endif |
2caff0b3 | 257 | for (aFaceIt.Init(myFaces); aFaceIt.More(); aFaceIt.Next()) |
258 | myMesh->Process(aFaceIt.Value()); | |
fc9b36d6 | 259 | #ifdef HAVE_TBB |
0b97567d | 260 | } |
fc9b36d6 | 261 | #endif |
7fd59977 | 262 | |
ceb418e1 | 263 | commit(); |
2caff0b3 | 264 | clear(); |
fc9b36d6 | 265 | } |
7fd59977 | 266 | |
fc9b36d6 | 267 | //======================================================================= |
268 | //function : discretizeFreeEdges | |
269 | //purpose : | |
270 | //======================================================================= | |
271 | void BRepMesh_IncrementalMesh::discretizeFreeEdges() | |
272 | { | |
273 | TopExp_Explorer aExplorer(myShape ,TopAbs_EDGE, TopAbs_FACE); | |
274 | for (; aExplorer.More(); aExplorer.Next()) | |
275 | { | |
276 | const TopoDS_Edge& aEdge = TopoDS::Edge(aExplorer.Current()); | |
277 | if(!BRep_Tool::IsGeometric(aEdge)) | |
7fd59977 | 278 | continue; |
7fd59977 | 279 | |
fc9b36d6 | 280 | TopLoc_Location aLoc; |
281 | Standard_Real aEdgeDeflection = edgeDeflection(aEdge); | |
282 | Handle(Poly_Polygon3D) aPoly3D = BRep_Tool::Polygon3D(aEdge, aLoc); | |
283 | if (!aPoly3D.IsNull() && aPoly3D->Deflection() < 1.1 * aEdgeDeflection) | |
284 | continue; | |
285 | ||
286 | BRepAdaptor_Curve aCurve(aEdge); | |
287 | GCPnts_TangentialDeflection aDiscret(aCurve, aCurve.FirstParameter(), | |
288 | aCurve.LastParameter(), myAngle, aEdgeDeflection, 2); | |
289 | ||
290 | Standard_Integer aNodesNb = aDiscret.NbPoints(); | |
291 | TColgp_Array1OfPnt aNodes (1, aNodesNb); | |
292 | TColStd_Array1OfReal aUVNodes(1, aNodesNb); | |
293 | for (Standard_Integer i = 1; i <= aNodesNb; ++i) | |
294 | { | |
295 | aNodes (i) = aDiscret.Value(i); | |
296 | aUVNodes(i) = aDiscret.Parameter(i); | |
7fd59977 | 297 | } |
fc9b36d6 | 298 | |
299 | aPoly3D = new Poly_Polygon3D(aNodes, aUVNodes); | |
300 | aPoly3D->Deflection(myDeflection); | |
7fd59977 | 301 | |
fc9b36d6 | 302 | BRep_Builder aBuilder; |
303 | aBuilder.UpdateEdge(aEdge, aPoly3D); | |
7fd59977 | 304 | } |
0b97567d K |
305 | } |
306 | ||
7fd59977 | 307 | //======================================================================= |
fc9b36d6 | 308 | //function : edgeDeflection |
309 | //purpose : | |
7fd59977 | 310 | //======================================================================= |
fc9b36d6 | 311 | Standard_Real BRepMesh_IncrementalMesh::edgeDeflection( |
312 | const TopoDS_Edge& theEdge) | |
7fd59977 | 313 | { |
fc9b36d6 | 314 | if (myEdgeDeflection.IsBound(theEdge)) |
315 | return myEdgeDeflection(theEdge); | |
7fd59977 | 316 | |
fc9b36d6 | 317 | Standard_Real aEdgeDeflection; |
318 | if (myRelative) | |
319 | { | |
320 | Standard_Real aScale; | |
321 | aEdgeDeflection = BRepMesh_ShapeTool::RelativeEdgeDeflection(theEdge, | |
322 | myDeflection, myMaxShapeSize, aScale); | |
323 | } | |
324 | else | |
325 | aEdgeDeflection = myDeflection; | |
326 | ||
327 | myEdgeDeflection.Bind(theEdge, aEdgeDeflection); | |
328 | return aEdgeDeflection; | |
7fd59977 | 329 | } |
330 | ||
fc9b36d6 | 331 | //======================================================================= |
332 | //function : faceDeflection | |
333 | //purpose : | |
334 | //======================================================================= | |
335 | Standard_Real BRepMesh_IncrementalMesh::faceDeflection( | |
336 | const TopoDS_Face& theFace) | |
337 | { | |
338 | if (!myRelative) | |
339 | return myDeflection; | |
340 | ||
341 | Standard_Integer aEdgesNb = 0; | |
342 | Standard_Real aFaceDeflection = 0.; | |
343 | ||
344 | TopExp_Explorer aEdgeIt(theFace, TopAbs_EDGE); | |
345 | for (; aEdgeIt.More(); aEdgeIt.Next(), ++aEdgesNb) | |
346 | { | |
347 | const TopoDS_Edge& aEdge = TopoDS::Edge(aEdgeIt.Current()); | |
348 | aFaceDeflection += edgeDeflection(aEdge); | |
349 | } | |
350 | ||
351 | return (aEdgesNb == 0) ? myDeflection : (aFaceDeflection / aEdgesNb); | |
352 | } | |
7fd59977 | 353 | |
354 | //======================================================================= | |
fc9b36d6 | 355 | //function : update(edge) |
356 | //purpose : | |
7fd59977 | 357 | //======================================================================= |
fc9b36d6 | 358 | void BRepMesh_IncrementalMesh::update(const TopoDS_Edge& theEdge) |
7fd59977 | 359 | { |
fc9b36d6 | 360 | Standard_Integer aPolyIndex = 1; |
361 | Standard_Real aEdgeDeflection = edgeDeflection(theEdge); | |
362 | Handle(Poly_PolygonOnTriangulation) aPolygon; | |
363 | do | |
364 | { | |
365 | TopLoc_Location aLoc; | |
366 | Handle(Poly_Triangulation) aTriangulation; | |
367 | BRep_Tool::PolygonOnTriangulation(theEdge, aPolygon, | |
368 | aTriangulation, aLoc, aPolyIndex++); | |
369 | ||
370 | if (!aTriangulation.IsNull() && !aPolygon.IsNull()) | |
371 | { | |
ceb418e1 | 372 | if (aPolygon->Deflection() < 1.1 * aEdgeDeflection && |
373 | aPolygon->HasParameters()) | |
374 | { | |
fc9b36d6 | 375 | continue; |
ceb418e1 | 376 | } |
fc9b36d6 | 377 | |
378 | myModified = Standard_True; | |
379 | BRepMesh_ShapeTool::NullifyEdge(theEdge, aTriangulation, aLoc); | |
7fd59977 | 380 | } |
fc9b36d6 | 381 | |
382 | if (!myEmptyEdges.IsBound(theEdge)) | |
848fa7e3 | 383 | myEmptyEdges.Bind(theEdge, BRepMesh::MapOfTriangulation()); |
fc9b36d6 | 384 | |
ceb418e1 | 385 | if (!aTriangulation.IsNull()) |
386 | myEmptyEdges(theEdge).Add(aTriangulation); | |
7fd59977 | 387 | } |
fc9b36d6 | 388 | while (!aPolygon.IsNull()); |
389 | } | |
7fd59977 | 390 | |
fc9b36d6 | 391 | //======================================================================= |
392 | //function : isToBeMeshed | |
393 | //purpose : | |
394 | //======================================================================= | |
395 | Standard_Boolean BRepMesh_IncrementalMesh::toBeMeshed( | |
396 | const TopoDS_Face& theFace, | |
397 | const Standard_Boolean isWithCheck) | |
398 | { | |
399 | TopLoc_Location aLoc; | |
400 | Handle(Poly_Triangulation) aTriangulation = | |
401 | BRep_Tool::Triangulation(theFace, aLoc); | |
402 | ||
403 | if (aTriangulation.IsNull()) | |
404 | return Standard_True; | |
405 | ||
406 | if (isWithCheck) | |
ab58a62b | 407 | { |
fc9b36d6 | 408 | Standard_Real aFaceDeflection = faceDeflection(theFace); |
409 | if (aTriangulation->Deflection() < 1.1 * aFaceDeflection) | |
ab58a62b | 410 | { |
fc9b36d6 | 411 | Standard_Boolean isEdgesConsistent = Standard_True; |
412 | TopExp_Explorer aEdgeIt(theFace, TopAbs_EDGE); | |
413 | for (; aEdgeIt.More() && isEdgesConsistent; aEdgeIt.Next()) | |
ab58a62b | 414 | { |
fc9b36d6 | 415 | const TopoDS_Edge& aEdge = TopoDS::Edge(aEdgeIt.Current()); |
416 | if (!myEmptyEdges.IsBound(aEdge)) | |
417 | continue; | |
418 | ||
848fa7e3 | 419 | BRepMesh::MapOfTriangulation& aTriMap = myEmptyEdges(aEdge); |
ceb418e1 | 420 | isEdgesConsistent &= !aTriMap.IsEmpty() && !aTriMap.Contains(aTriangulation); |
7fd59977 | 421 | } |
fc9b36d6 | 422 | |
423 | if (isEdgesConsistent) | |
424 | return Standard_False; | |
ab58a62b | 425 | } |
7fd59977 | 426 | } |
427 | ||
fc9b36d6 | 428 | // Nullify edges |
429 | TopExp_Explorer aEdgeIt(theFace, TopAbs_EDGE); | |
430 | for (; aEdgeIt.More(); aEdgeIt.Next()) | |
431 | { | |
432 | const TopoDS_Edge& aEdge = TopoDS::Edge(aEdgeIt.Current()); | |
433 | BRepMesh_ShapeTool::NullifyEdge(aEdge, aTriangulation, aLoc); | |
434 | } | |
7fd59977 | 435 | |
fc9b36d6 | 436 | BRepMesh_ShapeTool::NullifyFace(theFace); |
437 | return Standard_True; | |
438 | } | |
7fd59977 | 439 | |
fc9b36d6 | 440 | //======================================================================= |
441 | //function : update(face) | |
442 | //purpose : | |
443 | //======================================================================= | |
444 | void BRepMesh_IncrementalMesh::update(const TopoDS_Face& theFace) | |
445 | { | |
446 | if (!toBeMeshed(theFace, Standard_True)) | |
447 | return; | |
448 | ||
449 | myModified = Standard_True; | |
ceb418e1 | 450 | Standard_Integer aStatus = myMesh->Add(theFace); |
fc9b36d6 | 451 | |
ceb418e1 | 452 | myStatus |= aStatus; |
fc9b36d6 | 453 | if (aStatus != BRepMesh_ReMesh) |
454 | return; | |
455 | ||
848fa7e3 | 456 | BRepMesh::MapOfShape aUsedFaces; |
fc9b36d6 | 457 | aUsedFaces.Add(theFace); |
458 | ||
ceb418e1 | 459 | const TopTools_IndexedDataMapOfShapeListOfShape& aMapOfSharedFaces = |
460 | myMesh->SharedFaces(); | |
461 | ||
fc9b36d6 | 462 | TopExp_Explorer aEdgeIt(theFace, TopAbs_EDGE); |
463 | for (; aEdgeIt.More(); aEdgeIt.Next()) | |
464 | { | |
465 | const TopoDS_Edge& aEdge = TopoDS::Edge(aEdgeIt.Current()); | |
ceb418e1 | 466 | if (aMapOfSharedFaces.FindIndex(aEdge) == 0) |
fc9b36d6 | 467 | continue; |
468 | ||
ceb418e1 | 469 | const TopTools_ListOfShape& aSharedFaces = aMapOfSharedFaces.FindFromKey(aEdge); |
fc9b36d6 | 470 | TopTools_ListIteratorOfListOfShape aSharedFaceIt(aSharedFaces); |
471 | for (; aSharedFaceIt.More(); aSharedFaceIt.Next()) | |
472 | { | |
473 | const TopoDS_Face& aFace = TopoDS::Face(aSharedFaceIt.Value()); | |
474 | if (aUsedFaces.Contains(aFace)) | |
475 | continue; | |
476 | ||
477 | aUsedFaces.Add(aFace); | |
478 | toBeMeshed(aFace, Standard_False); | |
479 | ||
ceb418e1 | 480 | myStatus |= myMesh->Add(aFace); |
481 | } | |
482 | } | |
483 | } | |
484 | ||
485 | //======================================================================= | |
486 | //function : commit | |
487 | //purpose : | |
488 | //======================================================================= | |
489 | void BRepMesh_IncrementalMesh::commit() | |
490 | { | |
2caff0b3 | 491 | NCollection_Vector<TopoDS_Face>::Iterator aFaceIt(myFaces); |
492 | for (; aFaceIt.More(); aFaceIt.Next()) | |
493 | commitEdges(aFaceIt.Value()); | |
ceb418e1 | 494 | |
495 | discretizeFreeEdges(); | |
496 | } | |
497 | ||
498 | //======================================================================= | |
fcf15f5c | 499 | //function : commitEdges |
ceb418e1 | 500 | //purpose : |
501 | //======================================================================= | |
fcf15f5c | 502 | void BRepMesh_IncrementalMesh::commitEdges(const TopoDS_Face& theFace) |
ceb418e1 | 503 | { |
504 | TopoDS_Face aFace = theFace; | |
505 | aFace.Orientation(TopAbs_FORWARD); | |
506 | ||
507 | Handle(BRepMesh_FaceAttribute) aFaceAttribute; | |
508 | if (!myMesh->GetFaceAttribute(aFace, aFaceAttribute)) | |
509 | return; | |
510 | ||
ceb418e1 | 511 | if (!aFaceAttribute->IsValid()) |
512 | { | |
513 | myStatus |= aFaceAttribute->GetStatus(); | |
514 | return; | |
515 | } | |
516 | ||
517 | TopLoc_Location aLoc = aFace.Location(); | |
fcf15f5c | 518 | Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation(aFace, aLoc); |
519 | ||
520 | if (aTriangulation.IsNull()) | |
fcf15f5c | 521 | return; |
ceb418e1 | 522 | |
523 | try | |
524 | { | |
525 | OCC_CATCH_SIGNALS | |
526 | ||
ceb418e1 | 527 | // Store discretization of edges |
848fa7e3 | 528 | BRepMesh::HDMapOfShapePairOfPolygon& aInternalEdges = aFaceAttribute->ChangeInternalEdges(); |
529 | BRepMesh::DMapOfShapePairOfPolygon::Iterator aEdgeIt(*aInternalEdges); | |
ceb418e1 | 530 | for (; aEdgeIt.More(); aEdgeIt.Next()) |
531 | { | |
532 | const TopoDS_Edge& aEdge = TopoDS::Edge(aEdgeIt.Key()); | |
533 | const BRepMesh_PairOfPolygon& aPolyPair = aEdgeIt.Value(); | |
534 | const Handle(Poly_PolygonOnTriangulation)& aPolygon1 = aPolyPair.First(); | |
535 | const Handle(Poly_PolygonOnTriangulation)& aPolygon2 = aPolyPair.Last(); | |
536 | ||
ceb418e1 | 537 | if (aPolygon1 == aPolygon2) |
fcf15f5c | 538 | BRepMesh_ShapeTool::UpdateEdge(aEdge, aPolygon1, aTriangulation, aLoc); |
ceb418e1 | 539 | else |
fcf15f5c | 540 | BRepMesh_ShapeTool::UpdateEdge(aEdge, aPolygon1, aPolygon2, aTriangulation, aLoc); |
ceb418e1 | 541 | } |
542 | } | |
543 | catch (Standard_Failure) | |
544 | { | |
545 | myStatus |= BRepMesh_Failure; | |
7fd59977 | 546 | } |
547 | } | |
0b97567d K |
548 | |
549 | //======================================================================= | |
550 | //function : Discret | |
551 | //purpose : | |
552 | //======================================================================= | |
fc9b36d6 | 553 | Standard_Integer BRepMesh_IncrementalMesh::Discret( |
554 | const TopoDS_Shape& theShape, | |
555 | const Standard_Real theDeflection, | |
556 | const Standard_Real theAngle, | |
ceb418e1 | 557 | BRepMesh_DiscretRoot* &theAlgo) |
0b97567d K |
558 | { |
559 | BRepMesh_IncrementalMesh* anAlgo = new BRepMesh_IncrementalMesh(); | |
fc9b36d6 | 560 | anAlgo->SetDeflection(theDeflection); |
561 | anAlgo->SetAngle (theAngle); | |
562 | anAlgo->SetShape (theShape); | |
563 | anAlgo->SetParallel (IS_IN_PARALLEL); | |
0b97567d K |
564 | theAlgo = anAlgo; |
565 | return 0; // no error | |
566 | } | |
567 | ||
568 | //======================================================================= | |
569 | //function : IsParallelDefault | |
570 | //purpose : | |
571 | //======================================================================= | |
572 | Standard_Boolean BRepMesh_IncrementalMesh::IsParallelDefault() | |
573 | { | |
574 | #ifdef HAVE_TBB | |
575 | return IS_IN_PARALLEL; | |
576 | #else | |
577 | // no alternative parallelization yet - flag has no meaning | |
578 | return Standard_False; | |
579 | #endif | |
580 | } | |
581 | ||
582 | //======================================================================= | |
583 | //function : Discret | |
584 | //purpose : | |
585 | //======================================================================= | |
fc9b36d6 | 586 | void BRepMesh_IncrementalMesh::SetParallelDefault( |
587 | const Standard_Boolean theInParallel) | |
0b97567d K |
588 | { |
589 | IS_IN_PARALLEL = theInParallel; | |
590 | } | |
591 | ||
592 | //! Export Mesh Plugin entry function | |
593 | DISCRETPLUGIN(BRepMesh_IncrementalMesh) |