1 // Created on: 1994-10-12
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <TopOpeBRep_EdgesFiller.ixx>
18 #include <TopOpeBRep_PointGeomTool.hxx>
19 #include <TopOpeBRep_Point2d.hxx>
21 #include <TopOpeBRepDS_Transition.hxx>
22 #include <TopOpeBRepDS_Config.hxx>
23 #include <TopOpeBRepDS_Point.hxx>
24 #include <TopOpeBRepDS_EXPORT.hxx>
25 #include <TopOpeBRepDS_TKI.hxx>
26 #include <TopOpeBRepDS_InterferenceTool.hxx>
27 #include <TopOpeBRepTool_EXPORT.hxx>
28 #include <TopOpeBRepDS.hxx>
29 #include <BRep_Tool.hxx>
32 #include <TopOpeBRep_define.hxx>
35 #include <TopOpeBRepDS_reDEB.hxx>
36 extern Standard_Boolean TopOpeBRepDS_GettraceEDSF();
37 extern Standard_Boolean TopOpeBRepDS_GettraceDSF();
38 extern Standard_Boolean TopOpeBRep_GettraceEEFF();
39 Standard_EXPORT void debefre(const Standard_Integer IE) {cout<<"+++ debefre E"<<IE<<endl;}
40 Standard_EXPORT void debposesd(void) {/*cout<<"+++ debposesd"<<endl;*/}
41 Standard_EXPORT void debposnesd(void) {cout<<"+++ debposnesd"<<endl;}
42 Standard_EXPORT void debeeff() {}
45 #define M_REVERSED(O) (O == TopAbs_REVERSED)
46 #define M_FORWARD( O) (O == TopAbs_FORWARD)
47 #define M_INTERNAL(O) (O == TopAbs_INTERNAL)
48 #define M_EXTERNAL(O) (O == TopAbs_EXTERNAL)
50 //=======================================================================
51 //function : TopOpeBRep_EdgesFiller
53 //=======================================================================
54 TopOpeBRep_EdgesFiller::TopOpeBRep_EdgesFiller() : myPDS(NULL),myPEI(NULL) {}
58 //=======================================================================
61 //=======================================================================
62 void TopOpeBRep_EdgesFiller::Insert(const TopoDS_Shape& E1,const TopoDS_Shape& E2,TopOpeBRep_EdgesIntersector& EDGINT,const Handle(TopOpeBRepDS_HDataStructure)& HDS)
65 myPDS = &(HDS->ChangeDS());
66 myE1 = TopoDS::Edge(E1);
67 myE2 = TopoDS::Edge(E2);
73 Standard_Boolean trc = TopOpeBRepDS_GettraceDSF();
74 trc = trc || TopOpeBRepDS_GettraceEDSF();
75 trc = trc || TopOpeBRep_GettraceEEFF();
77 if (TopOpeBRep_GettraceEEFF()) debeeff();
78 TCollection_AsciiString str="EdgesFiller dim";str=str+myPEI->Dimension();
79 myPEI->Dump(str,myPDS->Shape(myE1),myPDS->Shape(myE2));
82 Standard_Boolean esd = myPEI->SameDomain();
83 if (esd) myPDS->FillShapesSameDomain(E1,E2);
86 myPEI->InitPoint(); if ( !myPEI->MorePoint() ) return;
88 // --- Add <E1,E2> in BDS
89 Standard_Integer E1index = myPDS->AddShape(E1,1);
90 Standard_Integer E2index = myPDS->AddShape(E2,2);
92 // --- get list of interferences connected to edges <E1>,<E2>
93 TopOpeBRepDS_ListOfInterference& EIL1 = myPDS->ChangeShapeInterferences(E1);
95 Handle(TopOpeBRepDS_Interference) EPI; //edge/point interference
96 Handle(TopOpeBRepDS_Interference) EVI; //edge/vertex interference
98 // TopOpeBRepDS_Transition TposF,TposL;
100 for (; myPEI->MorePoint(); myPEI->NextPoint() ) {
101 const TopOpeBRep_Point2d P2D = myPEI->Point();
102 Standard_Real par1 = P2D.Parameter(1);
103 Standard_Real par2 = P2D.Parameter(2);
104 if ( ! myF1.IsNull() ) myPDS->AddShape(myF1,1);
105 if ( ! myF2.IsNull() ) myPDS->AddShape(myF2,2);
108 Standard_Boolean pointofsegment = P2D.IsPointOfSegment();
113 if (pointofsegment && esd) debposesd();
114 else if (pointofsegment && !esd) debposnesd();
118 TopOpeBRepDS_Transition T1 = P2D.Transition(1);
119 TopOpeBRepDS_Transition T2 = P2D.Transition(2);
121 SetShapeTransition(P2D,T1,T2);
123 Standard_Boolean isvertex1 = P2D.IsVertex(1);
124 TopoDS_Vertex V1; if (isvertex1) V1 = P2D.Vertex(1);
125 Standard_Boolean isvertex2 = P2D.IsVertex(2);
126 TopoDS_Vertex V2; if (isvertex2) V2 = P2D.Vertex(2);
127 Standard_Boolean isvertex = isvertex1 || isvertex2;
130 if (isvertex1 && isvertex2) {
131 gp_Pnt P3D1 = BRep_Tool::Pnt(V1);
132 gp_Pnt P3D2 = BRep_Tool::Pnt(V2);
133 Standard_Real tol1 = BRep_Tool::Tolerance(V1);
134 Standard_Real tol2 = BRep_Tool::Tolerance(V2);
135 Standard_Real dpp = P3D1.Distance(P3D2);
136 if (dpp> tol1+tol2) {
138 cout<<"*** TopOpeBRep_EdgesFiller : isvertex1 && isvertex2 : P3D non confondus"<<endl;
139 cout<<"point PV1 "<<P3D1.X()<<" "<<P3D1.Y()<<" "<<P3D1.Z()<<endl;
140 cout<<"point PV2 "<<P3D2.X()<<" "<<P3D2.Y()<<" "<<P3D2.Z()<<endl;
146 // xpu : 080498 : CTS20072 (e12,e3,p8)
147 // edgesintersector called for tolerances = 0.
148 // facesintersector called for greater tolerances
149 // we assume facesintersector's ouput data to be valid
150 // and we use it for correcting edgesintersector's ouput data
151 TopOpeBRepDS_ListIteratorOfListOfInterference itloI1( myPDS->ShapeInterferences(E1) );
152 Standard_Integer G; TopOpeBRepDS_Kind K;
153 Standard_Boolean found = GetGeometry(itloI1,P2D,G,K);
154 if (!found) MakeGeometry(P2D,G,K);
156 Standard_Boolean foundpoint = (found) && (K == TopOpeBRepDS_POINT);
157 Standard_Boolean isnewpoint = (!found) && (K == TopOpeBRepDS_POINT);
158 Standard_Boolean isnewvertex = (!found) && (K == TopOpeBRepDS_VERTEX);
160 Standard_Boolean faulty = (isvertex && isnewpoint) || (!isvertex && isnewvertex);
162 #ifdef TOPOPEBREP_DEB
163 Standard_Boolean foundvertex = (found) && (K == TopOpeBRepDS_VERTEX);
164 cout<<"- - - faulty EdgesFiller : G "<<G<<" K ";TopOpeBRepDS::Print(K,cout);cout.flush();
165 cout<<" isvertex="<<isvertex;cout.flush();
166 cout<<" isop="<<foundpoint<<" isov="<<foundvertex;cout.flush();
167 cout<<" isnp="<<isnewpoint<<" isnv="<<isnewvertex<<endl;cout.flush();
171 if (isvertex && foundpoint) {
172 Standard_Integer is = 1, ns = myPDS->NbShapes();
174 const TopoDS_Shape& s = myPDS->Shape(is);
175 if (s.ShapeType() != TopAbs_EDGE) continue;
176 const TopoDS_Edge& e = TopoDS::Edge(s);
178 TopOpeBRepDS_ListOfInterference linew;
179 TopOpeBRepDS_ListOfInterference& li = myPDS->ChangeShapeInterferences(e); TopOpeBRepDS_ListIteratorOfListOfInterference it(li);
182 Handle(TopOpeBRepDS_Interference) I=it.Value(); TopOpeBRepDS_Kind ki=I->GeometryType(); Standard_Integer gi=I->Geometry();
183 Handle(Standard_Type) DTI = I->DynamicType();
184 Standard_Boolean iscpi = (DTI == STANDARD_TYPE(TopOpeBRepDS_CurvePointInterference)) ;
185 Standard_Boolean condcpi = ((ki==TopOpeBRepDS_POINT) && (gi==G) && iscpi);
186 if (condcpi) { // remplacer G,K de I par le vertex courant
191 Handle(TopOpeBRepDS_CurvePointInterference) epi = Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(I);
192 const TopOpeBRepDS_Transition& tevi = epi->Transition();
193 Standard_Integer sevi = epi->Support();
195 Standard_Integer gevi=0;
197 if (isvertex1) gevi = myPDS->AddShape(V1,1);
198 else if (isvertex2) gevi = myPDS->AddShape(V2,2);
199 Standard_Boolean bevi = Standard_False;
200 TopOpeBRepDS_Config cevi = TopOpeBRepDS_UNSHGEOMETRY;
201 Standard_Real pevi = epi->Parameter();
203 Handle(TopOpeBRepDS_Interference) evi;
204 evi = TopOpeBRepDS_InterferenceTool::MakeEdgeVertexInterference(tevi,sevi,gevi,bevi,cevi,pevi);
205 const TopOpeBRepDS_Kind& kevi = epi->SupportType();
206 evi->SupportType(kevi);
209 TopOpeBRepDS::Print(K,G,cout,"TopOpeBRep_EdgesFiller : remplacer "," ");
210 TopOpeBRepDS::Print(TopOpeBRepDS_VERTEX,gevi,cout,"par "," dans les courbes NYI\n");
219 if (!linew.IsEmpty()) {
220 myHDS->StoreInterferences(linew,is,"EdgesFiller modif : ");
223 } // (isvertex && foundpoint)
226 const TopoDS_Vertex& VV1 = V1;
227 // const TopoDS_Vertex& VV1 = TopoDS::Vertex(V1);
228 const TopoDS_Edge& EE1 = TopoDS::Edge(E1);
229 par1 = BRep_Tool::Parameter(VV1,EE1);
233 const TopoDS_Vertex& VV2 = V2;
234 // const TopoDS_Vertex& VV2 = TopoDS::Vertex(V2);
235 const TopoDS_Edge& EE2 = TopoDS::Edge(E2);
236 par2 = BRep_Tool::Parameter(VV2,EE2);
239 if ( isvertex1 && isvertex2 ) {
240 myPDS->FillShapesSameDomain(V1,V2);
243 Standard_Integer DSPindex;
244 Standard_Boolean EPIfound;
248 TopOpeBRepDS_Kind KKK;
249 TopOpeBRepDS_ListIteratorOfListOfInterference itEIL1(EIL1);
250 EPIfound = GetGeometry(itEIL1,P2D,DSPindex,KKK);
251 if ( ! EPIfound ) MakeGeometry(P2D,DSPindex,KKK);
253 SetShapeTransition(P2D,T1,T2);
255 if (KKK == TopOpeBRepDS_POINT) {
256 EPI = StorePI(P2D,T1,E2index,DSPindex,par1,1);
257 EPI = StorePI(P2D,T2,E1index,DSPindex,par2,2);
259 else if ( KKK == TopOpeBRepDS_VERTEX) {
260 Standard_Integer Vindex = DSPindex;
261 Standard_Boolean bevi = Standard_False;
262 TopOpeBRepDS_Config cevi = TopOpeBRepDS_UNSHGEOMETRY;
263 EVI = StoreVI(P2D,T1,E2index,Vindex,bevi,cevi,par1,1);
264 EVI = StoreVI(P2D,T2,E1index,Vindex,bevi,cevi,par2,2);
271 SetShapeTransition(P2D,T1,T2);
274 const TopoDS_Shape V = V1;
275 Standard_Integer Vindex = myPDS->AddShape(V,1);
276 TopOpeBRepDS_Config SSC = P2D.EdgesConfig();
277 EVI = StoreVI(P2D,T1,E2index,Vindex,Standard_True,SSC,par1,1);
278 EVI = StoreVI(P2D,T2,E1index,Vindex,Standard_False,SSC,par2,2);
282 const TopoDS_Shape V = V2;
283 Standard_Integer Vindex = myPDS->AddShape(V,2);
284 TopOpeBRepDS_Config SSC = P2D.EdgesConfig();
285 EVI = StoreVI(P2D,T1,E2index,Vindex,Standard_False,SSC,par1,1);
286 EVI = StoreVI(P2D,T2,E1index,Vindex,Standard_True,SSC,par2,2);
293 RecomputeInterferences(myE1,myLI1);
294 RecomputeInterferences(myE2,myLI2);
302 //=======================================================================
303 //function : SetShapeTransition
305 //=======================================================================
306 void TopOpeBRep_EdgesFiller::SetShapeTransition(const TopOpeBRep_Point2d& P2D,
307 TopOpeBRepDS_Transition& T1,TopOpeBRepDS_Transition& T2) const
309 Standard_Boolean pointofsegment = P2D.IsPointOfSegment();
310 Standard_Boolean esd = myPEI->SameDomain();
311 Standard_Integer ie1=0,ie2=0,if1=0,if2=0;
313 if (pointofsegment && esd) {
314 T1.ShapeBefore(TopAbs_EDGE);T1.ShapeAfter(TopAbs_EDGE);
315 T2.ShapeBefore(TopAbs_EDGE);T2.ShapeAfter(TopAbs_EDGE);
316 if ( ! myE1.IsNull() ) ie1 = myPDS->AddShape(myE1,1);
317 if ( ! myE2.IsNull() ) ie2 = myPDS->AddShape(myE2,2);
318 if ( ! myE2.IsNull() ) T1.Index(ie2);
319 if ( ! myE1.IsNull() ) T2.Index(ie1);
322 T1.ShapeBefore(TopAbs_FACE);T1.ShapeAfter(TopAbs_FACE);
323 T2.ShapeBefore(TopAbs_FACE);T2.ShapeAfter(TopAbs_FACE);
324 if ( ! myF1.IsNull() ) if1 = myPDS->AddShape(myF1,1);
325 if ( ! myF2.IsNull() ) if2 = myPDS->AddShape(myF2,2);
326 if ( ! myF1.IsNull() ) T2.Index(if1);
327 if ( ! myF2.IsNull() ) T1.Index(if2);
331 //=======================================================================
332 //function : GetGeometry
334 //=======================================================================
335 Standard_Boolean TopOpeBRep_EdgesFiller::GetGeometry(TopOpeBRepDS_ListIteratorOfListOfInterference& IT,const TopOpeBRep_Point2d& P2D,Standard_Integer& G,TopOpeBRepDS_Kind& K) const
338 TopOpeBRepDS_Point DSP = TopOpeBRep_PointGeomTool::MakePoint(P2D);
339 Standard_Boolean b = myHDS->GetGeometry(IT,DSP,G,K);
343 //=======================================================================
344 //function : MakeGeometry
346 //=======================================================================
347 Standard_Boolean TopOpeBRep_EdgesFiller::MakeGeometry(const TopOpeBRep_Point2d& P2D,Standard_Integer& G,TopOpeBRepDS_Kind& K) const
349 Standard_Boolean isvertex1 = P2D.IsVertex(1);
350 Standard_Boolean isvertex2 = P2D.IsVertex(2);
351 if (isvertex1 && isvertex2) {
352 Standard_Integer G1 = myPDS->AddShape(P2D.Vertex(1),1);
353 myPDS->AddShape(P2D.Vertex(2),2);
355 K = TopOpeBRepDS_VERTEX;
357 else if (isvertex1) {
358 G = myPDS->AddShape(P2D.Vertex(1),1);
359 K = TopOpeBRepDS_VERTEX;
361 else if (isvertex2) {
362 G = myPDS->AddShape(P2D.Vertex(2),2);
363 K = TopOpeBRepDS_VERTEX;
366 G = myPDS->AddPoint(TopOpeBRep_PointGeomTool::MakePoint(P2D));
367 K = TopOpeBRepDS_POINT;
369 return Standard_True;
372 //=======================================================================
375 //=======================================================================
376 void TopOpeBRep_EdgesFiller::Face(const Standard_Integer ISI,const TopoDS_Shape& F)
378 if (ISI == 1) myF1 = TopoDS::Face(F);
379 else if (ISI == 2) myF2 = TopoDS::Face(F);
380 else Standard_Failure::Raise("Face(i,f) : ISI incorrect");
383 //=======================================================================
386 //=======================================================================
387 const TopoDS_Shape& TopOpeBRep_EdgesFiller::Face(const Standard_Integer ISI) const
389 if (ISI == 1) return myF1;
390 else if (ISI == 2) return myF2;
391 else Standard_Failure::Raise("Face(i) : ISI incorrect");
395 //=======================================================================
398 //=======================================================================
399 Handle(TopOpeBRepDS_Interference) TopOpeBRep_EdgesFiller::StorePI(const TopOpeBRep_Point2d& P2D,
400 const TopOpeBRepDS_Transition& T,const Standard_Integer SI,const Standard_Integer GI,
401 const Standard_Real param,const Standard_Integer IEmother)
403 Handle(TopOpeBRepDS_Interference) I = TopOpeBRepDS_InterferenceTool::MakeEdgeInterference(T,TopOpeBRepDS_EDGE,SI,TopOpeBRepDS_POINT,GI,param);
404 TopoDS_Shape Emother;
405 if (IEmother == 1) Emother = myE1;
406 else if (IEmother == 2) Emother = myE2;
407 myHDS->StoreInterference(I,Emother);
408 Standard_Boolean b = ToRecompute(P2D,I,IEmother);
409 if (b) StoreRecompute(I,IEmother);
413 //=======================================================================
416 //=======================================================================
417 Handle(TopOpeBRepDS_Interference) TopOpeBRep_EdgesFiller::StoreVI(const TopOpeBRep_Point2d& P2D,
418 const TopOpeBRepDS_Transition& T,const Standard_Integer EI,const Standard_Integer VI,
419 const Standard_Boolean VisB,const TopOpeBRepDS_Config C,
420 const Standard_Real param,const Standard_Integer IEmother)
422 Handle(TopOpeBRepDS_Interference) I = TopOpeBRepDS_InterferenceTool::MakeEdgeVertexInterference(T,EI,VI,VisB,C,param);
423 TopoDS_Shape Emother;
424 if (IEmother == 1) Emother = myE1;
425 else if (IEmother == 2) Emother = myE2;
426 myHDS->StoreInterference(I,Emother);
427 Standard_Boolean b = ToRecompute(P2D,I,IEmother);
428 if (b) StoreRecompute(I,IEmother);
432 //=======================================================================
433 //function : ToRecompute
435 //=======================================================================
436 Standard_Boolean TopOpeBRep_EdgesFiller::ToRecompute(const TopOpeBRep_Point2d& P2D,const Handle(TopOpeBRepDS_Interference)& /*I*/,const Standard_Integer /*IEmother*/)
438 Standard_Boolean b = Standard_True;
439 Standard_Boolean pointofsegment = P2D.IsPointOfSegment();
440 Standard_Boolean esd = myPEI->SameDomain();
441 b = b && (pointofsegment && !esd);
445 //=======================================================================
446 //function : StoreRecompute
448 //=======================================================================
449 void TopOpeBRep_EdgesFiller::StoreRecompute(const Handle(TopOpeBRepDS_Interference)& I,const Standard_Integer IEmother)
451 if (IEmother == 1) myLI1.Append(I);
452 else if (IEmother == 2) myLI2.Append(I);
455 //=======================================================================
456 //function : RecomputeInterferences
458 //=======================================================================
459 void TopOpeBRep_EdgesFiller::RecomputeInterferences(const TopoDS_Edge& E,TopOpeBRepDS_ListOfInterference& LI)
461 if (LI.IsEmpty()) return;
463 TopOpeBRepDS_TKI tki; tki.FillOnGeometry(LI);
466 Standard_Integer EIX = myPDS->Shape(E); Standard_Boolean TRC=DSREDUEDGETRCE(EIX);
467 if (TRC) cout<<endl<<"RecomputeInterferences E"<<EIX<<" <- "<<LI.Extent()<<endl;
468 if (TRC) tki.DumpTKIIterator("","\n");
469 if (TRC) debefre(EIX);
472 for (tki.Init(); tki.More(); tki.Next()) {
473 TopOpeBRepDS_Kind K; Standard_Integer G; tki.Value(K,G);
474 TopOpeBRepDS_ListOfInterference& loi = tki.ChangeValue(K,G); TopOpeBRepDS_ListOfInterference Rloi;
475 Standard_Integer nloi = loi.Extent();
476 if (nloi == 0) continue;
479 if (nloi > 1) {cout<<"TopOpeBRep_EdgesFiller : > 1 I on UNUN/F on E"<<EIX<<" A FAIRE"<<endl;}
482 Handle(TopOpeBRepDS_Interference)& iloi = loi.First();
483 TopOpeBRepDS_Transition& TU = iloi->ChangeTransition();
484 Standard_Integer ifb = TU.IndexBefore();
485 const TopoDS_Face& fb = TopoDS::Face(myPDS->Shape(ifb));
488 Standard_Integer ifa = TU.IndexAfter();
489 if (ifb != ifa) {cout<<"TopOpeBRep_EdgesFiller : ifb != ifa on E"<<EIX<<" NYI"<<endl;}
492 Standard_Real pE = FDS_Parameter(iloi); TopOpeBRepDS_Transition TN;
493 TN.ShapeBefore(TU.ShapeBefore());TN.IndexBefore(TU.IndexBefore());
494 TN.ShapeAfter(TU.ShapeAfter());TN.IndexAfter(TU.IndexAfter());
497 Standard_Boolean ok =
499 FDS_stateEwithF2d(*myPDS,E,pE,K,G,fb,TN);
503 TopOpeBRepDS_ListOfInterference l1;l1.Append(iloi);
504 TopOpeBRepDS_TKI dt;dt.FillOnGeometry(l1);dt.DumpTKIIterator("","");
506 cout<<" ";TU.Dump(cout);cout<<endl;
507 cout<<"--> ";TN.Dump(cout);cout<<endl;
510 cout<<"--> TN ko"<<endl;
516 } // RecomputeInterferences