1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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)
27 #ifndef _BLSURFPlugin_Hypothesis_HXX_
28 #define _BLSURFPlugin_Hypothesis_HXX_
30 #include "SMESH_Hypothesis.hxx"
38 #include <utilities.h>
39 #include "BLSURFPlugin_Attractor.hxx"
41 // Parameters for work of BLSURF
43 class BLSURFPlugin_Hypothesis: public SMESH_Hypothesis
46 BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen);
63 GeometricalGlobalSize,
67 static const char* GetHypType() { return "BLSURF_Parameters"; }
69 TopoDS_Shape entryToShape(std::string entry);
71 void SetPhysicalMesh(PhysicalMesh thePhysicalMesh);
72 PhysicalMesh GetPhysicalMesh() const { return _physicalMesh; }
74 void SetGeometricMesh(GeometricMesh theGeometricMesh);
75 GeometricMesh GetGeometricMesh() const { return _geometricMesh; }
77 void SetPhySize(double thePhySize, bool isRelative = false);
78 double GetPhySize() const { return _phySize; }
79 bool IsPhySizeRel() const { return _phySizeRel; }
81 void SetMinSize(double theMinSize, bool isRelative = false);
82 double GetMinSize() const { return _minSize; }
83 bool IsMinSizeRel() const { return _minSizeRel; }
85 void SetMaxSize(double theMaxSize, bool isRelative = false);
86 double GetMaxSize() const { return _maxSize; }
87 bool IsMaxSizeRel() const { return _maxSizeRel; }
89 void SetGradation(double theGradation);
90 double GetGradation() const { return _gradation; }
92 void SetQuadAllowed(bool theVal);
93 bool GetQuadAllowed() const { return _quadAllowed; }
95 void SetAngleMesh(double theAngle);
96 double GetAngleMesh() const { return _angleMesh; }
98 void SetChordalError(double theDistance);
99 double GetChordalError() const { return _chordalError; }
101 void SetAnisotropic(bool theVal);
102 bool GetAnisotropic() const { return _anisotropic; }
104 void SetAnisotropicRatio(double theVal);
105 double GetAnisotropicRatio() const { return _anisotropicRatio; }
107 void SetRemoveTinyEdges(bool theVal);
108 bool GetRemoveTinyEdges() const { return _removeTinyEdges; }
110 void SetTinyEdgeLength(double theVal);
111 double GetTinyEdgeLength() const { return _tinyEdgeLength; }
113 void SetBadElementRemoval(bool theVal);
114 bool GetBadElementRemoval() const { return _badElementRemoval; }
116 void SetBadElementAspectRatio(double theVal);
117 double GetBadElementAspectRatio() const { return _badElementAspectRatio; }
119 void SetOptimizeMesh(bool theVal);
120 bool GetOptimizeMesh() const { return _optimizeMesh; }
122 void SetQuadraticMesh(bool theVal);
123 bool GetQuadraticMesh() const { return _quadraticMesh; }
125 void SetTopology(Topology theTopology);
126 Topology GetTopology() const { return _topology; }
128 void SetVerbosity(int theVal);
129 int GetVerbosity() const { return _verb; }
131 void ClearEntry(const std::string& entry);
132 void ClearSizeMaps();
134 void SetPreCADMergeEdges(bool theVal);
135 bool GetPreCADMergeEdges() const { return _preCADMergeEdges; }
137 void SetPreCADProcess3DTopology(bool theVal);
138 bool GetPreCADProcess3DTopology() const { return _preCADProcess3DTopology; }
140 void SetPreCADDiscardInput(bool theVal);
141 bool GetPreCADDiscardInput() const { return _preCADDiscardInput; }
143 typedef std::map<std::string,std::string> TSizeMap;
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; }
149 * \brief Return the size maps
151 static TSizeMap GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp);
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; };
158 * \brief Return the attractors
160 static TSizeMap GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp);
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; }
170 typedef std::map< std::string, BLSURFPlugin_Attractor* > TAttractorMap;
171 typedef std::map< std::string, std::vector<double> > TParamsMap; //TODO à finir
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; }
177 * \brief Return the attractors entries
179 static TAttractorMap GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp);
182 * To set/get/unset an enforced vertex
185 typedef std::string TEnfName;
187 typedef std::string TEntry;
189 typedef std::set<TEntry> TEntryList;
191 typedef std::string TEnfGroupName;
193 typedef std::vector<double> TEnfVertexCoords;
194 typedef std::set< TEnfVertexCoords > TEnfVertexCoordsList;
200 TEnfVertexCoords coords;
201 TEnfGroupName grpName;
202 TEntryList faceEntries;
203 TopoDS_Vertex vertex;
206 struct CompareEnfVertices
208 bool operator () (const TEnfVertex* e1, const TEnfVertex* e2) const {
210 if (e1->coords.size() && e2->coords.size())
211 return (e1->coords < e2->coords);
213 return (e1->geomEntry < e2->geomEntry);
219 // List of enforced vertices
220 typedef std::set< TEnfVertex*, CompareEnfVertices > TEnfVertexList;
222 // Map Face Entry / List of enforced vertices
223 typedef std::map< TEntry, TEnfVertexList > TFaceEntryEnfVertexListMap;
225 // List of Face Entry with internal enforced vertices activated
226 typedef std::set< TEntry > TFaceEntryInternalVerticesList;
228 // Map Face Entry / List of coords
229 typedef std::map< TEntry, TEnfVertexCoordsList > TFaceEntryCoordsListMap;
231 // Map Face Entry / List of Vertex entry
232 typedef std::map< TEntry, TEntryList > TFaceEntryEnfVertexEntryListMap;
234 // Map Coords / Enforced vertex
235 typedef std::map< TEnfVertexCoords, TEnfVertex* > TCoordsEnfVertexMap;
237 // Map Vertex entry / Enforced vertex
238 typedef std::map< TEntry, TEnfVertex* > TEnfVertexEntryEnfVertexMap;
240 typedef std::map< TEnfGroupName, std::set<int> > TGroupNameNodeIDMap;
242 // Map Group Name / List of enforced vertices
243 typedef std::map< TEnfGroupName , TEnfVertexList > TGroupNameEnfVertexListMap;
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);
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);
261 void ClearAllEnforcedVertices();
263 const TFaceEntryEnfVertexListMap _GetAllEnforcedVerticesByFace() const { return _faceEntryEnfVertexListMap; }
264 const TEnfVertexList _GetAllEnforcedVertices() const { return _enfVertexList; }
266 const TFaceEntryCoordsListMap _GetAllCoordsByFace() const { return _faceEntryCoordsListMap; }
267 const TCoordsEnfVertexMap _GetAllEnforcedVerticesByCoords() const { return _coordsEnfVertexMap; }
269 const TFaceEntryEnfVertexEntryListMap _GetAllEnfVertexEntriesByFace() const { return _faceEntryEnfVertexEntryListMap; }
270 const TEnfVertexEntryEnfVertexMap _GetAllEnforcedVerticesByEnfVertexEntry() const { return _enfVertexEntryEnfVertexMap; }
273 // const TEnfVertexGroupNameMap _GetEnforcedVertexGroupNameMap() const { return _enfVertexGroupNameMap; }
277 * \brief Return the enforced vertices
279 static TFaceEntryEnfVertexListMap GetAllEnforcedVerticesByFace(const BLSURFPlugin_Hypothesis* hyp);
280 static TEnfVertexList GetAllEnforcedVertices(const BLSURFPlugin_Hypothesis* hyp);
282 static TFaceEntryCoordsListMap GetAllCoordsByFace(const BLSURFPlugin_Hypothesis* hyp);
283 static TCoordsEnfVertexMap GetAllEnforcedVerticesByCoords(const BLSURFPlugin_Hypothesis* hyp);
285 static TFaceEntryEnfVertexEntryListMap GetAllEnfVertexEntriesByFace(const BLSURFPlugin_Hypothesis* hyp);
286 static TEnfVertexEntryEnfVertexMap GetAllEnforcedVerticesByEnfVertexEntry(const BLSURFPlugin_Hypothesis* hyp);
289 * \brief Internal enforced vertices
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 );
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);
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; }
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; }
332 static int GetDefaultVerbosity() { return 3; }
333 static Topology GetDefaultTopology() { return FromCAD; }
335 static bool GetDefaultPreCADMergeEdges() { return true; }
336 static bool GetDefaultPreCADProcess3DTopology() { return true; }
337 static bool GetDefaultPreCADDiscardInput() { return false; }
339 static TSizeMap GetDefaultSizeMap() { return TSizeMap();}
340 static TAttractorMap GetDefaultAttractorMap() { return TAttractorMap(); }
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(); }
350 static bool GetDefaultInternalEnforcedVertex() { return false; }
353 static TGroupNameEnfVertexListMap GetDefaultGroupNameEnfVertexListMap() { return TGroupNameEnfVertexListMap(); }
354 static TEnfVertexGroupNameMap GetDefaultEnfVertexGroupNameMap() { return TEnfVertexGroupNameMap(); }
357 static double undefinedDouble() { return -1.0; }
359 typedef std::map< std::string, std::string > TOptionValues;
360 typedef std::set< std::string > TOptionNames;
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; }
374 * Sets the file for export resulting mesh in GMF format
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; }
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);
389 * \brief Does nothing
390 * \param theMesh - the built mesh
391 * \param theShape - the geometry of interest
392 * \retval bool - always false
394 virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
397 * \brief Initialize my parameter values by default parameters.
398 * \retval bool - true if parameter values have been successfully defined
400 virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
404 PhysicalMesh _physicalMesh;
405 GeometricMesh _geometricMesh;
408 double _minSize, _maxSize;
409 bool _minSizeRel, _maxSizeRel;
413 double _chordalError;
415 double _anisotropicRatio;
416 bool _removeTinyEdges;
417 double _tinyEdgeLength;
418 bool _badElementRemoval;
419 double _badElementAspectRatio;
425 bool _preCADMergeEdges;
426 bool _preCADProcess3DTopology;
427 bool _preCADDiscardInput;
428 double _preCADEpsNano;
430 TOptionValues _option2value, _preCADoption2value;
431 TOptionNames _doubleOptions, _charOptions;
432 TOptionNames _preCADdoubleOptions, _preCADcharOptions;
434 TSizeMap _attractors;
435 TAttractorMap _classAttractors;
437 TParamsMap _attParams;
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;
449 // Enable internal enforced vertices on specific face if requested by user
450 // TFaceEntryInternalVerticesList _faceEntryInternalVerticesList;
451 bool _enforcedInternalVerticesAllFaces;
452 TEnfGroupName _enforcedInternalVerticesAllFacesGroup;
454 std::string _GMFFileName;
455 // bool _GMFFileMode;
457 // TSizeMap _customSizeMap;