]> SALOME platform Git repositories - modules/geom.git/blob - src/AdvancedEngine/GEOMImpl_SmoothingSurfaceDriver.cxx
Salome HOME
0022356: [CEA 968] Regression on the test script 01_geom.py
[modules/geom.git] / src / AdvancedEngine / GEOMImpl_SmoothingSurfaceDriver.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 #include <Standard_Stream.hxx>
23
24 #include "AdvancedEngine_Types.hxx"
25
26 #include <GEOMImpl_SmoothingSurfaceDriver.hxx>
27 #include <GEOMImpl_ISmoothingSurface.hxx>
28 #include <GEOMImpl_Types.hxx>
29 #include <GEOM_Function.hxx>
30
31 #include <TFunction_Logbook.hxx>
32 #include <StdFail_NotDone.hxx>
33
34 //@@ include required header files here @@//
35 #include <TopoDS_Vertex.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <TopoDS_Compound.hxx>
38 #include <TopoDS.hxx>
39
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>
45
46 #include <BRepAdaptor_HSurface.hxx>
47
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>
55
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>
62
63 #include <Geom_BSplineSurface.hxx>
64 #include <Geom_Surface.hxx>
65 #include <Geom_Plane.hxx>
66
67 #include <GProp_GProps.hxx>
68 #include <Bnd_Box.hxx>
69 #include <BRepBndLib.hxx>
70
71 #include <gp_Pnt.hxx>
72 #include <gp_Pln.hxx>
73 #include <gp_Ax3.hxx>
74 #include <gp_Dir.hxx>
75 #include <gp_Vec.hxx>
76
77 #include <GC_MakePlane.hxx>
78 //=======================================================================
79 //function : GetID
80 //purpose  :
81 //=======================================================================
82 const Standard_GUID& GEOMImpl_SmoothingSurfaceDriver::GetID()
83 {
84   static Standard_GUID aGUID("1C3A0F30-729D-4E83-8232-78E74FC5637C");
85   return aGUID;
86 }
87
88 //=======================================================================
89 //function : GEOMImpl_SmoothingSurfaceDriver
90 //purpose  :
91 //=======================================================================
92 GEOMImpl_SmoothingSurfaceDriver::GEOMImpl_SmoothingSurfaceDriver()
93 {
94 }
95
96 //=======================================================================
97 //function : MakeSmoothingSurfaceUnClosed
98 //purpose  :
99 //=======================================================================
100 TopoDS_Shape GEOMImpl_SmoothingSurfaceDriver::MakeSmoothingSurfaceUnClosed(Handle_TColgp_HArray1OfPnt myListOfPoints) const
101 {
102   TopoDS_Face aInitShape;
103   
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();
113   //return aInitShape;
114
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()));
120
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++)
126   {
127     gp_Pnt aPnt = myListOfPoints->Value(j); 
128     Handle(GeomPlate_PointConstraint) PCont = new GeomPlate_PointConstraint(aPnt,0);
129     aBuilder.Add(PCont);
130   }
131   // cout << "avant Perform surface" << endl;
132   aBuilder.Perform();
133   // cout << "Perform surface" << endl;
134
135   // A ce niveau : surface algo
136   Handle(GeomPlate_Surface) gpPlate = aBuilder.Surface();
137   
138   Standard_Integer nbcarreau=2;
139   Standard_Integer degmax=8;
140   Standard_Real seuil;
141   seuil = Max(0.0001,10*aBuilder.G0Error());
142   GeomPlate_MakeApprox Mapp(gpPlate,0.0001,nbcarreau,degmax,seuil);
143   // cout << "Approx surface" << endl;
144
145   Handle (Geom_Surface) Surf (Mapp.Surface());
146  
147   aBuilder.Surface()->Bounds( Umin, Umax, Vmin, Vmax);
148   
149   BRepBuilderAPI_MakeFace MF(Surf,Umin, Umax, Vmin, Vmax, Precision::Confusion());
150   TopoDS_Shape aShape = MF.Shape();
151   
152   return aShape;
153 }
154
155
156 //=======================================================================
157 //function : Execute
158 //purpose  :
159 //=======================================================================
160 Standard_Integer GEOMImpl_SmoothingSurfaceDriver::Execute(TFunction_Logbook& log) const
161 {
162   if (Label().IsNull()) return 0;
163   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
164   if (aFunction.IsNull()) return 0;
165
166   Standard_Integer aType = aFunction->GetType();
167
168   if (aType != SMOOTHINGSURFACE_LPOINTS) return 0;
169   // cout << "Youhou : " << aType << endl;
170
171   GEOMImpl_ISmoothingSurface aData (aFunction);
172   
173   Standard_Integer nbPoints = aData.GetLength();
174
175   Handle(TColgp_HArray1OfPnt) anArrayofPnt = new TColgp_HArray1OfPnt(1,nbPoints);
176   for (int ind=1;ind<=nbPoints;ind++)
177   {
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);
184   }
185
186   TopoDS_Shape aShape;
187   aShape = GEOMImpl_SmoothingSurfaceDriver::MakeSmoothingSurfaceUnClosed(anArrayofPnt);
188
189   if (aShape.IsNull()) return 0;
190
191   aFunction->SetValue(aShape);
192
193   log.SetTouched(Label());
194
195   return 1;
196 }
197
198 //================================================================================
199 /*!
200  * \brief Returns a name of creation operation and names and values of creation parameters
201  */
202 //================================================================================
203
204 bool GEOMImpl_SmoothingSurfaceDriver::
205 GetCreationInformation(std::string&             theOperationName,
206                        std::vector<GEOM_Param>& theParams)
207 {
208   if (Label().IsNull()) return 0;
209   Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
210
211   GEOMImpl_ISmoothingSurface aCI( function );
212   Standard_Integer aType = function->GetType();
213
214   theOperationName = "SMOOTHINGSURFACE";
215
216   switch ( aType ) {
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 ) << " ";
223     break;
224   default:
225     return false;
226   }
227   
228   return true;
229 }
230
231 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_SmoothingSurfaceDriver,GEOM_BaseDriver);
232 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_SmoothingSurfaceDriver,GEOM_BaseDriver);