1 // Copyright (C) 2007-2024 CEA, EDF
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
19 // Author : Anthony Geay (CEA/DEN)
21 #include "InterpolationOptions.hxx"
22 #include "InterpKernelGeo2DPrecision.hxx"
23 #include "InterpKernelException.hxx"
27 const double INTERP_KERNEL::InterpolationOptions::DFT_MEDIAN_PLANE=0.5;
29 const double INTERP_KERNEL::InterpolationOptions::DFT_SURF3D_ADJ_EPS=1.e-4;
31 const double INTERP_KERNEL::InterpolationOptions::DFT_MAX_DIST_3DSURF_INTERSECT=-1.;
33 const double INTERP_KERNEL::InterpolationOptions::DFT_MIN_DOT_BTW_3DSURF_INTERSECT=-1.;
35 const char INTERP_KERNEL::InterpolationOptions::PRECISION_STR[]="Precision";
37 const char INTERP_KERNEL::InterpolationOptions::MEDIANE_PLANE_STR[]="MedianPlane";
39 const char INTERP_KERNEL::InterpolationOptions::BOUNDING_BOX_ADJ_STR[]="BoundingBoxAdjustment";
41 const char INTERP_KERNEL::InterpolationOptions::BOUNDING_BOX_ADJ_ABS_STR[]="BoundingBoxAdjustmentAbs";
43 const char INTERP_KERNEL::InterpolationOptions::MAX_DISTANCE_3DSURF_INSECT_STR[]="MaxDistance3DSurfIntersect";
45 const char INTERP_KERNEL::InterpolationOptions::MIN_DOT_BTW_3DSURF_INSECT_STR[]="MinDotBetween3DSurfIntersect";
47 const char INTERP_KERNEL::InterpolationOptions::PRINT_LEV_STR[]="PrintLevel";
49 const char INTERP_KERNEL::InterpolationOptions::DO_ROTATE_STR[]="DoRotate";
51 const char INTERP_KERNEL::InterpolationOptions::ORIENTATION_STR[]="Orientation";
53 const char INTERP_KERNEL::InterpolationOptions::MEASURE_ABS_STR[]="MeasureAbs";
55 const char INTERP_KERNEL::InterpolationOptions::INTERSEC_TYPE_STR[]="IntersectionType";
57 const char INTERP_KERNEL::InterpolationOptions::SPLITTING_POLICY_STR[]="SplittingPolicy";
59 const char INTERP_KERNEL::InterpolationOptions::TRIANGULATION_INTERSECT2D_STR[]="Triangulation";
61 const char INTERP_KERNEL::InterpolationOptions::CONVEX_INTERSECT2D_STR[]="Convex";
63 const char INTERP_KERNEL::InterpolationOptions::GEOMETRIC_INTERSECT2D_STR[]="Geometric2D";
65 const char INTERP_KERNEL::InterpolationOptions::POINTLOCATOR_INTERSECT_STR[]="PointLocator";
67 const char INTERP_KERNEL::InterpolationOptions::BARYCENTRIC_INTERSECT_STR[]="Barycentric";
69 const char INTERP_KERNEL::InterpolationOptions::BARYCENTRICGEO2D_INTERSECT_STR[]="BarycentricGeo2D";
71 const char INTERP_KERNEL::InterpolationOptions::PLANAR_SPLIT_FACE_5_STR[]="PLANAR_FACE_5";
73 const char INTERP_KERNEL::InterpolationOptions::PLANAR_SPLIT_FACE_6_STR[]="PLANAR_FACE_6";
75 const char INTERP_KERNEL::InterpolationOptions::GENERAL_SPLIT_24_STR[]="GENERAL_24";
77 const char INTERP_KERNEL::InterpolationOptions::GENERAL_SPLIT_48_STR[]="GENERAL_48";
79 void INTERP_KERNEL::InterpolationOptions::init()
82 _intersection_type=Triangulation;
84 _median_plane=DFT_MEDIAN_PLANE;
86 _bounding_box_adjustment=DFT_SURF3D_ADJ_EPS;
87 _bounding_box_adjustment_abs=0.;
88 _max_distance_for_3Dsurf_intersect=DFT_MAX_DIST_3DSURF_INTERSECT;
89 _min_dot_btw_3Dsurf_intersect=DFT_MIN_DOT_BTW_3DSURF_INTERSECT;
92 _splitting_policy=PLANAR_FACE_5;
95 std::string INTERP_KERNEL::InterpolationOptions::getIntersectionTypeRepr() const
97 if(_intersection_type==INTERP_KERNEL::Triangulation)
98 return std::string(TRIANGULATION_INTERSECT2D_STR);
99 else if(_intersection_type==INTERP_KERNEL::Convex)
100 return std::string(CONVEX_INTERSECT2D_STR);
101 else if(_intersection_type==INTERP_KERNEL::Geometric2D)
102 return std::string(GEOMETRIC_INTERSECT2D_STR);
103 else if(_intersection_type==INTERP_KERNEL::PointLocator)
104 return std::string(POINTLOCATOR_INTERSECT_STR);
105 else if(_intersection_type==INTERP_KERNEL::Barycentric)
106 return std::string(BARYCENTRIC_INTERSECT_STR);
107 else if(_intersection_type==INTERP_KERNEL::BarycentricGeo2D)
108 return std::string(BARYCENTRICGEO2D_INTERSECT_STR);
110 return std::string("UNKNOWN_INTERSECT_TYPE");
113 bool INTERP_KERNEL::InterpolationOptions::setOptionDouble(const std::string& key, double value)
115 if(key==PRECISION_STR)
120 else if(key==MEDIANE_PLANE_STR)
122 setMedianPlane(value);
125 else if(key==BOUNDING_BOX_ADJ_STR)
127 setBoundingBoxAdjustment(value);
130 else if(key==BOUNDING_BOX_ADJ_ABS_STR)
132 setBoundingBoxAdjustmentAbs(value);
135 else if(key==MAX_DISTANCE_3DSURF_INSECT_STR)
137 setMaxDistance3DSurfIntersect(value);
140 else if(key==MIN_DOT_BTW_3DSURF_INSECT_STR)
142 setMinDotBtwPlane3DSurfIntersect(value);
149 bool INTERP_KERNEL::InterpolationOptions::setOptionInt(const std::string& key, int value)
151 if(key==PRINT_LEV_STR)
153 setPrintLevel(value);
156 else if(key==DO_ROTATE_STR)
158 setDoRotate(value != 0);
161 else if(key==ORIENTATION_STR)
163 setOrientation(value);
166 else if(key==MEASURE_ABS_STR)
168 bool valBool=(value!=0);
169 setMeasureAbsStatus(valBool);
176 bool INTERP_KERNEL::InterpolationOptions::setOptionString(const std::string& key, const std::string& value)
178 if(key==INTERSEC_TYPE_STR)
180 if(value==TRIANGULATION_INTERSECT2D_STR)
182 setIntersectionType(INTERP_KERNEL::Triangulation);
185 else if(value==CONVEX_INTERSECT2D_STR)
187 setIntersectionType(INTERP_KERNEL::Convex);
190 else if(value==GEOMETRIC_INTERSECT2D_STR)
192 setIntersectionType(INTERP_KERNEL::Geometric2D);
195 else if(value==POINTLOCATOR_INTERSECT_STR)
197 setIntersectionType(INTERP_KERNEL::PointLocator);
200 else if(value==BARYCENTRIC_INTERSECT_STR)
202 setIntersectionType(INTERP_KERNEL::Barycentric);
205 else if(value==BARYCENTRICGEO2D_INTERSECT_STR)
207 setIntersectionType(INTERP_KERNEL::BarycentricGeo2D);
211 else if(key==SPLITTING_POLICY_STR)
213 if(value==PLANAR_SPLIT_FACE_5_STR)
215 setSplittingPolicy(INTERP_KERNEL::PLANAR_FACE_5);
218 else if(value==PLANAR_SPLIT_FACE_6_STR)
220 setSplittingPolicy(INTERP_KERNEL::PLANAR_FACE_6);
223 else if(value==GENERAL_SPLIT_24_STR)
225 setSplittingPolicy(INTERP_KERNEL::GENERAL_24);
228 else if(value==GENERAL_SPLIT_48_STR)
230 setSplittingPolicy(INTERP_KERNEL::GENERAL_48);
239 std::string INTERP_KERNEL::InterpolationOptions::getSplittingPolicyRepr() const
241 if(_splitting_policy==INTERP_KERNEL::PLANAR_FACE_5)
242 return std::string(PLANAR_SPLIT_FACE_5_STR);
243 else if(_splitting_policy==INTERP_KERNEL::PLANAR_FACE_6)
244 return std::string(PLANAR_SPLIT_FACE_6_STR);
245 else if(_splitting_policy==INTERP_KERNEL::GENERAL_24)
246 return std::string(GENERAL_SPLIT_24_STR);
247 else if(_splitting_policy==INTERP_KERNEL::GENERAL_48)
248 return std::string(GENERAL_SPLIT_48_STR);
250 return std::string("UNKNOWN_SPLITTING_POLICY");
253 std::string INTERP_KERNEL::InterpolationOptions::filterInterpolationMethod(const std::string& meth) const
255 return std::string(meth);
258 bool INTERP_KERNEL::InterpolationOptions::setInterpolationOptions(int print_level,
259 std::string intersection_type,
263 double bounding_box_adjustment,
264 double bounding_box_adjustment_abs,
265 double max_distance_for_3Dsurf_intersect,
268 std::string splitting_policy)
270 _print_level=print_level;
271 _precision=precision;
272 _median_plane=median_plane;
273 _do_rotate=do_rotate;
274 _bounding_box_adjustment=bounding_box_adjustment;
275 _bounding_box_adjustment_abs=bounding_box_adjustment_abs;
276 _max_distance_for_3Dsurf_intersect=max_distance_for_3Dsurf_intersect;
277 _orientation=orientation;
278 _measure_abs=measure_abs;
279 return(setOptionString(INTERSEC_TYPE_STR,intersection_type) && setOptionString(SPLITTING_POLICY_STR,splitting_policy));
282 std::string INTERP_KERNEL::InterpolationOptions::printOptions() const
284 std::ostringstream oss; oss.precision(15); oss << "Interpolation Options ******" << std::endl;
285 oss << "Print level : " << _print_level << std::endl;
286 oss << "Intersection type : " << getIntersectionTypeRepr() << std::endl;
287 oss << "Precision : " << _precision << std::endl;
288 oss << "Median plane : " << _median_plane << std::endl;
289 oss << "Do Rotate status : " << std::boolalpha << _do_rotate << std::endl;
290 oss << "Bounding box adj : " << _bounding_box_adjustment << std::endl;
291 oss << "Bounding box adj abs : " << _bounding_box_adjustment_abs << std::endl;
292 oss << "Max distance for 3DSurf intersect : " << _max_distance_for_3Dsurf_intersect << std::endl;
293 oss << "Min dot between plane for 3DSurf intersect : " << _min_dot_btw_3Dsurf_intersect << std::endl;
294 oss << "Orientation : " << _orientation << std::endl;
295 oss << "Measure abs : " << _measure_abs << std::endl;
296 oss << "Splitting policy : " << getSplittingPolicyRepr() << std::endl;
297 oss << "****************************" << std::endl;
301 void INTERP_KERNEL::InterpolationOptions::CheckAndSplitInterpolationMethod(const std::string& method, std::string& srcMeth, std::string& trgMeth)
303 const int NB_OF_METH_MANAGED=4;
304 const char *METH_MANAGED[NB_OF_METH_MANAGED]={"P0P0","P0P1","P1P0","P1P1"};
306 for(int i=0;i<NB_OF_METH_MANAGED && !found;i++)
307 found=(method==METH_MANAGED[i]);
310 std::string msg("The interpolation method : \'"); msg+=method; msg+="\' not managed by INTERP_KERNEL interpolators ! Supported are \"P0P0\", \"P0P1\", \"P1P0\" and \"P1P1\".";
311 throw INTERP_KERNEL::Exception(msg.c_str());
313 srcMeth=method.substr(0,2);
314 trgMeth=method.substr(2);