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 AddEnforcedVertex( theFaceEntry, newEnfVertex );
1452 delete newEnfVertex;
1456 NotifySubMeshesHypothesisModification();
1461 //=======================================================================
1462 //function : AddEnforcedVertex
1463 //=======================================================================
1465 void BLSURFPlugin_Hypothesis::AddEnforcedVertex( const TEntry& faceEntry,
1466 TEnfVertex * newEnfVertex )
1470 _faceEntryEnfVertexListMap[faceEntry].insert(newEnfVertex);
1471 _enfVertexList.insert(newEnfVertex);
1472 if ( newEnfVertex->geomEntry.empty() ) {
1473 _faceEntryCoordsListMap[faceEntry].insert(newEnfVertex->coords);
1474 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
1477 _faceEntryEnfVertexEntryListMap[faceEntry].insert(newEnfVertex->geomEntry);
1478 _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
1483 //=======================================================================
1484 //function : GetEnforcedVertices
1485 //=======================================================================
1487 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
1488 throw (std::invalid_argument) {
1490 if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
1491 return _faceEntryEnfVertexListMap[theFaceEntry];
1493 return GetDefaultEnfVertexList();
1495 std::ostringstream msg;
1496 msg << "No enforced vertex for face entry " << theFaceEntry;
1497 throw std::invalid_argument(msg.str());
1500 //=======================================================================
1501 //function : GetEnfVertexCoordsList
1502 //=======================================================================
1504 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
1505 const TEntry& theFaceEntry) throw (std::invalid_argument) {
1507 if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
1508 return _faceEntryCoordsListMap[theFaceEntry];
1510 std::ostringstream msg;
1511 msg << "No enforced vertex coords for face entry " << theFaceEntry;
1512 throw std::invalid_argument(msg.str());
1515 //=======================================================================
1516 //function : GetEnfVertexEntryList
1517 //=======================================================================
1519 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
1520 throw (std::invalid_argument) {
1522 if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
1523 return _faceEntryEnfVertexEntryListMap[theFaceEntry];
1525 std::ostringstream msg;
1526 msg << "No enforced vertex entry for face entry " << theFaceEntry;
1527 throw std::invalid_argument(msg.str());
1530 //=======================================================================
1531 //function : GetEnfVertex(TEnfVertexCoords coords)
1532 //=======================================================================
1534 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
1535 throw (std::invalid_argument) {
1537 if (_coordsEnfVertexMap.count(coords) > 0)
1538 return _coordsEnfVertexMap[coords];
1540 std::ostringstream msg;
1541 msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
1542 throw std::invalid_argument(msg.str());
1545 //=======================================================================
1546 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
1547 //=======================================================================
1549 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
1550 throw (std::invalid_argument) {
1552 if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
1553 return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
1555 std::ostringstream msg;
1556 msg << "No enforced vertex with entry " << theEnfVertexEntry;
1557 throw std::invalid_argument(msg.str());
1560 //Enable internal enforced vertices on specific face if requested by user
1561 ////=======================================================================
1562 ////function : GetInternalEnforcedVertex
1563 ////=======================================================================
1565 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
1567 // if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
1572 //=======================================================================
1573 //function : ClearEnforcedVertex
1574 //=======================================================================
1576 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
1577 const TEntry& theVertexEntry) throw (std::invalid_argument) {
1579 bool toNotify = false;
1580 std::ostringstream msg;
1581 TEnfVertex *oldEnfVertex;
1582 TEnfVertexCoords coords;
1584 coords.push_back(x);
1585 coords.push_back(y);
1586 coords.push_back(z);
1588 // check that enf vertex with given enf vertex entry exists
1589 TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
1590 if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
1592 oldEnfVertex = it_enfVertexEntry->second;
1594 _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
1596 TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
1597 enfVertexEntryList.erase(theVertexEntry);
1598 if (enfVertexEntryList.size() == 0)
1599 _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
1600 // TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1601 // TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
1602 // it_entry_entry->second.erase(it_entryList);
1603 // if (it_entry_entry->second.size() == 0)
1604 // _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1607 MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
1608 msg << "No enforced vertex with geom entry " << theVertexEntry;
1609 // check that enf vertex with given coords exists
1610 TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
1611 if (it_coords_enf != _coordsEnfVertexMap.end()) {
1613 oldEnfVertex = it_coords_enf->second;
1615 _coordsEnfVertexMap.erase(it_coords_enf);
1617 TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
1618 enfVertexCoordsList.erase(coords);
1619 if (enfVertexCoordsList.size() == 0)
1620 _faceEntryCoordsListMap.erase(theFaceEntry);
1621 // TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1622 // TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
1623 // it_entry_coords->second.erase(it_coordsList);
1624 // if (it_entry_coords->second.size() == 0)
1625 // _faceEntryCoordsListMap.erase(it_entry_coords);
1628 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
1630 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
1631 throw std::invalid_argument(msg.str());
1635 // update _enfVertexList
1636 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1637 if (it != _enfVertexList.end()) {
1638 (*it)->faceEntries.erase(theFaceEntry);
1639 if ((*it)->faceEntries.size() == 0){
1640 _enfVertexList.erase(it);
1645 // update _faceEntryEnfVertexListMap
1646 TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
1647 currentEnfVertexList.erase(oldEnfVertex);
1649 if (currentEnfVertexList.size() == 0) {
1650 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1654 NotifySubMeshesHypothesisModification();
1659 //=======================================================================
1660 //function : ClearEnforcedVertices
1661 //=======================================================================
1663 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
1665 bool toNotify = false;
1666 TEnfVertex *oldEnfVertex;
1668 TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1669 if (it_entry_coords != _faceEntryCoordsListMap.end()) {
1671 TEnfVertexCoordsList coordsList = it_entry_coords->second;
1672 TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
1673 for (; it_coordsList != coordsList.end(); ++it_coordsList) {
1674 TEnfVertexCoords coords = (*it_coordsList);
1675 oldEnfVertex = _coordsEnfVertexMap[coords];
1676 _coordsEnfVertexMap.erase(coords);
1677 // update _enfVertexList
1678 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1679 if (it != _enfVertexList.end()) {
1680 (*it)->faceEntries.erase(theFaceEntry);
1681 if ((*it)->faceEntries.size() == 0){
1682 _enfVertexList.erase(it);
1687 _faceEntryCoordsListMap.erase(it_entry_coords);
1688 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1691 TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1692 if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
1694 TEntryList enfVertexEntryList = it_entry_entry->second;
1695 TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
1696 for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
1697 TEntry enfVertexEntry = (*it_enfVertexEntryList);
1698 oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
1699 _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
1700 // update _enfVertexList
1701 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1702 if (it != _enfVertexList.end()) {
1703 (*it)->faceEntries.erase(theFaceEntry);
1704 if ((*it)->faceEntries.size() == 0){
1705 _enfVertexList.erase(it);
1710 _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1711 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1715 NotifySubMeshesHypothesisModification();
1718 // std::ostringstream msg;
1719 // msg << "No enforced vertex for " << theFaceEntry;
1720 // throw std::invalid_argument(msg.str());
1723 //=======================================================================
1724 //function : ClearAllEnforcedVertices
1725 //=======================================================================
1726 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices()
1728 _faceEntryEnfVertexListMap.clear();
1729 _faceEntryCoordsListMap.clear();
1730 _coordsEnfVertexMap.clear();
1731 _faceEntryEnfVertexEntryListMap.clear();
1732 _enfVertexEntryEnfVertexMap.clear();
1734 TEnfVertexList::iterator it_enfVertex = _enfVertexList.begin();
1735 for ( ; it_enfVertex != _enfVertexList.end(); ++it_enfVertex )
1736 delete *it_enfVertex;
1737 _enfVertexList.clear();
1739 // Enable internal enforced vertices on specific face if requested by user
1740 // _faceEntryInternalVerticesList.clear();
1741 NotifySubMeshesHypothesisModification();
1745 //================================================================================
1747 * \brief Return the enforced vertices
1749 //================================================================================
1752 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1753 const BLSURFPlugin_Hypothesis* hyp) {
1754 return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1757 //Enable internal enforced vertices on specific face if requested by user
1758 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1759 // const BLSURFPlugin_Hypothesis* hyp) {
1760 // return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1763 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1765 return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1768 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1770 return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1773 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1774 const BLSURFPlugin_Hypothesis* hyp) {
1775 return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1778 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1779 const BLSURFPlugin_Hypothesis* hyp) {
1780 return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1783 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1784 const BLSURFPlugin_Hypothesis* hyp) {
1785 return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1788 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1789 const BLSURFPlugin_Hypothesis* hyp) {
1790 return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1793 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1794 const BLSURFPlugin_Hypothesis* hyp) {
1795 return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1798 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1800 TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1801 if (it != _groupNameNodeIDMap.end()) {
1804 std::ostringstream msg;
1805 msg << "No group " << theGroupName;
1806 throw std::invalid_argument(msg.str());
1809 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1811 _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1814 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1816 TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1817 if (it != _groupNameNodeIDMap.end()) {
1818 std::set<int>::iterator IDit = it->second.find(theNodeID);
1819 if (IDit != it->second.end())
1820 it->second.erase(IDit);
1821 std::ostringstream msg;
1822 msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1823 throw std::invalid_argument(msg.str());
1825 std::ostringstream msg;
1826 msg << "No group " << theGroupName;
1827 throw std::invalid_argument(msg.str());
1831 //=============================================================================
1832 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1833 if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1834 _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1835 if (toEnforceInternalVertices)
1836 SetPhysicalMesh(PhysicalLocalSize);
1837 NotifySubMeshesHypothesisModification();
1842 //=============================================================================
1843 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1844 if (std::string(theGroupName) != std::string(_enforcedInternalVerticesAllFacesGroup)) {
1845 _enforcedInternalVerticesAllFacesGroup = theGroupName;
1846 NotifySubMeshesHypothesisModification();
1850 //=============================================================================
1851 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
1852 const BLSURFPlugin_Hypothesis* hyp) {
1853 return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
1856 //=============================================================================
1857 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
1858 const BLSURFPlugin_Hypothesis* hyp) {
1859 return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
1862 //=============================================================================
1863 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
1864 const BLSURFPlugin_Hypothesis* hyp) {
1865 return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
1868 //=============================================================================
1869 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
1870 const BLSURFPlugin_Hypothesis* hyp){
1871 return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
1874 //=============================================================================
1875 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
1876 const BLSURFPlugin_Hypothesis* hyp){
1877 return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
1880 //=======================================================================
1881 //function : ClearAllEnforcedVertices
1882 //=======================================================================
1883 void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
1884 _preCadFacesPeriodicityVector.clear();
1885 _preCadEdgesPeriodicityVector.clear();
1886 NotifySubMeshesHypothesisModification();
1889 //=======================================================================
1890 //function : AddPreCadFacesPeriodicity
1891 //=======================================================================
1892 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
1893 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1895 TPreCadPeriodicity preCadFacesPeriodicity;
1896 preCadFacesPeriodicity.shape1Entry = theFace1Entry;
1897 preCadFacesPeriodicity.shape2Entry = theFace2Entry;
1898 preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1899 preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1901 _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
1903 NotifySubMeshesHypothesisModification();
1906 //=======================================================================
1907 //function : AddPreCadEdgesPeriodicity
1908 //=======================================================================
1909 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
1910 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1912 TPreCadPeriodicity preCadEdgesPeriodicity;
1913 preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
1914 preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
1915 preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1916 preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1918 _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
1920 NotifySubMeshesHypothesisModification();
1923 //=============================================================================
1924 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
1926 // We must keep at least the same number of arguments when increasing the SALOME version
1927 // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
1928 // parameter can be written several times to keep the old global number of parameters.
1930 // Treat old options which are now in the advanced options
1931 TOptionValues::iterator op_val;
1933 int _preCADRemoveNanoEdges = -1;
1934 double _preCADEpsNano = -1.0;
1935 op_val = _option2value.find("respect_geometry");
1936 if (op_val != _option2value.end()) {
1937 std::string value = op_val->second;
1939 _decimesh = value.compare("1") == 0 ? 1 : 0;
1941 op_val = _preCADoption2value.find("remove_tiny_edges");
1942 if (op_val != _preCADoption2value.end()) {
1943 std::string value = op_val->second;
1945 _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
1947 op_val = _preCADoption2value.find("tiny_edge_length");
1948 if (op_val != _preCADoption2value.end()) {
1949 std::string value = op_val->second;
1951 _preCADEpsNano = strtod(value.c_str(), NULL);
1954 save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1955 << _angleMesh << " " << _gradation << " " << (int) _elementType << " " << _decimesh;
1956 save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
1957 save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1958 save << " " << (int) _enforcedInternalVerticesAllFaces;
1959 save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
1960 save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
1961 save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
1962 save << " " << (int) _preCADProcess3DTopology << " " << (int) _preCADRemoveDuplicateCADFaces;
1963 save << " " << (int)_optimiseTinyEdges << " " << _tinyEdgeOptimisationLength;
1964 save << " " << (int)_correctSurfaceIntersec << " " << _corrSurfaceIntersCost;
1965 save << " " << (int)_useGradation << " " << (int)_useVolumeGradation << " " << _volumeGradation;
1967 op_val = _option2value.begin();
1968 if (op_val != _option2value.end()) {
1969 save << " " << "__OPTIONS_BEGIN__";
1970 for (; op_val != _option2value.end(); ++op_val) {
1971 if (!op_val->second.empty())
1972 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1974 save << " " << "__OPTIONS_END__";
1977 op_val = _customOption2value.begin();
1978 if (op_val != _customOption2value.end()) {
1979 save << " " << "__CUSTOM_OPTIONS_BEGIN__";
1980 for (; op_val != _customOption2value.end(); ++op_val) {
1981 if (!op_val->second.empty())
1982 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1984 save << " " << "__CUSTOM_OPTIONS_END__";
1987 op_val = _preCADoption2value.begin();
1988 if (op_val != _preCADoption2value.end()) {
1989 save << " " << "__PRECAD_OPTIONS_BEGIN__";
1990 for (; op_val != _preCADoption2value.end(); ++op_val) {
1991 if (!op_val->second.empty())
1992 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1994 save << " " << "__PRECAD_OPTIONS_END__";
1997 TSizeMap::iterator it_sm = _sizeMap.begin();
1998 if (it_sm != _sizeMap.end()) {
1999 save << " " << "__SIZEMAP_BEGIN__";
2000 for (; it_sm != _sizeMap.end(); ++it_sm) {
2001 save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
2003 save << " " << "__SIZEMAP_END__";
2006 TSizeMap::iterator it_at = _attractors.begin();
2007 if (it_at != _attractors.end()) {
2008 save << " " << "__ATTRACTORS_BEGIN__";
2009 for (; it_at != _attractors.end(); ++it_at) {
2010 save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
2012 save << " " << "__ATTRACTORS_END__";
2015 TAttractorMap::iterator it_At = _classAttractors.begin();
2016 if (it_At != _classAttractors.end()) {
2017 std::ostringstream test;
2018 save << " " << "__NEW_ATTRACTORS_BEGIN__";
2019 test << " " << "__NEW_ATTRACTORS_BEGIN__";
2020 for (; it_At != _classAttractors.end(); ++it_At) {
2021 std::vector<double> attParams;
2022 attParams = it_At->second->GetParameters();
2023 // double step = it_At->second->GetStep();
2024 save << " " << it_At->first;
2025 save << " " << it_At->second->GetAttractorEntry();
2026 save << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
2027 // save << " " << step;
2028 test << " " << it_At->first;
2029 test << " " << it_At->second->GetAttractorEntry();
2030 test << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
2031 // test << " " << step;
2033 save << " " << "__NEW_ATTRACTORS_END__";
2034 test << " " << "__NEW_ATTRACTORS_END__";
2037 TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
2038 if (it_enf != _enfVertexList.end()) {
2039 save << " " << "__ENFORCED_VERTICES_BEGIN__";
2040 for (; it_enf != _enfVertexList.end(); ++it_enf) {
2041 TEnfVertex *enfVertex = (*it_enf);
2042 save << " " << "__BEGIN_VERTEX__";
2043 if (!enfVertex->name.empty()) {
2044 save << " " << "__BEGIN_NAME__";
2045 save << " " << enfVertex->name;
2046 save << " " << "__END_NAME__";
2048 if (!enfVertex->geomEntry.empty()) {
2049 save << " " << "__BEGIN_ENTRY__";
2050 save << " " << enfVertex->geomEntry;
2051 save << " " << "__END_ENTRY__";
2053 if (!enfVertex->grpName.empty()) {
2054 save << " " << "__BEGIN_GROUP__";
2055 save << " " << enfVertex->grpName;
2056 save << " " << "__END_GROUP__";
2058 if (enfVertex->coords.size()) {
2059 save << " " << "__BEGIN_COORDS__";
2060 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
2061 save << " " << enfVertex->coords[i];
2062 save << " " << "__END_COORDS__";
2064 TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
2065 bool hasFaces = false;
2066 if (faceEntriesIt != enfVertex->faceEntries.end()) {
2068 save << " " << "__BEGIN_FACELIST__";
2070 for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
2071 if ( faceEntriesIt->empty() )
2072 save << " _no_face_";
2074 save << " " << (*faceEntriesIt);
2076 save << " " << "__END_FACELIST__";
2077 save << " " << "__END_VERTEX__";
2079 save << " " << "__ENFORCED_VERTICES_END__";
2084 SavePreCADPeriodicity(save, "FACES");
2085 SavePreCADPeriodicity(save, "EDGES");
2087 SaveFacesPeriodicity(save);
2088 SaveEdgesPeriodicity(save);
2089 SaveVerticesPeriodicity(save);
2092 save << " " << _hyperPatchList.size() << " ";
2093 for ( size_t i = 0; i < _hyperPatchList.size(); ++i )
2095 THyperPatchTags& patch = _hyperPatchList[i];
2096 save << patch.size() << " ";
2097 THyperPatchTags::iterator tag = patch.begin();
2098 for ( ; tag != patch.end(); ++tag )
2099 save << *tag << " ";
2105 void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
2107 TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
2108 if (it_faces_periodicity != _facesPeriodicityVector.end()) {
2109 save << " " << "__FACES_PERIODICITY_BEGIN__";
2110 for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
2111 TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
2112 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2113 save << " " << "__BEGIN_ENTRY1__";
2114 save << " " << periodicity_i.first;
2115 save << " " << "__END_ENTRY1__";
2116 save << " " << "__BEGIN_ENTRY2__";
2117 save << " " << periodicity_i.second;
2118 save << " " << "__END_ENTRY2__";
2119 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2121 save << " " << "__FACES_PERIODICITY_END__";
2125 void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
2127 TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
2128 if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
2129 save << " " << "__EDGES_PERIODICITY_BEGIN__";
2130 for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
2131 TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
2132 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2133 if (! periodicity_i.theFace1Entry.empty()){
2134 save << " " << "__BEGIN_FACE1__";
2135 save << " " << periodicity_i.theFace1Entry;
2136 save << " " << "__END_FACE1__";
2138 save << " " << "__BEGIN_EDGE1__";
2139 save << " " << periodicity_i.theEdge1Entry;
2140 save << " " << "__END_EDGE1__";
2141 if (! periodicity_i.theFace2Entry.empty()){
2142 save << " " << "__BEGIN_FACE2__";
2143 save << " " << periodicity_i.theFace2Entry;
2144 save << " " << "__END_FACE2__";
2146 save << " " << "__BEGIN_EDGE2__";
2147 save << " " << periodicity_i.theEdge2Entry;
2148 save << " " << "__END_EDGE2__";
2149 save << " " << "__BEGIN_EDGE_ORIENTATION__";
2150 save << " " << periodicity_i.edge_orientation;
2151 save << " " << "__END_EDGE_ORIENTATION__";
2152 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2154 save << " " << "__EDGES_PERIODICITY_END__";
2158 void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save){
2160 TVerticesPeriodicityVector::const_iterator it_vertices_periodicity = _verticesPeriodicityVector.begin();
2161 if (it_vertices_periodicity != _verticesPeriodicityVector.end()) {
2162 save << " " << "__VERTICES_PERIODICITY_BEGIN__";
2163 for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
2164 TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
2165 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2166 save << " " << "__BEGIN_EDGE1__";
2167 save << " " << periodicity_i.theEdge1Entry;
2168 save << " " << "__END_EDGE1__";
2169 save << " " << "__BEGIN_VERTEX1__";
2170 save << " " << periodicity_i.theVertex1Entry;
2171 save << " " << "__END_VERTEX1__";
2172 save << " " << "__BEGIN_EDGE2__";
2173 save << " " << periodicity_i.theEdge2Entry;
2174 save << " " << "__END_EDGE2__";
2175 save << " " << "__BEGIN_VERTEX2__";
2176 save << " " << periodicity_i.theVertex2Entry;
2177 save << " " << "__END_VERTEX2__";
2178 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2180 save << " " << "__VERTICES_PERIODICITY_END__";
2184 void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType) {
2185 TPreCadPeriodicityVector precad_periodicity;
2186 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
2187 precad_periodicity = _preCadFacesPeriodicityVector;
2189 precad_periodicity = _preCadEdgesPeriodicityVector;
2190 TPreCadPeriodicityVector::const_iterator it_precad_periodicity = precad_periodicity.begin();
2191 if (it_precad_periodicity != precad_periodicity.end()) {
2192 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_BEGIN__";
2193 for (; it_precad_periodicity != precad_periodicity.end(); ++it_precad_periodicity) {
2194 TPreCadPeriodicity periodicity_i = (*it_precad_periodicity);
2195 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2196 if (!periodicity_i.shape1Entry.empty()) {
2197 save << " " << "__BEGIN_ENTRY1__";
2198 save << " " << periodicity_i.shape1Entry;
2199 save << " " << "__END_ENTRY1__";
2201 if (!periodicity_i.shape2Entry.empty()) {
2202 save << " " << "__BEGIN_ENTRY2__";
2203 save << " " << periodicity_i.shape2Entry;
2204 save << " " << "__END_ENTRY2__";
2207 std::vector<std::string>::const_iterator sourceVerticesEntriesIt = periodicity_i.theSourceVerticesEntries.begin();
2208 bool hasSourceVertices = false;
2209 if (sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end()) {
2210 hasSourceVertices = true;
2211 save << " " << "__BEGIN_SOURCE_VERTICES_LIST__";
2213 for (; sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end(); ++sourceVerticesEntriesIt)
2214 save << " " << (*sourceVerticesEntriesIt);
2215 if (hasSourceVertices)
2216 save << " " << "__END_SOURCE_VERTICES_LIST__";
2218 std::vector<std::string>::const_iterator targetVerticesEntriesIt = periodicity_i.theTargetVerticesEntries.begin();
2219 bool hasTargetVertices = false;
2220 if (targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end()) {
2221 hasTargetVertices = true;
2222 save << " " << "__BEGIN_TARGET_VERTICES_LIST__";
2224 for (; targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end(); ++targetVerticesEntriesIt)
2225 save << " " << (*targetVerticesEntriesIt);
2226 if (hasTargetVertices)
2227 save << " " << "__END_TARGET_VERTICES_LIST__";
2229 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2231 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_END__";
2236 //=============================================================================
2237 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
2242 std::string option_or_sm;
2244 isOK = static_cast<bool>(load >> i);
2246 _topology = (Topology) i;
2248 load.clear(std::ios::badbit | load.rdstate());
2250 isOK = static_cast<bool>(load >> i);
2252 _physicalMesh = (PhysicalMesh) i;
2254 load.clear(std::ios::badbit | load.rdstate());
2256 isOK = static_cast<bool>(load >> i);
2258 _geometricMesh = (GeometricMesh) i;
2260 load.clear(std::ios::badbit | load.rdstate());
2262 isOK = static_cast<bool>(load >> val);
2266 load.clear(std::ios::badbit | load.rdstate());
2268 isOK = static_cast<bool>(load >> val);
2272 load.clear(std::ios::badbit | load.rdstate());
2274 isOK = static_cast<bool>(load >> val);
2278 load.clear(std::ios::badbit | load.rdstate());
2280 isOK = static_cast<bool>(load >> i);
2282 _elementType = (ElementType) i;
2284 load.clear(std::ios::badbit | load.rdstate());
2286 isOK = static_cast<bool>(load >> i);
2288 if ( i != -1) { // if value is -1, then this is no longer a standard option
2289 std::string & value = _option2value["respect_geometry"];
2290 bool _decimesh = (bool) i;
2291 value = _decimesh ? "1" : "0";
2295 load.clear(std::ios::badbit | load.rdstate());
2297 isOK = static_cast<bool>(load >> val);
2301 load.clear(std::ios::badbit | load.rdstate());
2303 isOK = static_cast<bool>(load >> val);
2307 load.clear(std::ios::badbit | load.rdstate());
2309 isOK = static_cast<bool>(load >> val);
2311 // former parameter: get min value
2312 _angleMesh = std::min(val,_angleMesh);
2314 load.clear(std::ios::badbit | load.rdstate());
2316 isOK = static_cast<bool>(load >> val);
2318 // former parameter: get min value
2319 _minSize = std::min(val,_minSize);
2321 load.clear(std::ios::badbit | load.rdstate());
2323 isOK = static_cast<bool>(load >> val);
2325 // former parameter: get max value
2326 _maxSize = std::max(val,_maxSize);
2328 load.clear(std::ios::badbit | load.rdstate());
2330 isOK = static_cast<bool>(load >> i);
2334 load.clear(std::ios::badbit | load.rdstate());
2336 isOK = static_cast<bool>(load >> i);
2338 _preCADMergeEdges = (bool) i;
2340 load.clear(std::ios::badbit | load.rdstate());
2342 isOK = static_cast<bool>(load >> i);
2344 if ( i != -1) { // if value is -1, then this is no longer a standard option
2345 std::string & value = _preCADoption2value["remove_tiny_edges"];
2346 bool _preCADRemoveNanoEdges = (bool) i;
2347 value = _preCADRemoveNanoEdges ? "1" : "0";
2351 load.clear(std::ios::badbit | load.rdstate());
2353 isOK = static_cast<bool>(load >> i);
2355 _preCADDiscardInput = (bool) i;
2357 load.clear(std::ios::badbit | load.rdstate());
2359 isOK = static_cast<bool>(load >> val);
2360 if (isOK) { // _preCADEpsNano
2361 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
2362 std::string & value = _preCADoption2value["tiny_edge_length"];
2363 std::ostringstream oss;
2369 load.clear(std::ios::badbit | load.rdstate());
2371 isOK = static_cast<bool>(load >> i);
2373 _enforcedInternalVerticesAllFaces = (bool) i;
2375 load.clear(std::ios::badbit | load.rdstate());
2377 // New options with MeshGems-CADSurf
2379 bool hasCADSurfOptions = false;
2380 bool hasOptions = false;
2381 bool hasCustomOptions = false;
2382 bool hasPreCADOptions = false;
2383 bool hasSizeMap = false;
2384 bool hasAttractor = false;
2385 bool hasNewAttractor = false;
2386 bool hasEnforcedVertex = false;
2387 bool hasPreCADFacesPeriodicity = false;
2388 bool hasPreCADEdgesPeriodicity = false;
2389 bool hasFacesPeriodicity = false;
2390 bool hasEdgesPeriodicity = false;
2391 bool hasVerticesPeriodicity = false;
2393 isOK = static_cast<bool>(load >> option_or_sm);
2395 if ( (option_or_sm == "1")||(option_or_sm == "0") ) {
2396 i = atoi(option_or_sm.c_str());
2397 hasCADSurfOptions = true;
2398 _phySizeRel = (bool) i;
2400 if (option_or_sm == "__OPTIONS_BEGIN__")
2402 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2403 hasCustomOptions = true;
2404 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2405 hasPreCADOptions = true;
2406 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2408 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2409 hasAttractor = true;
2410 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2411 hasNewAttractor = true;
2412 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2413 hasEnforcedVertex = true;
2414 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2415 hasPreCADFacesPeriodicity = true;
2416 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2417 hasPreCADEdgesPeriodicity = true;
2418 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2419 hasFacesPeriodicity = true;
2420 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2421 hasEdgesPeriodicity = true;
2422 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2423 hasVerticesPeriodicity = true;
2425 if (isOK && hasCADSurfOptions) {
2426 isOK = static_cast<bool>(load >> i);
2428 _minSizeRel = (bool) i;
2430 load.clear(std::ios::badbit | load.rdstate());
2432 isOK = static_cast<bool>(load >> i);
2434 _maxSizeRel = (bool) i;
2436 load.clear(std::ios::badbit | load.rdstate());
2438 isOK = static_cast<bool>(load >> val);
2440 _chordalError = val;
2442 load.clear(std::ios::badbit | load.rdstate());
2444 isOK = static_cast<bool>(load >> i);
2446 _anisotropic = (bool) i;
2448 load.clear(std::ios::badbit | load.rdstate());
2450 isOK = static_cast<bool>(load >> val);
2452 _anisotropicRatio = val;
2454 load.clear(std::ios::badbit | load.rdstate());
2456 isOK = static_cast<bool>(load >> i);
2458 _removeTinyEdges = (bool) i;
2460 load.clear(std::ios::badbit | load.rdstate());
2462 isOK = static_cast<bool>(load >> val);
2464 _tinyEdgeLength = val;
2466 load.clear(std::ios::badbit | load.rdstate());
2468 isOK = static_cast<bool>(load >> i);
2470 _badElementRemoval = (bool) i;
2472 load.clear(std::ios::badbit | load.rdstate());
2474 isOK = static_cast<bool>(load >> val);
2476 _badElementAspectRatio = val;
2478 load.clear(std::ios::badbit | load.rdstate());
2480 isOK = static_cast<bool>(load >> i);
2482 _optimizeMesh = (bool) i;
2484 load.clear(std::ios::badbit | load.rdstate());
2486 isOK = static_cast<bool>(load >> i);
2488 _quadraticMesh = (bool) i;
2490 load.clear(std::ios::badbit | load.rdstate());
2492 isOK = static_cast<bool>(load >> i);
2494 _preCADProcess3DTopology = (bool) i;
2496 load.clear(std::ios::badbit | load.rdstate());
2498 if (( load >> std::ws).peek() != '_' )
2500 isOK = static_cast<bool>(load >> i);
2502 _preCADRemoveDuplicateCADFaces = (bool) i;
2504 load.clear(std::ios::badbit | load.rdstate());
2506 isOK = static_cast<bool>(load >> i);
2508 _optimiseTinyEdges = (bool) i;
2510 load.clear(std::ios::badbit | load.rdstate());
2512 isOK = static_cast<bool>(load >> val);
2514 _tinyEdgeOptimisationLength = val;
2516 load.clear(std::ios::badbit | load.rdstate());
2518 isOK = static_cast<bool>(load >> i);
2520 _correctSurfaceIntersec = (bool) i;
2522 load.clear(std::ios::badbit | load.rdstate());
2524 isOK = static_cast<bool>(load >> val);
2526 _corrSurfaceIntersCost = val;
2528 load.clear(std::ios::badbit | load.rdstate());
2530 isOK = static_cast<bool>(load >> i);
2532 _useGradation = (bool) i;
2534 load.clear(std::ios::badbit | load.rdstate());
2536 isOK = static_cast<bool>(load >> i);
2538 _useVolumeGradation = (bool) i;
2540 load.clear(std::ios::badbit | load.rdstate());
2542 isOK = static_cast<bool>(load >> val);
2544 _volumeGradation = val;
2546 load.clear(std::ios::badbit | load.rdstate());
2551 if (hasCADSurfOptions) {
2552 isOK = static_cast<bool>(load >> option_or_sm);
2554 if (option_or_sm == "__OPTIONS_BEGIN__")
2556 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2557 hasCustomOptions = true;
2558 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2559 hasPreCADOptions = true;
2560 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2562 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2563 hasAttractor = true;
2564 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2565 hasNewAttractor = true;
2566 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2567 hasEnforcedVertex = true;
2568 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2569 hasPreCADFacesPeriodicity = true;
2570 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2571 hasPreCADEdgesPeriodicity = true;
2572 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2573 hasFacesPeriodicity = true;
2574 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2575 hasEdgesPeriodicity = true;
2576 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2577 hasVerticesPeriodicity = true;
2581 std::string optName, optValue;
2582 while (isOK && hasOptions) {
2583 isOK = static_cast<bool>(load >> optName);
2585 if (optName == "__OPTIONS_END__")
2587 isOK = static_cast<bool>(load >> optValue);
2590 std::string & value = _option2value[optName];
2592 int len = value.size();
2593 // continue reading until "%#" encountered
2594 while (value[len - 1] != '#' || value[len - 2] != '%') {
2595 isOK = static_cast<bool>(load >> optValue);
2604 if ( value[ len - 1] == '#' )
2605 value.resize(len - 2); //cut off "%#"
2610 isOK = static_cast<bool>(load >> option_or_sm);
2612 if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2613 hasCustomOptions = true;
2614 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2615 hasPreCADOptions = true;
2616 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2618 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2619 hasAttractor = true;
2620 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2621 hasNewAttractor = true;
2622 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2623 hasEnforcedVertex = true;
2624 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2625 hasPreCADFacesPeriodicity = true;
2626 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2627 hasPreCADEdgesPeriodicity = true;
2628 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2629 hasFacesPeriodicity = true;
2630 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2631 hasEdgesPeriodicity = true;
2632 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2633 hasVerticesPeriodicity = true;
2637 while (isOK && hasCustomOptions) {
2638 isOK = static_cast<bool>(load >> optName);
2640 if (optName == "__CUSTOM_OPTIONS_END__")
2642 isOK = static_cast<bool>(load >> optValue);
2645 std::string& value = optValue;
2646 int len = value.size();
2647 // continue reading until "%#" encountered
2648 while (value[len - 1] != '#' || value[len - 2] != '%') {
2649 isOK = static_cast<bool>(load >> optValue);
2658 if ( value[ len - 1] == '#' )
2659 value.resize(len - 2); //cut off "%#"
2660 _customOption2value[optName] = value;
2664 if (hasCustomOptions) {
2665 isOK = static_cast<bool>(load >> option_or_sm);
2667 if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2668 hasPreCADOptions = true;
2669 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2671 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2672 hasAttractor = true;
2673 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2674 hasNewAttractor = true;
2675 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2676 hasEnforcedVertex = true;
2677 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2678 hasPreCADFacesPeriodicity = true;
2679 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2680 hasPreCADEdgesPeriodicity = true;
2681 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2682 hasFacesPeriodicity = true;
2683 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2684 hasEdgesPeriodicity = true;
2685 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2686 hasVerticesPeriodicity = true;
2690 while (isOK && hasPreCADOptions) {
2691 isOK = static_cast<bool>(load >> optName);
2693 if (optName == "__PRECAD_OPTIONS_END__")
2695 isOK = static_cast<bool>(load >> optValue);
2698 std::string & value = _preCADoption2value[optName];
2700 int len = value.size();
2701 // continue reading until "%#" encountered
2702 while (value[len - 1] != '#' || value[len - 2] != '%') {
2703 isOK = static_cast<bool>(load >> optValue);
2712 if ( value[ len - 1] == '#' )
2713 value.resize(len - 2); //cut off "%#"
2717 if (hasPreCADOptions) {
2718 isOK = static_cast<bool>(load >> option_or_sm);
2720 if (option_or_sm == "__SIZEMAP_BEGIN__")
2722 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2723 hasAttractor = true;
2724 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2725 hasNewAttractor = true;
2726 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2727 hasEnforcedVertex = true;
2728 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2729 hasPreCADFacesPeriodicity = true;
2730 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2731 hasPreCADEdgesPeriodicity = true;
2732 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2733 hasFacesPeriodicity = true;
2734 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2735 hasEdgesPeriodicity = true;
2736 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2737 hasVerticesPeriodicity = true;
2741 std::string smEntry, smValue;
2742 while (isOK && hasSizeMap) {
2743 isOK = static_cast<bool>(load >> smEntry);
2745 if (smEntry == "__SIZEMAP_END__")
2747 isOK = static_cast<bool>(load >> smValue);
2750 std::string & value2 = _sizeMap[smEntry];
2752 int len2 = value2.size();
2753 // continue reading until "%#" encountered
2754 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2755 isOK = static_cast<bool>(load >> smValue);
2759 len2 = value2.size();
2764 value2.resize(len2 - 2); //cut off "%#"
2769 isOK = static_cast<bool>(load >> option_or_sm);
2771 if (option_or_sm == "__ATTRACTORS_BEGIN__")
2772 hasAttractor = true;
2773 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2774 hasNewAttractor = true;
2775 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2776 hasEnforcedVertex = true;
2777 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2778 hasPreCADFacesPeriodicity = true;
2779 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2780 hasPreCADEdgesPeriodicity = true;
2781 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2782 hasFacesPeriodicity = true;
2783 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2784 hasEdgesPeriodicity = true;
2785 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2786 hasVerticesPeriodicity = true;
2789 std::string atEntry, atValue;
2790 while (isOK && hasAttractor) {
2791 isOK = static_cast<bool>(load >> atEntry);
2793 if (atEntry == "__ATTRACTORS_END__")
2795 isOK = static_cast<bool>(load >> atValue);
2798 std::string & value3 = _attractors[atEntry];
2800 int len3 = value3.size();
2801 // continue reading until "%#" encountered
2802 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
2803 isOK = static_cast<bool>(load >> atValue);
2807 len3 = value3.size();
2812 value3.resize(len3 - 2); //cut off "%#"
2817 isOK = static_cast<bool>(load >> option_or_sm);
2819 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2820 hasNewAttractor = true;
2821 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2822 hasEnforcedVertex = true;
2823 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2824 hasPreCADFacesPeriodicity = true;
2825 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2826 hasPreCADEdgesPeriodicity = true;
2827 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2828 hasFacesPeriodicity = true;
2829 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2830 hasEdgesPeriodicity = true;
2831 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2832 hasVerticesPeriodicity = true;
2836 std::string newAtFaceEntry, atTestString;
2837 std::string newAtShapeEntry;
2838 double attParams[4];
2840 while (isOK && hasNewAttractor) {
2841 //std::cout<<"Load new attractor"<<std::endl;
2842 isOK = static_cast<bool>(load >> newAtFaceEntry);
2844 if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
2846 isOK = static_cast<bool>(load >> newAtShapeEntry);
2849 isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
2852 const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
2853 const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
2854 BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
2855 attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
2856 //attractor->BuildMap();
2857 _classAttractors.insert( make_pair( newAtFaceEntry, attractor ));
2862 if (hasNewAttractor) {
2863 isOK = static_cast<bool>(load >> option_or_sm);
2865 if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2866 hasEnforcedVertex = true;
2867 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2868 hasPreCADFacesPeriodicity = true;
2869 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2870 hasPreCADEdgesPeriodicity = true;
2871 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2872 hasFacesPeriodicity = true;
2873 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2874 hasEdgesPeriodicity = true;
2875 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2876 hasVerticesPeriodicity = true;
2882 // Here is a example of the saved stream:
2883 // __ENFORCED_VERTICES_BEGIN__
2884 // __BEGIN_VERTEX__ => no name, no entry
2885 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2886 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__
2887 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__
2889 // __BEGIN_VERTEX__ => no coords
2890 // __BEGIN_NAME__ mes points __END_NAME__
2891 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
2892 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2893 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
2895 // __ENFORCED_VERTICES_END__
2898 std::string enfSeparator;
2899 std::string enfName;
2900 std::string enfGeomEntry;
2901 std::string enfGroup;
2902 TEntryList enfFaceEntryList;
2903 double enfCoords[3];
2904 bool hasCoords = false;
2906 _faceEntryEnfVertexListMap.clear();
2907 _enfVertexList.clear();
2908 _faceEntryCoordsListMap.clear();
2909 _coordsEnfVertexMap.clear();
2910 _faceEntryEnfVertexEntryListMap.clear();
2911 _enfVertexEntryEnfVertexMap.clear();
2914 while (isOK && hasEnforcedVertex)
2916 isOK = static_cast<bool>(load >> enfSeparator); // __BEGIN_VERTEX__
2917 TEnfVertex *enfVertex = new TEnfVertex();
2918 if (enfSeparator == "__ENFORCED_VERTICES_END__")
2919 break; // __ENFORCED_VERTICES_END__
2920 if (enfSeparator != "__BEGIN_VERTEX__")
2921 throw std::exception();
2924 isOK = static_cast<bool>(load >> enfSeparator);
2925 if (enfSeparator == "__END_VERTEX__") {
2927 enfVertex->name = enfName;
2928 enfVertex->geomEntry = enfGeomEntry;
2929 enfVertex->grpName = enfGroup;
2930 enfVertex->coords.clear();
2932 enfVertex->coords.assign(enfCoords,enfCoords+3);
2933 enfVertex->faceEntries = enfFaceEntryList;
2935 _enfVertexList.insert(enfVertex);
2937 if (enfVertex->coords.size()) {
2938 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
2939 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2940 _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
2941 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2944 if (!enfVertex->geomEntry.empty()) {
2945 _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
2946 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2947 _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
2948 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2953 enfGeomEntry.clear();
2955 enfFaceEntryList.clear();
2957 break; // __END_VERTEX__
2960 if (enfSeparator == "__BEGIN_NAME__") { // __BEGIN_NAME__
2961 while (isOK && (enfSeparator != "__END_NAME__")) {
2962 isOK = static_cast<bool>(load >> enfSeparator);
2963 if (enfSeparator != "__END_NAME__") {
2964 if (!enfName.empty())
2966 enfName += enfSeparator;
2971 if (enfSeparator == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
2972 isOK = static_cast<bool>(load >> enfGeomEntry);
2973 isOK = static_cast<bool>(load >> enfSeparator); // __END_ENTRY__
2974 if (enfSeparator != "__END_ENTRY__")
2975 throw std::exception();
2978 if (enfSeparator == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
2979 while (isOK && (enfSeparator != "__END_GROUP__")) {
2980 isOK = static_cast<bool>(load >> enfSeparator);
2981 if (enfSeparator != "__END_GROUP__") {
2982 if (!enfGroup.empty())
2984 enfGroup += enfSeparator;
2989 if (enfSeparator == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
2991 isOK = static_cast<bool>(load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
2992 isOK = static_cast<bool>(load >> enfSeparator); // __END_COORDS__
2993 if (enfSeparator != "__END_COORDS__")
2994 throw std::exception();
2997 if (enfSeparator == "__BEGIN_FACELIST__") { // __BEGIN_FACELIST__
2998 while (isOK && (enfSeparator != "__END_FACELIST__")) {
2999 isOK = static_cast<bool>(load >> enfSeparator);
3000 if (enfSeparator != "__END_FACELIST__") {
3001 enfFaceEntryList.insert(enfSeparator);
3008 if ( hasEnforcedVertex ) {
3009 isOK = static_cast<bool>(load >> option_or_sm);
3011 if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
3012 hasPreCADFacesPeriodicity = true;
3013 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
3014 hasPreCADEdgesPeriodicity = true;
3015 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
3016 hasFacesPeriodicity = true;
3017 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3018 hasEdgesPeriodicity = true;
3019 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3020 hasVerticesPeriodicity = true;
3026 if (hasPreCADFacesPeriodicity)
3028 LoadPreCADPeriodicity(load, "FACES");
3030 isOK = static_cast<bool>(load >> option_or_sm);
3032 if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
3033 hasPreCADEdgesPeriodicity = true;
3034 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
3035 hasFacesPeriodicity = true;
3036 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3037 hasEdgesPeriodicity = true;
3038 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3039 hasVerticesPeriodicity = true;
3043 if (hasPreCADEdgesPeriodicity)
3045 LoadPreCADPeriodicity(load, "EDGES");
3047 isOK = static_cast<bool>(load >> option_or_sm);
3049 if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
3050 hasFacesPeriodicity = true;
3051 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3052 hasEdgesPeriodicity = true;
3053 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3054 hasVerticesPeriodicity = true;
3058 if (hasFacesPeriodicity)
3060 LoadFacesPeriodicity(load);
3062 isOK = static_cast<bool>(load >> option_or_sm);
3064 if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
3065 hasEdgesPeriodicity = true;
3066 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3067 hasVerticesPeriodicity = true;
3071 if (hasEdgesPeriodicity)
3073 LoadEdgesPeriodicity(load);
3075 isOK = static_cast<bool>(load >> option_or_sm);
3077 if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
3078 hasVerticesPeriodicity = true;
3081 if (hasVerticesPeriodicity)
3082 LoadVerticesPeriodicity(load);
3085 if ( !option_or_sm.empty() && option_or_sm[0] == '_' )
3086 isOK = static_cast<bool>(load >> option_or_sm);
3087 if ( isOK && !option_or_sm.empty() )
3089 int nbPatches = atoi( option_or_sm.c_str() );
3090 if ( nbPatches >= 0 )
3092 _hyperPatchList.resize( nbPatches );
3093 for ( int iP = 0; iP < nbPatches && isOK; ++iP )
3095 isOK = static_cast<bool>(load >> i) && i >= 2;
3098 for ( int iT = 0; iT < nbTags; ++iT )
3100 if (( isOK = static_cast<bool>(load >> i)))
3101 _hyperPatchList[ iP ].insert( i );
3106 if ( !isOK ) // remove invalid patches
3108 for ( i = nbPatches - 1; i >= 0; i-- )
3109 if ( _hyperPatchList[i].size() < 2 )
3110 _hyperPatchList.resize( i );
3118 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
3122 std::string periodicitySeparator;
3126 _facesPeriodicityVector.clear();
3129 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3130 TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
3131 if (periodicitySeparator == "__FACES_PERIODICITY_END__")
3132 break; // __FACES_PERIODICITY_END__
3133 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3134 throw std::exception();
3138 isOK = static_cast<bool>(load >> periodicitySeparator);
3139 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3141 periodicity_i->first = shape1Entry;
3142 periodicity_i->second = shape2Entry;
3144 _facesPeriodicityVector.push_back(*periodicity_i);
3146 break; // __END_PERIODICITY_DESCRIPTION__
3149 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3150 isOK = static_cast<bool>(load >> shape1Entry);
3151 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3152 if (periodicitySeparator != "__END_ENTRY1__")
3153 throw std::exception();
3156 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3157 isOK = static_cast<bool>(load >> shape2Entry);
3158 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3159 if (periodicitySeparator != "__END_ENTRY2__")
3160 throw std::exception();
3167 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
3171 std::string periodicitySeparator;
3172 TEntry theFace1Entry;
3173 TEntry theEdge1Entry;
3174 TEntry theFace2Entry;
3175 TEntry theEdge2Entry;
3176 int edge_orientation = 0;
3178 _edgesPeriodicityVector.clear();
3181 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3182 TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
3183 if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
3184 break; // __EDGES_PERIODICITY_END__
3185 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3186 throw std::exception();
3190 isOK = static_cast<bool>(load >> periodicitySeparator);
3191 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3193 periodicity_i->theFace1Entry = theFace1Entry;
3194 periodicity_i->theEdge1Entry = theEdge1Entry;
3195 periodicity_i->theFace2Entry = theFace2Entry;
3196 periodicity_i->theEdge2Entry = theEdge2Entry;
3197 periodicity_i->edge_orientation = edge_orientation;
3199 _edgesPeriodicityVector.push_back(*periodicity_i);
3201 break; // __END_PERIODICITY_DESCRIPTION__
3204 if (periodicitySeparator == "__BEGIN_FACE1__") { // __BEGIN_FACE1__
3205 isOK = static_cast<bool>(load >> theFace1Entry);
3206 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE1__
3207 if (periodicitySeparator != "__END_FACE1__"){
3208 throw std::exception();
3212 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3213 isOK = static_cast<bool>(load >> theEdge1Entry);
3214 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3215 if (periodicitySeparator != "__END_EDGE1__")
3216 throw std::exception();
3219 if (periodicitySeparator == "__BEGIN_FACE2__") { // __BEGIN_FACE2__
3220 isOK = static_cast<bool>(load >> theFace2Entry);
3221 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE2__
3222 if (periodicitySeparator != "__END_FACE2__")
3223 throw std::exception();
3226 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3227 isOK = static_cast<bool>(load >> theEdge2Entry);
3228 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3229 if (periodicitySeparator != "__END_EDGE2__")
3230 throw std::exception();
3233 if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") { // __BEGIN_EDGE_ORIENTATION__
3234 isOK = static_cast<bool>(load >> edge_orientation);
3235 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
3236 if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
3237 throw std::exception();
3243 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load)
3247 std::string periodicitySeparator;
3248 TEntry theEdge1Entry;
3249 TEntry theVertex1Entry;
3250 TEntry theEdge2Entry;
3251 TEntry theVertex2Entry;
3253 _verticesPeriodicityVector.clear();
3256 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3257 TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
3258 if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
3259 break; // __VERTICES_PERIODICITY_END__
3260 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3261 throw std::exception();
3265 isOK = static_cast<bool>(load >> periodicitySeparator);
3266 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3268 periodicity_i->theEdge1Entry = theEdge1Entry;
3269 periodicity_i->theVertex1Entry = theVertex1Entry;
3270 periodicity_i->theEdge2Entry = theEdge2Entry;
3271 periodicity_i->theVertex2Entry = theVertex2Entry;
3273 _verticesPeriodicityVector.push_back(*periodicity_i);
3275 break; // __END_PERIODICITY_DESCRIPTION__
3278 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3279 isOK = static_cast<bool>(load >> theEdge1Entry);
3280 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3281 if (periodicitySeparator != "__END_EDGE1__")
3282 throw std::exception();
3285 if (periodicitySeparator == "__BEGIN_VERTEX1__") { // __BEGIN_VERTEX1__
3286 isOK = static_cast<bool>(load >> theVertex1Entry);
3287 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX1__
3288 if (periodicitySeparator != "__END_VERTEX1__")
3289 throw std::exception();
3292 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3293 isOK = static_cast<bool>(load >> theEdge2Entry);
3294 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3295 if (periodicitySeparator != "__END_EDGE2__")
3296 throw std::exception();
3299 if (periodicitySeparator == "__BEGIN_VERTEX2__") { // __BEGIN_VERTEX2__
3300 isOK = static_cast<bool>(load >> theVertex2Entry);
3301 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX2__
3302 if (periodicitySeparator != "__END_VERTEX2__")
3303 throw std::exception();
3309 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
3313 std::string periodicitySeparator;
3316 std::vector<std::string> theSourceVerticesEntries;
3317 std::vector<std::string> theTargetVerticesEntries;
3319 bool hasSourceVertices = false;
3320 bool hasTargetVertices = false;
3322 if ( shapeType && strcmp( shapeType, "FACES") == 0 )
3323 _preCadFacesPeriodicityVector.clear();
3325 _preCadEdgesPeriodicityVector.clear();
3329 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3330 TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
3331 std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
3332 if (periodicitySeparator == endSeparator)
3333 break; // __PRECAD_FACES_PERIODICITY_END__
3334 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3335 throw std::exception();
3339 isOK = static_cast<bool>(load >> periodicitySeparator);
3340 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3342 periodicity_i->shape1Entry = shape1Entry;
3343 periodicity_i->shape2Entry = shape2Entry;
3345 if (hasSourceVertices)
3346 periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
3347 if (hasTargetVertices)
3348 periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
3350 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
3351 _preCadFacesPeriodicityVector.push_back(*periodicity_i);
3353 _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
3355 theSourceVerticesEntries.clear();
3356 theTargetVerticesEntries.clear();
3357 hasSourceVertices = false;
3358 hasTargetVertices = false;
3359 break; // __END_PERIODICITY_DESCRIPTION__
3362 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3363 isOK = static_cast<bool>(load >> shape1Entry);
3364 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3365 if (periodicitySeparator != "__END_ENTRY1__")
3366 throw std::exception();
3369 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3370 isOK = static_cast<bool>(load >> shape2Entry);
3371 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3372 if (periodicitySeparator != "__END_ENTRY2__")
3373 throw std::exception();
3376 if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") { // __BEGIN_SOURCE_VERTICES_LIST__
3377 hasSourceVertices = true;
3378 while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
3379 isOK = static_cast<bool>(load >> periodicitySeparator);
3380 if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
3381 theSourceVerticesEntries.push_back(periodicitySeparator);
3386 if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") { // __BEGIN_TARGET_VERTICES_LIST__
3387 hasTargetVertices = true;
3388 while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
3389 isOK = static_cast<bool>(load >> periodicitySeparator);
3390 if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
3391 theTargetVerticesEntries.push_back(periodicitySeparator);
3399 //=============================================================================
3400 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
3401 return hyp.SaveTo(save);
3404 //=============================================================================
3405 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
3406 return hyp.LoadFrom(load);
3409 //================================================================================
3411 * \brief Does nothing
3413 //================================================================================
3415 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
3419 //================================================================================
3421 * \brief Returns default global constant physical size given a default value of element length ratio
3423 //================================================================================
3425 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
3426 if (bbSegmentation != 0 && diagonal != 0)
3427 return diagonal / bbSegmentation ;
3431 //================================================================================
3433 * \brief Returns default min size given a default value of element length ratio
3435 //================================================================================
3437 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
3439 return diagonal / 1000.0 ;
3440 return undefinedDouble();
3443 //================================================================================
3445 * \brief Returns default max size given a default value of element length ratio
3447 //================================================================================
3449 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
3451 return diagonal / 5.0 ;
3452 return undefinedDouble();
3455 //================================================================================
3457 * \brief Returns default chordal error given a default value of element length ratio
3459 //================================================================================
3461 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
3464 return undefinedDouble();
3467 //================================================================================
3469 * \brief Returns default tiny edge length given a default value of element length ratio
3471 //================================================================================
3473 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
3475 return diagonal * 1e-6 ;
3476 return undefinedDouble();
3479 //================================================================================
3481 * \brief Returns default tiny edge optimisation length given a default value of element length ratio
3483 //================================================================================
3485 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal) {
3487 return diagonal * 1e-6 ;
3488 return undefinedDouble();
3491 //=============================================================================
3493 * \brief Initialize my parameter values by default parameters.
3494 * \retval bool - true if parameter values have been successfully defined
3496 //=============================================================================
3498 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
3499 double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
3500 _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
3501 _minSize = GetDefaultMinSize(diagonal);
3502 _maxSize = GetDefaultMaxSize(diagonal);
3503 _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
3504 _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
3505 _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(diagonal);
3510 //================================================================================
3512 * \brief Converts a string to a bool
3514 //================================================================================
3516 bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
3517 throw (std::invalid_argument)
3519 std::string s = str;
3520 if ( isOk ) *isOk = true;
3522 for ( size_t i = 0; i <= s.size(); ++i )
3523 s[i] = tolower( s[i] );
3525 if ( s == "1" || s == "true" || s == "active" || s == "yes" )
3528 if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
3534 std::string msg = "Not a Boolean value:'" + str + "'";
3535 throw std::invalid_argument(msg);
3540 //================================================================================
3542 * \brief Converts a string to a real value
3544 //================================================================================
3546 double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
3547 throw (std::invalid_argument)
3549 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3552 double val = strtod(&str[0], &endPtr);
3553 bool ok = (&str[0] != endPtr);
3555 if ( isOk ) *isOk = ok;
3559 std::string msg = "Not a real value:'" + str + "'";
3560 throw std::invalid_argument(msg);
3565 //================================================================================
3567 * \brief Converts a string to a integer value
3569 //================================================================================
3571 int BLSURFPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
3572 throw (std::invalid_argument)
3574 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3577 int val = (int)strtol( &str[0], &endPtr, 10);
3578 bool ok = (&str[0] != endPtr);
3580 if ( isOk ) *isOk = ok;
3584 std::string msg = "Not an integer value:'" + str + "'";
3585 throw std::invalid_argument(msg);