Salome HOME
Copyright update 2021
[tools/medcoupling.git] / src / INTERP_KERNEL / InterpolationOptions.cxx
1 // Copyright (C) 2007-2021  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::MEDIANE_PLANE_STR[]="MedianPlane";
38
39 const char INTERP_KERNEL::InterpolationOptions::BOUNDING_BOX_ADJ_STR[]="BoundingBoxAdjustment";
40
41 const char INTERP_KERNEL::InterpolationOptions::BOUNDING_BOX_ADJ_ABS_STR[]="BoundingBoxAdjustmentAbs";
42
43 const char INTERP_KERNEL::InterpolationOptions::MAX_DISTANCE_3DSURF_INSECT_STR[]="MaxDistance3DSurfIntersect";
44
45 const char INTERP_KERNEL::InterpolationOptions::MIN_DOT_BTW_3DSURF_INSECT_STR[]="MinDotBetween3DSurfIntersect";
46
47 const char INTERP_KERNEL::InterpolationOptions::PRINT_LEV_STR[]="PrintLevel";
48
49 const char INTERP_KERNEL::InterpolationOptions::DO_ROTATE_STR[]="DoRotate";
50
51 const char INTERP_KERNEL::InterpolationOptions::ORIENTATION_STR[]="Orientation";
52
53 const char INTERP_KERNEL::InterpolationOptions::MEASURE_ABS_STR[]="MeasureAbs";
54
55 const char INTERP_KERNEL::InterpolationOptions::INTERSEC_TYPE_STR[]="IntersectionType";
56
57 const char INTERP_KERNEL::InterpolationOptions::SPLITTING_POLICY_STR[]="SplittingPolicy";
58
59 const char INTERP_KERNEL::InterpolationOptions::TRIANGULATION_INTERSECT2D_STR[]="Triangulation";
60
61 const char INTERP_KERNEL::InterpolationOptions::CONVEX_INTERSECT2D_STR[]="Convex";
62
63 const char INTERP_KERNEL::InterpolationOptions::GEOMETRIC_INTERSECT2D_STR[]="Geometric2D";
64
65 const char INTERP_KERNEL::InterpolationOptions::POINTLOCATOR_INTERSECT_STR[]="PointLocator";
66
67 const char INTERP_KERNEL::InterpolationOptions::BARYCENTRIC_INTERSECT_STR[]="Barycentric";
68
69 const char INTERP_KERNEL::InterpolationOptions::BARYCENTRICGEO2D_INTERSECT_STR[]="BarycentricGeo2D";
70
71 const char INTERP_KERNEL::InterpolationOptions::PLANAR_SPLIT_FACE_5_STR[]="PLANAR_FACE_5";
72
73 const char INTERP_KERNEL::InterpolationOptions::PLANAR_SPLIT_FACE_6_STR[]="PLANAR_FACE_6";
74
75 const char INTERP_KERNEL::InterpolationOptions::GENERAL_SPLIT_24_STR[]="GENERAL_24";
76
77 const char INTERP_KERNEL::InterpolationOptions::GENERAL_SPLIT_48_STR[]="GENERAL_48";
78
79 void INTERP_KERNEL::InterpolationOptions::init()
80 {
81   _print_level=0;
82   _intersection_type=Triangulation;
83   _precision=1e-12;
84   _median_plane=DFT_MEDIAN_PLANE;
85   _do_rotate=true;
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;
90   _orientation=0;
91   _measure_abs=true;
92   _splitting_policy=PLANAR_FACE_5;
93 }
94
95 std::string INTERP_KERNEL::InterpolationOptions::getIntersectionTypeRepr() const
96 {
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);
109   else
110     return std::string("UNKNOWN_INTERSECT_TYPE");
111 }
112
113 bool INTERP_KERNEL::InterpolationOptions::setOptionDouble(const std::string& key, double value)
114 {
115   if(key==PRECISION_STR) 
116     {
117       setPrecision(value);
118       return true;
119     }
120   else if(key==MEDIANE_PLANE_STR) 
121     {
122       setMedianPlane(value);
123       return true;
124     }
125   else if(key==BOUNDING_BOX_ADJ_STR) 
126     {
127       setBoundingBoxAdjustment(value);
128       return true;
129     }
130   else if(key==BOUNDING_BOX_ADJ_ABS_STR) 
131     {
132       setBoundingBoxAdjustmentAbs(value);
133       return true;
134     }
135   else if(key==MAX_DISTANCE_3DSURF_INSECT_STR) 
136     {
137       setMaxDistance3DSurfIntersect(value);
138       return true;
139     }
140   else if(key==MIN_DOT_BTW_3DSURF_INSECT_STR)
141     {
142       setMinDotBtwPlane3DSurfIntersect(value);
143       return true;
144     }
145   else
146     return false;
147 }
148
149 bool INTERP_KERNEL::InterpolationOptions::setOptionInt(const std::string& key, int value)
150 {
151   if(key==PRINT_LEV_STR) 
152     {
153       setPrintLevel(value);
154       return true;
155     }
156     else if(key==DO_ROTATE_STR) 
157       {
158         setDoRotate(value != 0);
159         return true;
160       }
161     else if(key==ORIENTATION_STR) 
162       {
163         setOrientation(value);
164         return true;
165       }
166     else if(key==MEASURE_ABS_STR)
167       {
168         bool valBool=(value!=0);
169         setMeasureAbsStatus(valBool);
170         return true;
171       }
172     else
173       return false;
174 }
175
176 bool INTERP_KERNEL::InterpolationOptions::setOptionString(const std::string& key, const std::string& value)
177 {
178   if(key==INTERSEC_TYPE_STR) 
179     {
180       if(value==TRIANGULATION_INTERSECT2D_STR)
181         {
182           setIntersectionType(INTERP_KERNEL::Triangulation);
183           return true;
184         }
185       else if(value==CONVEX_INTERSECT2D_STR)
186         {
187           setIntersectionType(INTERP_KERNEL::Convex);
188           return true;
189         }
190       else if(value==GEOMETRIC_INTERSECT2D_STR)
191         {
192           setIntersectionType(INTERP_KERNEL::Geometric2D);
193           return true;
194         }
195       else if(value==POINTLOCATOR_INTERSECT_STR)
196         {
197           setIntersectionType(INTERP_KERNEL::PointLocator);
198           return true;
199         }
200       else if(value==BARYCENTRIC_INTERSECT_STR)
201         {
202           setIntersectionType(INTERP_KERNEL::Barycentric);
203           return true;
204         }
205       else if(value==BARYCENTRICGEO2D_INTERSECT_STR)
206         {
207           setIntersectionType(INTERP_KERNEL::BarycentricGeo2D);
208           return true;
209         }
210     }
211   else if(key==SPLITTING_POLICY_STR) 
212     {
213       if(value==PLANAR_SPLIT_FACE_5_STR)
214         {
215           setSplittingPolicy(INTERP_KERNEL::PLANAR_FACE_5);
216           return true;
217         }
218       else if(value==PLANAR_SPLIT_FACE_6_STR)
219         {
220           setSplittingPolicy(INTERP_KERNEL::PLANAR_FACE_6);
221           return true;
222         }
223       else if(value==GENERAL_SPLIT_24_STR)
224         {
225           setSplittingPolicy(INTERP_KERNEL::GENERAL_24);
226           return true;
227         }
228       else if(value==GENERAL_SPLIT_48_STR)
229         {
230           setSplittingPolicy(INTERP_KERNEL::GENERAL_48);
231           return true;
232         }
233       else
234         return false;
235     }
236   return false;
237 }
238
239 std::string INTERP_KERNEL::InterpolationOptions::getSplittingPolicyRepr() const
240 {
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);
249   else
250     return std::string("UNKNOWN_SPLITTING_POLICY");
251 }
252
253 std::string INTERP_KERNEL::InterpolationOptions::filterInterpolationMethod(const std::string& meth) const
254 {
255   return std::string(meth);
256 }
257
258 bool INTERP_KERNEL::InterpolationOptions::setInterpolationOptions(int print_level,
259                                                                   std::string intersection_type,
260                                                                   double precision,
261                                                                   double median_plane,
262                                                                   bool do_rotate,
263                                                                   double bounding_box_adjustment,
264                                                                   double bounding_box_adjustment_abs,
265                                                                   double max_distance_for_3Dsurf_intersect,
266                                                                   int orientation,
267                                                                   bool measure_abs,
268                                                                   std::string splitting_policy)
269 {
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));
280 }
281
282 std::string INTERP_KERNEL::InterpolationOptions::printOptions() const
283 {
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;
298   return oss.str();
299 }
300
301 void INTERP_KERNEL::InterpolationOptions::CheckAndSplitInterpolationMethod(const std::string& method, std::string& srcMeth, std::string& trgMeth)
302 {
303   const int NB_OF_METH_MANAGED=4;
304   const char *METH_MANAGED[NB_OF_METH_MANAGED]={"P0P0","P0P1","P1P0","P1P1"};
305   bool found=false;
306   for(int i=0;i<NB_OF_METH_MANAGED && !found;i++)
307     found=(method==METH_MANAGED[i]);
308   if(!found)
309     {
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());
312     }
313   srcMeth=method.substr(0,2);
314   trgMeth=method.substr(2);
315 }