1 // Created on: 1997-07-24
2 // Created by: Xuan PHAM PHU
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <TestTopOpe.hxx>
23 #include <TopOpeBRepTool_2d.hxx>
24 #include <TopOpeBRepTool_C2DF.hxx>
25 #include <TopOpeBRepTool_CORRISO.hxx>
26 #include <TopOpeBRepTool_TOOL.hxx>
27 #include <TopOpeBRepTool_REGUS.hxx>
28 #include <TopOpeBRepTool_CLASSI.hxx>
29 #include <TopOpeBRepTool_TOOL.hxx>
30 #include <TopOpeBRepBuild_define.hxx>
32 #include <gp_Pnt2d.hxx>
33 #include <gp_Trsf2d.hxx>
34 #include <gp_Pnt2d.hxx>
35 #include <gp_Dir2d.hxx>
36 #include <gp_Vec2d.hxx>
37 #include <BRepAdaptor_Curve2d.hxx>
38 #include <BndLib_Add2dCurve.hxx>
39 #include <BRepLProp_SLProps.hxx>
40 #include <Geom_Curve.hxx>
41 #include <Geom2dAdaptor_Curve.hxx>
42 #include <Geom2d_Line.hxx>
43 #include <Geom2d_Curve.hxx>
44 #include <Geom2d_TrimmedCurve.hxx>
45 #include <Geom_Line.hxx>
46 #include <Geom_Surface.hxx>
47 #include <GeomAPI_IntCS.hxx>
49 #include <TopoDS_Solid.hxx>
50 #include <TopoDS_Wire.hxx>
51 #include <TopoDS_Compound.hxx>
53 #include <TopExp_Explorer.hxx>
54 #include <BRep_Tool.hxx>
55 #include <BRep_Builder.hxx>
56 #include <Precision.hxx>
57 #include <Bnd_Box2d.hxx>
58 #include <Bnd_Array1OfBox2d.hxx>
59 #include <BRepClass3d_SolidClassifier.hxx>
61 #include <TopOpeBRepTool.hxx>
62 #include <TopOpeBRepDS.hxx>
63 #include <TopOpeBRepBuild_FaceBuilder.hxx>
64 #include <TopOpeBRepBuild_ShellToSolid.hxx>
65 #include <TopOpeBRepTool_EXPORT.hxx>
66 #include <TopOpeBRepTool_SolidClassifier.hxx>
67 #include <TopOpeBRepTool_ShapeClassifier.hxx>
68 #include <TopOpeBRepDS_EXPORT.hxx>
71 #include <Draw_Interpretor.hxx>
72 #include <DrawTrSurf.hxx>
73 #include <Draw_Color.hxx>
76 #include <Extrema_ExtFlag.hxx>
77 #include <Extrema_ExtAlgo.hxx>
80 #include <TopOpeBRepTool_DRAW.hxx>
83 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
84 Standard_IMPORT void DBRep_WriteColorOrientation ();
85 Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
87 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
88 Standard_IMPORT void DBRep_WriteColorOrientation ();
89 Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
90 Standard_EXPORT void FUN_tool_mkBnd2d(const TopoDS_Shape& W, const TopoDS_Shape& F,Bnd_Box2d& B2d);
91 Standard_EXPORT void FUN_tool_UpdateBnd2d(Bnd_Box2d& B2d, const Bnd_Box2d& newB2d);
92 Standard_IMPORT Standard_Integer FUN_tool_classiBnd2d(const Bnd_Array1OfBox2d& B,const Standard_Boolean chklarge = Standard_True);
93 Standard_IMPORT Standard_Boolean FUN_tool_chkp2dFORinE(const gp_Pnt2d& p2d,const TopoDS_Edge& E,
94 const TopoDS_Face& F, Standard_Real& tol2d);
95 Standard_IMPORT TopoDS_Vertex FUN_tool_getv(const Standard_Integer Index,const TopoDS_Edge& E);
101 #define oneINtwo ( 1)
102 #define twoINone ( 2)
105 static void FUN_coutsta(const Standard_Integer& sta, const Standard_Integer& i1, const Standard_Integer& i2, Draw_Interpretor& di)
109 di<<i1<<" gives SAME bnd with "<<i2<<"\n"; break;
111 di<<i1<<" gives OUT bnd with "<<i2<<"\n"; break;
113 di<<i1<<" is IN "<<i2<<"\n"; break;
115 di<<i2<<" is IN "<<i1<<"\n"; break;
120 static void FUN_test_draw(TCollection_AsciiString aa,
121 const TopoDS_Edge& E, const TopoDS_Face& F,
122 const Standard_Integer ie,
123 Draw_Interpretor& di)
125 if (E.IsNull()) {di<<"************* null edge\n"; return;}
126 Standard_Real f,l; const Handle(Geom2d_Curve)& PC = BRep_Tool::CurveOnSurface(E,F,f,l);
127 if (PC.IsNull()) {di<<"************* no curv on surf\n"; return;}
128 TCollection_AsciiString bb(aa); bb += TCollection_AsciiString(ie);
129 char* aaa = (char *)bb.ToCString();
131 Standard_Boolean coldef = Standard_False;
132 TopExp_Explorer ex(F,TopAbs_EDGE);
137 DrawTrSurf_CurveColor(Draw_Color(Draw_rouge));
138 for (; ex.More(); ex.Next())
139 if (E.IsEqual(ex.Current()))
140 {col = DBRep_ColorOrientation(ex.Current().Orientation());
141 coldef = Standard_True;
143 if (!coldef) col = DBRep_ColorOrientation(E.Orientation());
145 DrawTrSurf_CurveColor(col);
146 DrawTrSurf::Set(aaa,new Geom2d_TrimmedCurve(PC,f,l));
149 void FUN_draw(const TCollection_AsciiString aa,const TopoDS_Shape& s)
150 {char* aaa = (char *)aa.ToCString(); DBRep::Set(aaa,s);}
152 void FUN_cout(const gp_Pnt2d& p2d, Draw_Interpretor& di)
153 {di <<" = ("<<p2d.X()<<" "<<p2d.Y()<<") ";}
156 Standard_IMPORT void FUN_tool_coutsta(const Standard_Integer& sta, const Standard_Integer& i1, const Standard_Integer& i2);
160 Standard_Integer regularize(Draw_Interpretor& di, Standard_Integer n, const char** a)
163 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
164 TopoDS_Face fa = TopoDS::Face(aLocalShape);
165 // TopoDS_Face fa = TopoDS::Face(DBRep::Get(a[1]));
166 if (fa.IsNull()) {di<<"null face"<<"\n"; return 1;}
168 TopTools_DataMapOfShapeListOfShape ESplits;
169 TopTools_ListOfShape lof;
170 TopOpeBRepTool::Regularize(fa, lof, ESplits);
171 Standard_Integer nfa = lof.Extent();
172 di<<"face gives "<<nfa<<" newfaces"<<"\n";
174 Standard_Integer i = 0;
175 TopTools_ListIteratorOfListOfShape itlof(lof) ;
176 for ( ; itlof.More(); itlof.Next()) {
178 TCollection_AsciiString aa = TCollection_AsciiString("fa_");
179 aa += TCollection_AsciiString(i);
180 FUN_draw(aa,itlof.Value());
183 TopoDS_Compound CC; BB.MakeCompound(CC);
184 for (itlof.Initialize(lof); itlof.More(); itlof.Next()) BB.Add(CC, itlof.Value());
185 di<<"resulting compound is cmp"<<"\n";
186 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
192 static Standard_Integer splitF(Draw_Interpretor& di, Standard_Integer n, const char** a)
195 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
196 const TopoDS_Face& fa = TopoDS::Face(aLocalShape);
197 // const TopoDS_Face& fa = TopoDS::Face(DBRep::Get(a[1]));
198 if (fa.IsNull()) {di<<"null face"<<"\n"; return 1;}
200 TopTools_ListOfShape fsplits;
201 // Standard_Boolean splitok = FUN_tool_SplitF(fa,fsplits);
202 Standard_Boolean splitok = TopOpeBRepTool_REGUS::SplitF(fa,fsplits);
204 if (!splitok) {di<<"no splits"<<"\n"; return 0;}
205 di<<"fa gives "<<fsplits.Extent()<<" splits"<<"\n";
208 TopoDS_Compound CC; BB.MakeCompound(CC);
209 for (TopTools_ListIteratorOfListOfShape it(fsplits); it.More(); it.Next()) BB.Add(CC, it.Value());
211 di<<"resulting compound is cmp"<<"\n";
212 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
218 static Standard_Integer regush(Draw_Interpretor& di, Standard_Integer n, const char** a)
221 const TopoDS_Shape& sha = DBRep::Get(a[1]);
222 if (sha.IsNull()) {di<<"null shape"<<"\n"; return 1;}
223 TopExp_Explorer ex(sha, TopAbs_SOLID);
224 const TopoDS_Solid& so = TopoDS::Solid(ex.Current());
225 if (so.IsNull()) {di<<"no solid"<<"\n"; return 1;}
227 TopTools_DataMapOfShapeListOfShape FSplits;
228 TopTools_DataMapOfShapeListOfShape OldSheNewShe;
231 TopoDS_Compound CC; BB.MakeCompound(CC);
232 Standard_Integer nshe = 0;
233 Standard_Boolean regu = TopOpeBRepTool::RegularizeShells(so,OldSheNewShe,FSplits);
234 if (!regu) {di<<"solid gives no new shell"<<"\n";}
236 Standard_Integer noldshe = OldSheNewShe.Extent();
237 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape ite(OldSheNewShe);
238 for (; ite.More(); ite.Next()){
239 const TopoDS_Shape& oldshe = ite.Key();
240 const TopTools_ListOfShape& newshells = ite.Value();
241 if (newshells.IsEmpty()) {BB.Add(CC,oldshe); nshe++;}
243 for (TopTools_ListIteratorOfListOfShape it(newshells); it.More(); it.Next()){
244 BB.Add(CC,it.Value()); nshe++;
248 di <<"noldshe = "<<noldshe<<" gives nshe = "<<nshe<<"\n";
249 di<<"resulting compound is cmp"<<"\n";
250 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
256 Standard_Integer reguso(Draw_Interpretor& di, Standard_Integer n, const char** a)
259 const TopoDS_Shape& sha = DBRep::Get(a[1]);
260 if (sha.IsNull()) {di<<"null shape"<<"\n"; return 1;}
261 TopExp_Explorer ex(sha, TopAbs_SOLID);
262 const TopoDS_Solid& so = TopoDS::Solid(ex.Current());
263 if (so.IsNull()) {di<<"no solid"<<"\n"; return 1;}
265 TopTools_DataMapOfShapeListOfShape FSplits;
266 TopTools_DataMapOfShapeListOfShape OldSheNewShe;
269 TopoDS_Compound CC; BB.MakeCompound(CC);
270 // Standard_Integer nshe = 0;
271 Standard_Boolean regu = TopOpeBRepTool::RegularizeShells(so,OldSheNewShe,FSplits);
272 if (!regu) {di<<"solid gives no new shell"<<"\n";}
274 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(OldSheNewShe);
276 TopOpeBRepBuild_ShellToSolid SheToSo;
277 for (; itm.More(); itm.Next()) {
278 const TopTools_ListOfShape& lns = itm.Value();
279 TopTools_ListIteratorOfListOfShape itsh(lns);
280 for (; itsh.More(); itsh.Next()) {
281 const TopoDS_Shell& she = TopoDS::Shell(itsh.Value());
282 SheToSo.AddShell(she);
285 TopTools_ListOfShape splits;
286 SheToSo.MakeSolids(so,splits);
289 TopoDS_Compound CC; BB.MakeCompound(CC);
290 Standard_Integer nSo = 0;
291 TopTools_ListIteratorOfListOfShape itSo(splits);
292 for (; itSo.More(); itSo.Next()) {
293 const TopoDS_Shape& spli = itSo.Value();
297 di<<"so gives "<<nSo<<" new solids"<<"\n";
298 di<<"resulting compound is cmp"<<"\n";
299 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
305 static Standard_Integer purge(Draw_Interpretor& di, Standard_Integer n, const char** a)
309 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
310 TopoDS_Face fa = TopoDS::Face(aLocalShape);
311 // TopoDS_Face fa = TopoDS::Face(DBRep::Get(a[1]));
312 if (fa.IsNull()) return 1;
313 TopOpeBRepTool_CORRISO CORRISO(fa);
314 Standard_Real tolF = BRep_Tool::Tolerance(fa);
315 Standard_Real uperiod; Standard_Boolean uclosed = CORRISO.Refclosed(1,uperiod);
316 Standard_Real vperiod; Standard_Boolean vclosed = CORRISO.Refclosed(2,vperiod);
317 if (!uclosed && !vclosed) return 1;
318 Standard_Boolean inU = uclosed ? Standard_True : Standard_False;
319 Standard_Real xmin = inU ? (CORRISO.GASref().FirstUParameter()) : (CORRISO.GASref().LastUParameter());
320 Standard_Real xper = inU ? uperiod : vperiod;
321 Standard_Real tolx = inU ? (CORRISO.Tol(1,tolF)) : (CORRISO.Tol(2,tolF));
324 TopTools_ListOfShape lWs; Standard_Boolean hasnew = Standard_False;
325 TopExp_Explorer exw(fa, TopAbs_WIRE);
326 for (; exw.More(); exw.Next()){
327 const TopoDS_Shape& W = exw.Current();
330 Standard_Boolean ok = CORRISO.UVClosed();
331 if (ok) {lWs.Append(W); continue;}
333 TopTools_ListOfShape cEds;
334 TopTools_ListIteratorOfListOfShape ite(CORRISO.Eds());
335 for (; ite.More(); ite.Next()){
336 const TopoDS_Edge& E = TopoDS::Edge(ite.Value());
337 Standard_Boolean closing = BRep_Tool::IsClosed(E,fa);
338 if (!closing) {// xpu231198 : pcurve modified, the information is lost
339 TopOpeBRepTool_C2DF C2DF; Standard_Boolean isb = CORRISO.UVRep(E,C2DF);
340 if (!isb) return 1;//NYIRAISE
341 Standard_Boolean onclo = TopOpeBRepTool_TOOL::IsonCLO(C2DF,inU,xmin,xper,tolx);
342 if (onclo) closing=Standard_True;
344 if (closing) cEds.Append(E);
346 Standard_Integer ncE = cEds.Extent();
347 Standard_Boolean nopurge = (ncE <= 1);
348 if (nopurge) {lWs.Append(W); continue;}
351 TopTools_ListOfShape lfyE; Standard_Boolean topurge = CORRISO.PurgeFyClosingE(cEds,lfyE);
352 if (!topurge) {lWs.Append(W); continue;}
354 TopoDS_Wire Wi; BB.MakeWire(Wi); // Add une TShape
355 Wi.Free(Standard_True);
356 ite.Initialize(CORRISO.Eds());
357 for (; ite.More(); ite.Next()) {
358 const TopoDS_Edge& ed = TopoDS::Edge(ite.Value());
359 Standard_Boolean equ = Standard_False;
360 for (TopTools_ListIteratorOfListOfShape itlfyE(lfyE);itlfyE.More();itlfyE.Next()) {
361 const TopoDS_Shape& fyE = itlfyE.Value();
362 if (ed.IsEqual(fyE)) {
375 if (!hasnew) return 1;
377 // Building up the new face :
378 aLocalShape = fa.EmptyCopied();
379 TopoDS_Face newF = TopoDS::Face(aLocalShape);
380 // TopoDS_Face newF = TopoDS::Face(fa.EmptyCopied());
381 TopTools_ListIteratorOfListOfShape itw(lWs);
382 for (; itw.More(); itw.Next()) BB.Add(newF, TopoDS::Wire(itw.Value()));
384 di <<"New face built is newF"<<"\n";
385 TCollection_AsciiString aa("newF");
391 Standard_Integer correctONISO(Draw_Interpretor& di, Standard_Integer n, const char** a)
394 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
395 TopoDS_Face F = TopoDS::Face(aLocalShape);
396 aLocalShape = DBRep::Get(a[2]);
397 TopoDS_Face Fsp = TopoDS::Face(aLocalShape);
398 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[1]));
399 // TopoDS_Face Fsp = TopoDS::Face(DBRep::Get(a[2]));
403 if (F.IsNull() || Fsp.IsNull()) {di<<"NULL shape(s)"<<"\n";return 1;}
405 TopOpeBRepTool::CorrectONUVISO(F,Fsp);
406 TCollection_AsciiString aa("newFsp");
408 di<<"-> newFsp"<<"\n";
413 // ======================================================================
415 // ======================================================================
417 static Standard_Integer isclosingE(Draw_Interpretor& di, Standard_Integer n, const char** a)
420 TopoDS_Shape aLocalShape = DBRep::Get(a[1]) ;
421 TopoDS_Edge ed = TopoDS::Edge(aLocalShape);
422 aLocalShape = DBRep::Get(a[2]);
423 TopoDS_Face fa = TopoDS::Face(aLocalShape);
424 // TopoDS_Edge ed = TopoDS::Edge(DBRep::Get(a[1]));
425 // TopoDS_Face fa = TopoDS::Face(DBRep::Get(a[2]));
426 Standard_Boolean isclosing = BRep_Tool::IsClosed(ed,fa);
427 TopAbs_Orientation oriE = ed.Orientation();
428 if (isclosing) {di <<"edge is ";
429 //TopAbs::Print(oriE,cout);
430 Standard_SStream aSStream;
431 TopAbs::Print(oriE,aSStream);
433 di<<" closing edge"<<"\n";}
434 else di <<"edge is NOT closing edge"<<"\n";
438 static Standard_Integer compareshsh(Draw_Interpretor& di, Standard_Integer n, const char** a)
441 TopoDS_Shape sh1 = DBRep::Get(a[1]);
442 TopoDS_Shape sh2 = DBRep::Get(a[2]);
443 Standard_Boolean issame = sh1.IsSame(sh2);
444 if (issame) di<<" same shapes"<<"\n";
445 else di <<" shapes are not same"<<"\n";
446 Standard_Boolean isequal = sh1.IsEqual(sh2); if (isequal) di<<" equal shapes"<<"\n";
449 static Standard_Integer pcurveedgeonface(Draw_Interpretor& di, Standard_Integer n, const char** a)
452 TopoDS_Shape ed = DBRep::Get(a[1]);
453 TopoDS_Shape fa = DBRep::Get(a[2]);
454 TCollection_AsciiString aa("edonfa_");
455 FUN_test_draw(aa,TopoDS::Edge(ed),TopoDS::Face(fa),0,di);
459 static Standard_Integer pcurvesonface(Draw_Interpretor& di, Standard_Integer n, const char** a)
462 TopoDS_Shape sh = DBRep::Get(a[2]);
463 TopoDS_Shape fa = DBRep::Get(a[3]);
464 TopExp_Explorer exe(sh, TopAbs_EDGE);
465 Standard_Integer i = 0;
466 for (; exe.More(); exe.Next()){
468 TCollection_AsciiString aa(a[1]);
469 FUN_test_draw(aa,TopoDS::Edge(exe.Current()),TopoDS::Face(fa),i,di);
474 static Standard_Integer orivine(Draw_Interpretor& di, Standard_Integer n, const char** a)
477 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
478 TopoDS_Vertex v = TopoDS::Vertex(aLocalShape);
479 aLocalShape = DBRep::Get(a[2]);
480 TopoDS_Edge ed = TopoDS::Edge(aLocalShape);
481 // TopoDS_Vertex v = TopoDS::Vertex(DBRep::Get(a[1]));
482 // TopoDS_Edge ed = TopoDS::Edge(DBRep::Get(a[2]));
484 Standard_Integer ori = TopOpeBRepTool_TOOL::OriinSor(v,ed);
485 if (ori==0) di<<"v not in ed"<<"\n";
486 else if (ori==1) di<<"v FORWARD in ed"<<"\n";
487 else if (ori==2) di<<"v REVERSED in ed"<<"\n";
488 else if (ori==3) di<<"v INTERNAL in ed"<<"\n";
489 else if (ori==4) di<<"v EXTERNAL in ed"<<"\n";
490 else if (ori==5) di<<"v CLOSING in ed"<<"\n";
494 static Standard_Integer vine(Draw_Interpretor& di, Standard_Integer n, const char** a)
497 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
498 TopoDS_Vertex v = TopoDS::Vertex(aLocalShape);
499 aLocalShape = DBRep::Get(a[2]);
500 TopoDS_Edge ed = TopoDS::Edge(aLocalShape);
501 aLocalShape = DBRep::Get(a[3]);
502 TopoDS_Face fa = TopoDS::Face(aLocalShape);
503 // TopoDS_Vertex v = TopoDS::Vertex(DBRep::Get(a[1]));
504 // TopoDS_Edge ed = TopoDS::Edge(DBRep::Get(a[2]));
505 // TopoDS_Face fa = TopoDS::Face(DBRep::Get(a[3]));
508 const Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(ed,fa,pf,pl);
509 gp_Pnt2d p2df, p2dl; PC->D0(pf,p2df); PC->D0(pl,p2dl);
510 di << "p2df";FUN_cout(p2df,di); di << "p2dl";FUN_cout(p2dl,di);di<<"\n";
512 Standard_Integer ori = TopOpeBRepTool_TOOL::OriinSor(v,ed);
513 if (ori==0) {di<<"v not in ed"<<"\n"; return 0;}
514 else if (ori==1) di<<"v FORWARD in ed"<<"\n";
515 else if (ori==2) di<<"v REVERSED in ed"<<"\n";
516 else if (ori==3) di<<"v INTERNAL in ed"<<"\n";
517 else if (ori==4) di<<"v EXTERNAL in ed"<<"\n";
518 else if (ori==5) di<<"v CLOSING in ed"<<"\n";
520 if ((ori == 1) || (ori == 2)) {
521 Standard_Real par = TopOpeBRepTool_TOOL::ParE(ori,ed);//FUN_tool_parOnE(ind,ed,fa);
522 gp_Pnt2d p2d; PC->D0(par,p2d);
523 di <<"p2d : with TopOpeBRepTool_TOOL::ParE";FUN_cout(p2d,di);di<<"\n";
526 Standard_Real par = BRep_Tool::Parameter(v,ed,fa);
527 gp_Pnt2d pp2d; PC->D0(par,pp2d);
528 di <<"p2d computed with BRep_Tool::Parameter";FUN_cout(pp2d,di);di<<"\n";
533 static Standard_Integer issubshape(Draw_Interpretor& di, Standard_Integer n, const char** a)
536 TopoDS_Shape subshape = DBRep::Get(a[1]);
537 TopoDS_Shape shape = DBRep::Get(a[2]);
538 TopExp_Explorer ex(shape, subshape.ShapeType());
539 Standard_Boolean issubs = Standard_False;
540 for (; ex.More(); ex.Next())
541 if (ex.Current().IsSame(subshape)) {issubs = Standard_True; break;}
543 if (issubs) di<<" is subshape"<<"\n";
544 else di<<" is NOT subshape"<<"\n";
548 void FUN_mkBnd2dBREP(const TopoDS_Shape& W, const TopoDS_Shape& F,Bnd_Box2d& B2d,const Standard_Integer& i)
550 // greater <B> with <W>'s UV representation on <F>
551 Standard_Real tol = 1.e-8;
553 for (ex.Init(W, TopAbs_EDGE); ex.More(); ex.Next()) {
554 // for (TopExp_Explorer ex(W, TopAbs_EDGE); ex.More(); ex.Next()) {
556 FUN_tool_mkBnd2d(W,F,B2d);
559 BRepAdaptor_Curve2d BC2d(TopoDS::Edge(ex.Current()), TopoDS::Face(F));
560 BndLib_Add2dCurve::Add(BC2d, tol, B2d);
564 Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(TopoDS::Edge(ex.Current()),TopoDS::Face(F),f,l);
565 Geom2dAdaptor_Curve GC2d(PC);
566 BndLib_Add2dCurve::Add(GC2d, tol, B2d);
569 TopLoc_Location L; Standard_Real f,l;
570 const Handle(Geom_Surface)& S = BRep_Tool::Surface(TopoDS::Face(F),L);
571 const Handle(Geom2d_Curve)& PC = BRep_Tool::CurveOnSurface(TopoDS::Edge(ex.Current()),S,L,f,l);
572 Geom2dAdaptor_Curve GC2d(PC);
573 BndLib_Add2dCurve::Add(GC2d, tol, B2d);
579 static Standard_Integer drawbnd2d(Draw_Interpretor& , Standard_Integer n, const char** a)
582 Standard_Integer i = Draw::Atoi(a[4]);
583 TopoDS_Shape W = DBRep::Get(a[2]);
584 TopoDS_Shape F = DBRep::Get(a[3]);
585 if (W.IsNull() || F.IsNull()) return 1;
587 Standard_Real umin,vmin,umax,vmax;
588 FUN_mkBnd2dBREP(W,F,B2d,i);
589 B2d.Get(umin,vmin,umax,vmax);
591 Handle(Geom2d_Line) cx = new Geom2d_Line(gp_Pnt2d(umin,vmin),gp_Dir2d(1.,0.));
592 Handle(Geom2d_Line) cy = new Geom2d_Line(gp_Pnt2d(umin,vmin),gp_Dir2d(0.,1.));
593 gp_Trsf2d tx; gp_Vec2d vx(umax-umin,0.); tx.SetTranslation(vx);
594 gp_Trsf2d ty; gp_Vec2d vy(0.,vmax-vmin); ty.SetTranslation(vy);
596 Handle(Geom2d_TrimmedCurve) tcx = new Geom2d_TrimmedCurve(cx,0.,umax-umin);
597 Handle(Geom2d_TrimmedCurve) tcy = new Geom2d_TrimmedCurve(cy,0.,vmax-vmin);
598 Handle(Geom2d_TrimmedCurve) tccx = Handle(Geom2d_TrimmedCurve)::DownCast(tcx->Copy()); tccx->Transform(ty);
599 Handle(Geom2d_TrimmedCurve) tccy = Handle(Geom2d_TrimmedCurve)::DownCast(tcy->Copy()); tccy->Transform(tx);
601 Draw_Color col(Draw_blanc);
602 DrawTrSurf_CurveColor(col);
604 TCollection_AsciiString aa3 = TCollection_AsciiString(a[1]); aa3 += TCollection_AsciiString(3);
605 TCollection_AsciiString aa4 = TCollection_AsciiString(a[1]); aa4 += TCollection_AsciiString(4);
607 TCollection_AsciiString aa;
608 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(1); char* aaa = (char *)aa.ToCString(); DrawTrSurf::Set(aaa,tcx);
609 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(2); aaa=(char *)aa.ToCString(); DrawTrSurf::Set(aaa,tcy);
610 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(3); aaa=(char *)aa.ToCString(); DrawTrSurf::Set(aaa,tccx);
611 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(4); aaa=(char *)aa.ToCString(); DrawTrSurf::Set(aaa,tccy);
615 static Standard_Integer classifBnd2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
618 TopoDS_Shape W1 = DBRep::Get(a[1]);
619 TopoDS_Shape W2 = DBRep::Get(a[2]);
620 TopoDS_Shape F = DBRep::Get(a[3]);
622 TopoDS_Wire w1 = TopoDS::Wire(W1);
623 TopoDS_Wire w2 = TopoDS::Wire(W2);
624 TopoDS_Face Fref = TopoDS::Face(F);
626 TopOpeBRepTool_CLASSI classi; classi.Init2d(Fref);
627 Standard_Real tolF = BRep_Tool::Tolerance(Fref);
628 Standard_Real toluv = TopOpeBRepTool_TOOL::TolUV(Fref,tolF);
630 if (w1.IsNull() || w2.IsNull() || Fref.IsNull()) return 1;
632 Standard_Integer sta = classi.ClassiBnd2d(w1,w2,toluv,Standard_True);
633 di <<"wires classification : checklarge=true ";
635 FUN_tool_coutsta(sta,1,2);
638 sta = classi.ClassiBnd2d(w1,w2,toluv,Standard_False);
639 di <<"wires classification : checklarge=false ";
641 FUN_tool_coutsta(sta,1,2);
647 static Standard_Integer pntonc(Draw_Interpretor& di, Standard_Integer n, const char** a)
650 Standard_Real x = Draw::Atof(a[1]);
651 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
652 if (C.IsNull()) {di<<"null curve"<<"\n"; return 1;}
653 gp_Pnt p = C->Value(x);
654 di<<"point on curve of parameter "<<x<<" =("<<p.X()<<",";
655 di<<p.Y()<<","<<p.Z()<<")"<<"\n";
659 static Standard_Integer pntonc2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
662 Standard_Real x = Draw::Atof(a[1]);
663 Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(a[2]);
664 if (C2d.IsNull()) {di<<"null curve"<<"\n"; return 1;}
665 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[3]);
666 if (S.IsNull()) {di<<"null surface"<<"\n"; return 1;}
667 gp_Pnt2d p2d = C2d->Value(x);
668 di<<"point on curve of parameter "<<x<<" =("<<p2d.X()<<","<<p2d.Y()<<")"<<"\n";
669 gp_Pnt p = S->Value(p2d.X(),p2d.Y());
670 di<<"point on curve of parameter "<<x<<" =("<<p.X()<<",";
671 di<<p.Y()<<","<<p.Z()<<")"<<"\n";
675 static Standard_Integer projponf(Draw_Interpretor& di, Standard_Integer n, const char** a)
678 di << "projponf f pnt [extrema flag: -min/-max/-minmax] [extrema algo: -g(grad)/-t(tree)]\n";
682 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
683 TopoDS_Face f = TopoDS::Face(aLocalShape);
686 di<<"null shape"<<"\n";
690 Standard_Real dist=0.;
694 Extrema_ExtAlgo aExtAlgo = Extrema_ExtAlgo_Grad;
695 Extrema_ExtFlag aExtFlag = Extrema_ExtFlag_MINMAX;
697 DrawTrSurf::GetPoint(a[2], p);
700 const char* key1 = a[3];
701 const char* key2 = (n > 4) ? a[4] : NULL;
703 if (!strcasecmp(key1,"-min")) {
704 aExtFlag = Extrema_ExtFlag_MIN;
705 } else if (!strcasecmp(key1,"-max")) {
706 aExtFlag = Extrema_ExtFlag_MAX;
708 aExtAlgo = (!strcasecmp(key1,"-t")) ? Extrema_ExtAlgo_Tree : aExtAlgo;
712 aExtAlgo = (!strcasecmp(key2,"-t")) ? Extrema_ExtAlgo_Tree : aExtAlgo;
715 ok = FUN_tool_projPonF(p, f, uv, dist, aExtFlag, aExtAlgo);
718 di<<"projection failed"<<"\n";
722 ok = FUN_tool_value(uv,f,pproj);
724 di<<"projection failed"<<"\n";
728 di<<"proj dist = "<<dist<<" uvproj = ("<<uv.X()<<" "<<uv.Y();
729 di<<"); pproj = ("<<pproj.X()<<" "<<pproj.Y()<<" "<<pproj.Z()<<")"<<"\n";
733 static Standard_Integer tolmax(Draw_Interpretor& di, Standard_Integer n, const char** a)
736 TopoDS_Shape s = DBRep::Get(a[1]);
737 if (s.IsNull()) {di<<"null shape"<<"\n"; return 1;}
738 Standard_Real tol = FUN_tool_maxtol(s);
739 di<<"max tol = "<<tol<<"\n";
743 static Standard_Integer solidclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
746 TopoDS_Shape s = DBRep::Get(a[1]);
747 if (s.IsNull()) {di<<"null shape"<<"\n";return 1;}
748 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
749 Standard_Real tol = Draw::Atof(a[3]);
751 TopOpeBRepTool_SolidClassifier soclassi;
752 TopAbs_State sta = TopAbs_UNKNOWN;
753 if (s.ShapeType() == TopAbs_SOLID) soclassi.Classify(TopoDS::Solid(s),p,tol);
754 else if (s.ShapeType() == TopAbs_SHELL) soclassi.Classify(TopoDS::Shell(s),p,tol);
755 else {di<<"shape is not a solid nor a shell => KO"<<"\n"; return 1;}
757 sta = soclassi.State();
759 //TopAbs::Print(sta,cout);
760 Standard_SStream aSStream;
761 TopAbs::Print(sta,aSStream);
763 di<<" shape s"<<"\n";
767 static Standard_Integer class3dclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
770 TopoDS_Shape s = DBRep::Get(a[1]);
771 if (s.IsNull()) {di<<"null shape"<<"\n";return 1;}
772 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
773 Standard_Real tol = Draw::Atof(a[3]);
775 BRepClass3d_SolidClassifier soclassi(s);
776 TopAbs_State sta = TopAbs_UNKNOWN;
777 soclassi.Perform(p,tol);
779 sta = soclassi.State();
781 //TopAbs::Print(sta,cout);
782 Standard_SStream aSStream;
783 TopAbs::Print(sta,aSStream);
785 di<<" shape s"<<"\n";
788 static Standard_Integer shapeclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
791 TopoDS_Shape sh = DBRep::Get(a[1]);
792 if (sh.IsNull()) {di<<"null shape"<<"\n";return 1;}
793 TopoDS_Shape shref = DBRep::Get(a[2]);
794 if (shref.IsNull()) {di<<"null reference shape"<<"\n";return 1;}
795 Standard_Boolean hastoavoid = (n > 3);
796 TopTools_ListOfShape toavoid;
798 for (Standard_Integer i=3; i<=n; i++) {
799 TopoDS_Shape shtoavoid = DBRep::Get(a[i]);
800 if (shtoavoid.IsNull()) {di<<"null toavoid shape"<<"\n";return 1;}
801 toavoid.Append(shtoavoid);
805 TopOpeBRepTool_ShapeClassifier shclassi;
806 TopAbs_State sta = TopAbs_UNKNOWN;
807 if (hastoavoid) sta = shclassi.StateShapeShape(sh,shref);
808 else if (toavoid.Extent() == 1) sta = shclassi.StateShapeShape(sh,toavoid.First(),shref);
809 else sta = shclassi.StateShapeShape(sh,toavoid,shref);
812 //TopAbs::Print(sta,cout);
813 Standard_SStream aSStream;
814 TopAbs::Print(sta,aSStream);
816 di<<" shape ref"<<"\n";
822 static Standard_Integer normal(Draw_Interpretor& di, Standard_Integer n, const char** a)
825 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
826 TopoDS_Face f = TopoDS::Face(aLocalShape);
827 // TopoDS_Face f = TopoDS::Face(DBRep::Get(a[1]));
828 if (f.IsNull()) {di<<"null shape"<<"\n";return 1;}
829 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
831 Standard_Real dist=0.; gp_Pnt2d uv; Standard_Boolean ok = FUN_tool_projPonF(p,f,uv,dist);
832 if (!ok) {di<<"projection failed"<<"\n"; return 1;}
836 FUN_tool_nggeomF(uv,f);
837 TCollection_AsciiString aa("ngS");
839 FUN_tool_draw(aa,p,ngf,length);
844 static Standard_Integer curvature(Draw_Interpretor& di, Standard_Integer n, const char** a)
847 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
848 TopoDS_Face f = TopoDS::Face(aLocalShape);
849 // TopoDS_Face f = TopoDS::Face(DBRep::Get(a[1]));
850 if (f.IsNull()) {di<<"null shape"<<"\n";return 1;}
851 Standard_Real x = Draw::Atof(a[2]);
852 Standard_Real y = Draw::Atof(a[3]);
853 Standard_Real z = Draw::Atof(a[4]);
854 Handle(Geom_Line) line = new Geom_Line(gp_Ax1(gp_Pnt(0.,0.,0.), gp_Dir(x,y,z)));
855 BRepAdaptor_Surface BS(f);
856 Handle(Geom_Surface) su = BRep_Tool::Surface(f);
857 GeomAPI_IntCS intcs(line,su);
858 Standard_Boolean done = intcs.IsDone();
859 if (!done) {di<<"intersection point on surface not found"<<"\n"; return 1;}
860 Standard_Integer npnts = intcs.NbPoints();
861 if (npnts < 1) {di<<"intersection point on surface not found"<<"\n"; return 1;}
863 Standard_Real tol = Precision::Confusion();
864 BRepLProp_SLProps props(BS,2,tol);
865 Standard_Real Cur1=0., Cur2=0.;
867 for (Standard_Integer i = 1; i <= npnts; i++) {
868 gp_Pnt p = intcs.Point(i);
869 Standard_Real u,v,w; intcs.Parameters(i,u,v,w);
870 di<<"point("<<i<<") = { ("<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"), ("<<u<<" "<<v<<") }"<<"\n";
871 props.SetParameters(u,v);
872 Standard_Boolean curdef = props.IsCurvatureDefined();
873 if (!curdef) {di<<"!IsCurvatureDefined"<<"\n"; continue;}
874 Standard_Boolean umbilic = props.IsUmbilic();
876 Cur1 = Cur2 = props.MeanCurvature();
882 Cur1 = props.MaxCurvature();
883 Cur2 = props.MinCurvature();
884 props.CurvatureDirections(D1,D2);
886 Norm = gp_Dir(D1^D2);
887 di<<"D1 = ("<<D1.X()<<" "<<D1.Y()<<" "<<D1.Z()<<" "<<")"<<"\n";
888 di<<"D2 = ("<<D2.X()<<" "<<D2.Y()<<" "<<D2.Z()<<" "<<")"<<"\n";
889 di<<"Norm = ("<<Norm.X()<<" "<<Norm.Y()<<" "<<Norm.Z()<<" "<<")"<<"\n";
894 void TestTopOpe::CORCommands(Draw_Interpretor& theCommands)
896 static Standard_Boolean done = Standard_False;
897 if (done) return; done = Standard_True;
898 const char* g = "TestTopOpe CORCommands";
899 // purge, regularization commands :
900 theCommands.Add("purge", "purge f", __FILE__, purge, g);
901 theCommands.Add("corrISO", "corrISO f Fsp", __FILE__, correctONISO, g);
902 theCommands.Add("regufa", "regufa f", __FILE__, regularize, g);
903 theCommands.Add("splitf", "splitf f", __FILE__, splitF, g);
904 theCommands.Add("regush", "regush so", __FILE__, regush, g);
905 theCommands.Add("reguso", "reguso so", __FILE__, reguso, g);
906 // builder commands :
907 theCommands.Add("soclass", "soclass sh pnt tol", __FILE__, solidclassifier, g);
908 theCommands.Add("shclass", "shclass sh shref <toavoid>", __FILE__, shapeclassifier, g);
909 theCommands.Add("clclass", "clclass sh shref <toavoid>", __FILE__, class3dclassifier, g);
912 theCommands.Add("cled", "cled ed f", __FILE__, isclosingE, g);
913 theCommands.Add("compare", "compare s1 s2", __FILE__, compareshsh, g);
914 theCommands.Add("edonfa", "edonfa ed f", __FILE__, pcurveedgeonface, g);
915 theCommands.Add("pconfa", "pconfa name s f", __FILE__, pcurvesonface, g);
916 theCommands.Add("orivine", "orivine v ed", __FILE__, orivine, g);
917 theCommands.Add("vine", "vine v ed fa", __FILE__, vine, g);
918 theCommands.Add("issubsh", "issubsh subsh sh", __FILE__, issubshape, g);
919 theCommands.Add("bnd2d", "bnd2d name W F i", __FILE__, drawbnd2d, g);
920 theCommands.Add("classibnd2d","classibnd2d W1 W2 F i", __FILE__, classifBnd2d, g);
921 theCommands.Add("pntonc", "pntonc par C3d", __FILE__, pntonc, g);
922 theCommands.Add("pntonc2d", "pntonc2d par C2d S", __FILE__, pntonc2d, g);
923 theCommands.Add("projponf",
924 "projponf f pnt [extrema flag: -min/-max/-minmax] [extrema algo: -g(grad)/-t(tree)]",
925 __FILE__, projponf, g);
926 theCommands.Add("tolmax", "tolmax s", __FILE__, tolmax, g);
927 theCommands.Add("normal", "normal f p3d length", __FILE__, normal, g);
928 theCommands.Add("curvature", "curvature f x y z", __FILE__, curvature , g);