1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_SmoothingSurfaceDriver.hxx>
25 #include <GEOMImpl_ISmoothingSurface.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
29 #include <TFunction_Logbook.hxx>
30 #include <StdFail_NotDone.hxx>
32 //@@ include required header files here @@//
33 #include <TopoDS_Vertex.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Compound.hxx>
38 #include <TColgp_SequenceOfPnt.hxx>
39 #include <TColgp_Array2OfPnt.hxx>
40 #include <TColgp_SequenceOfXY.hxx>
41 #include <TColgp_SequenceOfXYZ.hxx>
42 #include <TColStd_Array1OfInteger.hxx>
44 #include <BRepAdaptor_HSurface.hxx>
46 #include <BRep_Builder.hxx>
47 #include <BRepGProp.hxx>
48 #include <BRep_Tool.hxx>
49 #include <BRepPrimAPI_MakeSphere.hxx>
50 #include <BRepPrimAPI_MakeBox.hxx>
51 #include <BRepBuilderAPI_MakeFace.hxx>
52 #include <BRepAlgoAPI_Cut.hxx>
54 #include <GeomPlate_Surface.hxx>
55 #include <GeomPlate_BuildPlateSurface.hxx>
56 #include <GeomPlate_PointConstraint.hxx>
57 #include <GeomPlate_MakeApprox.hxx>
58 #include <GeomPlate_PlateG0Criterion.hxx>
59 #include <GeomPlate_BuildAveragePlane.hxx>
61 #include <Geom_BSplineSurface.hxx>
62 #include <Geom_Surface.hxx>
63 #include <Geom_Plane.hxx>
65 #include <GProp_GProps.hxx>
66 #include <Bnd_Box.hxx>
67 #include <BRepBndLib.hxx>
75 #include <GC_MakePlane.hxx>
76 //=======================================================================
79 //=======================================================================
80 const Standard_GUID& GEOMImpl_SmoothingSurfaceDriver::GetID()
82 static Standard_GUID aGUID("1C3A0F30-729D-4E83-8232-78E74FC5637C");
86 //=======================================================================
87 //function : GEOMImpl_SmoothingSurfaceDriver
89 //=======================================================================
90 GEOMImpl_SmoothingSurfaceDriver::GEOMImpl_SmoothingSurfaceDriver()
94 //=======================================================================
95 //function : MakeSmoothingSurfaceUnClosed
97 //=======================================================================
98 TopoDS_Shape GEOMImpl_SmoothingSurfaceDriver::MakeSmoothingSurfaceUnClosed(Handle_TColgp_HArray1OfPnt myListOfPoints) const
100 TopoDS_Face aInitShape;
102 // Create an average Plane
103 //Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,myListOfPoints.Length())
104 GeomPlate_BuildAveragePlane gpbap(myListOfPoints,myListOfPoints->Length(),Precision::Confusion(),1,1);
105 Handle(Geom_Plane) plane(gpbap.Plane());
106 Standard_Real Umin, Umax, Vmin, Vmax;
107 gpbap.MinMaxBox(Umin,Umax,Vmin,Vmax);
108 // cout << "Vals : " << Umin << ", " << Umax << ", " << Vmin << ", " << Vmax << endl;
109 BRepBuilderAPI_MakeFace mf(plane,Umin,Umax,Vmin,Vmax,Precision::Confusion());
110 aInitShape = mf.Face();
113 GeomPlate_BuildPlateSurface aBuilder(3,10);
114 // ** Initialization of surface
115 Handle(BRepAdaptor_HSurface) HSI = new BRepAdaptor_HSurface();
116 HSI->ChangeSurface().Initialize(aInitShape);
117 aBuilder.LoadInitSurface( BRep_Tool::Surface(HSI->ChangeSurface().Face()));
119 Standard_Integer j, j1, j2;
120 // cout << "Init surface" << endl;
121 j1 = myListOfPoints->Lower();
122 j2 = myListOfPoints->Upper();
123 for (j=j1; j<=j2 ; j++)
125 gp_Pnt aPnt = myListOfPoints->Value(j);
126 Handle(GeomPlate_PointConstraint) PCont = new GeomPlate_PointConstraint(aPnt,0);
129 // cout << "avant Perform surface" << endl;
131 // cout << "Perform surface" << endl;
133 // A ce niveau : surface algo
134 Handle(GeomPlate_Surface) gpPlate = aBuilder.Surface();
136 Standard_Integer nbcarreau=2;
137 Standard_Integer degmax=8;
139 seuil = Max(0.0001,10*aBuilder.G0Error());
140 GeomPlate_MakeApprox Mapp(gpPlate,0.0001,nbcarreau,degmax,seuil);
141 // cout << "Approx surface" << endl;
143 Handle (Geom_Surface) Surf (Mapp.Surface());
145 aBuilder.Surface()->Bounds( Umin, Umax, Vmin, Vmax);
147 BRepBuilderAPI_MakeFace MF(Surf,Umin, Umax, Vmin, Vmax, Precision::Confusion());
148 TopoDS_Shape aShape = MF.Shape();
154 //=======================================================================
157 //=======================================================================
158 Standard_Integer GEOMImpl_SmoothingSurfaceDriver::Execute(TFunction_Logbook& log) const
160 if (Label().IsNull()) return 0;
161 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
162 if (aFunction.IsNull()) return 0;
164 Standard_Integer aType = aFunction->GetType();
166 if (aType != SMOOTHINGSURFACE_LPOINTS) return 0;
167 // cout << "Youhou : " << aType << endl;
169 GEOMImpl_ISmoothingSurface aData (aFunction);
171 Standard_Integer nbPoints = aData.GetLength();
173 Handle(TColgp_HArray1OfPnt) anArrayofPnt = new TColgp_HArray1OfPnt(1,nbPoints);
174 for (int ind=1;ind<=nbPoints;ind++)
176 Handle(GEOM_Function) aPoint = aData.GetPoint(ind);
177 TopoDS_Shape aShapePnt = aPoint->GetValue();
178 TopoDS_Vertex dsPoint;
179 dsPoint = TopoDS::Vertex( aShapePnt );
180 gp_Pnt aPnt = BRep_Tool::Pnt( dsPoint );
181 anArrayofPnt->SetValue(ind,aPnt);
185 aShape = GEOMImpl_SmoothingSurfaceDriver::MakeSmoothingSurfaceUnClosed(anArrayofPnt);
187 if (aShape.IsNull()) return 0;
189 aFunction->SetValue(aShape);
191 log.SetTouched(Label());
196 //================================================================================
198 * \brief Returns a name of creation operation and names and values of creation parameters
200 //================================================================================
202 bool GEOMImpl_SmoothingSurfaceDriver::
203 GetCreationInformation(std::string& theOperationName,
204 std::vector<GEOM_Param>& theParams)
206 if (Label().IsNull()) return 0;
207 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
209 GEOMImpl_ISmoothingSurface aCI( function );
210 Standard_Integer aType = function->GetType();
212 theOperationName = "SMOOTHINGSURFACE";
215 case SMOOTHINGSURFACE_LPOINTS:
216 AddParam( theParams, "Points" );
217 if ( aCI.GetLength() > 1 )
218 theParams[0] << aCI.GetLength() << " points: ";
219 for ( int i = 1, nb = aCI.GetLength(); i <= nb; ++i )
220 theParams[0] << aCI.GetPoint( i ) << " ";
229 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_SmoothingSurfaceDriver,GEOM_BaseDriver);
230 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_SmoothingSurfaceDriver,GEOM_BaseDriver);