1 // Created on: 1996-02-27
2 // Created by: Ekaterina SMIRNOVA
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <BRepMesh_FastDiscret.ixx>
24 #include <BRepMesh_FastDiscretFace.hxx>
25 #include <BRepMesh_FaceAttribute.hxx>
26 #include <BRepMesh_DataStructureOfDelaun.hxx>
27 #include <BRepMesh_ClassifierPtr.hxx>
28 #include <BRepMesh_GeomTool.hxx>
29 #include <BRepMesh_PairOfPolygon.hxx>
30 #include <BRepMesh_DataMapOfShapePairOfPolygon.hxx>
31 #include <BRepMesh_DataMapIteratorOfDataMapOfShapePairOfPolygon.hxx>
32 #include <Geom_Plane.hxx>
33 #include <GeomAbs_IsoType.hxx>
34 #include <GeomAbs_SurfaceType.hxx>
36 #include <TColStd_HArray1OfReal.hxx>
37 #include <Precision.hxx>
39 #include <BRep_Builder.hxx>
40 #include <BRep_Tool.hxx>
41 #include <Poly_Triangulation.hxx>
42 #include <Poly_PolygonOnTriangulation.hxx>
43 #include <Poly_Connect.hxx>
44 #include <TColStd_SequenceOfInteger.hxx>
45 #include <TColStd_Array1OfInteger.hxx>
46 #include <TColStd_HArray1OfInteger.hxx>
48 #include <TColgp_Array1OfPnt.hxx>
49 #include <TColgp_Array1OfPnt2d.hxx>
50 #include <Precision.hxx>
52 #include <BRepAdaptor_Curve.hxx>
53 #include <BRepAdaptor_Surface.hxx>
54 #include <BRepAdaptor_HSurface.hxx>
55 #include <BRepTools.hxx>
56 #include <BndLib_Add3dCurve.hxx>
57 #include <BRepBndLib.hxx>
58 #include <Bnd_Box.hxx>
61 #include <TopExp_Explorer.hxx>
63 #include <Geom2d_Curve.hxx>
65 #include <TColStd_DataMapOfIntegerInteger.hxx>
66 #include <BRepMesh_ShapeTool.hxx>
68 #include <Geom_Surface.hxx>
69 #include <Adaptor3d_IsoCurve.hxx>
70 #include <BRepMesh_IndexedMapOfVertex.hxx>
71 #include <Extrema_LocateExtPC.hxx>
73 #include <BRepMesh_ListOfXY.hxx>
74 #include <BRepMesh_ListIteratorOfListOfXY.hxx>
76 #include <TColStd_Array1OfInteger.hxx>
77 #include <BRepMesh_IDMapOfNodeOfDataStructureOfDelaun.hxx>
78 #include <Standard_ErrorHandler.hxx>
79 #include <Standard_Failure.hxx>
80 //#include <TColStd_DataMapOfInteger.hxx>
81 #include <TColGeom2d_SequenceOfCurve.hxx>
82 #include <TopTools_SequenceOfShape.hxx>
83 #include <NCollection_IncAllocator.hxx>
85 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
86 #include <BRep_PointRepresentation.hxx>
87 #include <BRep_TVertex.hxx>
88 #include <TColStd_MapOfInteger.hxx>
89 #include <SortTools_ShellSortOfReal.hxx>
90 #include <TCollection_CompareOfReal.hxx>
92 #include <TopTools_HArray1OfShape.hxx>
93 #include <TopTools_ListIteratorOfListOfShape.hxx>
98 // paralleling using Intel TBB
99 #include <tbb/parallel_for_each.h>
102 #define UVDEFLECTION 1.e-05
104 inline Standard_Real MaxFaceTol (const TopoDS_Face& theFace)
106 Standard_Real T, TMax = BRep_Tool::Tolerance(theFace);
109 for (Ex.Init(theFace,TopAbs_EDGE); Ex.More(); Ex.Next())
111 T = BRep_Tool::Tolerance(TopoDS::Edge(Ex.Current()));
112 if (T > TMax) TMax = T;
115 for (Ex.Init(theFace,TopAbs_VERTEX); Ex.More(); Ex.Next())
117 T = BRep_Tool::Tolerance(TopoDS::Vertex(Ex.Current()));
118 if (T > TMax) TMax = T;
125 //=======================================================================
126 //function : BRepMesh_FastDiscret
128 //=======================================================================
129 BRepMesh_FastDiscret::BRepMesh_FastDiscret(const Standard_Real theDefle,
130 const Standard_Real theAngl,
131 const Bnd_Box& theBox,
132 const Standard_Boolean theWithShare,
133 const Standard_Boolean theInshape,
134 const Standard_Boolean theRelative,
135 const Standard_Boolean theShapetrigu) :
137 myDeflection (theDefle),
138 myWithShare (theWithShare),
139 myInParallel (Standard_False),
141 myRelative (theRelative),
142 myShapetrigu (theShapetrigu),
143 myInshape (theInshape)
145 myAllocator = new NCollection_IncAllocator(64000);
147 BoxMaxDimension(theBox, myDtotale);
150 //=======================================================================
151 //function : BRepMesh_FastDiscret
153 //=======================================================================
155 BRepMesh_FastDiscret::BRepMesh_FastDiscret(const Standard_Real theDefle,
156 const TopoDS_Shape& theShape,
157 const Bnd_Box& theBox,
158 const Standard_Real theAngl,
159 const Standard_Boolean theWithShare,
160 const Standard_Boolean theInshape,
161 const Standard_Boolean theRelative,
162 const Standard_Boolean theShapetrigu):
164 myDeflection (theDefle),
165 myWithShare (theWithShare),
166 myInParallel (Standard_False),
168 myRelative (theRelative),
169 myShapetrigu (theShapetrigu),
170 myInshape (theInshape)
172 myAllocator = new NCollection_IncAllocator(64000);
174 BoxMaxDimension(theBox, myDtotale);
178 //=======================================================================
179 //function : SetParallel
181 //=======================================================================
182 void BRepMesh_FastDiscret::SetParallel (const Standard_Boolean theInParallel)
184 myInParallel = theInParallel;
187 //=======================================================================
188 //function : IsParallel
190 //=======================================================================
191 Standard_Boolean BRepMesh_FastDiscret::IsParallel() const
196 //=======================================================================
197 //function : BoxMaxDimension
199 //=======================================================================
201 void BRepMesh_FastDiscret::BoxMaxDimension(const Bnd_Box& theBox, Standard_Real& theMaxDim)
205 Standard_Real TXmin, TYmin, TZmin, TXmax, TYmax, TZmax;
206 theBox.Get(TXmin, TYmin, TZmin, TXmax, TYmax, TZmax);
207 theMaxDim = TXmax-TXmin;
208 const Standard_Real dy = TYmax-TYmin;
209 const Standard_Real dz = TZmax-TZmin;
210 if (dy > theMaxDim) theMaxDim = dy;
211 if (dz > theMaxDim) theMaxDim = dz;
214 //=======================================================================
215 //function : RelativeEdgeDeflection
217 //=======================================================================
219 Standard_Real BRepMesh_FastDiscret::RelativeEdgeDeflection(const TopoDS_Edge& theEdge,
220 const Standard_Real theDefle,
221 const Standard_Real theDTotale,
222 Standard_Real& theDefCoef)
225 Standard_Real defedge = theDefle;
230 BRepBndLib::Add(theEdge, B);
231 BoxMaxDimension(B, defedge);
233 // adjusted in relation to the total size:
234 theDefCoef = theDTotale/(2*defedge);
235 if (theDefCoef < 0.5) theDefCoef = 0.5;
236 if (theDefCoef > 2.) theDefCoef = 2.;
237 defedge = theDefCoef * defedge * theDefle;
242 //=======================================================================
243 //function : Perform(shape)
245 //=======================================================================
247 void BRepMesh_FastDiscret::Perform(const TopoDS_Shape& theShape)
249 TopTools_IndexedDataMapOfShapeListOfShape anAncestors;
250 TopExp::MapShapesAndAncestors(theShape, TopAbs_EDGE, TopAbs_FACE, anAncestors);
251 std::vector<TopoDS_Face> aFaces;
252 for (TopExp_Explorer ex(theShape, TopAbs_FACE); ex.More(); ex.Next()) {
253 TopoDS_Face aF = TopoDS::Face(ex.Current());
254 Add(aF, anAncestors);
255 aFaces.push_back(aF);
261 CreateMutexesForSubShapes(theShape, TopAbs_EDGE);
262 // mesh faces in parallel threads using TBB
263 tbb::parallel_for_each (aFaces.begin(), aFaces.end(), *this);
265 // alternative parallelization not yet available
266 for (std::vector<TopoDS_Face>::iterator it(aFaces.begin()); it != aFaces.end(); it++)
273 for (std::vector<TopoDS_Face>::iterator it(aFaces.begin()); it != aFaces.end(); it++)
279 //=======================================================================
282 //=======================================================================
284 void BRepMesh_FastDiscret::Process(const TopoDS_Face& theFace) const
286 //cout << "START face " << theFace.TShape().operator->() << endl << flush;
287 Handle(BRepMesh_FaceAttribute) fattribute;
288 if ( GetFaceAttribute (theFace, fattribute) )
290 BRepMesh_FastDiscretFace aTool (GetAngle(), WithShare());
291 aTool.Add (theFace, fattribute, GetMapOfDefEdge(), myMutexProvider);
293 //cout << "END face " << theFace.TShape().operator->() << endl << flush;
296 //=======================================================================
297 //function : Add(face)
299 //=======================================================================
301 #define MESH_FAILURE(theface) \
303 myFacestate = BRepMesh_Failure; \
304 myNottriangulated.Append(theface); \
308 void BRepMesh_FastDiscret::Add(const TopoDS_Face& theface,
309 const TopTools_IndexedDataMapOfShapeListOfShape& theAncestors)
316 TopoDS_Face face = theface;
317 BRepTools::Update(face);
318 face.Orientation(TopAbs_FORWARD);
319 myStructure.Nullify();
320 Handle(NCollection_IncAllocator) anAlloc = Handle(NCollection_IncAllocator)::DownCast(myAllocator);
321 anAlloc->Reset(Standard_False);
322 myStructure=new BRepMesh_DataStructureOfDelaun(anAlloc);
324 Standard_Real aUmin, aVmin, aUmax, aVmax;
325 BRepTools::UVBounds (theface, aUmin, aUmax, aVmin, aVmax);
326 Standard_Real aTolU = (aUmax - aUmin) * UVDEFLECTION;
327 Standard_Real aTolV = (aVmax - aVmin) * UVDEFLECTION;
328 myStructure->Data().SetCellSize ( 14 * aTolU, 14 * aTolV );
329 myStructure->Data().SetTolerance( aTolU, aTolV );
331 BRepAdaptor_Surface BS(face, Standard_False);
332 Handle(BRepAdaptor_HSurface) gFace = new BRepAdaptor_HSurface(BS);
334 GeomAbs_SurfaceType thetype;
335 thetype = BS.GetType();
337 gp_Pnt2d uvFirst, uvLast;
339 Handle(Poly_Triangulation) T;
348 myLocation2d.Clear();
349 myInternaledges.Clear();
354 Standard_Real defedge, defface;
355 Standard_Integer nbEdge = 0;
356 Standard_Real savangle = myAngle;
358 Standard_Real maxdef = 2.* MaxFaceTol(theface);
361 if (!myRelative) defface = Max(myDeflection, maxdef);
363 TColStd_SequenceOfReal aFSeq, aLSeq;
364 TColGeom2d_SequenceOfCurve aCSeq;
365 TopTools_SequenceOfShape aShSeq;
367 TopoDS_Iterator exW(face);
369 for (; exW.More(); exW.Next()) {
370 const TopoDS_Shape& aWire = exW.Value();
371 if (aWire.ShapeType() != TopAbs_WIRE)
373 TopoDS_Iterator ex(aWire);
374 for(; ex.More(); ex.Next()) {
375 const TopoDS_Edge& edge = TopoDS::Edge(ex.Value());
377 if (!myMapdefle.IsBound(edge)) {
379 if (myEdges.IsBound(edge)) {
380 const BRepMesh_PairOfPolygon& pair = myEdges.Find(edge);
381 const Handle(Poly_PolygonOnTriangulation)& P = pair.First();
382 defedge = P->Deflection();
385 defedge = RelativeEdgeDeflection(edge, myDeflection, myDtotale, cdef);
386 myAngle = savangle * cdef;
388 defface = defface + defedge;
389 defface = Max(maxdef, defface);
391 else defedge = myDeflection;
393 defedge = Max(maxdef, defedge);
394 defedge = Max(UVDEFLECTION , defedge);
395 myMapdefle.Bind(edge, defedge);
398 defedge = myMapdefle(edge);
399 if (myRelative) {defface = defface + defedge; defface = Max(maxdef, defface);}
402 Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(edge, face, f1, l1);
403 if (C.IsNull()) continue;
409 Add(edge, face, gFace, C, theAncestors, defedge, f1, l1);
414 if (nbEdge == 0 || myVemap.Extent() < 3)
416 MESH_FAILURE(theface);
419 if (myRelative ) defface = defface / nbEdge;
420 else defface = myDeflection;
422 if (myWithShare) defface = Max(maxdef, defface);
424 T = BRep_Tool::Triangulation(face, loc);
426 if (!myShapetrigu || T.IsNull()) {
428 Standard_Real xCur, yCur;
429 Standard_Real maxX, minX, maxY, minY;
433 Standard_Integer ipn = 0;
434 Standard_Integer i1 =1;
435 for (i1 = 1; i1 <= myVemap.Extent(); i1++) {
436 const BRepMesh_Vertex& aV = myStructure->GetNode(myVemap.FindKey(i1));
440 minX=Min(xCur, minX);
441 maxX=Max(xCur, maxX);
442 minY=Min(yCur, minY);
443 maxY=Max(yCur, maxY);
445 Standard_Real myumin = minX;
446 Standard_Real myumax = maxX;
447 Standard_Real myvmin = minY;
448 Standard_Real myvmax = maxY;
450 const Standard_Real umin = BS.FirstUParameter();
451 const Standard_Real umax = BS.LastUParameter();
452 const Standard_Real vmin = BS.FirstVParameter();
453 const Standard_Real vmax = BS.LastVParameter();
455 if (myumin < umin || myumax > umax)
457 if (BS.IsUPeriodic())
459 if ((myumax - myumin) > (umax - umin))
461 myumax = myumin + (umax - umin);
466 if (umin > myumin) myumin = umin;
467 if (umax < myumax) myumax = umax;
471 if (myvmin < vmin || myvmax > vmax)
473 if (BS.IsVPeriodic())
475 if ((myvmax - myvmin) > (vmax - vmin))
477 myvmax = myvmin + (vmax - vmin);
482 if (vmin > myvmin) myvmin = vmin;
483 if (vmax < myvmax) myvmax = vmax;
487 // fast verification of the validity of calculated limits. If wrong,
488 // sure a problem of pcurve.
489 if (thetype == GeomAbs_BezierSurface &&
490 (myumin < -0.5 || myumax > 1.5 || myvmin < -0.5 || myvmax > 1.5))
492 MESH_FAILURE(theface);
495 //define parameters for correct parametrics
497 Standard_Real deltaX = 1.0;
498 Standard_Real deltaY = 1.0;
499 Standard_Integer nbVertices = myVemap.Extent();
500 const Standard_Real tolclass = Precision::PConfusion(); //0.03*Max(myumax-myumin, myvmax-myvmin);
502 BRepMesh_ClassifierPtr classifier (
503 new BRepMesh_Classifier(face, tolclass, myInternaledges, myVemap,
504 myStructure, myumin, myumax, myvmin, myvmax) );
506 myFacestate = classifier->State();
507 if (myFacestate == BRepMesh_SelfIntersectingWire)
509 Standard_Integer nbmaill = 0;
510 Standard_Real eps = Precision::Confusion();
511 while (nbmaill < 5 && myFacestate != BRepMesh_ReMesh)
515 //clear the structure of links
516 myStructure.Nullify();
517 myStructure = new BRepMesh_DataStructureOfDelaun(anAlloc);
520 myLocation2d.Clear();
521 myInternaledges.Clear();
524 for(j1 = 1; j1 <= aShSeq.Length(); j1++)
526 const TopoDS_Edge& edge = TopoDS::Edge(aShSeq.Value(j1));
527 if (myEdges.IsBound(edge))
529 myEdges.UnBind(edge);
530 myInternaledges.UnBind(edge);
535 for( j1 = 1; j1 <= aShSeq.Length(); j1++)
537 const TopoDS_Edge& edge = TopoDS::Edge(aShSeq.Value(j1));
538 defedge = myMapdefle(edge) / 3.;
539 defedge = Max(defedge, eps);
540 myMapdefle.Bind(edge, defedge);
541 const Handle(Geom2d_Curve)& C = aCSeq.Value(j1);
542 Add(edge, face, gFace, C, theAncestors, defedge, aFSeq.Value(j1), aLSeq.Value(j1));
545 classifier.Nullify();
547 classifier = new BRepMesh_Classifier(face, tolclass, myInternaledges, myVemap,
548 myStructure, myumin, myumax, myvmin, myvmax);
550 if (classifier->State() == BRepMesh_NoError)
552 myFacestate = BRepMesh_ReMesh;
554 nbVertices = myVemap.Extent();
558 if (myFacestate != BRepMesh_NoError && myFacestate != BRepMesh_ReMesh)
560 myNottriangulated.Append(face);
561 classifier.Nullify();
565 // try to find the real length:
566 // akm (bug OCC16) : We must calculate these measures in non-singular
567 // parts of face. Let's try to compute average value of three
568 // (umin, (umin+umax)/2, umax), and respectively for v.
570 Standard_Real longu = 0.0, longv = 0.0; //, last , first;
571 gp_Pnt P11, P12, P21, P22, P31, P32;
573 Standard_Real du = (myumax-myumin)/20;
574 Standard_Real dv = (myvmax-myvmin)/20;
575 Standard_Real dfuave=(myumin+myumax)/2, dfucur;
576 Standard_Real dfvave=(myvmin+myvmax)/2, dfvcur;
578 BS.D0 (myumin, myvmin, P11);
579 BS.D0 (myumin, dfvave, P21);
580 BS.D0 (myumin, myvmax, P31);
581 for (i1=1, dfucur=myumin+du; i1 <= 20; i1++, dfucur+=du) {
582 BS.D0 (dfucur, myvmin, P12);
583 BS.D0 (dfucur, dfvave, P22);
584 BS.D0 (dfucur, myvmax, P32);
585 longu += ( P11.Distance(P12) + P21.Distance(P22) + P31.Distance(P32) );
591 BS.D0(myumin, myvmin, P11);
592 BS.D0(dfuave, myvmin, P21);
593 BS.D0(myumax, myvmin, P31);
594 for (i1=1, dfvcur=myvmin+dv; i1 <= 20; i1++, dfvcur+=dv) {
595 BS.D0 (myumin, dfvcur, P12);
596 BS.D0 (dfuave, dfvcur, P22);
597 BS.D0 (myumax, dfvcur, P32);
598 longv += ( P11.Distance(P12) + P21.Distance(P22) + P31.Distance(P32) );
605 // akm (bug OCC16) ^^^^^
607 if (longu <= 1.e-16 || longv <= 1.e-16) {
609 #ifdef DEB_MESH_CHRONO
611 MESH_CHRONO_TSTOP(thetype);
613 MESH_FAILURE(theface);
617 if (thetype == GeomAbs_Torus) {
618 gp_Torus Tor = BS.Torus();
619 Standard_Real r = Tor.MinorRadius(), R = Tor.MajorRadius();
620 Standard_Real Du, Dv;//, pasu, pasv;
622 Dv = Max(1.0e0 - (defface/r),0.0e0) ;
623 Standard_Real oldDv = 2.0 * ACos (Dv);
624 oldDv = Min(oldDv, myAngle);
625 Dv = 0.9*oldDv; //TWOTHIRD * oldDv;
628 Standard_Integer nbV = Max((Standard_Integer)((myvmax-myvmin)/Dv), 2);
629 Dv = (myvmax-myvmin)/(nbV+1);
631 Standard_Real ru = R + r;
633 Du = Max(1.0e0 - (defface/ru),0.0e0);
634 Du = (2.0 * ACos (Du));
635 Du = Min(Du, myAngle);
636 Standard_Real aa = sqrt(Du*Du + oldDv*oldDv);
637 if(aa < gp::Resolution())
640 Du = Du * Min(oldDv, Du) / aa;
644 Standard_Integer nbU = Max((Standard_Integer)((myumax-myumin)/Du), 2);
645 nbU = Max(nbU, (Standard_Integer)(nbV*(myumax-myumin)*R/((myvmax-myvmin)*r)/5.));
647 Du = (myumax-myumin)/(nbU+1);
648 //-- DeltaX and DeltaY are chosen so that to avoid "jumping"
649 //-- of points on the grid
653 else if (thetype == GeomAbs_Cylinder) {
654 /*Standard_Real aMax = Max(myumax,myvmax);
655 deltaX = 0.01; //1./aMax; //0.01;
657 gp_Cylinder Cyl = BS.Cylinder();
658 Standard_Real R = Cyl.Radius();
659 // Calculate parameters for iteration in U direction
660 Standard_Real Du = 1.0 - (defface/R);
661 if (Du < 0.0) Du = 0.0;
662 Du = 2.0 * ACos (Du);
663 if (Du > GetAngle()) Du = GetAngle();
668 deltaX = (myumax-myumin)/longu;
669 deltaY = (myvmax-myvmin)/longv;
672 if(!myMapattrib.IsBound(theface))
674 Handle(BRepMesh_FaceAttribute) aFA = new BRepMesh_FaceAttribute();
675 aFA->GetDefFace() = defface;
676 aFA->GetUMax() = myumax;
677 aFA->GetVMax() = myvmax;
678 aFA->GetUMin() = myumin;
679 aFA->GetVMin() = myvmin;
680 aFA->GetDeltaX() = deltaX;
681 aFA->GetDeltaY() = deltaY;
682 aFA->GetMinX() = minX;
683 aFA->GetMinY() = minY;
684 aFA->GetClassifier() = classifier;
685 myMapattrib.Bind(theface, aFA);
688 //Standard_Integer nbVertices = myVemap.Extent();
689 T = new Poly_Triangulation(nbVertices, 1, Standard_True);
690 TColgp_Array1OfPnt& Nodes = T->ChangeNodes();
691 TColgp_Array1OfPnt2d& Nodes2d = T->ChangeUVNodes();
693 Standard_Integer index;
694 for (i = 1; i <= nbVertices; i++) {
695 index = myVemap.FindKey(i);
696 Nodes(i) = Pnt(index);
697 Nodes2d(i).SetXY(Vertex(index).Coord());
700 // storage of triangulation in the BRep.
701 //TopLoc_Location loc = face.Location();
702 if (!loc.IsIdentity()) {
703 gp_Trsf tr = loc.Transformation();
705 for (i = Nodes.Lower(); i <= Nodes.Upper(); i++)
706 Nodes(i).Transform(tr);
710 B.UpdateFace(face, T);
712 BRepMesh_DataMapIteratorOfDataMapOfShapePairOfPolygon It(myInternaledges);
713 for (; It.More(); It.Next()) {
714 const BRepMesh_PairOfPolygon& pair = It.Value();
715 const Handle(Poly_PolygonOnTriangulation)& NOD1 = pair.First();
716 const Handle(Poly_PolygonOnTriangulation)& NOD2 = pair.Last();
718 B.UpdateEdge(TopoDS::Edge(It.Key()), NOD1, T, loc);
720 B.UpdateEdge(TopoDS::Edge(It.Key()), NOD1, NOD2, T, loc);
726 catch(Standard_Failure)
728 MESH_FAILURE(theface);
731 myStructure.Nullify();
734 //=======================================================================
735 //function : splitSegment
737 //=======================================================================
738 static void splitSegment( BRepMesh_GeomTool& theGT,
739 const Handle(Geom_Surface)& theSurf,
740 const Handle(Geom2d_Curve)& theCurve2d,
741 const BRepAdaptor_Curve& theBAC,
742 const Standard_Real theSquareEDef,
743 const Standard_Real theFirst,
744 const Standard_Real theLast,
745 const Standard_Integer theNbIter)
747 //limit ineration depth
750 gp_Pnt2d uvf, uvl, uvm;
751 gp_Pnt P3dF, P3dL, midP3d, midP3dFromSurf;
752 Standard_Real midpar;
754 if(Abs(theLast - theFirst) < 2*Precision::PConfusion())
757 theCurve2d->D0(theFirst, uvf);
758 theCurve2d->D0(theLast, uvl);
760 P3dF = theSurf->Value(uvf.X(), uvf.Y());
761 P3dL = theSurf->Value(uvl.X(), uvl.Y());
763 if(P3dF.SquareDistance(P3dL) < theSquareEDef)
766 uvm = gp_Pnt2d((uvf.XY() + uvl.XY())*0.5);
767 midP3dFromSurf = theSurf->Value(uvm.X(), uvm.Y());
769 gp_XYZ aVec = P3dL.XYZ()-P3dF.XYZ();
772 gp_XYZ Vec1 = midP3dFromSurf.XYZ() - P3dF.XYZ();
773 Standard_Real aModulus = Vec1.Dot(aVec);
774 gp_XYZ aProj = aVec*aModulus;
775 gp_XYZ aDist = Vec1 - aProj;
777 if(aDist.SquareModulus() < theSquareEDef)
780 midpar = (theFirst + theLast) * 0.5;
781 theBAC.D0(midpar, midP3d);
782 theGT.AddPoint(midP3d, midpar, Standard_False);
784 splitSegment(theGT, theSurf, theCurve2d, theBAC, theSquareEDef, theFirst, midpar, theNbIter+1);
785 splitSegment(theGT, theSurf, theCurve2d, theBAC, theSquareEDef, midpar, theLast, theNbIter+1);
788 //=======================================================================
791 //=======================================================================
792 void BRepMesh_FastDiscret::Add( const TopoDS_Edge& theEdge,
793 const TopoDS_Face& theFace,
794 const Handle(BRepAdaptor_HSurface)& theGFace,
795 const Handle(Geom2d_Curve)& theC2d,
796 const TopTools_IndexedDataMapOfShapeListOfShape& theAncestors,
797 const Standard_Real theDefEdge,
798 const Standard_Real theFirst,
799 const Standard_Real theLast)
801 const TopAbs_Orientation orEdge = theEdge.Orientation();
802 if (orEdge == TopAbs_EXTERNAL) return;
804 const Standard_Boolean isEdgeBound = myEdges.IsBound(theEdge);
808 if (Update(theEdge, theFace, theC2d, theDefEdge, theFirst, theLast))
814 TopoDS_Vertex pBegin, pEnd;
815 TopExp::Vertices(theEdge, pBegin, pEnd);
816 if (pBegin.IsNull() || pEnd.IsNull())
821 Standard_Real wFirst, wLast;
822 BRep_Tool::Range(theEdge, theFace, wFirst, wLast);
824 gp_Pnt2d uvFirst, uvLast;
825 BRep_Tool::UVPoints(theEdge, theFace, uvFirst, uvLast);
827 const Standard_Boolean sameUV = uvFirst.IsEqual(uvLast, Precision::PConfusion());
829 //Control vertexes tolerances
830 gp_Pnt pFirst = theGFace->Value(uvFirst.X(), uvFirst.Y());
831 gp_Pnt pLast = theGFace->Value(uvLast.X(), uvLast.Y());
833 Standard_Real mindist = 10. * Max(pFirst.Distance(BRep_Tool::Pnt(pBegin)),
834 pLast.Distance(BRep_Tool::Pnt(pEnd)));
836 if(mindist < BRep_Tool::Tolerance(pBegin) ||
837 mindist < BRep_Tool::Tolerance(pEnd) ) mindist = theDefEdge;
839 // control of degenerated non-coded edges.
841 Standard_Boolean degener = BRep_Tool::Degenerated(theEdge);
845 if (pBegin.IsSame(pEnd))
847 // calculation of the length of the edge in 3D
848 Standard_Real longueur = 0.0;
849 Standard_Real du = (wLast-wFirst)/20;
851 BRepAdaptor_Curve BC(theEdge);
853 Standard_Real tolV = BRep_Tool::Tolerance(pBegin);
854 Standard_Real tolV2 = 1.2*tolV;
855 for (Standard_Integer l = 1; l <= 20; l++) {
856 BC.D0(wFirst + l*du, P2);
857 longueur += P1.Distance(P2);
858 if (longueur > tolV2) break;
862 if (longueur < tolV2)
864 degener = Standard_True;
872 // 1. is it really sameUV without being degenerated
874 theC2d->D0(theFirst, uvF);
875 theC2d->D0(theLast, uvL);
876 if (!uvFirst.IsEqual(uvF, Precision::PConfusion()))
880 if (!uvLast.IsEqual(uvL, Precision::PConfusion()))
888 // Process first vertex
889 Standard_Integer ipf;
890 if (myVertices.IsBound(pBegin))
892 ipf = myVertices.Find(pBegin);
896 if (sameUV && myVertices.IsBound(pEnd))
898 ipf = myVertices.Find(pEnd);
904 myLocation3d.Bind(ipf, BRep_Tool::Pnt(pBegin));
906 myVertices.Bind(pBegin, ipf);
908 theUV = BRepMesh_FastDiscretFace::FindUV(pBegin, uvFirst, ipf, theGFace, mindist, myLocation2d);
909 BRepMesh_Vertex vf(theUV, ipf, BRepMesh_Frontier);
910 Standard_Integer ivf = myStructure->AddNode(vf);
912 // Process last vertex
913 Standard_Integer ipl;
914 if (pEnd.IsSame(pBegin))
920 if (myVertices.IsBound(pEnd))
922 ipl = myVertices.Find(pEnd);
934 myLocation3d.Bind(ipl, BRep_Tool::Pnt(pEnd));
936 myVertices.Bind(pEnd,ipl);
939 theUV = BRepMesh_FastDiscretFace::FindUV(pEnd, uvLast, ipl, theGFace, mindist, myLocation2d);
940 BRepMesh_Vertex vl(theUV, ipl, BRepMesh_Frontier);
941 Standard_Integer ivl= myStructure->AddNode(vl);
943 Standard_Integer isvf = myVemap.FindIndex(ivf);
944 if (isvf == 0) isvf = myVemap.Add(ivf);
945 Standard_Integer isvl = myVemap.FindIndex(ivl);
946 if (isvl == 0) isvl = myVemap.Add(ivl);
948 Standard_Real otherdefedge = 0.5*theDefEdge;
953 Handle(Poly_PolygonOnTriangulation) P1;
957 Handle(Poly_PolygonOnTriangulation) P2;
962 TColStd_Array1OfInteger Nodes(1, 2), NodInStruct(1, 2);
963 TColStd_Array1OfReal Param(1, 2);
965 NodInStruct(1) = ipf;
969 NodInStruct(2) = ipl;
973 P1 = new Poly_PolygonOnTriangulation(Nodes, Param);
974 P2 = new Poly_PolygonOnTriangulation(NodInStruct, Param);
978 if (orEdge == TopAbs_INTERNAL) otherdefedge *= 0.5;
980 BRepAdaptor_Curve cons;
981 Standard_Boolean isSameParam = BRep_Tool::SameParameter(theEdge);
984 cons.Initialize(theEdge);
988 cons.Initialize(theEdge, theFace);
992 Standard_Integer nbpmin = 2;
993 if (cons.GetType() == GeomAbs_Circle) nbpmin = 4; //OCC287
994 BRepMesh_GeomTool GT(cons, wFirst, wLast, 0.5*myAngle, otherdefedge, nbpmin);
996 // PTv, chl/922/G9, Take into account internal vertices
997 // it is necessary for internal edges, which do not split other edges, by their vertex
998 TopoDS_Iterator exV(theEdge);
999 for ( ; exV.More(); exV.Next() )
1001 TopoDS_Vertex aIntV = TopoDS::Vertex(exV.Value());
1002 if ( aIntV.Orientation() == TopAbs_INTERNAL )
1003 GT.AddPoint(BRep_Tool::Pnt(aIntV),
1004 BRep_Tool::Parameter(aIntV, theEdge),
1009 Standard_Integer nbnodes = GT.NbPoints();
1010 //Check deflection in 2d space for improvement of edge tesselation.
1011 if( isSameParam && nbnodes > 1)
1013 Standard_Real aSquareEdgeDef = otherdefedge * otherdefedge;
1014 const TopTools_ListOfShape& lf = theAncestors.FindFromKey(theEdge);
1015 TopTools_ListIteratorOfListOfShape itl(lf);
1016 for (; itl.More(); itl.Next()) {
1017 const TopoDS_Face& aFace = TopoDS::Face (itl.Value());
1019 TopLoc_Location aLoc;
1020 Standard_Real aF, aL;
1021 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
1022 const Handle(Standard_Type)& aType = aSurf->DynamicType();
1023 if(aType == STANDARD_TYPE(Geom_Plane))
1025 Handle(Geom2d_Curve) aCurve2d = BRep_Tool::CurveOnSurface(theEdge, aFace, aF, aL);
1026 if(Abs(aF-wFirst)>Precision::PConfusion()||Abs(aL-wLast)>Precision::PConfusion())
1031 nbnodes = GT.NbPoints();
1032 TColStd_Array1OfReal aParamArray(1, nbnodes);
1033 for (i = 1; i <= nbnodes; i++)
1035 GT.Value(cons, theGFace, i, parf, P3d, uvf);
1036 aParamArray.SetValue(i, parf);
1038 for (i = 1; i < nbnodes; i++)
1040 splitSegment(GT, aSurf, aCurve2d, cons, aSquareEdgeDef, aParamArray(i), aParamArray(i+1), 1);
1045 // Creation of polygons on triangulation:
1047 nbnodes = GT.NbPoints();
1049 TColStd_Array1OfInteger Nodes(1, nbnodes);
1050 TColStd_Array1OfInteger NodInStruct(1, nbnodes);
1051 TColStd_Array1OfReal Param(1, nbnodes);
1053 // processing of the 1st point:
1055 NodInStruct(1) = ipf;
1059 Nodes(nbnodes) = isvl;
1060 NodInStruct(nbnodes) = ipl;
1061 Param(nbnodes) = wLast;
1065 Standard_Integer iv2;
1066 for (i = 2; i < GT.NbPoints(); i++)
1069 GT.Value(cons, theGFace, i, puv, P3d, uv);
1071 myLocation3d.Bind(myNbLocat, P3d);
1072 NodInStruct(i) = myNbLocat;
1074 v2.Initialize(uv.Coord(), myNbLocat, BRepMesh_OnCurve);
1075 iv2=myStructure->AddNode(v2);
1077 Standard_Integer isv = myVemap.FindIndex(iv2);
1078 if (isv == 0) isv = myVemap.Add(iv2);
1080 NodInStruct(i) = myNbLocat;
1083 if (orEdge == TopAbs_FORWARD)
1084 myStructure->AddLink(BRepMesh_Edge(ivf, iv2, BRepMesh_Frontier));
1085 else if (orEdge == TopAbs_REVERSED)
1086 myStructure->AddLink(BRepMesh_Edge(iv2, ivf, BRepMesh_Frontier));
1087 else if (orEdge == TopAbs_INTERNAL)
1088 myStructure->AddLink(BRepMesh_Edge(ivf, iv2, BRepMesh_Fixed));
1093 P1 = new Poly_PolygonOnTriangulation(Nodes, Param);
1094 P2 = new Poly_PolygonOnTriangulation(NodInStruct, Param);
1097 P2->Deflection(otherdefedge);
1098 BRepMesh_PairOfPolygon pair;
1100 myEdges.Bind(theEdge, pair);
1103 if (orEdge == TopAbs_FORWARD)
1104 myStructure->AddLink(BRepMesh_Edge(ivf, ivl, BRepMesh_Frontier));
1105 else if (orEdge == TopAbs_REVERSED)
1106 myStructure->AddLink(BRepMesh_Edge(ivl, ivf, BRepMesh_Frontier));
1107 else if (orEdge == TopAbs_INTERNAL)
1108 myStructure->AddLink(BRepMesh_Edge(ivf, ivl, BRepMesh_Fixed));
1113 // If this Edge has been already checked and it is not degenerated,
1114 // the points of the polygon calculated at the first check are retrieved :
1119 // Create 2d polygon for degenerated edge
1120 TColStd_Array1OfInteger Nodes(1, 2);
1121 TColStd_Array1OfReal PPar(1, 2);
1129 P1 = new Poly_PolygonOnTriangulation(Nodes, PPar);
1133 // retrieve the polygone:
1134 const BRepMesh_PairOfPolygon& pair = myEdges.Find(theEdge);
1135 const Handle(Poly_PolygonOnTriangulation)& P = pair.First();
1136 const TColStd_Array1OfInteger& NOD = P->Nodes();
1137 Handle(TColStd_HArray1OfReal) Par = P->Parameters();
1140 const Standard_Integer nbnodes = NOD.Length();
1141 TColStd_Array1OfInteger Nodes(1, nbnodes);
1142 TColStd_Array1OfReal PPar(1, nbnodes);
1143 Standard_Integer iv2;
1148 Nodes(nbnodes) = isvl;
1149 PPar(nbnodes) = wLast;
1154 if (BRep_Tool::SameParameter(theEdge))
1156 for (i = 2; i < nbnodes; i++)
1158 const Standard_Real puv = Par->Value(i);
1159 theC2d->D0(puv, uv);
1160 v2.Initialize(uv.Coord(), NOD(i), BRepMesh_OnCurve);
1161 iv2 = myStructure->AddNode(v2);
1163 Standard_Integer isv = myVemap.FindIndex(iv2);
1164 if (isv == 0) isv = myVemap.Add(iv2);
1168 if (orEdge==TopAbs_FORWARD)
1169 myStructure->AddLink(BRepMesh_Edge(ivf, iv2, BRepMesh_Frontier));
1170 else if (orEdge == TopAbs_REVERSED)
1171 myStructure->AddLink(BRepMesh_Edge(iv2, ivf, BRepMesh_Frontier));
1172 else if (orEdge == TopAbs_INTERNAL)
1173 myStructure->AddLink(BRepMesh_Edge(ivf, iv2, BRepMesh_Fixed));
1180 const Standard_Real wFold = Par->Value(Par->Lower());
1181 const Standard_Real wLold = Par->Value(Par->Upper());
1183 Standard_Real wKoef = 1.;
1184 if ((wFold != wFirst || wLold != wLast) && wLold != wFold)
1186 wKoef = (wLast - wFirst) / (wLold - wFold);
1189 BRepAdaptor_Curve cons(theEdge, theFace);
1190 Extrema_LocateExtPC pcos;
1191 pcos.Initialize(cons, cons.FirstParameter(),
1192 cons.LastParameter(), Precision::PConfusion());
1194 Standard_Real wPrev;
1195 Standard_Real wCur = wFirst;
1196 Standard_Real wCurFound = wFirst;
1197 for (i = 2; i < nbnodes; i++)
1199 P3d = myLocation3d(NOD(i));
1202 wCur = wFirst + wKoef*(Par->Value(i) - wFold);
1203 wCurFound += (wCur - wPrev);
1204 pcos.Perform(P3d, wCurFound);
1205 if (pcos.IsDone()) wCurFound = pcos.Point().Parameter();
1206 theC2d->D0(wCurFound, uv);
1207 v2.Initialize(uv.Coord(), NOD(i), BRepMesh_OnCurve);
1208 iv2 = myStructure->AddNode(v2);
1210 Standard_Integer isv = myVemap.FindIndex(iv2);
1211 if (isv == 0) isv = myVemap.Add(iv2);
1213 PPar(i) = wCurFound;
1215 if (orEdge==TopAbs_FORWARD)
1216 myStructure->AddLink(BRepMesh_Edge(ivf, iv2, BRepMesh_Frontier));
1217 else if (orEdge == TopAbs_REVERSED)
1218 myStructure->AddLink(BRepMesh_Edge(iv2, ivf, BRepMesh_Frontier));
1219 else if (orEdge == TopAbs_INTERNAL)
1220 myStructure->AddLink(BRepMesh_Edge(ivf, iv2, BRepMesh_Fixed));
1227 P1 = new Poly_PolygonOnTriangulation(Nodes, PPar);
1230 if (orEdge == TopAbs_FORWARD)
1231 myStructure->AddLink(BRepMesh_Edge(ivf, ivl, BRepMesh_Frontier));
1232 else if (orEdge == TopAbs_REVERSED)
1233 myStructure->AddLink(BRepMesh_Edge(ivl, ivf, BRepMesh_Frontier));
1234 else if (orEdge == TopAbs_INTERNAL)
1235 myStructure->AddLink(BRepMesh_Edge(ivf, ivl, BRepMesh_Fixed));
1240 P1->Deflection(theDefEdge);
1241 if (myInternaledges.IsBound(theEdge))
1243 BRepMesh_PairOfPolygon& pair = myInternaledges.ChangeFind(theEdge);
1244 if (orEdge == TopAbs_REVERSED)
1251 BRepMesh_PairOfPolygon pair1;
1253 myInternaledges.Bind(theEdge, pair1);
1258 //=======================================================================
1259 //function : Update(edge)
1261 //=======================================================================
1262 Standard_Boolean BRepMesh_FastDiscret::Update(const TopoDS_Edge& theEdge,
1263 const TopoDS_Face& theFace,
1264 const Handle(Geom2d_Curve)& theC2d,
1265 const Standard_Real theDefEdge,
1266 const Standard_Real theFirst,
1267 const Standard_Real theLast)
1269 TopLoc_Location Loc;
1270 Handle(Poly_Triangulation) T, TNull;
1271 Handle(Poly_PolygonOnTriangulation) Poly, NullPoly;
1273 Standard_Integer i = 1;
1274 Standard_Boolean found = Standard_False;
1277 BRep_Tool::PolygonOnTriangulation(theEdge,Poly,T,Loc,i);
1279 if (!found && !T.IsNull() && T->HasUVNodes() &&
1280 !Poly.IsNull() && Poly->HasParameters())
1282 if (Poly->Deflection() <= 1.1*theDefEdge)
1284 // 2d vertex indices
1285 TopAbs_Orientation orEdge = theEdge.Orientation();
1286 Standard_Integer iv1, iv2, ivl;
1287 Standard_Integer isv1, isv, isvl;
1289 // Get range on 2d curve
1290 Standard_Real wFirst, wLast;
1291 BRep_Tool::Range(theEdge, theFace, wFirst, wLast);
1293 // Get end points on 2d curve
1294 gp_Pnt2d uvFirst, uvLast;
1295 BRep_Tool::UVPoints(theEdge, theFace, uvFirst, uvLast);
1298 TopoDS_Vertex pBegin, pEnd;
1299 TopExp::Vertices(theEdge,pBegin,pEnd);
1301 const Standard_Boolean sameUV =
1302 uvFirst.IsEqual(uvLast, Precision::PConfusion());
1304 //Controle vertice tolerances
1305 BRepAdaptor_Surface BS(theFace, Standard_False);
1306 Handle(BRepAdaptor_HSurface) gFace = new BRepAdaptor_HSurface(BS);
1309 gp_Pnt pFirst = gFace->Value(uvFirst.X(), uvFirst.Y());
1310 gp_Pnt pLast = gFace->Value(uvLast.X(), uvLast.Y());
1312 Standard_Real mindist = 10. * Max(pFirst.Distance(BRep_Tool::Pnt(pBegin)),
1313 pLast.Distance(BRep_Tool::Pnt(pEnd)));
1315 if (mindist < BRep_Tool::Tolerance(pBegin) ||
1316 mindist < BRep_Tool::Tolerance(pEnd) ) mindist = theDefEdge;
1320 // 1. is it really sameUV without being degenerated
1322 theC2d->D0(theFirst, uvF);
1323 theC2d->D0(theLast, uvL);
1324 if (!uvFirst.IsEqual(uvF, Precision::PConfusion())) {
1327 if (!uvLast.IsEqual(uvL, Precision::PConfusion())) {
1332 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1333 const TColStd_Array1OfInteger& Indices = Poly->Nodes();
1334 Handle(TColStd_HArray1OfReal) Param = Poly->Parameters();
1336 const Standard_Integer nbnodes = Indices.Length();
1337 TColStd_Array1OfInteger NewNodes(1, nbnodes);
1338 TColStd_Array1OfInteger NewNodInStruct(1, nbnodes);
1343 // Process first vertex
1344 Standard_Integer ipf;
1345 if (myVertices.IsBound(pBegin))
1347 ipf = myVertices.Find(pBegin);
1351 if (sameUV && myVertices.IsBound(pEnd))
1353 ipf = myVertices.Find(pEnd);
1357 P3d = Nodes(Indices(1));
1358 if (!Loc.IsIdentity())
1359 P3d.Transform(Loc.Transformation());
1361 myLocation3d.Bind(myNbLocat,P3d);
1364 myVertices.Bind(pBegin,ipf);
1366 NewNodInStruct(1) = ipf;
1367 theUV = BRepMesh_FastDiscretFace::FindUV(pBegin, uvFirst, ipf, gFace, mindist, myLocation2d);
1368 BRepMesh_Vertex vf(theUV,ipf,BRepMesh_Frontier);
1369 iv1 = myStructure->AddNode(vf);
1370 isv1 = myVemap.FindIndex(iv1);
1371 if (isv1 == 0) isv1 = myVemap.Add(iv1);
1374 // Process last vertex
1375 Standard_Integer ipl;
1376 if (pEnd.IsSame(pBegin))
1382 if (myVertices.IsBound(pEnd))
1384 ipl = myVertices.Find(pEnd);
1397 myLocation3d.Bind(myNbLocat,Nodes(Indices(nbnodes)).Transformed(Loc.Transformation()));
1400 myVertices.Bind(pEnd,ipl);
1403 NewNodInStruct(nbnodes) = ipl;
1404 theUV = BRepMesh_FastDiscretFace::FindUV(pEnd, uvLast, ipl, gFace, mindist, myLocation2d);
1405 BRepMesh_Vertex vl(theUV,ipl,BRepMesh_Frontier);
1407 ivl = myStructure->AddNode(vl);
1408 isvl = myVemap.FindIndex(ivl);
1409 if (isvl == 0) isvl = myVemap.Add(ivl);
1411 NewNodes(nbnodes) = isvl;
1416 if (BRep_Tool::SameParameter(theEdge))
1418 for (i = 2; i < Indices.Length(); i++)
1421 P3d = Nodes(Indices(i));
1422 if (!Loc.IsIdentity())
1423 P3d.Transform(Loc.Transformation());
1425 myLocation3d.Bind(myNbLocat, P3d);
1426 NewNodInStruct(i) = myNbLocat;
1428 uv = theC2d->Value(Param->Value(i));
1429 v.Initialize(uv.Coord(), myNbLocat, BRepMesh_Frontier);
1430 iv2 = myStructure->AddNode(v);
1431 isv = myVemap.FindIndex(iv2);
1432 if (isv == 0) isv = myVemap.Add(iv2);
1436 if (orEdge == TopAbs_FORWARD)
1437 myStructure->AddLink(BRepMesh_Edge(iv1,iv2,BRepMesh_Frontier));
1438 else if (orEdge == TopAbs_REVERSED)
1439 myStructure->AddLink(BRepMesh_Edge(iv2,iv1,BRepMesh_Frontier));
1440 else if (orEdge == TopAbs_INTERNAL)
1441 myStructure->AddLink(BRepMesh_Edge(iv1,iv2,BRepMesh_Fixed));
1447 if (orEdge == TopAbs_FORWARD)
1448 myStructure->AddLink(BRepMesh_Edge(iv1,ivl,BRepMesh_Frontier));
1449 else if (orEdge == TopAbs_REVERSED)
1450 myStructure->AddLink(BRepMesh_Edge(ivl,iv1,BRepMesh_Frontier));
1451 else if (orEdge == TopAbs_INTERNAL)
1452 myStructure->AddLink(BRepMesh_Edge(iv1,ivl,BRepMesh_Fixed));
1459 const Standard_Real wFold = Param->Value(Param->Lower());
1460 const Standard_Real wLold = Param->Value(Param->Upper());
1462 Standard_Real wKoef = 1.;
1463 if ((wFold != wFirst || wLold != wLast) && wLold != wFold)
1465 wKoef = (wLast - wFirst) / (wLold - wFold);
1468 BRepAdaptor_Curve cons(theEdge, theFace);
1469 Extrema_LocateExtPC pcos;
1470 pcos.Initialize(cons, cons.FirstParameter(),
1471 cons.LastParameter(), Precision::PConfusion());
1473 Standard_Real wPrev;
1474 Standard_Real wCur = wFirst;
1475 Standard_Real wCurFound = wFirst;
1476 for (i = 2; i < Indices.Length(); i++)
1479 P3d = Nodes(Indices(i));
1480 if (!Loc.IsIdentity())
1481 P3d.Transform(Loc.Transformation());
1483 myLocation3d.Bind(myNbLocat, P3d);
1484 NewNodInStruct(i) = myNbLocat;
1487 wCur = wFirst + wKoef*(Param->Value(i) - wFold);
1488 wCurFound += (wCur - wPrev);
1489 pcos.Perform(P3d, wCurFound);
1490 if (pcos.IsDone()) wCurFound = pcos.Point().Parameter();
1491 theC2d->D0(wCurFound, uv);
1492 v.Initialize(uv.Coord(), myNbLocat, BRepMesh_Frontier);
1493 iv2 = myStructure->AddNode(v);
1494 isv = myVemap.FindIndex(iv2);
1495 if (isv == 0) isv = myVemap.Add(iv2);
1500 if (orEdge == TopAbs_FORWARD)
1501 myStructure->AddLink(BRepMesh_Edge(iv1,iv2,BRepMesh_Frontier));
1502 else if (orEdge == TopAbs_REVERSED)
1503 myStructure->AddLink(BRepMesh_Edge(iv2,iv1,BRepMesh_Frontier));
1504 else if (orEdge == TopAbs_INTERNAL)
1505 myStructure->AddLink(BRepMesh_Edge(iv1,iv2,BRepMesh_Fixed));
1511 if (orEdge == TopAbs_FORWARD)
1512 myStructure->AddLink(BRepMesh_Edge(iv1,ivl,BRepMesh_Frontier));
1513 else if (orEdge == TopAbs_REVERSED)
1514 myStructure->AddLink(BRepMesh_Edge(ivl,iv1,BRepMesh_Frontier));
1515 else if (orEdge == TopAbs_INTERNAL)
1516 myStructure->AddLink(BRepMesh_Edge(iv1,ivl,BRepMesh_Fixed));
1520 Handle(Poly_PolygonOnTriangulation) P1 =
1521 new Poly_PolygonOnTriangulation(NewNodes, Param->Array1());
1522 P1->Deflection(theDefEdge);
1523 if (myInternaledges.IsBound(theEdge))
1525 BRepMesh_PairOfPolygon& pair = myInternaledges.ChangeFind(theEdge);
1526 if (theEdge.Orientation() == TopAbs_REVERSED)
1533 BRepMesh_PairOfPolygon pair1;
1535 myInternaledges.Bind(theEdge, pair1);
1538 Handle(Poly_PolygonOnTriangulation) P2 =
1539 new Poly_PolygonOnTriangulation(NewNodInStruct, Param->Array1());
1540 P2->Deflection(theDefEdge);
1541 BRepMesh_PairOfPolygon pair;
1543 myEdges.Bind(theEdge, pair);
1545 found = Standard_True;
1550 B.UpdateEdge(theEdge,NullPoly,T,Loc);
1551 B.UpdateFace(theFace,TNull);
1554 else if (!T.IsNull() && !T->HasUVNodes())
1557 B.UpdateEdge(theEdge,NullPoly,T,Loc);
1558 B.UpdateFace(theFace,TNull);
1561 while (!Poly.IsNull());
1566 //=======================================================================
1569 //=======================================================================
1570 Standard_Integer BRepMesh_FastDiscret::NbTriangles() const
1572 return myStructure->NbElements();
1575 //=======================================================================
1576 //function : Triangle
1578 //=======================================================================
1580 const BRepMesh_Triangle& BRepMesh_FastDiscret::Triangle
1581 (const Standard_Integer Index) const
1583 return myStructure->GetElement(Index);
1586 //=======================================================================
1587 //function : NbEdges
1589 //=======================================================================
1591 Standard_Integer BRepMesh_FastDiscret::NbEdges() const
1593 return myStructure->NbLinks();
1596 //=======================================================================
1599 //=======================================================================
1601 const BRepMesh_Edge& BRepMesh_FastDiscret::Edge(const Standard_Integer Index) const
1603 return myStructure->GetLink(Index);
1606 //=======================================================================
1607 //function : NbVertices
1609 //=======================================================================
1611 Standard_Integer BRepMesh_FastDiscret::NbVertices() const
1613 return myStructure->NbNodes();
1616 //=======================================================================
1619 //=======================================================================
1621 const BRepMesh_Vertex& BRepMesh_FastDiscret::Vertex
1622 (const Standard_Integer Index) const
1624 return myStructure->GetNode(Index);
1627 //=======================================================================
1630 //=======================================================================
1632 const gp_Pnt& BRepMesh_FastDiscret::Pnt(const Standard_Integer Index) const
1634 return myLocation3d(myStructure->GetNode(Index).Location3d());
1637 //=======================================================================
1638 //function : VerticesOfDomain
1640 //=======================================================================
1642 void BRepMesh_FastDiscret::VerticesOfDomain(BRepMesh_MapOfInteger& Indices) const
1646 // recuperate from the map of edges.
1647 const BRepMesh_MapOfInteger& edmap = myStructure->LinkOfDomain();
1649 // iterator on edges.
1650 BRepMesh_MapOfInteger::Iterator iter(edmap);
1652 Standard_Integer ind_edge;
1653 for (iter.Reset(); iter.More(); iter.Next()) {
1654 ind_edge = iter.Key();
1655 const BRepMesh_Edge& Ed = Edge(ind_edge);
1656 Indices.Add(Ed.FirstNode());
1657 Indices.Add(Ed.LastNode());
1661 BRepMesh_Status BRepMesh_FastDiscret::CurrentFaceStatus() const
1666 //=======================================================================
1667 //function : GetFaceAttribute
1669 //=======================================================================
1671 Standard_Boolean BRepMesh_FastDiscret::GetFaceAttribute(const TopoDS_Face& theFace,
1672 Handle(BRepMesh_FaceAttribute)& theFattrib) const
1674 if(myMapattrib.IsBound(theFace))
1676 theFattrib = myMapattrib(theFace);
1677 return Standard_True;
1679 return Standard_False;
1682 //=======================================================================
1683 //function : RemoveFaceAttribute
1685 //=======================================================================
1687 void BRepMesh_FastDiscret::RemoveFaceAttribute(const TopoDS_Face& theFace)
1689 if(myMapattrib.IsBound(theFace))
1690 myMapattrib.UnBind(theFace);
1693 //=======================================================================
1694 //function : CreateMutexesForSubShapes
1696 //=======================================================================
1697 void BRepMesh_FastDiscret::CreateMutexesForSubShapes(const TopoDS_Shape& theShape,
1698 const TopAbs_ShapeEnum theType)
1700 myMutexProvider.CreateMutexesForSubShapes(theShape, theType);
1703 //=======================================================================
1704 //function : RemoveAllMutexes
1706 //=======================================================================
1707 void BRepMesh_FastDiscret::RemoveAllMutexes()
1709 myMutexProvider.RemoveAllMutexes();