1 // Copyright (C) 2007-2016 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>
36 #include "ShapeAnalysis.hxx"
39 #include CORBA_CLIENT_HEADER(SALOMEDS)
40 #include CORBA_CLIENT_HEADER(GEOM_Gen)
44 struct GET_DEFAULT // struct used to get default value from GetOptionValue()
47 operator bool* () { return &isDefault; }
51 //=============================================================================
52 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, SMESH_Gen * gen, bool hasgeom) :
53 SMESH_Hypothesis(hypId, gen),
54 _physicalMesh(GetDefaultPhysicalMesh()),
55 _geometricMesh(GetDefaultGeometricMesh()),
56 _phySize(GetDefaultPhySize()),
57 _phySizeRel(GetDefaultPhySizeRel()),
58 _minSize(GetDefaultMinSize()),
59 _maxSize(GetDefaultMaxSize()),
60 _minSizeRel(GetDefaultMinSizeRel()),
61 _maxSizeRel(GetDefaultMaxSizeRel()),
62 _useGradation(GetDefaultUseGradation()),
63 _gradation(GetDefaultGradation()),
64 _useVolumeGradation(GetDefaultUseVolumeGradation()),
65 _volumeGradation(GetDefaultVolumeGradation()),
66 _elementType(GetDefaultElementType()),
67 _angleMesh(GetDefaultAngleMesh()),
68 _chordalError(GetDefaultChordalError()),
69 _anisotropic(GetDefaultAnisotropic()),
70 _anisotropicRatio(GetDefaultAnisotropicRatio()),
71 _removeTinyEdges(GetDefaultRemoveTinyEdges()),
72 _tinyEdgeLength(GetDefaultTinyEdgeLength()),
73 _optimiseTinyEdges(GetDefaultOptimiseTinyEdges()),
74 _tinyEdgeOptimisationLength(GetDefaultTinyEdgeOptimisationLength()),
75 _correctSurfaceIntersec(GetDefaultCorrectSurfaceIntersection()),
76 _corrSurfaceIntersCost(GetDefaultCorrectSurfaceIntersectionMaxCost()),
77 _badElementRemoval(GetDefaultBadElementRemoval()),
78 _badElementAspectRatio(GetDefaultBadElementAspectRatio()),
79 _optimizeMesh(GetDefaultOptimizeMesh()),
80 _quadraticMesh(GetDefaultQuadraticMesh()),
81 _verb(GetDefaultVerbosity()),
82 _topology(GetDefaultTopology()),
83 _preCADMergeEdges(GetDefaultPreCADMergeEdges()),
84 _preCADRemoveDuplicateCADFaces(GetDefaultPreCADRemoveDuplicateCADFaces()),
85 _preCADProcess3DTopology(GetDefaultPreCADProcess3DTopology()),
86 _preCADDiscardInput(GetDefaultPreCADDiscardInput()),
87 _sizeMap(GetDefaultSizeMap()),
88 _attractors(GetDefaultSizeMap()),
89 _classAttractors(GetDefaultAttractorMap()),
90 _faceEntryEnfVertexListMap(GetDefaultFaceEntryEnfVertexListMap()),
91 _enfVertexList(GetDefaultEnfVertexList()),
92 _faceEntryCoordsListMap(GetDefaultFaceEntryCoordsListMap()),
93 _coordsEnfVertexMap(GetDefaultCoordsEnfVertexMap()),
94 _faceEntryEnfVertexEntryListMap(GetDefaultFaceEntryEnfVertexEntryListMap()),
95 _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
96 _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap()),
97 _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex()),
98 _preCadFacesPeriodicityVector(GetDefaultPreCadFacesPeriodicityVector()),
99 _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector()),
100 _GMFFileName(GetDefaultGMFFile())
102 _name = GetHypType(hasgeom);
105 // _GMFFileMode = false; // GMF ascii mode
107 // Advanced options with their defaults according to MG User Manual
109 const char* boolOptionNames[] = { "enforce_cad_edge_sizes", // default = 0
110 // "correct_surface_intersections", // default = 1
111 // "create_tag_on_collision", // default = 1
112 "jacobian_rectification_respect_geometry", // default = 1
113 "rectify_jacobian", // default = 1
114 "respect_geometry", // default = 1
115 // "optimise_tiny_edges", // default = 0
116 // "remove_duplicate_cad_faces", // default = 1
117 "tiny_edge_avoid_surface_intersections", // default = 1
118 "debug", // default = 0
119 "use_deprecated_patch_mesher", // default 0
120 // "tiny_edge_respect_geometry", // default = 0
124 const char* intOptionNames[] = { "max_number_of_points_per_patch", // default = 100000
125 "max_number_of_threads", // default = 4
128 const char* doubleOptionNames[] = { // "surface_intersections_processing_max_cost",// default = 15
129 // "periodic_tolerance", // default = diag/100
130 // "volume_gradation",
131 // "tiny_edge_optimisation_length", // default = diag * 1e-6
134 const char* charOptionNames[] = { // "required_entities", // default = "respect"
135 // "tags", // default = "respect"
139 // PreCAD advanced options
140 const char* preCADboolOptionNames[] = { "closed_geometry", // default = 0
141 "discard_input_topology", // default = 0
142 "merge_edges", // default = = 1
143 "remove_duplicate_cad_faces", // default = 1
144 // "create_tag_on_collision", // default = 1
145 "process_3d_topology", // default = 1
146 // "remove_tiny_edges", // default = 0
147 // remove_tiny_uv_edges option is not documented
148 // but it is useful that the user can change it to disable all preprocessing options
149 "remove_tiny_uv_edges", // default = 1
152 const char* preCADintOptionNames[] = { // "manifold_geometry", // default = 0
155 const char* preCADdoubleOptionNames[] = { "periodic_tolerance", // default = diag * 1e-5
156 "sewing_tolerance", // default = diag * 5e-4
157 // "tiny_edge_length", // default = diag * 1e-5
160 const char* preCADcharOptionNames[] = { "required_entities", // default = "respect"
161 "tags", // default = "respect"
166 while (boolOptionNames[i][0])
168 _boolOptions.insert( boolOptionNames[i] );
169 _option2value[boolOptionNames[i++]].clear();
172 while (preCADboolOptionNames[i][0] && hasgeom)
174 _boolOptions.insert( preCADboolOptionNames[i] );
175 _preCADoption2value[preCADboolOptionNames[i++]].clear();
178 while (intOptionNames[i][0])
179 _option2value[intOptionNames[i++]].clear();
182 while (preCADintOptionNames[i][0] && hasgeom)
183 _preCADoption2value[preCADintOptionNames[i++]].clear();
186 while (doubleOptionNames[i][0]) {
187 _doubleOptions.insert(doubleOptionNames[i]);
188 _option2value[doubleOptionNames[i++]].clear();
191 while (preCADdoubleOptionNames[i][0] && hasgeom) {
192 _preCADdoubleOptions.insert(preCADdoubleOptionNames[i]);
193 _preCADoption2value[preCADdoubleOptionNames[i++]].clear();
196 while (charOptionNames[i][0]) {
197 _charOptions.insert(charOptionNames[i]);
198 _option2value[charOptionNames[i++]].clear();
201 while (preCADcharOptionNames[i][0] && hasgeom) {
202 _preCADcharOptions.insert(preCADcharOptionNames[i]);
203 _preCADoption2value[preCADcharOptionNames[i++]].clear();
206 // default values to be used while MG meshing
208 _defaultOptionValues["enforce_cad_edge_sizes" ] = "no";
209 _defaultOptionValues["jacobian_rectification_respect_geometry"] = "yes";
210 _defaultOptionValues["max_number_of_points_per_patch" ] = "0";
211 _defaultOptionValues["max_number_of_threads" ] = "4";
212 _defaultOptionValues["rectify_jacobian" ] = "yes";
213 _defaultOptionValues["use_deprecated_patch_mesher" ] = "yes";
214 _defaultOptionValues["respect_geometry" ] = "yes";
215 _defaultOptionValues["tiny_edge_avoid_surface_intersections" ] = "yes";
216 _defaultOptionValues["use_deprecated_patch_mesher" ] = "no";
217 _defaultOptionValues["debug" ] = "no";
220 _defaultOptionValues["closed_geometry" ] = "no";
221 _defaultOptionValues["discard_input_topology" ] = "no";
222 _defaultOptionValues["merge_edges" ] = "no";
223 _defaultOptionValues["periodic_tolerance" ] = "1e-5*D";
224 _defaultOptionValues["process_3d_topology" ] = "no";
225 _defaultOptionValues["remove_duplicate_cad_faces" ] = "no";
226 _defaultOptionValues["remove_tiny_uv_edges" ] = "no";
227 _defaultOptionValues["required_entities" ] = "respect";
228 _defaultOptionValues["sewing_tolerance" ] = "5e-4*D";
229 _defaultOptionValues["tags" ] = "respect";
233 // check validity of option names of _defaultOptionValues
234 TOptionValues::iterator n2v = _defaultOptionValues.begin();
235 for ( ; n2v != _defaultOptionValues.end(); ++n2v )
236 ASSERT( _option2value.count( n2v->first ) || _preCADoption2value.count( n2v->first ));
237 ASSERT( _option2value.size() + _preCADoption2value.size() == _defaultOptionValues.size() );
242 _faceEntryEnfVertexListMap.clear();
243 _enfVertexList.clear();
244 _faceEntryCoordsListMap.clear();
245 _coordsEnfVertexMap.clear();
246 _faceEntryEnfVertexEntryListMap.clear();
247 _enfVertexEntryEnfVertexMap.clear();
248 _groupNameNodeIDMap.clear();
251 _groupNameEnfVertexListMap.clear();
252 _enfVertexGroupNameMap.clear();
256 TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry)
258 GEOM::GEOM_Object_var aGeomObj;
260 TopoDS_Shape S = TopoDS_Shape();
261 SALOMEDS::SObject_var aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( entry.c_str() );
262 if (!aSObj->_is_nil() ) {
263 CORBA::Object_var obj = aSObj->GetObject();
264 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
267 if ( !aGeomObj->_is_nil() )
268 S = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aGeomObj.in() );
272 //=============================================================================
273 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
274 if (thePhysicalMesh != _physicalMesh) {
275 _physicalMesh = thePhysicalMesh;
276 NotifySubMeshesHypothesisModification();
280 //=============================================================================
281 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
282 if (theGeometricMesh != _geometricMesh) {
283 _geometricMesh = theGeometricMesh;
284 // switch (_geometricMesh) {
287 // _angleMesh = GetDefaultAngleMesh();
288 // _gradation = GetDefaultGradation();
291 NotifySubMeshesHypothesisModification();
295 //=============================================================================
296 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal, bool isRelative) {
297 if ((theVal != _phySize) || (isRelative != _phySizeRel)) {
298 _phySizeRel = isRelative;
300 _phySize = GetMaxSize();
304 NotifySubMeshesHypothesisModification();
308 //=============================================================================
309 void BLSURFPlugin_Hypothesis::SetMinSize(double theMinSize, bool isRelative) {
310 if ((theMinSize != _minSize) || (isRelative != _minSizeRel)) {
311 _minSizeRel = isRelative;
312 _minSize = theMinSize;
313 NotifySubMeshesHypothesisModification();
317 //=============================================================================
318 void BLSURFPlugin_Hypothesis::SetMaxSize(double theMaxSize, bool isRelative) {
319 if ((theMaxSize != _maxSize) || (isRelative != _maxSizeRel)) {
320 _maxSizeRel = isRelative;
321 _maxSize = theMaxSize;
322 NotifySubMeshesHypothesisModification();
326 //=============================================================================
327 void BLSURFPlugin_Hypothesis::SetUseGradation(bool theVal) {
328 if (theVal != _useGradation) {
329 _useGradation = theVal;
330 NotifySubMeshesHypothesisModification();
334 //=============================================================================
335 void BLSURFPlugin_Hypothesis::SetGradation(double theVal) {
336 _useGradation = ( theVal > 0 );
337 if (theVal != _gradation) {
339 NotifySubMeshesHypothesisModification();
343 //=============================================================================
344 void BLSURFPlugin_Hypothesis::SetUseVolumeGradation(bool theVal) {
345 if (theVal != _useVolumeGradation) {
346 _useVolumeGradation = theVal;
347 NotifySubMeshesHypothesisModification();
351 //=============================================================================
352 void BLSURFPlugin_Hypothesis::SetVolumeGradation(double theVal) {
353 _useVolumeGradation = ( theVal > 0 );
354 if (theVal != _volumeGradation) {
355 _volumeGradation = theVal;
356 NotifySubMeshesHypothesisModification();
360 //=============================================================================
361 void BLSURFPlugin_Hypothesis::SetElementType(ElementType theElementType) {
362 if (theElementType != _elementType) {
363 _elementType = theElementType;
364 NotifySubMeshesHypothesisModification();
368 //=============================================================================
369 void BLSURFPlugin_Hypothesis::SetAngleMesh(double theVal) {
370 if (theVal != _angleMesh) {
372 NotifySubMeshesHypothesisModification();
376 //=============================================================================
377 void BLSURFPlugin_Hypothesis::SetChordalError(double theDistance) {
378 if (theDistance != _chordalError) {
379 _chordalError = theDistance;
380 NotifySubMeshesHypothesisModification();
384 //=============================================================================
385 void BLSURFPlugin_Hypothesis::SetAnisotropic(bool theVal) {
386 if (theVal != _anisotropic) {
387 _anisotropic = theVal;
388 NotifySubMeshesHypothesisModification();
392 //=============================================================================
393 void BLSURFPlugin_Hypothesis::SetAnisotropicRatio(double theVal) {
394 if (theVal != _anisotropicRatio) {
395 _anisotropicRatio = theVal;
396 NotifySubMeshesHypothesisModification();
400 //=============================================================================
401 void BLSURFPlugin_Hypothesis::SetRemoveTinyEdges(bool theVal) {
402 if (theVal != _removeTinyEdges) {
403 _removeTinyEdges = theVal;
404 NotifySubMeshesHypothesisModification();
408 //=============================================================================
409 void BLSURFPlugin_Hypothesis::SetTinyEdgeLength(double theVal) {
410 if (theVal != _tinyEdgeLength) {
411 _tinyEdgeLength = theVal;
412 NotifySubMeshesHypothesisModification();
416 //=============================================================================
417 void BLSURFPlugin_Hypothesis::SetOptimiseTinyEdges(bool theVal) {
418 if (theVal != _optimiseTinyEdges) {
419 _optimiseTinyEdges = theVal;
420 NotifySubMeshesHypothesisModification();
424 //=============================================================================
425 void BLSURFPlugin_Hypothesis::SetTinyEdgeOptimisationLength(double theVal) {
426 if (theVal != _tinyEdgeOptimisationLength) {
427 _tinyEdgeOptimisationLength = theVal;
428 NotifySubMeshesHypothesisModification();
432 //=============================================================================
433 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersection(bool theVal) {
434 if (theVal != _correctSurfaceIntersec) {
435 _correctSurfaceIntersec = theVal;
436 NotifySubMeshesHypothesisModification();
440 //=============================================================================
441 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersectionMaxCost(double theVal) {
442 if (theVal != _corrSurfaceIntersCost) {
443 _corrSurfaceIntersCost = theVal;
444 NotifySubMeshesHypothesisModification();
448 //=============================================================================
449 void BLSURFPlugin_Hypothesis::SetBadElementRemoval(bool theVal) {
450 if (theVal != _badElementRemoval) {
451 _badElementRemoval = theVal;
452 NotifySubMeshesHypothesisModification();
456 //=============================================================================
457 void BLSURFPlugin_Hypothesis::SetBadElementAspectRatio(double theVal) {
458 if (theVal != _badElementAspectRatio) {
459 _badElementAspectRatio = theVal;
460 NotifySubMeshesHypothesisModification();
464 //=============================================================================
465 void BLSURFPlugin_Hypothesis::SetOptimizeMesh(bool theVal) {
466 if (theVal != _optimizeMesh) {
467 _optimizeMesh = theVal;
468 NotifySubMeshesHypothesisModification();
472 //=============================================================================
473 void BLSURFPlugin_Hypothesis::SetQuadraticMesh(bool theVal) {
474 if (theVal != _quadraticMesh) {
475 _quadraticMesh = theVal;
476 NotifySubMeshesHypothesisModification();
480 //=============================================================================
481 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology) {
482 if (theTopology != _topology) {
483 _topology = theTopology;
484 NotifySubMeshesHypothesisModification();
488 //=============================================================================
489 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
490 if (theVal != _verb) {
492 NotifySubMeshesHypothesisModification();
496 //=============================================================================
497 void BLSURFPlugin_Hypothesis::SetEnforceCadEdgesSize( bool toEnforce )
499 if ( GetEnforceCadEdgesSize() != toEnforce )
501 SetOptionValue( "enforce_cad_edge_sizes", toEnforce ? "yes" : "no" );
502 NotifySubMeshesHypothesisModification();
505 //=============================================================================
506 bool BLSURFPlugin_Hypothesis::GetEnforceCadEdgesSize()
508 return ToBool( GetOptionValue( "enforce_cad_edge_sizes" ), GET_DEFAULT() );
510 //=============================================================================
512 void BLSURFPlugin_Hypothesis::SetJacobianRectificationRespectGeometry( bool allowRectification )
514 if ( GetJacobianRectificationRespectGeometry() != allowRectification )
516 SetOptionValue("jacobian_rectification_respect_geometry", allowRectification ? "yes" : "no" );
517 NotifySubMeshesHypothesisModification();
520 //=============================================================================
521 bool BLSURFPlugin_Hypothesis::GetJacobianRectificationRespectGeometry()
523 return ToBool( GetOptionValue("jacobian_rectification_respect_geometry", GET_DEFAULT()));
525 //=============================================================================
527 void BLSURFPlugin_Hypothesis::SetJacobianRectification( bool allowRectification )
529 if ( GetJacobianRectification() != allowRectification )
531 SetOptionValue( "rectify_jacobian", allowRectification ? "yes" : "no" );
532 NotifySubMeshesHypothesisModification();
535 //=============================================================================
536 bool BLSURFPlugin_Hypothesis::GetJacobianRectification()
538 return ToBool( GetOptionValue("rectify_jacobian", GET_DEFAULT()));
540 //=============================================================================
542 void BLSURFPlugin_Hypothesis::SetUseDeprecatedPatchMesher( bool useDeprecatedPatchMesher )
544 if ( GetUseDeprecatedPatchMesher() != useDeprecatedPatchMesher )
546 SetOptionValue( "use_deprecated_patch_mesher", useDeprecatedPatchMesher ? "yes" : "no" );
547 NotifySubMeshesHypothesisModification();
550 //=============================================================================
551 bool BLSURFPlugin_Hypothesis::GetUseDeprecatedPatchMesher()
553 return ToBool( GetOptionValue("use_deprecated_patch_mesher", GET_DEFAULT()));
555 //=============================================================================
557 void BLSURFPlugin_Hypothesis::SetMaxNumberOfPointsPerPatch( int nb )
558 throw (std::invalid_argument)
561 throw std::invalid_argument( SMESH_Comment("Invalid number of points: ") << nb );
563 if ( GetMaxNumberOfPointsPerPatch() != nb )
565 SetOptionValue("max_number_of_points_per_patch", SMESH_Comment( nb ));
566 NotifySubMeshesHypothesisModification();
569 //=============================================================================
570 int BLSURFPlugin_Hypothesis::GetMaxNumberOfPointsPerPatch()
572 return ToInt( GetOptionValue("max_number_of_points_per_patch", GET_DEFAULT()));
574 //=============================================================================
576 void BLSURFPlugin_Hypothesis::SetMaxNumberOfThreads( int nb )
577 throw (std::invalid_argument)
580 throw std::invalid_argument( SMESH_Comment("Invalid number of threads: ") << nb );
582 if ( GetMaxNumberOfThreads() != nb )
584 SetOptionValue("max_number_of_threads", SMESH_Comment( nb ));
585 NotifySubMeshesHypothesisModification();
588 //=============================================================================
589 int BLSURFPlugin_Hypothesis::GetMaxNumberOfThreads()
591 return ToInt( GetOptionValue("max_number_of_threads", GET_DEFAULT()));
593 //=============================================================================
595 void BLSURFPlugin_Hypothesis::SetRespectGeometry( bool toRespect )
597 if ( GetRespectGeometry() != toRespect )
599 SetOptionValue("respect_geometry", toRespect ? "yes" : "no" );
600 NotifySubMeshesHypothesisModification();
603 //=============================================================================
604 bool BLSURFPlugin_Hypothesis::GetRespectGeometry()
606 return ToBool( GetOptionValue( "respect_geometry", GET_DEFAULT()));
608 //=============================================================================
610 void BLSURFPlugin_Hypothesis::SetTinyEdgesAvoidSurfaceIntersections( bool toAvoidIntersection )
612 if ( GetTinyEdgesAvoidSurfaceIntersections() != toAvoidIntersection )
614 SetOptionValue("tiny_edge_avoid_surface_intersections", toAvoidIntersection ? "yes" : "no" );
615 NotifySubMeshesHypothesisModification();
618 //=============================================================================
619 bool BLSURFPlugin_Hypothesis::GetTinyEdgesAvoidSurfaceIntersections()
621 return ToBool( GetOptionValue("tiny_edge_avoid_surface_intersections", GET_DEFAULT()));
623 //=============================================================================
625 void BLSURFPlugin_Hypothesis::SetClosedGeometry( bool isClosed )
627 if ( GetClosedGeometry() != isClosed )
629 SetPreCADOptionValue("closed_geometry", isClosed ? "yes" : "no" );
630 NotifySubMeshesHypothesisModification();
633 //=============================================================================
634 bool BLSURFPlugin_Hypothesis::GetClosedGeometry()
636 return ToBool( GetPreCADOptionValue( "closed_geometry", GET_DEFAULT()));
638 //=============================================================================
640 void BLSURFPlugin_Hypothesis::SetDebug( bool isDebug )
642 if ( GetDebug() != isDebug )
644 SetPreCADOptionValue("debug", isDebug ? "yes" : "no" );
645 NotifySubMeshesHypothesisModification();
648 //=============================================================================
649 bool BLSURFPlugin_Hypothesis::GetDebug()
651 return ToBool( GetPreCADOptionValue("debug", GET_DEFAULT()));
653 //=============================================================================
655 void BLSURFPlugin_Hypothesis::SetPeriodicTolerance( CORBA::Double tol )
656 throw (std::invalid_argument)
659 throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
660 if ( GetPeriodicTolerance() != tol )
662 SetPreCADOptionValue("periodic_tolerance", SMESH_Comment( tol ) );
663 NotifySubMeshesHypothesisModification();
666 //=============================================================================
667 double BLSURFPlugin_Hypothesis::GetPeriodicTolerance()
669 return ToDbl( GetPreCADOptionValue( "periodic_tolerance", GET_DEFAULT()));
671 //=============================================================================
673 void BLSURFPlugin_Hypothesis::SetRequiredEntities( const std::string& howToTreat )
674 throw (std::invalid_argument)
676 if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear" )
677 throw std::invalid_argument
678 ( SMESH_Comment("required_entities must be in ['respect','ignore','clear'] "));
680 if ( GetRequiredEntities() != howToTreat )
682 SetPreCADOptionValue("required_entities", howToTreat );
683 NotifySubMeshesHypothesisModification();
686 //=============================================================================
687 std::string BLSURFPlugin_Hypothesis::GetRequiredEntities()
689 return GetPreCADOptionValue("required_entities", GET_DEFAULT());
691 //=============================================================================
693 void BLSURFPlugin_Hypothesis::SetSewingTolerance( CORBA::Double tol )
694 throw (std::invalid_argument)
697 throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
698 if ( GetSewingTolerance() != tol )
700 SetPreCADOptionValue("sewing_tolerance", SMESH_Comment( tol ) );
701 NotifySubMeshesHypothesisModification();
704 //=============================================================================
705 CORBA::Double BLSURFPlugin_Hypothesis::GetSewingTolerance()
707 return ToDbl( GetPreCADOptionValue("sewing_tolerance", GET_DEFAULT()));
709 //=============================================================================
711 void BLSURFPlugin_Hypothesis::SetTags( const std::string& howToTreat )
712 throw (std::invalid_argument)
714 if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear" )
715 throw std::invalid_argument
716 ( SMESH_Comment("'tags' must be in ['respect','ignore','clear'] "));
718 if ( GetTags() != howToTreat )
720 SetPreCADOptionValue("tags", howToTreat );
721 NotifySubMeshesHypothesisModification();
724 //=============================================================================
725 std::string BLSURFPlugin_Hypothesis::GetTags()
727 return GetPreCADOptionValue("tags", GET_DEFAULT());
729 //=============================================================================
730 void BLSURFPlugin_Hypothesis::SetHyperPatches(const THyperPatchList& hpl)
732 if ( hpl != _hyperPatchList )
734 // join patches sharing tags
735 _hyperPatchList.clear();
736 for ( size_t i = 0; i < hpl.size(); ++i )
738 const THyperPatchTags& tags = hpl[i];
739 if ( tags.size() < 2 ) continue;
741 std::set<int> iPatches;
742 if ( !_hyperPatchList.empty() )
744 THyperPatchTags::iterator t = tags.begin();
745 for ( ; t != tags.end(); ++t )
748 GetHyperPatchTag( *t, this, &iPatch );
750 iPatches.insert( iPatch );
754 if ( iPatches.empty() )
756 _hyperPatchList.push_back( tags );
760 std::set<int>::iterator iPatch = iPatches.begin();
761 THyperPatchTags& mainPatch = _hyperPatchList[ *iPatch ];
762 mainPatch.insert( tags.begin(), tags.end() );
764 for ( ++iPatch; iPatch != iPatches.end(); ++iPatch )
766 mainPatch.insert( _hyperPatchList[ *iPatch ].begin(), _hyperPatchList[ *iPatch ].end() );
767 _hyperPatchList[ *iPatch ].clear();
769 if ( iPatches.size() > 1 )
770 for ( int j = _hyperPatchList.size()-1; j > 0; --j )
771 if ( _hyperPatchList[j].empty() )
772 _hyperPatchList.erase( _hyperPatchList.begin() + j );
775 NotifySubMeshesHypothesisModification();
778 //=============================================================================
780 * \brief Return a tag of a face taking into account the hyper-patches. Optionally
781 * return an index of a patch including the face
783 //================================================================================
785 int BLSURFPlugin_Hypothesis::GetHyperPatchTag( const int faceTag,
786 const BLSURFPlugin_Hypothesis* hyp,
791 const THyperPatchList& hpl = hyp->_hyperPatchList;
792 for ( size_t i = 0; i < hpl.size(); ++i )
793 if ( hpl[i].count( faceTag ))
795 if ( iPatch ) *iPatch = i;
796 return *( hpl[i].begin() );
801 //=============================================================================
802 void BLSURFPlugin_Hypothesis::SetPreCADMergeEdges(bool theVal)
804 if (theVal != ToBool( GetPreCADOptionValue("merge_edges", GET_DEFAULT()))) {
805 _preCADMergeEdges = theVal;
806 SetPreCADOptionValue("merge_edges", theVal ? "yes" : "no" );
807 NotifySubMeshesHypothesisModification();
811 //=============================================================================
812 void BLSURFPlugin_Hypothesis::SetPreCADRemoveDuplicateCADFaces(bool theVal)
814 if (theVal != ToBool( GetPreCADOptionValue("remove_duplicate_cad_faces", GET_DEFAULT()))) {
815 _preCADRemoveDuplicateCADFaces = theVal;
816 SetPreCADOptionValue("remove_duplicate_cad_faces", theVal ? "yes" : "no" );
817 NotifySubMeshesHypothesisModification();
821 //=============================================================================
822 void BLSURFPlugin_Hypothesis::SetPreCADProcess3DTopology(bool theVal)
824 if (theVal != ToBool( GetPreCADOptionValue("process_3d_topology", GET_DEFAULT()))) {
825 _preCADProcess3DTopology = theVal;
826 SetPreCADOptionValue("process_3d_topology", theVal ? "yes" : "no" );
827 NotifySubMeshesHypothesisModification();
831 //=============================================================================
832 void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal)
834 if (theVal != ToBool( GetPreCADOptionValue("discard_input_topology", GET_DEFAULT()))) {
835 _preCADDiscardInput = theVal;
836 SetPreCADOptionValue("discard_input_topology", theVal ? "yes" : "no" );
837 NotifySubMeshesHypothesisModification();
841 //=============================================================================
842 // Return true if any PreCAD option is activated
843 bool BLSURFPlugin_Hypothesis::HasPreCADOptions(const BLSURFPlugin_Hypothesis* hyp)
845 if ( !hyp || hyp->_name == GetHypType(/*hasgeom=*/false))
849 bool orDefault, isOk;
850 return ( ToBool( hyp->GetPreCADOptionValue("closed_geometry" , &orDefault )) ||
851 ToBool( hyp->GetPreCADOptionValue("discard_input_topology" , &orDefault )) ||
852 ToBool( hyp->GetPreCADOptionValue("merge_edges" , &orDefault )) ||
853 ToBool( hyp->GetPreCADOptionValue("remove_duplicate_cad_faces", &orDefault )) ||
854 ToBool( hyp->GetPreCADOptionValue("process_3d_topology" , &orDefault )) ||
855 ToBool( hyp->GetPreCADOption ("manifold_geometry") , &isOk ) ||
856 hyp->GetPreCADOptionValue("sewing_tolerance", &orDefault ) != "5e-4*D" ||
857 !hyp->_preCadFacesPeriodicityVector.empty() ||
858 !hyp->_preCadEdgesPeriodicityVector.empty() ||
859 !hyp->_facesPeriodicityVector.empty() ||
860 !hyp->_edgesPeriodicityVector.empty() ||
861 !hyp->_verticesPeriodicityVector.empty() ||
862 !hyp->GetHyperPatches().empty() ||
863 hyp->GetTopology() != FromCAD );
866 //=============================================================================
867 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
868 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
870 _GMFFileName = theFileName;
871 // _GMFFileMode = isBinary;
872 NotifySubMeshesHypothesisModification();
875 //=============================================================================
876 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
877 throw (std::invalid_argument) {
879 TOptionValues::iterator op_val = _option2value.find(optionName);
880 if (op_val == _option2value.end())
882 op_val = _preCADoption2value.find(optionName);
883 if (op_val == _preCADoption2value.end())
885 std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'. Try SetAdvancedOption()";
886 throw std::invalid_argument(msg);
889 if (op_val->second != optionValue)
891 const char* ptr = optionValue.c_str();
892 // strip white spaces
893 while (ptr[0] == ' ')
896 while (i != 0 && ptr[i - 1] == ' ')
900 std::string typeName;
903 } else if (_charOptions.count(optionName)) {
904 // do not check strings
905 } else if (_doubleOptions.count(optionName)) {
906 // check if value is double
909 } else if (_boolOptions.count(optionName)) {
910 // check if value is bool
911 ToBool(ptr, &typeOk);
914 // check if value is int
916 typeName = "integer";
919 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
920 throw std::invalid_argument(msg);
922 std::string value( ptr, i );
923 if ( _defaultOptionValues[ optionName ] == value )
926 op_val->second = value;
928 NotifySubMeshesHypothesisModification();
932 //=============================================================================
933 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
934 throw (std::invalid_argument) {
936 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
937 if (op_val == _preCADoption2value.end()) {
938 op_val = _option2value.find(optionName);
939 if (op_val == _option2value.end()) {
940 std::string msg = "Unknown MG-PreCAD option: '" + optionName + "'. Try SetAdvancedOption()";
941 throw std::invalid_argument(msg);
944 if (op_val->second != optionValue)
946 const char* ptr = optionValue.c_str();
947 // strip white spaces
948 while (ptr[0] == ' ')
951 while (i != 0 && ptr[i - 1] == ' ')
955 std::string typeName;
958 } else if (_preCADcharOptions.find(optionName) != _preCADcharOptions.end()) {
959 // do not check strings
960 } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
961 // check if value is double
963 strtod(ptr, &endPtr);
964 typeOk = (ptr != endPtr);
966 } else if (_boolOptions.count(optionName)) {
967 // check if value is bool
968 ToBool(ptr, &typeOk);
971 // check if value is int
973 strtol(ptr, &endPtr, 10);
974 typeOk = (ptr != endPtr);
975 typeName = "integer";
978 std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
979 throw std::invalid_argument(msg);
981 std::string value( ptr, i );
982 if ( _defaultOptionValues[ optionName ] == value )
985 op_val->second = value;
987 NotifySubMeshesHypothesisModification();
991 //=============================================================================
992 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
993 bool* isDefault) const
994 throw (std::invalid_argument)
996 TOptionValues::const_iterator op_val = _option2value.find(optionName);
997 if (op_val == _option2value.end())
999 op_val = _preCADoption2value.find(optionName);
1000 if (op_val == _preCADoption2value.end())
1002 op_val = _customOption2value.find(optionName);
1003 if (op_val == _customOption2value.end())
1005 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
1006 throw std::invalid_argument(msg);
1010 std::string val = op_val->second;
1011 if ( isDefault ) *isDefault = ( val.empty() );
1013 if ( val.empty() && isDefault )
1015 op_val = _defaultOptionValues.find( optionName );
1016 if (op_val != _defaultOptionValues.end())
1017 val = op_val->second;
1022 //=============================================================================
1023 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName,
1024 bool* isDefault) const
1025 throw (std::invalid_argument)
1027 TOptionValues::const_iterator op_val = _preCADoption2value.find(optionName);
1028 if (op_val == _preCADoption2value.end())
1030 op_val = _option2value.find(optionName);
1031 if (op_val == _option2value.end())
1033 op_val = _customOption2value.find(optionName);
1034 if (op_val == _customOption2value.end())
1036 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
1037 throw std::invalid_argument(msg);
1041 std::string val = op_val->second;
1042 if ( isDefault ) *isDefault = ( val.empty() );
1044 if ( val.empty() && isDefault )
1046 op_val = _defaultOptionValues.find( optionName );
1047 if (op_val != _option2value.end())
1048 val = op_val->second;
1053 //=============================================================================
1054 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
1056 TOptionValues::iterator op_val = _customOption2value.find(optionName);
1057 if (op_val != _customOption2value.end())
1058 _customOption2value.erase(op_val);
1060 op_val = _option2value.find(optionName);
1061 if (op_val != _option2value.end())
1062 op_val->second.clear();
1064 op_val = _preCADoption2value.find(optionName);
1065 if (op_val != _preCADoption2value.end())
1066 op_val->second.clear();
1071 //=============================================================================
1072 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName)
1074 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
1075 if (op_val != _preCADoption2value.end())
1076 op_val->second.clear();
1079 //=============================================================================
1080 void BLSURFPlugin_Hypothesis::AddOption(const std::string& optionName, const std::string& optionValue)
1083 TOptionValues::iterator op_val = _option2value.find(optionName);
1084 if (op_val != _option2value.end())
1086 if (op_val->second != optionValue)
1087 op_val->second = optionValue;
1093 op_val = _preCADoption2value.find(optionName);
1094 if (op_val != _preCADoption2value.end())
1096 if (op_val->second != optionValue)
1097 op_val->second = optionValue;
1101 else if ( optionValue.empty() )
1103 _customOption2value.erase( optionName );
1107 op_val = _customOption2value.find(optionName);
1108 if (op_val == _customOption2value.end())
1109 _customOption2value[optionName] = optionValue;
1110 else if (op_val->second != optionValue)
1111 op_val->second = optionValue;
1117 NotifySubMeshesHypothesisModification();
1120 //=============================================================================
1121 void BLSURFPlugin_Hypothesis::AddPreCADOption(const std::string& optionName, const std::string& optionValue)
1123 AddOption( optionName, optionValue );
1126 //=============================================================================
1127 std::string BLSURFPlugin_Hypothesis::GetOption(const std::string& optionName) const
1129 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1130 if (op_val != _customOption2value.end())
1131 return op_val->second;
1136 //=============================================================================
1137 std::string BLSURFPlugin_Hypothesis::GetPreCADOption(const std::string& optionName) const
1139 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1140 if (op_val != _customOption2value.end())
1141 return op_val->second;
1146 //=============================================================================
1147 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetOptionValues() const
1150 TOptionValues::const_iterator op_val = _option2value.begin();
1151 for ( ; op_val != _option2value.end(); ++op_val )
1152 vals.insert( make_pair( op_val->first, GetOptionValue( op_val->first, GET_DEFAULT() )));
1157 //=============================================================================
1158 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetPreCADOptionValues() const
1161 TOptionValues::const_iterator op_val = _preCADoption2value.begin();
1162 for ( ; op_val != _preCADoption2value.end(); ++op_val )
1163 vals.insert( make_pair( op_val->first, GetPreCADOptionValue( op_val->first, GET_DEFAULT() )));
1168 //=======================================================================
1169 //function : SetSizeMapEntry
1170 //=======================================================================
1171 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
1172 if (_sizeMap[entry].compare(sizeMap) != 0) {
1173 SetPhysicalMesh(PhysicalLocalSize);
1174 _sizeMap[entry] = sizeMap;
1175 NotifySubMeshesHypothesisModification();
1179 //=======================================================================
1180 //function : GetSizeMapEntry
1181 //=======================================================================
1182 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
1183 TSizeMap::iterator it = _sizeMap.find(entry);
1184 if (it != _sizeMap.end())
1187 return "No_Such_Entry";
1191 * \brief Return the size maps
1193 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
1194 return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
1197 //=======================================================================
1198 //function : SetAttractorEntry
1199 //=======================================================================
1200 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
1201 if (_attractors[entry].compare(attractor) != 0) {
1202 SetPhysicalMesh(PhysicalLocalSize);
1203 _attractors[entry] = attractor;
1204 NotifySubMeshesHypothesisModification();
1208 //=======================================================================
1209 //function : GetAttractorEntry
1210 //=======================================================================
1211 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
1212 TSizeMap::iterator it = _attractors.find(entry);
1213 if (it != _attractors.end())
1216 return "No_Such_Entry";
1220 * \brief Return the attractors
1222 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
1223 return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
1226 //=======================================================================
1227 //function : SetClassAttractorEntry
1228 //=======================================================================
1229 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
1231 SetPhysicalMesh(PhysicalLocalSize);
1233 // The new attractor can't be defined on the same face as another sizemap
1234 TSizeMap::iterator it = _sizeMap.find( entry );
1235 if ( it != _sizeMap.end() ) {
1237 NotifySubMeshesHypothesisModification();
1240 TSizeMap::iterator itAt = _attractors.find( entry );
1241 if ( itAt != _attractors.end() ) {
1242 _attractors.erase(itAt);
1243 NotifySubMeshesHypothesisModification();
1247 const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
1248 const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
1249 TAttractorMap::iterator attIt = _classAttractors.find(entry);
1250 for ( ; attIt != _classAttractors.end(); ++attIt )
1251 if ( attIt->first == entry &&
1252 attIt->second->GetAttractorEntry() == attEntry )
1254 bool attExists = (attIt != _classAttractors.end());
1256 BLSURFPlugin_Attractor* myAttractor;
1258 myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 );
1259 _classAttractors.insert( make_pair( entry, myAttractor ));
1262 myAttractor = attIt->second;
1264 // if (!myAttractor->IsMapBuilt())
1265 // myAttractor->BuildMap();
1266 myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
1268 NotifySubMeshesHypothesisModification();
1271 //=======================================================================
1272 //function : SetConstantSizeOnAdjacentFaces
1273 //=======================================================================
1274 // TODO uncomment and test (include the needed .hxx)
1275 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist ) {
1276 // TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
1277 // TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
1278 // TopTools_IndexedMapOfShapListOdShape::iterator it;
1279 // for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
1280 // SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
1288 //=======================================================================
1289 //function : GetClassAttractorEntry
1290 //=======================================================================
1291 // BLSURFPlugin_Attractor& BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
1293 // TAttractorMap::iterator it = _classAttractors.find( entry );
1294 // if ( it != _classAttractors.end() )
1295 // return it->second;
1297 // return "No_Such_Entry";
1301 * \brief Return the map of attractor instances
1303 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
1305 return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
1308 //=======================================================================
1309 //function : ClearEntry
1310 //=======================================================================
1311 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
1312 const char * attEntry/*=0*/)
1314 TSizeMap::iterator it = _sizeMap.find( entry );
1316 if ( it != _sizeMap.end() ) {
1318 NotifySubMeshesHypothesisModification();
1321 TSizeMap::iterator itAt = _attractors.find( entry );
1322 if ( itAt != _attractors.end() ) {
1323 _attractors.erase(itAt);
1324 NotifySubMeshesHypothesisModification();
1327 TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
1328 if ( it_clAt != _classAttractors.end() ) {
1330 if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
1331 _classAttractors.erase( it_clAt++ );
1335 while ( it_clAt != _classAttractors.end() );
1336 NotifySubMeshesHypothesisModification();
1339 std::cout<<"No_Such_Entry"<<std::endl;
1344 //=======================================================================
1345 //function : ClearSizeMaps
1346 //=======================================================================
1347 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
1349 _attractors.clear();
1350 _classAttractors.clear();
1353 // Enable internal enforced vertices on specific face if requested by user
1355 ////=======================================================================
1356 ////function : SetInternalEnforcedVertex
1357 ////=======================================================================
1358 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
1359 // bool toEnforceInternalVertices,
1360 // TEnfGroupName theGroupName) {
1362 // << toEnforceInternalVertices << ", " << theGroupName << ")");
1364 // TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
1365 // if (it != _faceEntryInternalVerticesList.end()) {
1366 // if (!toEnforceInternalVertices) {
1367 // _faceEntryInternalVerticesList.erase(it);
1371 // if (toEnforceInternalVertices) {
1372 // _faceEntryInternalVerticesList.insert(theFaceEntry);
1377 // // Take care of groups
1381 //=======================================================================
1382 //function : SetEnforcedVertex
1383 //=======================================================================
1384 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry,
1385 TEnfName theVertexName,
1386 TEntry theVertexEntry,
1387 TEnfGroupName theGroupName,
1388 double x, double y, double z)
1390 SetPhysicalMesh(PhysicalLocalSize);
1392 bool toNotify = false;
1393 bool toCreate = true;
1395 TEnfVertex *oldEnVertex;
1396 TEnfVertex *newEnfVertex = new TEnfVertex();
1397 newEnfVertex->name = theVertexName;
1398 newEnfVertex->geomEntry = theVertexEntry;
1399 newEnfVertex->coords.clear();
1400 if (theVertexEntry == "") {
1401 newEnfVertex->coords.push_back(x);
1402 newEnfVertex->coords.push_back(y);
1403 newEnfVertex->coords.push_back(z);
1405 newEnfVertex->grpName = theGroupName;
1406 newEnfVertex->faceEntries.clear();
1407 newEnfVertex->faceEntries.insert(theFaceEntry);
1410 // update _enfVertexList
1411 TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
1412 if (it != _enfVertexList.end()) {
1414 oldEnVertex = (*it);
1415 if (oldEnVertex->name != theVertexName) {
1416 oldEnVertex->name = theVertexName;
1419 if (oldEnVertex->grpName != theGroupName) {
1420 oldEnVertex->grpName = theGroupName;
1423 TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
1424 if (it_faceEntries == oldEnVertex->faceEntries.end()) {
1425 oldEnVertex->faceEntries.insert(theFaceEntry);
1426 _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
1430 // update map coords / enf vertex if needed
1431 if (oldEnVertex->coords.size()) {
1432 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
1433 _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
1436 // update map geom entry / enf vertex if needed
1437 if (oldEnVertex->geomEntry != "") {
1438 _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
1439 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
1444 // //////// CREATE ////////////
1447 _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
1448 _enfVertexList.insert(newEnfVertex);
1449 if (theVertexEntry == "") {
1450 _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
1451 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
1454 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
1455 _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
1460 NotifySubMeshesHypothesisModification();
1466 //=======================================================================
1467 //function : GetEnforcedVertices
1468 //=======================================================================
1470 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
1471 throw (std::invalid_argument) {
1473 if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
1474 return _faceEntryEnfVertexListMap[theFaceEntry];
1476 return GetDefaultEnfVertexList();
1478 std::ostringstream msg;
1479 msg << "No enforced vertex for face entry " << theFaceEntry;
1480 throw std::invalid_argument(msg.str());
1483 //=======================================================================
1484 //function : GetEnfVertexCoordsList
1485 //=======================================================================
1487 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
1488 const TEntry& theFaceEntry) throw (std::invalid_argument) {
1490 if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
1491 return _faceEntryCoordsListMap[theFaceEntry];
1493 std::ostringstream msg;
1494 msg << "No enforced vertex coords for face entry " << theFaceEntry;
1495 throw std::invalid_argument(msg.str());
1498 //=======================================================================
1499 //function : GetEnfVertexEntryList
1500 //=======================================================================
1502 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
1503 throw (std::invalid_argument) {
1505 if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
1506 return _faceEntryEnfVertexEntryListMap[theFaceEntry];
1508 std::ostringstream msg;
1509 msg << "No enforced vertex entry for face entry " << theFaceEntry;
1510 throw std::invalid_argument(msg.str());
1513 //=======================================================================
1514 //function : GetEnfVertex(TEnfVertexCoords coords)
1515 //=======================================================================
1517 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
1518 throw (std::invalid_argument) {
1520 if (_coordsEnfVertexMap.count(coords) > 0)
1521 return _coordsEnfVertexMap[coords];
1523 std::ostringstream msg;
1524 msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
1525 throw std::invalid_argument(msg.str());
1528 //=======================================================================
1529 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
1530 //=======================================================================
1532 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
1533 throw (std::invalid_argument) {
1535 if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
1536 return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
1538 std::ostringstream msg;
1539 msg << "No enforced vertex with entry " << theEnfVertexEntry;
1540 throw std::invalid_argument(msg.str());
1543 //Enable internal enforced vertices on specific face if requested by user
1544 ////=======================================================================
1545 ////function : GetInternalEnforcedVertex
1546 ////=======================================================================
1548 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
1550 // if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
1555 //=======================================================================
1556 //function : ClearEnforcedVertex
1557 //=======================================================================
1559 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
1560 const TEntry& theVertexEntry) throw (std::invalid_argument) {
1562 bool toNotify = false;
1563 std::ostringstream msg;
1564 TEnfVertex *oldEnfVertex;
1565 TEnfVertexCoords coords;
1567 coords.push_back(x);
1568 coords.push_back(y);
1569 coords.push_back(z);
1571 // check that enf vertex with given enf vertex entry exists
1572 TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
1573 if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
1575 oldEnfVertex = it_enfVertexEntry->second;
1577 _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
1579 TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
1580 enfVertexEntryList.erase(theVertexEntry);
1581 if (enfVertexEntryList.size() == 0)
1582 _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
1583 // TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1584 // TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
1585 // it_entry_entry->second.erase(it_entryList);
1586 // if (it_entry_entry->second.size() == 0)
1587 // _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1590 MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
1591 msg << "No enforced vertex with geom entry " << theVertexEntry;
1592 // check that enf vertex with given coords exists
1593 TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
1594 if (it_coords_enf != _coordsEnfVertexMap.end()) {
1596 oldEnfVertex = it_coords_enf->second;
1598 _coordsEnfVertexMap.erase(it_coords_enf);
1600 TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
1601 enfVertexCoordsList.erase(coords);
1602 if (enfVertexCoordsList.size() == 0)
1603 _faceEntryCoordsListMap.erase(theFaceEntry);
1604 // TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1605 // TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
1606 // it_entry_coords->second.erase(it_coordsList);
1607 // if (it_entry_coords->second.size() == 0)
1608 // _faceEntryCoordsListMap.erase(it_entry_coords);
1611 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
1613 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
1614 throw std::invalid_argument(msg.str());
1618 // update _enfVertexList
1619 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1620 if (it != _enfVertexList.end()) {
1621 (*it)->faceEntries.erase(theFaceEntry);
1622 if ((*it)->faceEntries.size() == 0){
1623 _enfVertexList.erase(it);
1628 // update _faceEntryEnfVertexListMap
1629 TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
1630 currentEnfVertexList.erase(oldEnfVertex);
1632 if (currentEnfVertexList.size() == 0) {
1633 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1637 NotifySubMeshesHypothesisModification();
1642 //=======================================================================
1643 //function : ClearEnforcedVertices
1644 //=======================================================================
1646 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
1648 bool toNotify = false;
1649 TEnfVertex *oldEnfVertex;
1651 TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1652 if (it_entry_coords != _faceEntryCoordsListMap.end()) {
1654 TEnfVertexCoordsList coordsList = it_entry_coords->second;
1655 TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
1656 for (; it_coordsList != coordsList.end(); ++it_coordsList) {
1657 TEnfVertexCoords coords = (*it_coordsList);
1658 oldEnfVertex = _coordsEnfVertexMap[coords];
1659 _coordsEnfVertexMap.erase(coords);
1660 // update _enfVertexList
1661 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1662 if (it != _enfVertexList.end()) {
1663 (*it)->faceEntries.erase(theFaceEntry);
1664 if ((*it)->faceEntries.size() == 0){
1665 _enfVertexList.erase(it);
1670 _faceEntryCoordsListMap.erase(it_entry_coords);
1671 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1674 TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1675 if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
1677 TEntryList enfVertexEntryList = it_entry_entry->second;
1678 TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
1679 for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
1680 TEntry enfVertexEntry = (*it_enfVertexEntryList);
1681 oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
1682 _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
1683 // update _enfVertexList
1684 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1685 if (it != _enfVertexList.end()) {
1686 (*it)->faceEntries.erase(theFaceEntry);
1687 if ((*it)->faceEntries.size() == 0){
1688 _enfVertexList.erase(it);
1693 _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1694 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1698 NotifySubMeshesHypothesisModification();
1701 // std::ostringstream msg;
1702 // msg << "No enforced vertex for " << theFaceEntry;
1703 // throw std::invalid_argument(msg.str());
1706 //=======================================================================
1707 //function : ClearAllEnforcedVertices
1708 //=======================================================================
1709 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
1710 _faceEntryEnfVertexListMap.clear();
1711 _enfVertexList.clear();
1712 _faceEntryCoordsListMap.clear();
1713 _coordsEnfVertexMap.clear();
1714 _faceEntryEnfVertexEntryListMap.clear();
1715 _enfVertexEntryEnfVertexMap.clear();
1716 // Enable internal enforced vertices on specific face if requested by user
1717 // _faceEntryInternalVerticesList.clear();
1718 NotifySubMeshesHypothesisModification();
1721 //================================================================================
1723 * \brief Return the enforced vertices
1725 //================================================================================
1728 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1729 const BLSURFPlugin_Hypothesis* hyp) {
1730 return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1733 //Enable internal enforced vertices on specific face if requested by user
1734 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1735 // const BLSURFPlugin_Hypothesis* hyp) {
1736 // return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1739 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1741 return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1744 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1746 return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1749 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1750 const BLSURFPlugin_Hypothesis* hyp) {
1751 return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1754 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1755 const BLSURFPlugin_Hypothesis* hyp) {
1756 return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1759 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1760 const BLSURFPlugin_Hypothesis* hyp) {
1761 return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1764 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1765 const BLSURFPlugin_Hypothesis* hyp) {
1766 return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1769 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1770 const BLSURFPlugin_Hypothesis* hyp) {
1771 return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1774 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1776 TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1777 if (it != _groupNameNodeIDMap.end()) {
1780 std::ostringstream msg;
1781 msg << "No group " << theGroupName;
1782 throw std::invalid_argument(msg.str());
1785 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1787 _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1790 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1792 TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1793 if (it != _groupNameNodeIDMap.end()) {
1794 std::set<int>::iterator IDit = it->second.find(theNodeID);
1795 if (IDit != it->second.end())
1796 it->second.erase(IDit);
1797 std::ostringstream msg;
1798 msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1799 throw std::invalid_argument(msg.str());
1801 std::ostringstream msg;
1802 msg << "No group " << theGroupName;
1803 throw std::invalid_argument(msg.str());
1807 //=============================================================================
1808 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1809 if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1810 _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1811 if (toEnforceInternalVertices)
1812 SetPhysicalMesh(PhysicalLocalSize);
1813 NotifySubMeshesHypothesisModification();
1818 //=============================================================================
1819 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1820 if (std::string(theGroupName) != std::string(_enforcedInternalVerticesAllFacesGroup)) {
1821 _enforcedInternalVerticesAllFacesGroup = theGroupName;
1822 NotifySubMeshesHypothesisModification();
1826 //=============================================================================
1827 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
1828 const BLSURFPlugin_Hypothesis* hyp) {
1829 return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
1832 //=============================================================================
1833 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
1834 const BLSURFPlugin_Hypothesis* hyp) {
1835 return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
1838 //=============================================================================
1839 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
1840 const BLSURFPlugin_Hypothesis* hyp) {
1841 return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
1844 //=============================================================================
1845 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
1846 const BLSURFPlugin_Hypothesis* hyp){
1847 return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
1850 //=============================================================================
1851 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
1852 const BLSURFPlugin_Hypothesis* hyp){
1853 return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
1856 //=======================================================================
1857 //function : ClearAllEnforcedVertices
1858 //=======================================================================
1859 void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
1860 _preCadFacesPeriodicityVector.clear();
1861 _preCadEdgesPeriodicityVector.clear();
1862 NotifySubMeshesHypothesisModification();
1865 //=======================================================================
1866 //function : AddPreCadFacesPeriodicity
1867 //=======================================================================
1868 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
1869 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1871 TPreCadPeriodicity preCadFacesPeriodicity;
1872 preCadFacesPeriodicity.shape1Entry = theFace1Entry;
1873 preCadFacesPeriodicity.shape2Entry = theFace2Entry;
1874 preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1875 preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1877 _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
1879 NotifySubMeshesHypothesisModification();
1882 //=======================================================================
1883 //function : AddPreCadEdgesPeriodicity
1884 //=======================================================================
1885 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
1886 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1888 TPreCadPeriodicity preCadEdgesPeriodicity;
1889 preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
1890 preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
1891 preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1892 preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1894 _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
1896 NotifySubMeshesHypothesisModification();
1899 //=============================================================================
1900 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
1902 // We must keep at least the same number of arguments when increasing the SALOME version
1903 // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
1904 // parameter can be written several times to keep the old global number of parameters.
1906 // Treat old options which are now in the advanced options
1907 TOptionValues::iterator op_val;
1909 int _preCADRemoveNanoEdges = -1;
1910 double _preCADEpsNano = -1.0;
1911 op_val = _option2value.find("respect_geometry");
1912 if (op_val != _option2value.end()) {
1913 std::string value = op_val->second;
1915 _decimesh = value.compare("1") == 0 ? 1 : 0;
1917 op_val = _preCADoption2value.find("remove_tiny_edges");
1918 if (op_val != _preCADoption2value.end()) {
1919 std::string value = op_val->second;
1921 _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
1923 op_val = _preCADoption2value.find("tiny_edge_length");
1924 if (op_val != _preCADoption2value.end()) {
1925 std::string value = op_val->second;
1927 _preCADEpsNano = strtod(value.c_str(), NULL);
1930 save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1931 << _angleMesh << " " << _gradation << " " << (int) _elementType << " " << _decimesh;
1932 save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
1933 save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1934 save << " " << (int) _enforcedInternalVerticesAllFaces;
1935 save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
1936 save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
1937 save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
1938 save << " " << (int) _preCADProcess3DTopology << " " << (int) _preCADRemoveDuplicateCADFaces;
1939 save << " " << (int)_optimiseTinyEdges << " " << _tinyEdgeOptimisationLength;
1940 save << " " << (int)_correctSurfaceIntersec << " " << _corrSurfaceIntersCost;
1941 save << " " << (int)_useGradation << " " << (int)_useVolumeGradation << " " << _volumeGradation;
1943 op_val = _option2value.begin();
1944 if (op_val != _option2value.end()) {
1945 save << " " << "__OPTIONS_BEGIN__";
1946 for (; op_val != _option2value.end(); ++op_val) {
1947 if (!op_val->second.empty())
1948 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1950 save << " " << "__OPTIONS_END__";
1953 op_val = _customOption2value.begin();
1954 if (op_val != _customOption2value.end()) {
1955 save << " " << "__CUSTOM_OPTIONS_BEGIN__";
1956 for (; op_val != _customOption2value.end(); ++op_val) {
1957 if (!op_val->second.empty())
1958 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1960 save << " " << "__CUSTOM_OPTIONS_END__";
1963 op_val = _preCADoption2value.begin();
1964 if (op_val != _preCADoption2value.end()) {
1965 save << " " << "__PRECAD_OPTIONS_BEGIN__";
1966 for (; op_val != _preCADoption2value.end(); ++op_val) {
1967 if (!op_val->second.empty())
1968 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1970 save << " " << "__PRECAD_OPTIONS_END__";
1973 TSizeMap::iterator it_sm = _sizeMap.begin();
1974 if (it_sm != _sizeMap.end()) {
1975 save << " " << "__SIZEMAP_BEGIN__";
1976 for (; it_sm != _sizeMap.end(); ++it_sm) {
1977 save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
1979 save << " " << "__SIZEMAP_END__";
1982 TSizeMap::iterator it_at = _attractors.begin();
1983 if (it_at != _attractors.end()) {
1984 save << " " << "__ATTRACTORS_BEGIN__";
1985 for (; it_at != _attractors.end(); ++it_at) {
1986 save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
1988 save << " " << "__ATTRACTORS_END__";
1991 TAttractorMap::iterator it_At = _classAttractors.begin();
1992 if (it_At != _classAttractors.end()) {
1993 std::ostringstream test;
1994 save << " " << "__NEW_ATTRACTORS_BEGIN__";
1995 test << " " << "__NEW_ATTRACTORS_BEGIN__";
1996 for (; it_At != _classAttractors.end(); ++it_At) {
1997 std::vector<double> attParams;
1998 attParams = it_At->second->GetParameters();
1999 // double step = it_At->second->GetStep();
2000 save << " " << it_At->first;
2001 save << " " << it_At->second->GetAttractorEntry();
2002 save << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
2003 // save << " " << step;
2004 test << " " << it_At->first;
2005 test << " " << it_At->second->GetAttractorEntry();
2006 test << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
2007 // test << " " << step;
2009 save << " " << "__NEW_ATTRACTORS_END__";
2010 test << " " << "__NEW_ATTRACTORS_END__";
2013 TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
2014 if (it_enf != _enfVertexList.end()) {
2015 save << " " << "__ENFORCED_VERTICES_BEGIN__";
2016 for (; it_enf != _enfVertexList.end(); ++it_enf) {
2017 TEnfVertex *enfVertex = (*it_enf);
2018 save << " " << "__BEGIN_VERTEX__";
2019 if (!enfVertex->name.empty()) {
2020 save << " " << "__BEGIN_NAME__";
2021 save << " " << enfVertex->name;
2022 save << " " << "__END_NAME__";
2024 if (!enfVertex->geomEntry.empty()) {
2025 save << " " << "__BEGIN_ENTRY__";
2026 save << " " << enfVertex->geomEntry;
2027 save << " " << "__END_ENTRY__";
2029 if (!enfVertex->grpName.empty()) {
2030 save << " " << "__BEGIN_GROUP__";
2031 save << " " << enfVertex->grpName;
2032 save << " " << "__END_GROUP__";
2034 if (enfVertex->coords.size()) {
2035 save << " " << "__BEGIN_COORDS__";
2036 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
2037 save << " " << enfVertex->coords[i];
2038 save << " " << "__END_COORDS__";
2040 TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
2041 bool hasFaces = false;
2042 if (faceEntriesIt != enfVertex->faceEntries.end()) {
2044 save << " " << "__BEGIN_FACELIST__";
2046 for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
2047 if ( faceEntriesIt->empty() )
2048 save << " _no_face_";
2050 save << " " << (*faceEntriesIt);
2052 save << " " << "__END_FACELIST__";
2053 save << " " << "__END_VERTEX__";
2055 save << " " << "__ENFORCED_VERTICES_END__";
2060 SavePreCADPeriodicity(save, "FACES");
2061 SavePreCADPeriodicity(save, "EDGES");
2063 SaveFacesPeriodicity(save);
2064 SaveEdgesPeriodicity(save);
2065 SaveVerticesPeriodicity(save);
2068 save << " " << _hyperPatchList.size() << " ";
2069 for ( size_t i = 0; i < _hyperPatchList.size(); ++i )
2071 THyperPatchTags& patch = _hyperPatchList[i];
2072 save << patch.size() << " ";
2073 THyperPatchTags::iterator tag = patch.begin();
2074 for ( ; tag != patch.end(); ++tag )
2075 save << *tag << " ";
2081 void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
2083 TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
2084 if (it_faces_periodicity != _facesPeriodicityVector.end()) {
2085 save << " " << "__FACES_PERIODICITY_BEGIN__";
2086 for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
2087 TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
2088 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2089 save << " " << "__BEGIN_ENTRY1__";
2090 save << " " << periodicity_i.first;
2091 save << " " << "__END_ENTRY1__";
2092 save << " " << "__BEGIN_ENTRY2__";
2093 save << " " << periodicity_i.second;
2094 save << " " << "__END_ENTRY2__";
2095 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2097 save << " " << "__FACES_PERIODICITY_END__";
2101 void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
2103 TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
2104 if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
2105 save << " " << "__EDGES_PERIODICITY_BEGIN__";
2106 for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
2107 TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
2108 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2109 if (! periodicity_i.theFace1Entry.empty()){
2110 save << " " << "__BEGIN_FACE1__";
2111 save << " " << periodicity_i.theFace1Entry;
2112 save << " " << "__END_FACE1__";
2114 save << " " << "__BEGIN_EDGE1__";
2115 save << " " << periodicity_i.theEdge1Entry;
2116 save << " " << "__END_EDGE1__";
2117 if (! periodicity_i.theFace2Entry.empty()){
2118 save << " " << "__BEGIN_FACE2__";
2119 save << " " << periodicity_i.theFace2Entry;
2120 save << " " << "__END_FACE2__";
2122 save << " " << "__BEGIN_EDGE2__";
2123 save << " " << periodicity_i.theEdge2Entry;
2124 save << " " << "__END_EDGE2__";
2125 save << " " << "__BEGIN_EDGE_ORIENTATION__";
2126 save << " " << periodicity_i.edge_orientation;
2127 save << " " << "__END_EDGE_ORIENTATION__";
2128 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2130 save << " " << "__EDGES_PERIODICITY_END__";
2134 void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save){
2136 TVerticesPeriodicityVector::const_iterator it_vertices_periodicity = _verticesPeriodicityVector.begin();
2137 if (it_vertices_periodicity != _verticesPeriodicityVector.end()) {
2138 save << " " << "__VERTICES_PERIODICITY_BEGIN__";
2139 for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
2140 TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
2141 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2142 save << " " << "__BEGIN_EDGE1__";
2143 save << " " << periodicity_i.theEdge1Entry;
2144 save << " " << "__END_EDGE1__";
2145 save << " " << "__BEGIN_VERTEX1__";
2146 save << " " << periodicity_i.theVertex1Entry;
2147 save << " " << "__END_VERTEX1__";
2148 save << " " << "__BEGIN_EDGE2__";
2149 save << " " << periodicity_i.theEdge2Entry;
2150 save << " " << "__END_EDGE2__";
2151 save << " " << "__BEGIN_VERTEX2__";
2152 save << " " << periodicity_i.theVertex2Entry;
2153 save << " " << "__END_VERTEX2__";
2154 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2156 save << " " << "__VERTICES_PERIODICITY_END__";
2160 void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType) {
2161 TPreCadPeriodicityVector precad_periodicity;
2162 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
2163 precad_periodicity = _preCadFacesPeriodicityVector;
2165 precad_periodicity = _preCadEdgesPeriodicityVector;
2166 TPreCadPeriodicityVector::const_iterator it_precad_periodicity = precad_periodicity.begin();
2167 if (it_precad_periodicity != precad_periodicity.end()) {
2168 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_BEGIN__";
2169 for (; it_precad_periodicity != precad_periodicity.end(); ++it_precad_periodicity) {
2170 TPreCadPeriodicity periodicity_i = (*it_precad_periodicity);
2171 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2172 if (!periodicity_i.shape1Entry.empty()) {
2173 save << " " << "__BEGIN_ENTRY1__";
2174 save << " " << periodicity_i.shape1Entry;
2175 save << " " << "__END_ENTRY1__";
2177 if (!periodicity_i.shape2Entry.empty()) {
2178 save << " " << "__BEGIN_ENTRY2__";
2179 save << " " << periodicity_i.shape2Entry;
2180 save << " " << "__END_ENTRY2__";
2183 std::vector<std::string>::const_iterator sourceVerticesEntriesIt = periodicity_i.theSourceVerticesEntries.begin();
2184 bool hasSourceVertices = false;
2185 if (sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end()) {
2186 hasSourceVertices = true;
2187 save << " " << "__BEGIN_SOURCE_VERTICES_LIST__";
2189 for (; sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end(); ++sourceVerticesEntriesIt)
2190 save << " " << (*sourceVerticesEntriesIt);
2191 if (hasSourceVertices)
2192 save << " " << "__END_SOURCE_VERTICES_LIST__";
2194 std::vector<std::string>::const_iterator targetVerticesEntriesIt = periodicity_i.theTargetVerticesEntries.begin();
2195 bool hasTargetVertices = false;
2196 if (targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end()) {
2197 hasTargetVertices = true;
2198 save << " " << "__BEGIN_TARGET_VERTICES_LIST__";
2200 for (; targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end(); ++targetVerticesEntriesIt)
2201 save << " " << (*targetVerticesEntriesIt);
2202 if (hasTargetVertices)
2203 save << " " << "__END_TARGET_VERTICES_LIST__";
2205 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2207 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_END__";
2212 //=============================================================================
2213 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
2218 std::string option_or_sm;
2220 isOK = static_cast<bool>(load >> i);
2222 _topology = (Topology) i;
2224 load.clear(std::ios::badbit | load.rdstate());
2226 isOK = static_cast<bool>(load >> i);
2228 _physicalMesh = (PhysicalMesh) i;
2230 load.clear(std::ios::badbit | load.rdstate());
2232 isOK = static_cast<bool>(load >> i);
2234 _geometricMesh = (GeometricMesh) i;
2236 load.clear(std::ios::badbit | load.rdstate());
2238 isOK = static_cast<bool>(load >> val);
2242 load.clear(std::ios::badbit | load.rdstate());
2244 isOK = static_cast<bool>(load >> val);
2248 load.clear(std::ios::badbit | load.rdstate());
2250 isOK = static_cast<bool>(load >> val);
2254 load.clear(std::ios::badbit | load.rdstate());
2256 isOK = static_cast<bool>(load >> i);
2258 _elementType = (ElementType) i;
2260 load.clear(std::ios::badbit | load.rdstate());
2262 isOK = static_cast<bool>(load >> i);
2264 if ( i != -1) { // if value is -1, then this is no longer a standard option
2265 std::string & value = _option2value["respect_geometry"];
2266 bool _decimesh = (bool) i;
2267 value = _decimesh ? "1" : "0";
2271 load.clear(std::ios::badbit | load.rdstate());
2273 isOK = static_cast<bool>(load >> val);
2277 load.clear(std::ios::badbit | load.rdstate());
2279 isOK = static_cast<bool>(load >> val);
2283 load.clear(std::ios::badbit | load.rdstate());
2285 isOK = static_cast<bool>(load >> val);
2287 // former parameter: get min value
2288 _angleMesh = std::min(val,_angleMesh);
2290 load.clear(std::ios::badbit | load.rdstate());
2292 isOK = static_cast<bool>(load >> val);
2294 // former parameter: get min value
2295 _minSize = std::min(val,_minSize);
2297 load.clear(std::ios::badbit | load.rdstate());
2299 isOK = static_cast<bool>(load >> val);
2301 // former parameter: get max value
2302 _maxSize = std::max(val,_maxSize);
2304 load.clear(std::ios::badbit | load.rdstate());
2306 isOK = static_cast<bool>(load >> i);
2310 load.clear(std::ios::badbit | load.rdstate());
2312 isOK = static_cast<bool>(load >> i);
2314 _preCADMergeEdges = (bool) i;
2316 load.clear(std::ios::badbit | load.rdstate());
2318 isOK = static_cast<bool>(load >> i);
2320 if ( i != -1) { // if value is -1, then this is no longer a standard option
2321 std::string & value = _preCADoption2value["remove_tiny_edges"];
2322 bool _preCADRemoveNanoEdges = (bool) i;
2323 value = _preCADRemoveNanoEdges ? "1" : "0";
2327 load.clear(std::ios::badbit | load.rdstate());
2329 isOK = static_cast<bool>(load >> i);
2331 _preCADDiscardInput = (bool) i;
2333 load.clear(std::ios::badbit | load.rdstate());
2335 isOK = static_cast<bool>(load >> val);
2336 if (isOK) { // _preCADEpsNano
2337 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
2338 std::string & value = _preCADoption2value["tiny_edge_length"];
2339 std::ostringstream oss;
2345 load.clear(std::ios::badbit | load.rdstate());
2347 isOK = static_cast<bool>(load >> i);
2349 _enforcedInternalVerticesAllFaces = (bool) i;
2351 load.clear(std::ios::badbit | load.rdstate());
2353 // New options with MeshGems-CADSurf
2355 bool hasCADSurfOptions = false;
2356 bool hasOptions = false;
2357 bool hasCustomOptions = false;
2358 bool hasPreCADOptions = false;
2359 bool hasSizeMap = false;
2360 bool hasAttractor = false;
2361 bool hasNewAttractor = false;
2362 bool hasEnforcedVertex = false;
2363 bool hasPreCADFacesPeriodicity = false;
2364 bool hasPreCADEdgesPeriodicity = false;
2365 bool hasFacesPeriodicity = false;
2366 bool hasEdgesPeriodicity = false;
2367 bool hasVerticesPeriodicity = false;
2369 isOK = static_cast<bool>(load >> option_or_sm);
2371 if ( (option_or_sm == "1")||(option_or_sm == "0") ) {
2372 i = atoi(option_or_sm.c_str());
2373 hasCADSurfOptions = true;
2374 _phySizeRel = (bool) i;
2376 if (option_or_sm == "__OPTIONS_BEGIN__")
2378 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2379 hasCustomOptions = true;
2380 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2381 hasPreCADOptions = true;
2382 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2384 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2385 hasAttractor = true;
2386 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2387 hasNewAttractor = true;
2388 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2389 hasEnforcedVertex = true;
2390 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2391 hasPreCADFacesPeriodicity = true;
2392 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2393 hasPreCADEdgesPeriodicity = true;
2394 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2395 hasFacesPeriodicity = true;
2396 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2397 hasEdgesPeriodicity = true;
2398 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2399 hasVerticesPeriodicity = true;
2401 if (isOK && hasCADSurfOptions) {
2402 isOK = static_cast<bool>(load >> i);
2404 _minSizeRel = (bool) i;
2406 load.clear(std::ios::badbit | load.rdstate());
2408 isOK = static_cast<bool>(load >> i);
2410 _maxSizeRel = (bool) i;
2412 load.clear(std::ios::badbit | load.rdstate());
2414 isOK = static_cast<bool>(load >> val);
2416 _chordalError = val;
2418 load.clear(std::ios::badbit | load.rdstate());
2420 isOK = static_cast<bool>(load >> i);
2422 _anisotropic = (bool) i;
2424 load.clear(std::ios::badbit | load.rdstate());
2426 isOK = static_cast<bool>(load >> val);
2428 _anisotropicRatio = val;
2430 load.clear(std::ios::badbit | load.rdstate());
2432 isOK = static_cast<bool>(load >> i);
2434 _removeTinyEdges = (bool) i;
2436 load.clear(std::ios::badbit | load.rdstate());
2438 isOK = static_cast<bool>(load >> val);
2440 _tinyEdgeLength = val;
2442 load.clear(std::ios::badbit | load.rdstate());
2444 isOK = static_cast<bool>(load >> i);
2446 _badElementRemoval = (bool) i;
2448 load.clear(std::ios::badbit | load.rdstate());
2450 isOK = static_cast<bool>(load >> val);
2452 _badElementAspectRatio = val;
2454 load.clear(std::ios::badbit | load.rdstate());
2456 isOK = static_cast<bool>(load >> i);
2458 _optimizeMesh = (bool) i;
2460 load.clear(std::ios::badbit | load.rdstate());
2462 isOK = static_cast<bool>(load >> i);
2464 _quadraticMesh = (bool) i;
2466 load.clear(std::ios::badbit | load.rdstate());
2468 isOK = static_cast<bool>(load >> i);
2470 _preCADProcess3DTopology = (bool) i;
2472 load.clear(std::ios::badbit | load.rdstate());
2474 if (( load >> std::ws).peek() != '_' )
2476 isOK = static_cast<bool>(load >> i);
2478 _preCADRemoveDuplicateCADFaces = (bool) i;
2480 load.clear(std::ios::badbit | load.rdstate());
2482 isOK = static_cast<bool>(load >> i);
2484 _optimiseTinyEdges = (bool) i;
2486 load.clear(std::ios::badbit | load.rdstate());
2488 isOK = static_cast<bool>(load >> val);
2490 _tinyEdgeOptimisationLength = val;
2492 load.clear(std::ios::badbit | load.rdstate());
2494 isOK = static_cast<bool>(load >> i);
2496 _correctSurfaceIntersec = (bool) i;
2498 load.clear(std::ios::badbit | load.rdstate());
2500 isOK = static_cast<bool>(load >> val);
2502 _corrSurfaceIntersCost = val;
2504 load.clear(std::ios::badbit | load.rdstate());
2506 isOK = static_cast<bool>(load >> i);
2508 _useGradation = (bool) i;
2510 load.clear(std::ios::badbit | load.rdstate());
2512 isOK = static_cast<bool>(load >> i);
2514 _useVolumeGradation = (bool) i;
2516 load.clear(std::ios::badbit | load.rdstate());
2518 isOK = static_cast<bool>(load >> val);
2520 _volumeGradation = val;
2522 load.clear(std::ios::badbit | load.rdstate());
2527 if (hasCADSurfOptions) {
2528 isOK = static_cast<bool>(load >> option_or_sm);
2530 if (option_or_sm == "__OPTIONS_BEGIN__")
2532 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2533 hasCustomOptions = true;
2534 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2535 hasPreCADOptions = true;
2536 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2538 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2539 hasAttractor = true;
2540 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2541 hasNewAttractor = true;
2542 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2543 hasEnforcedVertex = true;
2544 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2545 hasPreCADFacesPeriodicity = true;
2546 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2547 hasPreCADEdgesPeriodicity = true;
2548 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2549 hasFacesPeriodicity = true;
2550 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2551 hasEdgesPeriodicity = true;
2552 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2553 hasVerticesPeriodicity = true;
2557 std::string optName, optValue;
2558 while (isOK && hasOptions) {
2559 isOK = static_cast<bool>(load >> optName);
2561 if (optName == "__OPTIONS_END__")
2563 isOK = static_cast<bool>(load >> optValue);
2566 std::string & value = _option2value[optName];
2568 int len = value.size();
2569 // continue reading until "%#" encountered
2570 while (value[len - 1] != '#' || value[len - 2] != '%') {
2571 isOK = static_cast<bool>(load >> optValue);
2580 if ( value[ len - 1] == '#' )
2581 value.resize(len - 2); //cut off "%#"
2586 isOK = static_cast<bool>(load >> option_or_sm);
2588 if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2589 hasCustomOptions = true;
2590 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2591 hasPreCADOptions = true;
2592 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2594 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2595 hasAttractor = true;
2596 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2597 hasNewAttractor = true;
2598 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2599 hasEnforcedVertex = true;
2600 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2601 hasPreCADFacesPeriodicity = true;
2602 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2603 hasPreCADEdgesPeriodicity = true;
2604 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2605 hasFacesPeriodicity = true;
2606 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2607 hasEdgesPeriodicity = true;
2608 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2609 hasVerticesPeriodicity = true;
2613 while (isOK && hasCustomOptions) {
2614 isOK = static_cast<bool>(load >> optName);
2616 if (optName == "__CUSTOM_OPTIONS_END__")
2618 isOK = static_cast<bool>(load >> optValue);
2621 std::string& value = optValue;
2622 int len = value.size();
2623 // continue reading until "%#" encountered
2624 while (value[len - 1] != '#' || value[len - 2] != '%') {
2625 isOK = static_cast<bool>(load >> optValue);
2634 if ( value[ len - 1] == '#' )
2635 value.resize(len - 2); //cut off "%#"
2636 _customOption2value[optName] = value;
2640 if (hasCustomOptions) {
2641 isOK = static_cast<bool>(load >> option_or_sm);
2643 if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2644 hasPreCADOptions = true;
2645 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2647 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2648 hasAttractor = true;
2649 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2650 hasNewAttractor = true;
2651 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2652 hasEnforcedVertex = true;
2653 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2654 hasPreCADFacesPeriodicity = true;
2655 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2656 hasPreCADEdgesPeriodicity = true;
2657 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2658 hasFacesPeriodicity = true;
2659 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2660 hasEdgesPeriodicity = true;
2661 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2662 hasVerticesPeriodicity = true;
2666 while (isOK && hasPreCADOptions) {
2667 isOK = static_cast<bool>(load >> optName);
2669 if (optName == "__PRECAD_OPTIONS_END__")
2671 isOK = static_cast<bool>(load >> optValue);
2674 std::string & value = _preCADoption2value[optName];
2676 int len = value.size();
2677 // continue reading until "%#" encountered
2678 while (value[len - 1] != '#' || value[len - 2] != '%') {
2679 isOK = static_cast<bool>(load >> optValue);
2688 if ( value[ len - 1] == '#' )
2689 value.resize(len - 2); //cut off "%#"
2693 if (hasPreCADOptions) {
2694 isOK = static_cast<bool>(load >> option_or_sm);
2696 if (option_or_sm == "__SIZEMAP_BEGIN__")
2698 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2699 hasAttractor = true;
2700 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2701 hasNewAttractor = true;
2702 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2703 hasEnforcedVertex = true;
2704 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2705 hasPreCADFacesPeriodicity = true;
2706 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2707 hasPreCADEdgesPeriodicity = true;
2708 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2709 hasFacesPeriodicity = true;
2710 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2711 hasEdgesPeriodicity = true;
2712 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2713 hasVerticesPeriodicity = true;
2717 std::string smEntry, smValue;
2718 while (isOK && hasSizeMap) {
2719 isOK = static_cast<bool>(load >> smEntry);
2721 if (smEntry == "__SIZEMAP_END__")
2723 isOK = static_cast<bool>(load >> smValue);
2726 std::string & value2 = _sizeMap[smEntry];
2728 int len2 = value2.size();
2729 // continue reading until "%#" encountered
2730 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2731 isOK = static_cast<bool>(load >> smValue);
2735 len2 = value2.size();
2740 value2.resize(len2 - 2); //cut off "%#"
2745 isOK = static_cast<bool>(load >> option_or_sm);
2747 if (option_or_sm == "__ATTRACTORS_BEGIN__")
2748 hasAttractor = true;
2749 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2750 hasNewAttractor = true;
2751 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2752 hasEnforcedVertex = true;
2753 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2754 hasPreCADFacesPeriodicity = true;
2755 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2756 hasPreCADEdgesPeriodicity = true;
2757 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2758 hasFacesPeriodicity = true;
2759 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2760 hasEdgesPeriodicity = true;
2761 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2762 hasVerticesPeriodicity = true;
2765 std::string atEntry, atValue;
2766 while (isOK && hasAttractor) {
2767 isOK = static_cast<bool>(load >> atEntry);
2769 if (atEntry == "__ATTRACTORS_END__")
2771 isOK = static_cast<bool>(load >> atValue);
2774 std::string & value3 = _attractors[atEntry];
2776 int len3 = value3.size();
2777 // continue reading until "%#" encountered
2778 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
2779 isOK = static_cast<bool>(load >> atValue);
2783 len3 = value3.size();
2788 value3.resize(len3 - 2); //cut off "%#"
2793 isOK = static_cast<bool>(load >> option_or_sm);
2795 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2796 hasNewAttractor = true;
2797 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2798 hasEnforcedVertex = true;
2799 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2800 hasPreCADFacesPeriodicity = true;
2801 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2802 hasPreCADEdgesPeriodicity = true;
2803 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2804 hasFacesPeriodicity = true;
2805 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2806 hasEdgesPeriodicity = true;
2807 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2808 hasVerticesPeriodicity = true;
2812 std::string newAtFaceEntry, atTestString;
2813 std::string newAtShapeEntry;
2814 double attParams[4];
2816 while (isOK && hasNewAttractor) {
2817 //std::cout<<"Load new attractor"<<std::endl;
2818 isOK = static_cast<bool>(load >> newAtFaceEntry);
2820 if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
2822 isOK = static_cast<bool>(load >> newAtShapeEntry);
2825 isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
2828 const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
2829 const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
2830 BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
2831 attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
2832 //attractor->BuildMap();
2833 _classAttractors.insert( make_pair( newAtFaceEntry, attractor ));
2838 if (hasNewAttractor) {
2839 isOK = static_cast<bool>(load >> option_or_sm);
2841 if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2842 hasEnforcedVertex = true;
2843 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2844 hasPreCADFacesPeriodicity = true;
2845 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2846 hasPreCADEdgesPeriodicity = true;
2847 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2848 hasFacesPeriodicity = true;
2849 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2850 hasEdgesPeriodicity = true;
2851 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2852 hasVerticesPeriodicity = true;
2858 // Here is a example of the saved stream:
2859 // __ENFORCED_VERTICES_BEGIN__
2860 // __BEGIN_VERTEX__ => no name, no entry
2861 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2862 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__
2863 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__
2865 // __BEGIN_VERTEX__ => no coords
2866 // __BEGIN_NAME__ mes points __END_NAME__
2867 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
2868 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2869 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
2871 // __ENFORCED_VERTICES_END__
2874 std::string enfSeparator;
2875 std::string enfName;
2876 std::string enfGeomEntry;
2877 std::string enfGroup;
2878 TEntryList enfFaceEntryList;
2879 double enfCoords[3];
2880 bool hasCoords = false;
2882 _faceEntryEnfVertexListMap.clear();
2883 _enfVertexList.clear();
2884 _faceEntryCoordsListMap.clear();
2885 _coordsEnfVertexMap.clear();
2886 _faceEntryEnfVertexEntryListMap.clear();
2887 _enfVertexEntryEnfVertexMap.clear();
2890 while (isOK && hasEnforcedVertex)
2892 isOK = static_cast<bool>(load >> enfSeparator); // __BEGIN_VERTEX__
2893 TEnfVertex *enfVertex = new TEnfVertex();
2894 if (enfSeparator == "__ENFORCED_VERTICES_END__")
2895 break; // __ENFORCED_VERTICES_END__
2896 if (enfSeparator != "__BEGIN_VERTEX__")
2897 throw std::exception();
2900 isOK = static_cast<bool>(load >> enfSeparator);
2901 if (enfSeparator == "__END_VERTEX__") {
2903 enfVertex->name = enfName;
2904 enfVertex->geomEntry = enfGeomEntry;
2905 enfVertex->grpName = enfGroup;
2906 enfVertex->coords.clear();
2908 enfVertex->coords.assign(enfCoords,enfCoords+3);
2909 enfVertex->faceEntries = enfFaceEntryList;
2911 _enfVertexList.insert(enfVertex);
2913 if (enfVertex->coords.size()) {
2914 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
2915 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2916 _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
2917 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2920 if (!enfVertex->geomEntry.empty()) {
2921 _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
2922 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2923 _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
2924 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2929 enfGeomEntry.clear();
2931 enfFaceEntryList.clear();
2933 break; // __END_VERTEX__
2936 if (enfSeparator == "__BEGIN_NAME__") { // __BEGIN_NAME__
2937 while (isOK && (enfSeparator != "__END_NAME__")) {
2938 isOK = static_cast<bool>(load >> enfSeparator);
2939 if (enfSeparator != "__END_NAME__") {
2940 if (!enfName.empty())
2942 enfName += enfSeparator;
2947 if (enfSeparator == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
2948 isOK = static_cast<bool>(load >> enfGeomEntry);
2949 isOK = static_cast<bool>(load >> enfSeparator); // __END_ENTRY__
2950 if (enfSeparator != "__END_ENTRY__")
2951 throw std::exception();
2954 if (enfSeparator == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
2955 while (isOK && (enfSeparator != "__END_GROUP__")) {
2956 isOK = static_cast<bool>(load >> enfSeparator);
2957 if (enfSeparator != "__END_GROUP__") {
2958 if (!enfGroup.empty())
2960 enfGroup += enfSeparator;
2965 if (enfSeparator == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
2967 isOK = static_cast<bool>(load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
2968 isOK = static_cast<bool>(load >> enfSeparator); // __END_COORDS__
2969 if (enfSeparator != "__END_COORDS__")
2970 throw std::exception();
2973 if (enfSeparator == "__BEGIN_FACELIST__") { // __BEGIN_FACELIST__
2974 while (isOK && (enfSeparator != "__END_FACELIST__")) {
2975 isOK = static_cast<bool>(load >> enfSeparator);
2976 if (enfSeparator != "__END_FACELIST__") {
2977 enfFaceEntryList.insert(enfSeparator);
2986 if (hasPreCADFacesPeriodicity)
2988 LoadPreCADPeriodicity(load, "FACES");
2990 isOK = static_cast<bool>(load >> option_or_sm);
2992 if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2993 hasPreCADEdgesPeriodicity = true;
2994 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2995 hasFacesPeriodicity = true;
2996 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2997 hasEdgesPeriodicity = true;
2998 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2999 hasVerticesPeriodicity = true;
3003 if (hasPreCADEdgesPeriodicity)
3005 LoadPreCADPeriodicity(load, "EDGES");
3007 isOK = static_cast<bool>(load >> option_or_sm);
3009 if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
3010 hasFacesPeriodicity = true;
3011 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3012 hasEdgesPeriodicity = true;
3013 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3014 hasVerticesPeriodicity = true;
3018 if (hasFacesPeriodicity)
3020 LoadFacesPeriodicity(load);
3022 isOK = static_cast<bool>(load >> option_or_sm);
3024 if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3025 hasEdgesPeriodicity = true;
3026 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3027 hasVerticesPeriodicity = true;
3031 if (hasEdgesPeriodicity)
3033 LoadEdgesPeriodicity(load);
3035 isOK = static_cast<bool>(load >> option_or_sm);
3037 if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3038 hasVerticesPeriodicity = true;
3041 if (hasVerticesPeriodicity)
3042 LoadVerticesPeriodicity(load);
3045 if ( !option_or_sm.empty() && option_or_sm[0] == '_' )
3046 isOK = static_cast<bool>(load >> option_or_sm);
3047 if ( isOK && !option_or_sm.empty() )
3049 int nbPatches = atoi( option_or_sm.c_str() );
3050 if ( nbPatches >= 0 )
3052 _hyperPatchList.resize( nbPatches );
3053 for ( int iP = 0; iP < nbPatches && isOK; ++iP )
3055 isOK = static_cast<bool>(load >> i) && i >= 2;
3058 for ( int iT = 0; iT < nbTags; ++iT )
3060 if (( isOK = static_cast<bool>(load >> i)))
3061 _hyperPatchList[ iP ].insert( i );
3066 if ( !isOK ) // remove invalid patches
3068 for ( i = nbPatches - 1; i >= 0; i-- )
3069 if ( _hyperPatchList[i].size() < 2 )
3070 _hyperPatchList.resize( i );
3078 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
3082 std::string periodicitySeparator;
3086 _facesPeriodicityVector.clear();
3089 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3090 TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
3091 if (periodicitySeparator == "__FACES_PERIODICITY_END__")
3092 break; // __FACES_PERIODICITY_END__
3093 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3094 throw std::exception();
3098 isOK = static_cast<bool>(load >> periodicitySeparator);
3099 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3101 periodicity_i->first = shape1Entry;
3102 periodicity_i->second = shape2Entry;
3104 _facesPeriodicityVector.push_back(*periodicity_i);
3106 break; // __END_PERIODICITY_DESCRIPTION__
3109 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3110 isOK = static_cast<bool>(load >> shape1Entry);
3111 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3112 if (periodicitySeparator != "__END_ENTRY1__")
3113 throw std::exception();
3116 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3117 isOK = static_cast<bool>(load >> shape2Entry);
3118 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3119 if (periodicitySeparator != "__END_ENTRY2__")
3120 throw std::exception();
3127 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
3131 std::string periodicitySeparator;
3132 TEntry theFace1Entry;
3133 TEntry theEdge1Entry;
3134 TEntry theFace2Entry;
3135 TEntry theEdge2Entry;
3136 int edge_orientation = 0;
3138 _edgesPeriodicityVector.clear();
3141 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3142 TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
3143 if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
3144 break; // __EDGES_PERIODICITY_END__
3145 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3146 throw std::exception();
3150 isOK = static_cast<bool>(load >> periodicitySeparator);
3151 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3153 periodicity_i->theFace1Entry = theFace1Entry;
3154 periodicity_i->theEdge1Entry = theEdge1Entry;
3155 periodicity_i->theFace2Entry = theFace2Entry;
3156 periodicity_i->theEdge2Entry = theEdge2Entry;
3157 periodicity_i->edge_orientation = edge_orientation;
3159 _edgesPeriodicityVector.push_back(*periodicity_i);
3161 break; // __END_PERIODICITY_DESCRIPTION__
3164 if (periodicitySeparator == "__BEGIN_FACE1__") { // __BEGIN_FACE1__
3165 isOK = static_cast<bool>(load >> theFace1Entry);
3166 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE1__
3167 if (periodicitySeparator != "__END_FACE1__"){
3168 throw std::exception();
3172 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3173 isOK = static_cast<bool>(load >> theEdge1Entry);
3174 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3175 if (periodicitySeparator != "__END_EDGE1__")
3176 throw std::exception();
3179 if (periodicitySeparator == "__BEGIN_FACE2__") { // __BEGIN_FACE2__
3180 isOK = static_cast<bool>(load >> theFace2Entry);
3181 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE2__
3182 if (periodicitySeparator != "__END_FACE2__")
3183 throw std::exception();
3186 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3187 isOK = static_cast<bool>(load >> theEdge2Entry);
3188 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3189 if (periodicitySeparator != "__END_EDGE2__")
3190 throw std::exception();
3193 if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") { // __BEGIN_EDGE_ORIENTATION__
3194 isOK = static_cast<bool>(load >> edge_orientation);
3195 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
3196 if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
3197 throw std::exception();
3203 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load)
3207 std::string periodicitySeparator;
3208 TEntry theEdge1Entry;
3209 TEntry theVertex1Entry;
3210 TEntry theEdge2Entry;
3211 TEntry theVertex2Entry;
3213 _verticesPeriodicityVector.clear();
3216 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3217 TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
3218 if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
3219 break; // __VERTICES_PERIODICITY_END__
3220 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3221 throw std::exception();
3225 isOK = static_cast<bool>(load >> periodicitySeparator);
3226 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3228 periodicity_i->theEdge1Entry = theEdge1Entry;
3229 periodicity_i->theVertex1Entry = theVertex1Entry;
3230 periodicity_i->theEdge2Entry = theEdge2Entry;
3231 periodicity_i->theVertex2Entry = theVertex2Entry;
3233 _verticesPeriodicityVector.push_back(*periodicity_i);
3235 break; // __END_PERIODICITY_DESCRIPTION__
3238 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3239 isOK = static_cast<bool>(load >> theEdge1Entry);
3240 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3241 if (periodicitySeparator != "__END_EDGE1__")
3242 throw std::exception();
3245 if (periodicitySeparator == "__BEGIN_VERTEX1__") { // __BEGIN_VERTEX1__
3246 isOK = static_cast<bool>(load >> theVertex1Entry);
3247 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX1__
3248 if (periodicitySeparator != "__END_VERTEX1__")
3249 throw std::exception();
3252 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3253 isOK = static_cast<bool>(load >> theEdge2Entry);
3254 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3255 if (periodicitySeparator != "__END_EDGE2__")
3256 throw std::exception();
3259 if (periodicitySeparator == "__BEGIN_VERTEX2__") { // __BEGIN_VERTEX2__
3260 isOK = static_cast<bool>(load >> theVertex2Entry);
3261 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX2__
3262 if (periodicitySeparator != "__END_VERTEX2__")
3263 throw std::exception();
3269 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
3273 std::string periodicitySeparator;
3276 std::vector<std::string> theSourceVerticesEntries;
3277 std::vector<std::string> theTargetVerticesEntries;
3279 bool hasSourceVertices = false;
3280 bool hasTargetVertices = false;
3282 if ( shapeType && strcmp( shapeType, "FACES") == 0 )
3283 _preCadFacesPeriodicityVector.clear();
3285 _preCadEdgesPeriodicityVector.clear();
3289 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3290 TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
3291 std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
3292 if (periodicitySeparator == endSeparator)
3293 break; // __PRECAD_FACES_PERIODICITY_END__
3294 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3295 throw std::exception();
3299 isOK = static_cast<bool>(load >> periodicitySeparator);
3300 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3302 periodicity_i->shape1Entry = shape1Entry;
3303 periodicity_i->shape2Entry = shape2Entry;
3305 if (hasSourceVertices)
3306 periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
3307 if (hasTargetVertices)
3308 periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
3310 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
3311 _preCadFacesPeriodicityVector.push_back(*periodicity_i);
3313 _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
3315 theSourceVerticesEntries.clear();
3316 theTargetVerticesEntries.clear();
3317 hasSourceVertices = false;
3318 hasTargetVertices = false;
3319 break; // __END_PERIODICITY_DESCRIPTION__
3322 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3323 isOK = static_cast<bool>(load >> shape1Entry);
3324 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3325 if (periodicitySeparator != "__END_ENTRY1__")
3326 throw std::exception();
3329 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3330 isOK = static_cast<bool>(load >> shape2Entry);
3331 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3332 if (periodicitySeparator != "__END_ENTRY2__")
3333 throw std::exception();
3336 if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") { // __BEGIN_SOURCE_VERTICES_LIST__
3337 hasSourceVertices = true;
3338 while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
3339 isOK = static_cast<bool>(load >> periodicitySeparator);
3340 if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
3341 theSourceVerticesEntries.push_back(periodicitySeparator);
3346 if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") { // __BEGIN_TARGET_VERTICES_LIST__
3347 hasTargetVertices = true;
3348 while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
3349 isOK = static_cast<bool>(load >> periodicitySeparator);
3350 if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
3351 theTargetVerticesEntries.push_back(periodicitySeparator);
3359 //=============================================================================
3360 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
3361 return hyp.SaveTo(save);
3364 //=============================================================================
3365 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
3366 return hyp.LoadFrom(load);
3369 //================================================================================
3371 * \brief Does nothing
3373 //================================================================================
3375 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
3379 //================================================================================
3381 * \brief Returns default global constant physical size given a default value of element length ratio
3383 //================================================================================
3385 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
3386 if (bbSegmentation != 0 && diagonal != 0)
3387 return diagonal / bbSegmentation ;
3391 //================================================================================
3393 * \brief Returns default min size given a default value of element length ratio
3395 //================================================================================
3397 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
3399 return diagonal / 1000.0 ;
3400 return undefinedDouble();
3403 //================================================================================
3405 * \brief Returns default max size given a default value of element length ratio
3407 //================================================================================
3409 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
3411 return diagonal / 5.0 ;
3412 return undefinedDouble();
3415 //================================================================================
3417 * \brief Returns default chordal error given a default value of element length ratio
3419 //================================================================================
3421 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
3424 return undefinedDouble();
3427 //================================================================================
3429 * \brief Returns default tiny edge length given a default value of element length ratio
3431 //================================================================================
3433 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
3435 return diagonal * 1e-6 ;
3436 return undefinedDouble();
3439 //================================================================================
3441 * \brief Returns default tiny edge optimisation length given a default value of element length ratio
3443 //================================================================================
3445 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal) {
3447 return diagonal * 1e-6 ;
3448 return undefinedDouble();
3451 //=============================================================================
3453 * \brief Initialize my parameter values by default parameters.
3454 * \retval bool - true if parameter values have been successfully defined
3456 //=============================================================================
3458 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
3459 double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
3460 _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
3461 _minSize = GetDefaultMinSize(diagonal);
3462 _maxSize = GetDefaultMaxSize(diagonal);
3463 _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
3464 _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
3465 _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(diagonal);
3470 //================================================================================
3472 * \brief Converts a string to a bool
3474 //================================================================================
3476 bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
3477 throw (std::invalid_argument)
3479 std::string s = str;
3480 if ( isOk ) *isOk = true;
3482 for ( size_t i = 0; i <= s.size(); ++i )
3483 s[i] = tolower( s[i] );
3485 if ( s == "1" || s == "true" || s == "active" || s == "yes" )
3488 if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
3494 std::string msg = "Not a Boolean value:'" + str + "'";
3495 throw std::invalid_argument(msg);
3500 //================================================================================
3502 * \brief Converts a string to a real value
3504 //================================================================================
3506 double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
3507 throw (std::invalid_argument)
3509 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3512 double val = strtod(&str[0], &endPtr);
3513 bool ok = (&str[0] != endPtr);
3515 if ( isOk ) *isOk = ok;
3519 std::string msg = "Not a real value:'" + str + "'";
3520 throw std::invalid_argument(msg);
3525 //================================================================================
3527 * \brief Converts a string to a integer value
3529 //================================================================================
3531 int BLSURFPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
3532 throw (std::invalid_argument)
3534 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3537 int val = (int)strtol( &str[0], &endPtr, 10);
3538 bool ok = (&str[0] != endPtr);
3540 if ( isOk ) *isOk = ok;
3544 std::string msg = "Not an integer value:'" + str + "'";
3545 throw std::invalid_argument(msg);