1 // Created on: 1993-09-22
2 // Created by: Didier PIFFAULT
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <AppCont_ContMatrices.hxx>
19 #include <Bnd_Box.hxx>
20 #include <BRep_Builder.hxx>
21 #include <BRep_Tool.hxx>
22 #include <BRepAdaptor_Surface.hxx>
23 #include <BRepBndLib.hxx>
24 #include <BRepBuilderAPI_MakeFace.hxx>
25 #include <BRepBuilderAPI_MakePolygon.hxx>
26 #include <BRepBuilderAPI_MakeVertex.hxx>
27 #include <BRepLib.hxx>
28 #include <BRepMesh_DataStructureOfDelaun.hxx>
29 #include <BRepMesh_Delaun.hxx>
30 #include <BRepMesh_Edge.hxx>
31 #include <BRepMesh_FastDiscret.hxx>
32 #include <BRepMesh_IncrementalMesh.hxx>
33 #include <BRepMesh_Triangle.hxx>
34 #include <BRepMesh_Vertex.hxx>
35 #include <BRepTest.hxx>
36 #include <BRepTools.hxx>
38 #include <CSLib_DerivativeStatus.hxx>
41 #include <Draw_Appli.hxx>
42 #include <Draw_Interpretor.hxx>
43 #include <Draw_Marker3D.hxx>
44 #include <Draw_MarkerShape.hxx>
45 #include <Draw_Segment2D.hxx>
46 #include <DrawTrSurf.hxx>
47 #include <Extrema_LocateExtPC.hxx>
48 #include <GCPnts_UniformAbscissa.hxx>
49 #include <Geom_Curve.hxx>
50 #include <Geom_Plane.hxx>
51 #include <Geom_Surface.hxx>
52 #include <GeomAdaptor_Curve.hxx>
53 #include <GeometryTest.hxx>
55 #include <gp_Trsf.hxx>
57 #include <math_Matrix.hxx>
58 #include <math_Vector.hxx>
59 #include <MeshTest.hxx>
60 #include <MeshTest_DrawableMesh.hxx>
62 #include <Poly_Connect.hxx>
63 #include <Poly_PolygonOnTriangulation.hxx>
64 #include <Poly_Triangulation.hxx>
65 #include <Precision.hxx>
66 #include <Standard_Stream.hxx>
67 #include <TColgp_Array1OfPnt2d.hxx>
68 #include <TCollection_AsciiString.hxx>
69 #include <TColStd_HArray1OfInteger.hxx>
70 #include <TColStd_ListIteratorOfListOfInteger.hxx>
71 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
72 #include <TopAbs_ShapeEnum.hxx>
73 #include <TopExp_Explorer.hxx>
74 #include <TopLoc_Location.hxx>
76 #include <TopoDS_Compound.hxx>
77 #include <TopoDS_Edge.hxx>
78 #include <TopoDS_Face.hxx>
79 #include <TopoDS_Shape.hxx>
80 #include <TopoDS_Wire.hxx>
81 #include <TopTools_ListIteratorOfListOfShape.hxx>
82 #include <TopTools_MapIteratorOfMapOfShape.hxx>
85 //epa Memory leaks test
88 Standard_IMPORT Draw_Viewer dout;
91 #define MAX2(X, Y) ( Abs(X) > Abs(Y)? Abs(X) : Abs(Y) )
92 #define MAX3(X, Y, Z) ( MAX2 ( MAX2(X,Y) , Z) )
96 #define ONETHIRD 0.333333333333333333333333333333333333333333333333333333333333
97 #define TWOTHIRD 0.666666666666666666666666666666666666666666666666666666666666
99 #ifdef OCCT_DEBUG_MESH_CHRONO
100 #include <OSD_Chronometer.hxx>
101 Standard_Integer D0Control, D0Internal, D0Unif, D0Edges, NbControls;
102 OSD_Chronometer chTotal, chInternal, chControl, chUnif, chAddPoint;
103 OSD_Chronometer chEdges, chMaillEdges, chEtuInter, chLastControl, chStock;
104 OSD_Chronometer chAdd11, chAdd12, chAdd2, chUpdate, chPointValid;
105 OSD_Chronometer chIsos, chPointsOnIsos;
108 //=======================================================================
109 //function : incrementalmesh
111 //=======================================================================
112 static Standard_Integer incrementalmesh(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
117 Builds triangular mesh for the shape\n\
118 usage: incmesh Shape LinearDeflection [options]\n\
120 -a val angular deflection in deg\n\
121 (default ~28.64 deg = 0.5 rad)\n\n\
122 -min minimum size parameter limiting size of triangle's\n\
123 edges to prevent sinking into amplification in case\n\
124 of distorted curves and surfaces\n\n\
125 -relative notifies that relative deflection is used\n\
126 (switched off by default)\n\n\
127 -int_vert_off disables insertion of internal vertices into mesh\n\
128 (enabled by default)\n\
129 -surf_def_off disables control of deflection of mesh from real\n\
130 surface (enabled by default)\n\
131 -parallel enables parallel execution (switched off by default)\n\
132 -adaptive enables adaptive computation of minimal value in parametric space\n";
136 TopoDS_Shape aShape = DBRep::Get(argv[1]);
139 di << " Null shapes are not allowed here\n";
143 Standard_Real aLinDeflection = Max(Draw::Atof(argv[2]), Precision::Confusion());
144 Standard_Real aAngDeflection = 0.5;
145 Standard_Real aMinSize = Precision::Confusion();
146 Standard_Boolean isRelative = Standard_False;
147 Standard_Boolean isInParallel = Standard_False;
148 Standard_Boolean isIntVertices = Standard_True;
149 Standard_Boolean isControlSurDef = Standard_True;
150 Standard_Boolean isAdaptiveMin = Standard_False;
154 Standard_Integer i = 3;
157 TCollection_AsciiString aOpt(argv[i++]);
162 else if (aOpt == "-relative")
163 isRelative = Standard_True;
164 else if (aOpt == "-parallel")
165 isInParallel = Standard_True;
166 else if (aOpt == "-int_vert_off")
167 isIntVertices = Standard_False;
168 else if (aOpt == "-surf_def_off")
169 isControlSurDef = Standard_False;
170 else if (aOpt == "-adaptive")
171 isAdaptiveMin = Standard_True;
174 Standard_Real aVal = Draw::Atof(argv[i++]);
176 aAngDeflection = aVal * M_PI / 180.;
177 else if (aOpt == "-min")
185 di << "Incremental Mesh, multi-threading "
186 << (isInParallel ? "ON" : "OFF") << "\n";
188 BRepMesh_FastDiscret::Parameters aMeshParams;
189 aMeshParams.Deflection = aLinDeflection;
190 aMeshParams.Angle = aAngDeflection;
191 aMeshParams.Relative = isRelative;
192 aMeshParams.InParallel = isInParallel;
193 aMeshParams.MinSize = aMinSize;
194 aMeshParams.InternalVerticesMode = isIntVertices;
195 aMeshParams.ControlSurfaceDeflection = isControlSurDef;
196 aMeshParams.AdaptiveMin = isAdaptiveMin;
198 BRepMesh_IncrementalMesh aMesher (aShape, aMeshParams);
200 di << "Meshing statuses: ";
201 Standard_Integer statusFlags = aMesher.GetStatusFlags();
209 for( i = 0; i < 4; i++ )
211 if( (statusFlags >> i) & (Standard_Integer)1 )
219 di << "SelfIntersectingWire ";
235 //=======================================================================
236 //function : MemLeakTest
238 //=======================================================================
240 static Standard_Integer MemLeakTest(Draw_Interpretor&, Standard_Integer /*nbarg*/, const char** /*argv*/)
242 for(int i=0;i<10000;i++)
244 BRepBuilderAPI_MakePolygon w(gp_Pnt(0,0,0),gp_Pnt(0,100,0),gp_Pnt(20,100,0),gp_Pnt(20,0,0));
246 TopoDS_Wire wireShape( w.Wire());
247 BRepBuilderAPI_MakeFace faceBuilder(wireShape);
248 TopoDS_Face f( faceBuilder.Face());
249 BRepMesh_IncrementalMesh im(f,1);
255 //=======================================================================
256 //function : fastdiscret
258 //=======================================================================
260 static Standard_Integer fastdiscret(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
262 if (nbarg < 3) return 1;
264 TopoDS_Shape S = DBRep::Get(argv[1]);
265 if (S.IsNull()) return 1;
267 const Standard_Real d = Draw::Atof(argv[2]);
270 BRepBndLib::Add(S,B);
271 BRepMesh_FastDiscret::Parameters aParams;
272 aParams.Deflection = d;
274 BRepMesh_FastDiscret MESH(B,aParams);
276 //Standard_Integer NbIterations = MESH.NbIterations();
277 //if (nbarg > 4) NbIterations = Draw::Atoi(argv[4]);
278 //MESH.NbIterations() = NbIterations;
280 di<<"Starting FastDiscret with :"<<"\n";
281 di<<" Deflection="<<d<<"\n";
282 di<<" Angle="<<0.5<<"\n";
284 Handle(Poly_Triangulation) T;
285 BRep_Builder aBuilder;
288 // Clear existing triangulations
289 for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next())
290 aBuilder.UpdateFace(TopoDS::Face(ex.Current()),T);
294 TopoDS_Compound aCompGood, aCompFailed, aCompViolating;
297 Standard_Integer nbtriangles = 0, nbnodes = 0, nbfailed = 0, nbviolating = 0;
298 Standard_Real maxdef = 0.0;
299 for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next())
301 T = BRep_Tool::Triangulation(TopoDS::Face(ex.Current()),L);
305 if (aCompFailed.IsNull())
306 aBuilder.MakeCompound(aCompFailed);
307 aBuilder.Add(aCompFailed,ex.Current());
311 nbtriangles += T->NbTriangles();
312 nbnodes += T->NbNodes();
313 if (T->Deflection() > maxdef) maxdef = T->Deflection();
314 if (T->Deflection() > d)
317 if (aCompViolating.IsNull())
318 aBuilder.MakeCompound(aCompViolating);
319 aBuilder.Add(aCompViolating,ex.Current());
323 if (aCompGood.IsNull())
324 aBuilder.MakeCompound(aCompGood);
325 aBuilder.Add(aCompGood,ex.Current());
330 if (!aCompGood.IsNull())
333 strcpy(name,argv[1]);
334 strcat(name,"_good");
335 DBRep::Set(name,aCompGood);
337 if (!aCompFailed.IsNull())
340 strcpy(name,argv[1]);
341 strcat(name,"_failed");
342 DBRep::Set(name,aCompFailed);
344 if (!aCompViolating.IsNull())
347 strcpy(name,argv[1]);
348 strcat(name,"_violating");
349 DBRep::Set(name,aCompViolating);
352 di<<"FastDiscret completed with :"<<"\n";
353 di<<" MaxDeflection="<<maxdef<<"\n";
354 di<<" NbNodes="<<nbnodes<<"\n";
355 di<<" NbTriangles="<<nbtriangles<<"\n";
356 di<<" NbFailed="<<nbfailed<<"\n";
357 di<<" NbViolating="<<nbviolating<<"\n";
363 //=======================================================================
364 //function : triangule
366 //=======================================================================
369 class BRepMesh_Couple
372 BRepMesh_Couple() { myI1 = myI2 = 0; }
373 BRepMesh_Couple(const Standard_Integer I1,
374 const Standard_Integer I2)
375 { myI1 = I1; myI2 = I2; }
377 Standard_Integer myI1;
378 Standard_Integer myI2;
381 inline Standard_Boolean IsEqual(const BRepMesh_Couple& one,
382 const BRepMesh_Couple& other)
384 if (one.myI1 == other.myI1 &&
385 one.myI2 == other.myI2) return Standard_True;
386 else return Standard_False;
389 inline Standard_Integer HashCode(const BRepMesh_Couple& one,
390 const Standard_Integer Upper)
392 return ::HashCode((one.myI1+one.myI2), Upper);
395 typedef NCollection_Map<BRepMesh_Couple> BRepMesh_MapOfCouple;
398 static void AddLink(BRepMesh_MapOfCouple& aMap,
402 Standard_Integer i1 = v1;
403 Standard_Integer i2 = v2;
408 aMap.Add(BRepMesh_Couple(i1,i2));
411 static void MeshStats(const TopoDS_Shape& theSape,
412 Standard_Integer& theNbTri,
413 Standard_Integer& theNbEdges,
414 Standard_Integer& theNbNodes)
420 Handle(Poly_Triangulation) T;
423 for ( TopExp_Explorer ex(theSape, TopAbs_FACE); ex.More(); ex.Next()) {
424 TopoDS_Face F = TopoDS::Face(ex.Current());
425 T = BRep_Tool::Triangulation(F, L);
427 theNbTri += T->NbTriangles();
428 theNbNodes += T->NbNodes();
430 BRepMesh_MapOfCouple aMap;
431 //count number of links
432 Poly_Array1OfTriangle& Trian = T->ChangeTriangles();
433 for(Standard_Integer i = 1; i<=Trian.Length();i++) {
434 Standard_Integer v1, v2, v3;
435 Trian(i).Get(v1,v2,v3);
437 AddLink(aMap, v1, v2);
438 AddLink(aMap, v2, v3);
439 AddLink(aMap, v3, v1);
442 theNbEdges+=aMap.Extent();
447 static Standard_Integer triangule(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
452 const char *id1 = argv[2];
453 TopoDS_Shape aShape = DBRep::Get(id1);
457 di << argv[1] << " ";
459 Standard_Real aDeflection = Draw::Atof(argv[3]);
460 if (aDeflection <= 0.)
462 di << " Incorrect value of deflection!" << "\n";
466 Handle(MeshTest_DrawableMesh) aDMesh =
467 new MeshTest_DrawableMesh(aShape, aDeflection);
469 Draw::Set(argv[1], aDMesh);
471 Standard_Integer nbn, nbl, nbe;
472 MeshStats(aShape, nbe, nbl, nbn);
474 di<<"(Resultat ("<<nbe<<" mailles) ("<<nbl<<" aretes) ("<<nbn<<" sommets))"<<"\n";
476 // passe de verification du maillage.
477 /*Standard_Integer nbc;
478 for (Standard_Integer iLi=1; iLi<= DM->Mesh()->NbEdges(); iLi++) {
479 const BRepMesh_Edge& ed=DM->Mesh()->Edge(iLi);
480 if (ed.Movability()!=BRepMesh_Deleted) {
481 nbc=struc->ElemConnectedTo(iLi).Extent();
482 if (nbc != 1 && nbc != 2) di <<"ERROR MAILLAGE Edge no "<< iLi<<"\n";
489 TopExp_Explorer aFaceIt(aShape, TopAbs_FACE);
490 for (; aFaceIt.More(); aFaceIt.Next())
492 const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
494 TopLoc_Location aLoc = aFace.Location();
495 Handle(Poly_Triangulation) aTriangulation =
496 BRep_Tool::Triangulation(aFace, aLoc);
498 if (!aTriangulation.IsNull())
500 const Standard_Integer aLength = aTriangulation->NbNodes();
501 const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes();
502 for (Standard_Integer i = 1; i <= aLength; ++i)
507 Standard_Real aDelta = 0.;
510 Standard_Real x, y, z, X, Y, Z;
511 aBox.Get(x, y, z, X, Y, Z);
513 aDelta = Max(X - x, Max(Y - y, Z - z));
515 aDelta = aDeflection / aDelta;
518 di << " Ratio between deflection and total shape size is " << aDelta << "\n";
523 //=======================================================================
524 //function : addshape
526 //=======================================================================
528 Standard_Integer addshape(Draw_Interpretor&, Standard_Integer n, const char** a)
531 Handle(MeshTest_DrawableMesh) D =
532 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
533 if (D.IsNull()) return 1;
534 TopoDS_Shape S = DBRep::Get(a[2]);
535 if (S.IsNull()) return 1;
544 //=======================================================================
547 //=======================================================================
549 /*Standard_Integer smooth(Draw_Interpretor&, Standard_Integer n, const char** a)
552 Handle(MeshTest_DrawableMesh) D =
553 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
554 if (D.IsNull()) return 1;
555 Handle(BRepMesh_DataStructureOfDelaun) struc=
557 BRepMesh_Array1OfVertexOfDelaun toto(1,1);
558 BRepMesh_Delaun trial(struc,
561 trial.SmoothMesh(0.1);
567 //=======================================================================
570 //=======================================================================
572 /*static Standard_Integer edges (Draw_Interpretor&, Standard_Integer n, const char** a)
576 Handle(MeshTest_DrawableMesh) D =
577 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
578 if (D.IsNull()) return 1;
579 TopoDS_Shape S = DBRep::Get(a[2]);
580 if (S.IsNull()) return 1;
583 TColStd_SequenceOfInteger& eseq = D->Edges();
584 Handle(BRepMesh_FastDiscret) M = D->Mesh();
585 Handle(BRepMesh_DataStructureOfDelaun) DS = M->Result();
586 Standard_Integer e1, e2, e3, iTri;
587 Standard_Boolean o1, o2, o3;
590 for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
591 const BRepMesh_MapOfInteger& elems = DS->ElemOfDomain();
592 BRepMesh_MapOfInteger::Iterator it;
593 for (it.Initialize(elems); it.More(); it.Next()) {
595 const BRepMesh_Triangle& triang = M->Triangle(iTri);
596 if (triang.Movability()!=BRepMesh_Deleted) {
597 triang.Edges(e1, e2, e3, o1, o2, o3);
606 //for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE);ex.More();ex.Next()) {
614 //=======================================================================
615 //function : vertices
617 //=======================================================================
618 static Standard_Integer vertices(
619 Draw_Interpretor& /*di*/,
620 Standard_Integer /*argc*/,
621 const char** /*argv*/)
625 // TODO: OAN re-implement this command according changes in BRepMesh
629 //Handle(MeshTest_DrawableMesh) aDrawableMesh =
630 // Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(argv[1]));
631 //if (aDrawableMesh.IsNull())
634 //TopoDS_Shape aShape = DBRep::Get(argv[2]);
635 //if (aShape.IsNull())
638 //TColStd_SequenceOfInteger& aVertexSeq = aDrawableMesh->Vertices();
639 //Handle(BRepMesh_FastDiscret) aMesh = aDrawableMesh->Mesh();
641 //TopExp_Explorer aFaceIt(aShape, TopAbs_FACE);
642 //for (; aFaceIt.More(); aFaceIt.Next())
644 // const TopoDS_Face& aFace = TopoDS::Face(aFaceIt.Current());
646 // Handle(BRepMesh_FaceAttribute) aAttribute;
647 // if (aMesh->GetFaceAttribute(aFace, aAttribute))
649 // Handle(BRepMesh_DataStructureOfDelaun) aStructure = aAttribute->EditStructure();
651 // // Recuperate from the map of edges.
652 // const BRepMeshCol::MapOfInteger& aEdgeMap = aStructure->LinksOfDomain();
654 // // Iterator on edges.
655 // BRepMeshCol::MapOfInteger aVertices;
656 // BRepMeshCol::MapOfInteger::Iterator aEdgeIt(aEdgeMap);
657 // for (; aEdgeIt.More(); aEdgeIt.Next())
659 // const BRepMesh_Edge& aEdge = aStructure->GetLink(aEdgeIt.Key());
660 // aVertices.Add(aEdge.FirstNode());
661 // aVertices.Add(aEdge.LastNode());
664 // BRepMeshCol::MapOfInteger::Iterator anIt(vtx);
665 // for ( ; anIt.More(); anIt.Next() )
666 // aVertexSeq.Append(anIt.Key());
674 //=======================================================================
677 //=======================================================================
679 static Standard_Integer medge (Draw_Interpretor&, Standard_Integer n, const char** a)
683 Handle(MeshTest_DrawableMesh) D =
684 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
685 if (D.IsNull()) return 1;
687 Standard_Integer i,j,e;
688 TColStd_SequenceOfInteger& eseq = D->Edges();
689 for (i = 2; i < n; i++) {
690 e = Draw::Atoi(a[i]);
696 while (j <= eseq.Length()) {
712 //=======================================================================
715 //=======================================================================
717 static Standard_Integer mvertex (Draw_Interpretor&, Standard_Integer n, const char** a)
721 Handle(MeshTest_DrawableMesh) D =
722 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
723 if (D.IsNull()) return 1;
725 Standard_Integer i,j,v;
726 TColStd_SequenceOfInteger& vseq = D->Vertices();
727 for (i = 2; i < n; i++) {
728 v = Draw::Atoi(a[i]);
734 while (j <= vseq.Length()) {
749 //=======================================================================
750 //function : triangle
752 //=======================================================================
754 static Standard_Integer triangle (Draw_Interpretor&, Standard_Integer n, const char** a)
758 Handle(MeshTest_DrawableMesh) D =
759 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
760 if (D.IsNull()) return 1;
762 Standard_Integer i,j,v;
763 TColStd_SequenceOfInteger& tseq = D->Triangles();
764 for (i = 2; i < n; i++) {
765 v = Draw::Atoi(a[i]);
771 while (j <= tseq.Length()) {
785 //=======================================================================
786 //function : dumpvertex
788 //=======================================================================
791 Standard_Integer dumpvertex(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
793 if (argc < 2) return 1;
795 Handle(MeshTest_DrawableMesh) D =
796 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(argv[1]));
797 if (D.IsNull()) return 1;
799 Handle(BRepMesh_DataStructureOfDelaun) struc = D->Mesh()->Result();
801 Standard_Integer in=1;
803 in=Draw::Atoi(argv[2]);
806 Standard_Integer nbn=in;
808 nbn=Draw::Atoi(argv[3]);
809 nbn=Min(nbn,struc->NbNodes());
812 for (; in<=nbn; in++) {
813 BRepMesh_Vertex nod=struc->GetNode(in);
814 di<<"(node "<<in<<" (uv "<<nod.Coord().X()
815 <<" "<<nod.Coord().Y()<<") (3d "
816 <<nod.Location3d()<<") ";
817 printdegree(nod.Movability(), di);
819 BRepMesh_ListOfInteger::Iterator tati(struc->LinkNeighboursOf(in));
820 for (; tati.More(); tati.Next()) di<<" "<<tati.Value();
827 //=======================================================================
828 //function : dumpedge
830 //=======================================================================
832 Standard_Integer dumpedge(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
834 if (argc < 2) return 1;
836 Handle(MeshTest_DrawableMesh) D =
837 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(argv[1]));
838 if (D.IsNull()) return 1;
840 Handle(BRepMesh_DataStructureOfDelaun) struc=D->Mesh()->Result();
841 Standard_Integer il=1;
843 il=Draw::Atoi(argv[2]);
846 Standard_Integer nbl=il;
848 nbl=Draw::Atoi(argv[3]);
849 nbl=Min(nbl, struc->NbLinks());
852 for (; il<=nbl; il++) {
853 BRepMesh_Edge edg=struc->GetLink(il);
854 di << "(edge "<<il<<" ("<<edg.FirstNode()<<" "<<edg.LastNode()
856 printdegree(edg.Movability(), di);
858 const BRepMesh_PairOfIndex& pair = struc->ElemConnectedTo(il);
859 for (Standard_Integer j = 1, jn = pair.Extent(); j <= jn; j++)
860 di<<" "<<pair.Index(j);
867 //=======================================================================
868 //function : dumptriangle
870 //=======================================================================
872 Standard_Integer dumptriangle(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
874 if (argc < 2) return 1;
876 Handle(MeshTest_DrawableMesh) D =
877 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(argv[1]));
878 if (D.IsNull()) return 1;
880 Handle(BRepMesh_DataStructureOfDelaun) struc=D->Mesh()->Result();
881 Standard_Integer ie=1;
883 ie=Draw::Atoi(argv[2]);
886 Standard_Integer nbe=ie;
888 nbe=Draw::Atoi(argv[3]);
889 nbe=Min(nbe, struc->NbElements());
892 Standard_Integer e1, e2, e3;
893 Standard_Boolean o1, o2, o3;
895 for (; ie<=nbe; ie++) {
896 BRepMesh_Triangle tri=struc->GetElement(ie);
897 tri.Edges(e1, e2, e3, o1, o2, o3);
901 di<<" (maille "<<ie<<" (links "<<e1<<" "
903 printdegree(tri.Movability(), di);
911 //=======================================================================
912 //function : trianglesinfo
914 //=======================================================================
915 static Standard_Integer trianglesinfo(Draw_Interpretor& di, Standard_Integer n, const char** a)
917 if (n != 2) return 1;
918 TopoDS_Shape S = DBRep::Get(a[1]);
919 if (S.IsNull()) return 1;
921 Handle(Poly_Triangulation) T;
924 Standard_Real MaxDeflection = 0.0;
925 Standard_Integer nbtriangles = 0, nbnodes = 0;
926 for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next()) {
927 TopoDS_Face F = TopoDS::Face(ex.Current());
928 T = BRep_Tool::Triangulation(F, L);
930 nbtriangles += T->NbTriangles();
931 nbnodes += T->NbNodes();
932 if (T->Deflection() > MaxDeflection)
933 MaxDeflection = T->Deflection();
938 di<<"This shape contains " <<nbtriangles<<" triangles."<<"\n";
939 di<<" " <<nbnodes <<" nodes."<<"\n";
940 di<<"Maximal deflection " <<MaxDeflection<<"\n";
942 #ifdef OCCT_DEBUG_MESH_CHRONO
943 Standard_Real tot, addp, unif, contr, inter;
944 Standard_Real edges, mailledges, etuinter, lastcontrol, stock;
945 Standard_Real add11, add12, add2, upda, pointvalid;
946 Standard_Real isos, pointsisos;
947 chTotal.Show(tot); chAddPoint.Show(addp); chUnif.Show(unif);
948 chControl.Show(contr); chInternal.Show(inter);
949 chEdges.Show(edges); chMaillEdges.Show(mailledges);
950 chEtuInter.Show(etuinter); chLastControl.Show(lastcontrol);
952 chAdd11.Show(add11); chAdd12.Show(add12); chAdd2.Show(add2); chUpdate.Show(upda);
953 chPointValid.Show(pointvalid); chIsos.Show(isos); chPointsOnIsos.Show(pointsisos);
956 di <<"temps total de maillage: "<<tot <<" seconds"<< "\n";
957 di <<"dont: "<< "\n";
958 di <<"discretisation des edges: "<<edges <<" seconds---> "<< 100*edges/tot <<" %"<<"\n";
959 di <<"maillage des edges: "<<mailledges <<" seconds---> "<< 100*mailledges/tot <<" %"<<"\n";
960 di <<"controle et points internes: "<<etuinter <<" seconds---> "<< 100*etuinter/tot <<" %"<<"\n";
961 di <<"derniers controles: "<<lastcontrol<<" seconds---> "<< 100*lastcontrol/tot<<" %"<<"\n";
962 di <<"stockage dans la S.D. "<<stock <<" seconds---> "<< 100*stock/tot <<" %"<<"\n";
964 di <<"et plus precisement: "<<"\n";
965 di <<"Add 11ere partie : "<<add11 <<" seconds---> "<<100*add11/tot <<" %"<<"\n";
966 di <<"Add 12ere partie : "<<add12 <<" seconds---> "<<100*add12/tot <<" %"<<"\n";
967 di <<"Add 2eme partie : "<<add2 <<" seconds---> "<<100*add2/tot <<" %"<<"\n";
968 di <<"Update : "<<upda <<" seconds---> "<<100*upda/tot <<" %"<<"\n";
969 di <<"AddPoint : "<<addp <<" seconds---> "<<100*addp/tot <<" %"<<"\n";
970 di <<"UniformDeflection "<<unif <<" seconds---> "<<100*unif/tot <<" %"<<"\n";
971 di <<"Controle : "<<contr <<" seconds---> "<<100*contr/tot <<" %"<<"\n";
972 di <<"Points Internes: "<<inter <<" seconds---> "<<100*inter/tot <<" %"<<"\n";
973 di <<"calcul des isos et du, dv: "<<isos <<" seconds---> "<<100*isos/tot <<" %"<<"\n";
974 di <<"calcul des points sur isos: "<<pointsisos<<" seconds---> "<<100*pointsisos/tot <<" %"<<"\n";
975 di <<"IsPointValid: "<<pointvalid<<" seconds---> "<<100*pointvalid/tot <<" %"<<"\n";
979 di <<"nombre d'appels de controle apres points internes : "<< NbControls << "\n";
980 di <<"nombre de points sur restrictions : "<< D0Edges << "\n";
981 di <<"nombre de points calcules par UniformDeflection : "<< D0Unif << "\n";
982 di <<"nombre de points calcules dans InternalVertices : "<< D0Internal << "\n";
983 di <<"nombre de points calcules dans Control : "<< D0Control << "\n";
984 if (nbnodes-D0Edges != 0) {
985 Standard_Real ratio = (Standard_Real)(D0Internal+D0Control)/ (Standard_Real)(nbnodes-D0Edges);
986 di <<"---> Ratio: (D0Internal+D0Control) / (nbNodes-nbOnEdges) : "<< ratio << "\n";
991 chTotal.Reset(); chAddPoint.Reset(); chUnif.Reset();
992 chControl.Reset(); chInternal.Reset();
993 chEdges.Reset(); chMaillEdges.Reset();
994 chEtuInter.Reset(); chLastControl.Reset();
996 chAdd11.Reset(); chAdd12.Reset(); chAdd2.Reset(); chUpdate.Reset();
997 chPointValid.Reset(); chIsos.Reset(); chPointsOnIsos.Reset();
1004 //=======================================================================
1005 //function : veriftriangles
1007 //=======================================================================
1009 static Standard_Integer veriftriangles(Draw_Interpretor& di, Standard_Integer n, const char** a)
1011 if (n < 2) return 1;
1012 Standard_Boolean quiet = 1;
1013 if (n == 3) quiet = 0;
1014 TopoDS_Shape Sh = DBRep::Get(a[1]);
1015 if (Sh.IsNull()) return 1;
1017 Handle(Poly_Triangulation) T;
1019 Standard_Integer i, n1, n2, n3;
1020 gp_Pnt2d mitri, v1, v2, v3, mi2d1, mi2d2, mi2d3;
1021 gp_XYZ vecEd1, vecEd2, vecEd3;
1022 // Standard_Real dipo, dm, dv, d1, d2, d3, defle;
1023 Standard_Real dipo, dv, d1, d2, d3, defle;
1024 Handle(Geom_Surface) S;
1025 Standard_Integer nbface = 0;
1028 for (ex.Init(Sh, TopAbs_FACE); ex.More(); ex.Next()) {
1029 TopoDS_Face F = TopoDS::Face(ex.Current());
1031 T = BRep_Tool::Triangulation(F, L);
1032 Standard_Real deflemax = 0, deflemin = 1.e100;
1034 Standard_Real defstock = T->Deflection();
1035 const Poly_Array1OfTriangle& triangles = T->Triangles();
1036 const TColgp_Array1OfPnt2d& Nodes2d = T->UVNodes();
1037 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1039 S = BRep_Tool::Surface(F, L);
1041 for(i = 1; i <= triangles.Length(); i++) {
1042 if (F.Orientation() == TopAbs_REVERSED)
1043 triangles(i).Get(n1,n3,n2);
1045 triangles(i).Get(n1,n2,n3);
1047 const gp_XY& xy1 = Nodes2d(n1).XY();
1048 const gp_XY& xy2 = Nodes2d(n2).XY();
1049 const gp_XY& xy3 = Nodes2d(n3).XY();
1051 mi2d1.SetCoord((xy2.X()+xy3.X())*0.5,
1052 (xy2.Y()+xy3.Y())*0.5);
1053 mi2d2.SetCoord((xy1.X()+xy3.X())*0.5,
1054 (xy1.Y()+xy3.Y())*0.5);
1055 mi2d3.SetCoord((xy1.X()+xy2.X())*0.5,
1056 (xy1.Y()+xy2.Y())*0.5);
1058 gp_XYZ p1 = Nodes(n1).Transformed(L.Transformation()).XYZ();
1059 gp_XYZ p2 = Nodes(n2).Transformed(L.Transformation()).XYZ();
1060 gp_XYZ p3 = Nodes(n3).Transformed(L.Transformation()).XYZ();
1065 d1=vecEd1.SquareModulus();
1066 d2=vecEd2.SquareModulus();
1067 d3=vecEd3.SquareModulus();
1069 if (d1!=0. && d2!=0. && d3!=0.) {
1070 gp_XYZ equa(vecEd1^vecEd2);
1073 equa.SetCoord(equa.X()/dv, equa.Y()/dv, equa.Z()/dv);
1077 mitri.SetCoord(ONETHIRD*(xy1.X()+xy2.X()+xy3.X()),
1078 ONETHIRD*(xy1.Y()+xy2.Y()+xy3.Y()));
1079 v1.SetCoord(ONETHIRD*mi2d1.X()+TWOTHIRD*xy1.X(),
1080 ONETHIRD*mi2d1.Y()+TWOTHIRD*xy1.Y());
1081 v2.SetCoord(ONETHIRD*mi2d2.X()+TWOTHIRD*xy2.X(),
1082 ONETHIRD*mi2d2.Y()+TWOTHIRD*xy2.Y());
1083 v3.SetCoord(ONETHIRD*mi2d3.X()+TWOTHIRD*xy3.X(),
1084 ONETHIRD*mi2d3.Y()+TWOTHIRD*xy3.Y());
1086 S->D0(mi2d1.X(), mi2d1.Y(), PP);
1087 PP = PP.Transformed(L.Transformation());
1088 defle = Abs((equa*PP.XYZ())-dipo);
1089 deflemax = Max(deflemax, defle);
1090 deflemin = Min(deflemin, defle);
1092 S->D0(mi2d2.X(), mi2d2.Y(), PP);
1093 PP = PP.Transformed(L.Transformation());
1094 defle = Abs((equa*PP.XYZ())-dipo);
1095 deflemax = Max(deflemax, defle);
1096 deflemin = Min(deflemin, defle);
1098 S->D0(mi2d3.X(), mi2d3.Y(), PP);
1099 PP = PP.Transformed(L.Transformation());
1100 defle = Abs((equa*PP.XYZ())-dipo);
1101 deflemax = Max(deflemax, defle);
1102 deflemin = Min(deflemin, defle);
1104 S->D0(v1.X(), v1.Y(), PP);
1105 PP = PP.Transformed(L.Transformation());
1106 defle = Abs((equa*PP.XYZ())-dipo);
1107 deflemax = Max(deflemax, defle);
1108 deflemin = Min(deflemin, defle);
1110 S->D0(v2.X(), v2.Y(), PP);
1111 PP = PP.Transformed(L.Transformation());
1112 defle = Abs((equa*PP.XYZ())-dipo);
1113 deflemax = Max(deflemax, defle);
1114 deflemin = Min(deflemin, defle);
1116 S->D0(v3.X(), v3.Y(), PP);
1117 PP = PP.Transformed(L.Transformation());
1118 defle = Abs((equa*PP.XYZ())-dipo);
1119 deflemax = Max(deflemax, defle);
1120 deflemin = Min(deflemin, defle);
1122 S->D0(mitri.X(), mitri.Y(), PP);
1123 PP = PP.Transformed(L.Transformation());
1124 defle = Abs((equa*PP.XYZ())-dipo);
1125 deflemax = Max(deflemax, defle);
1126 deflemin = Min(deflemin, defle);
1128 if (defle > defstock) {
1129 di <<"face "<< nbface <<" deflection = " << defle <<" pour "<<defstock <<" stockee."<<"\n";
1135 di <<"face "<< nbface<<", deflemin = "<< deflemin<<", deflemax = "<<deflemax<<"\n";
1148 //=======================================================================
1151 //=======================================================================
1153 Standard_Integer tri2d(Draw_Interpretor&, Standard_Integer n, const char** a)
1156 if (n != 2) return 1;
1157 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
1158 TopoDS_Face F = TopoDS::Face(aLocalShape);
1159 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[1]));
1160 if (F.IsNull()) return 1;
1161 Handle(Poly_Triangulation) T;
1164 T = BRep_Tool::Triangulation(F, L);
1166 // Build the connect tool
1169 Standard_Integer i,j, nFree, nInternal, nbTriangles = T->NbTriangles();
1170 Standard_Integer t[3];
1172 // count the free edges
1174 for (i = 1; i <= nbTriangles; i++) {
1175 pc.Triangles(i,t[0],t[1],t[2]);
1176 for (j = 0; j < 3; j++)
1177 if (t[j] == 0) nFree++;
1180 // allocate the arrays
1181 TColStd_Array1OfInteger Free(1,2*nFree);
1182 nInternal = (3*nbTriangles - nFree) / 2;
1183 TColStd_Array1OfInteger Internal(0,2*nInternal);
1185 Standard_Integer fr = 1, in = 1;
1186 const Poly_Array1OfTriangle& triangles = T->Triangles();
1187 Standard_Integer nodes[3];
1188 for (i = 1; i <= nbTriangles; i++) {
1189 pc.Triangles(i,t[0],t[1],t[2]);
1190 triangles(i).Get(nodes[0],nodes[1],nodes[2]);
1191 for (j = 0; j < 3; j++) {
1192 Standard_Integer k = (j+1) % 3;
1194 Free(fr) = nodes[j];
1195 Free(fr+1) = nodes[k];
1198 // internal edge if this triangle has a lower index than the adjacent
1199 else if (i < t[j]) {
1200 Internal(in) = nodes[j];
1201 Internal(in+1) = nodes[k];
1207 // Display the edges
1208 if (T->HasUVNodes()) {
1209 const TColgp_Array1OfPnt2d& Nodes2d = T->UVNodes();
1211 Handle(Draw_Segment2D) Seg;
1214 Standard_Integer nn;
1215 nn = Free.Length() / 2;
1216 for (i = 1; i <= nn; i++) {
1217 Seg = new Draw_Segment2D(Nodes2d(Free(2*i-1)),
1226 for (i = 1; i <= nn; i++) {
1227 Seg = new Draw_Segment2D(Nodes2d(Internal(2*i-1)),
1228 Nodes2d(Internal(2*i)),
1242 //=======================================================================
1243 //function : wavefront
1245 //=======================================================================
1247 static Standard_Integer wavefront(Draw_Interpretor&, Standard_Integer nbarg, const char** argv)
1249 if (nbarg < 2) return 1;
1251 TopoDS_Shape S = DBRep::Get(argv[1]);
1252 if (S.IsNull()) return 1;
1254 // creation du maillage s'il n'existe pas.
1257 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
1258 BRepBndLib::Add(S, B);
1259 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
1260 Standard_Real aDeflection =
1261 MAX3( aXmax-aXmin , aYmax-aYmin , aZmax-aZmin) * 0.004;
1263 BRepMesh_IncrementalMesh aMesh (S, aDeflection);
1269 Standard_Integer i, nbface = 0;
1270 Standard_Boolean OK = Standard_True;
1272 gp_Vec D2U,D2V,D2UV;
1276 CSLib_DerivativeStatus Status;
1277 CSLib_NormalStatus NStat;
1278 Standard_Real x, y, z;
1279 Standard_Integer n1, n2, n3;
1280 Standard_Integer k1, k2, k3;
1285 strcpy(ffile, argv[2]);
1286 strcat(ffile, ".obj");
1288 else strcpy(ffile, "wave.obj");
1289 FILE* outfile = fopen(ffile, "w");
1292 fprintf(outfile, "%s %s\n%s %s\n\n", "# CASCADE ","MATRA DATAVISION", "#", ffile);
1294 Standard_Integer nbNodes, totalnodes = 0, nbpolygons = 0;
1295 for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next()) {
1297 TopoDS_Face F = TopoDS::Face(ex.Current());
1298 Handle(Poly_Triangulation) Tr = BRep_Tool::Triangulation(F, L);
1301 nbNodes = Tr->NbNodes();
1302 const TColgp_Array1OfPnt& Nodes = Tr->Nodes();
1305 for (i = 1; i <= nbNodes; i++) {
1306 gp_Pnt Pnt = Nodes(i).Transformed(L.Transformation());
1310 fprintf(outfile, "%s %f %f %f\n", "v", x, y, z);
1313 fprintf(outfile, "\n%s %d\n\n", "# number of vertex", nbNodes);
1318 if (Tr->HasUVNodes()) {
1319 const TColgp_Array1OfPnt2d& UVNodes = Tr->UVNodes();
1320 BRepAdaptor_Surface BS(F, Standard_False);
1322 for (i = 1; i <= nbNodes; i++) {
1326 BS.D1(U,V,P,D1U,D1V);
1327 CSLib::Normal(D1U,D1V,Precision::Angular(),Status,Nor);
1328 if (Status != CSLib_Done) {
1329 BS.D2(U,V,P,D1U,D1V,D2U,D2V,D2UV);
1330 CSLib::Normal(D1U,D1V,D2U,D2V,D2UV,Precision::Angular(),OK,NStat,Nor);
1332 if (F.Orientation() == TopAbs_REVERSED) Nor.Reverse();
1334 fprintf(outfile, "%s %f %f %f\n", "vn", Nor.X(), Nor.Y(), Nor.Z());
1337 fprintf(outfile, "\n%s %d\n\n", "# number of vertex normals", nbNodes);
1340 fprintf(outfile, "%s %d\n", "s", nbface);
1343 Standard_Integer nbTriangles = Tr->NbTriangles();
1344 const Poly_Array1OfTriangle& triangles = Tr->Triangles();
1347 for (i = 1; i <= nbTriangles; i++) {
1348 if (F.Orientation() == TopAbs_REVERSED)
1349 triangles(i).Get(n1, n3, n2);
1351 triangles(i).Get(n1, n2, n3);
1355 fprintf(outfile, "%s %d%s%d %d%s%d %d%s%d\n", "fo", k1,"//", k1, k2,"//", k2, k3,"//", k3);
1357 nbpolygons += nbTriangles;
1358 totalnodes += nbNodes;
1360 fprintf(outfile, "\n%s %d\n", "# number of smooth groups", nbface);
1361 fprintf(outfile, "\n%s %d\n", "# number of polygons", nbpolygons);
1372 //=======================================================================
1373 //function : onetriangulation
1375 //=======================================================================
1377 Standard_Integer onetriangulation(Draw_Interpretor&, Standard_Integer /*nbarg*/, const char** /*argv*/)
1382 if (nbarg < 2) return 1;
1384 TopoDS_Shape S = DBRep::Get(argv[1]);
1385 if (S.IsNull()) return 1;
1387 Handle(Poly_Triangulation) TFinale;
1389 Standard_Integer nbshell = 0;
1391 TopExp_Explorer ex, exs, ex2;
1393 for (ex.Init(S, TopAbs_SHELL); ex.More(); ex.Next()) {
1395 TopoDS_Shell Sh = TopoDS::Shell(ex.Current());
1397 for (exs.Init(Sh, TopAbs_Face); exs.More(); exs.Next()) {
1398 TopoDS_Face F = TopoDS::Face(exs.Current());
1399 Handle(Poly_Triangulation) T = BRep_Tool::Triangulation(F, L);
1401 for (ex2.Init(F, TopAbs_EDGE); ex2.More(); ex2.Next()) {
1402 TopoDS_Edge edge = TopoDS::Edge(ex2.Current());
1403 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1404 const Poly_Array1OfTriangle& triangles = T->Triangles();
1406 if (mapedges.IsBound(edge)) {
1407 const TColStd_ListOfTransient& L = edges.Find(edge);
1408 const Handle(Poly_PolygonOnTriangulation)& P =
1409 *(Handle(Poly_PolygonOnTriangulation)*)&(L.First());
1410 const TColStd_Array1OfInteger& NOD = P->Nodes();
1416 Sprintf(name, "%s_%i", "tr", nbshell);
1417 DrawTrSurf::Set(name, TFinale);
1428 //=======================================================================
1431 //=======================================================================
1433 Standard_Integer vb(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
1435 Standard_Integer NbPoints = 1, Deg = 1;
1437 for (Deg = 1; Deg <= 25; Deg++) {
1438 for (NbPoints = 1; NbPoints <= 24; NbPoints++) {
1440 math_Vector GaussP(1, NbPoints), GaussW(1, NbPoints);
1441 math_Vector TheWeights(1, NbPoints), VBParam(1, NbPoints);
1442 math_Matrix VB(1, Deg+1, 1, NbPoints);
1444 math::GaussPoints(NbPoints, GaussP);
1446 Standard_Integer i, j, classe = Deg+1, cl1 = Deg;
1448 // calcul et mise en ordre des parametres et des poids:
1449 for (i = 1; i <= NbPoints; i++) {
1450 if (i <= (NbPoints+1)/2) {
1451 VBParam(NbPoints-i+1) = 0.5*(1 + GaussP(i));
1454 VBParam(i-(NbPoints+1)/2) = 0.5*(1 + GaussP(i));
1459 // Calcul du VB (Valeur des fonctions de Bernstein):
1460 for (i = 1; i <= classe; i++) {
1461 for (j = 1; j <= NbPoints; j++) {
1462 VB(i,j)=PLib::Binomial(cl1,i-1)*Pow((1-VBParam(j)),classe-i)*Pow(VBParam(j),i-1);
1467 for (i = 1; i <= classe; i++) {
1468 for (j = 1; j <= NbPoints; j++) {
1469 di<< VB(i, j) << ", ";
1477 //=======================================================================
1478 //function : extrema
1480 //=======================================================================
1482 Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
1486 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(argv[1]);
1488 Standard_Real X, Y, Z, U0;
1489 X = Draw::Atof(argv[2]);
1490 Y = Draw::Atof(argv[3]);
1491 Z = Draw::Atof(argv[4]);
1492 U0 = Draw::Atof(argv[5]);
1495 GeomAdaptor_Curve GC(C);
1496 Standard_Real tol = 1.e-09;
1497 Extrema_LocateExtPC ext(P, GC, U0, tol);
1500 gp_Pnt P1 = ext.Point().Value();
1501 di <<"distance = "<<ext.Value() << "\n";
1502 di <<"point = "<<P1.X()<<" "<<P1.Y()<<" "<< P1.Z()<< "\n";
1503 di <<"parametre = "<<ext.Point().Parameter()<<"\n";
1512 //=======================================================================
1513 //function : triedgepoints
1515 //=======================================================================
1517 Standard_Integer triedgepoints(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
1522 for( Standard_Integer i = 1; i < nbarg; i++ )
1524 TopoDS_Shape aShape = DBRep::Get(argv[i]);
1525 if ( aShape.IsNull() )
1528 Handle(Poly_PolygonOnTriangulation) aPoly;
1529 Handle(Poly_Triangulation) aT;
1530 TopLoc_Location aLoc;
1531 TopTools_MapOfShape anEdgeMap;
1532 TopTools_MapIteratorOfMapOfShape it;
1534 if( aShape.ShapeType() == TopAbs_EDGE )
1536 anEdgeMap.Add( aShape );
1540 TopExp_Explorer ex(aShape, TopAbs_EDGE);
1541 for(; ex.More(); ex.Next() )
1542 anEdgeMap.Add( ex.Current() );
1545 if ( anEdgeMap.Extent() == 0 )
1549 strcpy(newname,argv[i]);
1551 while (*p != '\0') p++;
1555 Standard_Integer nbEdge = 1;
1556 for(it.Initialize(anEdgeMap); it.More(); it.Next())
1558 BRep_Tool::PolygonOnTriangulation(TopoDS::Edge(it.Key()), aPoly, aT, aLoc);
1559 if ( aT.IsNull() || aPoly.IsNull() )
1562 const TColgp_Array1OfPnt& Nodes = aT->Nodes();
1563 const TColStd_Array1OfInteger& Indices = aPoly->Nodes();
1564 const Standard_Integer nbnodes = Indices.Length();
1566 for( Standard_Integer j = 1; j <= nbnodes; j++ )
1568 gp_Pnt P3d = Nodes(Indices(j));
1569 if( !aLoc.IsIdentity() )
1570 P3d.Transform(aLoc.Transformation());
1572 if( anEdgeMap.Extent() > 1 )
1573 Sprintf(p,"%d_%d",nbEdge,j);
1576 DBRep::Set( newname, BRepBuilderAPI_MakeVertex(P3d) );
1577 di.AppendElement(newname);
1585 //=======================================================================
1586 //function : correctnormals
1587 //purpose : Corrects normals in shape triangulation nodes (...)
1588 //=======================================================================
1589 Standard_Integer correctnormals (Draw_Interpretor& theDI,
1590 Standard_Integer /*theNArg*/,
1591 const char** theArgVal)
1593 TopoDS_Shape S = DBRep::Get(theArgVal[1]);
1595 //Use "correctnormals shape"
1598 if(!BRepLib::EnsureNormalConsistency(S))
1600 theDI << "Normals have not been changed!\n";
1604 theDI << "Some corrections in source shape have been made!\n";
1610 //=======================================================================
1611 void MeshTest::Commands(Draw_Interpretor& theCommands)
1612 //=======================================================================
1614 Draw::Commands(theCommands);
1615 BRepTest::AllCommands(theCommands);
1616 GeometryTest::AllCommands(theCommands);
1617 MeshTest::PluginCommands(theCommands);
1620 g = "Mesh Commands";
1622 theCommands.Add("incmesh","Builds triangular mesh for the shape, run w/o args for help",__FILE__, incrementalmesh, g);
1623 theCommands.Add("MemLeakTest","MemLeakTest",__FILE__, MemLeakTest, g);
1624 theCommands.Add("fastdiscret","fastdiscret shape deflection",__FILE__, fastdiscret, g);
1625 theCommands.Add("mesh","mesh result Shape deflection",__FILE__, triangule, g);
1626 theCommands.Add("addshape","addshape meshname Shape [deflection]",__FILE__, addshape, g);
1627 //theCommands.Add("smooth","smooth meshname",__FILE__, smooth, g);
1628 //theCommands.Add("edges","edges mesh shape, highlight the edges",__FILE__,edges, g);
1629 theCommands.Add("vertices","vertices mesh shape, highlight the vertices",__FILE__,vertices, g);
1630 theCommands.Add("medge","medge mesh [-]index (0 to clear all)",__FILE__,medge, g);
1631 theCommands.Add("mvertex","mvertex mesh [-]index (0 to clear all)",__FILE__,mvertex, g);
1632 theCommands.Add("triangle","triangle mesh [-]index (0 to clear all)",__FILE__,triangle, g);
1633 //theCommands.Add("dumpvertex","dumpvertex mesh [index]",__FILE__,dumpvertex, g);
1634 //theCommands.Add("dumpedge","dumpedge mesh [index]",__FILE__,dumpedge, g);
1635 //theCommands.Add("dumptriangle","dumptriangle mesh [index]",__FILE__,dumptriangle, g);
1637 theCommands.Add("tri2d", "tri2d facename",__FILE__, tri2d, g);
1638 theCommands.Add("trinfo","trinfo name, print triangles information on objects",__FILE__,trianglesinfo,g);
1639 theCommands.Add("veriftriangles","veriftriangles name, verif triangles",__FILE__,veriftriangles,g);
1640 theCommands.Add("wavefront","wavefront name",__FILE__, wavefront, g);
1641 theCommands.Add("onetriangulation","onetriangulation name",__FILE__, onetriangulation, g);
1642 theCommands.Add("triepoints", "triepoints shape1 [shape2 ...]",__FILE__, triedgepoints, g);
1644 theCommands.Add("correctnormals", "correctnormals shape",__FILE__, correctnormals, g);
1647 theCommands.Add("extrema","extrema ",__FILE__, extrema, g);
1648 theCommands.Add("vb","vb ",__FILE__, vb, g);