0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / TestTopOpe / TestTopOpe_CORCommands.cxx
CommitLineData
7fd59977 1// File: TestTopOpe.cxx
2// Created: Thu Jul 24 10:58:20 1997
3// Author: Xuan PHAM PHU
4// <xpu@poulopox.paris1.matra-dtv.fr>
5
6#include <TestTopOpe.hxx>
7#include <TopOpeBRepTool_2d.hxx>
8#include <TopOpeBRepTool_C2DF.hxx>
9#include <TopOpeBRepTool_CORRISO.hxx>
10#include <TopOpeBRepTool_TOOL.hxx>
11#include <TopOpeBRepTool_REGUS.hxx>
12#include <TopOpeBRepTool_CLASSI.hxx>
13#include <TopOpeBRepTool_TOOL.hxx>
14#include <TopOpeBRepBuild_define.hxx>
15
16#include <gp_Pnt2d.hxx>
17#include <gp_Trsf2d.hxx>
18#include <gp_Pnt2d.hxx>
19#include <gp_Dir2d.hxx>
20#include <gp_Vec2d.hxx>
21#include <BRepAdaptor_Curve2d.hxx>
22#include <BndLib_Add2dCurve.hxx>
23#include <BRepLProp_SLProps.hxx>
24#include <Geom_Curve.hxx>
25#include <Geom2dAdaptor_Curve.hxx>
26#include <Geom2d_Line.hxx>
27#include <Geom2d_Curve.hxx>
28#include <Geom2d_TrimmedCurve.hxx>
29#include <Geom_Line.hxx>
30#include <Geom_Surface.hxx>
31#include <GeomAPI_IntCS.hxx>
32#include <TopoDS.hxx>
33#include <TopoDS_Solid.hxx>
34#include <TopoDS_Wire.hxx>
35#include <TopoDS_Compound.hxx>
36#include <TopExp.hxx>
37#include <TopExp_Explorer.hxx>
38#include <BRep_Tool.hxx>
39#include <BRep_Builder.hxx>
40#include <Precision.hxx>
41#include <Bnd_Box2d.hxx>
42#include <Bnd_Array1OfBox2d.hxx>
43#include <BRepClass3d_SolidClassifier.hxx>
44
45#include <TopOpeBRepTool.hxx>
46#include <TopOpeBRepDS.hxx>
47#include <TopOpeBRepBuild_FaceBuilder.hxx>
48#include <TopOpeBRepBuild_ShellToSolid.hxx>
49#include <TopOpeBRepTool_EXPORT.hxx>
50#include <TopOpeBRepTool_SolidClassifier.hxx>
51#include <TopOpeBRepTool_ShapeClassifier.hxx>
52#include <TopOpeBRepDS_EXPORT.hxx>
53
54#include <Draw_Interpretor.hxx>
55#include <DrawTrSurf.hxx>
56#include <Draw_Color.hxx>
57#include <DBRep.hxx>
58
59#ifdef DRAW
60#include <TopOpeBRepTool_DRAW.hxx>
61#endif
62
63Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
64Standard_IMPORT void DBRep_WriteColorOrientation ();
65Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
66
67Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
68Standard_IMPORT void DBRep_WriteColorOrientation ();
69Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
70Standard_EXPORT void FUN_tool_mkBnd2d(const TopoDS_Shape& W, const TopoDS_Shape& F,Bnd_Box2d& B2d);
71Standard_EXPORT void FUN_tool_UpdateBnd2d(Bnd_Box2d& B2d, const Bnd_Box2d& newB2d);
72Standard_IMPORT Standard_Integer FUN_tool_classiBnd2d(const Bnd_Array1OfBox2d& B,const Standard_Boolean chklarge = Standard_True);
73Standard_IMPORT Standard_Boolean FUN_tool_chkp2dFORinE(const gp_Pnt2d& p2d,const TopoDS_Edge& E,
74 const TopoDS_Face& F, Standard_Real& tol2d);
75Standard_IMPORT TopoDS_Vertex FUN_tool_getv(const Standard_Integer Index,const TopoDS_Edge& E);
76
77
78#define SAME (-1)
79#define DIFF (-2)
80#define UNKNOWN ( 0)
81#define oneINtwo ( 1)
82#define twoINone ( 2)
83
84#ifdef DEB
85static void FUN_coutsta(const Standard_Integer& sta, const Standard_Integer& i1, const Standard_Integer& i2, Draw_Interpretor& di)
86{
87 switch (sta) {
88 case SAME:
89 di<<i1<<" gives SAME bnd with "<<i2<<"\n"; break;
90 case DIFF:
91 di<<i1<<" gives OUT bnd with "<<i2<<"\n"; break;
92 case oneINtwo:
93 di<<i1<<" is IN "<<i2<<"\n"; break;
94 case twoINone:
95 di<<i2<<" is IN "<<i1<<"\n"; break;
96 }
97}
98#endif
99
100static void FUN_test_draw(TCollection_AsciiString aa,
101 const TopoDS_Edge& E, const TopoDS_Face& F,
102 const Standard_Integer ie,
103 Draw_Interpretor& di)
104{
105 if (E.IsNull()) {di<<"************* null edge\n"; return;}
106 Standard_Real f,l; const Handle(Geom2d_Curve)& PC = BRep_Tool::CurveOnSurface(E,F,f,l);
107 if (PC.IsNull()) {di<<"************* no curv on surf\n"; return;}
108 TCollection_AsciiString bb(aa); bb += TCollection_AsciiString(ie);
109 char* aaa = (char *)bb.ToCString();
110
111 Standard_Boolean coldef = Standard_False;
112 TopExp_Explorer ex(F,TopAbs_EDGE);
113 Draw_Color col;
114#ifdef DEB
115 Draw_Color savecol =
116#endif
117 DrawTrSurf_CurveColor(Draw_Color(Draw_rouge));
118 for (; ex.More(); ex.Next())
119 if (E.IsEqual(ex.Current()))
120 {col = DBRep_ColorOrientation(ex.Current().Orientation());
121 coldef = Standard_True;
122 break;}
123 if (!coldef) col = DBRep_ColorOrientation(E.Orientation());
124
125 DrawTrSurf_CurveColor(col);
126 DrawTrSurf::Set(aaa,new Geom2d_TrimmedCurve(PC,f,l));
127}
128
129void FUN_draw(const TCollection_AsciiString aa,const TopoDS_Shape& s)
130{char* aaa = (char *)aa.ToCString(); DBRep::Set(aaa,s);}
131
132void FUN_cout(const gp_Pnt2d& p2d, Draw_Interpretor& di)
133{di <<" = ("<<p2d.X()<<" "<<p2d.Y()<<") ";}
134
135#ifdef DEB
136Standard_IMPORT void FUN_tool_coutsta(const Standard_Integer& sta, const Standard_Integer& i1, const Standard_Integer& i2);
137#endif
138
139
140Standard_Integer regularize(Draw_Interpretor& di, Standard_Integer n, const char** a)
141{
142 if (n < 2) return 1;
143 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
144 TopoDS_Face fa = TopoDS::Face(aLocalShape);
145// TopoDS_Face fa = TopoDS::Face(DBRep::Get(a[1]));
146 if (fa.IsNull()) {di<<"null face"<<"\n"; return 1;}
147
148 TopTools_DataMapOfShapeListOfShape ESplits;
149 TopTools_ListOfShape lof;
150 TopOpeBRepTool::Regularize(fa, lof, ESplits);
151 Standard_Integer nfa = lof.Extent();
152 di<<"face gives "<<nfa<<" newfaces"<<"\n";
153
154 Standard_Integer i = 0;
155 TopTools_ListIteratorOfListOfShape itlof(lof) ;
156 for ( ; itlof.More(); itlof.Next()) {
157 i++;
158 TCollection_AsciiString aa = TCollection_AsciiString("fa_");
159 aa += TCollection_AsciiString(i);
160 FUN_draw(aa,itlof.Value());
161 }
162 BRep_Builder BB;
163 TopoDS_Compound CC; BB.MakeCompound(CC);
164 for (itlof.Initialize(lof); itlof.More(); itlof.Next()) BB.Add(CC, itlof.Value());
165 di<<"resulting compound is cmp"<<"\n";
166 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
167 FUN_draw(aa,CC);
168
169 return 0;
170}
171
172static Standard_Integer splitF(Draw_Interpretor& di, Standard_Integer n, const char** a)
173{
174 if (n < 2) return 1;
175 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
176 const TopoDS_Face& fa = TopoDS::Face(aLocalShape);
177// const TopoDS_Face& fa = TopoDS::Face(DBRep::Get(a[1]));
178 if (fa.IsNull()) {di<<"null face"<<"\n"; return 1;}
179
180 TopTools_ListOfShape fsplits;
181// Standard_Boolean splitok = FUN_tool_SplitF(fa,fsplits);
182 Standard_Boolean splitok = TopOpeBRepTool_REGUS::SplitF(fa,fsplits);
183
184 if (!splitok) {di<<"no splits"<<"\n"; return 0;}
185 di<<"fa gives "<<fsplits.Extent()<<" splits"<<"\n";
186
187 BRep_Builder BB;
188 TopoDS_Compound CC; BB.MakeCompound(CC);
189 for (TopTools_ListIteratorOfListOfShape it(fsplits); it.More(); it.Next()) BB.Add(CC, it.Value());
190
191 di<<"resulting compound is cmp"<<"\n";
192 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
193 FUN_draw(aa,CC);
194 return 0;
195}
196
197
198static Standard_Integer regush(Draw_Interpretor& di, Standard_Integer n, const char** a)
199{
200 if (n < 2) return 1;
201 const TopoDS_Shape& sha = DBRep::Get(a[1]);
202 if (sha.IsNull()) {di<<"null shape"<<"\n"; return 1;}
203 TopExp_Explorer ex(sha, TopAbs_SOLID);
204 const TopoDS_Solid& so = TopoDS::Solid(ex.Current());
205 if (so.IsNull()) {di<<"no solid"<<"\n"; return 1;}
206
207 TopTools_DataMapOfShapeListOfShape FSplits;
208 TopTools_DataMapOfShapeListOfShape OldSheNewShe;
209
210 BRep_Builder BB;
211 TopoDS_Compound CC; BB.MakeCompound(CC);
212 Standard_Integer nshe = 0;
213 Standard_Boolean regu = TopOpeBRepTool::RegularizeShells(so,OldSheNewShe,FSplits);
214 if (!regu) {di<<"solid gives no new shell"<<"\n";}
215 else {
216 Standard_Integer noldshe = OldSheNewShe.Extent();
217 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape ite(OldSheNewShe);
218 for (; ite.More(); ite.Next()){
219 const TopoDS_Shape& oldshe = ite.Key();
220 const TopTools_ListOfShape& newshells = ite.Value();
221 if (newshells.IsEmpty()) {BB.Add(CC,oldshe); nshe++;}
222 else {
223 for (TopTools_ListIteratorOfListOfShape it(newshells); it.More(); it.Next()){
224 BB.Add(CC,it.Value()); nshe++;
225 }
226 }
227 } // i = 1..noldshe
228 di <<"noldshe = "<<noldshe<<" gives nshe = "<<nshe<<"\n";
229 di<<"resulting compound is cmp"<<"\n";
230 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
231 FUN_draw(aa,CC);
232 }
233 return 0;
234}
235
236Standard_Integer reguso(Draw_Interpretor& di, Standard_Integer n, const char** a)
237{
238 if (n < 2) return 1;
239 const TopoDS_Shape& sha = DBRep::Get(a[1]);
240 if (sha.IsNull()) {di<<"null shape"<<"\n"; return 1;}
241 TopExp_Explorer ex(sha, TopAbs_SOLID);
242 const TopoDS_Solid& so = TopoDS::Solid(ex.Current());
243 if (so.IsNull()) {di<<"no solid"<<"\n"; return 1;}
244
245 TopTools_DataMapOfShapeListOfShape FSplits;
246 TopTools_DataMapOfShapeListOfShape OldSheNewShe;
247
248 BRep_Builder BB;
249 TopoDS_Compound CC; BB.MakeCompound(CC);
250// Standard_Integer nshe = 0;
251 Standard_Boolean regu = TopOpeBRepTool::RegularizeShells(so,OldSheNewShe,FSplits);
252 if (!regu) {di<<"solid gives no new shell"<<"\n";}
253 else {
254 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(OldSheNewShe);
255
256 TopOpeBRepBuild_ShellToSolid SheToSo;
257 for (; itm.More(); itm.Next()) {
258 const TopTools_ListOfShape& lns = itm.Value();
7fd59977 259 TopTools_ListIteratorOfListOfShape itsh(lns);
260 for (; itsh.More(); itsh.Next()) {
261 const TopoDS_Shell& she = TopoDS::Shell(itsh.Value());
262 SheToSo.AddShell(she);
263 }
264 }
265 TopTools_ListOfShape splits;
266 SheToSo.MakeSolids(so,splits);
267
268 BRep_Builder BB;
269 TopoDS_Compound CC; BB.MakeCompound(CC);
270 Standard_Integer nSo = 0;
271 TopTools_ListIteratorOfListOfShape itSo(splits);
272 for (; itSo.More(); itSo.Next()) {
273 const TopoDS_Shape& spli = itSo.Value();
274 BB.Add(CC,spli);
275 nSo++;
276 }
277 di<<"so gives "<<nSo<<" new solids"<<"\n";
278 di<<"resulting compound is cmp"<<"\n";
279 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
280 FUN_draw(aa,CC);
281 }
282 return 0;
283}
284
285static Standard_Integer purge(Draw_Interpretor& di, Standard_Integer n, const char** a)
286{
287
288 if (n < 2) return 1;
289 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
290 TopoDS_Face fa = TopoDS::Face(aLocalShape);
291// TopoDS_Face fa = TopoDS::Face(DBRep::Get(a[1]));
292 if (fa.IsNull()) return 1;
293 TopOpeBRepTool_CORRISO CORRISO(fa);
294 Standard_Real tolF = BRep_Tool::Tolerance(fa);
295 Standard_Real uperiod; Standard_Boolean uclosed = CORRISO.Refclosed(1,uperiod);
296 Standard_Real vperiod; Standard_Boolean vclosed = CORRISO.Refclosed(2,vperiod);
297 if (!uclosed && !vclosed) return 1;
298 Standard_Boolean inU = uclosed ? Standard_True : Standard_False;
299 Standard_Real xmin = inU ? (CORRISO.GASref().FirstUParameter()) : (CORRISO.GASref().LastUParameter());
300 Standard_Real xper = inU ? uperiod : vperiod;
301 Standard_Real tolx = inU ? (CORRISO.Tol(1,tolF)) : (CORRISO.Tol(2,tolF));
302
303 BRep_Builder BB;
304 TopTools_ListOfShape lWs; Standard_Boolean hasnew = Standard_False;
305 TopExp_Explorer exw(fa, TopAbs_WIRE);
306 for (; exw.More(); exw.Next()){
307 const TopoDS_Shape& W = exw.Current();
308
309 CORRISO.Init(W);
310 Standard_Boolean ok = CORRISO.UVClosed();
311 if (ok) {lWs.Append(W); continue;}
312
313 TopTools_ListOfShape cEds;
314 TopTools_ListIteratorOfListOfShape ite(CORRISO.Eds());
315 for (; ite.More(); ite.Next()){
316 const TopoDS_Edge& E = TopoDS::Edge(ite.Value());
317 Standard_Boolean closing = BRep_Tool::IsClosed(E,fa);
318 if (!closing) {// xpu231198 : pcurve modified, the information is lost
319 TopOpeBRepTool_C2DF C2DF; Standard_Boolean isb = CORRISO.UVRep(E,C2DF);
320 if (!isb) return 1;//NYIRAISE
321 Standard_Boolean onclo = TopOpeBRepTool_TOOL::IsonCLO(C2DF,inU,xmin,xper,tolx);
322 if (onclo) closing=Standard_True;
323 }
324 if (closing) cEds.Append(E);
325 }
326 Standard_Integer ncE = cEds.Extent();
327 Standard_Boolean nopurge = (ncE <= 1);
328 if (nopurge) {lWs.Append(W); continue;}
329
330 // Checking <W>
331 TopTools_ListOfShape lfyE; Standard_Boolean topurge = CORRISO.PurgeFyClosingE(cEds,lfyE);
332 if (!topurge) {lWs.Append(W); continue;}
333
334 TopoDS_Wire Wi; BB.MakeWire(Wi); // Add une TShape
335 Wi.Free(Standard_True);
336 ite.Initialize(CORRISO.Eds());
337 for (; ite.More(); ite.Next()) {
338 const TopoDS_Edge& ed = TopoDS::Edge(ite.Value());
339 Standard_Boolean equ = Standard_False;
340 for (TopTools_ListIteratorOfListOfShape itlfyE(lfyE);itlfyE.More();itlfyE.Next()) {
341 const TopoDS_Shape& fyE = itlfyE.Value();
342 if (ed.IsEqual(fyE)) {
343 equ = Standard_True;
344 break;
345 }
346 }
347 if (equ) {
348 continue;
349 }
350 BB.Add(Wi,ed);
351 }
352 lWs.Append(Wi);
353 } // exw
354
355 if (!hasnew) return 1;
356
357 // Building up the new face :
358 aLocalShape = fa.EmptyCopied();
359 TopoDS_Face newF = TopoDS::Face(aLocalShape);
360// TopoDS_Face newF = TopoDS::Face(fa.EmptyCopied());
361 TopTools_ListIteratorOfListOfShape itw(lWs);
362 for (; itw.More(); itw.Next()) BB.Add(newF, TopoDS::Wire(itw.Value()));
363
364 di <<"New face built is newF"<<"\n";
365 TCollection_AsciiString aa("newF");
366 FUN_draw(aa, newF);
367 return 0;
368}
369
370
371Standard_Integer correctONISO(Draw_Interpretor& di, Standard_Integer n, const char** a)
372{
373 if (n < 3) return 1;
374 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
375 TopoDS_Face F = TopoDS::Face(aLocalShape);
376 aLocalShape = DBRep::Get(a[2]);
377 TopoDS_Face Fsp = TopoDS::Face(aLocalShape);
378// TopoDS_Face F = TopoDS::Face(DBRep::Get(a[1]));
379// TopoDS_Face Fsp = TopoDS::Face(DBRep::Get(a[2]));
380
381 FC2D_Prepare(F,F);
382
383 if (F.IsNull() || Fsp.IsNull()) {di<<"NULL shape(s)"<<"\n";return 1;}
384
385 TopOpeBRepTool::CorrectONUVISO(F,Fsp);
386 TCollection_AsciiString aa("newFsp");
387 FUN_draw(aa,Fsp);
388 di<<"-> newFsp"<<"\n";
389
390 return 0;
391}
392
393// ======================================================================
394// useful commands :
395// ======================================================================
396
397static Standard_Integer isclosingE(Draw_Interpretor& di, Standard_Integer n, const char** a)
398{
399 if (n < 3) return 1;
400 TopoDS_Shape aLocalShape = DBRep::Get(a[1]) ;
401 TopoDS_Edge ed = TopoDS::Edge(aLocalShape);
402 aLocalShape = DBRep::Get(a[2]);
403 TopoDS_Face fa = TopoDS::Face(aLocalShape);
404// TopoDS_Edge ed = TopoDS::Edge(DBRep::Get(a[1]));
405// TopoDS_Face fa = TopoDS::Face(DBRep::Get(a[2]));
406 Standard_Boolean isclosing = BRep_Tool::IsClosed(ed,fa);
407 TopAbs_Orientation oriE = ed.Orientation();
408 if (isclosing) {di <<"edge is ";
409 //TopAbs::Print(oriE,cout);
410 Standard_SStream aSStream;
411 TopAbs::Print(oriE,aSStream);
412 di << aSStream;
413 di<<" closing edge"<<"\n";}
414 else di <<"edge is NOT closing edge"<<"\n";
415 return 0;
416}
417
418static Standard_Integer compareshsh(Draw_Interpretor& di, Standard_Integer n, const char** a)
419{
420 if (n < 3) return 1;
421 TopoDS_Shape sh1 = DBRep::Get(a[1]);
422 TopoDS_Shape sh2 = DBRep::Get(a[2]);
423 Standard_Boolean issame = sh1.IsSame(sh2);
424 if (issame) di<<" same shapes"<<"\n";
425 else di <<" shapes are not same"<<"\n";
426 Standard_Boolean isequal = sh1.IsEqual(sh2); if (isequal) di<<" equal shapes"<<"\n";
427 return 0;
428}
429static Standard_Integer pcurveedgeonface(Draw_Interpretor& di, Standard_Integer n, const char** a)
430{
431 if (n < 3) return 1;
432 TopoDS_Shape ed = DBRep::Get(a[1]);
433 TopoDS_Shape fa = DBRep::Get(a[2]);
434 TCollection_AsciiString aa("edonfa_");
435 FUN_test_draw(aa,TopoDS::Edge(ed),TopoDS::Face(fa),0,di);
436 return 0;
437}
438
439static Standard_Integer pcurvesonface(Draw_Interpretor& di, Standard_Integer n, const char** a)
440{
441 if (n < 3) return 1;
442 TopoDS_Shape sh = DBRep::Get(a[2]);
443 TopoDS_Shape fa = DBRep::Get(a[3]);
444 TopExp_Explorer exe(sh, TopAbs_EDGE);
445 Standard_Integer i = 0;
446 for (; exe.More(); exe.Next()){
447 i++;
448 TCollection_AsciiString aa(a[1]);
449 FUN_test_draw(aa,TopoDS::Edge(exe.Current()),TopoDS::Face(fa),i,di);
450 }
451 return 0;
452}
453
454static Standard_Integer orivine(Draw_Interpretor& di, Standard_Integer n, const char** a)
455{
456 if (n < 3) return 1;
457 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
458 TopoDS_Vertex v = TopoDS::Vertex(aLocalShape);
459 aLocalShape = DBRep::Get(a[2]);
460 TopoDS_Edge ed = TopoDS::Edge(aLocalShape);
461// TopoDS_Vertex v = TopoDS::Vertex(DBRep::Get(a[1]));
462// TopoDS_Edge ed = TopoDS::Edge(DBRep::Get(a[2]));
463
464 Standard_Integer ori = TopOpeBRepTool_TOOL::OriinSor(v,ed);
465 if (ori==0) di<<"v not in ed"<<"\n";
466 else if (ori==1) di<<"v FORWARD in ed"<<"\n";
467 else if (ori==2) di<<"v REVERSED in ed"<<"\n";
468 else if (ori==3) di<<"v INTERNAL in ed"<<"\n";
469 else if (ori==4) di<<"v EXTERNAL in ed"<<"\n";
470 else if (ori==5) di<<"v CLOSING in ed"<<"\n";
471 return 0;
472}
473
474static Standard_Integer vine(Draw_Interpretor& di, Standard_Integer n, const char** a)
475{
476 if (n < 4) return 1;
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 aLocalShape = DBRep::Get(a[3]);
482 TopoDS_Face fa = TopoDS::Face(aLocalShape);
483// TopoDS_Vertex v = TopoDS::Vertex(DBRep::Get(a[1]));
484// TopoDS_Edge ed = TopoDS::Edge(DBRep::Get(a[2]));
485// TopoDS_Face fa = TopoDS::Face(DBRep::Get(a[3]));
486
487 Standard_Real pf,pl;
488 const Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(ed,fa,pf,pl);
489 gp_Pnt2d p2df, p2dl; PC->D0(pf,p2df); PC->D0(pl,p2dl);
490 di << "p2df";FUN_cout(p2df,di); di << "p2dl";FUN_cout(p2dl,di);di<<"\n";
491
492 Standard_Integer ori = TopOpeBRepTool_TOOL::OriinSor(v,ed);
493 if (ori==0) {di<<"v not in ed"<<"\n"; return 0;}
494 else if (ori==1) di<<"v FORWARD in ed"<<"\n";
495 else if (ori==2) di<<"v REVERSED in ed"<<"\n";
496 else if (ori==3) di<<"v INTERNAL in ed"<<"\n";
497 else if (ori==4) di<<"v EXTERNAL in ed"<<"\n";
498 else if (ori==5) di<<"v CLOSING in ed"<<"\n";
499
500 if ((ori == 1) || (ori == 2)) {
501 Standard_Real par = TopOpeBRepTool_TOOL::ParE(ori,ed);//FUN_tool_parOnE(ind,ed,fa);
502 gp_Pnt2d p2d; PC->D0(par,p2d);
503 di <<"p2d : with TopOpeBRepTool_TOOL::ParE";FUN_cout(p2d,di);di<<"\n";
504 }
505
506 Standard_Real par = BRep_Tool::Parameter(v,ed,fa);
507 gp_Pnt2d pp2d; PC->D0(par,pp2d);
508 di <<"p2d computed with BRep_Tool::Parameter";FUN_cout(pp2d,di);di<<"\n";
509
510 return 0;
511}
512
513static Standard_Integer issubshape(Draw_Interpretor& di, Standard_Integer n, const char** a)
514{
515 if (n < 3) return 1;
516 TopoDS_Shape subshape = DBRep::Get(a[1]);
517 TopoDS_Shape shape = DBRep::Get(a[2]);
518 TopExp_Explorer ex(shape, subshape.ShapeType());
519 Standard_Boolean issubs = Standard_False;
520 for (; ex.More(); ex.Next())
521 if (ex.Current().IsSame(subshape)) {issubs = Standard_True; break;}
522
523 if (issubs) di<<" is subshape"<<"\n";
524 else di<<" is NOT subshape"<<"\n";
525 return 0;
526}
527
528void FUN_mkBnd2dBREP(const TopoDS_Shape& W, const TopoDS_Shape& F,Bnd_Box2d& B2d,const Standard_Integer& i)
529{
530 // greater <B> with <W>'s UV representation on <F>
531 Standard_Real tol = 1.e-8;
532 TopExp_Explorer ex;
533 for (ex.Init(W, TopAbs_EDGE); ex.More(); ex.Next()) {
534// for (TopExp_Explorer ex(W, TopAbs_EDGE); ex.More(); ex.Next()) {
535 if (i == 0) {
536 FUN_tool_mkBnd2d(W,F,B2d);
537 }
538 if (i == 1) {
539 BRepAdaptor_Curve2d BC2d(TopoDS::Edge(ex.Current()), TopoDS::Face(F));
540 BndLib_Add2dCurve::Add(BC2d, tol, B2d);
541 }
542 if (i == 2) {
543 Standard_Real f,l;
544 Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(TopoDS::Edge(ex.Current()),TopoDS::Face(F),f,l);
545 Geom2dAdaptor_Curve GC2d(PC);
546 BndLib_Add2dCurve::Add(GC2d, tol, B2d);
547 }
548 if (i == 3) {
549 TopLoc_Location L; Standard_Real f,l;
550 const Handle(Geom_Surface)& S = BRep_Tool::Surface(TopoDS::Face(F),L);
551 const Handle(Geom2d_Curve)& PC = BRep_Tool::CurveOnSurface(TopoDS::Edge(ex.Current()),S,L,f,l);
552 Geom2dAdaptor_Curve GC2d(PC);
553 BndLib_Add2dCurve::Add(GC2d, tol, B2d);
554 }
555
556 } //ex(W,EDGE)
557}
558
559static Standard_Integer drawbnd2d(Draw_Interpretor& , Standard_Integer n, const char** a)
560{
561 if (n < 5) return 1;
562 Standard_Integer i = atoi(a[4]);
563 TopoDS_Shape W = DBRep::Get(a[2]);
564 TopoDS_Shape F = DBRep::Get(a[3]);
565 if (W.IsNull() || F.IsNull()) return 1;
566 Bnd_Box2d B2d;
567 Standard_Real umin,vmin,umax,vmax;
568 FUN_mkBnd2dBREP(W,F,B2d,i);
569 B2d.Get(umin,vmin,umax,vmax);
570
571 Handle(Geom2d_Line) cx = new Geom2d_Line(gp_Pnt2d(umin,vmin),gp_Dir2d(1.,0.));
572 Handle(Geom2d_Line) cy = new Geom2d_Line(gp_Pnt2d(umin,vmin),gp_Dir2d(0.,1.));
573 gp_Trsf2d tx; gp_Vec2d vx(umax-umin,0.); tx.SetTranslation(vx);
574 gp_Trsf2d ty; gp_Vec2d vy(0.,vmax-vmin); ty.SetTranslation(vy);
575
576 Handle(Geom2d_TrimmedCurve) tcx = new Geom2d_TrimmedCurve(cx,0.,umax-umin);
577 Handle(Geom2d_TrimmedCurve) tcy = new Geom2d_TrimmedCurve(cy,0.,vmax-vmin);
578 Handle(Geom2d_TrimmedCurve) tccx = Handle(Geom2d_TrimmedCurve)::DownCast(tcx->Copy()); tccx->Transform(ty);
579 Handle(Geom2d_TrimmedCurve) tccy = Handle(Geom2d_TrimmedCurve)::DownCast(tcy->Copy()); tccy->Transform(tx);
580
581 Draw_Color col(Draw_blanc);
582 DrawTrSurf_CurveColor(col);
583
584 TCollection_AsciiString aa3 = TCollection_AsciiString(a[1]); aa3 += TCollection_AsciiString(3);
585 TCollection_AsciiString aa4 = TCollection_AsciiString(a[1]); aa4 += TCollection_AsciiString(4);
586
587 TCollection_AsciiString aa;
588 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(1); char* aaa = (char *)aa.ToCString(); DrawTrSurf::Set(aaa,tcx);
589 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(2); aaa=(char *)aa.ToCString(); DrawTrSurf::Set(aaa,tcy);
590 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(3); aaa=(char *)aa.ToCString(); DrawTrSurf::Set(aaa,tccx);
591 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(4); aaa=(char *)aa.ToCString(); DrawTrSurf::Set(aaa,tccy);
592 return 0;
593}
594
595static Standard_Integer classifBnd2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
596{
597 if (n < 5) return 1;
598 TopoDS_Shape W1 = DBRep::Get(a[1]);
599 TopoDS_Shape W2 = DBRep::Get(a[2]);
600 TopoDS_Shape F = DBRep::Get(a[3]);
7fd59977 601
602 TopoDS_Wire w1 = TopoDS::Wire(W1);
603 TopoDS_Wire w2 = TopoDS::Wire(W2);
604 TopoDS_Face Fref = TopoDS::Face(F);
605
606 TopOpeBRepTool_CLASSI classi; classi.Init2d(Fref);
607 Standard_Real tolF = BRep_Tool::Tolerance(Fref);
608 Standard_Real toluv = TopOpeBRepTool_TOOL::TolUV(Fref,tolF);
609
610 if (w1.IsNull() || w2.IsNull() || Fref.IsNull()) return 1;
611
612 Standard_Integer sta = classi.ClassiBnd2d(w1,w2,toluv,Standard_True);
613 di <<"wires classification : checklarge=true ";
614#ifdef DEB
615 FUN_tool_coutsta(sta,1,2);
616#endif
617
618 sta = classi.ClassiBnd2d(w1,w2,toluv,Standard_False);
619 di <<"wires classification : checklarge=false ";
620#ifdef DEB
621 FUN_tool_coutsta(sta,1,2);
622#endif
623
624 return 0;
625}
626
627static Standard_Integer pntonc(Draw_Interpretor& di, Standard_Integer n, const char** a)
628{
629 if (n < 3) return 1;
630 Standard_Real x = atof(a[1]);
631 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
632 if (C.IsNull()) {di<<"null curve"<<"\n"; return 1;}
633 gp_Pnt p = C->Value(x);
634 di<<"point on curve of parameter "<<x<<" =("<<p.X()<<",";
635 di<<p.Y()<<","<<p.Z()<<")"<<"\n";
636 return 0;
637}
638
639static Standard_Integer pntonc2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
640{
641 if (n < 4) return 1;
642 Standard_Real x = atof(a[1]);
643 Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(a[2]);
644 if (C2d.IsNull()) {di<<"null curve"<<"\n"; return 1;}
645 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[3]);
646 if (S.IsNull()) {di<<"null surface"<<"\n"; return 1;}
647 gp_Pnt2d p2d = C2d->Value(x);
648 di<<"point on curve of parameter "<<x<<" =("<<p2d.X()<<","<<p2d.Y()<<")"<<"\n";
649 gp_Pnt p = S->Value(p2d.X(),p2d.Y());
650 di<<"point on curve of parameter "<<x<<" =("<<p.X()<<",";
651 di<<p.Y()<<","<<p.Z()<<")"<<"\n";
652 return 0;
653}
654
655static Standard_Integer projponf(Draw_Interpretor& di, Standard_Integer n, const char** a)
656{
657 if (n < 3) return 1;
658 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
659 TopoDS_Face f = TopoDS::Face(aLocalShape);
660// TopoDS_Face f = TopoDS::Face(DBRep::Get(a[1]));
661 if (f.IsNull()) {di<<"null shape"<<"\n";return 1;}
662 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
663 Standard_Real dist=0.; gp_Pnt2d uv; Standard_Boolean ok = FUN_tool_projPonF(p,f,uv,dist);
664 if (!ok) {di<<"projection failed"<<"\n"; return 1;}
665 gp_Pnt pproj; ok = FUN_tool_value(uv,f,pproj);
666 if (!ok) {di<<"projection failed"<<"\n"; return 1;}
667 di<<"proj dist = "<<dist<<" uvproj = ("<<uv.X()<<" "<<uv.Y();
668 di<<"); pproj = ("<<pproj.X()<<" "<<pproj.Y()<<" "<<pproj.Z()<<")"<<"\n";
669 return 0;
670}
671
672static Standard_Integer tolmax(Draw_Interpretor& di, Standard_Integer n, const char** a)
673{
674 if (n < 2) return 1;
675 TopoDS_Shape s = DBRep::Get(a[1]);
676 if (s.IsNull()) {di<<"null shape"<<"\n"; return 1;}
677 Standard_Real tol = FUN_tool_maxtol(s);
678 di<<"max tol = "<<tol<<"\n";
679 return 0;
680}
681
682static Standard_Integer solidclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
683{
684 if (n < 4) return 1;
685 TopoDS_Shape s = DBRep::Get(a[1]);
686 if (s.IsNull()) {di<<"null shape"<<"\n";return 1;}
687 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
688 Standard_Real tol = atof(a[3]);
689
690 TopOpeBRepTool_SolidClassifier soclassi;
691 TopAbs_State sta = TopAbs_UNKNOWN;
692 if (s.ShapeType() == TopAbs_SOLID) soclassi.Classify(TopoDS::Solid(s),p,tol);
693 else if (s.ShapeType() == TopAbs_SHELL) soclassi.Classify(TopoDS::Shell(s),p,tol);
694 else {di<<"shape is not a solid nor a shell => KO"<<"\n"; return 1;}
695
696 sta = soclassi.State();
697 di<<"point is ";
698 //TopAbs::Print(sta,cout);
699 Standard_SStream aSStream;
700 TopAbs::Print(sta,aSStream);
701 di << aSStream;
702 di<<" shape s"<<"\n";
703 return 0;
704}
705
706static Standard_Integer class3dclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
707{
708 if (n < 4) return 1;
709 TopoDS_Shape s = DBRep::Get(a[1]);
710 if (s.IsNull()) {di<<"null shape"<<"\n";return 1;}
711 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
712 Standard_Real tol = atof(a[3]);
713
714 BRepClass3d_SolidClassifier soclassi(s);
715 TopAbs_State sta = TopAbs_UNKNOWN;
716 soclassi.Perform(p,tol);
717
718 sta = soclassi.State();
719 di<<"point is ";
720 //TopAbs::Print(sta,cout);
721 Standard_SStream aSStream;
722 TopAbs::Print(sta,aSStream);
723 di << aSStream;
724 di<<" shape s"<<"\n";
725 return 0;
726}
727static Standard_Integer shapeclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
728{
729 if (n < 3) return 1;
730 TopoDS_Shape sh = DBRep::Get(a[1]);
731 if (sh.IsNull()) {di<<"null shape"<<"\n";return 1;}
732 TopoDS_Shape shref = DBRep::Get(a[2]);
733 if (shref.IsNull()) {di<<"null reference shape"<<"\n";return 1;}
734 Standard_Boolean hastoavoid = (n > 3);
735 TopTools_ListOfShape toavoid;
736 if (hastoavoid) {
737 for (Standard_Integer i=3; i<=n; i++) {
738 TopoDS_Shape shtoavoid = DBRep::Get(a[i]);
739 if (shtoavoid.IsNull()) {di<<"null toavoid shape"<<"\n";return 1;}
740 toavoid.Append(shtoavoid);
741 }
742 }
743
744 TopOpeBRepTool_ShapeClassifier shclassi;
745 TopAbs_State sta = TopAbs_UNKNOWN;
746 if (hastoavoid) sta = shclassi.StateShapeShape(sh,shref);
747 else if (toavoid.Extent() == 1) sta = shclassi.StateShapeShape(sh,toavoid.First(),shref);
748 else sta = shclassi.StateShapeShape(sh,toavoid,shref);
749
750 di<<"shape is ";
751 //TopAbs::Print(sta,cout);
752 Standard_SStream aSStream;
753 TopAbs::Print(sta,aSStream);
754 di << aSStream;
755 di<<" shape ref"<<"\n";
756 return 0;
757}
758
759
760// normals ..
761static Standard_Integer normal(Draw_Interpretor& di, Standard_Integer n, const char** a)
762{
763 if (n < 3) return 1;
764 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
765 TopoDS_Face f = TopoDS::Face(aLocalShape);
766// TopoDS_Face f = TopoDS::Face(DBRep::Get(a[1]));
767 if (f.IsNull()) {di<<"null shape"<<"\n";return 1;}
768 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
769#ifdef DEB
770 Standard_Real length = atof(a[3]);
771#endif
772 Standard_Real dist=0.; gp_Pnt2d uv; Standard_Boolean ok = FUN_tool_projPonF(p,f,uv,dist);
773 if (!ok) {di<<"projection failed"<<"\n"; return 1;}
774#ifdef DEB
775 gp_Vec ngf =
776#endif
777 FUN_tool_nggeomF(uv,f);
778 TCollection_AsciiString aa("ngS");
779#ifdef DRAW
780 FUN_tool_draw(aa,p,ngf,length);
781#endif
782 return 0;
783}
784
785static Standard_Integer curvature(Draw_Interpretor& di, Standard_Integer n, const char** a)
786{
787 if (n < 5) return 1;
788 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
789 TopoDS_Face f = TopoDS::Face(aLocalShape);
790// TopoDS_Face f = TopoDS::Face(DBRep::Get(a[1]));
791 if (f.IsNull()) {di<<"null shape"<<"\n";return 1;}
792 Standard_Real x = atof(a[2]);
793 Standard_Real y = atof(a[3]);
794 Standard_Real z = atof(a[4]);
795 Handle(Geom_Line) line = new Geom_Line(gp_Ax1(gp_Pnt(0.,0.,0.), gp_Dir(x,y,z)));
796 BRepAdaptor_Surface BS(f);
797 Handle(Geom_Surface) su = BRep_Tool::Surface(f);
798 GeomAPI_IntCS intcs(line,su);
799 Standard_Boolean done = intcs.IsDone();
800 if (!done) {di<<"intersection point on surface not found"<<"\n"; return 1;}
801 Standard_Integer npnts = intcs.NbPoints();
802 if (npnts < 1) {di<<"intersection point on surface not found"<<"\n"; return 1;}
803
804 Standard_Real tol = Precision::Confusion();
805 BRepLProp_SLProps props(BS,2,tol);
806 Standard_Real Cur1=0., Cur2=0.;
807 gp_Dir Norm,D1,D2;
808 for (Standard_Integer i = 1; i <= npnts; i++) {
809 gp_Pnt p = intcs.Point(i);
810 Standard_Real u,v,w; intcs.Parameters(i,u,v,w);
811 di<<"point("<<i<<") = { ("<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"), ("<<u<<" "<<v<<") }"<<"\n";
812 props.SetParameters(u,v);
813 Standard_Boolean curdef = props.IsCurvatureDefined();
814 if (!curdef) {di<<"!IsCurvatureDefined"<<"\n"; continue;}
815 Standard_Boolean umbilic = props.IsUmbilic();
816 if (umbilic) {
817 Cur1 = Cur2 = props.MeanCurvature();
818 D1 = gp_Dir(0,0,1);
819 D2 = gp_Dir(0,1,0);
820 di<<"umbilic";
821 }
822 else {
823 Cur1 = props.MaxCurvature();
824 Cur2 = props.MinCurvature();
825 props.CurvatureDirections(D1,D2);
826 }
827 Norm = gp_Dir(D1^D2);
828 di<<"D1 = ("<<D1.X()<<" "<<D1.Y()<<" "<<D1.Z()<<" "<<")"<<"\n";
829 di<<"D2 = ("<<D2.X()<<" "<<D2.Y()<<" "<<D2.Z()<<" "<<")"<<"\n";
830 di<<"Norm = ("<<Norm.X()<<" "<<Norm.Y()<<" "<<Norm.Z()<<" "<<")"<<"\n";
831 } // i
832 return 0;
833}
834
835void TestTopOpe::CORCommands(Draw_Interpretor& theCommands)
836{
837 static Standard_Boolean done = Standard_False;
838 if (done) return; done = Standard_True;
839 const char* g = "TestTopOpe CORCommands";
840 // purge, regularization commands :
841 theCommands.Add("purge", "purge f", __FILE__, purge, g);
842 theCommands.Add("corrISO", "corrISO f Fsp", __FILE__, correctONISO, g);
843 theCommands.Add("regufa", "regufa f", __FILE__, regularize, g);
844 theCommands.Add("splitf", "splitf f", __FILE__, splitF, g);
845 theCommands.Add("regush", "regush so", __FILE__, regush, g);
846 theCommands.Add("reguso", "reguso so", __FILE__, reguso, g);
847 // builder commands :
848 theCommands.Add("soclass", "soclass sh pnt tol", __FILE__, solidclassifier, g);
849 theCommands.Add("shclass", "shclass sh shref <toavoid>", __FILE__, shapeclassifier, g);
850 theCommands.Add("clclass", "clclass sh shref <toavoid>", __FILE__, class3dclassifier, g);
851
852 // useful commands :
853 theCommands.Add("cled", "cled ed f", __FILE__, isclosingE, g);
854 theCommands.Add("compare", "compare s1 s2", __FILE__, compareshsh, g);
855 theCommands.Add("edonfa", "edonfa ed f", __FILE__, pcurveedgeonface, g);
856 theCommands.Add("pconfa", "pconfa name s f", __FILE__, pcurvesonface, g);
857 theCommands.Add("orivine", "orivine v ed", __FILE__, orivine, g);
858 theCommands.Add("vine", "vine v ed fa", __FILE__, vine, g);
859 theCommands.Add("issubsh", "issubsh subsh sh", __FILE__, issubshape, g);
860 theCommands.Add("bnd2d", "bnd2d name W F i", __FILE__, drawbnd2d, g);
861 theCommands.Add("classibnd2d","classibnd2d W1 W2 F i", __FILE__, classifBnd2d, g);
862 theCommands.Add("pntonc", "pntonc par C3d", __FILE__, pntonc, g);
863 theCommands.Add("pntonc2d", "pntonc2d par C2d S", __FILE__, pntonc2d, g);
864 theCommands.Add("projponf", "projponf f pnt", __FILE__, projponf, g);
865 theCommands.Add("tolmax", "tolmax s", __FILE__, tolmax, g);
866 theCommands.Add("normal", "normal f p3d length", __FILE__, normal, g);
867 theCommands.Add("curvature", "curvature f x y z", __FILE__, curvature , g);
868
869}