2 // Created: Wed Sep 22 18:35:55 1993
3 // Author: Didier PIFFAULT
6 #include <Standard_Stream.hxx>
10 #include <MeshTest.ixx>
12 #include <MeshTest_DrawableMesh.hxx>
13 #include <TopAbs_ShapeEnum.hxx>
15 #include <TopoDS_Edge.hxx>
16 #include <TopoDS_Face.hxx>
17 #include <TopoDS_Shape.hxx>
18 #include <TopoDS_Compound.hxx>
19 #include <TopExp_Explorer.hxx>
20 #include <TopTools_ListIteratorOfListOfShape.hxx>
22 #include <BRepTest.hxx>
23 #include <GeometryTest.hxx>
24 #include <BRep_Tool.hxx>
25 #include <BRep_Builder.hxx>
26 #include <Draw_MarkerShape.hxx>
27 #include <Draw_Appli.hxx>
29 #include <DrawTrSurf.hxx>
30 #include <BRepMesh_Triangle.hxx>
31 #include <BRepMesh_DataStructureOfDelaun.hxx>
32 #include <BRepMesh_Delaun.hxx>
33 #include <BRepMesh_FastDiscret.hxx>
34 #include <BRepMesh_Array1OfVertexOfDelaun.hxx>
35 #include <BRepMesh_Vertex.hxx>
36 #include <BRepMesh_Edge.hxx>
37 #include <BRepMesh_IncrementalMesh.hxx>
38 #include <TColStd_ListIteratorOfListOfInteger.hxx>
39 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
40 #include <Bnd_Box.hxx>
41 #include <Precision.hxx>
42 #include <Draw_Interpretor.hxx>
43 #include <IntPoly_PlaneSection.hxx>
44 #include <IntPoly_ShapeSection.hxx>
45 #include <Geom_Plane.hxx>
46 #include <Geom_Surface.hxx>
47 #include <Draw_Marker3D.hxx>
48 #include <Draw_Segment2D.hxx>
50 #include <GCPnts_UniformAbscissa.hxx>
51 #include <GeomAdaptor_Curve.hxx>
52 #include <Geom_Curve.hxx>
53 #include <Extrema_LocateExtPC.hxx>
55 #include <TopLoc_Location.hxx>
56 #include <gp_Trsf.hxx>
57 #include <Poly_Triangulation.hxx>
58 #include <Poly_Connect.hxx>
59 #include <TColgp_Array1OfPnt2d.hxx>
60 #include <TColStd_HArray1OfInteger.hxx>
61 #include <TopExp_Explorer.hxx>
65 #include <AppCont_ContMatrices.hxx>
66 #include <math_Vector.hxx>
67 #include <math_Matrix.hxx>
70 #include <CSLib_DerivativeStatus.hxx>
72 #include <BRepAdaptor_Surface.hxx>
73 #include <Bnd_Box.hxx>
74 #include <BRepBndLib.hxx>
77 //epa Memory leaks test
78 #include <BRepBuilderAPI_MakePolygon.hxx>
79 #include <TopoDS_Wire.hxx>
80 #include <BRepBuilderAPI_MakeFace.hxx>
81 #include <BRepTools.hxx>
84 Standard_IMPORT Draw_Viewer dout;
87 #define MAX2(X, Y) ( Abs(X) > Abs(Y)? Abs(X) : Abs(Y) )
88 #define MAX3(X, Y, Z) ( MAX2 ( MAX2(X,Y) , Z) )
92 #define ONETHIRD 0.333333333333333333333333333333333333333333333333333333333333
93 #define TWOTHIRD 0.666666666666666666666666666666666666666666666666666666666666
95 #ifdef DEB_MESH_CHRONO
96 #include <OSD_Chronometer.hxx>
97 Standard_Integer D0Control, D0Internal, D0Unif, D0Edges, NbControls;
98 OSD_Chronometer chTotal, chInternal, chControl, chUnif, chAddPoint;
99 OSD_Chronometer chEdges, chMaillEdges, chEtuInter, chLastControl, chStock;
100 OSD_Chronometer chAdd11, chAdd12, chAdd2, chUpdate, chPointValid;
101 OSD_Chronometer chIsos, chPointsOnIsos;
106 //=======================================================================
107 //function : shapesection
109 //=======================================================================
111 static Standard_Integer shapesection(Draw_Interpretor&, Standard_Integer nbarg, const char** argv)
113 if (nbarg < 4) return 1;
115 TopoDS_Shape S1 = DBRep::Get(argv[2]);
116 TopoDS_Shape S2 = DBRep::Get(argv[3]);
117 if (S1.IsNull() || S2.IsNull()) return 1;
119 IntPoly_ShapeSection SECTION(S1,S2);
124 for (Standard_Integer i = 1 ; i <= SECTION.NbEdges() ; i++) {
125 TopoDS_Shape E = SECTION.Edge(i);
126 if (!E.IsNull()) B.Add(C,E);
129 DBRep::Set(argv[1],C);
133 //=======================================================================
134 //function : planesection
136 //=======================================================================
138 static Standard_Integer planesection(Draw_Interpretor&, Standard_Integer nbarg, const char** argv)
140 if (nbarg < 4) return 1;
142 TopoDS_Shape S = DBRep::Get(argv[2]);
143 if (S.IsNull()) return 1;
144 Handle(Geom_Surface) Surf = DrawTrSurf::GetSurface(argv[3]);
146 Handle(Geom_Plane) pl = Handle(Geom_Plane)::DownCast(Surf);
148 IntPoly_PlaneSection SECTION(S,pl->Pln());
153 for (Standard_Integer i = 1 ; i <= SECTION.NbEdges() ; i++) {
154 TopoDS_Shape E = SECTION.Edge(i);
155 if (!E.IsNull()) B.Add(C,E);
158 DBRep::Set(argv[1],C);
164 //=======================================================================
165 //function : incrementalmesh
167 //=======================================================================
169 static Standard_Integer incrementalmesh(Draw_Interpretor&, Standard_Integer nbarg, const char** argv)
171 if (nbarg < 3) return 1;
173 Standard_Real d = atof(argv[2]);
174 TopoDS_Shape S = DBRep::Get(argv[1]);
175 if (S.IsNull()) return 1;
177 BRepMesh_IncrementalMesh MESH(S,d);
181 //=======================================================================
182 //function : MemLeakTest
184 //=======================================================================
186 static Standard_Integer MemLeakTest(Draw_Interpretor&, Standard_Integer nbarg, const char** argv)
188 for(int i=0;i<10000;i++)
190 BRepBuilderAPI_MakePolygon w(gp_Pnt(0,0,0),gp_Pnt(0,100,0),gp_Pnt(20,100,0),gp_Pnt(20,0,0));
192 TopoDS_Wire wireShape( w.Wire());
193 BRepBuilderAPI_MakeFace faceBuilder(wireShape);
194 TopoDS_Face f( faceBuilder.Face());
195 BRepMesh_IncrementalMesh im(f,1);
201 //=======================================================================
202 //function : fastdiscret
204 //=======================================================================
206 static Standard_Integer fastdiscret(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
208 if (nbarg < 3) return 1;
210 TopoDS_Shape S = DBRep::Get(argv[1]);
211 if (S.IsNull()) return 1;
213 const Standard_Real d = atof(argv[2]);
215 Standard_Boolean WithShare = Standard_True;
216 if (nbarg > 3) WithShare = atoi(argv[3]);
219 BRepBndLib::Add(S,B);
220 BRepMesh_FastDiscret MESH(d,0.5,B,WithShare,Standard_True,Standard_False,Standard_True);
222 //Standard_Integer NbIterations = MESH.NbIterations();
223 //if (nbarg > 4) NbIterations = atoi(argv[4]);
224 //MESH.NbIterations() = NbIterations;
226 di<<"Starting FastDiscret with :"<<"\n";
227 di<<" Deflection="<<d<<"\n";
228 di<<" Angle="<<0.5<<"\n";
229 di<<" SharedMode="<< (Standard_Integer) WithShare<<"\n";
230 //di<<" NbIterations="<<NbIterations<<"\n";
232 Handle(Poly_Triangulation) T;
233 BRep_Builder aBuilder;
236 // Clear existing triangulations
237 for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next())
238 aBuilder.UpdateFace(TopoDS::Face(ex.Current()),T);
242 TopoDS_Compound aCompGood, aCompFailed, aCompViolating;
245 Standard_Integer nbtriangles = 0, nbnodes = 0, nbfailed = 0, nbviolating = 0;
246 Standard_Real maxdef = 0.0;
247 for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next())
249 T = BRep_Tool::Triangulation(TopoDS::Face(ex.Current()),L);
253 if (aCompFailed.IsNull())
254 aBuilder.MakeCompound(aCompFailed);
255 aBuilder.Add(aCompFailed,ex.Current());
259 nbtriangles += T->NbTriangles();
260 nbnodes += T->NbNodes();
261 if (T->Deflection() > maxdef) maxdef = T->Deflection();
262 if (T->Deflection() > d)
265 if (aCompViolating.IsNull())
266 aBuilder.MakeCompound(aCompViolating);
267 aBuilder.Add(aCompViolating,ex.Current());
271 if (aCompGood.IsNull())
272 aBuilder.MakeCompound(aCompGood);
273 aBuilder.Add(aCompGood,ex.Current());
278 if (!aCompGood.IsNull())
281 strcpy(name,argv[1]);
282 strcat(name,"_good");
283 DBRep::Set(name,aCompGood);
285 if (!aCompFailed.IsNull())
288 strcpy(name,argv[1]);
289 strcat(name,"_failed");
290 DBRep::Set(name,aCompFailed);
292 if (!aCompViolating.IsNull())
295 strcpy(name,argv[1]);
296 strcat(name,"_violating");
297 DBRep::Set(name,aCompViolating);
300 di<<"FastDiscret completed with :"<<"\n";
301 di<<" MaxDeflection="<<maxdef<<"\n";
302 di<<" NbNodes="<<nbnodes<<"\n";
303 di<<" NbTriangles="<<nbtriangles<<"\n";
304 di<<" NbFailed="<<nbfailed<<"\n";
305 di<<" NbViolating="<<nbviolating<<"\n";
311 //=======================================================================
312 //function : triangule
314 //=======================================================================
317 class BRepMesh_Couple
320 BRepMesh_Couple() { myI1 = myI2 = 0; }
321 BRepMesh_Couple(const Standard_Integer I1,
322 const Standard_Integer I2)
323 { myI1 = I1; myI2 = I2; }
325 Standard_Integer myI1;
326 Standard_Integer myI2;
329 inline Standard_Boolean IsEqual(const BRepMesh_Couple& one,
330 const BRepMesh_Couple& other)
332 if (one.myI1 == other.myI1 &&
333 one.myI2 == other.myI2) return Standard_True;
334 else return Standard_False;
337 inline Standard_Integer HashCode(const BRepMesh_Couple& one,
338 const Standard_Integer Upper)
340 return ::HashCode((one.myI1+one.myI2), Upper);
343 typedef NCollection_Map<BRepMesh_Couple> BRepMesh_MapOfCouple;
346 static void AddLink(BRepMesh_MapOfCouple& aMap,
350 Standard_Integer i1 = v1;
351 Standard_Integer i2 = v2;
356 aMap.Add(BRepMesh_Couple(i1,i2));
359 static void MeshStats(const TopoDS_Shape& theSape,
360 Standard_Integer& theNbTri,
361 Standard_Integer& theNbEdges,
362 Standard_Integer& theNbNodes)
368 Handle(Poly_Triangulation) T;
371 for ( TopExp_Explorer ex(theSape, TopAbs_FACE); ex.More(); ex.Next()) {
372 TopoDS_Face F = TopoDS::Face(ex.Current());
373 T = BRep_Tool::Triangulation(F, L);
375 theNbTri += T->NbTriangles();
376 theNbNodes += T->NbNodes();
378 BRepMesh_MapOfCouple aMap;
379 //count number of links
380 Poly_Array1OfTriangle& Trian = T->ChangeTriangles();
381 for(Standard_Integer i = 1; i<=Trian.Length();i++) {
382 Standard_Integer v1, v2, v3;
383 Trian(i).Get(v1,v2,v3);
385 AddLink(aMap, v1, v2);
386 AddLink(aMap, v2, v3);
387 AddLink(aMap, v3, v1);
390 theNbEdges+=aMap.Extent();
395 static Standard_Integer triangule(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
397 if (nbarg < 4) return 1;
399 Standard_Boolean save = Standard_False;
401 const char *id1 = argv[2];
402 TopoDS_Shape S = DBRep::Get(id1);
403 if (S.IsNull()) return 1;
404 di << argv[1] << " ";
405 Standard_Real Deflect=atof(argv[3]);
407 di << " Donner la fleche !" << "\n";
412 save = (atoi(argv[4])==1);
415 Standard_Boolean partage=Standard_True;
417 partage=atoi(argv[5])==1;
420 Handle(MeshTest_DrawableMesh) DM =
421 new MeshTest_DrawableMesh(S,Deflect,partage, save);
423 Draw::Set(argv[1],DM);
425 Standard_Integer nbn, nbl, nbe;
426 MeshStats(S, nbe, nbl, nbn);
428 di<<"(Resultat ("<<nbe<<" mailles) ("<<nbl<<" aretes) ("<<nbn<<" sommets))"<<"\n";
430 // passe de verification du maillage.
431 /*Standard_Integer nbc;
432 for (Standard_Integer iLi=1; iLi<= DM->Mesh()->NbEdges(); iLi++) {
433 const BRepMesh_Edge& ed=DM->Mesh()->Edge(iLi);
434 if (ed.Movability()!=MeshDS_Deleted) {
435 nbc=struc->ElemConnectedTo(iLi).Extent();
436 if (nbc != 1 && nbc != 2) di <<"ERROR MAILLAGE Edge no "<< iLi<<"\n";
442 for (Standard_Integer lepnt=1; lepnt<DM->Mesh()->NbPoint3d(); lepnt++) {
443 bobo.Add(DM->Mesh()->Point3d(lepnt));
445 Standard_Real x,y,z,X,Y,Z;
446 bobo.Get(x,y,z,X,Y,Z);
447 Standard_Real delta=Max(X-x,Max(Y-y,Z-z));
448 if (delta>0) delta=Deflect/delta;
449 di << " Fleche de " << delta << " fois la taille de l''objet." << "\n";
454 //=======================================================================
455 //function : addshape
457 //=======================================================================
459 Standard_Integer addshape(Draw_Interpretor&, Standard_Integer n, const char** a)
462 Handle(MeshTest_DrawableMesh) D =
463 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
464 if (D.IsNull()) return 1;
465 TopoDS_Shape S = DBRep::Get(a[2]);
466 if (S.IsNull()) return 1;
475 //=======================================================================
478 //=======================================================================
480 /*Standard_Integer smooth(Draw_Interpretor&, Standard_Integer n, const char** a)
483 Handle(MeshTest_DrawableMesh) D =
484 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
485 if (D.IsNull()) return 1;
486 Handle(BRepMesh_DataStructureOfDelaun) struc=
488 BRepMesh_Array1OfVertexOfDelaun toto(1,1);
489 BRepMesh_Delaun trial(struc,
492 trial.SmoothMesh(0.1);
498 //=======================================================================
501 //=======================================================================
503 /*static Standard_Integer edges (Draw_Interpretor&, Standard_Integer n, const char** a)
507 Handle(MeshTest_DrawableMesh) D =
508 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
509 if (D.IsNull()) return 1;
510 TopoDS_Shape S = DBRep::Get(a[2]);
511 if (S.IsNull()) return 1;
514 TColStd_SequenceOfInteger& eseq = D->Edges();
515 Handle(BRepMesh_FastDiscret) M = D->Mesh();
516 Handle(BRepMesh_DataStructureOfDelaun) DS = M->Result();
517 Standard_Integer e1, e2, e3, iTri;
518 Standard_Boolean o1, o2, o3;
521 for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
522 const MeshDS_MapOfInteger& elems = DS->ElemOfDomain();
523 MeshDS_MapOfInteger::Iterator it;
524 for (it.Initialize(elems); it.More(); it.Next()) {
526 const BRepMesh_Triangle& triang = M->Triangle(iTri);
527 if (triang.Movability()!=MeshDS_Deleted) {
528 triang.Edges(e1, e2, e3, o1, o2, o3);
537 //for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE);ex.More();ex.Next()) {
545 //=======================================================================
546 //function : vertices
548 //=======================================================================
550 static Standard_Integer vertices (Draw_Interpretor&, Standard_Integer n, const char** a)
554 Handle(MeshTest_DrawableMesh) D =
555 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
556 if (D.IsNull()) return 1;
557 TopoDS_Shape S = DBRep::Get(a[2]);
558 if (S.IsNull()) return 1;
561 TColStd_SequenceOfInteger& vseq = D->Vertices();
562 Handle(BRepMesh_FastDiscret) M = D->Mesh();
565 for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
566 MeshDS_MapOfInteger vtx;
567 M->VerticesOfDomain(vtx);
568 for (MeshDS_MapOfInteger::Iterator it(vtx); it.More(); it.Next())
569 vseq.Append(it.Key());
574 //for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE);ex.More();ex.Next()) {
581 //=======================================================================
584 //=======================================================================
586 static Standard_Integer medge (Draw_Interpretor&, Standard_Integer n, const char** a)
590 Handle(MeshTest_DrawableMesh) D =
591 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
592 if (D.IsNull()) return 1;
594 Standard_Integer i,j,e;
595 TColStd_SequenceOfInteger& eseq = D->Edges();
596 for (i = 2; i < n; i++) {
603 while (j <= eseq.Length()) {
619 //=======================================================================
622 //=======================================================================
624 static Standard_Integer mvertex (Draw_Interpretor&, Standard_Integer n, const char** a)
628 Handle(MeshTest_DrawableMesh) D =
629 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
630 if (D.IsNull()) return 1;
632 Standard_Integer i,j,v;
633 TColStd_SequenceOfInteger& vseq = D->Vertices();
634 for (i = 2; i < n; i++) {
641 while (j <= vseq.Length()) {
656 //=======================================================================
657 //function : triangle
659 //=======================================================================
661 static Standard_Integer triangle (Draw_Interpretor&, Standard_Integer n, const char** a)
665 Handle(MeshTest_DrawableMesh) D =
666 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
667 if (D.IsNull()) return 1;
669 Standard_Integer i,j,v;
670 TColStd_SequenceOfInteger& tseq = D->Triangles();
671 for (i = 2; i < n; i++) {
678 while (j <= tseq.Length()) {
693 //=======================================================================
694 //function : printdegree
696 //=======================================================================
698 static void printdegree(MeshDS_DegreeOfFreedom dof, Draw_Interpretor& di)
701 case MeshDS_InVolume :
704 case MeshDS_OnSurface :
707 case MeshDS_OnCurve :
713 case MeshDS_Frontier :
716 case MeshDS_Deleted :
725 //=======================================================================
726 //function : dumpvertex
728 //=======================================================================
731 Standard_Integer dumpvertex(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
733 if (argc < 2) return 1;
735 Handle(MeshTest_DrawableMesh) D =
736 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(argv[1]));
737 if (D.IsNull()) return 1;
739 Handle(BRepMesh_DataStructureOfDelaun) struc = D->Mesh()->Result();
741 Standard_Integer in=1;
746 Standard_Integer nbn=in;
749 nbn=Min(nbn,struc->NbNodes());
752 for (; in<=nbn; in++) {
753 BRepMesh_Vertex nod=struc->GetNode(in);
754 di<<"(node "<<in<<" (uv "<<nod.Coord().X()
755 <<" "<<nod.Coord().Y()<<") (3d "
756 <<nod.Location3d()<<") ";
757 printdegree(nod.Movability(), di);
759 MeshDS_ListOfInteger::Iterator tati(struc->LinkNeighboursOf(in));
760 for (; tati.More(); tati.Next()) di<<" "<<tati.Value();
767 //=======================================================================
768 //function : dumpedge
770 //=======================================================================
772 Standard_Integer dumpedge(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
774 if (argc < 2) return 1;
776 Handle(MeshTest_DrawableMesh) D =
777 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(argv[1]));
778 if (D.IsNull()) return 1;
780 Handle(BRepMesh_DataStructureOfDelaun) struc=D->Mesh()->Result();
781 Standard_Integer il=1;
786 Standard_Integer nbl=il;
789 nbl=Min(nbl, struc->NbLinks());
792 for (; il<=nbl; il++) {
793 BRepMesh_Edge edg=struc->GetLink(il);
794 di << "(edge "<<il<<" ("<<edg.FirstNode()<<" "<<edg.LastNode()
796 printdegree(edg.Movability(), di);
798 const MeshDS_PairOfIndex& pair = struc->ElemConnectedTo(il);
799 for (Standard_Integer j = 1, jn = pair.Extent(); j <= jn; j++)
800 di<<" "<<pair.Index(j);
807 //=======================================================================
808 //function : dumptriangle
810 //=======================================================================
812 Standard_Integer dumptriangle(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
814 if (argc < 2) return 1;
816 Handle(MeshTest_DrawableMesh) D =
817 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(argv[1]));
818 if (D.IsNull()) return 1;
820 Handle(BRepMesh_DataStructureOfDelaun) struc=D->Mesh()->Result();
821 Standard_Integer ie=1;
826 Standard_Integer nbe=ie;
829 nbe=Min(nbe, struc->NbElements());
832 Standard_Integer e1, e2, e3;
833 Standard_Boolean o1, o2, o3;
835 for (; ie<=nbe; ie++) {
836 BRepMesh_Triangle tri=struc->GetElement(ie);
837 tri.Edges(e1, e2, e3, o1, o2, o3);
841 di<<" (maille "<<ie<<" (links "<<e1<<" "
843 printdegree(tri.Movability(), di);
851 //=======================================================================
852 //function : trianglesinfo
854 //=======================================================================
855 static Standard_Integer trianglesinfo(Draw_Interpretor& di, Standard_Integer n, const char** a)
857 if (n != 2) return 1;
858 TopoDS_Shape S = DBRep::Get(a[1]);
859 if (S.IsNull()) return 1;
861 Handle(Poly_Triangulation) T;
864 Standard_Real MaxDeflection = 0.0;
865 Standard_Integer nbtriangles = 0, nbnodes = 0;
866 for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next()) {
867 TopoDS_Face F = TopoDS::Face(ex.Current());
868 T = BRep_Tool::Triangulation(F, L);
870 nbtriangles += T->NbTriangles();
871 nbnodes += T->NbNodes();
872 if (T->Deflection() > MaxDeflection)
873 MaxDeflection = T->Deflection();
878 di<<"This shape contains " <<nbtriangles<<" triangles."<<"\n";
879 di<<" " <<nbnodes <<" nodes."<<"\n";
880 di<<"Maximal deflection " <<MaxDeflection<<"\n";
882 #ifdef DEB_MESH_CHRONO
883 Standard_Real tot, addp, unif, contr, inter;
884 Standard_Real edges, mailledges, etuinter, lastcontrol, stock;
885 Standard_Real add11, add12, add2, upda, pointvalid;
886 Standard_Real isos, pointsisos;
887 chTotal.Show(tot); chAddPoint.Show(addp); chUnif.Show(unif);
888 chControl.Show(contr); chInternal.Show(inter);
889 chEdges.Show(edges); chMaillEdges.Show(mailledges);
890 chEtuInter.Show(etuinter); chLastControl.Show(lastcontrol);
892 chAdd11.Show(add11); chAdd12.Show(add12); chAdd2.Show(add2); chUpdate.Show(upda);
893 chPointValid.Show(pointvalid); chIsos.Show(isos); chPointsOnIsos.Show(pointsisos);
896 di <<"temps total de maillage: "<<tot <<" seconds"<< "\n";
897 di <<"dont: "<< "\n";
898 di <<"discretisation des edges: "<<edges <<" seconds---> "<< 100*edges/tot <<" %"<<"\n";
899 di <<"maillage des edges: "<<mailledges <<" seconds---> "<< 100*mailledges/tot <<" %"<<"\n";
900 di <<"controle et points internes: "<<etuinter <<" seconds---> "<< 100*etuinter/tot <<" %"<<"\n";
901 di <<"derniers controles: "<<lastcontrol<<" seconds---> "<< 100*lastcontrol/tot<<" %"<<"\n";
902 di <<"stockage dans la S.D. "<<stock <<" seconds---> "<< 100*stock/tot <<" %"<<"\n";
904 di <<"et plus precisement: "<<"\n";
905 di <<"Add 11ere partie : "<<add11 <<" seconds---> "<<100*add11/tot <<" %"<<"\n";
906 di <<"Add 12ere partie : "<<add12 <<" seconds---> "<<100*add12/tot <<" %"<<"\n";
907 di <<"Add 2eme partie : "<<add2 <<" seconds---> "<<100*add2/tot <<" %"<<"\n";
908 di <<"Update : "<<upda <<" seconds---> "<<100*upda/tot <<" %"<<"\n";
909 di <<"AddPoint : "<<addp <<" seconds---> "<<100*addp/tot <<" %"<<"\n";
910 di <<"UniformDeflection "<<unif <<" seconds---> "<<100*unif/tot <<" %"<<"\n";
911 di <<"Controle : "<<contr <<" seconds---> "<<100*contr/tot <<" %"<<"\n";
912 di <<"Points Internes: "<<inter <<" seconds---> "<<100*inter/tot <<" %"<<"\n";
913 di <<"calcul des isos et du, dv: "<<isos <<" seconds---> "<<100*isos/tot <<" %"<<"\n";
914 di <<"calcul des points sur isos: "<<pointsisos<<" seconds---> "<<100*pointsisos/tot <<" %"<<"\n";
915 di <<"IsPointValid: "<<pointvalid<<" seconds---> "<<100*pointvalid/tot <<" %"<<"\n";
919 di <<"nombre d'appels de controle apres points internes : "<< NbControls << "\n";
920 di <<"nombre de points sur restrictions : "<< D0Edges << "\n";
921 di <<"nombre de points calcules par UniformDeflection : "<< D0Unif << "\n";
922 di <<"nombre de points calcules dans InternalVertices : "<< D0Internal << "\n";
923 di <<"nombre de points calcules dans Control : "<< D0Control << "\n";
924 if (nbnodes-D0Edges != 0) {
925 Standard_Real ratio = (Standard_Real)(D0Internal+D0Control)/ (Standard_Real)(nbnodes-D0Edges);
926 di <<"---> Ratio: (D0Internal+D0Control) / (nbNodes-nbOnEdges) : "<< ratio << "\n";
931 chTotal.Reset(); chAddPoint.Reset(); chUnif.Reset();
932 chControl.Reset(); chInternal.Reset();
933 chEdges.Reset(); chMaillEdges.Reset();
934 chEtuInter.Reset(); chLastControl.Reset();
936 chAdd11.Reset(); chAdd12.Reset(); chAdd2.Reset(); chUpdate.Reset();
937 chPointValid.Reset(); chIsos.Reset(); chPointsOnIsos.Reset();
944 //=======================================================================
945 //function : veriftriangles
947 //=======================================================================
949 static Standard_Integer veriftriangles(Draw_Interpretor& di, Standard_Integer n, const char** a)
952 Standard_Boolean quiet = 1;
953 if (n == 3) quiet = 0;
954 TopoDS_Shape Sh = DBRep::Get(a[1]);
955 if (Sh.IsNull()) return 1;
957 Handle(Poly_Triangulation) T;
959 Standard_Integer i, n1, n2, n3;
960 gp_Pnt2d mitri, v1, v2, v3, mi2d1, mi2d2, mi2d3;
961 gp_XYZ vecEd1, vecEd2, vecEd3;
962 // Standard_Real dipo, dm, dv, d1, d2, d3, defle;
963 Standard_Real dipo, dv, d1, d2, d3, defle;
964 Handle(Geom_Surface) S;
965 Standard_Integer nbface = 0;
968 for (ex.Init(Sh, TopAbs_FACE); ex.More(); ex.Next()) {
969 TopoDS_Face F = TopoDS::Face(ex.Current());
971 T = BRep_Tool::Triangulation(F, L);
972 Standard_Real deflemax = 0, deflemin = 1.e100;
974 Standard_Real defstock = T->Deflection();
975 const Poly_Array1OfTriangle& triangles = T->Triangles();
976 const TColgp_Array1OfPnt2d& Nodes2d = T->UVNodes();
977 const TColgp_Array1OfPnt& Nodes = T->Nodes();
979 S = BRep_Tool::Surface(F, L);
981 for(i = 1; i <= triangles.Length(); i++) {
982 if (F.Orientation() == TopAbs_REVERSED)
983 triangles(i).Get(n1,n3,n2);
985 triangles(i).Get(n1,n2,n3);
987 const gp_XY& xy1 = Nodes2d(n1).XY();
988 const gp_XY& xy2 = Nodes2d(n2).XY();
989 const gp_XY& xy3 = Nodes2d(n3).XY();
991 mi2d1.SetCoord((xy2.X()+xy3.X())*0.5,
992 (xy2.Y()+xy3.Y())*0.5);
993 mi2d2.SetCoord((xy1.X()+xy3.X())*0.5,
994 (xy1.Y()+xy3.Y())*0.5);
995 mi2d3.SetCoord((xy1.X()+xy2.X())*0.5,
996 (xy1.Y()+xy2.Y())*0.5);
998 gp_XYZ p1 = Nodes(n1).Transformed(L.Transformation()).XYZ();
999 gp_XYZ p2 = Nodes(n2).Transformed(L.Transformation()).XYZ();
1000 gp_XYZ p3 = Nodes(n3).Transformed(L.Transformation()).XYZ();
1005 d1=vecEd1.SquareModulus();
1006 d2=vecEd2.SquareModulus();
1007 d3=vecEd3.SquareModulus();
1009 if (d1!=0. && d2!=0. && d3!=0.) {
1010 gp_XYZ equa(vecEd1^vecEd2);
1013 equa.SetCoord(equa.X()/dv, equa.Y()/dv, equa.Z()/dv);
1017 mitri.SetCoord(ONETHIRD*(xy1.X()+xy2.X()+xy3.X()),
1018 ONETHIRD*(xy1.Y()+xy2.Y()+xy3.Y()));
1019 v1.SetCoord(ONETHIRD*mi2d1.X()+TWOTHIRD*xy1.X(),
1020 ONETHIRD*mi2d1.Y()+TWOTHIRD*xy1.Y());
1021 v2.SetCoord(ONETHIRD*mi2d2.X()+TWOTHIRD*xy2.X(),
1022 ONETHIRD*mi2d2.Y()+TWOTHIRD*xy2.Y());
1023 v3.SetCoord(ONETHIRD*mi2d3.X()+TWOTHIRD*xy3.X(),
1024 ONETHIRD*mi2d3.Y()+TWOTHIRD*xy3.Y());
1026 S->D0(mi2d1.X(), mi2d1.Y(), PP);
1027 PP = PP.Transformed(L.Transformation());
1028 defle = Abs((equa*PP.XYZ())-dipo);
1029 deflemax = Max(deflemax, defle);
1030 deflemin = Min(deflemin, defle);
1032 S->D0(mi2d2.X(), mi2d2.Y(), PP);
1033 PP = PP.Transformed(L.Transformation());
1034 defle = Abs((equa*PP.XYZ())-dipo);
1035 deflemax = Max(deflemax, defle);
1036 deflemin = Min(deflemin, defle);
1038 S->D0(mi2d3.X(), mi2d3.Y(), PP);
1039 PP = PP.Transformed(L.Transformation());
1040 defle = Abs((equa*PP.XYZ())-dipo);
1041 deflemax = Max(deflemax, defle);
1042 deflemin = Min(deflemin, defle);
1044 S->D0(v1.X(), v1.Y(), PP);
1045 PP = PP.Transformed(L.Transformation());
1046 defle = Abs((equa*PP.XYZ())-dipo);
1047 deflemax = Max(deflemax, defle);
1048 deflemin = Min(deflemin, defle);
1050 S->D0(v2.X(), v2.Y(), PP);
1051 PP = PP.Transformed(L.Transformation());
1052 defle = Abs((equa*PP.XYZ())-dipo);
1053 deflemax = Max(deflemax, defle);
1054 deflemin = Min(deflemin, defle);
1056 S->D0(v3.X(), v3.Y(), PP);
1057 PP = PP.Transformed(L.Transformation());
1058 defle = Abs((equa*PP.XYZ())-dipo);
1059 deflemax = Max(deflemax, defle);
1060 deflemin = Min(deflemin, defle);
1062 S->D0(mitri.X(), mitri.Y(), PP);
1063 PP = PP.Transformed(L.Transformation());
1064 defle = Abs((equa*PP.XYZ())-dipo);
1065 deflemax = Max(deflemax, defle);
1066 deflemin = Min(deflemin, defle);
1068 if (defle > defstock) {
1069 di <<"face "<< nbface <<" deflection = " << defle <<" pour "<<defstock <<" stockee."<<"\n";
1075 di <<"face "<< nbface<<", deflemin = "<< deflemin<<", deflemax = "<<deflemax<<"\n";
1088 //=======================================================================
1091 //=======================================================================
1093 Standard_Integer tri2d(Draw_Interpretor&, Standard_Integer n, const char** a)
1096 if (n != 2) return 1;
1097 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
1098 TopoDS_Face F = TopoDS::Face(aLocalShape);
1099 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[1]));
1100 if (F.IsNull()) return 1;
1101 Handle(Poly_Triangulation) T;
1104 T = BRep_Tool::Triangulation(F, L);
1107 gp_Trsf tr = L.Transformation();
1112 // Build the connect tool
1115 Standard_Integer i,j, nFree, nInternal, nbTriangles = T->NbTriangles();
1116 Standard_Integer t[3];
1118 // count the free edges
1120 for (i = 1; i <= nbTriangles; i++) {
1121 pc.Triangles(i,t[0],t[1],t[2]);
1122 for (j = 0; j < 3; j++)
1123 if (t[j] == 0) nFree++;
1126 // allocate the arrays
1127 TColStd_Array1OfInteger Free(1,2*nFree);
1128 nInternal = (3*nbTriangles - nFree) / 2;
1129 TColStd_Array1OfInteger Internal(0,2*nInternal);
1131 Standard_Integer fr = 1, in = 1;
1132 const Poly_Array1OfTriangle& triangles = T->Triangles();
1133 Standard_Integer nodes[3];
1134 for (i = 1; i <= nbTriangles; i++) {
1135 pc.Triangles(i,t[0],t[1],t[2]);
1136 triangles(i).Get(nodes[0],nodes[1],nodes[2]);
1137 for (j = 0; j < 3; j++) {
1138 Standard_Integer k = (j+1) % 3;
1140 Free(fr) = nodes[j];
1141 Free(fr+1) = nodes[k];
1144 // internal edge if this triangle has a lower index than the adjacent
1145 else if (i < t[j]) {
1146 Internal(in) = nodes[j];
1147 Internal(in+1) = nodes[k];
1153 // Display the edges
1154 if (T->HasUVNodes()) {
1155 const TColgp_Array1OfPnt2d& Nodes2d = T->UVNodes();
1157 Handle(Draw_Segment2D) Seg;
1160 Standard_Integer nn;
1161 nn = Free.Length() / 2;
1162 for (i = 1; i <= nn; i++) {
1163 Seg = new Draw_Segment2D(Nodes2d(Free(2*i-1)),
1172 for (i = 1; i <= nn; i++) {
1173 Seg = new Draw_Segment2D(Nodes2d(Internal(2*i-1)),
1174 Nodes2d(Internal(2*i)),
1188 //=======================================================================
1189 //function : wavefront
1191 //=======================================================================
1193 static Standard_Integer wavefront(Draw_Interpretor&, Standard_Integer nbarg, const char** argv)
1195 if (nbarg < 2) return 1;
1197 TopoDS_Shape S = DBRep::Get(argv[1]);
1198 if (S.IsNull()) return 1;
1200 // creation du maillage s'il n'existe pas.
1203 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
1204 BRepBndLib::Add(S, B);
1205 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
1206 Standard_Real aDeflection =
1207 MAX3( aXmax-aXmin , aYmax-aYmin , aZmax-aZmin) * 0.004;
1209 BRepMesh_IncrementalMesh(S, aDeflection);
1215 Standard_Integer i, nbface = 0;
1216 Standard_Boolean OK = Standard_True;
1218 gp_Vec D2U,D2V,D2UV;
1222 CSLib_DerivativeStatus Status;
1223 CSLib_NormalStatus NStat;
1224 Standard_Real x, y, z;
1225 Standard_Integer n1, n2, n3;
1226 Standard_Integer k1, k2, k3;
1231 strcpy(ffile, argv[2]);
1232 strcat(ffile, ".obj");
1234 else strcpy(ffile, "wave.obj");
1235 FILE* outfile = fopen(ffile, "w");
1238 fprintf(outfile, "%s %s\n%s %s\n\n", "# CASCADE ","MATRA DATAVISION", "#", ffile);
1240 Standard_Integer nbNodes, totalnodes = 0, nbpolygons = 0;
1241 for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next()) {
1243 TopoDS_Face F = TopoDS::Face(ex.Current());
1244 Handle(Poly_Triangulation) Tr = BRep_Tool::Triangulation(F, L);
1247 nbNodes = Tr->NbNodes();
1248 const TColgp_Array1OfPnt& Nodes = Tr->Nodes();
1251 for (i = 1; i <= nbNodes; i++) {
1252 gp_Pnt Pnt = Nodes(i).Transformed(L.Transformation());
1256 fprintf(outfile, "%s %f %f %f\n", "v", x, y, z);
1259 fprintf(outfile, "\n%s %d\n\n", "# number of vertex", nbNodes);
1264 if (Tr->HasUVNodes()) {
1265 const TColgp_Array1OfPnt2d& UVNodes = Tr->UVNodes();
1266 BRepAdaptor_Surface BS(F, Standard_False);
1268 for (i = 1; i <= nbNodes; i++) {
1272 BS.D1(U,V,P,D1U,D1V);
1273 CSLib::Normal(D1U,D1V,Precision::Angular(),Status,Nor);
1274 if (Status != CSLib_Done) {
1275 BS.D2(U,V,P,D1U,D1V,D2U,D2V,D2UV);
1276 CSLib::Normal(D1U,D1V,D2U,D2V,D2UV,Precision::Angular(),OK,NStat,Nor);
1278 if (F.Orientation() == TopAbs_REVERSED) Nor.Reverse();
1280 fprintf(outfile, "%s %f %f %f\n", "vn", Nor.X(), Nor.Y(), Nor.Z());
1283 fprintf(outfile, "\n%s %d\n\n", "# number of vertex normals", nbNodes);
1286 fprintf(outfile, "%s %d\n", "s", nbface);
1289 Standard_Integer nbTriangles = Tr->NbTriangles();
1290 const Poly_Array1OfTriangle& triangles = Tr->Triangles();
1293 for (i = 1; i <= nbTriangles; i++) {
1294 if (F.Orientation() == TopAbs_REVERSED)
1295 triangles(i).Get(n1, n3, n2);
1297 triangles(i).Get(n1, n2, n3);
1301 fprintf(outfile, "%s %d%s%d %d%s%d %d%s%d\n", "fo", k1,"//", k1, k2,"//", k2, k3,"//", k3);
1303 nbpolygons += nbTriangles;
1304 totalnodes += nbNodes;
1306 fprintf(outfile, "\n%s %d\n", "# number of smooth groups", nbface);
1307 fprintf(outfile, "\n%s %d\n", "# number of polygons", nbpolygons);
1318 //=======================================================================
1319 //function : onetriangulation
1321 //=======================================================================
1323 Standard_Integer onetriangulation(Draw_Interpretor&, Standard_Integer nbarg, const char** argv)
1328 if (nbarg < 2) return 1;
1330 TopoDS_Shape S = DBRep::Get(argv[1]);
1331 if (S.IsNull()) return 1;
1333 Handle(Poly_Triangulation) TFinale;
1335 Standard_Integer nbshell = 0;
1337 TopExp_Explorer ex, exs, ex2;
1339 for (ex.Init(S, TopAbs_SHELL); ex.More(); ex.Next()) {
1341 TopoDS_Shell Sh = TopoDS::Shell(ex.Current());
1343 for (exs.Init(Sh, TopAbs_Face); exs.More(); exs.Next()) {
1344 TopoDS_Face F = TopoDS::Face(exs.Current());
1345 Handle(Poly_Triangulation) T = BRep_Tool::Triangulation(F, L);
1347 for (ex2.Init(F, TopAbs_EDGE); ex2.More(); ex2.Next()) {
1348 TopoDS_Edge edge = TopoDS::Edge(ex2.Current());
1349 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1350 const Poly_Array1OfTriangle& triangles = T->Triangles();
1352 if (mapedges.IsBound(edge)) {
1353 const TColStd_ListOfTransient& L = edges.Find(edge);
1354 const Handle(Poly_PolygonOnTriangulation)& P =
1355 *(Handle(Poly_PolygonOnTriangulation)*)&(L.First());
1356 const TColStd_Array1OfInteger& NOD = P->Nodes();
1362 sprintf(name, "%s_%i", "tr", nbshell);
1363 DrawTrSurf::Set(name, TFinale);
1374 //=======================================================================
1377 //=======================================================================
1379 Standard_Integer vb(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
1381 Standard_Integer NbPoints = 1, Deg = 1;
1383 for (Deg = 1; Deg <= 25; Deg++) {
1384 for (NbPoints = 1; NbPoints <= 24; NbPoints++) {
1386 math_Vector GaussP(1, NbPoints), GaussW(1, NbPoints);
1387 math_Vector TheWeights(1, NbPoints), VBParam(1, NbPoints);
1388 math_Matrix VB(1, Deg+1, 1, NbPoints);
1390 math::GaussPoints(NbPoints, GaussP);
1392 Standard_Integer i, j, classe = Deg+1, cl1 = Deg;
1394 // calcul et mise en ordre des parametres et des poids:
1395 for (i = 1; i <= NbPoints; i++) {
1396 if (i <= (NbPoints+1)/2) {
1397 VBParam(NbPoints-i+1) = 0.5*(1 + GaussP(i));
1400 VBParam(i-(NbPoints+1)/2) = 0.5*(1 + GaussP(i));
1405 // Calcul du VB (Valeur des fonctions de Bernstein):
1406 for (i = 1; i <= classe; i++) {
1407 for (j = 1; j <= NbPoints; j++) {
1408 VB(i,j)=PLib::Binomial(cl1,i-1)*Pow((1-VBParam(j)),classe-i)*Pow(VBParam(j),i-1);
1413 for (i = 1; i <= classe; i++) {
1414 for (j = 1; j <= NbPoints; j++) {
1415 di<< VB(i, j) << ", ";
1423 //=======================================================================
1424 //function : extrema
1426 //=======================================================================
1428 Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
1432 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(argv[1]);
1434 Standard_Real X, Y, Z, U0;
1441 GeomAdaptor_Curve GC(C);
1442 Standard_Real tol = 1.e-09;
1443 Extrema_LocateExtPC ext(P, GC, U0, tol);
1446 gp_Pnt P1 = ext.Point().Value();
1447 di <<"distance = "<<ext.Value() << "\n";
1448 di <<"point = "<<P1.X()<<" "<<P1.Y()<<" "<< P1.Z()<< "\n";
1449 di <<"parametre = "<<ext.Point().Parameter()<<"\n";
1460 //=======================================================================
1461 void MeshTest::Commands(Draw_Interpretor& theCommands)
1462 //=======================================================================
1464 Draw::Commands(theCommands);
1465 BRepTest::AllCommands(theCommands);
1466 GeometryTest::AllCommands(theCommands);
1467 MeshTest::PluginCommands(theCommands);
1470 g = "Mesh Commands";
1472 theCommands.Add("shpsec","shpsec result shape shape",__FILE__, shapesection, g);
1473 theCommands.Add("plnsec","plnsec result shape plane",__FILE__, planesection, g);
1474 theCommands.Add("incmesh","incmesh shape deflection",__FILE__, incrementalmesh, g);
1475 theCommands.Add("MemLeakTest","MemLeakTest",__FILE__, MemLeakTest, g);
1476 theCommands.Add("fastdiscret","fastdiscret shape deflection [shared [nbiter]]",__FILE__, fastdiscret, g);
1477 theCommands.Add("mesh","mesh result Shape deflection [save partage]",__FILE__, triangule, g);
1478 theCommands.Add("addshape","addshape meshname Shape [deflection]",__FILE__, addshape, g);
1479 //theCommands.Add("smooth","smooth meshname",__FILE__, smooth, g);
1480 //theCommands.Add("edges","edges mesh shape, highlight the edges",__FILE__,edges, g);
1481 theCommands.Add("vertices","vertices mesh shape, highlight the vertices",__FILE__,vertices, g);
1482 theCommands.Add("medge","medge mesh [-]index (0 to clear all)",__FILE__,medge, g);
1483 theCommands.Add("mvertex","mvertex mesh [-]index (0 to clear all)",__FILE__,mvertex, g);
1484 theCommands.Add("triangle","triangle mesh [-]index (0 to clear all)",__FILE__,triangle, g);
1485 //theCommands.Add("dumpvertex","dumpvertex mesh [index]",__FILE__,dumpvertex, g);
1486 //theCommands.Add("dumpedge","dumpedge mesh [index]",__FILE__,dumpedge, g);
1487 //theCommands.Add("dumptriangle","dumptriangle mesh [index]",__FILE__,dumptriangle, g);
1489 theCommands.Add("tri2d", "tri2d facename",__FILE__, tri2d, g);
1490 theCommands.Add("trinfo","trinfo name, print triangles information on objects",__FILE__,trianglesinfo,g);
1491 theCommands.Add("veriftriangles","veriftriangles name, verif triangles",__FILE__,veriftriangles,g);
1492 theCommands.Add("wavefront","wavefront name",__FILE__, wavefront, g);
1493 theCommands.Add("onetriangulation","onetriangulation name",__FILE__, onetriangulation, g);
1496 theCommands.Add("extrema","extrema ",__FILE__, extrema, g);
1497 theCommands.Add("vb","vb ",__FILE__, vb, g);