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