1 // Copyright (C) 2013-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Standard_Stream.hxx>
22 #include "AdvancedEngine_SmoothingSurfaceDriver.hxx"
23 #include "AdvancedEngine_ISmoothingSurface.hxx"
24 #include "AdvancedEngine_Types.hxx"
26 #include "GEOM_Function.hxx"
28 #include <StdFail_NotDone.hxx>
30 #include <TopoDS_Vertex.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Compound.hxx>
34 #include <TopTools_MapOfShape.hxx>
35 #include <TopTools_MapIteratorOfMapOfShape.hxx>
36 #include <TopExp_Explorer.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 <Basics_OCCTVersion.hxx>
46 #if OCC_VERSION_LARGE < 0x07070000
47 #include <BRepAdaptor_HSurface.hxx>
49 #include <BRepAdaptor_Surface.hxx>
52 #include <BRep_Builder.hxx>
53 #include <BRepGProp.hxx>
54 #include <BRep_Tool.hxx>
55 #include <BRepPrimAPI_MakeSphere.hxx>
56 #include <BRepPrimAPI_MakeBox.hxx>
57 #include <BRepBuilderAPI_MakeFace.hxx>
58 #include <BRepAlgoAPI_Cut.hxx>
60 #include <GeomPlate_Surface.hxx>
61 #include <GeomPlate_BuildPlateSurface.hxx>
62 #include <GeomPlate_PointConstraint.hxx>
63 #include <GeomPlate_MakeApprox.hxx>
64 #include <GeomPlate_PlateG0Criterion.hxx>
65 #include <GeomPlate_BuildAveragePlane.hxx>
67 #include <Geom_BSplineSurface.hxx>
68 #include <Geom_Surface.hxx>
69 #include <Geom_Plane.hxx>
71 #include <GProp_GProps.hxx>
72 #include <Bnd_Box.hxx>
73 #include <BRepBndLib.hxx>
81 #include <GC_MakePlane.hxx>
83 //=======================================================================
86 //=======================================================================
87 const Standard_GUID& AdvancedEngine_SmoothingSurfaceDriver::GetID()
89 static Standard_GUID aGUID("1C3A0F30-729D-4E83-8232-78E74FC5637C");
93 //=======================================================================
94 //function : AdvancedEngine_SmoothingSurfaceDriver
96 //=======================================================================
97 AdvancedEngine_SmoothingSurfaceDriver::AdvancedEngine_SmoothingSurfaceDriver()
101 //=======================================================================
102 //function : MakeSmoothingSurfaceUnClosed
104 //=======================================================================
105 TopoDS_Shape AdvancedEngine_SmoothingSurfaceDriver::MakeSmoothingSurfaceUnClosed
106 (const Handle(TColgp_HArray1OfPnt) &theListOfPoints,
107 const Standard_Integer theNbMax,
108 const Standard_Integer theDegMax,
109 const Standard_Real theDMax) const
111 TopoDS_Face aInitShape;
113 // Create an average Plane
114 //Handle(TColgp_HArray1OfPnt) HAP = new TColgp_HArray1OfPnt(1,theListOfPoints.Length())
115 GeomPlate_BuildAveragePlane gpbap(theListOfPoints,theListOfPoints->Length(),Precision::Confusion(),1,1);
116 Handle(Geom_Plane) plane(gpbap.Plane());
117 Standard_Real Umin, Umax, Vmin, Vmax;
118 gpbap.MinMaxBox(Umin,Umax,Vmin,Vmax);
119 // cout << "Vals : " << Umin << ", " << Umax << ", " << Vmin << ", " << Vmax << endl;
120 BRepBuilderAPI_MakeFace mf(plane,Umin,Umax,Vmin,Vmax,Precision::Confusion());
121 aInitShape = mf.Face();
124 GeomPlate_BuildPlateSurface aBuilder(3,10);
125 // ** Initialization of surface
126 #if OCC_VERSION_LARGE < 0x07070000
127 Handle(BRepAdaptor_HSurface) HSI = new BRepAdaptor_HSurface();
128 HSI->ChangeSurface().Initialize(aInitShape);
129 aBuilder.LoadInitSurface( BRep_Tool::Surface(HSI->ChangeSurface().Face()));
131 Handle(BRepAdaptor_Surface) HSI = new BRepAdaptor_Surface();
132 HSI->Initialize(aInitShape);
133 aBuilder.LoadInitSurface( BRep_Tool::Surface(HSI->Face()) );
136 Standard_Integer j, j1, j2;
137 // cout << "Init surface" << endl;
138 j1 = theListOfPoints->Lower();
139 j2 = theListOfPoints->Upper();
140 for (j=j1; j<=j2 ; j++)
142 gp_Pnt aPnt = theListOfPoints->Value(j);
143 Handle(GeomPlate_PointConstraint) PCont = new GeomPlate_PointConstraint(aPnt,0);
146 // cout << "avant Perform surface" << endl;
148 // cout << "Perform surface" << endl;
150 // A ce niveau : surface algo
151 Handle(GeomPlate_Surface) gpPlate = aBuilder.Surface();
153 Standard_Integer nbcarreau = (theNbMax > 0 ? theNbMax : 2);
154 Standard_Integer degmax = (theDegMax > 0 ? theDegMax : 8);
155 Standard_Real seuil = theDMax;
158 seuil = Max(0.0001,10*aBuilder.G0Error());
161 GeomPlate_MakeApprox Mapp(gpPlate,0.0001,nbcarreau,degmax,seuil);
162 // cout << "Approx surface" << endl;
164 Handle (Geom_Surface) Surf (Mapp.Surface());
166 aBuilder.Surface()->Bounds( Umin, Umax, Vmin, Vmax);
168 BRepBuilderAPI_MakeFace MF(Surf,Umin, Umax, Vmin, Vmax, Precision::Confusion());
169 TopoDS_Shape aShape = MF.Shape();
175 //=======================================================================
178 //=======================================================================
179 Standard_Integer AdvancedEngine_SmoothingSurfaceDriver::Execute(Handle(TFunction_Logbook)& log) const
181 if (Label().IsNull()) return 0;
182 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
183 if (aFunction.IsNull()) return 0;
185 Standard_Integer aType = aFunction->GetType();
187 if (aType != SMOOTHINGSURFACE_LPOINTS) return 0;
188 // cout << "Youhou : " << aType << endl;
190 AdvancedEngine_ISmoothingSurface aData (aFunction);
192 // Fill the map of vertices.
193 Standard_Integer aNbShapes = aData.GetLength();
194 TopTools_MapOfShape aMapPoints;
197 for (i = 1; i <= aNbShapes; i++) {
198 Handle(GEOM_Function) aFShape = aData.GetPntOrComp(i);
199 TopoDS_Shape aShape = aFShape->GetValue();
201 if (aShape.ShapeType() == TopAbs_VERTEX) {
202 aMapPoints.Add(aShape);
204 TopExp_Explorer anExp(aShape, TopAbs_VERTEX);
206 for (; anExp.More(); anExp.Next()) {
207 aMapPoints.Add(anExp.Current());
212 // Add points to the array of points.
213 const Standard_Integer aNbPoints = aMapPoints.Extent();
214 Handle(TColgp_HArray1OfPnt) anArrayofPnt =
215 new TColgp_HArray1OfPnt(1, aNbPoints);
216 TopTools_MapIteratorOfMapOfShape anIter(aMapPoints);
218 for (i = 1; anIter.More(); anIter.Next(), i++) {
219 TopoDS_Vertex aPoint = TopoDS::Vertex(anIter.Key());
220 gp_Pnt aPnt = BRep_Tool::Pnt(aPoint);
222 anArrayofPnt->SetValue(i, aPnt);
225 const Standard_Integer aNbMax = aData.GetNbMax();
226 const Standard_Integer aDegMax = aData.GetDegMax();
227 const Standard_Real aDMax = aData.GetDMax();
229 // Make smoothing surface.
230 TopoDS_Shape aShape = AdvancedEngine_SmoothingSurfaceDriver::
231 MakeSmoothingSurfaceUnClosed(anArrayofPnt, aNbMax, aDegMax, aDMax);
233 if (aShape.IsNull()) return 0;
235 aFunction->SetValue(aShape);
237 log->SetTouched(Label());
242 //================================================================================
244 * \brief Returns a name of creation operation and names and values of creation parameters
246 //================================================================================
248 bool AdvancedEngine_SmoothingSurfaceDriver::
249 GetCreationInformation(std::string& theOperationName,
250 std::vector<GEOM_Param>& theParams)
252 if (Label().IsNull()) return 0;
253 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
255 AdvancedEngine_ISmoothingSurface aCI( function );
256 Standard_Integer aType = function->GetType();
258 theOperationName = "SMOOTHINGSURFACE";
261 case SMOOTHINGSURFACE_LPOINTS:
263 AddParam( theParams, "Points" );
264 if ( aCI.GetLength() > 1 )
265 theParams[0] << aCI.GetLength() << " points: ";
266 for ( int i = 1, nb = aCI.GetLength(); i <= nb; ++i )
267 theParams[0] << aCI.GetPntOrComp( i ) << " ";
269 AddParam(theParams, "Max nbr of Bezier pieces", aCI.GetNbMax());
270 AddParam(theParams, "Max BSpline surface degree", aCI.GetDegMax());
271 AddParam(theParams, "3D tolerance of initial approximation", aCI.GetDMax());
281 IMPLEMENT_STANDARD_RTTIEXT (AdvancedEngine_SmoothingSurfaceDriver,GEOM_BaseDriver)