// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com #include #include #include #include #include #include #include //@@ include required header files here @@// #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 //======================================================================= //function : GetID //purpose : //======================================================================= const Standard_GUID& GEOMImpl_SmoothingSurfaceDriver::GetID() { static Standard_GUID aGUID("1C3A0F30-729D-4E83-8232-78E74FC5637C"); return aGUID; } //======================================================================= //function : GEOMImpl_SmoothingSurfaceDriver //purpose : //======================================================================= GEOMImpl_SmoothingSurfaceDriver::GEOMImpl_SmoothingSurfaceDriver() { } //======================================================================= //function : MakeSmoothingSurfaceUnClosed //purpose : //======================================================================= TopoDS_Shape GEOMImpl_SmoothingSurfaceDriver::MakeSmoothingSurfaceUnClosed(Handle_TColgp_HArray1OfPnt myListOfPoints) const { TopoDS_Face aInitShape; // Create an average Plane //Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,myListOfPoints.Length()) GeomPlate_BuildAveragePlane gpbap(myListOfPoints,myListOfPoints->Length(),Precision::Confusion(),1,1); Handle(Geom_Plane) plane(gpbap.Plane()); Standard_Real Umin, Umax, Vmin, Vmax; gpbap.MinMaxBox(Umin,Umax,Vmin,Vmax); // cout << "Vals : " << Umin << ", " << Umax << ", " << Vmin << ", " << Vmax << endl; BRepBuilderAPI_MakeFace mf(plane,Umin,Umax,Vmin,Vmax,Precision::Confusion()); aInitShape = mf.Face(); //return aInitShape; GeomPlate_BuildPlateSurface aBuilder(3,10); // ** Initialization of surface Handle(BRepAdaptor_HSurface) HSI = new BRepAdaptor_HSurface(); HSI->ChangeSurface().Initialize(aInitShape); aBuilder.LoadInitSurface( BRep_Tool::Surface(HSI->ChangeSurface().Face())); Standard_Integer j, j1, j2; // cout << "Init surface" << endl; j1 = myListOfPoints->Lower(); j2 = myListOfPoints->Upper(); for (j=j1; j<=j2 ; j++) { gp_Pnt aPnt = myListOfPoints->Value(j); Handle(GeomPlate_PointConstraint) PCont = new GeomPlate_PointConstraint(aPnt,0); aBuilder.Add(PCont); } // cout << "avant Perform surface" << endl; aBuilder.Perform(); // cout << "Perform surface" << endl; // A ce niveau : surface algo Handle(GeomPlate_Surface) gpPlate = aBuilder.Surface(); Standard_Integer nbcarreau=2; Standard_Integer degmax=8; Standard_Real seuil; seuil = Max(0.0001,10*aBuilder.G0Error()); GeomPlate_MakeApprox Mapp(gpPlate,0.0001,nbcarreau,degmax,seuil); // cout << "Approx surface" << endl; Handle (Geom_Surface) Surf (Mapp.Surface()); aBuilder.Surface()->Bounds( Umin, Umax, Vmin, Vmax); BRepBuilderAPI_MakeFace MF(Surf,Umin, Umax, Vmin, Vmax, Precision::Confusion()); TopoDS_Shape aShape = MF.Shape(); return aShape; } //======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_SmoothingSurfaceDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); if (aFunction.IsNull()) return 0; Standard_Integer aType = aFunction->GetType(); if (aType != SMOOTHINGSURFACE_LPOINTS) return 0; // cout << "Youhou : " << aType << endl; GEOMImpl_ISmoothingSurface aData (aFunction); Standard_Integer nbPoints = aData.GetLength(); Handle(TColgp_HArray1OfPnt) anArrayofPnt = new TColgp_HArray1OfPnt(1,nbPoints); for (int ind=1;ind<=nbPoints;ind++) { Handle(GEOM_Function) aPoint = aData.GetPoint(ind); TopoDS_Shape aShapePnt = aPoint->GetValue(); TopoDS_Vertex dsPoint; dsPoint = TopoDS::Vertex( aShapePnt ); gp_Pnt aPnt = BRep_Tool::Pnt( dsPoint ); anArrayofPnt->SetValue(ind,aPnt); } TopoDS_Shape aShape; aShape = GEOMImpl_SmoothingSurfaceDriver::MakeSmoothingSurfaceUnClosed(anArrayofPnt); if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; } //================================================================================ /*! * \brief Returns a name of creation operation and names and values of creation parameters */ //================================================================================ bool GEOMImpl_SmoothingSurfaceDriver:: GetCreationInformation(std::string& theOperationName, std::vector& theParams) { if (Label().IsNull()) return 0; Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label()); GEOMImpl_ISmoothingSurface aCI( function ); Standard_Integer aType = function->GetType(); theOperationName = "SMOOTHINGSURFACE"; switch ( aType ) { case SMOOTHINGSURFACE_LPOINTS: AddParam( theParams, "Points" ); if ( aCI.GetLength() > 1 ) theParams[0] << aCI.GetLength() << " points: "; for ( int i = 1, nb = aCI.GetLength(); i <= nb; ++i ) theParams[0] << aCI.GetPoint( i ) << " "; break; default: return false; } return true; } IMPLEMENT_STANDARD_HANDLE (GEOMImpl_SmoothingSurfaceDriver,GEOM_BaseDriver); IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_SmoothingSurfaceDriver,GEOM_BaseDriver);