1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
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.
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 "InterpKernelException.hxx"
26 const double INTERP_KERNEL::InterpolationOptions::DFT_MEDIAN_PLANE=0.5;
28 const double INTERP_KERNEL::InterpolationOptions::DFT_SURF3D_ADJ_EPS=1.e-4;
30 const double INTERP_KERNEL::InterpolationOptions::DFT_MAX_DIST_3DSURF_INTERSECT=-1.;
32 const char INTERP_KERNEL::InterpolationOptions::PRECISION_STR[]="Precision";
34 const char INTERP_KERNEL::InterpolationOptions::MEDIANE_PLANE_STR[]="MedianPlane";
36 const char INTERP_KERNEL::InterpolationOptions::BOUNDING_BOX_ADJ_STR[]="BoundingBoxAdjustment";
38 const char INTERP_KERNEL::InterpolationOptions::BOUNDING_BOX_ADJ_ABS_STR[]="BoundingBoxAdjustmentAbs";
40 const char INTERP_KERNEL::InterpolationOptions::MAX_DISTANCE_3DSURF_INSECT_STR[]="MaxDistance3DSurfIntersect";
42 const char INTERP_KERNEL::InterpolationOptions::PRINT_LEV_STR[]="PrintLevel";
44 const char INTERP_KERNEL::InterpolationOptions::DO_ROTATE_STR[]="DoRotate";
46 const char INTERP_KERNEL::InterpolationOptions::ORIENTATION_STR[]="Orientation";
48 const char INTERP_KERNEL::InterpolationOptions::MEASURE_ABS_STR[]="MeasureAbs";
50 const char INTERP_KERNEL::InterpolationOptions::INTERSEC_TYPE_STR[]="IntersectionType";
52 const char INTERP_KERNEL::InterpolationOptions::SPLITTING_POLICY_STR[]="SplittingPolicy";
54 const char INTERP_KERNEL::InterpolationOptions::TRIANGULATION_INTERSECT2D_STR[]="Triangulation";
56 const char INTERP_KERNEL::InterpolationOptions::CONVEX_INTERSECT2D_STR[]="Convex";
58 const char INTERP_KERNEL::InterpolationOptions::GEOMETRIC_INTERSECT2D_STR[]="Geometric2D";
60 const char INTERP_KERNEL::InterpolationOptions::POINTLOCATOR_INTERSECT_STR[]="PointLocator";
62 const char INTERP_KERNEL::InterpolationOptions::BARYCENTRIC_INTERSECT_STR[]="Barycentric";
64 const char INTERP_KERNEL::InterpolationOptions::BARYCENTRICGEO2D_INTERSECT_STR[]="BarycentricGeo2D";
66 const char INTERP_KERNEL::InterpolationOptions::PLANAR_SPLIT_FACE_5_STR[]="PLANAR_FACE_5";
68 const char INTERP_KERNEL::InterpolationOptions::PLANAR_SPLIT_FACE_6_STR[]="PLANAR_FACE_6";
70 const char INTERP_KERNEL::InterpolationOptions::GENERAL_SPLIT_24_STR[]="GENERAL_24";
72 const char INTERP_KERNEL::InterpolationOptions::GENERAL_SPLIT_48_STR[]="GENERAL_48";
74 void INTERP_KERNEL::InterpolationOptions::init()
77 _intersection_type=Triangulation;
79 _median_plane=DFT_MEDIAN_PLANE;
81 _bounding_box_adjustment=DFT_SURF3D_ADJ_EPS;
82 _bounding_box_adjustment_abs=0.;
83 _max_distance_for_3Dsurf_intersect=DFT_MAX_DIST_3DSURF_INTERSECT;
86 _splitting_policy=PLANAR_FACE_5;
89 std::string INTERP_KERNEL::InterpolationOptions::getIntersectionTypeRepr() const
91 if(_intersection_type==INTERP_KERNEL::Triangulation)
92 return std::string(TRIANGULATION_INTERSECT2D_STR);
93 else if(_intersection_type==INTERP_KERNEL::Convex)
94 return std::string(CONVEX_INTERSECT2D_STR);
95 else if(_intersection_type==INTERP_KERNEL::Geometric2D)
96 return std::string(GEOMETRIC_INTERSECT2D_STR);
97 else if(_intersection_type==INTERP_KERNEL::PointLocator)
98 return std::string(POINTLOCATOR_INTERSECT_STR);
99 else if(_intersection_type==INTERP_KERNEL::Barycentric)
100 return std::string(BARYCENTRIC_INTERSECT_STR);
101 else if(_intersection_type==INTERP_KERNEL::BarycentricGeo2D)
102 return std::string(BARYCENTRICGEO2D_INTERSECT_STR);
104 return std::string("UNKNOWN_INTERSECT_TYPE");
107 bool INTERP_KERNEL::InterpolationOptions::setOptionDouble(const std::string& key, double value)
109 if(key==PRECISION_STR)
114 else if(key==MEDIANE_PLANE_STR)
116 setMedianPlane(value);
119 else if(key==BOUNDING_BOX_ADJ_STR)
121 setBoundingBoxAdjustment(value);
124 else if(key==BOUNDING_BOX_ADJ_ABS_STR)
126 setBoundingBoxAdjustmentAbs(value);
129 else if(key==MAX_DISTANCE_3DSURF_INSECT_STR)
131 setMaxDistance3DSurfIntersect(value);
138 bool INTERP_KERNEL::InterpolationOptions::setOptionInt(const std::string& key, int value)
140 if(key==PRINT_LEV_STR)
142 setPrintLevel(value);
145 else if(key==DO_ROTATE_STR)
147 setDoRotate(value != 0);
150 else if(key==ORIENTATION_STR)
152 setOrientation(value);
155 else if(key==MEASURE_ABS_STR)
157 bool valBool=(value!=0);
158 setMeasureAbsStatus(valBool);
165 bool INTERP_KERNEL::InterpolationOptions::setOptionString(const std::string& key, const std::string& value)
167 if(key==INTERSEC_TYPE_STR)
169 if(value==TRIANGULATION_INTERSECT2D_STR)
171 setIntersectionType(INTERP_KERNEL::Triangulation);
174 else if(value==CONVEX_INTERSECT2D_STR)
176 setIntersectionType(INTERP_KERNEL::Convex);
179 else if(value==GEOMETRIC_INTERSECT2D_STR)
181 setIntersectionType(INTERP_KERNEL::Geometric2D);
184 else if(value==POINTLOCATOR_INTERSECT_STR)
186 setIntersectionType(INTERP_KERNEL::PointLocator);
189 else if(value==BARYCENTRIC_INTERSECT_STR)
191 setIntersectionType(INTERP_KERNEL::Barycentric);
194 else if(value==BARYCENTRICGEO2D_INTERSECT_STR)
196 setIntersectionType(INTERP_KERNEL::BarycentricGeo2D);
200 else if(key==SPLITTING_POLICY_STR)
202 if(value==PLANAR_SPLIT_FACE_5_STR)
204 setSplittingPolicy(INTERP_KERNEL::PLANAR_FACE_5);
207 else if(value==PLANAR_SPLIT_FACE_6_STR)
209 setSplittingPolicy(INTERP_KERNEL::PLANAR_FACE_6);
212 else if(value==GENERAL_SPLIT_24_STR)
214 setSplittingPolicy(INTERP_KERNEL::GENERAL_24);
217 else if(value==GENERAL_SPLIT_48_STR)
219 setSplittingPolicy(INTERP_KERNEL::GENERAL_48);
228 std::string INTERP_KERNEL::InterpolationOptions::getSplittingPolicyRepr() const
230 if(_splitting_policy==INTERP_KERNEL::PLANAR_FACE_5)
231 return std::string(PLANAR_SPLIT_FACE_5_STR);
232 else if(_splitting_policy==INTERP_KERNEL::PLANAR_FACE_6)
233 return std::string(PLANAR_SPLIT_FACE_6_STR);
234 else if(_splitting_policy==INTERP_KERNEL::GENERAL_24)
235 return std::string(GENERAL_SPLIT_24_STR);
236 else if(_splitting_policy==INTERP_KERNEL::GENERAL_48)
237 return std::string(GENERAL_SPLIT_48_STR);
239 return std::string("UNKNOWN_SPLITTING_POLICY");
242 std::string INTERP_KERNEL::InterpolationOptions::filterInterpolationMethod(const std::string& meth) const
244 return std::string(meth);
247 bool INTERP_KERNEL::InterpolationOptions::setInterpolationOptions(long print_level,
248 std::string intersection_type,
252 double bounding_box_adjustment,
253 double bounding_box_adjustment_abs,
254 double max_distance_for_3Dsurf_intersect,
257 std::string splitting_policy)
259 _print_level=print_level;
260 _precision=precision;
261 _median_plane=median_plane;
262 _do_rotate=do_rotate;
263 _bounding_box_adjustment=bounding_box_adjustment;
264 _bounding_box_adjustment_abs=bounding_box_adjustment_abs;
265 _max_distance_for_3Dsurf_intersect=max_distance_for_3Dsurf_intersect;
266 _orientation=orientation;
267 _measure_abs=measure_abs;
268 return(setOptionString(INTERSEC_TYPE_STR,intersection_type) && setOptionString(SPLITTING_POLICY_STR,splitting_policy));
271 std::string INTERP_KERNEL::InterpolationOptions::printOptions() const
273 std::ostringstream oss; oss.precision(15); oss << "Interpolation Options ******" << std::endl;
274 oss << "Print level : " << _print_level << std::endl;
275 oss << "Intersection type : " << getIntersectionTypeRepr() << std::endl;
276 oss << "Precision : " << _precision << std::endl;
277 oss << "Median plane : " << _median_plane << std::endl;
278 oss << "Do Rotate status : " << std::boolalpha << _do_rotate << std::endl;
279 oss << "Bounding box adj : " << _bounding_box_adjustment << std::endl;
280 oss << "Bounding box adj abs : " << _bounding_box_adjustment_abs << std::endl;
281 oss << "Max distance for 3DSurf intersect : " << _max_distance_for_3Dsurf_intersect << std::endl;
282 oss << "Orientation : " << _orientation << std::endl;
283 oss << "Measure abs : " << _measure_abs << std::endl;
284 oss << "Splitting policy : " << getSplittingPolicyRepr() << std::endl;
285 oss << "****************************" << std::endl;
289 void INTERP_KERNEL::InterpolationOptions::CheckAndSplitInterpolationMethod(const std::string& method, std::string& srcMeth, std::string& trgMeth)
291 const int NB_OF_METH_MANAGED=4;
292 const char *METH_MANAGED[NB_OF_METH_MANAGED]={"P0P0","P0P1","P1P0","P1P1"};
294 for(int i=0;i<NB_OF_METH_MANAGED && !found;i++)
295 found=(method==METH_MANAGED[i]);
298 std::string msg("The interpolation method : \'"); msg+=method; msg+="\' not managed by INTERP_KERNEL interpolators ! Supported are \"P0P0\", \"P0P1\", \"P1P0\" and \"P1P1\".";
299 throw INTERP_KERNEL::Exception(msg.c_str());
301 srcMeth=method.substr(0,2);
302 trgMeth=method.substr(2);