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 "AdvancedEngine_Types.hxx"
26 #include <GEOMImpl_SmoothingSurfaceDriver.hxx>
27 #include <GEOMImpl_ISmoothingSurface.hxx>
28 #include <GEOMImpl_Types.hxx>
29 #include <GEOM_Function.hxx>
31 #include <TFunction_Logbook.hxx>
32 #include <StdFail_NotDone.hxx>
34 //@@ include required header files here @@//
35 #include <TopoDS_Vertex.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <TopoDS_Compound.hxx>
40 #include <TColgp_SequenceOfPnt.hxx>
41 #include <TColgp_Array2OfPnt.hxx>
42 #include <TColgp_SequenceOfXY.hxx>
43 #include <TColgp_SequenceOfXYZ.hxx>
44 #include <TColStd_Array1OfInteger.hxx>
46 #include <BRepAdaptor_HSurface.hxx>
48 #include <BRep_Builder.hxx>
49 #include <BRepGProp.hxx>
50 #include <BRep_Tool.hxx>
51 #include <BRepPrimAPI_MakeSphere.hxx>
52 #include <BRepPrimAPI_MakeBox.hxx>
53 #include <BRepBuilderAPI_MakeFace.hxx>
54 #include <BRepAlgoAPI_Cut.hxx>
56 #include <GeomPlate_Surface.hxx>
57 #include <GeomPlate_BuildPlateSurface.hxx>
58 #include <GeomPlate_PointConstraint.hxx>
59 #include <GeomPlate_MakeApprox.hxx>
60 #include <GeomPlate_PlateG0Criterion.hxx>
61 #include <GeomPlate_BuildAveragePlane.hxx>
63 #include <Geom_BSplineSurface.hxx>
64 #include <Geom_Surface.hxx>
65 #include <Geom_Plane.hxx>
67 #include <GProp_GProps.hxx>
68 #include <Bnd_Box.hxx>
69 #include <BRepBndLib.hxx>
77 #include <GC_MakePlane.hxx>
78 //=======================================================================
81 //=======================================================================
82 const Standard_GUID& GEOMImpl_SmoothingSurfaceDriver::GetID()
84 static Standard_GUID aGUID("1C3A0F30-729D-4E83-8232-78E74FC5637C");
88 //=======================================================================
89 //function : GEOMImpl_SmoothingSurfaceDriver
91 //=======================================================================
92 GEOMImpl_SmoothingSurfaceDriver::GEOMImpl_SmoothingSurfaceDriver()
96 //=======================================================================
97 //function : MakeSmoothingSurfaceUnClosed
99 //=======================================================================
100 TopoDS_Shape GEOMImpl_SmoothingSurfaceDriver::MakeSmoothingSurfaceUnClosed(Handle_TColgp_HArray1OfPnt myListOfPoints) const
102 TopoDS_Face aInitShape;
104 // Create an average Plane
105 //Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,myListOfPoints.Length())
106 GeomPlate_BuildAveragePlane gpbap(myListOfPoints,myListOfPoints->Length(),Precision::Confusion(),1,1);
107 Handle(Geom_Plane) plane(gpbap.Plane());
108 Standard_Real Umin, Umax, Vmin, Vmax;
109 gpbap.MinMaxBox(Umin,Umax,Vmin,Vmax);
110 // cout << "Vals : " << Umin << ", " << Umax << ", " << Vmin << ", " << Vmax << endl;
111 BRepBuilderAPI_MakeFace mf(plane,Umin,Umax,Vmin,Vmax,Precision::Confusion());
112 aInitShape = mf.Face();
115 GeomPlate_BuildPlateSurface aBuilder(3,10);
116 // ** Initialization of surface
117 Handle(BRepAdaptor_HSurface) HSI = new BRepAdaptor_HSurface();
118 HSI->ChangeSurface().Initialize(aInitShape);
119 aBuilder.LoadInitSurface( BRep_Tool::Surface(HSI->ChangeSurface().Face()));
121 Standard_Integer j, j1, j2;
122 // cout << "Init surface" << endl;
123 j1 = myListOfPoints->Lower();
124 j2 = myListOfPoints->Upper();
125 for (j=j1; j<=j2 ; j++)
127 gp_Pnt aPnt = myListOfPoints->Value(j);
128 Handle(GeomPlate_PointConstraint) PCont = new GeomPlate_PointConstraint(aPnt,0);
131 // cout << "avant Perform surface" << endl;
133 // cout << "Perform surface" << endl;
135 // A ce niveau : surface algo
136 Handle(GeomPlate_Surface) gpPlate = aBuilder.Surface();
138 Standard_Integer nbcarreau=2;
139 Standard_Integer degmax=8;
141 seuil = Max(0.0001,10*aBuilder.G0Error());
142 GeomPlate_MakeApprox Mapp(gpPlate,0.0001,nbcarreau,degmax,seuil);
143 // cout << "Approx surface" << endl;
145 Handle (Geom_Surface) Surf (Mapp.Surface());
147 aBuilder.Surface()->Bounds( Umin, Umax, Vmin, Vmax);
149 BRepBuilderAPI_MakeFace MF(Surf,Umin, Umax, Vmin, Vmax, Precision::Confusion());
150 TopoDS_Shape aShape = MF.Shape();
156 //=======================================================================
159 //=======================================================================
160 Standard_Integer GEOMImpl_SmoothingSurfaceDriver::Execute(TFunction_Logbook& log) const
162 if (Label().IsNull()) return 0;
163 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
164 if (aFunction.IsNull()) return 0;
166 Standard_Integer aType = aFunction->GetType();
168 if (aType != SMOOTHINGSURFACE_LPOINTS) return 0;
169 // cout << "Youhou : " << aType << endl;
171 GEOMImpl_ISmoothingSurface aData (aFunction);
173 Standard_Integer nbPoints = aData.GetLength();
175 Handle(TColgp_HArray1OfPnt) anArrayofPnt = new TColgp_HArray1OfPnt(1,nbPoints);
176 for (int ind=1;ind<=nbPoints;ind++)
178 Handle(GEOM_Function) aPoint = aData.GetPoint(ind);
179 TopoDS_Shape aShapePnt = aPoint->GetValue();
180 TopoDS_Vertex dsPoint;
181 dsPoint = TopoDS::Vertex( aShapePnt );
182 gp_Pnt aPnt = BRep_Tool::Pnt( dsPoint );
183 anArrayofPnt->SetValue(ind,aPnt);
187 aShape = GEOMImpl_SmoothingSurfaceDriver::MakeSmoothingSurfaceUnClosed(anArrayofPnt);
189 if (aShape.IsNull()) return 0;
191 aFunction->SetValue(aShape);
193 log.SetTouched(Label());
198 //================================================================================
200 * \brief Returns a name of creation operation and names and values of creation parameters
202 //================================================================================
204 bool GEOMImpl_SmoothingSurfaceDriver::
205 GetCreationInformation(std::string& theOperationName,
206 std::vector<GEOM_Param>& theParams)
208 if (Label().IsNull()) return 0;
209 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
211 GEOMImpl_ISmoothingSurface aCI( function );
212 Standard_Integer aType = function->GetType();
214 theOperationName = "SMOOTHINGSURFACE";
217 case SMOOTHINGSURFACE_LPOINTS:
218 AddParam( theParams, "Points" );
219 if ( aCI.GetLength() > 1 )
220 theParams[0] << aCI.GetLength() << " points: ";
221 for ( int i = 1, nb = aCI.GetLength(); i <= nb; ++i )
222 theParams[0] << aCI.GetPoint( i ) << " ";
231 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_SmoothingSurfaceDriver,GEOM_BaseDriver);
232 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_SmoothingSurfaceDriver,GEOM_BaseDriver);