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