Salome HOME
885bb90ec2e98266c4411aca5286237fd0deae33
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_Hypothesis.hxx
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
20 // ---
21 // File    : BLSURFPlugin_Hypothesis.hxx
22 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
23 //           & Aurelien ALLEAUME (DISTENE)
24 //           Size maps developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
25 // ---
26 //
27 #ifndef _BLSURFPlugin_Hypothesis_HXX_
28 #define _BLSURFPlugin_Hypothesis_HXX_
29
30 #include "SMESH_Hypothesis.hxx"
31 #include <vector>
32 #include <map>
33 #include <set>
34 #include <stdexcept>
35 #include <string>
36 #include <cstring>
37 #include <sstream>
38 #include <utilities.h>
39 #include "BLSURFPlugin_Attractor.hxx"
40
41 //  Parameters for work of BLSURF
42
43 class BLSURFPlugin_Hypothesis: public SMESH_Hypothesis
44 {
45 public:
46   BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen);
47
48   enum Topology {
49     FromCAD,
50     Process,
51     Process2,
52     PreCAD
53   };
54
55   enum PhysicalMesh {
56     DefaultSize,
57     PhysicalGlobalSize,
58     PhysicalLocalSize
59   };
60
61   enum GeometricMesh {
62     DefaultGeom,
63     GeometricalGlobalSize,
64     GeometricalLocalSize
65   };
66
67   static const char* GetHypType() { return "BLSURF_Parameters"; }
68   
69   TopoDS_Shape entryToShape(std::string entry);
70
71   void SetPhysicalMesh(PhysicalMesh thePhysicalMesh);
72   PhysicalMesh GetPhysicalMesh() const { return _physicalMesh; }
73
74   void SetGeometricMesh(GeometricMesh theGeometricMesh);
75   GeometricMesh GetGeometricMesh() const { return _geometricMesh; }
76
77   void SetPhySize(double thePhySize, bool isRelative = false);
78   double GetPhySize() const { return _phySize; }
79   bool IsPhySizeRel() const { return _phySizeRel; }
80
81   void SetMinSize(double theMinSize, bool isRelative = false);
82   double GetMinSize() const { return _minSize; }
83   bool IsMinSizeRel() const { return _minSizeRel; }
84
85   void SetMaxSize(double theMaxSize, bool isRelative = false);
86   double GetMaxSize() const { return _maxSize; }
87   bool IsMaxSizeRel() const { return _maxSizeRel; }
88
89   void SetGradation(double theGradation);
90   double GetGradation() const { return _gradation; }
91
92   void SetQuadAllowed(bool theVal);
93   bool GetQuadAllowed() const { return _quadAllowed; }
94
95   void SetAngleMesh(double theAngle);
96   double GetAngleMesh() const { return _angleMesh; }
97
98   void SetChordalError(double theDistance);
99   double GetChordalError() const { return _chordalError; }
100
101   void SetAnisotropic(bool theVal);
102   bool GetAnisotropic() const { return _anisotropic; }
103
104   void SetAnisotropicRatio(double theVal);
105   double GetAnisotropicRatio() const { return _anisotropicRatio; }
106
107   void SetRemoveTinyEdges(bool theVal);
108   bool GetRemoveTinyEdges() const { return _removeTinyEdges; }
109
110   void SetTinyEdgeLength(double theVal);
111   double GetTinyEdgeLength() const { return _tinyEdgeLength; }
112
113   void SetBadElementRemoval(bool theVal);
114   bool GetBadElementRemoval() const { return _badElementRemoval; }
115
116   void SetBadElementAspectRatio(double theVal);
117   double GetBadElementAspectRatio() const { return _badElementAspectRatio; }
118
119   void SetOptimizeMesh(bool theVal);
120   bool GetOptimizeMesh() const { return _optimizeMesh; }
121
122   void SetQuadraticMesh(bool theVal);
123   bool GetQuadraticMesh() const { return _quadraticMesh; }
124
125   void SetTopology(Topology theTopology);
126   Topology GetTopology() const { return _topology; }
127
128   void SetVerbosity(int theVal);
129   int GetVerbosity() const { return _verb; }
130   
131   void ClearEntry(const std::string& entry);
132   void ClearSizeMaps();
133
134   void SetPreCADMergeEdges(bool theVal);
135   bool GetPreCADMergeEdges() const { return _preCADMergeEdges; }
136
137   void SetPreCADProcess3DTopology(bool theVal);
138   bool GetPreCADProcess3DTopology() const { return _preCADProcess3DTopology; }
139
140   void SetPreCADDiscardInput(bool theVal);
141   bool GetPreCADDiscardInput() const { return _preCADDiscardInput; }
142     
143   typedef std::map<std::string,std::string> TSizeMap;
144
145   void SetSizeMapEntry(const std::string& entry,const std::string& sizeMap );
146   std::string  GetSizeMapEntry(const std::string& entry);
147   const TSizeMap& _GetSizeMapEntries() const { return _sizeMap; }
148   /*!
149    * \brief Return the size maps
150    */
151   static TSizeMap GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp);
152
153
154   void SetAttractorEntry(const std::string& entry,const std::string& attractor );
155   std::string GetAttractorEntry(const std::string& entry);
156   const TSizeMap& _GetAttractorEntries() const { return _attractors; };
157   /*!
158    * \brief Return the attractors
159    */
160   static TSizeMap GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp);
161
162
163 /*
164   void SetCustomSizeMapEntry(const std::string& entry,const std::string& sizeMap );
165   std::string  GetCustomSizeMapEntry(const std::string& entry);
166   void UnsetCustomSizeMap(const std::string& entry);
167   const TSizeMap& GetCustomSizeMapEntries() const { return _customSizeMap; }
168  */
169   
170   typedef std::map< std::string, BLSURFPlugin_Attractor* > TAttractorMap;
171   typedef std::map< std::string, std::vector<double> > TParamsMap; //TODO à finir 
172   
173   void SetClassAttractorEntry(const std::string& entry, const std::string& att_entry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius);
174   std::string  GetClassAttractorEntry(const std::string& entry);
175   const TAttractorMap& _GetClassAttractorEntries() const { return _classAttractors; }
176   /*!
177    * \brief Return the attractors entries
178    */
179   static TAttractorMap GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp);
180
181   /*!
182    * To set/get/unset an enforced vertex
183    */
184   // Name
185   typedef std::string TEnfName;
186   // Entry
187   typedef std::string TEntry;
188   // List of entries
189   typedef std::set<TEntry> TEntryList;
190   // Group name
191   typedef std::string TEnfGroupName;
192   // Coordinates
193   typedef std::vector<double> TEnfVertexCoords;
194   typedef std::set< TEnfVertexCoords > TEnfVertexCoordsList;
195
196   // Enforced vertex
197   struct TEnfVertex {
198     TEnfName name;
199     TEntry geomEntry;
200     TEnfVertexCoords coords;
201     TEnfGroupName grpName;
202     TEntryList faceEntries;
203     TopoDS_Vertex vertex;
204   };
205     
206   struct CompareEnfVertices
207   {
208     bool operator () (const TEnfVertex* e1, const TEnfVertex* e2) const {
209       if (e1 && e2) {
210         if (e1->coords.size() && e2->coords.size())
211           return (e1->coords < e2->coords);
212         else
213           return (e1->geomEntry < e2->geomEntry);
214       }
215       return false;
216     }
217   };
218
219   // List of enforced vertices
220   typedef std::set< TEnfVertex*, CompareEnfVertices > TEnfVertexList;
221
222   // Map Face Entry / List of enforced vertices
223   typedef std::map< TEntry, TEnfVertexList > TFaceEntryEnfVertexListMap;
224
225   // List of Face Entry with internal enforced vertices activated
226   typedef std::set< TEntry > TFaceEntryInternalVerticesList;
227
228   // Map Face Entry / List of coords
229   typedef std::map< TEntry, TEnfVertexCoordsList > TFaceEntryCoordsListMap;
230
231   // Map Face Entry / List of Vertex entry
232   typedef std::map< TEntry, TEntryList > TFaceEntryEnfVertexEntryListMap;
233   
234   // Map Coords / Enforced vertex
235   typedef std::map< TEnfVertexCoords, TEnfVertex* > TCoordsEnfVertexMap;
236
237   // Map Vertex entry / Enforced vertex
238   typedef std::map< TEntry, TEnfVertex* > TEnfVertexEntryEnfVertexMap;
239
240   typedef std::map< TEnfGroupName, std::set<int> > TGroupNameNodeIDMap;
241   /* TODO GROUPS
242   // Map Group Name / List of enforced vertices
243   typedef std::map< TEnfGroupName , TEnfVertexList > TGroupNameEnfVertexListMap;
244   */
245
246   
247   bool                  SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry, TEnfGroupName theGroupName,
248                                           double x = 0.0, double y = 0.0, double z = 0.0);
249   TEnfVertexList        GetEnfVertexList(const TEntry& theFaceEntry) throw (std::invalid_argument);
250   TEnfVertexCoordsList  GetEnfVertexCoordsList(const TEntry& theFaceEntry) throw (std::invalid_argument);
251   TEntryList            GetEnfVertexEntryList (const TEntry& theFaceEntry) throw (std::invalid_argument);
252   TEnfVertex*           GetEnfVertex(TEnfVertexCoords coords) throw (std::invalid_argument);
253   TEnfVertex*           GetEnfVertex(const TEntry& theEnfVertexEntry) throw (std::invalid_argument);
254   void                  AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID);
255   std::set<int>         GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument);
256   void                  RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument);
257   
258   bool ClearEnforcedVertex(const TEntry& theFaceEntry, double x = 0.0, double y = 0.0, double z = 0.0, const TEntry& theVertexEntry="") throw (std::invalid_argument);
259   bool ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument);
260
261   void ClearAllEnforcedVertices();
262
263   const TFaceEntryEnfVertexListMap  _GetAllEnforcedVerticesByFace() const { return _faceEntryEnfVertexListMap; }
264   const TEnfVertexList              _GetAllEnforcedVertices() const { return _enfVertexList; }
265
266   const TFaceEntryCoordsListMap     _GetAllCoordsByFace() const { return _faceEntryCoordsListMap; }
267   const TCoordsEnfVertexMap         _GetAllEnforcedVerticesByCoords() const { return _coordsEnfVertexMap; }
268
269   const TFaceEntryEnfVertexEntryListMap _GetAllEnfVertexEntriesByFace() const { return _faceEntryEnfVertexEntryListMap; }
270   const TEnfVertexEntryEnfVertexMap     _GetAllEnforcedVerticesByEnfVertexEntry() const { return _enfVertexEntryEnfVertexMap; }
271
272 //   TODO GROUPS
273 //   const TEnfVertexGroupNameMap _GetEnforcedVertexGroupNameMap() const { return _enfVertexGroupNameMap; }
274   
275
276   /*!
277    * \brief Return the enforced vertices
278    */
279   static TFaceEntryEnfVertexListMap       GetAllEnforcedVerticesByFace(const BLSURFPlugin_Hypothesis* hyp);
280   static TEnfVertexList                   GetAllEnforcedVertices(const BLSURFPlugin_Hypothesis* hyp);
281
282   static TFaceEntryCoordsListMap          GetAllCoordsByFace(const BLSURFPlugin_Hypothesis* hyp);
283   static TCoordsEnfVertexMap              GetAllEnforcedVerticesByCoords(const BLSURFPlugin_Hypothesis* hyp);
284
285   static TFaceEntryEnfVertexEntryListMap  GetAllEnfVertexEntriesByFace(const BLSURFPlugin_Hypothesis* hyp);
286   static TEnfVertexEntryEnfVertexMap      GetAllEnforcedVerticesByEnfVertexEntry(const BLSURFPlugin_Hypothesis* hyp);
287
288   /*!
289    * \brief Internal enforced vertices
290    */
291   void SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices);
292   const bool _GetInternalEnforcedVertexAllFaces() const { return _enforcedInternalVerticesAllFaces; }
293   static bool GetInternalEnforcedVertexAllFaces( const BLSURFPlugin_Hypothesis* hyp );
294   void SetInternalEnforcedVertexAllFacesGroup(TEnfGroupName theGroupName);
295   const TEnfGroupName _GetInternalEnforcedVertexAllFacesGroup() const { return _enforcedInternalVerticesAllFacesGroup; }
296   static TEnfGroupName GetInternalEnforcedVertexAllFacesGroup( const BLSURFPlugin_Hypothesis* hyp );
297
298 //  Enable internal enforced vertices on specific face if requested by user
299 //  static TFaceEntryInternalVerticesList GetDefaultFaceEntryInternalVerticesMap() { return TFaceEntryInternalVerticesList(); }
300 //  const TFaceEntryInternalVerticesList  _GetAllInternalEnforcedVerticesByFace() const { return _faceEntryInternalVerticesList; }
301 //  static TFaceEntryInternalVerticesList GetAllInternalEnforcedVerticesByFace(const BLSURFPlugin_Hypothesis* hyp);
302 //  void SetInternalEnforcedVertex(TEntry theFaceEntry, bool toEnforceInternalVertices, TEnfGroupName theGroupName);
303 //  bool GetInternalEnforcedVertex(const TEntry& theFaceEntry);
304
305   static PhysicalMesh    GetDefaultPhysicalMesh() { return PhysicalGlobalSize; }
306   static GeometricMesh   GetDefaultGeometricMesh() { return DefaultGeom; }
307   static double          GetDefaultPhySize(double diagonal, double bbSegmentation);
308   static double          GetDefaultPhySize() { return undefinedDouble(); }
309   static bool            GetDefaultPhySizeRel() { return false; }
310   static double          GetDefaultMinSize(double diagonal);
311   static double          GetDefaultMinSize() { return undefinedDouble(); }
312   static bool            GetDefaultMinSizeRel() { return false; }
313   static double          GetDefaultMaxSize(double diagonal);
314   static double          GetDefaultMaxSize() { return undefinedDouble(); }
315   static bool            GetDefaultMaxSizeRel() { return false; }
316   static double          GetDefaultGradation() { return 1.3; }
317   static bool            GetDefaultQuadAllowed() { return false; }
318   static double          GetDefaultAngleMesh() { return 22.0; }
319   
320   static double          GetDefaultChordalError(double diagonal);
321   static double          GetDefaultChordalError() { return undefinedDouble(); }
322   static bool            GetDefaultAnisotropic() { return false; }
323   static double          GetDefaultAnisotropicRatio() { return 0.0; }
324   static bool            GetDefaultRemoveTinyEdges() { return false; }
325   static double          GetDefaultTinyEdgeLength(double diagonal);
326   static double          GetDefaultTinyEdgeLength() { return undefinedDouble(); }
327   static bool            GetDefaultBadElementRemoval() { return false; }
328   static double          GetDefaultBadElementAspectRatio() {return 1000.0; } 
329   static bool            GetDefaultOptimizeMesh() { return true; }
330   static bool            GetDefaultQuadraticMesh() { return false; }
331   
332   static int             GetDefaultVerbosity() { return 3; }
333   static Topology        GetDefaultTopology() { return FromCAD; }
334   // PreCAD
335   static bool            GetDefaultPreCADMergeEdges() { return true; }
336   static bool            GetDefaultPreCADProcess3DTopology() { return true; }
337   static bool            GetDefaultPreCADDiscardInput() { return false; }
338   
339   static TSizeMap        GetDefaultSizeMap() { return TSizeMap();}
340   static TAttractorMap   GetDefaultAttractorMap() { return TAttractorMap(); }
341
342   static TFaceEntryEnfVertexListMap       GetDefaultFaceEntryEnfVertexListMap() { return TFaceEntryEnfVertexListMap(); }
343   static TEnfVertexList                   GetDefaultEnfVertexList() { return TEnfVertexList(); }
344   static TFaceEntryCoordsListMap          GetDefaultFaceEntryCoordsListMap() { return TFaceEntryCoordsListMap(); }
345   static TCoordsEnfVertexMap              GetDefaultCoordsEnfVertexMap() { return TCoordsEnfVertexMap(); }
346   static TFaceEntryEnfVertexEntryListMap  GetDefaultFaceEntryEnfVertexEntryListMap() { return TFaceEntryEnfVertexEntryListMap(); }
347   static TEnfVertexEntryEnfVertexMap      GetDefaultEnfVertexEntryEnfVertexMap() { return TEnfVertexEntryEnfVertexMap(); }
348   static TGroupNameNodeIDMap              GetDefaultGroupNameNodeIDMap() { return TGroupNameNodeIDMap(); }
349
350   static bool            GetDefaultInternalEnforcedVertex() { return false; }
351
352   /* TODO GROUPS
353   static TGroupNameEnfVertexListMap GetDefaultGroupNameEnfVertexListMap() { return TGroupNameEnfVertexListMap(); }
354   static TEnfVertexGroupNameMap     GetDefaultEnfVertexGroupNameMap() { return TEnfVertexGroupNameMap(); }
355   */
356
357   static double undefinedDouble() { return -1.0; }
358
359   typedef std::map< std::string, std::string > TOptionValues;
360   typedef std::set< std::string >              TOptionNames;
361
362   void SetOptionValue(const std::string& optionName,
363                       const std::string& optionValue) throw (std::invalid_argument);
364   void SetPreCADOptionValue(const std::string& optionName,
365                             const std::string& optionValue) throw (std::invalid_argument);
366   std::string GetOptionValue(const std::string& optionName) throw (std::invalid_argument);
367   std::string GetPreCADOptionValue(const std::string& optionName) throw (std::invalid_argument);
368   void ClearOption(const std::string& optionName);
369   void ClearPreCADOption(const std::string& optionName);
370   const TOptionValues& GetOptionValues() const { return _option2value; }
371   const TOptionValues& GetPreCADOptionValues() const { return _preCADoption2value; }
372
373   /*!
374     * Sets the file for export resulting mesh in GMF format
375     */
376 //   void SetGMFFile(const std::string& theFileName, bool isBinary);
377   void SetGMFFile(const std::string& theFileName);
378   std::string GetGMFFile() const { return _GMFFileName; }
379   static std::string GetDefaultGMFFile() { return "";}
380 //   bool GetGMFFileMode() const { return _GMFFileMode; }
381   
382   // Persistence
383   virtual std::ostream & SaveTo(std::ostream & save);
384   virtual std::istream & LoadFrom(std::istream & load);
385   friend std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp);
386   friend std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp);
387
388   /*!
389    * \brief Does nothing
390    * \param theMesh - the built mesh
391    * \param theShape - the geometry of interest
392    * \retval bool - always false
393    */
394   virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
395
396   /*!
397    * \brief Initialize my parameter values by default parameters.
398    *  \retval bool - true if parameter values have been successfully defined
399    */
400   virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
401
402
403 private:
404   PhysicalMesh    _physicalMesh;
405   GeometricMesh   _geometricMesh;
406   double          _phySize;
407   bool            _phySizeRel;
408   double          _minSize, _maxSize;
409   bool            _minSizeRel, _maxSizeRel;
410   double          _gradation;
411   bool            _quadAllowed;
412   double          _angleMesh;
413   double          _chordalError;
414   bool            _anisotropic;
415   double          _anisotropicRatio;
416   bool            _removeTinyEdges;
417   double          _tinyEdgeLength;
418   bool            _badElementRemoval;
419   double          _badElementAspectRatio;
420   bool            _optimizeMesh;
421   bool            _quadraticMesh;
422   int             _verb;
423   Topology        _topology;
424   
425   bool            _preCADMergeEdges;
426   bool            _preCADProcess3DTopology;
427   bool            _preCADDiscardInput;
428   double          _preCADEpsNano;
429   
430   TOptionValues   _option2value, _preCADoption2value;
431   TOptionNames    _doubleOptions, _charOptions;
432   TOptionNames    _preCADdoubleOptions, _preCADcharOptions;
433   TSizeMap        _sizeMap;
434   TSizeMap        _attractors;
435   TAttractorMap   _classAttractors;
436   TSizeMap        _attEntry;
437   TParamsMap      _attParams;
438
439   TFaceEntryEnfVertexListMap  _faceEntryEnfVertexListMap;
440   TEnfVertexList              _enfVertexList;
441   // maps to get "manual" enf vertex (through their coordinates)
442   TFaceEntryCoordsListMap     _faceEntryCoordsListMap;
443   TCoordsEnfVertexMap         _coordsEnfVertexMap;
444   // maps to get "geom" enf vertex (through their geom entries)
445   TFaceEntryEnfVertexEntryListMap _faceEntryEnfVertexEntryListMap;
446   TEnfVertexEntryEnfVertexMap     _enfVertexEntryEnfVertexMap;
447   TGroupNameNodeIDMap             _groupNameNodeIDMap;
448   
449 //  Enable internal enforced vertices on specific face if requested by user
450 //  TFaceEntryInternalVerticesList  _faceEntryInternalVerticesList;
451   bool            _enforcedInternalVerticesAllFaces;
452   TEnfGroupName   _enforcedInternalVerticesAllFacesGroup;
453   
454   std::string     _GMFFileName;
455 //   bool            _GMFFileMode;
456
457 //   TSizeMap      _customSizeMap;
458 };
459
460 #endif