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