// Created on: 1996-07-10 // Created by: Joelle CHAUVET // Copyright (c) 1996-1999 Matra Datavision // Copyright (c) 1999-2012 OPEN CASCADE SAS // // The content of this file is subject to the Open CASCADE Technology Public // License Version 6.5 (the "License"). You may not use the content of this file // except in compliance with the License. Please obtain a copy of the License // at http://www.opencascade.org and read it completely before using this file. // // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. // // The Original Code and all software distributed under the License is // distributed on an "AS IS" basis, without warranty of any kind, and the // Initial Developer hereby disclaims all such warranties, including without // limitation, any warranties of merchantability, fitness for a particular // purpose or non-infringement. Please see the License for the specific terms // and conditions governing the rights and limitations under the License. // Modified: Wed Mar 5 09:45:42 1997 // by: Joelle CHAUVET // G1134 : new command "approxplate" // Modified: Thu Jun 12 16:51:36 1997 // by: Jerome LEMONIER // Mise a jour suite a la modification des methodes Curves2d // et Sense GeomPlate_BuildPlateSurface. // Modified: Mon Nov 3 10:24:07 1997 // utilisation de BRepFill_CurveConstraint #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // pour mes tests #ifdef DEB #include #include #endif const Standard_Integer defDegree = 3; const Standard_Integer defNbPtsOnCur = 10; const Standard_Integer defNbIter = 3; const Standard_Boolean defAnisotropie = Standard_False; const Standard_Real defTol2d = 0.00001; const Standard_Real defTol3d = 0.0001; const Standard_Real defTolAng = 0.01; const Standard_Real defTolCurv = 0.1; const Standard_Integer defMaxDeg = 8; const Standard_Integer defMaxSegments = 9; Standard_Integer Degree = defDegree; Standard_Integer NbPtsOnCur = defNbPtsOnCur ; Standard_Integer NbIter = defNbIter; Standard_Boolean Anisotropie = defAnisotropie ; Standard_Real Tol2d = defTol2d; Standard_Real Tol3d = defTol3d; Standard_Real TolAng = defTolAng; Standard_Real TolCurv = defTolCurv; Standard_Integer MaxDeg = defMaxDeg; Standard_Integer MaxSegments = defMaxSegments; //////////////////////////////////////////////////////////////////////////////// // commande plate : resultat face sur surface plate //////////////////////////////////////////////////////////////////////////////// static Standard_Integer plate (Draw_Interpretor & di,Standard_Integer n,const char** a) { if (n < 8 ) return 1; Standard_Integer NbCurFront=Draw::Atoi(a[3]); Handle(GeomPlate_HArray1OfHCurveOnSurface) Fronts = new GeomPlate_HArray1OfHCurveOnSurface(1,NbCurFront); Handle(TColStd_HArray1OfInteger) Tang = new TColStd_HArray1OfInteger(1,NbCurFront); Handle(TColStd_HArray1OfInteger) NbPtsCur = new TColStd_HArray1OfInteger(1,NbCurFront); BRep_Builder B; GeomPlate_BuildPlateSurface Henri(3,15,2); Standard_Integer i; for (i=1; i<=NbCurFront ; i++) { TopoDS_Shape aLocalEdge(DBRep::Get(a[3*i+1],TopAbs_EDGE)); TopoDS_Edge E = TopoDS::Edge(aLocalEdge); // TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[3*i+1],TopAbs_EDGE)); if(E.IsNull()) return 1; TopoDS_Shape aLocalFace(DBRep::Get(a[3*i+2],TopAbs_FACE)); TopoDS_Face F = TopoDS::Face(aLocalFace); // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[3*i+2],TopAbs_FACE)); if(F.IsNull()) return 1; Standard_Integer T = Draw::Atoi(a[3*i+3]); Tang->SetValue(i,T); NbPtsCur->SetValue(i,Draw::Atoi(a[2])); Handle(BRepAdaptor_HSurface) S = new BRepAdaptor_HSurface(); S->ChangeSurface().Initialize(F); Handle(BRepAdaptor_HCurve2d) C = new BRepAdaptor_HCurve2d(); C->ChangeCurve2d().Initialize(E,F); Adaptor3d_CurveOnSurface ConS(C,S); Handle (Adaptor3d_HCurveOnSurface) HConS = new Adaptor3d_HCurveOnSurface(ConS); Fronts->SetValue(i,HConS); Handle(BRepFill_CurveConstraint) Cont = new BRepFill_CurveConstraint(HConS, Tang->Value(i), NbPtsCur->Value(i)); Henri.Add(Cont); } Henri.Perform(); Standard_Real ErrG0 = 1.1*Henri.G0Error(); //cout<<" dist. max = "<Value(i); TopoDS_Edge E; if (Henri.Sense()->Value(iInOrder)==1) { BRepBuilderAPI_MakeEdge ME(Henri.Curves2d()->Value(iInOrder), Henri.Surface(), Fronts->Value(iInOrder)->LastParameter(), Fronts->Value(iInOrder)->FirstParameter()); E = ME.Edge(); } else { BRepBuilderAPI_MakeEdge ME(Henri.Curves2d()->Value(iInOrder), Henri.Surface(), Fronts->Value(iInOrder)->FirstParameter(), Fronts->Value(iInOrder)->LastParameter()); E = ME.Edge(); } B.UpdateVertex(TopExp::FirstVertex(E), ErrG0); B.UpdateVertex(TopExp::LastVertex(E), ErrG0); BRepLib::BuildCurve3d(E); char name[100]; Sprintf(name,"Edge_%d", i); DBRep::Set(name, E); MW.Add(E); if (MW.IsDone()==Standard_False) { Standard_Failure::Raise("mkWire is over "); } } TopoDS_Wire W; W=MW.Wire(); if (!(W.Closed())) Standard_Failure::Raise("Wire is not closed"); BRepBuilderAPI_MakeFace MF(Henri.Surface(),W,Standard_True); DBRep::Set(a[1],MF.Face()); return 0; } //////////////////////////////////////////////////////////////////////////////// // commande gplate : resultat face egale a la surface approchee //////////////////////////////////////////////////////////////////////////////// static Standard_Integer gplate (Draw_Interpretor & ,Standard_Integer n,const char** a) { if (n < 6 ) return 1; Standard_Integer NbCurFront=Draw::Atoi(a[2]), NbPointConstraint=Draw::Atoi(a[3]); GeomPlate_BuildPlateSurface Henri(3,15,2); Standard_Integer i; Standard_Integer Conti; Standard_Integer Indice=4; //Surface d'init TopoDS_Shape aLocalFace(DBRep::Get(a[Indice++],TopAbs_FACE)); TopoDS_Face SI = TopoDS::Face(aLocalFace); // TopoDS_Face SI = TopoDS::Face(DBRep::Get(a[Indice++],TopAbs_FACE)); if(SI.IsNull()) Indice--; else { Handle(BRepAdaptor_HSurface) HSI = new BRepAdaptor_HSurface(); HSI->ChangeSurface().Initialize(SI); Henri.LoadInitSurface( BRep_Tool::Surface(HSI->ChangeSurface().Face())); } for (i=1; i<=NbCurFront ; i++) { TopoDS_Shape aLocalShape(DBRep::Get(a[Indice++],TopAbs_EDGE)); TopoDS_Edge E = TopoDS::Edge(aLocalShape); // TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[Indice++],TopAbs_EDGE)); if(E.IsNull()) return 1; Conti=Draw::Atoi(a[Indice++]); if ((Conti==0)||(Conti==-1)) { Handle(BRepAdaptor_HCurve) C = new BRepAdaptor_HCurve(); C->ChangeCurve().Initialize(E); Handle(BRepFill_CurveConstraint) Cont= new BRepFill_CurveConstraint(C,Conti); Henri.Add(Cont); } else { aLocalFace = DBRep::Get(a[Indice++],TopAbs_FACE); TopoDS_Face F = TopoDS::Face(aLocalFace); // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[Indice++],TopAbs_FACE)); if(F.IsNull()) return 1; Handle(BRepAdaptor_HSurface) S = new BRepAdaptor_HSurface(); S->ChangeSurface().Initialize(F); Handle(BRepAdaptor_HCurve2d) C = new BRepAdaptor_HCurve2d(); C->ChangeCurve2d().Initialize(E,F); Adaptor3d_CurveOnSurface ConS(C,S); Handle (Adaptor3d_HCurveOnSurface) HConS = new Adaptor3d_HCurveOnSurface(ConS); Handle(BRepFill_CurveConstraint) Cont= new BRepFill_CurveConstraint(HConS,Conti); Henri.Add(Cont); } } for (i=1; i<=NbPointConstraint ; i++) { // gp_Pnt P1,P2,P3; gp_Pnt P1; // gp_Vec V1,V2,V3,V4,V5; if (DrawTrSurf::GetPoint(a[Indice], P1) ) { Conti=0; Handle(GeomPlate_PointConstraint) PCont= new GeomPlate_PointConstraint(P1,0); Henri.Add(PCont); Indice++; } else { Standard_Real u=Draw::Atof(a[Indice++]), v=Draw::Atof(a[Indice++]); Conti=Draw::Atoi(a[Indice++]); aLocalFace = DBRep::Get(a[Indice++],TopAbs_FACE); TopoDS_Face F = TopoDS::Face(aLocalFace); // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[Indice++],TopAbs_FACE)); if(F.IsNull()) return 1; Handle(BRepAdaptor_HSurface) HF = new BRepAdaptor_HSurface(); HF->ChangeSurface().Initialize(F); Handle(GeomPlate_PointConstraint) PCont= new GeomPlate_PointConstraint(u,v,BRep_Tool::Surface(HF->ChangeSurface().Face()),Conti,0.001,0.001,0.001); Henri.Add(PCont); } } Henri.Perform(); Standard_Integer nbcarreau=9; Standard_Integer degmax=8; Standard_Real seuil; Handle(GeomPlate_Surface) gpPlate = Henri.Surface(); TColgp_SequenceOfXY S2d; TColgp_SequenceOfXYZ S3d; S2d.Clear(); S3d.Clear(); Henri.Disc2dContour(4,S2d); Henri.Disc3dContour(4,0,S3d); seuil = Max(0.0001,10*Henri.G0Error()); GeomPlate_PlateG0Criterion critere (S2d,S3d,seuil); GeomPlate_MakeApprox Mapp(gpPlate,critere,0.0001,nbcarreau,degmax); Handle (Geom_Surface) Surf (Mapp.Surface()); Standard_Real Umin, Umax, Vmin, Vmax; Henri.Surface()->Bounds( Umin, Umax, Vmin, Vmax); BRepBuilderAPI_MakeFace MF(Surf, Umin, Umax, Vmin, Vmax, Precision::Confusion()); DBRep::Set(a[1],MF.Face()); return 0; } //////////////////////////////////////////////////////////////////////////////// // commande approxplate : resultat face sur surface approchee //////////////////////////////////////////////////////////////////////////////// static Standard_Integer approxplate (Draw_Interpretor & di,Standard_Integer n,const char** a) { if (n < 9 ) return 1; Standard_Integer NbMedium=Draw::Atoi(a[2]); Standard_Integer NbCurFront=Draw::Atoi(a[3]); Handle(GeomPlate_HArray1OfHCurveOnSurface) Fronts = new GeomPlate_HArray1OfHCurveOnSurface(1,NbCurFront); Handle(TColStd_HArray1OfInteger) Tang = new TColStd_HArray1OfInteger(1,NbCurFront); Handle(TColStd_HArray1OfInteger) NbPtsCur = new TColStd_HArray1OfInteger(1,NbCurFront); GeomPlate_BuildPlateSurface Henri(3,15,2); Standard_Integer i; for (i=1; i<=NbCurFront ; i++) { TopoDS_Shape aLocalShape(DBRep::Get(a[3*i+1],TopAbs_EDGE)); TopoDS_Edge E = TopoDS::Edge(aLocalShape); // TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[3*i+1],TopAbs_EDGE)); if(E.IsNull()) return 1; TopoDS_Shape aLocalFace(DBRep::Get(a[3*i+2],TopAbs_FACE)); TopoDS_Face F = TopoDS::Face(aLocalFace); // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[3*i+2],TopAbs_FACE)); if(F.IsNull()) return 1; Standard_Integer T = Draw::Atoi(a[3*i+3]); Tang->SetValue(i,T); NbPtsCur->SetValue(i,NbMedium); Handle(BRepAdaptor_HSurface) S = new BRepAdaptor_HSurface(); S->ChangeSurface().Initialize(F); Handle(BRepAdaptor_HCurve2d) C = new BRepAdaptor_HCurve2d(); C->ChangeCurve2d().Initialize(E,F); Adaptor3d_CurveOnSurface ConS(C,S); Handle (Adaptor3d_HCurveOnSurface) HConS = new Adaptor3d_HCurveOnSurface(ConS); Fronts->SetValue(i,HConS); Handle(BRepFill_CurveConstraint) Cont = new BRepFill_CurveConstraint(HConS, Tang->Value(i), NbPtsCur->Value(i)); Henri.Add(Cont); } Henri.Perform(); Standard_Real dmax = Henri.G0Error(), anmax = Henri.G1Error(); //cout<<" dist. max = "<=0) { TColgp_SequenceOfXY S2d; TColgp_SequenceOfXYZ S3d; S2d.Clear(); S3d.Clear(); Standard_Real seuil; if (CritOrder==0) { Henri.Disc2dContour(4,S2d); Henri.Disc3dContour(4,0,S3d); seuil = Max(Tol3d,dmax*10); GeomPlate_PlateG0Criterion Crit0(S2d,S3d,seuil); GeomPlate_MakeApprox MApp(surf,Crit0,Tol3d,Nbmax,degmax); support = MApp.Surface(); } else if (CritOrder==1) { Henri.Disc2dContour(4,S2d); Henri.Disc3dContour(4,1,S3d); seuil = Max(Tol3d,anmax*10); GeomPlate_PlateG1Criterion Crit1(S2d,S3d,seuil); GeomPlate_MakeApprox MApp(surf,Crit1,Tol3d,Nbmax,degmax); support = MApp.Surface(); } } BRepBuilderAPI_MakeWire MW; BRep_Builder B; for (i=1 ; i<=NbCurFront ; i++) { Standard_Integer iInOrder=Henri.Order()->Value(i); TopoDS_Edge E; if (Henri.Sense()->Value(iInOrder)==1) { BRepBuilderAPI_MakeEdge ME(Henri.Curves2d()->Value(iInOrder), support, Fronts->Value(iInOrder)->LastParameter(), Fronts->Value(iInOrder)->FirstParameter()); E = ME.Edge(); } else { BRepBuilderAPI_MakeEdge ME(Henri.Curves2d()->Value(iInOrder), support, Fronts->Value(iInOrder)->FirstParameter(), Fronts->Value(iInOrder)->LastParameter()); E = ME.Edge(); } B.UpdateVertex(TopExp::FirstVertex(E), dmax); B.UpdateVertex(TopExp::LastVertex(E), dmax); BRepLib::BuildCurve3d(E); MW.Add(E); if (MW.IsDone()==Standard_False) { Standard_Failure::Raise("mkWire is over "); } } TopoDS_Wire W; W=MW.Wire(); if (!(W.Closed())) Standard_Failure::Raise("Wire is not closed"); BRepBuilderAPI_MakeFace MF(support,W,Standard_True); DBRep::Set(a[1],MF.Face()); return 0; } static Standard_Integer filling( Draw_Interpretor & di, Standard_Integer n, const char** a ) { #ifdef DEB // Chronmetrage OSD_Chronometer Chrono; Chrono.Reset(); Chrono.Start(); #endif if (n < 7) return 1; Standard_Integer NbBounds = Draw::Atoi( a[2] ); Standard_Integer NbConstraints = Draw::Atoi( a[3] ); Standard_Integer NbPoints = Draw::Atoi( a[4] ); BRepOffsetAPI_MakeFilling MakeFilling( Degree, NbPtsOnCur, NbIter, Anisotropie, Tol2d, Tol3d, TolAng, TolCurv, MaxDeg, MaxSegments ); //TopoDS_Shape aLocalFace(DBRep::Get( a[5], TopAbs_FACE ) ); //TopoDS_Face InitFace = TopoDS::Face( aLocalFace); TopoDS_Face InitFace = TopoDS::Face( DBRep::Get(a[5], TopAbs_FACE) ); if (! InitFace.IsNull()) MakeFilling.LoadInitSurface( InitFace ); Standard_Integer i = (InitFace.IsNull())? 5 : 6, k; TopoDS_Edge E; TopoDS_Face F; gp_Pnt Point; Standard_Integer Order; for (k = 1; k <= NbBounds; k++) { E.Nullify(); F.Nullify(); //TopoDS_Shape aLocalEdge(DBRep::Get( a[i], TopAbs_EDGE )); //E = TopoDS::Edge(aLocalEdge); E = TopoDS::Edge( DBRep::Get(a[i], TopAbs_EDGE) ); if (! E.IsNull()) i++; //aLocalFace = DBRep::Get( a[i], TopAbs_FACE ) ; //F = TopoDS::Face(aLocalFace); F = TopoDS::Face( DBRep::Get(a[i], TopAbs_FACE) ); if (! F.IsNull()) i++; Order = Draw::Atoi( a[i++] ); if (! E.IsNull() && ! F.IsNull()) MakeFilling.Add( E, F, (GeomAbs_Shape)Order ); else if (E.IsNull()) { if (F.IsNull()) { //cout< 1) { TCollection_AsciiString AS( a[1] ); AS.LowerCase(); const char* flag = AS.ToCString(); if (strcmp( flag, "-l" ) == 0 && n == 2) { //cout<