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, int studyId, SMESH_Gen * gen, bool hasgeom) :
53 SMESH_Hypothesis(hypId, studyId, 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;
259 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
260 SALOMEDS::Study_ptr myStudy = smeshGen_i->GetCurrentStudy();
262 TopoDS_Shape S = TopoDS_Shape();
263 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
264 if (!aSObj->_is_nil() ) {
265 CORBA::Object_var obj = aSObj->GetObject();
266 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
269 if ( !aGeomObj->_is_nil() )
270 S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
274 //=============================================================================
275 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
276 if (thePhysicalMesh != _physicalMesh) {
277 _physicalMesh = thePhysicalMesh;
278 NotifySubMeshesHypothesisModification();
282 //=============================================================================
283 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
284 if (theGeometricMesh != _geometricMesh) {
285 _geometricMesh = theGeometricMesh;
286 // switch (_geometricMesh) {
289 // _angleMesh = GetDefaultAngleMesh();
290 // _gradation = GetDefaultGradation();
293 NotifySubMeshesHypothesisModification();
297 //=============================================================================
298 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal, bool isRelative) {
299 if ((theVal != _phySize) || (isRelative != _phySizeRel)) {
300 _phySizeRel = isRelative;
302 _phySize = GetMaxSize();
306 NotifySubMeshesHypothesisModification();
310 //=============================================================================
311 void BLSURFPlugin_Hypothesis::SetMinSize(double theMinSize, bool isRelative) {
312 if ((theMinSize != _minSize) || (isRelative != _minSizeRel)) {
313 _minSizeRel = isRelative;
314 _minSize = theMinSize;
315 NotifySubMeshesHypothesisModification();
319 //=============================================================================
320 void BLSURFPlugin_Hypothesis::SetMaxSize(double theMaxSize, bool isRelative) {
321 if ((theMaxSize != _maxSize) || (isRelative != _maxSizeRel)) {
322 _maxSizeRel = isRelative;
323 _maxSize = theMaxSize;
324 NotifySubMeshesHypothesisModification();
328 //=============================================================================
329 void BLSURFPlugin_Hypothesis::SetUseGradation(bool theVal) {
330 if (theVal != _useGradation) {
331 _useGradation = theVal;
332 NotifySubMeshesHypothesisModification();
336 //=============================================================================
337 void BLSURFPlugin_Hypothesis::SetGradation(double theVal) {
338 _useGradation = ( theVal > 0 );
339 if (theVal != _gradation) {
341 NotifySubMeshesHypothesisModification();
345 //=============================================================================
346 void BLSURFPlugin_Hypothesis::SetUseVolumeGradation(bool theVal) {
347 if (theVal != _useVolumeGradation) {
348 _useVolumeGradation = theVal;
349 NotifySubMeshesHypothesisModification();
353 //=============================================================================
354 void BLSURFPlugin_Hypothesis::SetVolumeGradation(double theVal) {
355 _useVolumeGradation = ( theVal > 0 );
356 if (theVal != _volumeGradation) {
357 _volumeGradation = theVal;
358 NotifySubMeshesHypothesisModification();
362 //=============================================================================
363 void BLSURFPlugin_Hypothesis::SetElementType(ElementType theElementType) {
364 if (theElementType != _elementType) {
365 _elementType = theElementType;
366 NotifySubMeshesHypothesisModification();
370 //=============================================================================
371 void BLSURFPlugin_Hypothesis::SetAngleMesh(double theVal) {
372 if (theVal != _angleMesh) {
374 NotifySubMeshesHypothesisModification();
378 //=============================================================================
379 void BLSURFPlugin_Hypothesis::SetChordalError(double theDistance) {
380 if (theDistance != _chordalError) {
381 _chordalError = theDistance;
382 NotifySubMeshesHypothesisModification();
386 //=============================================================================
387 void BLSURFPlugin_Hypothesis::SetAnisotropic(bool theVal) {
388 if (theVal != _anisotropic) {
389 _anisotropic = theVal;
390 NotifySubMeshesHypothesisModification();
394 //=============================================================================
395 void BLSURFPlugin_Hypothesis::SetAnisotropicRatio(double theVal) {
396 if (theVal != _anisotropicRatio) {
397 _anisotropicRatio = theVal;
398 NotifySubMeshesHypothesisModification();
402 //=============================================================================
403 void BLSURFPlugin_Hypothesis::SetRemoveTinyEdges(bool theVal) {
404 if (theVal != _removeTinyEdges) {
405 _removeTinyEdges = theVal;
406 NotifySubMeshesHypothesisModification();
410 //=============================================================================
411 void BLSURFPlugin_Hypothesis::SetTinyEdgeLength(double theVal) {
412 if (theVal != _tinyEdgeLength) {
413 _tinyEdgeLength = theVal;
414 NotifySubMeshesHypothesisModification();
418 //=============================================================================
419 void BLSURFPlugin_Hypothesis::SetOptimiseTinyEdges(bool theVal) {
420 if (theVal != _optimiseTinyEdges) {
421 _optimiseTinyEdges = theVal;
422 NotifySubMeshesHypothesisModification();
426 //=============================================================================
427 void BLSURFPlugin_Hypothesis::SetTinyEdgeOptimisationLength(double theVal) {
428 if (theVal != _tinyEdgeOptimisationLength) {
429 _tinyEdgeOptimisationLength = theVal;
430 NotifySubMeshesHypothesisModification();
434 //=============================================================================
435 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersection(bool theVal) {
436 if (theVal != _correctSurfaceIntersec) {
437 _correctSurfaceIntersec = theVal;
438 NotifySubMeshesHypothesisModification();
442 //=============================================================================
443 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersectionMaxCost(double theVal) {
444 if (theVal != _corrSurfaceIntersCost) {
445 _corrSurfaceIntersCost = theVal;
446 NotifySubMeshesHypothesisModification();
450 //=============================================================================
451 void BLSURFPlugin_Hypothesis::SetBadElementRemoval(bool theVal) {
452 if (theVal != _badElementRemoval) {
453 _badElementRemoval = theVal;
454 NotifySubMeshesHypothesisModification();
458 //=============================================================================
459 void BLSURFPlugin_Hypothesis::SetBadElementAspectRatio(double theVal) {
460 if (theVal != _badElementAspectRatio) {
461 _badElementAspectRatio = theVal;
462 NotifySubMeshesHypothesisModification();
466 //=============================================================================
467 void BLSURFPlugin_Hypothesis::SetOptimizeMesh(bool theVal) {
468 if (theVal != _optimizeMesh) {
469 _optimizeMesh = theVal;
470 NotifySubMeshesHypothesisModification();
474 //=============================================================================
475 void BLSURFPlugin_Hypothesis::SetQuadraticMesh(bool theVal) {
476 if (theVal != _quadraticMesh) {
477 _quadraticMesh = theVal;
478 NotifySubMeshesHypothesisModification();
482 //=============================================================================
483 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology) {
484 if (theTopology != _topology) {
485 _topology = theTopology;
486 NotifySubMeshesHypothesisModification();
490 //=============================================================================
491 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
492 if (theVal != _verb) {
494 NotifySubMeshesHypothesisModification();
498 //=============================================================================
499 void BLSURFPlugin_Hypothesis::SetEnforceCadEdgesSize( bool toEnforce )
501 if ( GetEnforceCadEdgesSize() != toEnforce )
503 SetOptionValue( "enforce_cad_edge_sizes", toEnforce ? "yes" : "no" );
504 NotifySubMeshesHypothesisModification();
507 //=============================================================================
508 bool BLSURFPlugin_Hypothesis::GetEnforceCadEdgesSize()
510 return ToBool( GetOptionValue( "enforce_cad_edge_sizes" ), GET_DEFAULT() );
512 //=============================================================================
514 void BLSURFPlugin_Hypothesis::SetJacobianRectificationRespectGeometry( bool allowRectification )
516 if ( GetJacobianRectificationRespectGeometry() != allowRectification )
518 SetOptionValue("jacobian_rectification_respect_geometry", allowRectification ? "yes" : "no" );
519 NotifySubMeshesHypothesisModification();
522 //=============================================================================
523 bool BLSURFPlugin_Hypothesis::GetJacobianRectificationRespectGeometry()
525 return ToBool( GetOptionValue("jacobian_rectification_respect_geometry", GET_DEFAULT()));
527 //=============================================================================
529 void BLSURFPlugin_Hypothesis::SetJacobianRectification( bool allowRectification )
531 if ( GetJacobianRectification() != allowRectification )
533 SetOptionValue( "rectify_jacobian", allowRectification ? "yes" : "no" );
534 NotifySubMeshesHypothesisModification();
537 //=============================================================================
538 bool BLSURFPlugin_Hypothesis::GetJacobianRectification()
540 return ToBool( GetOptionValue("rectify_jacobian", GET_DEFAULT()));
542 //=============================================================================
544 void BLSURFPlugin_Hypothesis::SetUseDeprecatedPatchMesher( bool useDeprecatedPatchMesher )
546 if ( GetUseDeprecatedPatchMesher() != useDeprecatedPatchMesher )
548 SetOptionValue( "use_deprecated_patch_mesher", useDeprecatedPatchMesher ? "yes" : "no" );
549 NotifySubMeshesHypothesisModification();
552 //=============================================================================
553 bool BLSURFPlugin_Hypothesis::GetUseDeprecatedPatchMesher()
555 return ToBool( GetOptionValue("use_deprecated_patch_mesher", GET_DEFAULT()));
557 //=============================================================================
559 void BLSURFPlugin_Hypothesis::SetMaxNumberOfPointsPerPatch( int nb )
560 throw (std::invalid_argument)
563 throw std::invalid_argument( SMESH_Comment("Invalid number of points: ") << nb );
565 if ( GetMaxNumberOfPointsPerPatch() != nb )
567 SetOptionValue("max_number_of_points_per_patch", SMESH_Comment( nb ));
568 NotifySubMeshesHypothesisModification();
571 //=============================================================================
572 int BLSURFPlugin_Hypothesis::GetMaxNumberOfPointsPerPatch()
574 return ToInt( GetOptionValue("max_number_of_points_per_patch", GET_DEFAULT()));
576 //=============================================================================
578 void BLSURFPlugin_Hypothesis::SetMaxNumberOfThreads( int nb )
579 throw (std::invalid_argument)
582 throw std::invalid_argument( SMESH_Comment("Invalid number of threads: ") << nb );
584 if ( GetMaxNumberOfThreads() != nb )
586 SetOptionValue("max_number_of_threads", SMESH_Comment( nb ));
587 NotifySubMeshesHypothesisModification();
590 //=============================================================================
591 int BLSURFPlugin_Hypothesis::GetMaxNumberOfThreads()
593 return ToInt( GetOptionValue("max_number_of_threads", GET_DEFAULT()));
595 //=============================================================================
597 void BLSURFPlugin_Hypothesis::SetRespectGeometry( bool toRespect )
599 if ( GetRespectGeometry() != toRespect )
601 SetOptionValue("respect_geometry", toRespect ? "yes" : "no" );
602 NotifySubMeshesHypothesisModification();
605 //=============================================================================
606 bool BLSURFPlugin_Hypothesis::GetRespectGeometry()
608 return ToBool( GetOptionValue( "respect_geometry", GET_DEFAULT()));
610 //=============================================================================
612 void BLSURFPlugin_Hypothesis::SetTinyEdgesAvoidSurfaceIntersections( bool toAvoidIntersection )
614 if ( GetTinyEdgesAvoidSurfaceIntersections() != toAvoidIntersection )
616 SetOptionValue("tiny_edge_avoid_surface_intersections", toAvoidIntersection ? "yes" : "no" );
617 NotifySubMeshesHypothesisModification();
620 //=============================================================================
621 bool BLSURFPlugin_Hypothesis::GetTinyEdgesAvoidSurfaceIntersections()
623 return ToBool( GetOptionValue("tiny_edge_avoid_surface_intersections", GET_DEFAULT()));
625 //=============================================================================
627 void BLSURFPlugin_Hypothesis::SetClosedGeometry( bool isClosed )
629 if ( GetClosedGeometry() != isClosed )
631 SetPreCADOptionValue("closed_geometry", isClosed ? "yes" : "no" );
632 NotifySubMeshesHypothesisModification();
635 //=============================================================================
636 bool BLSURFPlugin_Hypothesis::GetClosedGeometry()
638 return ToBool( GetPreCADOptionValue( "closed_geometry", GET_DEFAULT()));
640 //=============================================================================
642 void BLSURFPlugin_Hypothesis::SetDebug( bool isDebug )
644 if ( GetDebug() != isDebug )
646 SetPreCADOptionValue("debug", isDebug ? "yes" : "no" );
647 NotifySubMeshesHypothesisModification();
650 //=============================================================================
651 bool BLSURFPlugin_Hypothesis::GetDebug()
653 return ToBool( GetPreCADOptionValue("debug", GET_DEFAULT()));
655 //=============================================================================
657 void BLSURFPlugin_Hypothesis::SetPeriodicTolerance( CORBA::Double tol )
658 throw (std::invalid_argument)
661 throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
662 if ( GetPeriodicTolerance() != tol )
664 SetPreCADOptionValue("periodic_tolerance", SMESH_Comment( tol ) );
665 NotifySubMeshesHypothesisModification();
668 //=============================================================================
669 double BLSURFPlugin_Hypothesis::GetPeriodicTolerance()
671 return ToDbl( GetPreCADOptionValue( "periodic_tolerance", GET_DEFAULT()));
673 //=============================================================================
675 void BLSURFPlugin_Hypothesis::SetRequiredEntities( const std::string& howToTreat )
676 throw (std::invalid_argument)
678 if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear" )
679 throw std::invalid_argument
680 ( SMESH_Comment("required_entities must be in ['respect','ignore','clear'] "));
682 if ( GetRequiredEntities() != howToTreat )
684 SetPreCADOptionValue("required_entities", howToTreat );
685 NotifySubMeshesHypothesisModification();
688 //=============================================================================
689 std::string BLSURFPlugin_Hypothesis::GetRequiredEntities()
691 return GetPreCADOptionValue("required_entities", GET_DEFAULT());
693 //=============================================================================
695 void BLSURFPlugin_Hypothesis::SetSewingTolerance( CORBA::Double tol )
696 throw (std::invalid_argument)
699 throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
700 if ( GetSewingTolerance() != tol )
702 SetPreCADOptionValue("sewing_tolerance", SMESH_Comment( tol ) );
703 NotifySubMeshesHypothesisModification();
706 //=============================================================================
707 CORBA::Double BLSURFPlugin_Hypothesis::GetSewingTolerance()
709 return ToDbl( GetPreCADOptionValue("sewing_tolerance", GET_DEFAULT()));
711 //=============================================================================
713 void BLSURFPlugin_Hypothesis::SetTags( const std::string& howToTreat )
714 throw (std::invalid_argument)
716 if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear" )
717 throw std::invalid_argument
718 ( SMESH_Comment("'tags' must be in ['respect','ignore','clear'] "));
720 if ( GetTags() != howToTreat )
722 SetPreCADOptionValue("tags", howToTreat );
723 NotifySubMeshesHypothesisModification();
726 //=============================================================================
727 std::string BLSURFPlugin_Hypothesis::GetTags()
729 return GetPreCADOptionValue("tags", GET_DEFAULT());
731 //=============================================================================
732 void BLSURFPlugin_Hypothesis::SetHyperPatches(const THyperPatchList& hpl)
734 if ( hpl != _hyperPatchList )
736 // join patches sharing tags
737 _hyperPatchList.clear();
738 for ( size_t i = 0; i < hpl.size(); ++i )
740 const THyperPatchTags& tags = hpl[i];
741 if ( tags.size() < 2 ) continue;
743 std::set<int> iPatches;
744 if ( !_hyperPatchList.empty() )
746 THyperPatchTags::iterator t = tags.begin();
747 for ( ; t != tags.end(); ++t )
750 GetHyperPatchTag( *t, this, &iPatch );
752 iPatches.insert( iPatch );
756 if ( iPatches.empty() )
758 _hyperPatchList.push_back( tags );
762 std::set<int>::iterator iPatch = iPatches.begin();
763 THyperPatchTags& mainPatch = _hyperPatchList[ *iPatch ];
764 mainPatch.insert( tags.begin(), tags.end() );
766 for ( ++iPatch; iPatch != iPatches.end(); ++iPatch )
768 mainPatch.insert( _hyperPatchList[ *iPatch ].begin(), _hyperPatchList[ *iPatch ].end() );
769 _hyperPatchList[ *iPatch ].clear();
771 if ( iPatches.size() > 1 )
772 for ( int j = _hyperPatchList.size()-1; j > 0; --j )
773 if ( _hyperPatchList[j].empty() )
774 _hyperPatchList.erase( _hyperPatchList.begin() + j );
777 NotifySubMeshesHypothesisModification();
780 //=============================================================================
782 * \brief Return a tag of a face taking into account the hyper-patches. Optionally
783 * return an index of a patch including the face
785 //================================================================================
787 int BLSURFPlugin_Hypothesis::GetHyperPatchTag( const int faceTag,
788 const BLSURFPlugin_Hypothesis* hyp,
793 const THyperPatchList& hpl = hyp->_hyperPatchList;
794 for ( size_t i = 0; i < hpl.size(); ++i )
795 if ( hpl[i].count( faceTag ))
797 if ( iPatch ) *iPatch = i;
798 return *( hpl[i].begin() );
803 //=============================================================================
804 void BLSURFPlugin_Hypothesis::SetPreCADMergeEdges(bool theVal)
806 if (theVal != ToBool( GetPreCADOptionValue("merge_edges", GET_DEFAULT()))) {
807 _preCADMergeEdges = theVal;
808 SetPreCADOptionValue("merge_edges", theVal ? "yes" : "no" );
809 NotifySubMeshesHypothesisModification();
813 //=============================================================================
814 void BLSURFPlugin_Hypothesis::SetPreCADRemoveDuplicateCADFaces(bool theVal)
816 if (theVal != ToBool( GetPreCADOptionValue("remove_duplicate_cad_faces", GET_DEFAULT()))) {
817 _preCADRemoveDuplicateCADFaces = theVal;
818 SetPreCADOptionValue("remove_duplicate_cad_faces", theVal ? "yes" : "no" );
819 NotifySubMeshesHypothesisModification();
823 //=============================================================================
824 void BLSURFPlugin_Hypothesis::SetPreCADProcess3DTopology(bool theVal)
826 if (theVal != ToBool( GetPreCADOptionValue("process_3d_topology", GET_DEFAULT()))) {
827 _preCADProcess3DTopology = theVal;
828 SetPreCADOptionValue("process_3d_topology", theVal ? "yes" : "no" );
829 NotifySubMeshesHypothesisModification();
833 //=============================================================================
834 void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal)
836 if (theVal != ToBool( GetPreCADOptionValue("discard_input_topology", GET_DEFAULT()))) {
837 _preCADDiscardInput = theVal;
838 SetPreCADOptionValue("discard_input_topology", theVal ? "yes" : "no" );
839 NotifySubMeshesHypothesisModification();
843 //=============================================================================
844 // Return true if any PreCAD option is activated
845 bool BLSURFPlugin_Hypothesis::HasPreCADOptions(const BLSURFPlugin_Hypothesis* hyp)
847 if ( !hyp || hyp->_name == GetHypType(/*hasgeom=*/false))
851 bool orDefault, isOk;
852 return ( ToBool( hyp->GetPreCADOptionValue("closed_geometry" , &orDefault )) ||
853 ToBool( hyp->GetPreCADOptionValue("discard_input_topology" , &orDefault )) ||
854 ToBool( hyp->GetPreCADOptionValue("merge_edges" , &orDefault )) ||
855 ToBool( hyp->GetPreCADOptionValue("remove_duplicate_cad_faces", &orDefault )) ||
856 ToBool( hyp->GetPreCADOptionValue("process_3d_topology" , &orDefault )) ||
857 ToBool( hyp->GetPreCADOption ("manifold_geometry") , &isOk ) ||
858 hyp->GetPreCADOptionValue("sewing_tolerance", &orDefault ) != "5e-4*D" ||
859 !hyp->_preCadFacesPeriodicityVector.empty() ||
860 !hyp->_preCadEdgesPeriodicityVector.empty() ||
861 !hyp->_facesPeriodicityVector.empty() ||
862 !hyp->_edgesPeriodicityVector.empty() ||
863 !hyp->_verticesPeriodicityVector.empty() ||
864 !hyp->GetHyperPatches().empty() ||
865 hyp->GetTopology() != FromCAD );
868 //=============================================================================
869 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
870 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
872 _GMFFileName = theFileName;
873 // _GMFFileMode = isBinary;
874 NotifySubMeshesHypothesisModification();
877 //=============================================================================
878 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
879 throw (std::invalid_argument) {
881 TOptionValues::iterator op_val = _option2value.find(optionName);
882 if (op_val == _option2value.end())
884 op_val = _preCADoption2value.find(optionName);
885 if (op_val == _preCADoption2value.end())
887 std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'. Try SetAdvancedOption()";
888 throw std::invalid_argument(msg);
891 if (op_val->second != optionValue)
893 const char* ptr = optionValue.c_str();
894 // strip white spaces
895 while (ptr[0] == ' ')
898 while (i != 0 && ptr[i - 1] == ' ')
902 std::string typeName;
905 } else if (_charOptions.count(optionName)) {
906 // do not check strings
907 } else if (_doubleOptions.count(optionName)) {
908 // check if value is double
911 } else if (_boolOptions.count(optionName)) {
912 // check if value is bool
913 ToBool(ptr, &typeOk);
916 // check if value is int
918 typeName = "integer";
921 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
922 throw std::invalid_argument(msg);
924 std::string value( ptr, i );
925 if ( _defaultOptionValues[ optionName ] == value )
928 op_val->second = value;
930 NotifySubMeshesHypothesisModification();
934 //=============================================================================
935 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
936 throw (std::invalid_argument) {
938 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
939 if (op_val == _preCADoption2value.end()) {
940 op_val = _option2value.find(optionName);
941 if (op_val == _option2value.end()) {
942 std::string msg = "Unknown MG-PreCAD option: '" + optionName + "'. Try SetAdvancedOption()";
943 throw std::invalid_argument(msg);
946 if (op_val->second != optionValue)
948 const char* ptr = optionValue.c_str();
949 // strip white spaces
950 while (ptr[0] == ' ')
953 while (i != 0 && ptr[i - 1] == ' ')
957 std::string typeName;
960 } else if (_preCADcharOptions.find(optionName) != _preCADcharOptions.end()) {
961 // do not check strings
962 } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
963 // check if value is double
965 strtod(ptr, &endPtr);
966 typeOk = (ptr != endPtr);
968 } else if (_boolOptions.count(optionName)) {
969 // check if value is bool
970 ToBool(ptr, &typeOk);
973 // check if value is int
975 strtol(ptr, &endPtr, 10);
976 typeOk = (ptr != endPtr);
977 typeName = "integer";
980 std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
981 throw std::invalid_argument(msg);
983 std::string value( ptr, i );
984 if ( _defaultOptionValues[ optionName ] == value )
987 op_val->second = value;
989 NotifySubMeshesHypothesisModification();
993 //=============================================================================
994 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
995 bool* isDefault) const
996 throw (std::invalid_argument)
998 TOptionValues::const_iterator op_val = _option2value.find(optionName);
999 if (op_val == _option2value.end())
1001 op_val = _preCADoption2value.find(optionName);
1002 if (op_val == _preCADoption2value.end())
1004 op_val = _customOption2value.find(optionName);
1005 if (op_val == _customOption2value.end())
1007 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
1008 throw std::invalid_argument(msg);
1012 std::string val = op_val->second;
1013 if ( isDefault ) *isDefault = ( val.empty() );
1015 if ( val.empty() && isDefault )
1017 op_val = _defaultOptionValues.find( optionName );
1018 if (op_val != _defaultOptionValues.end())
1019 val = op_val->second;
1024 //=============================================================================
1025 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName,
1026 bool* isDefault) const
1027 throw (std::invalid_argument)
1029 TOptionValues::const_iterator op_val = _preCADoption2value.find(optionName);
1030 if (op_val == _preCADoption2value.end())
1032 op_val = _option2value.find(optionName);
1033 if (op_val == _option2value.end())
1035 op_val = _customOption2value.find(optionName);
1036 if (op_val == _customOption2value.end())
1038 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
1039 throw std::invalid_argument(msg);
1043 std::string val = op_val->second;
1044 if ( isDefault ) *isDefault = ( val.empty() );
1046 if ( val.empty() && isDefault )
1048 op_val = _defaultOptionValues.find( optionName );
1049 if (op_val != _option2value.end())
1050 val = op_val->second;
1055 //=============================================================================
1056 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
1058 TOptionValues::iterator op_val = _customOption2value.find(optionName);
1059 if (op_val != _customOption2value.end())
1060 _customOption2value.erase(op_val);
1062 op_val = _option2value.find(optionName);
1063 if (op_val != _option2value.end())
1064 op_val->second.clear();
1066 op_val = _preCADoption2value.find(optionName);
1067 if (op_val != _preCADoption2value.end())
1068 op_val->second.clear();
1073 //=============================================================================
1074 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName)
1076 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
1077 if (op_val != _preCADoption2value.end())
1078 op_val->second.clear();
1081 //=============================================================================
1082 void BLSURFPlugin_Hypothesis::AddOption(const std::string& optionName, const std::string& optionValue)
1085 TOptionValues::iterator op_val = _option2value.find(optionName);
1086 if (op_val != _option2value.end())
1088 if (op_val->second != optionValue)
1089 op_val->second = optionValue;
1095 op_val = _preCADoption2value.find(optionName);
1096 if (op_val != _preCADoption2value.end())
1098 if (op_val->second != optionValue)
1099 op_val->second = optionValue;
1103 else if ( optionValue.empty() )
1105 _customOption2value.erase( optionName );
1109 op_val = _customOption2value.find(optionName);
1110 if (op_val == _customOption2value.end())
1111 _customOption2value[optionName] = optionValue;
1112 else if (op_val->second != optionValue)
1113 op_val->second = optionValue;
1119 NotifySubMeshesHypothesisModification();
1122 //=============================================================================
1123 void BLSURFPlugin_Hypothesis::AddPreCADOption(const std::string& optionName, const std::string& optionValue)
1125 AddOption( optionName, optionValue );
1128 //=============================================================================
1129 std::string BLSURFPlugin_Hypothesis::GetOption(const std::string& optionName) const
1131 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1132 if (op_val != _customOption2value.end())
1133 return op_val->second;
1138 //=============================================================================
1139 std::string BLSURFPlugin_Hypothesis::GetPreCADOption(const std::string& optionName) const
1141 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1142 if (op_val != _customOption2value.end())
1143 return op_val->second;
1148 //=============================================================================
1149 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetOptionValues() const
1152 TOptionValues::const_iterator op_val = _option2value.begin();
1153 for ( ; op_val != _option2value.end(); ++op_val )
1154 vals.insert( make_pair( op_val->first, GetOptionValue( op_val->first, GET_DEFAULT() )));
1159 //=============================================================================
1160 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetPreCADOptionValues() const
1163 TOptionValues::const_iterator op_val = _preCADoption2value.begin();
1164 for ( ; op_val != _preCADoption2value.end(); ++op_val )
1165 vals.insert( make_pair( op_val->first, GetPreCADOptionValue( op_val->first, GET_DEFAULT() )));
1170 //=======================================================================
1171 //function : SetSizeMapEntry
1172 //=======================================================================
1173 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
1174 if (_sizeMap[entry].compare(sizeMap) != 0) {
1175 SetPhysicalMesh(PhysicalLocalSize);
1176 _sizeMap[entry] = sizeMap;
1177 NotifySubMeshesHypothesisModification();
1181 //=======================================================================
1182 //function : GetSizeMapEntry
1183 //=======================================================================
1184 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
1185 TSizeMap::iterator it = _sizeMap.find(entry);
1186 if (it != _sizeMap.end())
1189 return "No_Such_Entry";
1193 * \brief Return the size maps
1195 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
1196 return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
1199 //=======================================================================
1200 //function : SetAttractorEntry
1201 //=======================================================================
1202 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
1203 if (_attractors[entry].compare(attractor) != 0) {
1204 SetPhysicalMesh(PhysicalLocalSize);
1205 _attractors[entry] = attractor;
1206 NotifySubMeshesHypothesisModification();
1210 //=======================================================================
1211 //function : GetAttractorEntry
1212 //=======================================================================
1213 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
1214 TSizeMap::iterator it = _attractors.find(entry);
1215 if (it != _attractors.end())
1218 return "No_Such_Entry";
1222 * \brief Return the attractors
1224 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
1225 return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
1228 //=======================================================================
1229 //function : SetClassAttractorEntry
1230 //=======================================================================
1231 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
1233 SetPhysicalMesh(PhysicalLocalSize);
1235 // The new attractor can't be defined on the same face as another sizemap
1236 TSizeMap::iterator it = _sizeMap.find( entry );
1237 if ( it != _sizeMap.end() ) {
1239 NotifySubMeshesHypothesisModification();
1242 TSizeMap::iterator itAt = _attractors.find( entry );
1243 if ( itAt != _attractors.end() ) {
1244 _attractors.erase(itAt);
1245 NotifySubMeshesHypothesisModification();
1249 const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
1250 const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
1251 TAttractorMap::iterator attIt = _classAttractors.find(entry);
1252 for ( ; attIt != _classAttractors.end(); ++attIt )
1253 if ( attIt->first == entry &&
1254 attIt->second->GetAttractorEntry() == attEntry )
1256 bool attExists = (attIt != _classAttractors.end());
1258 BLSURFPlugin_Attractor* myAttractor;
1260 myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 );
1261 _classAttractors.insert( make_pair( entry, myAttractor ));
1264 myAttractor = attIt->second;
1266 // if (!myAttractor->IsMapBuilt())
1267 // myAttractor->BuildMap();
1268 myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
1270 NotifySubMeshesHypothesisModification();
1273 //=======================================================================
1274 //function : SetConstantSizeOnAdjacentFaces
1275 //=======================================================================
1276 // TODO uncomment and test (include the needed .hxx)
1277 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist ) {
1278 // TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
1279 // TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
1280 // TopTools_IndexedMapOfShapListOdShape::iterator it;
1281 // for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
1282 // SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
1290 //=======================================================================
1291 //function : GetClassAttractorEntry
1292 //=======================================================================
1293 // BLSURFPlugin_Attractor& BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
1295 // TAttractorMap::iterator it = _classAttractors.find( entry );
1296 // if ( it != _classAttractors.end() )
1297 // return it->second;
1299 // return "No_Such_Entry";
1303 * \brief Return the map of attractor instances
1305 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
1307 return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
1310 //=======================================================================
1311 //function : ClearEntry
1312 //=======================================================================
1313 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
1314 const char * attEntry/*=0*/)
1316 TSizeMap::iterator it = _sizeMap.find( entry );
1318 if ( it != _sizeMap.end() ) {
1320 NotifySubMeshesHypothesisModification();
1323 TSizeMap::iterator itAt = _attractors.find( entry );
1324 if ( itAt != _attractors.end() ) {
1325 _attractors.erase(itAt);
1326 NotifySubMeshesHypothesisModification();
1329 TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
1330 if ( it_clAt != _classAttractors.end() ) {
1332 if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
1333 _classAttractors.erase( it_clAt++ );
1337 while ( it_clAt != _classAttractors.end() );
1338 NotifySubMeshesHypothesisModification();
1341 std::cout<<"No_Such_Entry"<<std::endl;
1346 //=======================================================================
1347 //function : ClearSizeMaps
1348 //=======================================================================
1349 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
1351 _attractors.clear();
1352 _classAttractors.clear();
1355 // Enable internal enforced vertices on specific face if requested by user
1357 ////=======================================================================
1358 ////function : SetInternalEnforcedVertex
1359 ////=======================================================================
1360 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
1361 // bool toEnforceInternalVertices,
1362 // TEnfGroupName theGroupName) {
1364 // << toEnforceInternalVertices << ", " << theGroupName << ")");
1366 // TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
1367 // if (it != _faceEntryInternalVerticesList.end()) {
1368 // if (!toEnforceInternalVertices) {
1369 // _faceEntryInternalVerticesList.erase(it);
1373 // if (toEnforceInternalVertices) {
1374 // _faceEntryInternalVerticesList.insert(theFaceEntry);
1379 // // Take care of groups
1383 //=======================================================================
1384 //function : SetEnforcedVertex
1385 //=======================================================================
1386 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry,
1387 TEnfName theVertexName,
1388 TEntry theVertexEntry,
1389 TEnfGroupName theGroupName,
1390 double x, double y, double z)
1392 SetPhysicalMesh(PhysicalLocalSize);
1394 bool toNotify = false;
1395 bool toCreate = true;
1397 TEnfVertex *oldEnVertex;
1398 TEnfVertex *newEnfVertex = new TEnfVertex();
1399 newEnfVertex->name = theVertexName;
1400 newEnfVertex->geomEntry = theVertexEntry;
1401 newEnfVertex->coords.clear();
1402 if (theVertexEntry == "") {
1403 newEnfVertex->coords.push_back(x);
1404 newEnfVertex->coords.push_back(y);
1405 newEnfVertex->coords.push_back(z);
1407 newEnfVertex->grpName = theGroupName;
1408 newEnfVertex->faceEntries.clear();
1409 newEnfVertex->faceEntries.insert(theFaceEntry);
1412 // update _enfVertexList
1413 TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
1414 if (it != _enfVertexList.end()) {
1416 oldEnVertex = (*it);
1417 if (oldEnVertex->name != theVertexName) {
1418 oldEnVertex->name = theVertexName;
1421 if (oldEnVertex->grpName != theGroupName) {
1422 oldEnVertex->grpName = theGroupName;
1425 TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
1426 if (it_faceEntries == oldEnVertex->faceEntries.end()) {
1427 oldEnVertex->faceEntries.insert(theFaceEntry);
1428 _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
1432 // update map coords / enf vertex if needed
1433 if (oldEnVertex->coords.size()) {
1434 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
1435 _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
1438 // update map geom entry / enf vertex if needed
1439 if (oldEnVertex->geomEntry != "") {
1440 _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
1441 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
1446 // //////// CREATE ////////////
1449 _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
1450 _enfVertexList.insert(newEnfVertex);
1451 if (theVertexEntry == "") {
1452 _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
1453 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
1456 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
1457 _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
1462 NotifySubMeshesHypothesisModification();
1468 //=======================================================================
1469 //function : GetEnforcedVertices
1470 //=======================================================================
1472 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
1473 throw (std::invalid_argument) {
1475 if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
1476 return _faceEntryEnfVertexListMap[theFaceEntry];
1478 return GetDefaultEnfVertexList();
1480 std::ostringstream msg;
1481 msg << "No enforced vertex for face entry " << theFaceEntry;
1482 throw std::invalid_argument(msg.str());
1485 //=======================================================================
1486 //function : GetEnfVertexCoordsList
1487 //=======================================================================
1489 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
1490 const TEntry& theFaceEntry) throw (std::invalid_argument) {
1492 if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
1493 return _faceEntryCoordsListMap[theFaceEntry];
1495 std::ostringstream msg;
1496 msg << "No enforced vertex coords for face entry " << theFaceEntry;
1497 throw std::invalid_argument(msg.str());
1500 //=======================================================================
1501 //function : GetEnfVertexEntryList
1502 //=======================================================================
1504 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
1505 throw (std::invalid_argument) {
1507 if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
1508 return _faceEntryEnfVertexEntryListMap[theFaceEntry];
1510 std::ostringstream msg;
1511 msg << "No enforced vertex entry for face entry " << theFaceEntry;
1512 throw std::invalid_argument(msg.str());
1515 //=======================================================================
1516 //function : GetEnfVertex(TEnfVertexCoords coords)
1517 //=======================================================================
1519 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
1520 throw (std::invalid_argument) {
1522 if (_coordsEnfVertexMap.count(coords) > 0)
1523 return _coordsEnfVertexMap[coords];
1525 std::ostringstream msg;
1526 msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
1527 throw std::invalid_argument(msg.str());
1530 //=======================================================================
1531 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
1532 //=======================================================================
1534 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
1535 throw (std::invalid_argument) {
1537 if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
1538 return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
1540 std::ostringstream msg;
1541 msg << "No enforced vertex with entry " << theEnfVertexEntry;
1542 throw std::invalid_argument(msg.str());
1545 //Enable internal enforced vertices on specific face if requested by user
1546 ////=======================================================================
1547 ////function : GetInternalEnforcedVertex
1548 ////=======================================================================
1550 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
1552 // if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
1557 //=======================================================================
1558 //function : ClearEnforcedVertex
1559 //=======================================================================
1561 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
1562 const TEntry& theVertexEntry) throw (std::invalid_argument) {
1564 bool toNotify = false;
1565 std::ostringstream msg;
1566 TEnfVertex *oldEnfVertex;
1567 TEnfVertexCoords coords;
1569 coords.push_back(x);
1570 coords.push_back(y);
1571 coords.push_back(z);
1573 // check that enf vertex with given enf vertex entry exists
1574 TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
1575 if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
1577 oldEnfVertex = it_enfVertexEntry->second;
1579 _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
1581 TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
1582 enfVertexEntryList.erase(theVertexEntry);
1583 if (enfVertexEntryList.size() == 0)
1584 _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
1585 // TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1586 // TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
1587 // it_entry_entry->second.erase(it_entryList);
1588 // if (it_entry_entry->second.size() == 0)
1589 // _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1592 MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
1593 msg << "No enforced vertex with geom entry " << theVertexEntry;
1594 // check that enf vertex with given coords exists
1595 TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
1596 if (it_coords_enf != _coordsEnfVertexMap.end()) {
1598 oldEnfVertex = it_coords_enf->second;
1600 _coordsEnfVertexMap.erase(it_coords_enf);
1602 TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
1603 enfVertexCoordsList.erase(coords);
1604 if (enfVertexCoordsList.size() == 0)
1605 _faceEntryCoordsListMap.erase(theFaceEntry);
1606 // TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1607 // TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
1608 // it_entry_coords->second.erase(it_coordsList);
1609 // if (it_entry_coords->second.size() == 0)
1610 // _faceEntryCoordsListMap.erase(it_entry_coords);
1613 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
1615 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
1616 throw std::invalid_argument(msg.str());
1620 // update _enfVertexList
1621 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1622 if (it != _enfVertexList.end()) {
1623 (*it)->faceEntries.erase(theFaceEntry);
1624 if ((*it)->faceEntries.size() == 0){
1625 _enfVertexList.erase(it);
1630 // update _faceEntryEnfVertexListMap
1631 TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
1632 currentEnfVertexList.erase(oldEnfVertex);
1634 if (currentEnfVertexList.size() == 0) {
1635 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1639 NotifySubMeshesHypothesisModification();
1644 //=======================================================================
1645 //function : ClearEnforcedVertices
1646 //=======================================================================
1648 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
1650 bool toNotify = false;
1651 TEnfVertex *oldEnfVertex;
1653 TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1654 if (it_entry_coords != _faceEntryCoordsListMap.end()) {
1656 TEnfVertexCoordsList coordsList = it_entry_coords->second;
1657 TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
1658 for (; it_coordsList != coordsList.end(); ++it_coordsList) {
1659 TEnfVertexCoords coords = (*it_coordsList);
1660 oldEnfVertex = _coordsEnfVertexMap[coords];
1661 _coordsEnfVertexMap.erase(coords);
1662 // update _enfVertexList
1663 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1664 if (it != _enfVertexList.end()) {
1665 (*it)->faceEntries.erase(theFaceEntry);
1666 if ((*it)->faceEntries.size() == 0){
1667 _enfVertexList.erase(it);
1672 _faceEntryCoordsListMap.erase(it_entry_coords);
1673 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1676 TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1677 if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
1679 TEntryList enfVertexEntryList = it_entry_entry->second;
1680 TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
1681 for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
1682 TEntry enfVertexEntry = (*it_enfVertexEntryList);
1683 oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
1684 _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
1685 // update _enfVertexList
1686 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1687 if (it != _enfVertexList.end()) {
1688 (*it)->faceEntries.erase(theFaceEntry);
1689 if ((*it)->faceEntries.size() == 0){
1690 _enfVertexList.erase(it);
1695 _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1696 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1700 NotifySubMeshesHypothesisModification();
1703 // std::ostringstream msg;
1704 // msg << "No enforced vertex for " << theFaceEntry;
1705 // throw std::invalid_argument(msg.str());
1708 //=======================================================================
1709 //function : ClearAllEnforcedVertices
1710 //=======================================================================
1711 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
1712 _faceEntryEnfVertexListMap.clear();
1713 _enfVertexList.clear();
1714 _faceEntryCoordsListMap.clear();
1715 _coordsEnfVertexMap.clear();
1716 _faceEntryEnfVertexEntryListMap.clear();
1717 _enfVertexEntryEnfVertexMap.clear();
1718 // Enable internal enforced vertices on specific face if requested by user
1719 // _faceEntryInternalVerticesList.clear();
1720 NotifySubMeshesHypothesisModification();
1723 //================================================================================
1725 * \brief Return the enforced vertices
1727 //================================================================================
1730 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1731 const BLSURFPlugin_Hypothesis* hyp) {
1732 return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1735 //Enable internal enforced vertices on specific face if requested by user
1736 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1737 // const BLSURFPlugin_Hypothesis* hyp) {
1738 // return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1741 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1743 return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1746 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1748 return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1751 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1752 const BLSURFPlugin_Hypothesis* hyp) {
1753 return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1756 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1757 const BLSURFPlugin_Hypothesis* hyp) {
1758 return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1761 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1762 const BLSURFPlugin_Hypothesis* hyp) {
1763 return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1766 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1767 const BLSURFPlugin_Hypothesis* hyp) {
1768 return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1771 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1772 const BLSURFPlugin_Hypothesis* hyp) {
1773 return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1776 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1778 TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1779 if (it != _groupNameNodeIDMap.end()) {
1782 std::ostringstream msg;
1783 msg << "No group " << theGroupName;
1784 throw std::invalid_argument(msg.str());
1787 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1789 _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1792 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1794 TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1795 if (it != _groupNameNodeIDMap.end()) {
1796 std::set<int>::iterator IDit = it->second.find(theNodeID);
1797 if (IDit != it->second.end())
1798 it->second.erase(IDit);
1799 std::ostringstream msg;
1800 msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1801 throw std::invalid_argument(msg.str());
1803 std::ostringstream msg;
1804 msg << "No group " << theGroupName;
1805 throw std::invalid_argument(msg.str());
1809 //=============================================================================
1810 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1811 if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1812 _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1813 if (toEnforceInternalVertices)
1814 SetPhysicalMesh(PhysicalLocalSize);
1815 NotifySubMeshesHypothesisModification();
1820 //=============================================================================
1821 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1822 if (std::string(theGroupName) != std::string(_enforcedInternalVerticesAllFacesGroup)) {
1823 _enforcedInternalVerticesAllFacesGroup = theGroupName;
1824 NotifySubMeshesHypothesisModification();
1828 //=============================================================================
1829 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
1830 const BLSURFPlugin_Hypothesis* hyp) {
1831 return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
1834 //=============================================================================
1835 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
1836 const BLSURFPlugin_Hypothesis* hyp) {
1837 return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
1840 //=============================================================================
1841 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
1842 const BLSURFPlugin_Hypothesis* hyp) {
1843 return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
1846 //=============================================================================
1847 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
1848 const BLSURFPlugin_Hypothesis* hyp){
1849 return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
1852 //=============================================================================
1853 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
1854 const BLSURFPlugin_Hypothesis* hyp){
1855 return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
1858 //=======================================================================
1859 //function : ClearAllEnforcedVertices
1860 //=======================================================================
1861 void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
1862 _preCadFacesPeriodicityVector.clear();
1863 _preCadEdgesPeriodicityVector.clear();
1864 NotifySubMeshesHypothesisModification();
1867 //=======================================================================
1868 //function : AddPreCadFacesPeriodicity
1869 //=======================================================================
1870 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
1871 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1873 TPreCadPeriodicity preCadFacesPeriodicity;
1874 preCadFacesPeriodicity.shape1Entry = theFace1Entry;
1875 preCadFacesPeriodicity.shape2Entry = theFace2Entry;
1876 preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1877 preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1879 _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
1881 NotifySubMeshesHypothesisModification();
1884 //=======================================================================
1885 //function : AddPreCadEdgesPeriodicity
1886 //=======================================================================
1887 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
1888 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1890 TPreCadPeriodicity preCadEdgesPeriodicity;
1891 preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
1892 preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
1893 preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1894 preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1896 _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
1898 NotifySubMeshesHypothesisModification();
1901 //=============================================================================
1902 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
1904 // We must keep at least the same number of arguments when increasing the SALOME version
1905 // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
1906 // parameter can be written several times to keep the old global number of parameters.
1908 // Treat old options which are now in the advanced options
1909 TOptionValues::iterator op_val;
1911 int _preCADRemoveNanoEdges = -1;
1912 double _preCADEpsNano = -1.0;
1913 op_val = _option2value.find("respect_geometry");
1914 if (op_val != _option2value.end()) {
1915 std::string value = op_val->second;
1917 _decimesh = value.compare("1") == 0 ? 1 : 0;
1919 op_val = _preCADoption2value.find("remove_tiny_edges");
1920 if (op_val != _preCADoption2value.end()) {
1921 std::string value = op_val->second;
1923 _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
1925 op_val = _preCADoption2value.find("tiny_edge_length");
1926 if (op_val != _preCADoption2value.end()) {
1927 std::string value = op_val->second;
1929 _preCADEpsNano = strtod(value.c_str(), NULL);
1932 save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1933 << _angleMesh << " " << _gradation << " " << (int) _elementType << " " << _decimesh;
1934 save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
1935 save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1936 save << " " << (int) _enforcedInternalVerticesAllFaces;
1937 save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
1938 save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
1939 save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
1940 save << " " << (int) _preCADProcess3DTopology << " " << (int) _preCADRemoveDuplicateCADFaces;
1941 save << " " << (int)_optimiseTinyEdges << " " << _tinyEdgeOptimisationLength;
1942 save << " " << (int)_correctSurfaceIntersec << " " << _corrSurfaceIntersCost;
1943 save << " " << (int)_useGradation << " " << (int)_useVolumeGradation << " " << _volumeGradation;
1945 op_val = _option2value.begin();
1946 if (op_val != _option2value.end()) {
1947 save << " " << "__OPTIONS_BEGIN__";
1948 for (; op_val != _option2value.end(); ++op_val) {
1949 if (!op_val->second.empty())
1950 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1952 save << " " << "__OPTIONS_END__";
1955 op_val = _customOption2value.begin();
1956 if (op_val != _customOption2value.end()) {
1957 save << " " << "__CUSTOM_OPTIONS_BEGIN__";
1958 for (; op_val != _customOption2value.end(); ++op_val) {
1959 if (!op_val->second.empty())
1960 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1962 save << " " << "__CUSTOM_OPTIONS_END__";
1965 op_val = _preCADoption2value.begin();
1966 if (op_val != _preCADoption2value.end()) {
1967 save << " " << "__PRECAD_OPTIONS_BEGIN__";
1968 for (; op_val != _preCADoption2value.end(); ++op_val) {
1969 if (!op_val->second.empty())
1970 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1972 save << " " << "__PRECAD_OPTIONS_END__";
1975 TSizeMap::iterator it_sm = _sizeMap.begin();
1976 if (it_sm != _sizeMap.end()) {
1977 save << " " << "__SIZEMAP_BEGIN__";
1978 for (; it_sm != _sizeMap.end(); ++it_sm) {
1979 save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
1981 save << " " << "__SIZEMAP_END__";
1984 TSizeMap::iterator it_at = _attractors.begin();
1985 if (it_at != _attractors.end()) {
1986 save << " " << "__ATTRACTORS_BEGIN__";
1987 for (; it_at != _attractors.end(); ++it_at) {
1988 save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
1990 save << " " << "__ATTRACTORS_END__";
1993 TAttractorMap::iterator it_At = _classAttractors.begin();
1994 if (it_At != _classAttractors.end()) {
1995 std::ostringstream test;
1996 save << " " << "__NEW_ATTRACTORS_BEGIN__";
1997 test << " " << "__NEW_ATTRACTORS_BEGIN__";
1998 for (; it_At != _classAttractors.end(); ++it_At) {
1999 std::vector<double> attParams;
2000 attParams = it_At->second->GetParameters();
2001 // double step = it_At->second->GetStep();
2002 save << " " << it_At->first;
2003 save << " " << it_At->second->GetAttractorEntry();
2004 save << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
2005 // save << " " << step;
2006 test << " " << it_At->first;
2007 test << " " << it_At->second->GetAttractorEntry();
2008 test << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
2009 // test << " " << step;
2011 save << " " << "__NEW_ATTRACTORS_END__";
2012 test << " " << "__NEW_ATTRACTORS_END__";
2015 TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
2016 if (it_enf != _enfVertexList.end()) {
2017 save << " " << "__ENFORCED_VERTICES_BEGIN__";
2018 for (; it_enf != _enfVertexList.end(); ++it_enf) {
2019 TEnfVertex *enfVertex = (*it_enf);
2020 save << " " << "__BEGIN_VERTEX__";
2021 if (!enfVertex->name.empty()) {
2022 save << " " << "__BEGIN_NAME__";
2023 save << " " << enfVertex->name;
2024 save << " " << "__END_NAME__";
2026 if (!enfVertex->geomEntry.empty()) {
2027 save << " " << "__BEGIN_ENTRY__";
2028 save << " " << enfVertex->geomEntry;
2029 save << " " << "__END_ENTRY__";
2031 if (!enfVertex->grpName.empty()) {
2032 save << " " << "__BEGIN_GROUP__";
2033 save << " " << enfVertex->grpName;
2034 save << " " << "__END_GROUP__";
2036 if (enfVertex->coords.size()) {
2037 save << " " << "__BEGIN_COORDS__";
2038 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
2039 save << " " << enfVertex->coords[i];
2040 save << " " << "__END_COORDS__";
2042 TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
2043 bool hasFaces = false;
2044 if (faceEntriesIt != enfVertex->faceEntries.end()) {
2046 save << " " << "__BEGIN_FACELIST__";
2048 for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
2049 if ( faceEntriesIt->empty() )
2050 save << " _no_face_";
2052 save << " " << (*faceEntriesIt);
2054 save << " " << "__END_FACELIST__";
2055 save << " " << "__END_VERTEX__";
2057 save << " " << "__ENFORCED_VERTICES_END__";
2062 SavePreCADPeriodicity(save, "FACES");
2063 SavePreCADPeriodicity(save, "EDGES");
2065 SaveFacesPeriodicity(save);
2066 SaveEdgesPeriodicity(save);
2067 SaveVerticesPeriodicity(save);
2070 save << " " << _hyperPatchList.size() << " ";
2071 for ( size_t i = 0; i < _hyperPatchList.size(); ++i )
2073 THyperPatchTags& patch = _hyperPatchList[i];
2074 save << patch.size() << " ";
2075 THyperPatchTags::iterator tag = patch.begin();
2076 for ( ; tag != patch.end(); ++tag )
2077 save << *tag << " ";
2083 void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
2085 TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
2086 if (it_faces_periodicity != _facesPeriodicityVector.end()) {
2087 save << " " << "__FACES_PERIODICITY_BEGIN__";
2088 for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
2089 TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
2090 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2091 save << " " << "__BEGIN_ENTRY1__";
2092 save << " " << periodicity_i.first;
2093 save << " " << "__END_ENTRY1__";
2094 save << " " << "__BEGIN_ENTRY2__";
2095 save << " " << periodicity_i.second;
2096 save << " " << "__END_ENTRY2__";
2097 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2099 save << " " << "__FACES_PERIODICITY_END__";
2103 void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
2105 TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
2106 if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
2107 save << " " << "__EDGES_PERIODICITY_BEGIN__";
2108 for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
2109 TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
2110 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2111 if (! periodicity_i.theFace1Entry.empty()){
2112 save << " " << "__BEGIN_FACE1__";
2113 save << " " << periodicity_i.theFace1Entry;
2114 save << " " << "__END_FACE1__";
2116 save << " " << "__BEGIN_EDGE1__";
2117 save << " " << periodicity_i.theEdge1Entry;
2118 save << " " << "__END_EDGE1__";
2119 if (! periodicity_i.theFace2Entry.empty()){
2120 save << " " << "__BEGIN_FACE2__";
2121 save << " " << periodicity_i.theFace2Entry;
2122 save << " " << "__END_FACE2__";
2124 save << " " << "__BEGIN_EDGE2__";
2125 save << " " << periodicity_i.theEdge2Entry;
2126 save << " " << "__END_EDGE2__";
2127 save << " " << "__BEGIN_EDGE_ORIENTATION__";
2128 save << " " << periodicity_i.edge_orientation;
2129 save << " " << "__END_EDGE_ORIENTATION__";
2130 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2132 save << " " << "__EDGES_PERIODICITY_END__";
2136 void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save){
2138 TVerticesPeriodicityVector::const_iterator it_vertices_periodicity = _verticesPeriodicityVector.begin();
2139 if (it_vertices_periodicity != _verticesPeriodicityVector.end()) {
2140 save << " " << "__VERTICES_PERIODICITY_BEGIN__";
2141 for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
2142 TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
2143 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2144 save << " " << "__BEGIN_EDGE1__";
2145 save << " " << periodicity_i.theEdge1Entry;
2146 save << " " << "__END_EDGE1__";
2147 save << " " << "__BEGIN_VERTEX1__";
2148 save << " " << periodicity_i.theVertex1Entry;
2149 save << " " << "__END_VERTEX1__";
2150 save << " " << "__BEGIN_EDGE2__";
2151 save << " " << periodicity_i.theEdge2Entry;
2152 save << " " << "__END_EDGE2__";
2153 save << " " << "__BEGIN_VERTEX2__";
2154 save << " " << periodicity_i.theVertex2Entry;
2155 save << " " << "__END_VERTEX2__";
2156 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2158 save << " " << "__VERTICES_PERIODICITY_END__";
2162 void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType) {
2163 TPreCadPeriodicityVector precad_periodicity;
2164 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
2165 precad_periodicity = _preCadFacesPeriodicityVector;
2167 precad_periodicity = _preCadEdgesPeriodicityVector;
2168 TPreCadPeriodicityVector::const_iterator it_precad_periodicity = precad_periodicity.begin();
2169 if (it_precad_periodicity != precad_periodicity.end()) {
2170 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_BEGIN__";
2171 for (; it_precad_periodicity != precad_periodicity.end(); ++it_precad_periodicity) {
2172 TPreCadPeriodicity periodicity_i = (*it_precad_periodicity);
2173 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2174 if (!periodicity_i.shape1Entry.empty()) {
2175 save << " " << "__BEGIN_ENTRY1__";
2176 save << " " << periodicity_i.shape1Entry;
2177 save << " " << "__END_ENTRY1__";
2179 if (!periodicity_i.shape2Entry.empty()) {
2180 save << " " << "__BEGIN_ENTRY2__";
2181 save << " " << periodicity_i.shape2Entry;
2182 save << " " << "__END_ENTRY2__";
2185 std::vector<std::string>::const_iterator sourceVerticesEntriesIt = periodicity_i.theSourceVerticesEntries.begin();
2186 bool hasSourceVertices = false;
2187 if (sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end()) {
2188 hasSourceVertices = true;
2189 save << " " << "__BEGIN_SOURCE_VERTICES_LIST__";
2191 for (; sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end(); ++sourceVerticesEntriesIt)
2192 save << " " << (*sourceVerticesEntriesIt);
2193 if (hasSourceVertices)
2194 save << " " << "__END_SOURCE_VERTICES_LIST__";
2196 std::vector<std::string>::const_iterator targetVerticesEntriesIt = periodicity_i.theTargetVerticesEntries.begin();
2197 bool hasTargetVertices = false;
2198 if (targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end()) {
2199 hasTargetVertices = true;
2200 save << " " << "__BEGIN_TARGET_VERTICES_LIST__";
2202 for (; targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end(); ++targetVerticesEntriesIt)
2203 save << " " << (*targetVerticesEntriesIt);
2204 if (hasTargetVertices)
2205 save << " " << "__END_TARGET_VERTICES_LIST__";
2207 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2209 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_END__";
2214 //=============================================================================
2215 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
2220 std::string option_or_sm;
2222 isOK = static_cast<bool>(load >> i);
2224 _topology = (Topology) i;
2226 load.clear(std::ios::badbit | load.rdstate());
2228 isOK = static_cast<bool>(load >> i);
2230 _physicalMesh = (PhysicalMesh) i;
2232 load.clear(std::ios::badbit | load.rdstate());
2234 isOK = static_cast<bool>(load >> i);
2236 _geometricMesh = (GeometricMesh) i;
2238 load.clear(std::ios::badbit | load.rdstate());
2240 isOK = static_cast<bool>(load >> val);
2244 load.clear(std::ios::badbit | load.rdstate());
2246 isOK = static_cast<bool>(load >> val);
2250 load.clear(std::ios::badbit | load.rdstate());
2252 isOK = static_cast<bool>(load >> val);
2256 load.clear(std::ios::badbit | load.rdstate());
2258 isOK = static_cast<bool>(load >> i);
2260 _elementType = (ElementType) i;
2262 load.clear(std::ios::badbit | load.rdstate());
2264 isOK = static_cast<bool>(load >> i);
2266 if ( i != -1) { // if value is -1, then this is no longer a standard option
2267 std::string & value = _option2value["respect_geometry"];
2268 bool _decimesh = (bool) i;
2269 value = _decimesh ? "1" : "0";
2273 load.clear(std::ios::badbit | load.rdstate());
2275 isOK = static_cast<bool>(load >> val);
2279 load.clear(std::ios::badbit | load.rdstate());
2281 isOK = static_cast<bool>(load >> val);
2285 load.clear(std::ios::badbit | load.rdstate());
2287 isOK = static_cast<bool>(load >> val);
2289 // former parameter: get min value
2290 _angleMesh = std::min(val,_angleMesh);
2292 load.clear(std::ios::badbit | load.rdstate());
2294 isOK = static_cast<bool>(load >> val);
2296 // former parameter: get min value
2297 _minSize = std::min(val,_minSize);
2299 load.clear(std::ios::badbit | load.rdstate());
2301 isOK = static_cast<bool>(load >> val);
2303 // former parameter: get max value
2304 _maxSize = std::max(val,_maxSize);
2306 load.clear(std::ios::badbit | load.rdstate());
2308 isOK = static_cast<bool>(load >> i);
2312 load.clear(std::ios::badbit | load.rdstate());
2314 isOK = static_cast<bool>(load >> i);
2316 _preCADMergeEdges = (bool) i;
2318 load.clear(std::ios::badbit | load.rdstate());
2320 isOK = static_cast<bool>(load >> i);
2322 if ( i != -1) { // if value is -1, then this is no longer a standard option
2323 std::string & value = _preCADoption2value["remove_tiny_edges"];
2324 bool _preCADRemoveNanoEdges = (bool) i;
2325 value = _preCADRemoveNanoEdges ? "1" : "0";
2329 load.clear(std::ios::badbit | load.rdstate());
2331 isOK = static_cast<bool>(load >> i);
2333 _preCADDiscardInput = (bool) i;
2335 load.clear(std::ios::badbit | load.rdstate());
2337 isOK = static_cast<bool>(load >> val);
2338 if (isOK) { // _preCADEpsNano
2339 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
2340 std::string & value = _preCADoption2value["tiny_edge_length"];
2341 std::ostringstream oss;
2347 load.clear(std::ios::badbit | load.rdstate());
2349 isOK = static_cast<bool>(load >> i);
2351 _enforcedInternalVerticesAllFaces = (bool) i;
2353 load.clear(std::ios::badbit | load.rdstate());
2355 // New options with MeshGems-CADSurf
2357 bool hasCADSurfOptions = false;
2358 bool hasOptions = false;
2359 bool hasCustomOptions = false;
2360 bool hasPreCADOptions = false;
2361 bool hasSizeMap = false;
2362 bool hasAttractor = false;
2363 bool hasNewAttractor = false;
2364 bool hasEnforcedVertex = false;
2365 bool hasPreCADFacesPeriodicity = false;
2366 bool hasPreCADEdgesPeriodicity = false;
2367 bool hasFacesPeriodicity = false;
2368 bool hasEdgesPeriodicity = false;
2369 bool hasVerticesPeriodicity = false;
2371 isOK = static_cast<bool>(load >> option_or_sm);
2373 if ( (option_or_sm == "1")||(option_or_sm == "0") ) {
2374 i = atoi(option_or_sm.c_str());
2375 hasCADSurfOptions = true;
2376 _phySizeRel = (bool) i;
2378 if (option_or_sm == "__OPTIONS_BEGIN__")
2380 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2381 hasCustomOptions = true;
2382 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2383 hasPreCADOptions = true;
2384 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2386 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2387 hasAttractor = true;
2388 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2389 hasNewAttractor = true;
2390 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2391 hasEnforcedVertex = true;
2392 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2393 hasPreCADFacesPeriodicity = true;
2394 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2395 hasPreCADEdgesPeriodicity = true;
2396 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2397 hasFacesPeriodicity = true;
2398 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2399 hasEdgesPeriodicity = true;
2400 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2401 hasVerticesPeriodicity = true;
2403 if (isOK && hasCADSurfOptions) {
2404 isOK = static_cast<bool>(load >> i);
2406 _minSizeRel = (bool) i;
2408 load.clear(std::ios::badbit | load.rdstate());
2410 isOK = static_cast<bool>(load >> i);
2412 _maxSizeRel = (bool) i;
2414 load.clear(std::ios::badbit | load.rdstate());
2416 isOK = static_cast<bool>(load >> val);
2418 _chordalError = val;
2420 load.clear(std::ios::badbit | load.rdstate());
2422 isOK = static_cast<bool>(load >> i);
2424 _anisotropic = (bool) i;
2426 load.clear(std::ios::badbit | load.rdstate());
2428 isOK = static_cast<bool>(load >> val);
2430 _anisotropicRatio = val;
2432 load.clear(std::ios::badbit | load.rdstate());
2434 isOK = static_cast<bool>(load >> i);
2436 _removeTinyEdges = (bool) i;
2438 load.clear(std::ios::badbit | load.rdstate());
2440 isOK = static_cast<bool>(load >> val);
2442 _tinyEdgeLength = val;
2444 load.clear(std::ios::badbit | load.rdstate());
2446 isOK = static_cast<bool>(load >> i);
2448 _badElementRemoval = (bool) i;
2450 load.clear(std::ios::badbit | load.rdstate());
2452 isOK = static_cast<bool>(load >> val);
2454 _badElementAspectRatio = val;
2456 load.clear(std::ios::badbit | load.rdstate());
2458 isOK = static_cast<bool>(load >> i);
2460 _optimizeMesh = (bool) i;
2462 load.clear(std::ios::badbit | load.rdstate());
2464 isOK = static_cast<bool>(load >> i);
2466 _quadraticMesh = (bool) i;
2468 load.clear(std::ios::badbit | load.rdstate());
2470 isOK = static_cast<bool>(load >> i);
2472 _preCADProcess3DTopology = (bool) i;
2474 load.clear(std::ios::badbit | load.rdstate());
2476 if (( load >> std::ws).peek() != '_' )
2478 isOK = static_cast<bool>(load >> i);
2480 _preCADRemoveDuplicateCADFaces = (bool) i;
2482 load.clear(std::ios::badbit | load.rdstate());
2484 isOK = static_cast<bool>(load >> i);
2486 _optimiseTinyEdges = (bool) i;
2488 load.clear(std::ios::badbit | load.rdstate());
2490 isOK = static_cast<bool>(load >> val);
2492 _tinyEdgeOptimisationLength = val;
2494 load.clear(std::ios::badbit | load.rdstate());
2496 isOK = static_cast<bool>(load >> i);
2498 _correctSurfaceIntersec = (bool) i;
2500 load.clear(std::ios::badbit | load.rdstate());
2502 isOK = static_cast<bool>(load >> val);
2504 _corrSurfaceIntersCost = val;
2506 load.clear(std::ios::badbit | load.rdstate());
2508 isOK = static_cast<bool>(load >> i);
2510 _useGradation = (bool) i;
2512 load.clear(std::ios::badbit | load.rdstate());
2514 isOK = static_cast<bool>(load >> i);
2516 _useVolumeGradation = (bool) i;
2518 load.clear(std::ios::badbit | load.rdstate());
2520 isOK = static_cast<bool>(load >> val);
2522 _volumeGradation = val;
2524 load.clear(std::ios::badbit | load.rdstate());
2529 if (hasCADSurfOptions) {
2530 isOK = static_cast<bool>(load >> option_or_sm);
2532 if (option_or_sm == "__OPTIONS_BEGIN__")
2534 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2535 hasCustomOptions = true;
2536 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2537 hasPreCADOptions = true;
2538 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2540 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2541 hasAttractor = true;
2542 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2543 hasNewAttractor = true;
2544 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2545 hasEnforcedVertex = true;
2546 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2547 hasPreCADFacesPeriodicity = true;
2548 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2549 hasPreCADEdgesPeriodicity = true;
2550 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2551 hasFacesPeriodicity = true;
2552 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2553 hasEdgesPeriodicity = true;
2554 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2555 hasVerticesPeriodicity = true;
2559 std::string optName, optValue;
2560 while (isOK && hasOptions) {
2561 isOK = static_cast<bool>(load >> optName);
2563 if (optName == "__OPTIONS_END__")
2565 isOK = static_cast<bool>(load >> optValue);
2568 std::string & value = _option2value[optName];
2570 int len = value.size();
2571 // continue reading until "%#" encountered
2572 while (value[len - 1] != '#' || value[len - 2] != '%') {
2573 isOK = static_cast<bool>(load >> optValue);
2582 if ( value[ len - 1] == '#' )
2583 value.resize(len - 2); //cut off "%#"
2588 isOK = static_cast<bool>(load >> option_or_sm);
2590 if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2591 hasCustomOptions = true;
2592 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2593 hasPreCADOptions = true;
2594 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2596 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2597 hasAttractor = true;
2598 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2599 hasNewAttractor = true;
2600 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2601 hasEnforcedVertex = true;
2602 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2603 hasPreCADFacesPeriodicity = true;
2604 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2605 hasPreCADEdgesPeriodicity = true;
2606 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2607 hasFacesPeriodicity = true;
2608 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2609 hasEdgesPeriodicity = true;
2610 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2611 hasVerticesPeriodicity = true;
2615 while (isOK && hasCustomOptions) {
2616 isOK = static_cast<bool>(load >> optName);
2618 if (optName == "__CUSTOM_OPTIONS_END__")
2620 isOK = static_cast<bool>(load >> optValue);
2623 std::string& value = optValue;
2624 int len = value.size();
2625 // continue reading until "%#" encountered
2626 while (value[len - 1] != '#' || value[len - 2] != '%') {
2627 isOK = static_cast<bool>(load >> optValue);
2636 if ( value[ len - 1] == '#' )
2637 value.resize(len - 2); //cut off "%#"
2638 _customOption2value[optName] = value;
2642 if (hasCustomOptions) {
2643 isOK = static_cast<bool>(load >> option_or_sm);
2645 if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2646 hasPreCADOptions = true;
2647 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2649 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2650 hasAttractor = true;
2651 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2652 hasNewAttractor = true;
2653 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2654 hasEnforcedVertex = true;
2655 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2656 hasPreCADFacesPeriodicity = true;
2657 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2658 hasPreCADEdgesPeriodicity = true;
2659 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2660 hasFacesPeriodicity = true;
2661 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2662 hasEdgesPeriodicity = true;
2663 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2664 hasVerticesPeriodicity = true;
2668 while (isOK && hasPreCADOptions) {
2669 isOK = static_cast<bool>(load >> optName);
2671 if (optName == "__PRECAD_OPTIONS_END__")
2673 isOK = static_cast<bool>(load >> optValue);
2676 std::string & value = _preCADoption2value[optName];
2678 int len = value.size();
2679 // continue reading until "%#" encountered
2680 while (value[len - 1] != '#' || value[len - 2] != '%') {
2681 isOK = static_cast<bool>(load >> optValue);
2690 if ( value[ len - 1] == '#' )
2691 value.resize(len - 2); //cut off "%#"
2695 if (hasPreCADOptions) {
2696 isOK = static_cast<bool>(load >> option_or_sm);
2698 if (option_or_sm == "__SIZEMAP_BEGIN__")
2700 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2701 hasAttractor = true;
2702 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2703 hasNewAttractor = true;
2704 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2705 hasEnforcedVertex = true;
2706 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2707 hasPreCADFacesPeriodicity = true;
2708 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2709 hasPreCADEdgesPeriodicity = true;
2710 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2711 hasFacesPeriodicity = true;
2712 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2713 hasEdgesPeriodicity = true;
2714 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2715 hasVerticesPeriodicity = true;
2719 std::string smEntry, smValue;
2720 while (isOK && hasSizeMap) {
2721 isOK = static_cast<bool>(load >> smEntry);
2723 if (smEntry == "__SIZEMAP_END__")
2725 isOK = static_cast<bool>(load >> smValue);
2728 std::string & value2 = _sizeMap[smEntry];
2730 int len2 = value2.size();
2731 // continue reading until "%#" encountered
2732 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2733 isOK = static_cast<bool>(load >> smValue);
2737 len2 = value2.size();
2742 value2.resize(len2 - 2); //cut off "%#"
2747 isOK = static_cast<bool>(load >> option_or_sm);
2749 if (option_or_sm == "__ATTRACTORS_BEGIN__")
2750 hasAttractor = true;
2751 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2752 hasNewAttractor = true;
2753 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2754 hasEnforcedVertex = true;
2755 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2756 hasPreCADFacesPeriodicity = true;
2757 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2758 hasPreCADEdgesPeriodicity = true;
2759 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2760 hasFacesPeriodicity = true;
2761 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2762 hasEdgesPeriodicity = true;
2763 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2764 hasVerticesPeriodicity = true;
2767 std::string atEntry, atValue;
2768 while (isOK && hasAttractor) {
2769 isOK = static_cast<bool>(load >> atEntry);
2771 if (atEntry == "__ATTRACTORS_END__")
2773 isOK = static_cast<bool>(load >> atValue);
2776 std::string & value3 = _attractors[atEntry];
2778 int len3 = value3.size();
2779 // continue reading until "%#" encountered
2780 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
2781 isOK = static_cast<bool>(load >> atValue);
2785 len3 = value3.size();
2790 value3.resize(len3 - 2); //cut off "%#"
2795 isOK = static_cast<bool>(load >> option_or_sm);
2797 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2798 hasNewAttractor = true;
2799 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2800 hasEnforcedVertex = true;
2801 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2802 hasPreCADFacesPeriodicity = true;
2803 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2804 hasPreCADEdgesPeriodicity = true;
2805 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2806 hasFacesPeriodicity = true;
2807 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2808 hasEdgesPeriodicity = true;
2809 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2810 hasVerticesPeriodicity = true;
2814 std::string newAtFaceEntry, atTestString;
2815 std::string newAtShapeEntry;
2816 double attParams[4];
2818 while (isOK && hasNewAttractor) {
2819 //std::cout<<"Load new attractor"<<std::endl;
2820 isOK = static_cast<bool>(load >> newAtFaceEntry);
2822 if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
2824 isOK = static_cast<bool>(load >> newAtShapeEntry);
2827 isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
2830 const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
2831 const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
2832 BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
2833 attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
2834 //attractor->BuildMap();
2835 _classAttractors.insert( make_pair( newAtFaceEntry, attractor ));
2840 if (hasNewAttractor) {
2841 isOK = static_cast<bool>(load >> option_or_sm);
2843 if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2844 hasEnforcedVertex = true;
2845 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2846 hasPreCADFacesPeriodicity = true;
2847 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2848 hasPreCADEdgesPeriodicity = true;
2849 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2850 hasFacesPeriodicity = true;
2851 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2852 hasEdgesPeriodicity = true;
2853 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2854 hasVerticesPeriodicity = true;
2860 // Here is a example of the saved stream:
2861 // __ENFORCED_VERTICES_BEGIN__
2862 // __BEGIN_VERTEX__ => no name, no entry
2863 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2864 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__
2865 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__
2867 // __BEGIN_VERTEX__ => no coords
2868 // __BEGIN_NAME__ mes points __END_NAME__
2869 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
2870 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2871 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
2873 // __ENFORCED_VERTICES_END__
2876 std::string enfSeparator;
2877 std::string enfName;
2878 std::string enfGeomEntry;
2879 std::string enfGroup;
2880 TEntryList enfFaceEntryList;
2881 double enfCoords[3];
2882 bool hasCoords = false;
2884 _faceEntryEnfVertexListMap.clear();
2885 _enfVertexList.clear();
2886 _faceEntryCoordsListMap.clear();
2887 _coordsEnfVertexMap.clear();
2888 _faceEntryEnfVertexEntryListMap.clear();
2889 _enfVertexEntryEnfVertexMap.clear();
2892 while (isOK && hasEnforcedVertex)
2894 isOK = static_cast<bool>(load >> enfSeparator); // __BEGIN_VERTEX__
2895 TEnfVertex *enfVertex = new TEnfVertex();
2896 if (enfSeparator == "__ENFORCED_VERTICES_END__")
2897 break; // __ENFORCED_VERTICES_END__
2898 if (enfSeparator != "__BEGIN_VERTEX__")
2899 throw std::exception();
2902 isOK = static_cast<bool>(load >> enfSeparator);
2903 if (enfSeparator == "__END_VERTEX__") {
2905 enfVertex->name = enfName;
2906 enfVertex->geomEntry = enfGeomEntry;
2907 enfVertex->grpName = enfGroup;
2908 enfVertex->coords.clear();
2910 enfVertex->coords.assign(enfCoords,enfCoords+3);
2911 enfVertex->faceEntries = enfFaceEntryList;
2913 _enfVertexList.insert(enfVertex);
2915 if (enfVertex->coords.size()) {
2916 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
2917 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2918 _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
2919 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2922 if (!enfVertex->geomEntry.empty()) {
2923 _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
2924 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2925 _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
2926 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2931 enfGeomEntry.clear();
2933 enfFaceEntryList.clear();
2935 break; // __END_VERTEX__
2938 if (enfSeparator == "__BEGIN_NAME__") { // __BEGIN_NAME__
2939 while (isOK && (enfSeparator != "__END_NAME__")) {
2940 isOK = static_cast<bool>(load >> enfSeparator);
2941 if (enfSeparator != "__END_NAME__") {
2942 if (!enfName.empty())
2944 enfName += enfSeparator;
2949 if (enfSeparator == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
2950 isOK = static_cast<bool>(load >> enfGeomEntry);
2951 isOK = static_cast<bool>(load >> enfSeparator); // __END_ENTRY__
2952 if (enfSeparator != "__END_ENTRY__")
2953 throw std::exception();
2956 if (enfSeparator == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
2957 while (isOK && (enfSeparator != "__END_GROUP__")) {
2958 isOK = static_cast<bool>(load >> enfSeparator);
2959 if (enfSeparator != "__END_GROUP__") {
2960 if (!enfGroup.empty())
2962 enfGroup += enfSeparator;
2967 if (enfSeparator == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
2969 isOK = static_cast<bool>(load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
2970 isOK = static_cast<bool>(load >> enfSeparator); // __END_COORDS__
2971 if (enfSeparator != "__END_COORDS__")
2972 throw std::exception();
2975 if (enfSeparator == "__BEGIN_FACELIST__") { // __BEGIN_FACELIST__
2976 while (isOK && (enfSeparator != "__END_FACELIST__")) {
2977 isOK = static_cast<bool>(load >> enfSeparator);
2978 if (enfSeparator != "__END_FACELIST__") {
2979 enfFaceEntryList.insert(enfSeparator);
2988 if (hasPreCADFacesPeriodicity)
2990 LoadPreCADPeriodicity(load, "FACES");
2992 isOK = static_cast<bool>(load >> option_or_sm);
2994 if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2995 hasPreCADEdgesPeriodicity = true;
2996 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2997 hasFacesPeriodicity = true;
2998 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2999 hasEdgesPeriodicity = true;
3000 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3001 hasVerticesPeriodicity = true;
3005 if (hasPreCADEdgesPeriodicity)
3007 LoadPreCADPeriodicity(load, "EDGES");
3009 isOK = static_cast<bool>(load >> option_or_sm);
3011 if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
3012 hasFacesPeriodicity = true;
3013 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3014 hasEdgesPeriodicity = true;
3015 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3016 hasVerticesPeriodicity = true;
3020 if (hasFacesPeriodicity)
3022 LoadFacesPeriodicity(load);
3024 isOK = static_cast<bool>(load >> option_or_sm);
3026 if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3027 hasEdgesPeriodicity = true;
3028 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3029 hasVerticesPeriodicity = true;
3033 if (hasEdgesPeriodicity)
3035 LoadEdgesPeriodicity(load);
3037 isOK = static_cast<bool>(load >> option_or_sm);
3039 if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3040 hasVerticesPeriodicity = true;
3043 if (hasVerticesPeriodicity)
3044 LoadVerticesPeriodicity(load);
3047 if ( !option_or_sm.empty() && option_or_sm[0] == '_' )
3048 isOK = static_cast<bool>(load >> option_or_sm);
3049 if ( isOK && !option_or_sm.empty() )
3051 int nbPatches = atoi( option_or_sm.c_str() );
3052 if ( nbPatches >= 0 )
3054 _hyperPatchList.resize( nbPatches );
3055 for ( int iP = 0; iP < nbPatches && isOK; ++iP )
3057 isOK = static_cast<bool>(load >> i) && i >= 2;
3060 for ( int iT = 0; iT < nbTags; ++iT )
3062 if (( isOK = static_cast<bool>(load >> i)))
3063 _hyperPatchList[ iP ].insert( i );
3068 if ( !isOK ) // remove invalid patches
3070 for ( i = nbPatches - 1; i >= 0; i-- )
3071 if ( _hyperPatchList[i].size() < 2 )
3072 _hyperPatchList.resize( i );
3080 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
3084 std::string periodicitySeparator;
3088 _facesPeriodicityVector.clear();
3091 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3092 TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
3093 if (periodicitySeparator == "__FACES_PERIODICITY_END__")
3094 break; // __FACES_PERIODICITY_END__
3095 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3096 throw std::exception();
3100 isOK = static_cast<bool>(load >> periodicitySeparator);
3101 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3103 periodicity_i->first = shape1Entry;
3104 periodicity_i->second = shape2Entry;
3106 _facesPeriodicityVector.push_back(*periodicity_i);
3108 break; // __END_PERIODICITY_DESCRIPTION__
3111 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3112 isOK = static_cast<bool>(load >> shape1Entry);
3113 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3114 if (periodicitySeparator != "__END_ENTRY1__")
3115 throw std::exception();
3118 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3119 isOK = static_cast<bool>(load >> shape2Entry);
3120 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3121 if (periodicitySeparator != "__END_ENTRY2__")
3122 throw std::exception();
3129 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
3133 std::string periodicitySeparator;
3134 TEntry theFace1Entry;
3135 TEntry theEdge1Entry;
3136 TEntry theFace2Entry;
3137 TEntry theEdge2Entry;
3138 int edge_orientation = 0;
3140 _edgesPeriodicityVector.clear();
3143 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3144 TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
3145 if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
3146 break; // __EDGES_PERIODICITY_END__
3147 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3148 throw std::exception();
3152 isOK = static_cast<bool>(load >> periodicitySeparator);
3153 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3155 periodicity_i->theFace1Entry = theFace1Entry;
3156 periodicity_i->theEdge1Entry = theEdge1Entry;
3157 periodicity_i->theFace2Entry = theFace2Entry;
3158 periodicity_i->theEdge2Entry = theEdge2Entry;
3159 periodicity_i->edge_orientation = edge_orientation;
3161 _edgesPeriodicityVector.push_back(*periodicity_i);
3163 break; // __END_PERIODICITY_DESCRIPTION__
3166 if (periodicitySeparator == "__BEGIN_FACE1__") { // __BEGIN_FACE1__
3167 isOK = static_cast<bool>(load >> theFace1Entry);
3168 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE1__
3169 if (periodicitySeparator != "__END_FACE1__"){
3170 throw std::exception();
3174 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3175 isOK = static_cast<bool>(load >> theEdge1Entry);
3176 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3177 if (periodicitySeparator != "__END_EDGE1__")
3178 throw std::exception();
3181 if (periodicitySeparator == "__BEGIN_FACE2__") { // __BEGIN_FACE2__
3182 isOK = static_cast<bool>(load >> theFace2Entry);
3183 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE2__
3184 if (periodicitySeparator != "__END_FACE2__")
3185 throw std::exception();
3188 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3189 isOK = static_cast<bool>(load >> theEdge2Entry);
3190 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3191 if (periodicitySeparator != "__END_EDGE2__")
3192 throw std::exception();
3195 if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") { // __BEGIN_EDGE_ORIENTATION__
3196 isOK = static_cast<bool>(load >> edge_orientation);
3197 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
3198 if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
3199 throw std::exception();
3205 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load)
3209 std::string periodicitySeparator;
3210 TEntry theEdge1Entry;
3211 TEntry theVertex1Entry;
3212 TEntry theEdge2Entry;
3213 TEntry theVertex2Entry;
3215 _verticesPeriodicityVector.clear();
3218 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3219 TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
3220 if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
3221 break; // __VERTICES_PERIODICITY_END__
3222 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3223 throw std::exception();
3227 isOK = static_cast<bool>(load >> periodicitySeparator);
3228 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3230 periodicity_i->theEdge1Entry = theEdge1Entry;
3231 periodicity_i->theVertex1Entry = theVertex1Entry;
3232 periodicity_i->theEdge2Entry = theEdge2Entry;
3233 periodicity_i->theVertex2Entry = theVertex2Entry;
3235 _verticesPeriodicityVector.push_back(*periodicity_i);
3237 break; // __END_PERIODICITY_DESCRIPTION__
3240 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3241 isOK = static_cast<bool>(load >> theEdge1Entry);
3242 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3243 if (periodicitySeparator != "__END_EDGE1__")
3244 throw std::exception();
3247 if (periodicitySeparator == "__BEGIN_VERTEX1__") { // __BEGIN_VERTEX1__
3248 isOK = static_cast<bool>(load >> theVertex1Entry);
3249 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX1__
3250 if (periodicitySeparator != "__END_VERTEX1__")
3251 throw std::exception();
3254 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3255 isOK = static_cast<bool>(load >> theEdge2Entry);
3256 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3257 if (periodicitySeparator != "__END_EDGE2__")
3258 throw std::exception();
3261 if (periodicitySeparator == "__BEGIN_VERTEX2__") { // __BEGIN_VERTEX2__
3262 isOK = static_cast<bool>(load >> theVertex2Entry);
3263 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX2__
3264 if (periodicitySeparator != "__END_VERTEX2__")
3265 throw std::exception();
3271 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
3275 std::string periodicitySeparator;
3278 std::vector<std::string> theSourceVerticesEntries;
3279 std::vector<std::string> theTargetVerticesEntries;
3281 bool hasSourceVertices = false;
3282 bool hasTargetVertices = false;
3284 if ( shapeType && strcmp( shapeType, "FACES") == 0 )
3285 _preCadFacesPeriodicityVector.clear();
3287 _preCadEdgesPeriodicityVector.clear();
3291 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3292 TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
3293 std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
3294 if (periodicitySeparator == endSeparator)
3295 break; // __PRECAD_FACES_PERIODICITY_END__
3296 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3297 throw std::exception();
3301 isOK = static_cast<bool>(load >> periodicitySeparator);
3302 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3304 periodicity_i->shape1Entry = shape1Entry;
3305 periodicity_i->shape2Entry = shape2Entry;
3307 if (hasSourceVertices)
3308 periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
3309 if (hasTargetVertices)
3310 periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
3312 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
3313 _preCadFacesPeriodicityVector.push_back(*periodicity_i);
3315 _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
3317 theSourceVerticesEntries.clear();
3318 theTargetVerticesEntries.clear();
3319 hasSourceVertices = false;
3320 hasTargetVertices = false;
3321 break; // __END_PERIODICITY_DESCRIPTION__
3324 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3325 isOK = static_cast<bool>(load >> shape1Entry);
3326 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3327 if (periodicitySeparator != "__END_ENTRY1__")
3328 throw std::exception();
3331 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3332 isOK = static_cast<bool>(load >> shape2Entry);
3333 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3334 if (periodicitySeparator != "__END_ENTRY2__")
3335 throw std::exception();
3338 if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") { // __BEGIN_SOURCE_VERTICES_LIST__
3339 hasSourceVertices = true;
3340 while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
3341 isOK = static_cast<bool>(load >> periodicitySeparator);
3342 if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
3343 theSourceVerticesEntries.push_back(periodicitySeparator);
3348 if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") { // __BEGIN_TARGET_VERTICES_LIST__
3349 hasTargetVertices = true;
3350 while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
3351 isOK = static_cast<bool>(load >> periodicitySeparator);
3352 if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
3353 theTargetVerticesEntries.push_back(periodicitySeparator);
3361 //=============================================================================
3362 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
3363 return hyp.SaveTo(save);
3366 //=============================================================================
3367 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
3368 return hyp.LoadFrom(load);
3371 //================================================================================
3373 * \brief Does nothing
3375 //================================================================================
3377 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
3381 //================================================================================
3383 * \brief Returns default global constant physical size given a default value of element length ratio
3385 //================================================================================
3387 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
3388 if (bbSegmentation != 0 && diagonal != 0)
3389 return diagonal / bbSegmentation ;
3393 //================================================================================
3395 * \brief Returns default min size given a default value of element length ratio
3397 //================================================================================
3399 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
3401 return diagonal / 1000.0 ;
3402 return undefinedDouble();
3405 //================================================================================
3407 * \brief Returns default max size given a default value of element length ratio
3409 //================================================================================
3411 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
3413 return diagonal / 5.0 ;
3414 return undefinedDouble();
3417 //================================================================================
3419 * \brief Returns default chordal error given a default value of element length ratio
3421 //================================================================================
3423 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
3426 return undefinedDouble();
3429 //================================================================================
3431 * \brief Returns default tiny edge length given a default value of element length ratio
3433 //================================================================================
3435 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
3437 return diagonal * 1e-6 ;
3438 return undefinedDouble();
3441 //================================================================================
3443 * \brief Returns default tiny edge optimisation length given a default value of element length ratio
3445 //================================================================================
3447 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal) {
3449 return diagonal * 1e-6 ;
3450 return undefinedDouble();
3453 //=============================================================================
3455 * \brief Initialize my parameter values by default parameters.
3456 * \retval bool - true if parameter values have been successfully defined
3458 //=============================================================================
3460 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
3461 double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
3462 _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
3463 _minSize = GetDefaultMinSize(diagonal);
3464 _maxSize = GetDefaultMaxSize(diagonal);
3465 _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
3466 _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
3467 _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(diagonal);
3472 //================================================================================
3474 * \brief Converts a string to a bool
3476 //================================================================================
3478 bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
3479 throw (std::invalid_argument)
3481 std::string s = str;
3482 if ( isOk ) *isOk = true;
3484 for ( size_t i = 0; i <= s.size(); ++i )
3485 s[i] = tolower( s[i] );
3487 if ( s == "1" || s == "true" || s == "active" || s == "yes" )
3490 if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
3496 std::string msg = "Not a Boolean value:'" + str + "'";
3497 throw std::invalid_argument(msg);
3502 //================================================================================
3504 * \brief Converts a string to a real value
3506 //================================================================================
3508 double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
3509 throw (std::invalid_argument)
3511 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3514 double val = strtod(&str[0], &endPtr);
3515 bool ok = (&str[0] != endPtr);
3517 if ( isOk ) *isOk = ok;
3521 std::string msg = "Not a real value:'" + str + "'";
3522 throw std::invalid_argument(msg);
3527 //================================================================================
3529 * \brief Converts a string to a integer value
3531 //================================================================================
3533 int BLSURFPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
3534 throw (std::invalid_argument)
3536 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3539 int val = (int)strtol( &str[0], &endPtr, 10);
3540 bool ok = (&str[0] != endPtr);
3542 if ( isOk ) *isOk = ok;
3546 std::string msg = "Not an integer value:'" + str + "'";
3547 throw std::invalid_argument(msg);