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