]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/INTERP_KERNEL/InterpolationOptions.cxx
Salome HOME
Refactoring QuadraticPlanar precision tuning. Fixes intersector bugs.
[tools/medcoupling.git] / src / INTERP_KERNEL / InterpolationOptions.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #include "InterpolationOptions.hxx"
22 #include "InterpKernelGeo2DPrecision.hxx"
23 #include "InterpKernelException.hxx"
24
25 #include <sstream>
26
27 const double INTERP_KERNEL::InterpolationOptions::DFT_MEDIAN_PLANE=0.5;
28
29 const double INTERP_KERNEL::InterpolationOptions::DFT_SURF3D_ADJ_EPS=1.e-4;
30
31 const double INTERP_KERNEL::InterpolationOptions::DFT_MAX_DIST_3DSURF_INTERSECT=-1.;
32
33 const double INTERP_KERNEL::InterpolationOptions::DFT_MIN_DOT_BTW_3DSURF_INTERSECT=-1.;
34
35 const char INTERP_KERNEL::InterpolationOptions::PRECISION_STR[]="Precision";
36
37 const char INTERP_KERNEL::InterpolationOptions::ARC_DETECTION_PRECISION_STR[]="ArcDetectionPrecision";
38
39 const char INTERP_KERNEL::InterpolationOptions::MEDIANE_PLANE_STR[]="MedianPlane";
40
41 const char INTERP_KERNEL::InterpolationOptions::BOUNDING_BOX_ADJ_STR[]="BoundingBoxAdjustment";
42
43 const char INTERP_KERNEL::InterpolationOptions::BOUNDING_BOX_ADJ_ABS_STR[]="BoundingBoxAdjustmentAbs";
44
45 const char INTERP_KERNEL::InterpolationOptions::MAX_DISTANCE_3DSURF_INSECT_STR[]="MaxDistance3DSurfIntersect";
46
47 const char INTERP_KERNEL::InterpolationOptions::MIN_DOT_BTW_3DSURF_INSECT_STR[]="MinDotBetween3DSurfIntersect";
48
49 const char INTERP_KERNEL::InterpolationOptions::PRINT_LEV_STR[]="PrintLevel";
50
51 const char INTERP_KERNEL::InterpolationOptions::DO_ROTATE_STR[]="DoRotate";
52
53 const char INTERP_KERNEL::InterpolationOptions::ORIENTATION_STR[]="Orientation";
54
55 const char INTERP_KERNEL::InterpolationOptions::MEASURE_ABS_STR[]="MeasureAbs";
56
57 const char INTERP_KERNEL::InterpolationOptions::INTERSEC_TYPE_STR[]="IntersectionType";
58
59 const char INTERP_KERNEL::InterpolationOptions::SPLITTING_POLICY_STR[]="SplittingPolicy";
60
61 const char INTERP_KERNEL::InterpolationOptions::TRIANGULATION_INTERSECT2D_STR[]="Triangulation";
62
63 const char INTERP_KERNEL::InterpolationOptions::CONVEX_INTERSECT2D_STR[]="Convex";
64
65 const char INTERP_KERNEL::InterpolationOptions::GEOMETRIC_INTERSECT2D_STR[]="Geometric2D";
66
67 const char INTERP_KERNEL::InterpolationOptions::POINTLOCATOR_INTERSECT_STR[]="PointLocator";
68
69 const char INTERP_KERNEL::InterpolationOptions::BARYCENTRIC_INTERSECT_STR[]="Barycentric";
70
71 const char INTERP_KERNEL::InterpolationOptions::BARYCENTRICGEO2D_INTERSECT_STR[]="BarycentricGeo2D";
72
73 const char INTERP_KERNEL::InterpolationOptions::PLANAR_SPLIT_FACE_5_STR[]="PLANAR_FACE_5";
74
75 const char INTERP_KERNEL::InterpolationOptions::PLANAR_SPLIT_FACE_6_STR[]="PLANAR_FACE_6";
76
77 const char INTERP_KERNEL::InterpolationOptions::GENERAL_SPLIT_24_STR[]="GENERAL_24";
78
79 const char INTERP_KERNEL::InterpolationOptions::GENERAL_SPLIT_48_STR[]="GENERAL_48";
80
81 void INTERP_KERNEL::InterpolationOptions::init()
82 {
83   _print_level=0;
84   _intersection_type=Triangulation;
85   _precision=1e-12;
86   _median_plane=DFT_MEDIAN_PLANE;
87   _do_rotate=true;
88   _bounding_box_adjustment=DFT_SURF3D_ADJ_EPS;
89   _bounding_box_adjustment_abs=0.;
90   _max_distance_for_3Dsurf_intersect=DFT_MAX_DIST_3DSURF_INTERSECT;
91   _min_dot_btw_3Dsurf_intersect=DFT_MIN_DOT_BTW_3DSURF_INTERSECT;
92   _orientation=0;
93   _measure_abs=true;
94   _splitting_policy=PLANAR_FACE_5;
95 }
96
97 double INTERP_KERNEL::InterpolationOptions::getArcDetectionPrecision() const
98 {
99   return INTERP_KERNEL::QuadraticPlanarArcDetectionPrecision::getArcDetectionPrecision();
100 }
101
102 void INTERP_KERNEL::InterpolationOptions::setArcDetectionPrecision(double p)
103 {
104   INTERP_KERNEL::QuadraticPlanarArcDetectionPrecision::setArcDetectionPrecision(p);
105 }
106
107 std::string INTERP_KERNEL::InterpolationOptions::getIntersectionTypeRepr() const
108 {
109   if(_intersection_type==INTERP_KERNEL::Triangulation)
110     return std::string(TRIANGULATION_INTERSECT2D_STR);
111   else if(_intersection_type==INTERP_KERNEL::Convex)
112     return std::string(CONVEX_INTERSECT2D_STR);
113   else if(_intersection_type==INTERP_KERNEL::Geometric2D)
114     return std::string(GEOMETRIC_INTERSECT2D_STR);
115   else if(_intersection_type==INTERP_KERNEL::PointLocator)
116     return std::string(POINTLOCATOR_INTERSECT_STR);
117   else if(_intersection_type==INTERP_KERNEL::Barycentric)
118     return std::string(BARYCENTRIC_INTERSECT_STR);
119   else if(_intersection_type==INTERP_KERNEL::BarycentricGeo2D)
120     return std::string(BARYCENTRICGEO2D_INTERSECT_STR);
121   else
122     return std::string("UNKNOWN_INTERSECT_TYPE");
123 }
124
125 bool INTERP_KERNEL::InterpolationOptions::setOptionDouble(const std::string& key, double value)
126 {
127   if(key==PRECISION_STR) 
128     {
129       setPrecision(value);
130       return true;
131     }
132   if(key==ARC_DETECTION_PRECISION_STR)
133     {
134       setArcDetectionPrecision(value);
135       return true;
136     }
137   else if(key==MEDIANE_PLANE_STR) 
138     {
139       setMedianPlane(value);
140       return true;
141     }
142   else if(key==BOUNDING_BOX_ADJ_STR) 
143     {
144       setBoundingBoxAdjustment(value);
145       return true;
146     }
147   else if(key==BOUNDING_BOX_ADJ_ABS_STR) 
148     {
149       setBoundingBoxAdjustmentAbs(value);
150       return true;
151     }
152   else if(key==MAX_DISTANCE_3DSURF_INSECT_STR) 
153     {
154       setMaxDistance3DSurfIntersect(value);
155       return true;
156     }
157   else if(key==MIN_DOT_BTW_3DSURF_INSECT_STR)
158     {
159       setMinDotBtwPlane3DSurfIntersect(value);
160       return true;
161     }
162   else
163     return false;
164 }
165
166 bool INTERP_KERNEL::InterpolationOptions::setOptionInt(const std::string& key, int value)
167 {
168   if(key==PRINT_LEV_STR) 
169     {
170       setPrintLevel(value);
171       return true;
172     }
173     else if(key==DO_ROTATE_STR) 
174       {
175         setDoRotate(value != 0);
176         return true;
177       }
178     else if(key==ORIENTATION_STR) 
179       {
180         setOrientation(value);
181         return true;
182       }
183     else if(key==MEASURE_ABS_STR)
184       {
185         bool valBool=(value!=0);
186         setMeasureAbsStatus(valBool);
187         return true;
188       }
189     else
190       return false;
191 }
192
193 bool INTERP_KERNEL::InterpolationOptions::setOptionString(const std::string& key, const std::string& value)
194 {
195   if(key==INTERSEC_TYPE_STR) 
196     {
197       if(value==TRIANGULATION_INTERSECT2D_STR)
198         {
199           setIntersectionType(INTERP_KERNEL::Triangulation);
200           return true;
201         }
202       else if(value==CONVEX_INTERSECT2D_STR)
203         {
204           setIntersectionType(INTERP_KERNEL::Convex);
205           return true;
206         }
207       else if(value==GEOMETRIC_INTERSECT2D_STR)
208         {
209           setIntersectionType(INTERP_KERNEL::Geometric2D);
210           return true;
211         }
212       else if(value==POINTLOCATOR_INTERSECT_STR)
213         {
214           setIntersectionType(INTERP_KERNEL::PointLocator);
215           return true;
216         }
217       else if(value==BARYCENTRIC_INTERSECT_STR)
218         {
219           setIntersectionType(INTERP_KERNEL::Barycentric);
220           return true;
221         }
222       else if(value==BARYCENTRICGEO2D_INTERSECT_STR)
223         {
224           setIntersectionType(INTERP_KERNEL::BarycentricGeo2D);
225           return true;
226         }
227     }
228   else if(key==SPLITTING_POLICY_STR) 
229     {
230       if(value==PLANAR_SPLIT_FACE_5_STR)
231         {
232           setSplittingPolicy(INTERP_KERNEL::PLANAR_FACE_5);
233           return true;
234         }
235       else if(value==PLANAR_SPLIT_FACE_6_STR)
236         {
237           setSplittingPolicy(INTERP_KERNEL::PLANAR_FACE_6);
238           return true;
239         }
240       else if(value==GENERAL_SPLIT_24_STR)
241         {
242           setSplittingPolicy(INTERP_KERNEL::GENERAL_24);
243           return true;
244         }
245       else if(value==GENERAL_SPLIT_48_STR)
246         {
247           setSplittingPolicy(INTERP_KERNEL::GENERAL_48);
248           return true;
249         }
250       else
251         return false;
252     }
253   return false;
254 }
255
256 std::string INTERP_KERNEL::InterpolationOptions::getSplittingPolicyRepr() const
257 {
258   if(_splitting_policy==INTERP_KERNEL::PLANAR_FACE_5)
259     return std::string(PLANAR_SPLIT_FACE_5_STR);
260   else if(_splitting_policy==INTERP_KERNEL::PLANAR_FACE_6)
261     return std::string(PLANAR_SPLIT_FACE_6_STR);
262   else if(_splitting_policy==INTERP_KERNEL::GENERAL_24)
263     return std::string(GENERAL_SPLIT_24_STR);
264   else if(_splitting_policy==INTERP_KERNEL::GENERAL_48)
265     return std::string(GENERAL_SPLIT_48_STR);
266   else
267     return std::string("UNKNOWN_SPLITTING_POLICY");
268 }
269
270 std::string INTERP_KERNEL::InterpolationOptions::filterInterpolationMethod(const std::string& meth) const
271 {
272   return std::string(meth);
273 }
274
275 bool INTERP_KERNEL::InterpolationOptions::setInterpolationOptions(long print_level,
276                                                                   std::string intersection_type,
277                                                                   double precision,
278                                                                   double median_plane,
279                                                                   bool do_rotate,
280                                                                   double bounding_box_adjustment,
281                                                                   double bounding_box_adjustment_abs,
282                                                                   double max_distance_for_3Dsurf_intersect,
283                                                                   long orientation,
284                                                                   bool measure_abs,
285                                                                   std::string splitting_policy)
286 {
287   _print_level=print_level;
288   _precision=precision;
289   _median_plane=median_plane;
290   _do_rotate=do_rotate;
291   _bounding_box_adjustment=bounding_box_adjustment;
292   _bounding_box_adjustment_abs=bounding_box_adjustment_abs;
293   _max_distance_for_3Dsurf_intersect=max_distance_for_3Dsurf_intersect;
294   _orientation=orientation;
295   _measure_abs=measure_abs;
296   return(setOptionString(INTERSEC_TYPE_STR,intersection_type) && setOptionString(SPLITTING_POLICY_STR,splitting_policy));
297 }
298
299 std::string INTERP_KERNEL::InterpolationOptions::printOptions() const
300 {
301   std::ostringstream oss; oss.precision(15); oss << "Interpolation Options ******" << std::endl;
302   oss << "Print level : " << _print_level << std::endl;
303   oss << "Intersection type : " << getIntersectionTypeRepr() << std::endl;
304   oss << "Precision : " << _precision << std::endl;
305   oss << "Arc Detection Precision : " << getArcDetectionPrecision() << std::endl;
306   oss << "Median plane : " << _median_plane << std::endl;
307   oss << "Do Rotate status : " << std::boolalpha << _do_rotate << std::endl;
308   oss << "Bounding box adj : " << _bounding_box_adjustment << std::endl;
309   oss << "Bounding box adj abs : " << _bounding_box_adjustment_abs << std::endl;
310   oss << "Max distance for 3DSurf intersect : " << _max_distance_for_3Dsurf_intersect << std::endl;
311   oss << "Min dot between plane for 3DSurf intersect : " << _min_dot_btw_3Dsurf_intersect << std::endl;
312   oss << "Orientation : " << _orientation << std::endl;
313   oss << "Measure abs : " << _measure_abs << std::endl;
314   oss << "Splitting policy : " << getSplittingPolicyRepr() << std::endl;
315   oss << "****************************" << std::endl;
316   return oss.str();
317 }
318
319 void INTERP_KERNEL::InterpolationOptions::CheckAndSplitInterpolationMethod(const std::string& method, std::string& srcMeth, std::string& trgMeth)
320 {
321   const int NB_OF_METH_MANAGED=4;
322   const char *METH_MANAGED[NB_OF_METH_MANAGED]={"P0P0","P0P1","P1P0","P1P1"};
323   bool found=false;
324   for(int i=0;i<NB_OF_METH_MANAGED && !found;i++)
325     found=(method==METH_MANAGED[i]);
326   if(!found)
327     {
328       std::string msg("The interpolation method : \'"); msg+=method; msg+="\' not managed by INTERP_KERNEL interpolators ! Supported are \"P0P0\", \"P0P1\", \"P1P0\" and \"P1P1\".";
329       throw INTERP_KERNEL::Exception(msg.c_str());
330     }
331   srcMeth=method.substr(0,2);
332   trgMeth=method.substr(2);
333 }