1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
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.cxx
22 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
23 // & Aurelien ALLEAUME (DISTENE)
24 // Size maps development: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
27 #include "BLSURFPlugin_Hypothesis.hxx"
28 #include "BLSURFPlugin_Attractor.hxx"
29 #include "SMESH_Gen_i.hxx"
30 #include <utilities.h>
35 #include <Basics_Utils.hxx>
38 #include "ShapeAnalysis.hxx"
41 #include CORBA_CLIENT_HEADER(SALOMEDS)
42 #include CORBA_CLIENT_HEADER(GEOM_Gen)
44 #include <meshgems/meshgems.h>
45 #define MESHGEMS_VERSION_HEX (MESHGEMS_VERSION_MAJOR << 16 | MESHGEMS_VERSION_MINOR << 8 | MESHGEMS_VERSION_PATCH)
47 #include <boost/archive/text_oarchive.hpp>
48 #include <boost/archive/text_iarchive.hpp>
49 #include <boost/serialization/set.hpp>
50 #include <boost/serialization/vector.hpp>
51 #include <boost/serialization/string.hpp>
55 struct GET_DEFAULT // struct used to get default value from GetOptionValue()
58 operator bool* () { return &isDefault; }
62 //=============================================================================
63 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, SMESH_Gen * gen, bool hasgeom) :
64 SMESH_Hypothesis(hypId, gen),
65 _physicalMesh(GetDefaultPhysicalMesh()),
66 _geometricMesh(GetDefaultGeometricMesh()),
67 _phySize(GetDefaultPhySize()),
68 _phySizeRel(GetDefaultPhySizeRel()),
69 _minSize(GetDefaultMinSize()),
70 _maxSize(GetDefaultMaxSize()),
71 _minSizeRel(GetDefaultMinSizeRel()),
72 _maxSizeRel(GetDefaultMaxSizeRel()),
73 _useGradation(GetDefaultUseGradation()),
74 _gradation(GetDefaultGradation()),
75 _useVolumeGradation(GetDefaultUseVolumeGradation()),
76 _volumeGradation(GetDefaultVolumeGradation()),
77 _elementType(GetDefaultElementType()),
78 _angleMesh(GetDefaultAngleMesh()),
79 _chordalError(GetDefaultChordalError()),
80 _anisotropic(GetDefaultAnisotropic()),
81 _anisotropicRatio(GetDefaultAnisotropicRatio()),
82 _removeTinyEdges(GetDefaultRemoveTinyEdges()),
83 _tinyEdgeLength(GetDefaultTinyEdgeLength()),
84 _optimiseTinyEdges(GetDefaultOptimiseTinyEdges()),
85 _tinyEdgeOptimisationLength(GetDefaultTinyEdgeOptimisationLength()),
86 _correctSurfaceIntersec(GetDefaultCorrectSurfaceIntersection()),
87 _corrSurfaceIntersCost(GetDefaultCorrectSurfaceIntersectionMaxCost()),
88 _badElementRemoval(GetDefaultBadElementRemoval()),
89 _badElementAspectRatio(GetDefaultBadElementAspectRatio()),
90 _optimizeMesh(GetDefaultOptimizeMesh()),
91 _quadraticMesh(GetDefaultQuadraticMesh()),
92 _verb(GetDefaultVerbosity()),
93 _topology(GetDefaultTopology()),
94 _useSurfaceProximity(GetDefaultUseSurfaceProximity()),
95 _nbSurfaceProximityLayers(GetDefaultNbSurfaceProximityLayers()),
96 _surfaceProximityRatio(GetDefaultSurfaceProximityRatio()),
97 _useVolumeProximity(GetDefaultUseVolumeProximity()),
98 _nbVolumeProximityLayers(GetDefaultNbVolumeProximityLayers()),
99 _volumeProximityRatio(GetDefaultVolumeProximityRatio()),
100 _preCADMergeEdges(GetDefaultPreCADMergeEdges()),
101 _preCADRemoveDuplicateCADFaces(GetDefaultPreCADRemoveDuplicateCADFaces()),
102 _preCADProcess3DTopology(GetDefaultPreCADProcess3DTopology()),
103 _preCADDiscardInput(GetDefaultPreCADDiscardInput()),
104 _sizeMap(GetDefaultSizeMap()),
105 _attractors(GetDefaultSizeMap()),
106 _classAttractors(GetDefaultAttractorMap()),
107 _faceEntryEnfVertexListMap(GetDefaultFaceEntryEnfVertexListMap()),
108 _enfVertexList(GetDefaultEnfVertexList()),
109 _faceEntryCoordsListMap(GetDefaultFaceEntryCoordsListMap()),
110 _coordsEnfVertexMap(GetDefaultCoordsEnfVertexMap()),
111 _faceEntryEnfVertexEntryListMap(GetDefaultFaceEntryEnfVertexEntryListMap()),
112 _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
113 _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap()),
114 _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex()),
115 _preCadFacesPeriodicityVector(GetDefaultPreCadFacesPeriodicityVector()),
116 _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector()),
117 _GMFFileName(GetDefaultGMFFile())
119 _name = GetHypType(hasgeom);
122 // Advanced options with their defaults according to MG User Manual
124 const char* boolOptionNames[] = {
125 #if MESHGEMS_VERSION_HEX < 0x020A00
126 "enforce_cad_edge_sizes", // default = 0 // Deprecated since MeshGems 2.10
128 "jacobian_rectification_respect_geometry", // default = 1
129 "rectify_jacobian", // default = 1
130 "respect_geometry", // default = 1
131 "tiny_edge_avoid_surface_intersections", // default = 1
132 "debug", // default = 0
133 "allow_patch_independent", // false
137 const char* intOptionNames[] = {
138 #if MESHGEMS_VERSION_HEX < 0x020A00
139 "max_number_of_points_per_patch", // default = 100000 // Deprecated since MeshGems 2.10
141 "max_number_of_threads", // default = 4
144 const char* doubleOptionNames[] = { // "surface_intersections_processing_max_cost",// default = 15
145 // "periodic_tolerance", // default = diag/100
146 // "volume_gradation",
147 // "tiny_edge_optimisation_length", // default = diag * 1e-6
150 const char* charOptionNames[] = { // "required_entities", // default = "respect"
151 // "tags", // default = "respect"
155 // PreCAD advanced options
156 const char* preCADboolOptionNames[] = { "closed_geometry", // default = 0
157 "discard_input_topology", // default = 0
158 "merge_edges", // default = = 1
159 "remove_duplicate_cad_faces", // default = 1
160 // "create_tag_on_collision", // default = 1
161 "process_3d_topology", // default = 1
162 // "remove_tiny_edges", // default = 0
163 // remove_tiny_uv_edges option is not documented
164 // but it is useful that the user can change it to disable all preprocessing options
165 "remove_tiny_uv_edges", // default = 1
166 "compute_ridges", // true
169 const char* preCADintOptionNames[] = { // "manifold_geometry", // default = 0
172 const char* preCADdoubleOptionNames[] = { "periodic_tolerance", // default = diag * 1e-5
173 "sewing_tolerance", // default = diag * 5e-4
174 // "tiny_edge_length", // default = diag * 1e-5
177 const char* preCADcharOptionNames[] = { "required_entities", // default = "respect"
178 "tags", // default = "respect"
183 while (boolOptionNames[i][0])
185 _boolOptions.insert( boolOptionNames[i] );
186 _option2value[boolOptionNames[i++]].clear();
189 while (preCADboolOptionNames[i][0] && hasgeom)
191 _boolOptions.insert( preCADboolOptionNames[i] );
192 _preCADoption2value[preCADboolOptionNames[i++]].clear();
195 while (intOptionNames[i][0])
196 _option2value[intOptionNames[i++]].clear();
199 while (preCADintOptionNames[i][0] && hasgeom)
200 _preCADoption2value[preCADintOptionNames[i++]].clear();
203 while (doubleOptionNames[i][0]) {
204 _doubleOptions.insert(doubleOptionNames[i]);
205 _option2value[doubleOptionNames[i++]].clear();
208 while (preCADdoubleOptionNames[i][0] && hasgeom) {
209 _preCADdoubleOptions.insert(preCADdoubleOptionNames[i]);
210 _preCADoption2value[preCADdoubleOptionNames[i++]].clear();
213 while (charOptionNames[i][0]) {
214 _charOptions.insert(charOptionNames[i]);
215 _option2value[charOptionNames[i++]].clear();
218 while (preCADcharOptionNames[i][0] && hasgeom) {
219 _preCADcharOptions.insert(preCADcharOptionNames[i]);
220 _preCADoption2value[preCADcharOptionNames[i++]].clear();
223 // default values to be used while MG meshing
225 #if MESHGEMS_VERSION_HEX < 0x020A00
226 _defaultOptionValues["enforce_cad_edge_sizes" ] = "no"; // Deprecated since MeshGems 2.10
228 _defaultOptionValues["jacobian_rectification_respect_geometry"] = "yes";
229 #if MESHGEMS_VERSION_HEX < 0x020A00
230 _defaultOptionValues["max_number_of_points_per_patch" ] = "0"; // Deprecated since MeshGems 2.10
232 _defaultOptionValues["max_number_of_threads" ] = "4";
233 _defaultOptionValues["rectify_jacobian" ] = "yes";
234 _defaultOptionValues["respect_geometry" ] = "yes";
235 _defaultOptionValues["tiny_edge_avoid_surface_intersections" ] = "yes";
236 //_defaultOptionValues["use_deprecated_patch_mesher" ] = "no";
237 _defaultOptionValues["debug" ] = "no";
238 _defaultOptionValues["allow_patch_independent" ] = "no";
241 _defaultOptionValues["closed_geometry" ] = "no";
242 _defaultOptionValues["discard_input_topology" ] = "no";
243 _defaultOptionValues["merge_edges" ] = "no";
244 _defaultOptionValues["periodic_tolerance" ] = "1e-5*D";
245 _defaultOptionValues["process_3d_topology" ] = "no";
246 _defaultOptionValues["remove_duplicate_cad_faces" ] = "no";
247 _defaultOptionValues["remove_tiny_uv_edges" ] = "no";
248 _defaultOptionValues["required_entities" ] = "respect";
249 _defaultOptionValues["sewing_tolerance" ] = "5e-4*D";
250 _defaultOptionValues["tags" ] = "respect";
251 _defaultOptionValues["compute_ridges" ] = "yes";
254 if ( MESHGEMS_VERSION_HEX < 0x020906 )
256 std::string missingOption = "allow_patch_independent";
257 _defaultOptionValues.erase( missingOption );
258 _boolOptions.erase( missingOption );
259 _option2value.erase( missingOption );
263 // check validity of option names of _defaultOptionValues
264 TOptionValues::iterator n2v = _defaultOptionValues.begin();
265 for ( ; n2v != _defaultOptionValues.end(); ++n2v )
266 ASSERT( _option2value.count( n2v->first ) || _preCADoption2value.count( n2v->first ));
267 ASSERT( _option2value.size() + _preCADoption2value.size() == _defaultOptionValues.size() );
272 TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry)
274 GEOM::GEOM_Object_var aGeomObj;
276 TopoDS_Shape S = TopoDS_Shape();
277 SALOMEDS::SObject_var aSObj = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectID( entry.c_str() );
278 if (!aSObj->_is_nil() ) {
279 CORBA::Object_var obj = aSObj->GetObject();
280 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
283 if ( !aGeomObj->_is_nil() )
284 S = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aGeomObj.in() );
288 //=============================================================================
289 std::string BLSURFPlugin_Hypothesis::GetMeshGemsVersion()
291 return MESHGEMS_VERSION_LONG;
294 //=============================================================================
295 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh)
297 if (thePhysicalMesh != _physicalMesh) {
298 _physicalMesh = thePhysicalMesh;
299 NotifySubMeshesHypothesisModification();
303 //=============================================================================
304 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh)
306 if (theGeometricMesh != _geometricMesh) {
307 _geometricMesh = theGeometricMesh;
308 // switch (_geometricMesh) {
311 // _angleMesh = GetDefaultAngleMesh();
312 // _gradation = GetDefaultGradation();
315 NotifySubMeshesHypothesisModification();
319 //=============================================================================
320 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal, bool isRelative)
322 if ((theVal != _phySize) || (isRelative != _phySizeRel)) {
323 _phySizeRel = isRelative;
325 _phySize = GetMaxSize();
329 NotifySubMeshesHypothesisModification();
333 //=============================================================================
334 void BLSURFPlugin_Hypothesis::SetMinSize(double theMinSize, bool isRelative)
336 if ((theMinSize != _minSize) || (isRelative != _minSizeRel)) {
337 _minSizeRel = isRelative;
338 _minSize = theMinSize;
339 NotifySubMeshesHypothesisModification();
343 //=============================================================================
344 void BLSURFPlugin_Hypothesis::SetMaxSize(double theMaxSize, bool isRelative)
346 if ((theMaxSize != _maxSize) || (isRelative != _maxSizeRel)) {
347 _maxSizeRel = isRelative;
348 _maxSize = theMaxSize;
349 NotifySubMeshesHypothesisModification();
353 //=============================================================================
354 void BLSURFPlugin_Hypothesis::SetUseGradation(bool theVal)
356 if (theVal != _useGradation) {
357 _useGradation = theVal;
358 NotifySubMeshesHypothesisModification();
362 //=============================================================================
363 void BLSURFPlugin_Hypothesis::SetGradation(double theVal)
365 _useGradation = ( theVal > 0 );
366 if (theVal != _gradation) {
368 NotifySubMeshesHypothesisModification();
372 //=============================================================================
373 void BLSURFPlugin_Hypothesis::SetUseVolumeGradation(bool theVal)
375 if (theVal != _useVolumeGradation) {
376 _useVolumeGradation = theVal;
377 NotifySubMeshesHypothesisModification();
381 //=============================================================================
382 void BLSURFPlugin_Hypothesis::SetVolumeGradation(double theVal)
384 _useVolumeGradation = ( theVal > 0 );
385 if (theVal != _volumeGradation) {
386 _volumeGradation = theVal;
387 NotifySubMeshesHypothesisModification();
391 //=============================================================================
392 void BLSURFPlugin_Hypothesis::SetElementType(ElementType theElementType)
394 if (theElementType != _elementType) {
395 _elementType = theElementType;
396 NotifySubMeshesHypothesisModification();
400 //=============================================================================
401 void BLSURFPlugin_Hypothesis::SetAngleMesh(double theVal)
403 if (theVal != _angleMesh) {
405 NotifySubMeshesHypothesisModification();
409 //=============================================================================
410 void BLSURFPlugin_Hypothesis::SetChordalError(double theDistance)
412 if (theDistance != _chordalError) {
413 _chordalError = theDistance;
414 NotifySubMeshesHypothesisModification();
418 //=============================================================================
419 void BLSURFPlugin_Hypothesis::SetAnisotropic(bool theVal)
421 if (theVal != _anisotropic) {
422 _anisotropic = theVal;
423 NotifySubMeshesHypothesisModification();
427 //=============================================================================
428 void BLSURFPlugin_Hypothesis::SetAnisotropicRatio(double theVal)
430 if (theVal != _anisotropicRatio) {
431 _anisotropicRatio = theVal;
432 NotifySubMeshesHypothesisModification();
436 //=============================================================================
437 void BLSURFPlugin_Hypothesis::SetRemoveTinyEdges(bool theVal)
439 if (theVal != _removeTinyEdges) {
440 _removeTinyEdges = theVal;
441 NotifySubMeshesHypothesisModification();
445 //=============================================================================
446 void BLSURFPlugin_Hypothesis::SetTinyEdgeLength(double theVal)
448 if (theVal != _tinyEdgeLength) {
449 _tinyEdgeLength = theVal;
450 NotifySubMeshesHypothesisModification();
454 //=============================================================================
455 void BLSURFPlugin_Hypothesis::SetOptimiseTinyEdges(bool theVal)
457 if (theVal != _optimiseTinyEdges) {
458 _optimiseTinyEdges = theVal;
459 NotifySubMeshesHypothesisModification();
463 //=============================================================================
464 void BLSURFPlugin_Hypothesis::SetTinyEdgeOptimisationLength(double theVal)
466 if (theVal != _tinyEdgeOptimisationLength) {
467 _tinyEdgeOptimisationLength = theVal;
468 NotifySubMeshesHypothesisModification();
472 //=============================================================================
473 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersection(bool theVal)
475 if (theVal != _correctSurfaceIntersec) {
476 _correctSurfaceIntersec = theVal;
477 NotifySubMeshesHypothesisModification();
481 //=============================================================================
482 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersectionMaxCost(double theVal)
484 if (theVal != _corrSurfaceIntersCost) {
485 _corrSurfaceIntersCost = theVal;
486 NotifySubMeshesHypothesisModification();
490 //=============================================================================
491 void BLSURFPlugin_Hypothesis::SetBadElementRemoval(bool theVal)
493 if (theVal != _badElementRemoval) {
494 _badElementRemoval = theVal;
495 NotifySubMeshesHypothesisModification();
499 //=============================================================================
500 void BLSURFPlugin_Hypothesis::SetBadElementAspectRatio(double theVal)
502 if (theVal != _badElementAspectRatio) {
503 _badElementAspectRatio = theVal;
504 NotifySubMeshesHypothesisModification();
508 //=============================================================================
509 void BLSURFPlugin_Hypothesis::SetOptimizeMesh(bool theVal)
511 if (theVal != _optimizeMesh) {
512 _optimizeMesh = theVal;
513 NotifySubMeshesHypothesisModification();
517 //=============================================================================
518 void BLSURFPlugin_Hypothesis::SetQuadraticMesh(bool theVal)
520 if (theVal != _quadraticMesh) {
521 _quadraticMesh = theVal;
522 NotifySubMeshesHypothesisModification();
526 //=============================================================================
527 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology)
529 if (theTopology != _topology) {
530 _topology = theTopology;
531 NotifySubMeshesHypothesisModification();
535 //=============================================================================
536 void BLSURFPlugin_Hypothesis::SetUseSurfaceProximity( bool toUse )
538 if ( _useSurfaceProximity != toUse )
540 _useSurfaceProximity = toUse;
541 NotifySubMeshesHypothesisModification();
545 //=============================================================================
546 void BLSURFPlugin_Hypothesis::SetNbSurfaceProximityLayers( int nbLayers )
548 if ( _nbSurfaceProximityLayers != nbLayers )
550 _nbSurfaceProximityLayers = nbLayers;
551 NotifySubMeshesHypothesisModification();
555 //=============================================================================
556 void BLSURFPlugin_Hypothesis::SetSurfaceProximityRatio( double ratio )
558 if ( _surfaceProximityRatio != ratio )
560 _surfaceProximityRatio = ratio;
561 NotifySubMeshesHypothesisModification();
565 //=============================================================================
566 void BLSURFPlugin_Hypothesis::SetUseVolumeProximity( bool toUse )
568 if ( _useVolumeProximity != toUse )
570 _useVolumeProximity = toUse;
571 NotifySubMeshesHypothesisModification();
575 //=============================================================================
576 void BLSURFPlugin_Hypothesis::SetNbVolumeProximityLayers( int nbLayers )
578 if ( _nbVolumeProximityLayers != nbLayers )
580 _nbVolumeProximityLayers = nbLayers;
581 NotifySubMeshesHypothesisModification();
585 //=============================================================================
586 void BLSURFPlugin_Hypothesis::SetVolumeProximityRatio( double ratio )
588 if ( _volumeProximityRatio != ratio )
590 _volumeProximityRatio = ratio;
591 NotifySubMeshesHypothesisModification();
595 //=============================================================================
596 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
597 if (theVal != _verb) {
599 NotifySubMeshesHypothesisModification();
603 //=============================================================================
604 void BLSURFPlugin_Hypothesis::SetEnforceCadEdgesSize( bool toEnforce )
606 #if MESHGEMS_VERSION_HEX < 0x020A00
607 // Deprecated since MeshGems 2.10
608 if ( GetEnforceCadEdgesSize() != toEnforce )
610 SetOptionValue( "enforce_cad_edge_sizes", toEnforce ? "yes" : "no" );
611 NotifySubMeshesHypothesisModification();
614 (void)toEnforce; // maybe unused
617 //=============================================================================
618 bool BLSURFPlugin_Hypothesis::GetEnforceCadEdgesSize()
620 #if MESHGEMS_VERSION_HEX < 0x020A00
621 // Deprecated since MeshGems 2.10
622 return ToBool( GetOptionValue( "enforce_cad_edge_sizes" ), GET_DEFAULT() );
627 //=============================================================================
629 void BLSURFPlugin_Hypothesis::SetJacobianRectificationRespectGeometry( bool allowRectification )
631 if ( GetJacobianRectificationRespectGeometry() != allowRectification )
633 SetOptionValue("jacobian_rectification_respect_geometry", allowRectification ? "yes" : "no" );
634 NotifySubMeshesHypothesisModification();
637 //=============================================================================
638 bool BLSURFPlugin_Hypothesis::GetJacobianRectificationRespectGeometry()
640 return ToBool( GetOptionValue("jacobian_rectification_respect_geometry", GET_DEFAULT()));
642 //=============================================================================
644 void BLSURFPlugin_Hypothesis::SetJacobianRectification( bool allowRectification )
646 if ( GetJacobianRectification() != allowRectification )
648 SetOptionValue( "rectify_jacobian", allowRectification ? "yes" : "no" );
649 NotifySubMeshesHypothesisModification();
652 //=============================================================================
653 bool BLSURFPlugin_Hypothesis::GetJacobianRectification()
655 return ToBool( GetOptionValue("rectify_jacobian", GET_DEFAULT()));
657 //=============================================================================
659 void BLSURFPlugin_Hypothesis::SetUseDeprecatedPatchMesher( bool /*useDeprecatedPatchMesher*/ )
661 // if ( GetUseDeprecatedPatchMesher() != useDeprecatedPatchMesher )
663 // SetOptionValue( "use_deprecated_patch_mesher", useDeprecatedPatchMesher ? "yes" : "no" );
664 // NotifySubMeshesHypothesisModification();
667 //=============================================================================
668 bool BLSURFPlugin_Hypothesis::GetUseDeprecatedPatchMesher()
670 return false;//ToBool( GetOptionValue("use_deprecated_patch_mesher", GET_DEFAULT()));
672 //=============================================================================
674 void BLSURFPlugin_Hypothesis::SetMaxNumberOfPointsPerPatch( int nb )
676 #if MESHGEMS_VERSION_HEX < 0x020A00
677 // Deprecated since MeshGems 2.10
679 throw std::invalid_argument( SMESH_Comment("Invalid number of points: ") << nb );
681 if ( GetMaxNumberOfPointsPerPatch() != nb )
683 SetOptionValue("max_number_of_points_per_patch", SMESH_Comment( nb ));
684 NotifySubMeshesHypothesisModification();
687 (void)nb; // maybe unused
690 //=============================================================================
691 int BLSURFPlugin_Hypothesis::GetMaxNumberOfPointsPerPatch()
693 #if MESHGEMS_VERSION_HEX < 0x020A00
694 // Deprecated since MeshGems 2.10
695 return ToInt( GetOptionValue("max_number_of_points_per_patch", GET_DEFAULT()));
700 //=============================================================================
702 void BLSURFPlugin_Hypothesis::SetMaxNumberOfThreads( int nb )
705 throw std::invalid_argument( SMESH_Comment("Invalid number of threads: ") << nb );
707 if ( GetMaxNumberOfThreads() != nb )
709 SetOptionValue("max_number_of_threads", SMESH_Comment( nb ));
710 NotifySubMeshesHypothesisModification();
713 //=============================================================================
714 int BLSURFPlugin_Hypothesis::GetMaxNumberOfThreads()
716 return ToInt( GetOptionValue("max_number_of_threads", GET_DEFAULT()));
718 //=============================================================================
720 void BLSURFPlugin_Hypothesis::SetRespectGeometry( bool toRespect )
722 if ( GetRespectGeometry() != toRespect )
724 SetOptionValue("respect_geometry", toRespect ? "yes" : "no" );
725 NotifySubMeshesHypothesisModification();
728 //=============================================================================
729 bool BLSURFPlugin_Hypothesis::GetRespectGeometry()
731 return ToBool( GetOptionValue( "respect_geometry", GET_DEFAULT()));
733 //=============================================================================
735 void BLSURFPlugin_Hypothesis::SetTinyEdgesAvoidSurfaceIntersections( bool toAvoidIntersection )
737 if ( GetTinyEdgesAvoidSurfaceIntersections() != toAvoidIntersection )
739 SetOptionValue("tiny_edge_avoid_surface_intersections", toAvoidIntersection ? "yes" : "no" );
740 NotifySubMeshesHypothesisModification();
743 //=============================================================================
744 bool BLSURFPlugin_Hypothesis::GetTinyEdgesAvoidSurfaceIntersections()
746 return ToBool( GetOptionValue("tiny_edge_avoid_surface_intersections", GET_DEFAULT()));
748 //=============================================================================
750 void BLSURFPlugin_Hypothesis::SetClosedGeometry( bool isClosed )
752 if ( GetClosedGeometry() != isClosed )
754 SetPreCADOptionValue("closed_geometry", isClosed ? "yes" : "no" );
755 NotifySubMeshesHypothesisModification();
758 //=============================================================================
759 bool BLSURFPlugin_Hypothesis::GetClosedGeometry()
761 return ToBool( GetPreCADOptionValue( "closed_geometry", GET_DEFAULT()));
763 //=============================================================================
765 void BLSURFPlugin_Hypothesis::SetDebug( bool isDebug )
767 if ( GetDebug() != isDebug )
769 SetPreCADOptionValue("debug", isDebug ? "yes" : "no" );
770 NotifySubMeshesHypothesisModification();
773 //=============================================================================
774 bool BLSURFPlugin_Hypothesis::GetDebug()
776 return ToBool( GetPreCADOptionValue("debug", GET_DEFAULT()));
778 //=============================================================================
780 void BLSURFPlugin_Hypothesis::SetPeriodicTolerance( CORBA::Double tol )
783 throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
784 if ( GetPeriodicTolerance() != tol )
786 SetPreCADOptionValue("periodic_tolerance", SMESH_Comment( tol ) );
787 NotifySubMeshesHypothesisModification();
790 //=============================================================================
791 double BLSURFPlugin_Hypothesis::GetPeriodicTolerance()
793 return ToDbl( GetPreCADOptionValue( "periodic_tolerance", GET_DEFAULT()));
795 //=============================================================================
797 void BLSURFPlugin_Hypothesis::SetRequiredEntities( const std::string& howToTreat )
799 if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear" )
800 throw std::invalid_argument
801 ( SMESH_Comment("required_entities must be in ['respect','ignore','clear'] "));
803 if ( GetRequiredEntities() != howToTreat )
805 SetPreCADOptionValue("required_entities", howToTreat );
806 NotifySubMeshesHypothesisModification();
809 //=============================================================================
810 std::string BLSURFPlugin_Hypothesis::GetRequiredEntities()
812 return GetPreCADOptionValue("required_entities", GET_DEFAULT());
814 //=============================================================================
816 void BLSURFPlugin_Hypothesis::SetSewingTolerance( CORBA::Double tol )
819 throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
820 if ( GetSewingTolerance() != tol )
822 SetPreCADOptionValue("sewing_tolerance", SMESH_Comment( tol ) );
823 NotifySubMeshesHypothesisModification();
826 //=============================================================================
827 CORBA::Double BLSURFPlugin_Hypothesis::GetSewingTolerance()
829 return ToDbl( GetPreCADOptionValue("sewing_tolerance", GET_DEFAULT()));
831 //=============================================================================
833 void BLSURFPlugin_Hypothesis::SetTags( const std::string& howToTreat )
835 if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear" )
836 throw std::invalid_argument
837 ( SMESH_Comment("'tags' must be in ['respect','ignore','clear'] "));
839 if ( GetTags() != howToTreat )
841 SetPreCADOptionValue("tags", howToTreat );
842 NotifySubMeshesHypothesisModification();
845 //=============================================================================
846 std::string BLSURFPlugin_Hypothesis::GetTags()
848 return GetPreCADOptionValue("tags", GET_DEFAULT());
851 //=============================================================================
852 void BLSURFPlugin_Hypothesis::SetHyperPatches(const THyperPatchList& hpl, bool notifyMesh)
854 if ( hpl != _hyperPatchList )
856 // join patches sharing tags
857 _hyperPatchList.clear();
858 for ( size_t i = 0; i < hpl.size(); ++i )
860 const THyperPatchTags& tags = hpl[i];
861 if ( tags.size() < 2 ) continue;
863 std::set<int> iPatches;
864 if ( !_hyperPatchList.empty() )
866 THyperPatchTags::iterator t = tags.begin();
867 for ( ; t != tags.end(); ++t )
870 GetHyperPatchTag( *t, this, &iPatch );
872 iPatches.insert( iPatch );
876 if ( iPatches.empty() )
878 _hyperPatchList.push_back( tags );
882 std::set<int>::iterator iPatch = iPatches.begin();
883 THyperPatchTags& mainPatch = _hyperPatchList[ *iPatch ];
884 mainPatch.insert( tags.begin(), tags.end() );
886 for ( ++iPatch; iPatch != iPatches.end(); ++iPatch )
888 mainPatch.insert( _hyperPatchList[ *iPatch ].begin(), _hyperPatchList[ *iPatch ].end() );
889 _hyperPatchList[ *iPatch ].clear();
891 if ( iPatches.size() > 1 )
892 for ( int j = (int) _hyperPatchList.size()-1; j > 0; --j )
893 if ( _hyperPatchList[j].empty() )
894 _hyperPatchList.erase( _hyperPatchList.begin() + j );
898 NotifySubMeshesHypothesisModification();
901 //=============================================================================
902 void BLSURFPlugin_Hypothesis::SetHyperPatches(const THyperPatchEntriesList& hpel)
904 if ( hpel != _hyperPatchEntriesList )
906 _hyperPatchEntriesList = hpel;
907 _hyperPatchList.clear();
909 NotifySubMeshesHypothesisModification();
912 //================================================================================
914 * \brief Set _hyperPatchList by _hyperPatchEntriesList
916 //================================================================================
918 void BLSURFPlugin_Hypothesis::
919 SetHyperPatchIDsByEntry( const TopoDS_Shape& mainShape,
920 const std::map< std::string, TopoDS_Shape >& entryToShape)
922 _hyperPatchList.clear();
923 if ( _hyperPatchEntriesList.empty() || mainShape.IsNull() )
926 _hyperPatchList.resize( _hyperPatchEntriesList.size() );
928 TopTools_IndexedMapOfShape shapeMap;
929 TopExp::MapShapes( mainShape, shapeMap );
931 for ( size_t i = 0; i < _hyperPatchEntriesList.size(); ++i )
933 THyperPatchTags & idsList = _hyperPatchList [ i ];
934 const THyperPatchEntries & entryList = _hyperPatchEntriesList[ i ];
935 for ( const std::string & entry : entryList )
937 auto e2sIt = entryToShape.find( entry );
938 if ( e2sIt != entryToShape.end() )
940 for ( TopExp_Explorer fExp( e2sIt->second, TopAbs_FACE ); fExp.More(); fExp.Next() )
942 int id = shapeMap.FindIndex( fExp.Current() );
944 idsList.insert( id );
950 hpl.swap( _hyperPatchList );
951 SetHyperPatches( hpl, /*notifyMesh=*/false );
954 //=============================================================================
956 * \brief Return a tag of a face taking into account the hyper-patches. Optionally
957 * return an index of a patch including the face
959 //================================================================================
961 int BLSURFPlugin_Hypothesis::GetHyperPatchTag( const int faceTag,
962 const BLSURFPlugin_Hypothesis* hyp,
967 const THyperPatchList& hpl = hyp->_hyperPatchList;
968 for ( size_t i = 0; i < hpl.size(); ++i )
969 if ( hpl[i].count( faceTag ))
971 if ( iPatch ) *iPatch = (int) i;
972 return *( hpl[i].begin() );
977 //=============================================================================
978 void BLSURFPlugin_Hypothesis::SetPreCADMergeEdges(bool theVal)
980 if (theVal != ToBool( GetPreCADOptionValue("merge_edges", GET_DEFAULT()))) {
981 _preCADMergeEdges = theVal;
982 SetPreCADOptionValue("merge_edges", theVal ? "yes" : "no" );
983 NotifySubMeshesHypothesisModification();
987 //=============================================================================
988 void BLSURFPlugin_Hypothesis::SetPreCADRemoveDuplicateCADFaces(bool theVal)
990 if (theVal != ToBool( GetPreCADOptionValue("remove_duplicate_cad_faces", GET_DEFAULT()))) {
991 _preCADRemoveDuplicateCADFaces = theVal;
992 SetPreCADOptionValue("remove_duplicate_cad_faces", theVal ? "yes" : "no" );
993 NotifySubMeshesHypothesisModification();
997 //=============================================================================
998 void BLSURFPlugin_Hypothesis::SetPreCADProcess3DTopology(bool theVal)
1000 if (theVal != ToBool( GetPreCADOptionValue("process_3d_topology", GET_DEFAULT()))) {
1001 _preCADProcess3DTopology = theVal;
1002 SetPreCADOptionValue("process_3d_topology", theVal ? "yes" : "no" );
1003 NotifySubMeshesHypothesisModification();
1007 //=============================================================================
1008 void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal)
1010 if (theVal != ToBool( GetPreCADOptionValue("discard_input_topology", GET_DEFAULT()))) {
1011 _preCADDiscardInput = theVal;
1012 SetPreCADOptionValue("discard_input_topology", theVal ? "yes" : "no" );
1013 NotifySubMeshesHypothesisModification();
1017 //=============================================================================
1018 // Return true if any PreCAD option is activated
1019 bool BLSURFPlugin_Hypothesis::HasPreCADOptions(const BLSURFPlugin_Hypothesis* hyp)
1021 if ( !hyp || hyp->_name == GetHypType(/*hasgeom=*/false))
1025 bool orDefault, isOk;
1026 return ( ToBool( hyp->GetPreCADOptionValue("closed_geometry" , &orDefault )) ||
1027 ToBool( hyp->GetPreCADOptionValue("discard_input_topology" , &orDefault )) ||
1028 ToBool( hyp->GetPreCADOptionValue("merge_edges" , &orDefault )) ||
1029 ToBool( hyp->GetPreCADOptionValue("remove_duplicate_cad_faces", &orDefault )) ||
1030 ToBool( hyp->GetPreCADOptionValue("process_3d_topology" , &orDefault )) ||
1031 ToBool( hyp->GetPreCADOption ("manifold_geometry") , &isOk ) ||
1032 hyp->GetPreCADOptionValue("sewing_tolerance", &orDefault ) != "5e-4*D" ||
1033 !hyp->_preCadFacesPeriodicityVector.empty() ||
1034 !hyp->_preCadEdgesPeriodicityVector.empty() ||
1035 !hyp->_facesPeriodicityVector.empty() ||
1036 !hyp->_edgesPeriodicityVector.empty() ||
1037 !hyp->_verticesPeriodicityVector.empty() ||
1038 !hyp->GetHyperPatches().empty() ||
1039 hyp->GetTopology() != FromCAD );
1042 //=============================================================================
1043 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
1044 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
1046 _GMFFileName = theFileName;
1047 // _GMFFileMode = isBinary;
1048 NotifySubMeshesHypothesisModification();
1051 //=============================================================================
1052 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
1054 TOptionValues::iterator op_val = _option2value.find(optionName);
1055 if (op_val == _option2value.end())
1057 op_val = _preCADoption2value.find(optionName);
1058 if (op_val == _preCADoption2value.end())
1060 std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'. Try SetAdvancedOption()";
1061 throw std::invalid_argument(msg);
1064 if (op_val->second != optionValue)
1066 const char* ptr = optionValue.c_str();
1067 // strip white spaces
1068 while (ptr[0] == ' ')
1070 size_t i = strlen(ptr);
1071 while (i != 0 && ptr[i - 1] == ' ')
1075 std::string typeName;
1078 } else if (_charOptions.count(optionName)) {
1079 // do not check strings
1080 } else if (_doubleOptions.count(optionName)) {
1081 // check if value is double
1082 ToDbl(ptr, &typeOk);
1084 } else if (_boolOptions.count(optionName)) {
1085 // check if value is bool
1086 ToBool(ptr, &typeOk);
1089 // check if value is int
1090 ToInt(ptr, &typeOk);
1091 typeName = "integer";
1094 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
1095 throw std::invalid_argument(msg);
1097 std::string value( ptr, i );
1098 if ( _defaultOptionValues[ optionName ] == value )
1101 op_val->second = value;
1103 NotifySubMeshesHypothesisModification();
1107 //=============================================================================
1108 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
1110 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
1111 if (op_val == _preCADoption2value.end()) {
1112 op_val = _option2value.find(optionName);
1113 if (op_val == _option2value.end()) {
1114 std::string msg = "Unknown MG-PreCAD option: '" + optionName + "'. Try SetAdvancedOption()";
1115 throw std::invalid_argument(msg);
1118 if (op_val->second != optionValue)
1120 const char* ptr = optionValue.c_str();
1121 // strip white spaces
1122 while (ptr[0] == ' ')
1124 size_t i = strlen(ptr);
1125 while (i != 0 && ptr[i - 1] == ' ')
1129 std::string typeName;
1132 } else if (_preCADcharOptions.find(optionName) != _preCADcharOptions.end()) {
1133 // do not check strings
1134 } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
1135 // check if value is double
1137 strtod(ptr, &endPtr);
1138 typeOk = (ptr != endPtr);
1140 } else if (_boolOptions.count(optionName)) {
1141 // check if value is bool
1142 ToBool(ptr, &typeOk);
1145 // check if value is int
1147 strtol(ptr, &endPtr, 10);
1148 typeOk = (ptr != endPtr);
1149 typeName = "integer";
1152 std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
1153 throw std::invalid_argument(msg);
1155 std::string value( ptr, i );
1156 if ( _defaultOptionValues[ optionName ] == value )
1159 op_val->second = value;
1161 NotifySubMeshesHypothesisModification();
1165 //=============================================================================
1166 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
1167 bool* isDefault) const
1169 TOptionValues::const_iterator op_val = _option2value.find(optionName);
1170 if (op_val == _option2value.end())
1172 op_val = _preCADoption2value.find(optionName);
1173 if (op_val == _preCADoption2value.end())
1175 op_val = _customOption2value.find(optionName);
1176 if (op_val == _customOption2value.end())
1178 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
1179 throw std::invalid_argument(msg);
1183 std::string val = op_val->second;
1184 if ( isDefault ) *isDefault = ( val.empty() );
1186 if ( val.empty() && isDefault )
1188 op_val = _defaultOptionValues.find( optionName );
1189 if (op_val != _defaultOptionValues.end())
1190 val = op_val->second;
1195 //=============================================================================
1196 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName,
1197 bool* isDefault) const
1199 TOptionValues::const_iterator op_val = _preCADoption2value.find(optionName);
1200 if (op_val == _preCADoption2value.end())
1202 op_val = _option2value.find(optionName);
1203 if (op_val == _option2value.end())
1205 op_val = _customOption2value.find(optionName);
1206 if (op_val == _customOption2value.end())
1208 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
1209 throw std::invalid_argument(msg);
1213 std::string val = op_val->second;
1214 if ( isDefault ) *isDefault = ( val.empty() );
1216 if ( val.empty() && isDefault )
1218 op_val = _defaultOptionValues.find( optionName );
1219 if (op_val != _option2value.end())
1220 val = op_val->second;
1225 //=============================================================================
1226 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
1228 TOptionValues::iterator op_val = _customOption2value.find(optionName);
1229 if (op_val != _customOption2value.end())
1230 _customOption2value.erase(op_val);
1232 op_val = _option2value.find(optionName);
1233 if (op_val != _option2value.end())
1234 op_val->second.clear();
1236 op_val = _preCADoption2value.find(optionName);
1237 if (op_val != _preCADoption2value.end())
1238 op_val->second.clear();
1243 //=============================================================================
1244 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName)
1246 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
1247 if (op_val != _preCADoption2value.end())
1248 op_val->second.clear();
1251 //=============================================================================
1252 void BLSURFPlugin_Hypothesis::AddOption(const std::string& optionName, const std::string& optionValue)
1255 TOptionValues::iterator op_val = _option2value.find(optionName);
1256 if (op_val != _option2value.end())
1258 if (op_val->second != optionValue)
1259 op_val->second = optionValue;
1265 op_val = _preCADoption2value.find(optionName);
1266 if (op_val != _preCADoption2value.end())
1268 if (op_val->second != optionValue)
1269 op_val->second = optionValue;
1273 else if ( optionValue.empty() )
1275 _customOption2value.erase( optionName );
1279 op_val = _customOption2value.find(optionName);
1280 if (op_val == _customOption2value.end())
1281 _customOption2value[optionName] = optionValue;
1282 else if (op_val->second != optionValue)
1283 op_val->second = optionValue;
1289 NotifySubMeshesHypothesisModification();
1292 //=============================================================================
1293 void BLSURFPlugin_Hypothesis::AddPreCADOption(const std::string& optionName, const std::string& optionValue)
1295 AddOption( optionName, optionValue );
1298 //=============================================================================
1299 std::string BLSURFPlugin_Hypothesis::GetOption(const std::string& optionName) const
1301 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1302 if (op_val != _customOption2value.end())
1303 return op_val->second;
1308 //=============================================================================
1309 std::string BLSURFPlugin_Hypothesis::GetPreCADOption(const std::string& optionName) const
1311 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1312 if (op_val != _customOption2value.end())
1313 return op_val->second;
1318 //=============================================================================
1319 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetOptionValues() const
1322 TOptionValues::const_iterator op_val = _option2value.begin();
1323 for ( ; op_val != _option2value.end(); ++op_val )
1324 vals.insert( make_pair( op_val->first, GetOptionValue( op_val->first, GET_DEFAULT() )));
1329 //=============================================================================
1330 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetPreCADOptionValues() const
1333 TOptionValues::const_iterator op_val = _preCADoption2value.begin();
1334 for ( ; op_val != _preCADoption2value.end(); ++op_val )
1335 vals.insert( make_pair( op_val->first, GetPreCADOptionValue( op_val->first, GET_DEFAULT() )));
1340 //=======================================================================
1341 //function : SetSizeMapEntry
1342 //=======================================================================
1343 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
1344 if (_sizeMap[entry].compare(sizeMap) != 0) {
1345 SetPhysicalMesh(PhysicalLocalSize);
1346 _sizeMap[entry] = sizeMap;
1347 NotifySubMeshesHypothesisModification();
1351 //=======================================================================
1352 //function : GetSizeMapEntry
1353 //=======================================================================
1354 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
1355 TSizeMap::iterator it = _sizeMap.find(entry);
1356 if (it != _sizeMap.end())
1359 return "No_Such_Entry";
1363 * \brief Return the size maps
1365 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
1366 return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
1369 //=======================================================================
1370 //function : SetAttractorEntry
1371 //=======================================================================
1372 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
1373 if (_attractors[entry].compare(attractor) != 0) {
1374 SetPhysicalMesh(PhysicalLocalSize);
1375 _attractors[entry] = attractor;
1376 NotifySubMeshesHypothesisModification();
1380 //=======================================================================
1381 //function : GetAttractorEntry
1382 //=======================================================================
1383 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
1384 TSizeMap::iterator it = _attractors.find(entry);
1385 if (it != _attractors.end())
1388 return "No_Such_Entry";
1392 * \brief Return the attractors
1394 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
1395 return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
1398 //=======================================================================
1399 //function : SetClassAttractorEntry
1400 //=======================================================================
1401 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
1403 SetPhysicalMesh(PhysicalLocalSize);
1405 // The new attractor can't be defined on the same face as another sizemap
1406 TSizeMap::iterator it = _sizeMap.find( entry );
1407 if ( it != _sizeMap.end() ) {
1409 NotifySubMeshesHypothesisModification();
1412 TSizeMap::iterator itAt = _attractors.find( entry );
1413 if ( itAt != _attractors.end() ) {
1414 _attractors.erase(itAt);
1415 NotifySubMeshesHypothesisModification();
1419 const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
1420 const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
1421 TAttractorMap::iterator attIt = _classAttractors.find(entry);
1422 for ( ; attIt != _classAttractors.end(); ++attIt )
1423 if ( attIt->first == entry &&
1424 attIt->second->GetAttractorEntry() == attEntry )
1426 bool attExists = (attIt != _classAttractors.end());
1428 BLSURFPlugin_Attractor* myAttractor;
1430 myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 );
1431 _classAttractors.insert( make_pair( entry, myAttractor ));
1434 myAttractor = attIt->second;
1436 // if (!myAttractor->IsMapBuilt())
1437 // myAttractor->BuildMap();
1438 myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
1440 NotifySubMeshesHypothesisModification();
1443 //=======================================================================
1444 //function : SetConstantSizeOnAdjacentFaces
1445 //=======================================================================
1446 // TODO uncomment and test (include the needed .hxx)
1447 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist ) {
1448 // TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
1449 // TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
1450 // TopTools_IndexedMapOfShapListOdShape::iterator it;
1451 // for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
1452 // SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
1460 //=======================================================================
1461 //function : GetClassAttractorEntry
1462 //=======================================================================
1463 // BLSURFPlugin_Attractor& BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
1465 // TAttractorMap::iterator it = _classAttractors.find( entry );
1466 // if ( it != _classAttractors.end() )
1467 // return it->second;
1469 // return "No_Such_Entry";
1473 * \brief Return the map of attractor instances
1475 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
1477 return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
1480 //=======================================================================
1481 //function : ClearEntry
1482 //=======================================================================
1483 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
1484 const char * attEntry/*=0*/)
1486 TSizeMap::iterator it = _sizeMap.find( entry );
1488 if ( it != _sizeMap.end() ) {
1490 NotifySubMeshesHypothesisModification();
1493 TSizeMap::iterator itAt = _attractors.find( entry );
1494 if ( itAt != _attractors.end() ) {
1495 _attractors.erase(itAt);
1496 NotifySubMeshesHypothesisModification();
1499 TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
1500 if ( it_clAt != _classAttractors.end() ) {
1502 if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
1503 _classAttractors.erase( it_clAt++ );
1507 while ( it_clAt != _classAttractors.end() );
1508 NotifySubMeshesHypothesisModification();
1511 std::cout<<"No_Such_Entry"<<std::endl;
1516 //=======================================================================
1517 //function : ClearSizeMaps
1518 //=======================================================================
1519 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
1521 _attractors.clear();
1522 _classAttractors.clear();
1525 // Enable internal enforced vertices on specific face if requested by user
1527 ////=======================================================================
1528 ////function : SetInternalEnforcedVertex
1529 ////=======================================================================
1530 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
1531 // bool toEnforceInternalVertices,
1532 // TEnfGroupName theGroupName) {
1534 // << toEnforceInternalVertices << ", " << theGroupName << ")");
1536 // TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
1537 // if (it != _faceEntryInternalVerticesList.end()) {
1538 // if (!toEnforceInternalVertices) {
1539 // _faceEntryInternalVerticesList.erase(it);
1543 // if (toEnforceInternalVertices) {
1544 // _faceEntryInternalVerticesList.insert(theFaceEntry);
1549 // // Take care of groups
1553 //=======================================================================
1554 //function : SetEnforcedVertex
1555 //=======================================================================
1556 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry,
1557 TEnfName theVertexName,
1558 TEntry theVertexEntry,
1559 TEnfGroupName theGroupName,
1560 double x, double y, double z)
1562 SetPhysicalMesh(PhysicalLocalSize);
1564 bool toNotify = false;
1565 bool toCreate = true;
1567 TEnfVertex *oldEnVertex;
1568 TEnfVertex *newEnfVertex = new TEnfVertex();
1569 newEnfVertex->name = theVertexName;
1570 newEnfVertex->geomEntry = theVertexEntry;
1571 newEnfVertex->coords.clear();
1572 if (theVertexEntry == "") {
1573 newEnfVertex->coords.push_back(x);
1574 newEnfVertex->coords.push_back(y);
1575 newEnfVertex->coords.push_back(z);
1577 newEnfVertex->grpName = theGroupName;
1578 newEnfVertex->faceEntries.clear();
1579 newEnfVertex->faceEntries.insert(theFaceEntry);
1582 // update _enfVertexList
1583 TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
1584 if (it != _enfVertexList.end()) {
1586 oldEnVertex = (*it);
1587 if (oldEnVertex->name != theVertexName) {
1588 oldEnVertex->name = theVertexName;
1591 if (oldEnVertex->grpName != theGroupName) {
1592 oldEnVertex->grpName = theGroupName;
1595 TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
1596 if (it_faceEntries == oldEnVertex->faceEntries.end()) {
1597 oldEnVertex->faceEntries.insert(theFaceEntry);
1598 _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
1602 // update map coords / enf vertex if needed
1603 if (oldEnVertex->coords.size()) {
1604 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
1605 _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
1608 // update map geom entry / enf vertex if needed
1609 if (oldEnVertex->geomEntry != "") {
1610 _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
1611 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
1616 // //////// CREATE ////////////
1619 AddEnforcedVertex( theFaceEntry, newEnfVertex );
1622 delete newEnfVertex;
1626 NotifySubMeshesHypothesisModification();
1631 //=======================================================================
1632 //function : AddEnforcedVertex
1633 //=======================================================================
1635 void BLSURFPlugin_Hypothesis::AddEnforcedVertex( const TEntry& faceEntry,
1636 TEnfVertex * newEnfVertex )
1640 _faceEntryEnfVertexListMap[faceEntry].insert(newEnfVertex);
1641 _enfVertexList.insert(newEnfVertex);
1642 if ( newEnfVertex->geomEntry.empty() ) {
1643 _faceEntryCoordsListMap[faceEntry].insert(newEnfVertex->coords);
1644 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
1647 _faceEntryEnfVertexEntryListMap[faceEntry].insert(newEnfVertex->geomEntry);
1648 _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
1653 //=======================================================================
1654 //function : GetEnforcedVertices
1655 //=======================================================================
1657 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
1659 if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
1660 return _faceEntryEnfVertexListMap[theFaceEntry];
1662 return GetDefaultEnfVertexList();
1664 std::ostringstream msg;
1665 msg << "No enforced vertex for face entry " << theFaceEntry;
1666 throw std::invalid_argument(msg.str());
1669 //=======================================================================
1670 //function : GetEnfVertexCoordsList
1671 //=======================================================================
1673 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(const TEntry& theFaceEntry)
1675 if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
1676 return _faceEntryCoordsListMap[theFaceEntry];
1678 std::ostringstream msg;
1679 msg << "No enforced vertex coords for face entry " << theFaceEntry;
1680 throw std::invalid_argument(msg.str());
1683 //=======================================================================
1684 //function : GetEnfVertexEntryList
1685 //=======================================================================
1687 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
1689 if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
1690 return _faceEntryEnfVertexEntryListMap[theFaceEntry];
1692 std::ostringstream msg;
1693 msg << "No enforced vertex entry for face entry " << theFaceEntry;
1694 throw std::invalid_argument(msg.str());
1697 //=======================================================================
1698 //function : GetEnfVertex(TEnfVertexCoords coords)
1699 //=======================================================================
1701 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
1703 if (_coordsEnfVertexMap.count(coords) > 0)
1704 return _coordsEnfVertexMap[coords];
1706 std::ostringstream msg;
1707 msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
1708 throw std::invalid_argument(msg.str());
1711 //=======================================================================
1712 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
1713 //=======================================================================
1715 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
1717 if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
1718 return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
1720 std::ostringstream msg;
1721 msg << "No enforced vertex with entry " << theEnfVertexEntry;
1722 throw std::invalid_argument(msg.str());
1725 //Enable internal enforced vertices on specific face if requested by user
1726 ////=======================================================================
1727 ////function : GetInternalEnforcedVertex
1728 ////=======================================================================
1730 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
1732 // if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
1737 //=======================================================================
1738 //function : ClearEnforcedVertex
1739 //=======================================================================
1741 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry,
1742 double x, double y, double z,
1743 const TEntry& theVertexEntry)
1745 bool toNotify = false;
1746 std::ostringstream msg;
1747 TEnfVertex *oldEnfVertex;
1748 TEnfVertexCoords coords;
1750 coords.push_back(x);
1751 coords.push_back(y);
1752 coords.push_back(z);
1754 // check that enf vertex with given enf vertex entry exists
1755 TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
1756 if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
1758 oldEnfVertex = it_enfVertexEntry->second;
1760 _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
1762 TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
1763 enfVertexEntryList.erase(theVertexEntry);
1764 if (enfVertexEntryList.size() == 0)
1765 _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
1766 // TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1767 // TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
1768 // it_entry_entry->second.erase(it_entryList);
1769 // if (it_entry_entry->second.size() == 0)
1770 // _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1773 MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
1774 msg << "No enforced vertex with geom entry " << theVertexEntry;
1775 // check that enf vertex with given coords exists
1776 TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
1777 if (it_coords_enf != _coordsEnfVertexMap.end()) {
1779 oldEnfVertex = it_coords_enf->second;
1781 _coordsEnfVertexMap.erase(it_coords_enf);
1783 TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
1784 enfVertexCoordsList.erase(coords);
1785 if (enfVertexCoordsList.size() == 0)
1786 _faceEntryCoordsListMap.erase(theFaceEntry);
1787 // TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1788 // TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
1789 // it_entry_coords->second.erase(it_coordsList);
1790 // if (it_entry_coords->second.size() == 0)
1791 // _faceEntryCoordsListMap.erase(it_entry_coords);
1794 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
1796 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
1797 throw std::invalid_argument(msg.str());
1801 // update _enfVertexList
1802 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1803 if (it != _enfVertexList.end()) {
1804 (*it)->faceEntries.erase(theFaceEntry);
1805 if ((*it)->faceEntries.size() == 0){
1806 _enfVertexList.erase(it);
1811 // update _faceEntryEnfVertexListMap
1812 TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
1813 currentEnfVertexList.erase(oldEnfVertex);
1815 if (currentEnfVertexList.size() == 0) {
1816 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1820 NotifySubMeshesHypothesisModification();
1825 //=======================================================================
1826 //function : ClearEnforcedVertices
1827 //=======================================================================
1829 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry)
1831 bool toNotify = false;
1832 TEnfVertex *oldEnfVertex;
1834 TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1835 if (it_entry_coords != _faceEntryCoordsListMap.end()) {
1837 TEnfVertexCoordsList coordsList = it_entry_coords->second;
1838 TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
1839 for (; it_coordsList != coordsList.end(); ++it_coordsList) {
1840 TEnfVertexCoords coords = (*it_coordsList);
1841 oldEnfVertex = _coordsEnfVertexMap[coords];
1842 _coordsEnfVertexMap.erase(coords);
1843 // update _enfVertexList
1844 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1845 if (it != _enfVertexList.end()) {
1846 (*it)->faceEntries.erase(theFaceEntry);
1847 if ((*it)->faceEntries.size() == 0){
1848 _enfVertexList.erase(it);
1853 _faceEntryCoordsListMap.erase(it_entry_coords);
1854 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1857 TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1858 if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
1860 TEntryList enfVertexEntryList = it_entry_entry->second;
1861 TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
1862 for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
1863 TEntry enfVertexEntry = (*it_enfVertexEntryList);
1864 oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
1865 _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
1866 // update _enfVertexList
1867 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1868 if (it != _enfVertexList.end()) {
1869 (*it)->faceEntries.erase(theFaceEntry);
1870 if ((*it)->faceEntries.size() == 0){
1871 _enfVertexList.erase(it);
1876 _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1877 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1881 NotifySubMeshesHypothesisModification();
1884 // std::ostringstream msg;
1885 // msg << "No enforced vertex for " << theFaceEntry;
1886 // throw std::invalid_argument(msg.str());
1889 //=======================================================================
1890 //function : ClearAllEnforcedVertices
1891 //=======================================================================
1892 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices()
1894 _faceEntryEnfVertexListMap.clear();
1895 _faceEntryCoordsListMap.clear();
1896 _coordsEnfVertexMap.clear();
1897 _faceEntryEnfVertexEntryListMap.clear();
1898 _enfVertexEntryEnfVertexMap.clear();
1900 TEnfVertexList::iterator it_enfVertex = _enfVertexList.begin();
1901 for ( ; it_enfVertex != _enfVertexList.end(); ++it_enfVertex )
1902 delete *it_enfVertex;
1903 _enfVertexList.clear();
1905 // Enable internal enforced vertices on specific face if requested by user
1906 // _faceEntryInternalVerticesList.clear();
1907 NotifySubMeshesHypothesisModification();
1911 //================================================================================
1913 * \brief Return the enforced vertices
1915 //================================================================================
1918 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1919 const BLSURFPlugin_Hypothesis* hyp)
1921 return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1924 //Enable internal enforced vertices on specific face if requested by user
1925 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1926 // const BLSURFPlugin_Hypothesis* hyp) {
1927 // return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1930 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1932 return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1935 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1937 return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1940 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1941 const BLSURFPlugin_Hypothesis* hyp)
1943 return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1946 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1947 const BLSURFPlugin_Hypothesis* hyp)
1949 return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1952 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1953 const BLSURFPlugin_Hypothesis* hyp)
1955 return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1958 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1959 const BLSURFPlugin_Hypothesis* hyp)
1961 return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1964 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1965 const BLSURFPlugin_Hypothesis* hyp)
1967 return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1970 std::set<smIdType> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName)
1972 TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1973 if (it != _groupNameNodeIDMap.end()) {
1976 std::ostringstream msg;
1977 msg << "No group " << theGroupName;
1978 throw std::invalid_argument(msg.str());
1981 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,smIdType theNodeID)
1983 _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1986 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,smIdType theNodeID)
1988 TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1989 if (it != _groupNameNodeIDMap.end()) {
1990 std::set<smIdType>::iterator IDit = it->second.find(theNodeID);
1991 if (IDit != it->second.end())
1992 it->second.erase(IDit);
1993 std::ostringstream msg;
1994 msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1995 throw std::invalid_argument(msg.str());
1997 std::ostringstream msg;
1998 msg << "No group " << theGroupName;
1999 throw std::invalid_argument(msg.str());
2003 //=============================================================================
2004 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices)
2006 if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
2007 _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
2008 if (toEnforceInternalVertices)
2009 SetPhysicalMesh(PhysicalLocalSize);
2010 NotifySubMeshesHypothesisModification();
2015 //=============================================================================
2016 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName)
2018 if (std::string(theGroupName) != std::string(_enforcedInternalVerticesAllFacesGroup)) {
2019 _enforcedInternalVerticesAllFacesGroup = theGroupName;
2020 NotifySubMeshesHypothesisModification();
2024 //=============================================================================
2025 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
2026 const BLSURFPlugin_Hypothesis* hyp)
2028 return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
2031 //=============================================================================
2032 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
2033 const BLSURFPlugin_Hypothesis* hyp)
2035 return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
2038 //=============================================================================
2039 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
2040 const BLSURFPlugin_Hypothesis* hyp)
2042 return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
2045 //=============================================================================
2046 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
2047 const BLSURFPlugin_Hypothesis* hyp)
2049 return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
2052 //=============================================================================
2053 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
2054 const BLSURFPlugin_Hypothesis* hyp)
2056 return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
2059 //=======================================================================
2060 //function : ClearAllEnforcedVertices
2061 //=======================================================================
2062 void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors()
2064 _preCadFacesPeriodicityVector.clear();
2065 _preCadEdgesPeriodicityVector.clear();
2066 NotifySubMeshesHypothesisModification();
2069 //=======================================================================
2070 //function : AddPreCadFacesPeriodicity
2071 //=======================================================================
2072 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
2073 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries)
2076 TPreCadPeriodicity preCadFacesPeriodicity;
2077 preCadFacesPeriodicity.shape1Entry = theFace1Entry;
2078 preCadFacesPeriodicity.shape2Entry = theFace2Entry;
2079 preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
2080 preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
2082 _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
2084 NotifySubMeshesHypothesisModification();
2087 //=======================================================================
2088 //function : AddPreCadEdgesPeriodicity
2089 //=======================================================================
2090 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
2091 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries)
2093 TPreCadPeriodicity preCadEdgesPeriodicity;
2094 preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
2095 preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
2096 preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
2097 preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
2099 _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
2101 NotifySubMeshesHypothesisModification();
2104 //=============================================================================
2105 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
2107 // We must keep at least the same number of arguments when increasing the SALOME version
2108 // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
2109 // parameter can be written several times to keep the old global number of parameters.
2111 // Treat old options which are now in the advanced options
2112 TOptionValues::iterator op_val;
2114 int _preCADRemoveNanoEdges = -1;
2115 double _preCADEpsNano = -1.0;
2116 op_val = _option2value.find("respect_geometry");
2117 if (op_val != _option2value.end()) {
2118 std::string value = op_val->second;
2120 _decimesh = value.compare("1") == 0 ? 1 : 0;
2122 op_val = _preCADoption2value.find("remove_tiny_edges");
2123 if (op_val != _preCADoption2value.end()) {
2124 std::string value = op_val->second;
2126 _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
2128 op_val = _preCADoption2value.find("tiny_edge_length");
2129 if (op_val != _preCADoption2value.end()) {
2130 std::string value = op_val->second;
2132 _preCADEpsNano = strtod(value.c_str(), NULL);
2135 save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
2136 << _angleMesh << " " << _gradation << " " << (int) _elementType << " " << _decimesh;
2137 save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
2138 save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
2139 save << " " << (int) _enforcedInternalVerticesAllFaces;
2140 save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
2141 save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
2142 save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
2143 save << " " << (int) _preCADProcess3DTopology << " " << (int) _preCADRemoveDuplicateCADFaces;
2144 save << " " << (int)_optimiseTinyEdges << " " << _tinyEdgeOptimisationLength;
2145 save << " " << (int)_correctSurfaceIntersec << " " << _corrSurfaceIntersCost;
2146 save << " " << (int)_useGradation << " " << (int)_useVolumeGradation << " " << _volumeGradation;
2148 op_val = _option2value.begin();
2149 if (op_val != _option2value.end()) {
2150 save << " " << "__OPTIONS_BEGIN__";
2151 for (; op_val != _option2value.end(); ++op_val) {
2152 if (!op_val->second.empty())
2153 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
2155 save << " " << "__OPTIONS_END__";
2158 op_val = _customOption2value.begin();
2159 if (op_val != _customOption2value.end()) {
2160 save << " " << "__CUSTOM_OPTIONS_BEGIN__";
2161 for (; op_val != _customOption2value.end(); ++op_val) {
2162 if (!op_val->second.empty())
2163 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
2165 save << " " << "__CUSTOM_OPTIONS_END__";
2168 op_val = _preCADoption2value.begin();
2169 if (op_val != _preCADoption2value.end()) {
2170 save << " " << "__PRECAD_OPTIONS_BEGIN__";
2171 for (; op_val != _preCADoption2value.end(); ++op_val) {
2172 if (!op_val->second.empty())
2173 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
2175 save << " " << "__PRECAD_OPTIONS_END__";
2178 TSizeMap::iterator it_sm = _sizeMap.begin();
2179 if (it_sm != _sizeMap.end()) {
2180 save << " " << "__SIZEMAP_BEGIN__";
2181 for (; it_sm != _sizeMap.end(); ++it_sm) {
2182 save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
2184 save << " " << "__SIZEMAP_END__";
2187 TSizeMap::iterator it_at = _attractors.begin();
2188 if (it_at != _attractors.end()) {
2189 save << " " << "__ATTRACTORS_BEGIN__";
2190 for (; it_at != _attractors.end(); ++it_at) {
2191 save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
2193 save << " " << "__ATTRACTORS_END__";
2196 TAttractorMap::iterator it_At = _classAttractors.begin();
2197 if (it_At != _classAttractors.end()) {
2198 std::ostringstream test;
2199 save << " " << "__NEW_ATTRACTORS_BEGIN__";
2200 test << " " << "__NEW_ATTRACTORS_BEGIN__";
2201 for (; it_At != _classAttractors.end(); ++it_At) {
2202 std::vector<double> attParams;
2203 attParams = it_At->second->GetParameters();
2204 // double step = it_At->second->GetStep();
2205 save << " " << it_At->first;
2206 save << " " << it_At->second->GetAttractorEntry();
2207 save << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
2208 // save << " " << step;
2209 test << " " << it_At->first;
2210 test << " " << it_At->second->GetAttractorEntry();
2211 test << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
2212 // test << " " << step;
2214 save << " " << "__NEW_ATTRACTORS_END__";
2215 test << " " << "__NEW_ATTRACTORS_END__";
2218 TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
2219 if (it_enf != _enfVertexList.end()) {
2220 save << " " << "__ENFORCED_VERTICES_BEGIN__";
2221 for (; it_enf != _enfVertexList.end(); ++it_enf) {
2222 TEnfVertex *enfVertex = (*it_enf);
2223 save << " " << "__BEGIN_VERTEX__";
2224 if (!enfVertex->name.empty()) {
2225 save << " " << "__BEGIN_NAME__";
2226 save << " " << enfVertex->name;
2227 save << " " << "__END_NAME__";
2229 if (!enfVertex->geomEntry.empty()) {
2230 save << " " << "__BEGIN_ENTRY__";
2231 save << " " << enfVertex->geomEntry;
2232 save << " " << "__END_ENTRY__";
2234 if (!enfVertex->grpName.empty()) {
2235 save << " " << "__BEGIN_GROUP__";
2236 save << " " << enfVertex->grpName;
2237 save << " " << "__END_GROUP__";
2239 if (enfVertex->coords.size()) {
2240 save << " " << "__BEGIN_COORDS__";
2241 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
2242 save << " " << enfVertex->coords[i];
2243 save << " " << "__END_COORDS__";
2245 TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
2246 bool hasFaces = false;
2247 if (faceEntriesIt != enfVertex->faceEntries.end()) {
2249 save << " " << "__BEGIN_FACELIST__";
2251 for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
2252 if ( faceEntriesIt->empty() )
2253 save << " _no_face_";
2255 save << " " << (*faceEntriesIt);
2257 save << " " << "__END_FACELIST__";
2258 save << " " << "__END_VERTEX__";
2260 save << " " << "__ENFORCED_VERTICES_END__";
2265 SavePreCADPeriodicity(save, "FACES");
2266 SavePreCADPeriodicity(save, "EDGES");
2268 SaveFacesPeriodicity(save);
2269 SaveEdgesPeriodicity(save);
2270 SaveVerticesPeriodicity(save);
2273 save << " " << _hyperPatchList.size() << " ";
2274 for ( size_t i = 0; i < _hyperPatchList.size(); ++i )
2276 THyperPatchTags& patch = _hyperPatchList[i];
2277 save << patch.size() << " ";
2278 THyperPatchTags::iterator tag = patch.begin();
2279 for ( ; tag != patch.end(); ++tag )
2280 save << *tag << " ";
2283 // New options in 2.9.6 (issue #17784)
2284 save << " " << _useSurfaceProximity;
2285 save << " " << _nbSurfaceProximityLayers;
2286 save << " " << _surfaceProximityRatio;
2287 save << " " << _useVolumeProximity;
2288 save << " " << _nbVolumeProximityLayers;
2289 save << " " << _volumeProximityRatio;
2291 // hyper-patches as entries
2292 std::ostringstream hpStream;
2293 boost::archive::text_oarchive( hpStream ) << _hyperPatchEntriesList;
2294 std::string hpString = hpStream.str();
2295 save << " " << hpString.size() << " " << hpString;
2301 void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save)
2303 TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
2304 if (it_faces_periodicity != _facesPeriodicityVector.end()) {
2305 save << " " << "__FACES_PERIODICITY_BEGIN__";
2306 for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
2307 TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
2308 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2309 save << " " << "__BEGIN_ENTRY1__";
2310 save << " " << periodicity_i.first;
2311 save << " " << "__END_ENTRY1__";
2312 save << " " << "__BEGIN_ENTRY2__";
2313 save << " " << periodicity_i.second;
2314 save << " " << "__END_ENTRY2__";
2315 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2317 save << " " << "__FACES_PERIODICITY_END__";
2321 void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save)
2323 TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
2324 if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
2325 save << " " << "__EDGES_PERIODICITY_BEGIN__";
2326 for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
2327 TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
2328 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2329 if (! periodicity_i.theFace1Entry.empty()){
2330 save << " " << "__BEGIN_FACE1__";
2331 save << " " << periodicity_i.theFace1Entry;
2332 save << " " << "__END_FACE1__";
2334 save << " " << "__BEGIN_EDGE1__";
2335 save << " " << periodicity_i.theEdge1Entry;
2336 save << " " << "__END_EDGE1__";
2337 if (! periodicity_i.theFace2Entry.empty()){
2338 save << " " << "__BEGIN_FACE2__";
2339 save << " " << periodicity_i.theFace2Entry;
2340 save << " " << "__END_FACE2__";
2342 save << " " << "__BEGIN_EDGE2__";
2343 save << " " << periodicity_i.theEdge2Entry;
2344 save << " " << "__END_EDGE2__";
2345 save << " " << "__BEGIN_EDGE_ORIENTATION__";
2346 save << " " << periodicity_i.edge_orientation;
2347 save << " " << "__END_EDGE_ORIENTATION__";
2348 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2350 save << " " << "__EDGES_PERIODICITY_END__";
2354 void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save)
2356 TVerticesPeriodicityVector::const_iterator it_vertices_periodicity = _verticesPeriodicityVector.begin();
2357 if (it_vertices_periodicity != _verticesPeriodicityVector.end()) {
2358 save << " " << "__VERTICES_PERIODICITY_BEGIN__";
2359 for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
2360 TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
2361 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2362 save << " " << "__BEGIN_EDGE1__";
2363 save << " " << periodicity_i.theEdge1Entry;
2364 save << " " << "__END_EDGE1__";
2365 save << " " << "__BEGIN_VERTEX1__";
2366 save << " " << periodicity_i.theVertex1Entry;
2367 save << " " << "__END_VERTEX1__";
2368 save << " " << "__BEGIN_EDGE2__";
2369 save << " " << periodicity_i.theEdge2Entry;
2370 save << " " << "__END_EDGE2__";
2371 save << " " << "__BEGIN_VERTEX2__";
2372 save << " " << periodicity_i.theVertex2Entry;
2373 save << " " << "__END_VERTEX2__";
2374 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2376 save << " " << "__VERTICES_PERIODICITY_END__";
2380 void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType)
2382 TPreCadPeriodicityVector precad_periodicity;
2383 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
2384 precad_periodicity = _preCadFacesPeriodicityVector;
2386 precad_periodicity = _preCadEdgesPeriodicityVector;
2387 TPreCadPeriodicityVector::const_iterator it_precad_periodicity = precad_periodicity.begin();
2388 if (it_precad_periodicity != precad_periodicity.end()) {
2389 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_BEGIN__";
2390 for (; it_precad_periodicity != precad_periodicity.end(); ++it_precad_periodicity) {
2391 TPreCadPeriodicity periodicity_i = (*it_precad_periodicity);
2392 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2393 if (!periodicity_i.shape1Entry.empty()) {
2394 save << " " << "__BEGIN_ENTRY1__";
2395 save << " " << periodicity_i.shape1Entry;
2396 save << " " << "__END_ENTRY1__";
2398 if (!periodicity_i.shape2Entry.empty()) {
2399 save << " " << "__BEGIN_ENTRY2__";
2400 save << " " << periodicity_i.shape2Entry;
2401 save << " " << "__END_ENTRY2__";
2404 std::vector<std::string>::const_iterator sourceVerticesEntriesIt = periodicity_i.theSourceVerticesEntries.begin();
2405 bool hasSourceVertices = false;
2406 if (sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end()) {
2407 hasSourceVertices = true;
2408 save << " " << "__BEGIN_SOURCE_VERTICES_LIST__";
2410 for (; sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end(); ++sourceVerticesEntriesIt)
2411 save << " " << (*sourceVerticesEntriesIt);
2412 if (hasSourceVertices)
2413 save << " " << "__END_SOURCE_VERTICES_LIST__";
2415 std::vector<std::string>::const_iterator targetVerticesEntriesIt = periodicity_i.theTargetVerticesEntries.begin();
2416 bool hasTargetVertices = false;
2417 if (targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end()) {
2418 hasTargetVertices = true;
2419 save << " " << "__BEGIN_TARGET_VERTICES_LIST__";
2421 for (; targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end(); ++targetVerticesEntriesIt)
2422 save << " " << (*targetVerticesEntriesIt);
2423 if (hasTargetVertices)
2424 save << " " << "__END_TARGET_VERTICES_LIST__";
2426 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2428 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_END__";
2433 //=============================================================================
2434 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
2439 std::string option_or_sm;
2441 isOK = static_cast<bool>(load >> i);
2443 _topology = (Topology) i;
2445 load.clear(std::ios::badbit | load.rdstate());
2447 isOK = static_cast<bool>(load >> i);
2449 _physicalMesh = (PhysicalMesh) i;
2451 load.clear(std::ios::badbit | load.rdstate());
2453 isOK = static_cast<bool>(load >> i);
2455 _geometricMesh = (GeometricMesh) i;
2457 load.clear(std::ios::badbit | load.rdstate());
2459 isOK = static_cast<bool>(load >> val);
2463 load.clear(std::ios::badbit | load.rdstate());
2465 isOK = static_cast<bool>(load >> val);
2469 load.clear(std::ios::badbit | load.rdstate());
2471 isOK = static_cast<bool>(load >> val);
2475 load.clear(std::ios::badbit | load.rdstate());
2477 isOK = static_cast<bool>(load >> i);
2479 _elementType = (ElementType) i;
2481 load.clear(std::ios::badbit | load.rdstate());
2483 isOK = static_cast<bool>(load >> i);
2485 if ( i != -1) { // if value is -1, then this is no longer a standard option
2486 std::string & value = _option2value["respect_geometry"];
2487 bool _decimesh = (bool) i;
2488 value = _decimesh ? "1" : "0";
2492 load.clear(std::ios::badbit | load.rdstate());
2494 isOK = static_cast<bool>(load >> val);
2498 load.clear(std::ios::badbit | load.rdstate());
2500 isOK = static_cast<bool>(load >> val);
2504 load.clear(std::ios::badbit | load.rdstate());
2506 isOK = static_cast<bool>(load >> val);
2508 // former parameter: get min value
2509 _angleMesh = std::min(val,_angleMesh);
2511 load.clear(std::ios::badbit | load.rdstate());
2513 isOK = static_cast<bool>(load >> val);
2515 // former parameter: get min value
2516 _minSize = std::min(val,_minSize);
2518 load.clear(std::ios::badbit | load.rdstate());
2520 isOK = static_cast<bool>(load >> val);
2522 // former parameter: get max value
2523 _maxSize = std::max(val,_maxSize);
2525 load.clear(std::ios::badbit | load.rdstate());
2527 isOK = static_cast<bool>(load >> i);
2531 load.clear(std::ios::badbit | load.rdstate());
2533 isOK = static_cast<bool>(load >> i);
2535 _preCADMergeEdges = (bool) i;
2537 load.clear(std::ios::badbit | load.rdstate());
2539 isOK = static_cast<bool>(load >> i);
2541 if ( i != -1) { // if value is -1, then this is no longer a standard option
2542 std::string & value = _preCADoption2value["remove_tiny_edges"];
2543 bool _preCADRemoveNanoEdges = (bool) i;
2544 value = _preCADRemoveNanoEdges ? "1" : "0";
2548 load.clear(std::ios::badbit | load.rdstate());
2550 isOK = static_cast<bool>(load >> i);
2552 _preCADDiscardInput = (bool) i;
2554 load.clear(std::ios::badbit | load.rdstate());
2556 isOK = static_cast<bool>(load >> val);
2557 if (isOK) { // _preCADEpsNano
2558 if ( (i + 1.0) < 1e-6 ) { // if value is -1, then this is no longer a standard option: get optional value "tiny_edge_length" instead
2559 std::string & value = _preCADoption2value["tiny_edge_length"];
2560 std::ostringstream oss;
2566 load.clear(std::ios::badbit | load.rdstate());
2568 isOK = static_cast<bool>(load >> i);
2570 _enforcedInternalVerticesAllFaces = (bool) i;
2572 load.clear(std::ios::badbit | load.rdstate());
2574 // New options with MeshGems-CADSurf
2576 bool hasCADSurfOptions = false;
2577 bool hasOptions = false;
2578 bool hasCustomOptions = false;
2579 bool hasPreCADOptions = false;
2580 bool hasSizeMap = false;
2581 bool hasAttractor = false;
2582 bool hasNewAttractor = false;
2583 bool hasEnforcedVertex = false;
2584 bool hasPreCADFacesPeriodicity = false;
2585 bool hasPreCADEdgesPeriodicity = false;
2586 bool hasFacesPeriodicity = false;
2587 bool hasEdgesPeriodicity = false;
2588 bool hasVerticesPeriodicity = false;
2590 isOK = static_cast<bool>(load >> option_or_sm);
2592 if (( option_or_sm == "1" ) || ( option_or_sm == "0" )) {
2593 i = atoi(option_or_sm.c_str());
2594 hasCADSurfOptions = true;
2595 _phySizeRel = (bool) i;
2597 else if (option_or_sm == "__OPTIONS_BEGIN__")
2599 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2600 hasCustomOptions = true;
2601 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2602 hasPreCADOptions = true;
2603 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2605 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2606 hasAttractor = true;
2607 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2608 hasNewAttractor = true;
2609 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2610 hasEnforcedVertex = true;
2611 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2612 hasPreCADFacesPeriodicity = true;
2613 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2614 hasPreCADEdgesPeriodicity = true;
2615 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2616 hasFacesPeriodicity = true;
2617 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2618 hasEdgesPeriodicity = true;
2619 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2620 hasVerticesPeriodicity = true;
2623 if (isOK && hasCADSurfOptions) {
2624 isOK = static_cast<bool>(load >> i);
2626 _minSizeRel = (bool) i;
2628 load.clear(std::ios::badbit | load.rdstate());
2630 isOK = static_cast<bool>(load >> i);
2632 _maxSizeRel = (bool) i;
2634 load.clear(std::ios::badbit | load.rdstate());
2636 isOK = static_cast<bool>(load >> val);
2638 _chordalError = val;
2640 load.clear(std::ios::badbit | load.rdstate());
2642 isOK = static_cast<bool>(load >> i);
2644 _anisotropic = (bool) i;
2646 load.clear(std::ios::badbit | load.rdstate());
2648 isOK = static_cast<bool>(load >> val);
2650 _anisotropicRatio = val;
2652 load.clear(std::ios::badbit | load.rdstate());
2654 isOK = static_cast<bool>(load >> i);
2656 _removeTinyEdges = (bool) i;
2658 load.clear(std::ios::badbit | load.rdstate());
2660 isOK = static_cast<bool>(load >> val);
2662 _tinyEdgeLength = val;
2664 load.clear(std::ios::badbit | load.rdstate());
2666 isOK = static_cast<bool>(load >> i);
2668 _badElementRemoval = (bool) i;
2670 load.clear(std::ios::badbit | load.rdstate());
2672 isOK = static_cast<bool>(load >> val);
2674 _badElementAspectRatio = val;
2676 load.clear(std::ios::badbit | load.rdstate());
2678 isOK = static_cast<bool>(load >> i);
2680 _optimizeMesh = (bool) i;
2682 load.clear(std::ios::badbit | load.rdstate());
2684 isOK = static_cast<bool>(load >> i);
2686 _quadraticMesh = (bool) i;
2688 load.clear(std::ios::badbit | load.rdstate());
2690 isOK = static_cast<bool>(load >> i);
2692 _preCADProcess3DTopology = (bool) i;
2694 load.clear(std::ios::badbit | load.rdstate());
2696 if (( load >> std::ws).peek() != '_' )
2698 isOK = static_cast<bool>(load >> i);
2700 _preCADRemoveDuplicateCADFaces = (bool) i;
2702 load.clear(std::ios::badbit | load.rdstate());
2704 isOK = static_cast<bool>(load >> i);
2706 _optimiseTinyEdges = (bool) i;
2708 load.clear(std::ios::badbit | load.rdstate());
2710 isOK = static_cast<bool>(load >> val);
2712 _tinyEdgeOptimisationLength = val;
2714 load.clear(std::ios::badbit | load.rdstate());
2716 isOK = static_cast<bool>(load >> i);
2718 _correctSurfaceIntersec = (bool) i;
2720 load.clear(std::ios::badbit | load.rdstate());
2722 isOK = static_cast<bool>(load >> val);
2724 _corrSurfaceIntersCost = val;
2726 load.clear(std::ios::badbit | load.rdstate());
2728 isOK = static_cast<bool>(load >> i);
2730 _useGradation = (bool) i;
2732 load.clear(std::ios::badbit | load.rdstate());
2734 isOK = static_cast<bool>(load >> i);
2736 _useVolumeGradation = (bool) i;
2738 load.clear(std::ios::badbit | load.rdstate());
2740 isOK = static_cast<bool>(load >> val);
2742 _volumeGradation = val;
2744 load.clear(std::ios::badbit | load.rdstate());
2749 if (hasCADSurfOptions) {
2750 isOK = static_cast<bool>(load >> option_or_sm);
2752 if (option_or_sm == "__OPTIONS_BEGIN__")
2754 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2755 hasCustomOptions = true;
2756 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2757 hasPreCADOptions = true;
2758 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2760 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2761 hasAttractor = true;
2762 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2763 hasNewAttractor = true;
2764 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2765 hasEnforcedVertex = true;
2766 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2767 hasPreCADFacesPeriodicity = true;
2768 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2769 hasPreCADEdgesPeriodicity = true;
2770 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2771 hasFacesPeriodicity = true;
2772 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2773 hasEdgesPeriodicity = true;
2774 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2775 hasVerticesPeriodicity = true;
2779 std::string optName, optValue;
2780 while (isOK && hasOptions) {
2781 isOK = static_cast<bool>(load >> optName);
2783 if (optName == "__OPTIONS_END__")
2785 isOK = static_cast<bool>(load >> optValue);
2787 // read the value of the advanced option
2788 // unless this option is no more used
2790 #if MESHGEMS_VERSION_HEX >= 0x020A00
2791 && optName != "enforce_cad_edge_sizes" && optName != "max_number_of_points_per_patch"
2794 std::string & value = _option2value[optName];
2796 int len = (int) value.size();
2797 // continue reading until "%#" encountered
2798 while (value[len - 1] != '#' || value[len - 2] != '%') {
2799 isOK = static_cast<bool>(load >> optValue);
2803 len = (int) value.size();
2808 if ( value[ len - 1] == '#' )
2809 value.resize(len - 2); //cut off "%#"
2814 isOK = static_cast<bool>(load >> option_or_sm);
2816 if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2817 hasCustomOptions = true;
2818 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2819 hasPreCADOptions = true;
2820 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2822 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2823 hasAttractor = true;
2824 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2825 hasNewAttractor = true;
2826 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2827 hasEnforcedVertex = true;
2828 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2829 hasPreCADFacesPeriodicity = true;
2830 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2831 hasPreCADEdgesPeriodicity = true;
2832 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2833 hasFacesPeriodicity = true;
2834 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2835 hasEdgesPeriodicity = true;
2836 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2837 hasVerticesPeriodicity = true;
2841 while (isOK && hasCustomOptions) {
2842 isOK = static_cast<bool>(load >> optName);
2844 if (optName == "__CUSTOM_OPTIONS_END__")
2846 isOK = static_cast<bool>(load >> optValue);
2849 std::string& value = optValue;
2850 int len = (int) value.size();
2851 // continue reading until "%#" encountered
2852 while (value[len - 1] != '#' || value[len - 2] != '%') {
2853 isOK = static_cast<bool>(load >> optValue);
2857 len = (int) value.size();
2862 if ( value[ len - 1] == '#' )
2863 value.resize(len - 2); //cut off "%#"
2864 _customOption2value[optName] = value;
2868 if (hasCustomOptions) {
2869 isOK = static_cast<bool>(load >> option_or_sm);
2871 if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2872 hasPreCADOptions = true;
2873 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2875 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2876 hasAttractor = true;
2877 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2878 hasNewAttractor = true;
2879 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2880 hasEnforcedVertex = true;
2881 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2882 hasPreCADFacesPeriodicity = true;
2883 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2884 hasPreCADEdgesPeriodicity = true;
2885 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2886 hasFacesPeriodicity = true;
2887 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2888 hasEdgesPeriodicity = true;
2889 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2890 hasVerticesPeriodicity = true;
2894 while (isOK && hasPreCADOptions) {
2895 isOK = static_cast<bool>(load >> optName);
2897 if (optName == "__PRECAD_OPTIONS_END__")
2899 isOK = static_cast<bool>(load >> optValue);
2902 std::string & value = _preCADoption2value[optName];
2904 int len = (int) value.size();
2905 // continue reading until "%#" encountered
2906 while (value[len - 1] != '#' || value[len - 2] != '%') {
2907 isOK = static_cast<bool>(load >> optValue);
2911 len = (int) value.size();
2916 if ( value[ len - 1] == '#' )
2917 value.resize(len - 2); //cut off "%#"
2921 if (hasPreCADOptions) {
2922 isOK = static_cast<bool>(load >> option_or_sm);
2924 if (option_or_sm == "__SIZEMAP_BEGIN__")
2926 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2927 hasAttractor = true;
2928 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2929 hasNewAttractor = true;
2930 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2931 hasEnforcedVertex = true;
2932 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2933 hasPreCADFacesPeriodicity = true;
2934 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2935 hasPreCADEdgesPeriodicity = true;
2936 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2937 hasFacesPeriodicity = true;
2938 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2939 hasEdgesPeriodicity = true;
2940 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2941 hasVerticesPeriodicity = true;
2945 std::string smEntry, smValue;
2946 while (isOK && hasSizeMap) {
2947 isOK = static_cast<bool>(load >> smEntry);
2949 if (smEntry == "__SIZEMAP_END__")
2951 isOK = static_cast<bool>(load >> smValue);
2954 std::string & value2 = _sizeMap[smEntry];
2956 int len2 = (int) value2.size();
2957 // continue reading until "%#" encountered
2958 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2959 isOK = static_cast<bool>(load >> smValue);
2963 len2 = (int) value2.size();
2968 value2.resize(len2 - 2); //cut off "%#"
2973 isOK = static_cast<bool>(load >> option_or_sm);
2975 if (option_or_sm == "__ATTRACTORS_BEGIN__")
2976 hasAttractor = true;
2977 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2978 hasNewAttractor = true;
2979 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2980 hasEnforcedVertex = true;
2981 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2982 hasPreCADFacesPeriodicity = true;
2983 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2984 hasPreCADEdgesPeriodicity = true;
2985 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2986 hasFacesPeriodicity = true;
2987 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2988 hasEdgesPeriodicity = true;
2989 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2990 hasVerticesPeriodicity = true;
2994 std::string atEntry, atValue;
2995 while (isOK && hasAttractor) {
2996 isOK = static_cast<bool>(load >> atEntry);
2998 if (atEntry == "__ATTRACTORS_END__")
3000 isOK = static_cast<bool>(load >> atValue);
3003 std::string & value3 = _attractors[atEntry];
3005 int len3 = (int) value3.size();
3006 // continue reading until "%#" encountered
3007 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
3008 isOK = static_cast<bool>(load >> atValue);
3012 len3 = (int) value3.size();
3017 value3.resize(len3 - 2); //cut off "%#"
3022 isOK = static_cast<bool>(load >> option_or_sm);
3024 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
3025 hasNewAttractor = true;
3026 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
3027 hasEnforcedVertex = true;
3028 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
3029 hasPreCADFacesPeriodicity = true;
3030 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
3031 hasPreCADEdgesPeriodicity = true;
3032 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
3033 hasFacesPeriodicity = true;
3034 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3035 hasEdgesPeriodicity = true;
3036 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3037 hasVerticesPeriodicity = true;
3041 std::string newAtFaceEntry, atTestString;
3042 std::string newAtShapeEntry;
3043 double attParams[4];
3045 while (isOK && hasNewAttractor) {
3046 //std::cout<<"Load new attractor"<<std::endl;
3047 isOK = static_cast<bool>(load >> newAtFaceEntry);
3049 if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
3051 isOK = static_cast<bool>(load >> newAtShapeEntry);
3054 isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
3057 const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
3058 const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
3059 BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
3060 attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
3061 //attractor->BuildMap();
3062 _classAttractors.insert( make_pair( newAtFaceEntry, attractor ));
3067 if (hasNewAttractor) {
3068 isOK = static_cast<bool>(load >> option_or_sm);
3070 if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
3071 hasEnforcedVertex = true;
3072 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
3073 hasPreCADFacesPeriodicity = true;
3074 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
3075 hasPreCADEdgesPeriodicity = true;
3076 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
3077 hasFacesPeriodicity = true;
3078 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3079 hasEdgesPeriodicity = true;
3080 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3081 hasVerticesPeriodicity = true;
3087 // Here is a example of the saved stream:
3088 // __ENFORCED_VERTICES_BEGIN__
3089 // __BEGIN_VERTEX__ => no name, no entry
3090 // __BEGIN_GROUP__ mon groupe __END_GROUP__
3091 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__
3092 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__
3094 // __BEGIN_VERTEX__ => no coords
3095 // __BEGIN_NAME__ mes points __END_NAME__
3096 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
3097 // __BEGIN_GROUP__ mon groupe __END_GROUP__
3098 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
3100 // __ENFORCED_VERTICES_END__
3103 std::string enfSeparator;
3104 std::string enfName;
3105 std::string enfGeomEntry;
3106 std::string enfGroup;
3107 TEntryList enfFaceEntryList;
3108 double enfCoords[3];
3109 bool hasCoords = false;
3111 _faceEntryEnfVertexListMap.clear();
3112 _enfVertexList.clear();
3113 _faceEntryCoordsListMap.clear();
3114 _coordsEnfVertexMap.clear();
3115 _faceEntryEnfVertexEntryListMap.clear();
3116 _enfVertexEntryEnfVertexMap.clear();
3119 while (isOK && hasEnforcedVertex)
3121 isOK = static_cast<bool>(load >> enfSeparator); // __BEGIN_VERTEX__
3122 TEnfVertex *enfVertex = new TEnfVertex();
3123 if (enfSeparator == "__ENFORCED_VERTICES_END__")
3124 break; // __ENFORCED_VERTICES_END__
3125 if (enfSeparator != "__BEGIN_VERTEX__")
3126 throw std::exception();
3129 isOK = static_cast<bool>(load >> enfSeparator);
3130 if (enfSeparator == "__END_VERTEX__") {
3132 enfVertex->name = enfName;
3133 enfVertex->geomEntry = enfGeomEntry;
3134 enfVertex->grpName = enfGroup;
3135 enfVertex->coords.clear();
3137 enfVertex->coords.assign(enfCoords,enfCoords+3);
3138 enfVertex->faceEntries = enfFaceEntryList;
3140 _enfVertexList.insert(enfVertex);
3142 if (enfVertex->coords.size()) {
3143 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
3144 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
3145 _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
3146 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
3149 if (!enfVertex->geomEntry.empty()) {
3150 _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
3151 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
3152 _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
3153 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
3158 enfGeomEntry.clear();
3160 enfFaceEntryList.clear();
3162 break; // __END_VERTEX__
3165 if (enfSeparator == "__BEGIN_NAME__") { // __BEGIN_NAME__
3166 while (isOK && (enfSeparator != "__END_NAME__")) {
3167 isOK = static_cast<bool>(load >> enfSeparator);
3168 if (enfSeparator != "__END_NAME__") {
3169 if (!enfName.empty())
3171 enfName += enfSeparator;
3176 if (enfSeparator == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
3177 isOK = static_cast<bool>(load >> enfGeomEntry);
3178 isOK = static_cast<bool>(load >> enfSeparator); // __END_ENTRY__
3179 if (enfSeparator != "__END_ENTRY__")
3180 throw std::exception();
3183 if (enfSeparator == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
3184 while (isOK && (enfSeparator != "__END_GROUP__")) {
3185 isOK = static_cast<bool>(load >> enfSeparator);
3186 if (enfSeparator != "__END_GROUP__") {
3187 if (!enfGroup.empty())
3189 enfGroup += enfSeparator;
3194 if (enfSeparator == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
3196 isOK = static_cast<bool>(load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
3197 isOK = static_cast<bool>(load >> enfSeparator); // __END_COORDS__
3198 if (enfSeparator != "__END_COORDS__")
3199 throw std::exception();
3202 if (enfSeparator == "__BEGIN_FACELIST__") { // __BEGIN_FACELIST__
3203 while (isOK && (enfSeparator != "__END_FACELIST__")) {
3204 isOK = static_cast<bool>(load >> enfSeparator);
3205 if (enfSeparator != "__END_FACELIST__") {
3206 enfFaceEntryList.insert(enfSeparator);
3213 if ( hasEnforcedVertex ) {
3214 isOK = static_cast<bool>(load >> option_or_sm);
3216 if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
3217 hasPreCADFacesPeriodicity = true;
3218 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
3219 hasPreCADEdgesPeriodicity = true;
3220 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
3221 hasFacesPeriodicity = true;
3222 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3223 hasEdgesPeriodicity = true;
3224 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3225 hasVerticesPeriodicity = true;
3231 if (hasPreCADFacesPeriodicity)
3233 LoadPreCADPeriodicity(load, "FACES");
3235 isOK = static_cast<bool>(load >> option_or_sm);
3237 if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
3238 hasPreCADEdgesPeriodicity = true;
3239 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
3240 hasFacesPeriodicity = true;
3241 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3242 hasEdgesPeriodicity = true;
3243 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3244 hasVerticesPeriodicity = true;
3248 if (hasPreCADEdgesPeriodicity)
3250 LoadPreCADPeriodicity(load, "EDGES");
3252 isOK = static_cast<bool>(load >> option_or_sm);
3254 if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
3255 hasFacesPeriodicity = true;
3256 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3257 hasEdgesPeriodicity = true;
3258 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3259 hasVerticesPeriodicity = true;
3263 if (hasFacesPeriodicity)
3265 LoadFacesPeriodicity(load);
3267 isOK = static_cast<bool>(load >> option_or_sm);
3269 if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3270 hasEdgesPeriodicity = true;
3271 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3272 hasVerticesPeriodicity = true;
3276 if (hasEdgesPeriodicity)
3278 LoadEdgesPeriodicity(load);
3280 isOK = static_cast<bool>(load >> option_or_sm);
3282 if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3283 hasVerticesPeriodicity = true;
3286 if (hasVerticesPeriodicity)
3287 LoadVerticesPeriodicity(load);
3290 if ( !option_or_sm.empty() && option_or_sm[0] == '_' )
3291 isOK = static_cast<bool>(load >> option_or_sm);
3292 if ( isOK && !option_or_sm.empty() )
3294 int nbPatches = atoi( option_or_sm.c_str() );
3295 if ( nbPatches >= 0 )
3297 _hyperPatchList.resize( nbPatches );
3298 for ( int iP = 0; iP < nbPatches && isOK; ++iP )
3300 isOK = static_cast<bool>(load >> i) && i >= 2;
3303 for ( int iT = 0; iT < nbTags; ++iT )
3305 if (( isOK = static_cast<bool>(load >> i)))
3306 _hyperPatchList[ iP ].insert( i );
3311 if ( !isOK ) // remove invalid patches
3313 for ( i = nbPatches - 1; i >= 0; i-- )
3314 if ( _hyperPatchList[i].size() < 2 )
3315 _hyperPatchList.resize( i );
3320 // New options in 2.9.6 (issue #17784)
3321 if ( static_cast<bool>( load >> _useSurfaceProximity ))
3323 load >> _nbSurfaceProximityLayers;
3324 load >> _surfaceProximityRatio;
3325 load >> _useVolumeProximity;
3326 load >> _nbVolumeProximityLayers;
3327 isOK = static_cast<bool>( load >> _volumeProximityRatio );
3330 // hyper-patches as entries (issue bos #20543)
3331 if ( static_cast<bool>( load >> i ) && i > 0 )
3333 std::string buffer( i, '\0' );
3334 load.get( buffer[0] ); // remove a white-space
3335 load.get( & buffer[0], i + 1 );
3337 std::istringstream istream( buffer.data() );
3338 boost::archive::text_iarchive archive( istream );
3340 archive >> _hyperPatchEntriesList;
3348 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load)
3352 std::string periodicitySeparator;
3356 _facesPeriodicityVector.clear();
3359 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3360 TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
3361 if (periodicitySeparator == "__FACES_PERIODICITY_END__")
3362 break; // __FACES_PERIODICITY_END__
3363 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3364 throw std::exception();
3368 isOK = static_cast<bool>(load >> periodicitySeparator);
3369 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3371 periodicity_i->first = shape1Entry;
3372 periodicity_i->second = shape2Entry;
3374 _facesPeriodicityVector.push_back(*periodicity_i);
3376 break; // __END_PERIODICITY_DESCRIPTION__
3379 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3380 isOK = static_cast<bool>(load >> shape1Entry);
3381 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3382 if (periodicitySeparator != "__END_ENTRY1__")
3383 throw std::exception();
3386 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3387 isOK = static_cast<bool>(load >> shape2Entry);
3388 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3389 if (periodicitySeparator != "__END_ENTRY2__")
3390 throw std::exception();
3397 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load)
3401 std::string periodicitySeparator;
3402 TEntry theFace1Entry;
3403 TEntry theEdge1Entry;
3404 TEntry theFace2Entry;
3405 TEntry theEdge2Entry;
3406 int edge_orientation = 0;
3408 _edgesPeriodicityVector.clear();
3411 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3412 TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
3413 if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
3414 break; // __EDGES_PERIODICITY_END__
3415 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3416 throw std::exception();
3420 isOK = static_cast<bool>(load >> periodicitySeparator);
3421 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3423 periodicity_i->theFace1Entry = theFace1Entry;
3424 periodicity_i->theEdge1Entry = theEdge1Entry;
3425 periodicity_i->theFace2Entry = theFace2Entry;
3426 periodicity_i->theEdge2Entry = theEdge2Entry;
3427 periodicity_i->edge_orientation = edge_orientation;
3429 _edgesPeriodicityVector.push_back(*periodicity_i);
3431 break; // __END_PERIODICITY_DESCRIPTION__
3434 if (periodicitySeparator == "__BEGIN_FACE1__") { // __BEGIN_FACE1__
3435 isOK = static_cast<bool>(load >> theFace1Entry);
3436 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE1__
3437 if (periodicitySeparator != "__END_FACE1__"){
3438 throw std::exception();
3442 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3443 isOK = static_cast<bool>(load >> theEdge1Entry);
3444 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3445 if (periodicitySeparator != "__END_EDGE1__")
3446 throw std::exception();
3449 if (periodicitySeparator == "__BEGIN_FACE2__") { // __BEGIN_FACE2__
3450 isOK = static_cast<bool>(load >> theFace2Entry);
3451 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE2__
3452 if (periodicitySeparator != "__END_FACE2__")
3453 throw std::exception();
3456 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3457 isOK = static_cast<bool>(load >> theEdge2Entry);
3458 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3459 if (periodicitySeparator != "__END_EDGE2__")
3460 throw std::exception();
3463 if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") { // __BEGIN_EDGE_ORIENTATION__
3464 isOK = static_cast<bool>(load >> edge_orientation);
3465 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
3466 if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
3467 throw std::exception();
3473 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load)
3477 std::string periodicitySeparator;
3478 TEntry theEdge1Entry;
3479 TEntry theVertex1Entry;
3480 TEntry theEdge2Entry;
3481 TEntry theVertex2Entry;
3483 _verticesPeriodicityVector.clear();
3486 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3487 TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
3488 if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
3489 break; // __VERTICES_PERIODICITY_END__
3490 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3491 throw std::exception();
3495 isOK = static_cast<bool>(load >> periodicitySeparator);
3496 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3498 periodicity_i->theEdge1Entry = theEdge1Entry;
3499 periodicity_i->theVertex1Entry = theVertex1Entry;
3500 periodicity_i->theEdge2Entry = theEdge2Entry;
3501 periodicity_i->theVertex2Entry = theVertex2Entry;
3503 _verticesPeriodicityVector.push_back(*periodicity_i);
3505 break; // __END_PERIODICITY_DESCRIPTION__
3508 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3509 isOK = static_cast<bool>(load >> theEdge1Entry);
3510 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3511 if (periodicitySeparator != "__END_EDGE1__")
3512 throw std::exception();
3515 if (periodicitySeparator == "__BEGIN_VERTEX1__") { // __BEGIN_VERTEX1__
3516 isOK = static_cast<bool>(load >> theVertex1Entry);
3517 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX1__
3518 if (periodicitySeparator != "__END_VERTEX1__")
3519 throw std::exception();
3522 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3523 isOK = static_cast<bool>(load >> theEdge2Entry);
3524 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3525 if (periodicitySeparator != "__END_EDGE2__")
3526 throw std::exception();
3529 if (periodicitySeparator == "__BEGIN_VERTEX2__") { // __BEGIN_VERTEX2__
3530 isOK = static_cast<bool>(load >> theVertex2Entry);
3531 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX2__
3532 if (periodicitySeparator != "__END_VERTEX2__")
3533 throw std::exception();
3539 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType)
3543 std::string periodicitySeparator;
3546 std::vector<std::string> theSourceVerticesEntries;
3547 std::vector<std::string> theTargetVerticesEntries;
3549 bool hasSourceVertices = false;
3550 bool hasTargetVertices = false;
3552 if ( shapeType && strcmp( shapeType, "FACES") == 0 )
3553 _preCadFacesPeriodicityVector.clear();
3555 _preCadEdgesPeriodicityVector.clear();
3559 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3560 TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
3561 std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
3562 if (periodicitySeparator == endSeparator)
3563 break; // __PRECAD_FACES_PERIODICITY_END__
3564 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3565 throw std::exception();
3569 isOK = static_cast<bool>(load >> periodicitySeparator);
3570 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3572 periodicity_i->shape1Entry = shape1Entry;
3573 periodicity_i->shape2Entry = shape2Entry;
3575 if (hasSourceVertices)
3576 periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
3577 if (hasTargetVertices)
3578 periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
3580 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
3581 _preCadFacesPeriodicityVector.push_back(*periodicity_i);
3583 _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
3585 theSourceVerticesEntries.clear();
3586 theTargetVerticesEntries.clear();
3587 hasSourceVertices = false;
3588 hasTargetVertices = false;
3589 break; // __END_PERIODICITY_DESCRIPTION__
3592 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3593 isOK = static_cast<bool>(load >> shape1Entry);
3594 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3595 if (periodicitySeparator != "__END_ENTRY1__")
3596 throw std::exception();
3599 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3600 isOK = static_cast<bool>(load >> shape2Entry);
3601 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3602 if (periodicitySeparator != "__END_ENTRY2__")
3603 throw std::exception();
3606 if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") { // __BEGIN_SOURCE_VERTICES_LIST__
3607 hasSourceVertices = true;
3608 while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
3609 isOK = static_cast<bool>(load >> periodicitySeparator);
3610 if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
3611 theSourceVerticesEntries.push_back(periodicitySeparator);
3616 if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") { // __BEGIN_TARGET_VERTICES_LIST__
3617 hasTargetVertices = true;
3618 while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
3619 isOK = static_cast<bool>(load >> periodicitySeparator);
3620 if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
3621 theTargetVerticesEntries.push_back(periodicitySeparator);
3629 //=============================================================================
3630 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
3631 return hyp.SaveTo(save);
3634 //=============================================================================
3635 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
3636 return hyp.LoadFrom(load);
3639 //================================================================================
3641 * \brief Does nothing
3643 //================================================================================
3645 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, const TopoDS_Shape& /*theShape*/)
3650 //================================================================================
3652 * \brief Returns default global constant physical size given a default value of element length ratio
3654 //================================================================================
3656 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation)
3658 if (bbSegmentation != 0 && diagonal != 0)
3659 return diagonal / bbSegmentation ;
3663 //================================================================================
3665 * \brief Returns default min size given a default value of element length ratio
3667 //================================================================================
3669 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal)
3672 return diagonal / 1000.0 ;
3673 return undefinedDouble();
3676 //================================================================================
3678 * \brief Returns default max size given a default value of element length ratio
3680 //================================================================================
3682 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal)
3685 return diagonal / 5.0 ;
3686 return undefinedDouble();
3689 //================================================================================
3691 * \brief Returns default chordal error given a default value of element length ratio
3693 //================================================================================
3695 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal)
3699 return undefinedDouble();
3702 //================================================================================
3704 * \brief Returns default tiny edge length given a default value of element length ratio
3706 //================================================================================
3708 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal)
3711 return diagonal * 1e-6 ;
3712 return undefinedDouble();
3715 //================================================================================
3717 * \brief Returns default tiny edge optimisation length given a default value of element length ratio
3719 //================================================================================
3721 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal)
3724 return diagonal * 1e-6 ;
3725 return undefinedDouble();
3728 //=============================================================================
3730 * \brief Initialize my parameter values by default parameters.
3731 * \retval bool - true if parameter values have been successfully defined
3733 //=============================================================================
3735 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
3736 const SMESH_Mesh* /*theMesh*/)
3738 _phySize = GetDefaultPhySize(dflts._diagonal, _gen->GetBoundaryBoxSegmentation());
3739 _minSize = GetDefaultMinSize(dflts._diagonal);
3740 _maxSize = GetDefaultMaxSize(dflts._diagonal);
3741 _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
3743 if ( dflts._way == SMESH_Hypothesis::BY_AVERAGE_LENGTH )
3745 _phySize = dflts._elemLength;
3746 _minSize = dflts._elemLength / 100.;
3747 _maxSize = dflts._elemLength * 2.;
3748 _chordalError = dflts._elemLength / 2.;
3749 _elementType = dflts._quadDominated ? QuadrangleDominant : Triangles;
3750 _physicalMesh = PhysicalLocalSize; // to activate _enforcedInternalVerticesAllFaces
3751 _enforcedInternalVerticesAllFaces = true;
3755 _tinyEdgeLength = GetDefaultTinyEdgeLength(dflts._diagonal);
3756 _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(dflts._diagonal);
3762 //================================================================================
3764 * \brief Converts a string to a bool
3766 //================================================================================
3768 bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
3770 std::string s = str;
3771 if ( isOk ) *isOk = true;
3773 for ( size_t i = 0; i <= s.size(); ++i )
3774 s[i] = (char) tolower( s[i] );
3776 if ( s == "1" || s == "true" || s == "active" || s == "yes" )
3779 if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
3785 std::string msg = "Not a Boolean value:'" + str + "'";
3786 throw std::invalid_argument(msg);
3791 //================================================================================
3793 * \brief Converts a string to a real value
3795 //================================================================================
3797 double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
3799 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3801 // Forces "C" locale to be set as LC_NUMERIC
3802 Kernel_Utils::Localizer loc;
3805 double val = strtod(&str[0], &endPtr);
3806 bool ok = (&str[0] != endPtr);
3808 if ( isOk ) *isOk = ok;
3812 std::string msg = "Not a real value:'" + str + "'";
3813 throw std::invalid_argument(msg);
3818 //================================================================================
3820 * \brief Converts a string to a integer value
3822 //================================================================================
3824 int BLSURFPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
3826 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3829 int val = (int)strtol( &str[0], &endPtr, 10);
3830 bool ok = (&str[0] != endPtr);
3832 if ( isOk ) *isOk = ok;
3836 std::string msg = "Not an integer value:'" + str + "'";
3837 throw std::invalid_argument(msg);