0022627: Change OCCT memory management defaults
[occt.git] / src / MeshTest / MeshTest.cxx
CommitLineData
d51c7072
O
1// File: MeshTest.cxx
2// Created: Wed Sep 22 18:35:55 1993
3// Author: Didier PIFFAULT
4// <dpf@zerox>
7fd59977 5
6#include <Standard_Stream.hxx>
7
8#include <stdio.h>
9
10#include <MeshTest.ixx>
11
12#include <MeshTest_DrawableMesh.hxx>
13#include <TopAbs_ShapeEnum.hxx>
14#include <TopoDS.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>
21#include <DBRep.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>
28#include <Draw.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>
49
50#include <GCPnts_UniformAbscissa.hxx>
51#include <GeomAdaptor_Curve.hxx>
52#include <Geom_Curve.hxx>
53#include <Extrema_LocateExtPC.hxx>
54
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>
62#include <gp_Pln.hxx>
63
64#include <PLib.hxx>
65#include <AppCont_ContMatrices.hxx>
66#include <math_Vector.hxx>
67#include <math_Matrix.hxx>
68#include <math.hxx>
69
70#include <CSLib_DerivativeStatus.hxx>
71#include <CSLib.hxx>
72#include <BRepAdaptor_Surface.hxx>
73#include <Bnd_Box.hxx>
74#include <BRepBndLib.hxx>
75
76
77//epa Memory leaks test
78#include <BRepBuilderAPI_MakePolygon.hxx>
79#include <TopoDS_Wire.hxx>
80#include <BRepBuilderAPI_MakeFace.hxx>
81#include <BRepTools.hxx>
82
d51c7072
O
83//OAN: for triepoints
84#include <BRepBuilderAPI_MakeVertex.hxx>
85#include <Poly_PolygonOnTriangulation.hxx>
86#include <TopTools_MapIteratorOfMapOfShape.hxx>
87
7fd59977 88#ifdef WNT
89Standard_IMPORT Draw_Viewer dout;
90#endif
91
92#define MAX2(X, Y) ( Abs(X) > Abs(Y)? Abs(X) : Abs(Y) )
93#define MAX3(X, Y, Z) ( MAX2 ( MAX2(X,Y) , Z) )
94
95
96
97#define ONETHIRD 0.333333333333333333333333333333333333333333333333333333333333
98#define TWOTHIRD 0.666666666666666666666666666666666666666666666666666666666666
99
100#ifdef DEB_MESH_CHRONO
101#include <OSD_Chronometer.hxx>
102Standard_Integer D0Control, D0Internal, D0Unif, D0Edges, NbControls;
103OSD_Chronometer chTotal, chInternal, chControl, chUnif, chAddPoint;
104OSD_Chronometer chEdges, chMaillEdges, chEtuInter, chLastControl, chStock;
105OSD_Chronometer chAdd11, chAdd12, chAdd2, chUpdate, chPointValid;
106OSD_Chronometer chIsos, chPointsOnIsos;
107#endif
108
109
110
111//=======================================================================
112//function : shapesection
113//purpose :
114//=======================================================================
115
116static Standard_Integer shapesection(Draw_Interpretor&, Standard_Integer nbarg, const char** argv)
117{
118 if (nbarg < 4) return 1;
119
120 TopoDS_Shape S1 = DBRep::Get(argv[2]);
121 TopoDS_Shape S2 = DBRep::Get(argv[3]);
122 if (S1.IsNull() || S2.IsNull()) return 1;
123
124 IntPoly_ShapeSection SECTION(S1,S2);
0d88155b 125 // char name[100];
7fd59977 126 BRep_Builder B;
127 TopoDS_Compound C;
128 B.MakeCompound(C);
129 for (Standard_Integer i = 1 ; i <= SECTION.NbEdges() ; i++) {
130 TopoDS_Shape E = SECTION.Edge(i);
131 if (!E.IsNull()) B.Add(C,E);
132 }
133
134 DBRep::Set(argv[1],C);
135 return 0;
136}
137
138//=======================================================================
139//function : planesection
140//purpose :
141//=======================================================================
142
143static Standard_Integer planesection(Draw_Interpretor&, Standard_Integer nbarg, const char** argv)
144{
145 if (nbarg < 4) return 1;
146
147 TopoDS_Shape S = DBRep::Get(argv[2]);
148 if (S.IsNull()) return 1;
149 Handle(Geom_Surface) Surf = DrawTrSurf::GetSurface(argv[3]);
150
151 Handle(Geom_Plane) pl = Handle(Geom_Plane)::DownCast(Surf);
152 if (!pl.IsNull()) {
153 IntPoly_PlaneSection SECTION(S,pl->Pln());
0d88155b 154 // char name[100];
7fd59977 155 BRep_Builder B;
156 TopoDS_Compound C;
157 B.MakeCompound(C);
158 for (Standard_Integer i = 1 ; i <= SECTION.NbEdges() ; i++) {
159 TopoDS_Shape E = SECTION.Edge(i);
160 if (!E.IsNull()) B.Add(C,E);
161 }
162
163 DBRep::Set(argv[1],C);
164 return 0;
165 }
166 else return 1;
167}
168
169//=======================================================================
170//function : incrementalmesh
171//purpose :
172//=======================================================================
173
d51c7072 174static Standard_Integer incrementalmesh(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
7fd59977 175{
176 if (nbarg < 3) return 1;
177
178 Standard_Real d = atof(argv[2]);
179 TopoDS_Shape S = DBRep::Get(argv[1]);
180 if (S.IsNull()) return 1;
181
182 BRepMesh_IncrementalMesh MESH(S,d);
d51c7072
O
183 Standard_Integer statusFlags = MESH.GetStatusFlags();
184
185 di << "Meshing statuses: ";
186
187 if( !statusFlags )
188 {
189 di << "NoError";
190 }
191 else
192 {
193 Standard_Integer i;
194 for( i = 0; i < 4; i++ )
195 {
196 if( (statusFlags >> i) & (Standard_Integer)1 )
197 {
198 switch(i+1)
199 {
200 case 1:
201 di << "OpenWire ";
202 break;
203 case 2:
204 di << "SelfIntersectingWire ";
205 break;
206 case 3:
207 di << "Failure ";
208 break;
209 case 4:
210 di << "ReMesh ";
211 break;
212 }
213 }
214 }
215 }
216
7fd59977 217 return 0;
218}
219
220//=======================================================================
221//function : MemLeakTest
222//purpose :
223//=======================================================================
224
225static Standard_Integer MemLeakTest(Draw_Interpretor&, Standard_Integer nbarg, const char** argv)
226{
227 for(int i=0;i<10000;i++)
228 {
229 BRepBuilderAPI_MakePolygon w(gp_Pnt(0,0,0),gp_Pnt(0,100,0),gp_Pnt(20,100,0),gp_Pnt(20,0,0));
230 w.Close();
231 TopoDS_Wire wireShape( w.Wire());
232 BRepBuilderAPI_MakeFace faceBuilder(wireShape);
233 TopoDS_Face f( faceBuilder.Face());
234 BRepMesh_IncrementalMesh im(f,1);
235 BRepTools::Clean(f);
236 }
237 return 0;
238}
239
240//=======================================================================
241//function : fastdiscret
242//purpose :
243//=======================================================================
244
245static Standard_Integer fastdiscret(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
246{
247 if (nbarg < 3) return 1;
248
249 TopoDS_Shape S = DBRep::Get(argv[1]);
250 if (S.IsNull()) return 1;
251
252 const Standard_Real d = atof(argv[2]);
253
254 Standard_Boolean WithShare = Standard_True;
255 if (nbarg > 3) WithShare = atoi(argv[3]);
256
257 Bnd_Box B;
258 BRepBndLib::Add(S,B);
259 BRepMesh_FastDiscret MESH(d,0.5,B,WithShare,Standard_True,Standard_False,Standard_True);
260
261 //Standard_Integer NbIterations = MESH.NbIterations();
262 //if (nbarg > 4) NbIterations = atoi(argv[4]);
263 //MESH.NbIterations() = NbIterations;
264
265 di<<"Starting FastDiscret with :"<<"\n";
266 di<<" Deflection="<<d<<"\n";
267 di<<" Angle="<<0.5<<"\n";
268 di<<" SharedMode="<< (Standard_Integer) WithShare<<"\n";
269 //di<<" NbIterations="<<NbIterations<<"\n";
270
271 Handle(Poly_Triangulation) T;
272 BRep_Builder aBuilder;
273 TopExp_Explorer ex;
274
275 // Clear existing triangulations
276 for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next())
277 aBuilder.UpdateFace(TopoDS::Face(ex.Current()),T);
278
279 MESH.Perform(S);
280
281 TopoDS_Compound aCompGood, aCompFailed, aCompViolating;
282
283 TopLoc_Location L;
284 Standard_Integer nbtriangles = 0, nbnodes = 0, nbfailed = 0, nbviolating = 0;
285 Standard_Real maxdef = 0.0;
286 for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next())
287 {
288 T = BRep_Tool::Triangulation(TopoDS::Face(ex.Current()),L);
289 if (T.IsNull())
290 {
291 nbfailed++;
292 if (aCompFailed.IsNull())
293 aBuilder.MakeCompound(aCompFailed);
294 aBuilder.Add(aCompFailed,ex.Current());
295 }
296 else
297 {
298 nbtriangles += T->NbTriangles();
299 nbnodes += T->NbNodes();
300 if (T->Deflection() > maxdef) maxdef = T->Deflection();
301 if (T->Deflection() > d)
302 {
303 nbviolating++;
304 if (aCompViolating.IsNull())
305 aBuilder.MakeCompound(aCompViolating);
306 aBuilder.Add(aCompViolating,ex.Current());
307 }
308 else
309 {
310 if (aCompGood.IsNull())
311 aBuilder.MakeCompound(aCompGood);
312 aBuilder.Add(aCompGood,ex.Current());
313 }
314 }
315 }
316
317 if (!aCompGood.IsNull())
318 {
319 char name[256];
320 strcpy(name,argv[1]);
321 strcat(name,"_good");
322 DBRep::Set(name,aCompGood);
323 }
324 if (!aCompFailed.IsNull())
325 {
326 char name[256];
327 strcpy(name,argv[1]);
328 strcat(name,"_failed");
329 DBRep::Set(name,aCompFailed);
330 }
331 if (!aCompViolating.IsNull())
332 {
333 char name[256];
334 strcpy(name,argv[1]);
335 strcat(name,"_violating");
336 DBRep::Set(name,aCompViolating);
337 }
338
339 di<<"FastDiscret completed with :"<<"\n";
340 di<<" MaxDeflection="<<maxdef<<"\n";
341 di<<" NbNodes="<<nbnodes<<"\n";
342 di<<" NbTriangles="<<nbtriangles<<"\n";
343 di<<" NbFailed="<<nbfailed<<"\n";
344 di<<" NbViolating="<<nbviolating<<"\n";
345
346 return 0;
347}
348
349
350//=======================================================================
351//function : triangule
352//purpose :
353//=======================================================================
354
355
356class BRepMesh_Couple
357{
0d88155b 358public:
7fd59977 359 BRepMesh_Couple() { myI1 = myI2 = 0; }
360 BRepMesh_Couple(const Standard_Integer I1,
0d88155b 361 const Standard_Integer I2)
7fd59977 362 { myI1 = I1; myI2 = I2; }
363
364 Standard_Integer myI1;
365 Standard_Integer myI2;
366};
367
368inline Standard_Boolean IsEqual(const BRepMesh_Couple& one,
369 const BRepMesh_Couple& other)
370{
371 if (one.myI1 == other.myI1 &&
0d88155b 372 one.myI2 == other.myI2) return Standard_True;
7fd59977 373 else return Standard_False;
374}
375
376inline Standard_Integer HashCode(const BRepMesh_Couple& one,
377 const Standard_Integer Upper)
378{
379 return ::HashCode((one.myI1+one.myI2), Upper);
380}
381
382typedef NCollection_Map<BRepMesh_Couple> BRepMesh_MapOfCouple;
383
384
385static void AddLink(BRepMesh_MapOfCouple& aMap,
386 Standard_Integer v1,
387 Standard_Integer v2)
388{
389 Standard_Integer i1 = v1;
390 Standard_Integer i2 = v2;
391 if(i1 > i2) {
392 i1 = v2;
393 i2 = v1;
394 }
395 aMap.Add(BRepMesh_Couple(i1,i2));
396}
397
398static void MeshStats(const TopoDS_Shape& theSape,
0d88155b
O
399 Standard_Integer& theNbTri,
400 Standard_Integer& theNbEdges,
401 Standard_Integer& theNbNodes)
7fd59977 402{
403 theNbTri = 0;
404 theNbEdges = 0;
405 theNbNodes = 0;
406
407 Handle(Poly_Triangulation) T;
408 TopLoc_Location L;
409
410 for ( TopExp_Explorer ex(theSape, TopAbs_FACE); ex.More(); ex.Next()) {
411 TopoDS_Face F = TopoDS::Face(ex.Current());
412 T = BRep_Tool::Triangulation(F, L);
413 if (!T.IsNull()) {
414 theNbTri += T->NbTriangles();
415 theNbNodes += T->NbNodes();
416
417 BRepMesh_MapOfCouple aMap;
418 //count number of links
419 Poly_Array1OfTriangle& Trian = T->ChangeTriangles();
420 for(Standard_Integer i = 1; i<=Trian.Length();i++) {
0d88155b 421 Standard_Integer v1, v2, v3;
7fd59977 422 Trian(i).Get(v1,v2,v3);
423
0d88155b
O
424 AddLink(aMap, v1, v2);
425 AddLink(aMap, v2, v3);
426 AddLink(aMap, v3, v1);
7fd59977 427 }
428
429 theNbEdges+=aMap.Extent();
430 }
431 }
432}
433
434static Standard_Integer triangule(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
435{
436 if (nbarg < 4) return 1;
437
438 Standard_Boolean save = Standard_False;
439
440 const char *id1 = argv[2];
441 TopoDS_Shape S = DBRep::Get(id1);
442 if (S.IsNull()) return 1;
443 di << argv[1] << " ";
444 Standard_Real Deflect=atof(argv[3]);
445 if (Deflect<=0.) {
446 di << " Donner la fleche !" << "\n";
447 return 1;
448 }
449
450 if (nbarg >4) {
451 save = (atoi(argv[4])==1);
452 }
453
454 Standard_Boolean partage=Standard_True;
455 if (nbarg>5) {
456 partage=atoi(argv[5])==1;
457 }
458
459 Handle(MeshTest_DrawableMesh) DM =
460 new MeshTest_DrawableMesh(S,Deflect,partage, save);
461
462 Draw::Set(argv[1],DM);
463
464 Standard_Integer nbn, nbl, nbe;
465 MeshStats(S, nbe, nbl, nbn);
466
467 di<<"(Resultat ("<<nbe<<" mailles) ("<<nbl<<" aretes) ("<<nbn<<" sommets))"<<"\n";
468
469 // passe de verification du maillage.
470 /*Standard_Integer nbc;
471 for (Standard_Integer iLi=1; iLi<= DM->Mesh()->NbEdges(); iLi++) {
0d88155b
O
472 const BRepMesh_Edge& ed=DM->Mesh()->Edge(iLi);
473 if (ed.Movability()!=BRepMesh_Deleted) {
474 nbc=struc->ElemConnectedTo(iLi).Extent();
475 if (nbc != 1 && nbc != 2) di <<"ERROR MAILLAGE Edge no "<< iLi<<"\n";
476 }
7fd59977 477 }*/
478
479 Bnd_Box bobo;
0d88155b 480
7fd59977 481 for (Standard_Integer lepnt=1; lepnt<DM->Mesh()->NbPoint3d(); lepnt++) {
482 bobo.Add(DM->Mesh()->Point3d(lepnt));
483 }
484 Standard_Real x,y,z,X,Y,Z;
485 bobo.Get(x,y,z,X,Y,Z);
486 Standard_Real delta=Max(X-x,Max(Y-y,Z-z));
487 if (delta>0) delta=Deflect/delta;
488 di << " Fleche de " << delta << " fois la taille de l''objet." << "\n";
489
490 return 0;
491}
492
493//=======================================================================
494//function : addshape
495//purpose :
496//=======================================================================
497
498Standard_Integer addshape(Draw_Interpretor&, Standard_Integer n, const char** a)
499{
500 if (n < 3) return 1;
501 Handle(MeshTest_DrawableMesh) D =
502 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
503 if (D.IsNull()) return 1;
504 TopoDS_Shape S = DBRep::Get(a[2]);
505 if (S.IsNull()) return 1;
506
507 D->Add(S);
508 Draw::Repaint();
509
510 return 0;
511}
512
513
514//=======================================================================
515//function : smooth
516//purpose :
517//=======================================================================
518
519/*Standard_Integer smooth(Draw_Interpretor&, Standard_Integer n, const char** a)
520{
0d88155b
O
521if (n < 2) return 1;
522Handle(MeshTest_DrawableMesh) D =
523Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
524if (D.IsNull()) return 1;
525Handle(BRepMesh_DataStructureOfDelaun) struc=
526D->Mesh()->Result();
527BRepMesh_Array1OfVertexOfDelaun toto(1,1);
528BRepMesh_Delaun trial(struc,
529toto,
530Standard_True);
531trial.SmoothMesh(0.1);
532Draw::Repaint();
533return 0;
7fd59977 534}
535*/
536
537//=======================================================================
538//function : edges
539//purpose :
540//=======================================================================
541
0d88155b 542/*static Standard_Integer edges (Draw_Interpretor&, Standard_Integer n, const char** a)
7fd59977 543{
0d88155b
O
544if (n < 3) return 1;
545
546Handle(MeshTest_DrawableMesh) D =
547Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
548if (D.IsNull()) return 1;
549TopoDS_Shape S = DBRep::Get(a[2]);
550if (S.IsNull()) return 1;
551
552TopExp_Explorer ex;
553TColStd_SequenceOfInteger& eseq = D->Edges();
554Handle(BRepMesh_FastDiscret) M = D->Mesh();
555Handle(BRepMesh_DataStructureOfDelaun) DS = M->Result();
556Standard_Integer e1, e2, e3, iTri;
557Standard_Boolean o1, o2, o3;
558
559// the faces
560for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
561const BRepMesh_MapOfInteger& elems = DS->ElemOfDomain();
562BRepMesh_MapOfInteger::Iterator it;
563for (it.Initialize(elems); it.More(); it.Next()) {
564iTri = it.Key();
565const BRepMesh_Triangle& triang = M->Triangle(iTri);
566if (triang.Movability()!=BRepMesh_Deleted) {
567triang.Edges(e1, e2, e3, o1, o2, o3);
568eseq.Append(e1);
569eseq.Append(e2);
570eseq.Append(e3);
571}
572}
573}
7fd59977 574
0d88155b
O
575// the edges
576//for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE);ex.More();ex.Next()) {
577//}
7fd59977 578
0d88155b
O
579Draw::Repaint();
580return 0;
7fd59977 581}
582*/
583
584//=======================================================================
585//function : vertices
586//purpose :
587//=======================================================================
588
589static Standard_Integer vertices (Draw_Interpretor&, Standard_Integer n, const char** a)
590{
591 if (n < 3) return 1;
592
593 Handle(MeshTest_DrawableMesh) D =
594 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
595 if (D.IsNull()) return 1;
596 TopoDS_Shape S = DBRep::Get(a[2]);
597 if (S.IsNull()) return 1;
598
599 TopExp_Explorer ex;
600 TColStd_SequenceOfInteger& vseq = D->Vertices();
601 Handle(BRepMesh_FastDiscret) M = D->Mesh();
0d88155b 602
7fd59977 603 // the faces
604 for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
0d88155b 605 BRepMesh_MapOfInteger vtx;
7fd59977 606 M->VerticesOfDomain(vtx);
0d88155b 607 for (BRepMesh_MapOfInteger::Iterator it(vtx); it.More(); it.Next())
7fd59977 608 vseq.Append(it.Key());
609 }
0d88155b 610
7fd59977 611
612 // the edges
613 //for (ex.Init(S,TopAbs_EDGE,TopAbs_FACE);ex.More();ex.Next()) {
614 //}
0d88155b 615
7fd59977 616 Draw::Repaint();
617 return 0;
618}
619
620//=======================================================================
621//function : medge
622//purpose :
623//=======================================================================
624
625static Standard_Integer medge (Draw_Interpretor&, Standard_Integer n, const char** a)
626{
627 if (n < 3) return 1;
628
629 Handle(MeshTest_DrawableMesh) D =
630 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
631 if (D.IsNull()) return 1;
632
633 Standard_Integer i,j,e;
634 TColStd_SequenceOfInteger& eseq = D->Edges();
635 for (i = 2; i < n; i++) {
636 e = atoi(a[i]);
637 if (e > 0)
638 eseq.Append(e);
639 else if (e < 0) {
640 e = -e;
641 j = 1;
642 while (j <= eseq.Length()) {
0d88155b
O
643 if (eseq(j) == e)
644 eseq.Remove(j);
645 else
646 j++;
7fd59977 647 }
648 }
649 else
650 eseq.Clear();
651 }
0d88155b 652
7fd59977 653 Draw::Repaint();
654 return 0;
655}
656
657
658//=======================================================================
659//function : mvertex
660//purpose :
661//=======================================================================
662
663static Standard_Integer mvertex (Draw_Interpretor&, Standard_Integer n, const char** a)
664{
665 if (n < 3) return 1;
666
667 Handle(MeshTest_DrawableMesh) D =
668 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
669 if (D.IsNull()) return 1;
670
671 Standard_Integer i,j,v;
672 TColStd_SequenceOfInteger& vseq = D->Vertices();
673 for (i = 2; i < n; i++) {
674 v = atoi(a[i]);
675 if (v > 0)
676 vseq.Append(v);
677 else if (v < 0) {
678 v = -v;
679 j = 1;
680 while (j <= vseq.Length()) {
0d88155b
O
681 if (vseq(j) == v)
682 vseq.Remove(v);
683 else
684 j++;
7fd59977 685 }
686 }
687 else
688 vseq.Clear();
689 }
690 Draw::Repaint();
691 return 0;
692}
693
694
695//=======================================================================
696//function : triangle
697//purpose :
698//=======================================================================
699
700static Standard_Integer triangle (Draw_Interpretor&, Standard_Integer n, const char** a)
701{
702 if (n < 3) return 1;
703
704 Handle(MeshTest_DrawableMesh) D =
705 Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(a[1]));
706 if (D.IsNull()) return 1;
707
708 Standard_Integer i,j,v;
709 TColStd_SequenceOfInteger& tseq = D->Triangles();
710 for (i = 2; i < n; i++) {
711 v = atoi(a[i]);
712 if (v > 0)
713 tseq.Append(v);
714 else if (v < 0) {
715 v = -v;
716 j = 1;
717 while (j <= tseq.Length()) {
0d88155b
O
718 if (tseq(j) == v)
719 tseq.Remove(v);
720 else
721 j++;
7fd59977 722 }
723 }
724 else
725 tseq.Clear();
726 }
727 Draw::Repaint();
728 return 0;
729}
730
731
732//=======================================================================
733//function : printdegree
734//purpose :
735//=======================================================================
736
0d88155b 737static void printdegree(BRepMesh_DegreeOfFreedom dof, Draw_Interpretor& di)
7fd59977 738{
739 switch (dof) {
0d88155b
O
740case BRepMesh_InVolume :
741 di << "InVolume";
742 break;
743case BRepMesh_OnSurface :
744 di << "OnSurface";
745 break;
746case BRepMesh_OnCurve :
747 di << "OnCurve";
748 break;
749case BRepMesh_Fixed :
750 di << "Fixed";
751 break;
752case BRepMesh_Frontier :
753 di << "Frontier";
754 break;
755case BRepMesh_Deleted :
756 di << "Deleted";
757 break;
758case BRepMesh_Free :
759 di << "Free";
760 break;
7fd59977 761 }
762}
763
764//=======================================================================
765//function : dumpvertex
766//purpose :
767//=======================================================================
768
769/*
770Standard_Integer dumpvertex(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
771{
0d88155b 772if (argc < 2) return 1;
7fd59977 773
0d88155b
O
774Handle(MeshTest_DrawableMesh) D =
775Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(argv[1]));
776if (D.IsNull()) return 1;
7fd59977 777
0d88155b 778Handle(BRepMesh_DataStructureOfDelaun) struc = D->Mesh()->Result();
7fd59977 779
0d88155b
O
780Standard_Integer in=1;
781if (argc>=3) {
782in=atoi(argv[2]);
783in=Max(1,in);
784}
785Standard_Integer nbn=in;
786if (argc>=4) {
787nbn=atoi(argv[3]);
788nbn=Min(nbn,struc->NbNodes());
789}
790
791for (; in<=nbn; in++) {
792BRepMesh_Vertex nod=struc->GetNode(in);
793di<<"(node "<<in<<" (uv "<<nod.Coord().X()
794<<" "<<nod.Coord().Y()<<") (3d "
795<<nod.Location3d()<<") ";
796printdegree(nod.Movability(), di);
797di<<" (edgeconex";
798BRepMesh_ListOfInteger::Iterator tati(struc->LinkNeighboursOf(in));
799for (; tati.More(); tati.Next()) di<<" "<<tati.Value();
800di << "))\n";
801}
802di <<"\n";
803return 0;
7fd59977 804}
805
806//=======================================================================
807//function : dumpedge
808//purpose :
809//=======================================================================
810
811Standard_Integer dumpedge(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
812{
0d88155b 813if (argc < 2) return 1;
7fd59977 814
0d88155b
O
815Handle(MeshTest_DrawableMesh) D =
816Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(argv[1]));
817if (D.IsNull()) return 1;
7fd59977 818
0d88155b
O
819Handle(BRepMesh_DataStructureOfDelaun) struc=D->Mesh()->Result();
820Standard_Integer il=1;
821if (argc>=3) {
822il=atoi(argv[2]);
823il=Max(1, il);
824}
825Standard_Integer nbl=il;
826if (argc>=4) {
827nbl=atoi(argv[3]);
828nbl=Min(nbl, struc->NbLinks());
829}
830
831for (; il<=nbl; il++) {
832BRepMesh_Edge edg=struc->GetLink(il);
833di << "(edge "<<il<<" ("<<edg.FirstNode()<<" "<<edg.LastNode()
834<<" ";
835printdegree(edg.Movability(), di);
836di<<") (triconex";
837const BRepMesh_PairOfIndex& pair = struc->ElemConnectedTo(il);
838for (Standard_Integer j = 1, jn = pair.Extent(); j <= jn; j++)
839di<<" "<<pair.Index(j);
840di << "))\n";
841}
842di <<"\n";
843return 0;
7fd59977 844}
845
846//=======================================================================
847//function : dumptriangle
848//purpose :
849//=======================================================================
850
851Standard_Integer dumptriangle(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
852{
0d88155b 853if (argc < 2) return 1;
7fd59977 854
0d88155b
O
855Handle(MeshTest_DrawableMesh) D =
856Handle(MeshTest_DrawableMesh)::DownCast(Draw::Get(argv[1]));
857if (D.IsNull()) return 1;
7fd59977 858
0d88155b
O
859Handle(BRepMesh_DataStructureOfDelaun) struc=D->Mesh()->Result();
860Standard_Integer ie=1;
861if (argc>=3) {
862ie=atoi(argv[2]);
863ie=Max(1, ie);
864}
865Standard_Integer nbe=ie;
866if (argc>=4) {
867nbe=atoi(argv[3]);
868nbe=Min(nbe, struc->NbElements());
869}
870
871Standard_Integer e1, e2, e3;
872Standard_Boolean o1, o2, o3;
873
874for (; ie<=nbe; ie++) {
875BRepMesh_Triangle tri=struc->GetElement(ie);
876tri.Edges(e1, e2, e3, o1, o2, o3);
877if (o1) e1=-e1;
878if (o2) e2=-e2;
879if (o3) e3=-e3;
880di<<" (maille "<<ie<<" (links "<<e1<<" "
881<<e2<<" "<<e3<<")";
882printdegree(tri.Movability(), di);
883di<<")\n";
884}
885di << "\n";
886return 0;
7fd59977 887}
888*/
889
890//=======================================================================
891//function : trianglesinfo
892//purpose :
893//=======================================================================
894static Standard_Integer trianglesinfo(Draw_Interpretor& di, Standard_Integer n, const char** a)
895{
896 if (n != 2) return 1;
897 TopoDS_Shape S = DBRep::Get(a[1]);
898 if (S.IsNull()) return 1;
899 TopExp_Explorer ex;
900 Handle(Poly_Triangulation) T;
901 TopLoc_Location L;
902
903 Standard_Real MaxDeflection = 0.0;
904 Standard_Integer nbtriangles = 0, nbnodes = 0;
905 for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next()) {
906 TopoDS_Face F = TopoDS::Face(ex.Current());
907 T = BRep_Tool::Triangulation(F, L);
908 if (!T.IsNull()) {
909 nbtriangles += T->NbTriangles();
910 nbnodes += T->NbNodes();
911 if (T->Deflection() > MaxDeflection)
912 MaxDeflection = T->Deflection();
913 }
914 }
915
916 di<<"\n";
917 di<<"This shape contains " <<nbtriangles<<" triangles."<<"\n";
918 di<<" " <<nbnodes <<" nodes."<<"\n";
919 di<<"Maximal deflection " <<MaxDeflection<<"\n";
920 di<<"\n";
921#ifdef DEB_MESH_CHRONO
922 Standard_Real tot, addp, unif, contr, inter;
923 Standard_Real edges, mailledges, etuinter, lastcontrol, stock;
924 Standard_Real add11, add12, add2, upda, pointvalid;
925 Standard_Real isos, pointsisos;
926 chTotal.Show(tot); chAddPoint.Show(addp); chUnif.Show(unif);
927 chControl.Show(contr); chInternal.Show(inter);
928 chEdges.Show(edges); chMaillEdges.Show(mailledges);
929 chEtuInter.Show(etuinter); chLastControl.Show(lastcontrol);
930 chStock.Show(stock);
931 chAdd11.Show(add11); chAdd12.Show(add12); chAdd2.Show(add2); chUpdate.Show(upda);
932 chPointValid.Show(pointvalid); chIsos.Show(isos); chPointsOnIsos.Show(pointsisos);
933
934 if (tot > 0.00001) {
0d88155b
O
935 di <<"temps total de maillage: "<<tot <<" seconds"<< "\n";
936 di <<"dont: "<< "\n";
937 di <<"discretisation des edges: "<<edges <<" seconds---> "<< 100*edges/tot <<" %"<<"\n";
938 di <<"maillage des edges: "<<mailledges <<" seconds---> "<< 100*mailledges/tot <<" %"<<"\n";
939 di <<"controle et points internes: "<<etuinter <<" seconds---> "<< 100*etuinter/tot <<" %"<<"\n";
940 di <<"derniers controles: "<<lastcontrol<<" seconds---> "<< 100*lastcontrol/tot<<" %"<<"\n";
941 di <<"stockage dans la S.D. "<<stock <<" seconds---> "<< 100*stock/tot <<" %"<<"\n";
942 di << "\n";
943 di <<"et plus precisement: "<<"\n";
944 di <<"Add 11ere partie : "<<add11 <<" seconds---> "<<100*add11/tot <<" %"<<"\n";
945 di <<"Add 12ere partie : "<<add12 <<" seconds---> "<<100*add12/tot <<" %"<<"\n";
946 di <<"Add 2eme partie : "<<add2 <<" seconds---> "<<100*add2/tot <<" %"<<"\n";
947 di <<"Update : "<<upda <<" seconds---> "<<100*upda/tot <<" %"<<"\n";
948 di <<"AddPoint : "<<addp <<" seconds---> "<<100*addp/tot <<" %"<<"\n";
949 di <<"UniformDeflection "<<unif <<" seconds---> "<<100*unif/tot <<" %"<<"\n";
950 di <<"Controle : "<<contr <<" seconds---> "<<100*contr/tot <<" %"<<"\n";
951 di <<"Points Internes: "<<inter <<" seconds---> "<<100*inter/tot <<" %"<<"\n";
952 di <<"calcul des isos et du, dv: "<<isos <<" seconds---> "<<100*isos/tot <<" %"<<"\n";
953 di <<"calcul des points sur isos: "<<pointsisos<<" seconds---> "<<100*pointsisos/tot <<" %"<<"\n";
954 di <<"IsPointValid: "<<pointvalid<<" seconds---> "<<100*pointvalid/tot <<" %"<<"\n";
955 di << "\n";
956
957
958 di <<"nombre d'appels de controle apres points internes : "<< NbControls << "\n";
959 di <<"nombre de points sur restrictions : "<< D0Edges << "\n";
960 di <<"nombre de points calcules par UniformDeflection : "<< D0Unif << "\n";
961 di <<"nombre de points calcules dans InternalVertices : "<< D0Internal << "\n";
962 di <<"nombre de points calcules dans Control : "<< D0Control << "\n";
963 if (nbnodes-D0Edges != 0) {
964 Standard_Real ratio = (Standard_Real)(D0Internal+D0Control)/ (Standard_Real)(nbnodes-D0Edges);
965 di <<"---> Ratio: (D0Internal+D0Control) / (nbNodes-nbOnEdges) : "<< ratio << "\n";
966 }
7fd59977 967
0d88155b 968 di << "\n";
7fd59977 969
0d88155b
O
970 chTotal.Reset(); chAddPoint.Reset(); chUnif.Reset();
971 chControl.Reset(); chInternal.Reset();
972 chEdges.Reset(); chMaillEdges.Reset();
973 chEtuInter.Reset(); chLastControl.Reset();
974 chStock.Reset();
975 chAdd11.Reset(); chAdd12.Reset(); chAdd2.Reset(); chUpdate.Reset();
976 chPointValid.Reset(); chIsos.Reset(); chPointsOnIsos.Reset();
7fd59977 977
978 }
979#endif
980 return 0;
981}
982
983//=======================================================================
984//function : veriftriangles
985//purpose :
986//=======================================================================
987
988static Standard_Integer veriftriangles(Draw_Interpretor& di, Standard_Integer n, const char** a)
989{
990 if (n < 2) return 1;
991 Standard_Boolean quiet = 1;
992 if (n == 3) quiet = 0;
993 TopoDS_Shape Sh = DBRep::Get(a[1]);
994 if (Sh.IsNull()) return 1;
995 TopExp_Explorer ex;
996 Handle(Poly_Triangulation) T;
997 TopLoc_Location L;
998 Standard_Integer i, n1, n2, n3;
999 gp_Pnt2d mitri, v1, v2, v3, mi2d1, mi2d2, mi2d3;
1000 gp_XYZ vecEd1, vecEd2, vecEd3;
0d88155b 1001 // Standard_Real dipo, dm, dv, d1, d2, d3, defle;
7fd59977 1002 Standard_Real dipo, dv, d1, d2, d3, defle;
1003 Handle(Geom_Surface) S;
1004 Standard_Integer nbface = 0;
1005 gp_Pnt PP;
1006
1007 for (ex.Init(Sh, TopAbs_FACE); ex.More(); ex.Next()) {
1008 TopoDS_Face F = TopoDS::Face(ex.Current());
1009 nbface++;
1010 T = BRep_Tool::Triangulation(F, L);
1011 Standard_Real deflemax = 0, deflemin = 1.e100;
1012 if (!T.IsNull()) {
1013 Standard_Real defstock = T->Deflection();
1014 const Poly_Array1OfTriangle& triangles = T->Triangles();
1015 const TColgp_Array1OfPnt2d& Nodes2d = T->UVNodes();
1016 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1017
1018 S = BRep_Tool::Surface(F, L);
1019
1020 for(i = 1; i <= triangles.Length(); i++) {
0d88155b
O
1021 if (F.Orientation() == TopAbs_REVERSED)
1022 triangles(i).Get(n1,n3,n2);
1023 else
1024 triangles(i).Get(n1,n2,n3);
1025
1026 const gp_XY& xy1 = Nodes2d(n1).XY();
1027 const gp_XY& xy2 = Nodes2d(n2).XY();
1028 const gp_XY& xy3 = Nodes2d(n3).XY();
1029
1030 mi2d1.SetCoord((xy2.X()+xy3.X())*0.5,
1031 (xy2.Y()+xy3.Y())*0.5);
1032 mi2d2.SetCoord((xy1.X()+xy3.X())*0.5,
1033 (xy1.Y()+xy3.Y())*0.5);
1034 mi2d3.SetCoord((xy1.X()+xy2.X())*0.5,
1035 (xy1.Y()+xy2.Y())*0.5);
1036
1037 gp_XYZ p1 = Nodes(n1).Transformed(L.Transformation()).XYZ();
1038 gp_XYZ p2 = Nodes(n2).Transformed(L.Transformation()).XYZ();
1039 gp_XYZ p3 = Nodes(n3).Transformed(L.Transformation()).XYZ();
1040
1041 vecEd1=p2-p1;
1042 vecEd2=p3-p2;
1043 vecEd3=p1-p3;
1044 d1=vecEd1.SquareModulus();
1045 d2=vecEd2.SquareModulus();
1046 d3=vecEd3.SquareModulus();
1047
1048 if (d1!=0. && d2!=0. && d3!=0.) {
1049 gp_XYZ equa(vecEd1^vecEd2);
1050 dv=equa.Modulus();
1051 if (dv>0.) {
1052 equa.SetCoord(equa.X()/dv, equa.Y()/dv, equa.Z()/dv);
1053 dipo=equa*p1;
1054
1055
1056 mitri.SetCoord(ONETHIRD*(xy1.X()+xy2.X()+xy3.X()),
1057 ONETHIRD*(xy1.Y()+xy2.Y()+xy3.Y()));
1058 v1.SetCoord(ONETHIRD*mi2d1.X()+TWOTHIRD*xy1.X(),
1059 ONETHIRD*mi2d1.Y()+TWOTHIRD*xy1.Y());
1060 v2.SetCoord(ONETHIRD*mi2d2.X()+TWOTHIRD*xy2.X(),
1061 ONETHIRD*mi2d2.Y()+TWOTHIRD*xy2.Y());
1062 v3.SetCoord(ONETHIRD*mi2d3.X()+TWOTHIRD*xy3.X(),
1063 ONETHIRD*mi2d3.Y()+TWOTHIRD*xy3.Y());
1064
1065 S->D0(mi2d1.X(), mi2d1.Y(), PP);
1066 PP = PP.Transformed(L.Transformation());
1067 defle = Abs((equa*PP.XYZ())-dipo);
1068 deflemax = Max(deflemax, defle);
1069 deflemin = Min(deflemin, defle);
1070
1071 S->D0(mi2d2.X(), mi2d2.Y(), PP);
1072 PP = PP.Transformed(L.Transformation());
1073 defle = Abs((equa*PP.XYZ())-dipo);
1074 deflemax = Max(deflemax, defle);
1075 deflemin = Min(deflemin, defle);
1076
1077 S->D0(mi2d3.X(), mi2d3.Y(), PP);
1078 PP = PP.Transformed(L.Transformation());
1079 defle = Abs((equa*PP.XYZ())-dipo);
1080 deflemax = Max(deflemax, defle);
1081 deflemin = Min(deflemin, defle);
1082
1083 S->D0(v1.X(), v1.Y(), PP);
1084 PP = PP.Transformed(L.Transformation());
1085 defle = Abs((equa*PP.XYZ())-dipo);
1086 deflemax = Max(deflemax, defle);
1087 deflemin = Min(deflemin, defle);
1088
1089 S->D0(v2.X(), v2.Y(), PP);
1090 PP = PP.Transformed(L.Transformation());
1091 defle = Abs((equa*PP.XYZ())-dipo);
1092 deflemax = Max(deflemax, defle);
1093 deflemin = Min(deflemin, defle);
1094
1095 S->D0(v3.X(), v3.Y(), PP);
1096 PP = PP.Transformed(L.Transformation());
1097 defle = Abs((equa*PP.XYZ())-dipo);
1098 deflemax = Max(deflemax, defle);
1099 deflemin = Min(deflemin, defle);
1100
1101 S->D0(mitri.X(), mitri.Y(), PP);
1102 PP = PP.Transformed(L.Transformation());
1103 defle = Abs((equa*PP.XYZ())-dipo);
1104 deflemax = Max(deflemax, defle);
1105 deflemin = Min(deflemin, defle);
1106
1107 if (defle > defstock) {
1108 di <<"face "<< nbface <<" deflection = " << defle <<" pour "<<defstock <<" stockee."<<"\n";
1109 }
1110 }
1111 }
7fd59977 1112 }
1113 if (!quiet) {
0d88155b 1114 di <<"face "<< nbface<<", deflemin = "<< deflemin<<", deflemax = "<<deflemax<<"\n";
7fd59977 1115 }
1116
1117 }
1118 }
1119
1120
1121 return 0;
1122}
1123
1124
1125
1126
1127//=======================================================================
1128//function : tri2d
1129//purpose :
1130//=======================================================================
1131
1132Standard_Integer tri2d(Draw_Interpretor&, Standard_Integer n, const char** a)
1133{
1134
1135 if (n != 2) return 1;
1136 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
1137 TopoDS_Face F = TopoDS::Face(aLocalShape);
0d88155b 1138 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[1]));
7fd59977 1139 if (F.IsNull()) return 1;
1140 Handle(Poly_Triangulation) T;
1141 TopLoc_Location L;
1142
1143 T = BRep_Tool::Triangulation(F, L);
1144 if (!T.IsNull()) {
1145#ifdef DEB
1146 gp_Trsf tr = L.Transformation();
1147#else
1148 L.Transformation();
1149#endif
1150
1151 // Build the connect tool
1152 Poly_Connect pc(T);
0d88155b 1153
7fd59977 1154 Standard_Integer i,j, nFree, nInternal, nbTriangles = T->NbTriangles();
1155 Standard_Integer t[3];
0d88155b 1156
7fd59977 1157 // count the free edges
1158 nFree = 0;
1159 for (i = 1; i <= nbTriangles; i++) {
1160 pc.Triangles(i,t[0],t[1],t[2]);
1161 for (j = 0; j < 3; j++)
0d88155b 1162 if (t[j] == 0) nFree++;
7fd59977 1163 }
0d88155b 1164
7fd59977 1165 // allocate the arrays
1166 TColStd_Array1OfInteger Free(1,2*nFree);
1167 nInternal = (3*nbTriangles - nFree) / 2;
1168 TColStd_Array1OfInteger Internal(0,2*nInternal);
0d88155b 1169
7fd59977 1170 Standard_Integer fr = 1, in = 1;
1171 const Poly_Array1OfTriangle& triangles = T->Triangles();
1172 Standard_Integer nodes[3];
1173 for (i = 1; i <= nbTriangles; i++) {
1174 pc.Triangles(i,t[0],t[1],t[2]);
1175 triangles(i).Get(nodes[0],nodes[1],nodes[2]);
1176 for (j = 0; j < 3; j++) {
0d88155b
O
1177 Standard_Integer k = (j+1) % 3;
1178 if (t[j] == 0) {
1179 Free(fr) = nodes[j];
1180 Free(fr+1) = nodes[k];
1181 fr += 2;
1182 }
1183 // internal edge if this triangle has a lower index than the adjacent
1184 else if (i < t[j]) {
1185 Internal(in) = nodes[j];
1186 Internal(in+1) = nodes[k];
1187 in += 2;
1188 }
7fd59977 1189 }
1190 }
0d88155b 1191
7fd59977 1192 // Display the edges
1193 if (T->HasUVNodes()) {
1194 const TColgp_Array1OfPnt2d& Nodes2d = T->UVNodes();
1195
1196 Handle(Draw_Segment2D) Seg;
1197
1198 // free edges
1199 Standard_Integer nn;
1200 nn = Free.Length() / 2;
1201 for (i = 1; i <= nn; i++) {
0d88155b
O
1202 Seg = new Draw_Segment2D(Nodes2d(Free(2*i-1)),
1203 Nodes2d(Free(2*i)),
1204 Draw_rouge);
1205 dout << Seg;
7fd59977 1206 }
0d88155b 1207
7fd59977 1208 // internal edges
0d88155b 1209
7fd59977 1210 nn = nInternal;
1211 for (i = 1; i <= nn; i++) {
0d88155b
O
1212 Seg = new Draw_Segment2D(Nodes2d(Internal(2*i-1)),
1213 Nodes2d(Internal(2*i)),
1214 Draw_bleu);
1215 dout << Seg;
7fd59977 1216 }
1217 }
1218 dout.Flush();
1219 }
1220
1221 return 0;
1222}
1223
1224
1225
1226
1227//=======================================================================
1228//function : wavefront
1229//purpose :
1230//=======================================================================
1231
1232static Standard_Integer wavefront(Draw_Interpretor&, Standard_Integer nbarg, const char** argv)
1233{
1234 if (nbarg < 2) return 1;
1235
1236 TopoDS_Shape S = DBRep::Get(argv[1]);
1237 if (S.IsNull()) return 1;
1238
1239 // creation du maillage s'il n'existe pas.
1240
1241 Bnd_Box B;
1242 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
1243 BRepBndLib::Add(S, B);
1244 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
1245 Standard_Real aDeflection =
1246 MAX3( aXmax-aXmin , aYmax-aYmin , aZmax-aZmin) * 0.004;
1247
1248 BRepMesh_IncrementalMesh(S, aDeflection);
1249
1250
1251 TopLoc_Location L;
1252 TopExp_Explorer ex;
1253
1254 Standard_Integer i, nbface = 0;
1255 Standard_Boolean OK = Standard_True;
1256 gp_Vec D1U,D1V;
1257 gp_Vec D2U,D2V,D2UV;
1258 gp_Dir Nor;
1259 gp_Pnt P;
1260 Standard_Real U, V;
1261 CSLib_DerivativeStatus Status;
1262 CSLib_NormalStatus NStat;
1263 Standard_Real x, y, z;
1264 Standard_Integer n1, n2, n3;
1265 Standard_Integer k1, k2, k3;
0d88155b 1266
7fd59977 1267 char ffile[100];
0d88155b 1268
7fd59977 1269 if (nbarg == 3) {
1270 strcpy(ffile, argv[2]);
1271 strcat(ffile, ".obj");
1272 }
1273 else strcpy(ffile, "wave.obj");
1274 FILE* outfile = fopen(ffile, "w");
1275
1276
1277 fprintf(outfile, "%s %s\n%s %s\n\n", "# CASCADE ","MATRA DATAVISION", "#", ffile);
1278
1279 Standard_Integer nbNodes, totalnodes = 0, nbpolygons = 0;
1280 for (ex.Init(S, TopAbs_FACE); ex.More(); ex.Next()) {
1281 nbface++;
1282 TopoDS_Face F = TopoDS::Face(ex.Current());
1283 Handle(Poly_Triangulation) Tr = BRep_Tool::Triangulation(F, L);
0d88155b 1284
7fd59977 1285 if (!Tr.IsNull()) {
1286 nbNodes = Tr->NbNodes();
1287 const TColgp_Array1OfPnt& Nodes = Tr->Nodes();
0d88155b 1288
7fd59977 1289 // les noeuds.
1290 for (i = 1; i <= nbNodes; i++) {
0d88155b
O
1291 gp_Pnt Pnt = Nodes(i).Transformed(L.Transformation());
1292 x = Pnt.X();
1293 y = Pnt.Y();
1294 z = Pnt.Z();
1295 fprintf(outfile, "%s %f %f %f\n", "v", x, y, z);
7fd59977 1296 }
0d88155b 1297
7fd59977 1298 fprintf(outfile, "\n%s %d\n\n", "# number of vertex", nbNodes);
0d88155b
O
1299
1300
7fd59977 1301 // les normales.
0d88155b 1302
7fd59977 1303 if (Tr->HasUVNodes()) {
0d88155b
O
1304 const TColgp_Array1OfPnt2d& UVNodes = Tr->UVNodes();
1305 BRepAdaptor_Surface BS(F, Standard_False);
1306
1307 for (i = 1; i <= nbNodes; i++) {
1308 U = UVNodes(i).X();
1309 V = UVNodes(i).Y();
1310
1311 BS.D1(U,V,P,D1U,D1V);
1312 CSLib::Normal(D1U,D1V,Precision::Angular(),Status,Nor);
1313 if (Status != CSLib_Done) {
1314 BS.D2(U,V,P,D1U,D1V,D2U,D2V,D2UV);
1315 CSLib::Normal(D1U,D1V,D2U,D2V,D2UV,Precision::Angular(),OK,NStat,Nor);
1316 }
1317 if (F.Orientation() == TopAbs_REVERSED) Nor.Reverse();
1318
1319 fprintf(outfile, "%s %f %f %f\n", "vn", Nor.X(), Nor.Y(), Nor.Z());
1320 }
1321
1322 fprintf(outfile, "\n%s %d\n\n", "# number of vertex normals", nbNodes);
7fd59977 1323 }
0d88155b 1324
7fd59977 1325 fprintf(outfile, "%s %d\n", "s", nbface);
0d88155b 1326
7fd59977 1327 // les triangles.
1328 Standard_Integer nbTriangles = Tr->NbTriangles();
1329 const Poly_Array1OfTriangle& triangles = Tr->Triangles();
0d88155b
O
1330
1331
7fd59977 1332 for (i = 1; i <= nbTriangles; i++) {
0d88155b
O
1333 if (F.Orientation() == TopAbs_REVERSED)
1334 triangles(i).Get(n1, n3, n2);
1335 else
1336 triangles(i).Get(n1, n2, n3);
1337 k1 = n1+totalnodes;
1338 k2 = n2+totalnodes;
1339 k3 = n3+totalnodes;
1340 fprintf(outfile, "%s %d%s%d %d%s%d %d%s%d\n", "fo", k1,"//", k1, k2,"//", k2, k3,"//", k3);
7fd59977 1341 }
1342 nbpolygons += nbTriangles;
1343 totalnodes += nbNodes;
0d88155b 1344
7fd59977 1345 fprintf(outfile, "\n%s %d\n", "# number of smooth groups", nbface);
1346 fprintf(outfile, "\n%s %d\n", "# number of polygons", nbpolygons);
0d88155b 1347
7fd59977 1348 }
1349 }
1350
1351 fclose(outfile);
1352
1353 return 0;
1354}
1355
1356
1357//=======================================================================
1358//function : onetriangulation
1359//purpose :
1360//=======================================================================
1361
1362Standard_Integer onetriangulation(Draw_Interpretor&, Standard_Integer nbarg, const char** argv)
1363{
1364
0d88155b 1365 /*
7fd59977 1366
1367 if (nbarg < 2) return 1;
1368
1369 TopoDS_Shape S = DBRep::Get(argv[1]);
1370 if (S.IsNull()) return 1;
0d88155b 1371
7fd59977 1372 Handle(Poly_Triangulation) TFinale;
1373 char name[100];
1374 Standard_Integer nbshell = 0;
1375
1376 TopExp_Explorer ex, exs, ex2;
0d88155b 1377
7fd59977 1378 for (ex.Init(S, TopAbs_SHELL); ex.More(); ex.Next()) {
0d88155b
O
1379 nbshell++;
1380 TopoDS_Shell Sh = TopoDS::Shell(ex.Current());
1381
1382 for (exs.Init(Sh, TopAbs_Face); exs.More(); exs.Next()) {
1383 TopoDS_Face F = TopoDS::Face(exs.Current());
1384 Handle(Poly_Triangulation) T = BRep_Tool::Triangulation(F, L);
1385
1386 for (ex2.Init(F, TopAbs_EDGE); ex2.More(); ex2.Next()) {
1387 TopoDS_Edge edge = TopoDS::Edge(ex2.Current());
1388 const TColgp_Array1OfPnt& Nodes = T->Nodes();
1389 const Poly_Array1OfTriangle& triangles = T->Triangles();
7fd59977 1390
0d88155b
O
1391 if (mapedges.IsBound(edge)) {
1392 const TColStd_ListOfTransient& L = edges.Find(edge);
1393 const Handle(Poly_PolygonOnTriangulation)& P =
1394 *(Handle(Poly_PolygonOnTriangulation)*)&(L.First());
1395 const TColStd_Array1OfInteger& NOD = P->Nodes();
1396
1397 }
1398 }
7fd59977 1399 }
1400
0d88155b
O
1401 sprintf(name, "%s_%i", "tr", nbshell);
1402 DrawTrSurf::Set(name, TFinale);
1403
1404 }
1405
1406 */
7fd59977 1407 return 0;
1408}
1409
1410
1411#if 0
1412
1413//=======================================================================
1414//function : vb
1415//purpose :
1416//=======================================================================
1417
1418Standard_Integer vb(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
1419{
1420 Standard_Integer NbPoints = 1, Deg = 1;
1421
1422 for (Deg = 1; Deg <= 25; Deg++) {
1423 for (NbPoints = 1; NbPoints <= 24; NbPoints++) {
1424
1425 math_Vector GaussP(1, NbPoints), GaussW(1, NbPoints);
1426 math_Vector TheWeights(1, NbPoints), VBParam(1, NbPoints);
1427 math_Matrix VB(1, Deg+1, 1, NbPoints);
0d88155b 1428
7fd59977 1429 math::GaussPoints(NbPoints, GaussP);
0d88155b 1430
7fd59977 1431 Standard_Integer i, j, classe = Deg+1, cl1 = Deg;
0d88155b 1432
7fd59977 1433 // calcul et mise en ordre des parametres et des poids:
1434 for (i = 1; i <= NbPoints; i++) {
0d88155b
O
1435 if (i <= (NbPoints+1)/2) {
1436 VBParam(NbPoints-i+1) = 0.5*(1 + GaussP(i));
1437 }
1438 else {
1439 VBParam(i-(NbPoints+1)/2) = 0.5*(1 + GaussP(i));
1440 }
7fd59977 1441 }
0d88155b
O
1442
1443
7fd59977 1444 // Calcul du VB (Valeur des fonctions de Bernstein):
1445 for (i = 1; i <= classe; i++) {
0d88155b
O
1446 for (j = 1; j <= NbPoints; j++) {
1447 VB(i,j)=PLib::Binomial(cl1,i-1)*Pow((1-VBParam(j)),classe-i)*Pow(VBParam(j),i-1);
1448 }
7fd59977 1449 }
0d88155b
O
1450
1451
7fd59977 1452 for (i = 1; i <= classe; i++) {
0d88155b
O
1453 for (j = 1; j <= NbPoints; j++) {
1454 di<< VB(i, j) << ", ";
1455 }
7fd59977 1456 }
1457 di << "\n" << "\n";
1458 }
1459 }
1460 return 0;
1461}
1462//=======================================================================
1463//function : extrema
1464//purpose :
1465//=======================================================================
1466
1467Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
1468{
0d88155b
O
1469
1470
7fd59977 1471 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(argv[1]);
1472
1473 Standard_Real X, Y, Z, U0;
1474 X = atof(argv[2]);
1475 Y = atof(argv[3]);
1476 Z = atof(argv[4]);
1477 U0 = atof(argv[5]);
1478
1479 gp_Pnt P(X, Y, Z);
1480 GeomAdaptor_Curve GC(C);
1481 Standard_Real tol = 1.e-09;
1482 Extrema_LocateExtPC ext(P, GC, U0, tol);
1483
1484 if (ext.IsDone()) {
1485 gp_Pnt P1 = ext.Point().Value();
1486 di <<"distance = "<<ext.Value() << "\n";
1487 di <<"point = "<<P1.X()<<" "<<P1.Y()<<" "<< P1.Z()<< "\n";
1488 di <<"parametre = "<<ext.Point().Parameter()<<"\n";
1489 }
1490
1491 return 0;
1492}
1493
1494#endif
1495
1496
d51c7072
O
1497//=======================================================================
1498//function : triedgepoints
1499//purpose :
1500//=======================================================================
1501
1502Standard_Integer triedgepoints(Draw_Interpretor& di, Standard_Integer nbarg, const char** argv)
1503{
1504 if( nbarg < 2 )
1505 return 1;
7fd59977 1506
d51c7072
O
1507 for( Standard_Integer i = 1; i < nbarg; i++ )
1508 {
1509 TopoDS_Shape aShape = DBRep::Get(argv[i]);
1510 if ( aShape.IsNull() )
1511 continue;
1512
1513 Handle(Poly_PolygonOnTriangulation) aPoly;
1514 Handle(Poly_Triangulation) aT;
1515 TopLoc_Location aLoc;
1516 TopTools_MapOfShape anEdgeMap;
1517 TopTools_MapIteratorOfMapOfShape it;
1518
1519 if( aShape.ShapeType() == TopAbs_EDGE )
1520 {
1521 anEdgeMap.Add( aShape );
1522 }
1523 else
1524 {
1525 TopExp_Explorer ex(aShape, TopAbs_EDGE);
1526 for(; ex.More(); ex.Next() )
1527 anEdgeMap.Add( ex.Current() );
1528 }
1529
1530 if ( anEdgeMap.Extent() == 0 )
1531 continue;
1532
1533 char newname[1024];
1534 strcpy(newname,argv[i]);
1535 char* p = newname;
1536 while (*p != '\0') p++;
1537 *p = '_';
1538 p++;
1539
1540 Standard_Integer nbEdge = 1;
1541 for(it.Initialize(anEdgeMap); it.More(); it.Next())
1542 {
1543 BRep_Tool::PolygonOnTriangulation(TopoDS::Edge(it.Key()), aPoly, aT, aLoc);
1544 if ( aT.IsNull() || aPoly.IsNull() )
1545 continue;
1546
1547 const TColgp_Array1OfPnt& Nodes = aT->Nodes();
1548 const TColStd_Array1OfInteger& Indices = aPoly->Nodes();
1549 const Standard_Integer nbnodes = Indices.Length();
1550
1551 for( Standard_Integer j = 1; j <= nbnodes; j++ )
1552 {
1553 gp_Pnt P3d = Nodes(Indices(j));
1554 if( !aLoc.IsIdentity() )
1555 P3d.Transform(aLoc.Transformation());
1556
1557 if( anEdgeMap.Extent() > 1 )
1558 sprintf(p,"%d_%d",nbEdge,j);
1559 else
1560 sprintf(p,"%d",j);
1561 DBRep::Set( newname, BRepBuilderAPI_MakeVertex(P3d) );
1562 di.AppendElement(newname);
1563 }
1564 nbEdge++;
1565 }
1566 }
1567 return 0;
1568}
7fd59977 1569
1570//=======================================================================
0d88155b 1571void MeshTest::Commands(Draw_Interpretor& theCommands)
7fd59977 1572//=======================================================================
1573{
1574 Draw::Commands(theCommands);
1575 BRepTest::AllCommands(theCommands);
1576 GeometryTest::AllCommands(theCommands);
1577 MeshTest::PluginCommands(theCommands);
1578 const char* g;
1579
1580 g = "Mesh Commands";
0d88155b 1581
7fd59977 1582 theCommands.Add("shpsec","shpsec result shape shape",__FILE__, shapesection, g);
1583 theCommands.Add("plnsec","plnsec result shape plane",__FILE__, planesection, g);
1584 theCommands.Add("incmesh","incmesh shape deflection",__FILE__, incrementalmesh, g);
1585 theCommands.Add("MemLeakTest","MemLeakTest",__FILE__, MemLeakTest, g);
1586 theCommands.Add("fastdiscret","fastdiscret shape deflection [shared [nbiter]]",__FILE__, fastdiscret, g);
1587 theCommands.Add("mesh","mesh result Shape deflection [save partage]",__FILE__, triangule, g);
1588 theCommands.Add("addshape","addshape meshname Shape [deflection]",__FILE__, addshape, g);
1589 //theCommands.Add("smooth","smooth meshname",__FILE__, smooth, g);
1590 //theCommands.Add("edges","edges mesh shape, highlight the edges",__FILE__,edges, g);
1591 theCommands.Add("vertices","vertices mesh shape, highlight the vertices",__FILE__,vertices, g);
1592 theCommands.Add("medge","medge mesh [-]index (0 to clear all)",__FILE__,medge, g);
1593 theCommands.Add("mvertex","mvertex mesh [-]index (0 to clear all)",__FILE__,mvertex, g);
1594 theCommands.Add("triangle","triangle mesh [-]index (0 to clear all)",__FILE__,triangle, g);
1595 //theCommands.Add("dumpvertex","dumpvertex mesh [index]",__FILE__,dumpvertex, g);
1596 //theCommands.Add("dumpedge","dumpedge mesh [index]",__FILE__,dumpedge, g);
1597 //theCommands.Add("dumptriangle","dumptriangle mesh [index]",__FILE__,dumptriangle, g);
1598
1599 theCommands.Add("tri2d", "tri2d facename",__FILE__, tri2d, g);
1600 theCommands.Add("trinfo","trinfo name, print triangles information on objects",__FILE__,trianglesinfo,g);
1601 theCommands.Add("veriftriangles","veriftriangles name, verif triangles",__FILE__,veriftriangles,g);
1602 theCommands.Add("wavefront","wavefront name",__FILE__, wavefront, g);
1603 theCommands.Add("onetriangulation","onetriangulation name",__FILE__, onetriangulation, g);
d51c7072 1604 theCommands.Add("triepoints", "triepoints shape1 [shape2 ...]",__FILE__, triedgepoints, g);
7fd59977 1605
1606#if 0
1607 theCommands.Add("extrema","extrema ",__FILE__, extrema, g);
1608 theCommands.Add("vb","vb ",__FILE__, vb, g);
1609#endif
1610}