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) :
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 _quadAllowed(GetDefaultQuadAllowed()),
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 _preCADRemoveTinyUVEdges(GetDefaultPreCADRemoveTinyUVEdges()),
85 _preCADRemoveDuplicateCADFaces(GetDefaultPreCADRemoveDuplicateCADFaces()),
86 _preCADProcess3DTopology(GetDefaultPreCADProcess3DTopology()),
87 _preCADDiscardInput(GetDefaultPreCADDiscardInput()),
88 _sizeMap(GetDefaultSizeMap()),
89 _attractors(GetDefaultSizeMap()),
90 _classAttractors(GetDefaultAttractorMap()),
91 _faceEntryEnfVertexListMap(GetDefaultFaceEntryEnfVertexListMap()),
92 _enfVertexList(GetDefaultEnfVertexList()),
93 _faceEntryCoordsListMap(GetDefaultFaceEntryCoordsListMap()),
94 _coordsEnfVertexMap(GetDefaultCoordsEnfVertexMap()),
95 _faceEntryEnfVertexEntryListMap(GetDefaultFaceEntryEnfVertexEntryListMap()),
96 _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
97 _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap()),
98 _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex()),
99 _preCadFacesPeriodicityVector(GetDefaultPreCadFacesPeriodicityVector()),
100 _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector()),
101 _GMFFileName(GetDefaultGMFFile())
103 _name = GetHypType();
106 // _GMFFileMode = false; // GMF ascii mode
108 // Advanced options with their defaults according to MG User Manual
110 const char* boolOptionNames[] = { "enforce_cad_edge_sizes", // default = 0
111 // "correct_surface_intersections", // default = 1
112 // "create_tag_on_collision", // default = 1
113 "jacobian_rectification_respect_geometry", // default = 1
114 "rectify_jacobian", // default = 1
115 "respect_geometry", // default = 1
116 // "optimise_tiny_edges", // default = 0
117 // "remove_duplicate_cad_faces", // default = 1
118 "tiny_edge_avoid_surface_intersections", // default = 1
119 // "tiny_edge_respect_geometry", // default = 0
123 const char* intOptionNames[] = { "max_number_of_points_per_patch", // default = 100000
126 const char* doubleOptionNames[] = { // "surface_intersections_processing_max_cost",// default = 15
127 // "periodic_tolerance", // default = diag/100
128 // "volume_gradation",
129 // "tiny_edge_optimisation_length", // default = diag * 1e-6
132 const char* charOptionNames[] = { // "required_entities", // default = "respect"
133 // "tags", // default = "respect"
137 // PreCAD advanced options
138 const char* preCADboolOptionNames[] = { "closed_geometry", // default = 0
139 "discard_input_topology", // default = 0
140 "merge_edges", // default = = 1
141 "remove_duplicate_cad_faces", // default = 1
142 // "create_tag_on_collision", // default = 1
143 "debug", // default = 0
144 "process_3d_topology", // default = 1
145 // "remove_tiny_edges", // default = 0
148 const char* preCADintOptionNames[] = { // "manifold_geometry", // default = 0
151 const char* preCADdoubleOptionNames[] = { "periodic_tolerance", // default = diag * 1e-5
152 "sewing_tolerance", // default = diag * 5e-4
153 // "tiny_edge_length", // default = diag * 1e-5
156 const char* preCADcharOptionNames[] = { "required_entities", // default = "respect"
157 "tags", // default = "respect"
162 while (boolOptionNames[i][0])
164 _boolOptions.insert( boolOptionNames[i] );
165 _option2value[boolOptionNames[i++]].clear();
168 while (preCADboolOptionNames[i][0])
170 _boolOptions.insert( preCADboolOptionNames[i] );
171 _preCADoption2value[preCADboolOptionNames[i++]].clear();
174 while (intOptionNames[i][0])
175 _option2value[intOptionNames[i++]].clear();
178 while (preCADintOptionNames[i][0])
179 _preCADoption2value[preCADintOptionNames[i++]].clear();
182 while (doubleOptionNames[i][0]) {
183 _doubleOptions.insert(doubleOptionNames[i]);
184 _option2value[doubleOptionNames[i++]].clear();
187 while (preCADdoubleOptionNames[i][0]) {
188 _preCADdoubleOptions.insert(preCADdoubleOptionNames[i]);
189 _preCADoption2value[preCADdoubleOptionNames[i++]].clear();
192 while (charOptionNames[i][0]) {
193 _charOptions.insert(charOptionNames[i]);
194 _option2value[charOptionNames[i++]].clear();
197 while (preCADcharOptionNames[i][0]) {
198 _preCADcharOptions.insert(preCADcharOptionNames[i]);
199 _preCADoption2value[preCADcharOptionNames[i++]].clear();
202 // default values to be used while MG meshing
204 _defaultOptionValues["enforce_cad_edge_sizes" ] = "no";
205 _defaultOptionValues["jacobian_rectification_respect_geometry"] = "yes";
206 _defaultOptionValues["max_number_of_points_per_patch" ] = "0";
207 _defaultOptionValues["rectify_jacobian" ] = "yes";
208 _defaultOptionValues["respect_geometry" ] = "yes";
209 _defaultOptionValues["tiny_edge_avoid_surface_intersections" ] = "yes";
210 _defaultOptionValues["process_3d_topology" ] = "no";
211 _defaultOptionValues["closed_geometry" ] = "no";
212 _defaultOptionValues["debug" ] = "no";
213 _defaultOptionValues["discard_input_topology" ] = "no";
214 _defaultOptionValues["merge_edges" ] = "no";
215 _defaultOptionValues["periodic_tolerance" ] = "1e-5*D";
216 _defaultOptionValues["remove_duplicate_cad_faces" ] = "no";
217 _defaultOptionValues["required_entities" ] = "respect";
218 _defaultOptionValues["sewing_tolerance" ] = "5e-4*D";
219 _defaultOptionValues["tags" ] = "respect";
222 // check validity of option names of _defaultOptionValues
223 TOptionValues::iterator n2v = _defaultOptionValues.begin();
224 for ( ; n2v != _defaultOptionValues.end(); ++n2v )
225 ASSERT( _option2value.count( n2v->first ) || _preCADoption2value.count( n2v->first ));
226 ASSERT( _option2value.size() + _preCADoption2value.size() == _defaultOptionValues.size() );
231 _faceEntryEnfVertexListMap.clear();
232 _enfVertexList.clear();
233 _faceEntryCoordsListMap.clear();
234 _coordsEnfVertexMap.clear();
235 _faceEntryEnfVertexEntryListMap.clear();
236 _enfVertexEntryEnfVertexMap.clear();
237 _groupNameNodeIDMap.clear();
240 _groupNameEnfVertexListMap.clear();
241 _enfVertexGroupNameMap.clear();
245 TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry)
247 GEOM::GEOM_Object_var aGeomObj;
248 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
249 SALOMEDS::Study_ptr myStudy = smeshGen_i->GetCurrentStudy();
251 TopoDS_Shape S = TopoDS_Shape();
252 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
253 if (!aSObj->_is_nil() ) {
254 CORBA::Object_var obj = aSObj->GetObject();
255 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
258 if ( !aGeomObj->_is_nil() )
259 S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
263 //=============================================================================
264 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
265 if (thePhysicalMesh != _physicalMesh) {
266 _physicalMesh = thePhysicalMesh;
267 NotifySubMeshesHypothesisModification();
271 //=============================================================================
272 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
273 if (theGeometricMesh != _geometricMesh) {
274 _geometricMesh = theGeometricMesh;
275 // switch (_geometricMesh) {
278 // _angleMesh = GetDefaultAngleMesh();
279 // _gradation = GetDefaultGradation();
282 NotifySubMeshesHypothesisModification();
286 //=============================================================================
287 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal, bool isRelative) {
288 if ((theVal != _phySize) || (isRelative != _phySizeRel)) {
289 _phySizeRel = isRelative;
291 _phySize = GetMaxSize();
295 NotifySubMeshesHypothesisModification();
299 //=============================================================================
300 void BLSURFPlugin_Hypothesis::SetMinSize(double theMinSize, bool isRelative) {
301 if ((theMinSize != _minSize) || (isRelative != _minSizeRel)) {
302 _minSizeRel = isRelative;
303 _minSize = theMinSize;
304 NotifySubMeshesHypothesisModification();
308 //=============================================================================
309 void BLSURFPlugin_Hypothesis::SetMaxSize(double theMaxSize, bool isRelative) {
310 if ((theMaxSize != _maxSize) || (isRelative != _maxSizeRel)) {
311 _maxSizeRel = isRelative;
312 _maxSize = theMaxSize;
313 NotifySubMeshesHypothesisModification();
317 //=============================================================================
318 void BLSURFPlugin_Hypothesis::SetUseGradation(bool theVal) {
319 if (theVal != _useGradation) {
320 _useGradation = theVal;
321 NotifySubMeshesHypothesisModification();
325 //=============================================================================
326 void BLSURFPlugin_Hypothesis::SetGradation(double theVal) {
327 _useGradation = ( theVal > 0 );
328 if (theVal != _gradation) {
330 NotifySubMeshesHypothesisModification();
334 //=============================================================================
335 void BLSURFPlugin_Hypothesis::SetUseVolumeGradation(bool theVal) {
336 if (theVal != _useVolumeGradation) {
337 _useVolumeGradation = theVal;
338 NotifySubMeshesHypothesisModification();
342 //=============================================================================
343 void BLSURFPlugin_Hypothesis::SetVolumeGradation(double theVal) {
344 _useVolumeGradation = ( theVal > 0 );
345 if (theVal != _volumeGradation) {
346 _volumeGradation = theVal;
347 NotifySubMeshesHypothesisModification();
351 //=============================================================================
352 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal) {
353 if (theVal != _quadAllowed) {
354 _quadAllowed = theVal;
355 NotifySubMeshesHypothesisModification();
359 //=============================================================================
360 void BLSURFPlugin_Hypothesis::SetAngleMesh(double theVal) {
361 if (theVal != _angleMesh) {
363 NotifySubMeshesHypothesisModification();
367 //=============================================================================
368 void BLSURFPlugin_Hypothesis::SetChordalError(double theDistance) {
369 if (theDistance != _chordalError) {
370 _chordalError = theDistance;
371 NotifySubMeshesHypothesisModification();
375 //=============================================================================
376 void BLSURFPlugin_Hypothesis::SetAnisotropic(bool theVal) {
377 if (theVal != _anisotropic) {
378 _anisotropic = theVal;
379 NotifySubMeshesHypothesisModification();
383 //=============================================================================
384 void BLSURFPlugin_Hypothesis::SetAnisotropicRatio(double theVal) {
385 if (theVal != _anisotropicRatio) {
386 _anisotropicRatio = theVal;
387 NotifySubMeshesHypothesisModification();
391 //=============================================================================
392 void BLSURFPlugin_Hypothesis::SetRemoveTinyEdges(bool theVal) {
393 if (theVal != _removeTinyEdges) {
394 _removeTinyEdges = theVal;
395 NotifySubMeshesHypothesisModification();
399 //=============================================================================
400 void BLSURFPlugin_Hypothesis::SetTinyEdgeLength(double theVal) {
401 if (theVal != _tinyEdgeLength) {
402 _tinyEdgeLength = theVal;
403 NotifySubMeshesHypothesisModification();
407 //=============================================================================
408 void BLSURFPlugin_Hypothesis::SetOptimiseTinyEdges(bool theVal) {
409 if (theVal != _optimiseTinyEdges) {
410 _optimiseTinyEdges = theVal;
411 NotifySubMeshesHypothesisModification();
415 //=============================================================================
416 void BLSURFPlugin_Hypothesis::SetTinyEdgeOptimisationLength(double theVal) {
417 if (theVal != _tinyEdgeOptimisationLength) {
418 _tinyEdgeOptimisationLength = theVal;
419 NotifySubMeshesHypothesisModification();
423 //=============================================================================
424 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersection(bool theVal) {
425 if (theVal != _correctSurfaceIntersec) {
426 _correctSurfaceIntersec = theVal;
427 NotifySubMeshesHypothesisModification();
431 //=============================================================================
432 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersectionMaxCost(double theVal) {
433 if (theVal != _corrSurfaceIntersCost) {
434 _corrSurfaceIntersCost = theVal;
435 NotifySubMeshesHypothesisModification();
439 //=============================================================================
440 void BLSURFPlugin_Hypothesis::SetBadElementRemoval(bool theVal) {
441 if (theVal != _badElementRemoval) {
442 _badElementRemoval = theVal;
443 NotifySubMeshesHypothesisModification();
447 //=============================================================================
448 void BLSURFPlugin_Hypothesis::SetBadElementAspectRatio(double theVal) {
449 if (theVal != _badElementAspectRatio) {
450 _badElementAspectRatio = theVal;
451 NotifySubMeshesHypothesisModification();
455 //=============================================================================
456 void BLSURFPlugin_Hypothesis::SetOptimizeMesh(bool theVal) {
457 if (theVal != _optimizeMesh) {
458 _optimizeMesh = theVal;
459 NotifySubMeshesHypothesisModification();
463 //=============================================================================
464 void BLSURFPlugin_Hypothesis::SetQuadraticMesh(bool theVal) {
465 if (theVal != _quadraticMesh) {
466 _quadraticMesh = theVal;
467 NotifySubMeshesHypothesisModification();
471 //=============================================================================
472 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology) {
473 if (theTopology != _topology) {
474 _topology = theTopology;
475 NotifySubMeshesHypothesisModification();
479 //=============================================================================
480 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
481 if (theVal != _verb) {
483 NotifySubMeshesHypothesisModification();
487 //=============================================================================
488 void BLSURFPlugin_Hypothesis::SetEnforceCadEdgesSize( bool toEnforce )
490 if ( GetEnforceCadEdgesSize() != toEnforce )
492 SetOptionValue( "enforce_cad_edge_sizes", toEnforce ? "yes" : "no" );
493 NotifySubMeshesHypothesisModification();
496 //=============================================================================
497 bool BLSURFPlugin_Hypothesis::GetEnforceCadEdgesSize()
499 return ToBool( GetOptionValue( "enforce_cad_edge_sizes" ), GET_DEFAULT() );
501 //=============================================================================
503 void BLSURFPlugin_Hypothesis::SetJacobianRectificationRespectGeometry( bool allowRectification )
505 if ( GetJacobianRectificationRespectGeometry() != allowRectification )
507 SetOptionValue("jacobian_rectification_respect_geometry", allowRectification ? "yes" : "no" );
508 NotifySubMeshesHypothesisModification();
511 //=============================================================================
512 bool BLSURFPlugin_Hypothesis::GetJacobianRectificationRespectGeometry()
514 return ToBool( GetOptionValue("jacobian_rectification_respect_geometry", GET_DEFAULT()));
516 //=============================================================================
518 void BLSURFPlugin_Hypothesis::SetJacobianRectification( bool allowRectification )
520 if ( GetJacobianRectification() != allowRectification )
522 SetOptionValue( "rectify_jacobian", allowRectification ? "yes" : "no" );
523 NotifySubMeshesHypothesisModification();
526 //=============================================================================
527 bool BLSURFPlugin_Hypothesis::GetJacobianRectification()
529 return ToBool( GetOptionValue("rectify_jacobian", GET_DEFAULT()));
531 //=============================================================================
533 void BLSURFPlugin_Hypothesis::SetMaxNumberOfPointsPerPatch( int nb )
534 throw (std::invalid_argument)
537 throw std::invalid_argument( SMESH_Comment("Invalid number of points: ") << nb );
539 if ( GetMaxNumberOfPointsPerPatch() != nb )
541 SetOptionValue("max_number_of_points_per_patch", SMESH_Comment( nb ));
542 NotifySubMeshesHypothesisModification();
545 //=============================================================================
546 int BLSURFPlugin_Hypothesis::GetMaxNumberOfPointsPerPatch()
548 return ToInt( GetOptionValue("max_number_of_points_per_patch", GET_DEFAULT()));
550 //=============================================================================
552 void BLSURFPlugin_Hypothesis::SetRespectGeometry( bool toRespect )
554 if ( GetRespectGeometry() != toRespect )
556 SetOptionValue("respect_geometry", toRespect ? "yes" : "no" );
557 NotifySubMeshesHypothesisModification();
560 //=============================================================================
561 bool BLSURFPlugin_Hypothesis::GetRespectGeometry()
563 return ToBool( GetOptionValue( "respect_geometry", GET_DEFAULT()));
565 //=============================================================================
567 void BLSURFPlugin_Hypothesis::SetTinyEdgesAvoidSurfaceIntersections( bool toAvoidIntersection )
569 if ( GetTinyEdgesAvoidSurfaceIntersections() != toAvoidIntersection )
571 SetOptionValue("tiny_edge_avoid_surface_intersections", toAvoidIntersection ? "yes" : "no" );
572 NotifySubMeshesHypothesisModification();
575 //=============================================================================
576 bool BLSURFPlugin_Hypothesis::GetTinyEdgesAvoidSurfaceIntersections()
578 return ToBool( GetOptionValue("tiny_edge_avoid_surface_intersections", GET_DEFAULT()));
580 //=============================================================================
582 void BLSURFPlugin_Hypothesis::SetClosedGeometry( bool isClosed )
584 if ( GetClosedGeometry() != isClosed )
586 SetPreCADOptionValue("closed_geometry", isClosed ? "yes" : "no" );
587 NotifySubMeshesHypothesisModification();
590 //=============================================================================
591 bool BLSURFPlugin_Hypothesis::GetClosedGeometry()
593 return ToBool( GetPreCADOptionValue( "closed_geometry", GET_DEFAULT()));
595 //=============================================================================
597 void BLSURFPlugin_Hypothesis::SetDebug( bool isDebug )
599 if ( GetDebug() != isDebug )
601 SetPreCADOptionValue("debug", isDebug ? "yes" : "no" );
602 NotifySubMeshesHypothesisModification();
605 //=============================================================================
606 bool BLSURFPlugin_Hypothesis::GetDebug()
608 return ToBool( GetPreCADOptionValue("debug", GET_DEFAULT()));
610 //=============================================================================
612 void BLSURFPlugin_Hypothesis::SetPeriodicTolerance( CORBA::Double tol )
613 throw (std::invalid_argument)
616 throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
617 if ( GetPeriodicTolerance() != tol )
619 SetPreCADOptionValue("periodic_tolerance", SMESH_Comment( tol ) );
620 NotifySubMeshesHypothesisModification();
623 //=============================================================================
624 double BLSURFPlugin_Hypothesis::GetPeriodicTolerance()
626 return ToDbl( GetPreCADOptionValue( "periodic_tolerance", GET_DEFAULT()));
628 //=============================================================================
630 void BLSURFPlugin_Hypothesis::SetRequiredEntities( const std::string& howToTreat )
631 throw (std::invalid_argument)
633 if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear" )
634 throw std::invalid_argument
635 ( SMESH_Comment("required_entities must be in ['respect','ignore','clear'] "));
637 if ( GetRequiredEntities() != howToTreat )
639 SetPreCADOptionValue("required_entities", howToTreat );
640 NotifySubMeshesHypothesisModification();
643 //=============================================================================
644 std::string BLSURFPlugin_Hypothesis::GetRequiredEntities()
646 return GetPreCADOptionValue("required_entities", GET_DEFAULT());
648 //=============================================================================
650 void BLSURFPlugin_Hypothesis::SetSewingTolerance( CORBA::Double tol )
651 throw (std::invalid_argument)
654 throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
655 if ( GetSewingTolerance() != tol )
657 SetPreCADOptionValue("sewing_tolerance", SMESH_Comment( tol ) );
658 NotifySubMeshesHypothesisModification();
661 //=============================================================================
662 CORBA::Double BLSURFPlugin_Hypothesis::GetSewingTolerance()
664 return ToDbl( GetPreCADOptionValue("sewing_tolerance", GET_DEFAULT()));
666 //=============================================================================
668 void BLSURFPlugin_Hypothesis::SetTags( const std::string& howToTreat )
669 throw (std::invalid_argument)
671 if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear" )
672 throw std::invalid_argument
673 ( SMESH_Comment("'tags' must be in ['respect','ignore','clear'] "));
675 if ( GetTags() != howToTreat )
677 SetPreCADOptionValue("tags", howToTreat );
678 NotifySubMeshesHypothesisModification();
681 //=============================================================================
682 std::string BLSURFPlugin_Hypothesis::GetTags()
684 return GetPreCADOptionValue("tags", GET_DEFAULT());
686 //=============================================================================
687 void BLSURFPlugin_Hypothesis::SetPreCADMergeEdges(bool theVal)
689 if (theVal != ToBool( GetPreCADOptionValue("merge_edges", GET_DEFAULT()))) {
690 _preCADMergeEdges = theVal;
691 SetPreCADOptionValue("merge_edges", theVal ? "yes" : "no" );
692 NotifySubMeshesHypothesisModification();
696 //=============================================================================
697 void BLSURFPlugin_Hypothesis::SetPreCADRemoveTinyUVEdges(bool theVal)
699 if (theVal != _preCADRemoveTinyUVEdges) {
700 _preCADRemoveTinyUVEdges = theVal;
701 NotifySubMeshesHypothesisModification();
705 //=============================================================================
706 void BLSURFPlugin_Hypothesis::SetPreCADRemoveDuplicateCADFaces(bool theVal)
708 if (theVal != ToBool( GetPreCADOptionValue("remove_duplicate_cad_faces", GET_DEFAULT()))) {
709 _preCADRemoveDuplicateCADFaces = theVal;
710 SetPreCADOptionValue("remove_duplicate_cad_faces", theVal ? "yes" : "no" );
711 NotifySubMeshesHypothesisModification();
715 //=============================================================================
716 void BLSURFPlugin_Hypothesis::SetPreCADProcess3DTopology(bool theVal)
718 if (theVal != ToBool( GetPreCADOptionValue("process_3d_topology", GET_DEFAULT()))) {
719 _preCADProcess3DTopology = theVal;
720 SetPreCADOptionValue("process_3d_topology", theVal ? "yes" : "no" );
721 NotifySubMeshesHypothesisModification();
725 //=============================================================================
726 void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal)
728 if (theVal != ToBool( GetPreCADOptionValue("discard_input_topology", GET_DEFAULT()))) {
729 _preCADDiscardInput = theVal;
730 SetPreCADOptionValue("discard_input_topology", theVal ? "yes" : "no" );
731 NotifySubMeshesHypothesisModification();
735 //=============================================================================
736 // Return true if any PreCAD option is activated
737 bool BLSURFPlugin_Hypothesis::HasPreCADOptions(const BLSURFPlugin_Hypothesis* hyp)
743 bool orDefault, isOk;
744 return ( ToBool( hyp->GetPreCADOptionValue("closed_geometry" , &orDefault )) ||
745 ToBool( hyp->GetPreCADOptionValue("discard_input_topology" , &orDefault )) ||
746 ToBool( hyp->GetPreCADOptionValue("merge_edges" , &orDefault )) ||
747 ToBool( hyp->GetPreCADOptionValue("remove_duplicate_cad_faces", &orDefault )) ||
748 ToBool( hyp->GetPreCADOptionValue("process_3d_topology" , &orDefault )) ||
749 ToBool( hyp->GetPreCADOption ("manifold_geometry") , &isOk ) ||
750 hyp->GetPreCADOptionValue("sewing_tolerance", &orDefault ) != "5e-4*D" ||
751 !hyp->_preCadFacesPeriodicityVector.empty() ||
752 !hyp->_preCadEdgesPeriodicityVector.empty() ||
753 !hyp->_facesPeriodicityVector.empty() ||
754 !hyp->_edgesPeriodicityVector.empty() ||
755 !hyp->_verticesPeriodicityVector.empty() ||
756 hyp->GetTopology() != FromCAD );
759 //=============================================================================
760 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
761 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
763 _GMFFileName = theFileName;
764 // _GMFFileMode = isBinary;
765 NotifySubMeshesHypothesisModification();
768 //=============================================================================
769 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
770 throw (std::invalid_argument) {
772 TOptionValues::iterator op_val = _option2value.find(optionName);
773 if (op_val == _option2value.end())
775 op_val = _preCADoption2value.find(optionName);
776 if (op_val == _preCADoption2value.end())
778 std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'. Try SetAdvancedOption()";
779 throw std::invalid_argument(msg);
782 if (op_val->second != optionValue)
784 const char* ptr = optionValue.c_str();
785 // strip white spaces
786 while (ptr[0] == ' ')
789 while (i != 0 && ptr[i - 1] == ' ')
793 std::string typeName;
796 } else if (_charOptions.count(optionName)) {
797 // do not check strings
798 } else if (_doubleOptions.count(optionName)) {
799 // check if value is double
802 } else if (_boolOptions.count(optionName)) {
803 // check if value is bool
804 ToBool(ptr, &typeOk);
807 // check if value is int
809 typeName = "integer";
812 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
813 throw std::invalid_argument(msg);
815 std::string value( ptr, i );
816 if ( _defaultOptionValues[ optionName ] == value )
819 op_val->second = value;
821 NotifySubMeshesHypothesisModification();
825 //=============================================================================
826 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
827 throw (std::invalid_argument) {
829 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
830 if (op_val == _preCADoption2value.end()) {
831 op_val = _option2value.find(optionName);
832 if (op_val == _option2value.end()) {
833 std::string msg = "Unknown MG-PreCAD option: '" + optionName + "'. Try SetAdvancedOption()";
834 throw std::invalid_argument(msg);
837 if (op_val->second != optionValue)
839 const char* ptr = optionValue.c_str();
840 // strip white spaces
841 while (ptr[0] == ' ')
844 while (i != 0 && ptr[i - 1] == ' ')
848 std::string typeName;
851 } else if (_preCADcharOptions.find(optionName) != _preCADcharOptions.end()) {
852 // do not check strings
853 } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
854 // check if value is double
856 strtod(ptr, &endPtr);
857 typeOk = (ptr != endPtr);
859 } else if (_boolOptions.count(optionName)) {
860 // check if value is bool
861 ToBool(ptr, &typeOk);
864 // check if value is int
866 strtol(ptr, &endPtr, 10);
867 typeOk = (ptr != endPtr);
868 typeName = "integer";
871 std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
872 throw std::invalid_argument(msg);
874 std::string value( ptr, i );
875 if ( _defaultOptionValues[ optionName ] == value )
878 op_val->second = value;
880 NotifySubMeshesHypothesisModification();
884 //=============================================================================
885 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
886 bool* isDefault) const
887 throw (std::invalid_argument)
889 TOptionValues::const_iterator op_val = _option2value.find(optionName);
890 if (op_val == _option2value.end())
892 op_val = _preCADoption2value.find(optionName);
893 if (op_val == _preCADoption2value.end())
895 op_val = _customOption2value.find(optionName);
896 if (op_val == _customOption2value.end())
898 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
899 throw std::invalid_argument(msg);
903 std::string val = op_val->second;
904 if ( isDefault ) *isDefault = ( val.empty() );
906 if ( val.empty() && isDefault )
908 op_val = _defaultOptionValues.find( optionName );
909 if (op_val != _defaultOptionValues.end())
910 val = op_val->second;
915 //=============================================================================
916 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName,
917 bool* isDefault) const
918 throw (std::invalid_argument)
920 TOptionValues::const_iterator op_val = _preCADoption2value.find(optionName);
921 if (op_val == _preCADoption2value.end())
923 op_val = _option2value.find(optionName);
924 if (op_val == _option2value.end())
926 op_val = _customOption2value.find(optionName);
927 if (op_val == _customOption2value.end())
929 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
930 throw std::invalid_argument(msg);
934 std::string val = op_val->second;
935 if ( isDefault ) *isDefault = ( val.empty() );
937 if ( val.empty() && isDefault )
939 op_val = _defaultOptionValues.find( optionName );
940 if (op_val != _option2value.end())
941 val = op_val->second;
946 //=============================================================================
947 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
949 TOptionValues::iterator op_val = _customOption2value.find(optionName);
950 if (op_val != _customOption2value.end())
951 _customOption2value.erase(op_val);
953 op_val = _option2value.find(optionName);
954 if (op_val != _option2value.end())
955 op_val->second.clear();
957 op_val = _preCADoption2value.find(optionName);
958 if (op_val != _preCADoption2value.end())
959 op_val->second.clear();
964 //=============================================================================
965 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName)
967 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
968 if (op_val != _preCADoption2value.end())
969 op_val->second.clear();
972 //=============================================================================
973 void BLSURFPlugin_Hypothesis::AddOption(const std::string& optionName, const std::string& optionValue)
976 TOptionValues::iterator op_val = _option2value.find(optionName);
977 if (op_val != _option2value.end())
979 if (op_val->second != optionValue)
980 op_val->second = optionValue;
986 op_val = _preCADoption2value.find(optionName);
987 if (op_val != _preCADoption2value.end())
989 if (op_val->second != optionValue)
990 op_val->second = optionValue;
994 else if ( optionValue.empty() )
996 _customOption2value.erase( optionName );
1000 op_val = _customOption2value.find(optionName);
1001 if (op_val == _customOption2value.end())
1002 _customOption2value[optionName] = optionValue;
1003 else if (op_val->second != optionValue)
1004 op_val->second = optionValue;
1010 NotifySubMeshesHypothesisModification();
1013 //=============================================================================
1014 void BLSURFPlugin_Hypothesis::AddPreCADOption(const std::string& optionName, const std::string& optionValue)
1016 AddOption( optionName, optionValue );
1019 //=============================================================================
1020 std::string BLSURFPlugin_Hypothesis::GetOption(const std::string& optionName) const
1022 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1023 if (op_val != _customOption2value.end())
1024 return op_val->second;
1029 //=============================================================================
1030 std::string BLSURFPlugin_Hypothesis::GetPreCADOption(const std::string& optionName) const
1032 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1033 if (op_val != _customOption2value.end())
1034 return op_val->second;
1039 //=============================================================================
1040 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetOptionValues() const
1043 TOptionValues::const_iterator op_val = _option2value.begin();
1044 for ( ; op_val != _option2value.end(); ++op_val )
1045 vals.insert( make_pair( op_val->first, GetOptionValue( op_val->first, GET_DEFAULT() )));
1050 //=============================================================================
1051 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetPreCADOptionValues() const
1054 TOptionValues::const_iterator op_val = _preCADoption2value.begin();
1055 for ( ; op_val != _preCADoption2value.end(); ++op_val )
1056 vals.insert( make_pair( op_val->first, GetPreCADOptionValue( op_val->first, GET_DEFAULT() )));
1061 //=======================================================================
1062 //function : SetSizeMapEntry
1063 //=======================================================================
1064 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
1065 if (_sizeMap[entry].compare(sizeMap) != 0) {
1066 SetPhysicalMesh(PhysicalLocalSize);
1067 _sizeMap[entry] = sizeMap;
1068 NotifySubMeshesHypothesisModification();
1072 //=======================================================================
1073 //function : GetSizeMapEntry
1074 //=======================================================================
1075 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
1076 TSizeMap::iterator it = _sizeMap.find(entry);
1077 if (it != _sizeMap.end())
1080 return "No_Such_Entry";
1084 * \brief Return the size maps
1086 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
1087 return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
1090 //=======================================================================
1091 //function : SetAttractorEntry
1092 //=======================================================================
1093 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
1094 if (_attractors[entry].compare(attractor) != 0) {
1095 SetPhysicalMesh(PhysicalLocalSize);
1096 _attractors[entry] = attractor;
1097 NotifySubMeshesHypothesisModification();
1101 //=======================================================================
1102 //function : GetAttractorEntry
1103 //=======================================================================
1104 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
1105 TSizeMap::iterator it = _attractors.find(entry);
1106 if (it != _attractors.end())
1109 return "No_Such_Entry";
1113 * \brief Return the attractors
1115 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
1116 return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
1119 //=======================================================================
1120 //function : SetClassAttractorEntry
1121 //=======================================================================
1122 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
1124 SetPhysicalMesh(PhysicalLocalSize);
1126 // The new attractor can't be defined on the same face as another sizemap
1127 TSizeMap::iterator it = _sizeMap.find( entry );
1128 if ( it != _sizeMap.end() ) {
1130 NotifySubMeshesHypothesisModification();
1133 TSizeMap::iterator itAt = _attractors.find( entry );
1134 if ( itAt != _attractors.end() ) {
1135 _attractors.erase(itAt);
1136 NotifySubMeshesHypothesisModification();
1140 const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
1141 const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
1142 TAttractorMap::iterator attIt = _classAttractors.find(entry);
1143 for ( ; attIt != _classAttractors.end(); ++attIt )
1144 if ( attIt->first == entry &&
1145 attIt->second->GetAttractorEntry() == attEntry )
1147 bool attExists = (attIt != _classAttractors.end());
1149 BLSURFPlugin_Attractor* myAttractor;
1151 myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 );
1152 _classAttractors.insert( make_pair( entry, myAttractor ));
1155 myAttractor = attIt->second;
1157 // if (!myAttractor->IsMapBuilt())
1158 // myAttractor->BuildMap();
1159 myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
1161 NotifySubMeshesHypothesisModification();
1164 //=======================================================================
1165 //function : SetConstantSizeOnAdjacentFaces
1166 //=======================================================================
1167 // TODO uncomment and test (include the needed .hxx)
1168 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist ) {
1169 // TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
1170 // TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
1171 // TopTools_IndexedMapOfShapListOdShape::iterator it;
1172 // for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
1173 // SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
1181 //=======================================================================
1182 //function : GetClassAttractorEntry
1183 //=======================================================================
1184 // BLSURFPlugin_Attractor& BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
1186 // TAttractorMap::iterator it = _classAttractors.find( entry );
1187 // if ( it != _classAttractors.end() )
1188 // return it->second;
1190 // return "No_Such_Entry";
1194 * \brief Return the map of attractor instances
1196 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
1198 return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
1201 //=======================================================================
1202 //function : ClearEntry
1203 //=======================================================================
1204 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
1205 const char * attEntry/*=0*/)
1207 TSizeMap::iterator it = _sizeMap.find( entry );
1209 if ( it != _sizeMap.end() ) {
1211 NotifySubMeshesHypothesisModification();
1214 TSizeMap::iterator itAt = _attractors.find( entry );
1215 if ( itAt != _attractors.end() ) {
1216 _attractors.erase(itAt);
1217 NotifySubMeshesHypothesisModification();
1220 TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
1221 if ( it_clAt != _classAttractors.end() ) {
1223 if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
1224 _classAttractors.erase( it_clAt++ );
1228 while ( it_clAt != _classAttractors.end() );
1229 NotifySubMeshesHypothesisModification();
1232 std::cout<<"No_Such_Entry"<<std::endl;
1237 //=======================================================================
1238 //function : ClearSizeMaps
1239 //=======================================================================
1240 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
1242 _attractors.clear();
1243 _classAttractors.clear();
1246 // Enable internal enforced vertices on specific face if requested by user
1248 ////=======================================================================
1249 ////function : SetInternalEnforcedVertex
1250 ////=======================================================================
1251 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
1252 // bool toEnforceInternalVertices,
1253 // TEnfGroupName theGroupName) {
1255 // << toEnforceInternalVertices << ", " << theGroupName << ")");
1257 // TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
1258 // if (it != _faceEntryInternalVerticesList.end()) {
1259 // if (!toEnforceInternalVertices) {
1260 // _faceEntryInternalVerticesList.erase(it);
1264 // if (toEnforceInternalVertices) {
1265 // _faceEntryInternalVerticesList.insert(theFaceEntry);
1270 // // Take care of groups
1274 //=======================================================================
1275 //function : SetEnforcedVertex
1276 //=======================================================================
1277 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry,
1278 TEnfName theVertexName,
1279 TEntry theVertexEntry,
1280 TEnfGroupName theGroupName,
1281 double x, double y, double z)
1283 SetPhysicalMesh(PhysicalLocalSize);
1285 bool toNotify = false;
1286 bool toCreate = true;
1288 TEnfVertex *oldEnVertex;
1289 TEnfVertex *newEnfVertex = new TEnfVertex();
1290 newEnfVertex->name = theVertexName;
1291 newEnfVertex->geomEntry = theVertexEntry;
1292 newEnfVertex->coords.clear();
1293 if (theVertexEntry == "") {
1294 newEnfVertex->coords.push_back(x);
1295 newEnfVertex->coords.push_back(y);
1296 newEnfVertex->coords.push_back(z);
1298 newEnfVertex->grpName = theGroupName;
1299 newEnfVertex->faceEntries.clear();
1300 newEnfVertex->faceEntries.insert(theFaceEntry);
1303 // update _enfVertexList
1304 TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
1305 if (it != _enfVertexList.end()) {
1307 oldEnVertex = (*it);
1308 if (oldEnVertex->name != theVertexName) {
1309 oldEnVertex->name = theVertexName;
1312 if (oldEnVertex->grpName != theGroupName) {
1313 oldEnVertex->grpName = theGroupName;
1316 TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
1317 if (it_faceEntries == oldEnVertex->faceEntries.end()) {
1318 oldEnVertex->faceEntries.insert(theFaceEntry);
1319 _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
1323 // update map coords / enf vertex if needed
1324 if (oldEnVertex->coords.size()) {
1325 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
1326 _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
1329 // update map geom entry / enf vertex if needed
1330 if (oldEnVertex->geomEntry != "") {
1331 _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
1332 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
1337 // //////// CREATE ////////////
1340 _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
1341 _enfVertexList.insert(newEnfVertex);
1342 if (theVertexEntry == "") {
1343 _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
1344 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
1347 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
1348 _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
1353 NotifySubMeshesHypothesisModification();
1359 //=======================================================================
1360 //function : GetEnforcedVertices
1361 //=======================================================================
1363 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
1364 throw (std::invalid_argument) {
1366 if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
1367 return _faceEntryEnfVertexListMap[theFaceEntry];
1369 return GetDefaultEnfVertexList();
1371 std::ostringstream msg;
1372 msg << "No enforced vertex for face entry " << theFaceEntry;
1373 throw std::invalid_argument(msg.str());
1376 //=======================================================================
1377 //function : GetEnfVertexCoordsList
1378 //=======================================================================
1380 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
1381 const TEntry& theFaceEntry) throw (std::invalid_argument) {
1383 if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
1384 return _faceEntryCoordsListMap[theFaceEntry];
1386 std::ostringstream msg;
1387 msg << "No enforced vertex coords for face entry " << theFaceEntry;
1388 throw std::invalid_argument(msg.str());
1391 //=======================================================================
1392 //function : GetEnfVertexEntryList
1393 //=======================================================================
1395 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
1396 throw (std::invalid_argument) {
1398 if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
1399 return _faceEntryEnfVertexEntryListMap[theFaceEntry];
1401 std::ostringstream msg;
1402 msg << "No enforced vertex entry for face entry " << theFaceEntry;
1403 throw std::invalid_argument(msg.str());
1406 //=======================================================================
1407 //function : GetEnfVertex(TEnfVertexCoords coords)
1408 //=======================================================================
1410 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
1411 throw (std::invalid_argument) {
1413 if (_coordsEnfVertexMap.count(coords) > 0)
1414 return _coordsEnfVertexMap[coords];
1416 std::ostringstream msg;
1417 msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
1418 throw std::invalid_argument(msg.str());
1421 //=======================================================================
1422 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
1423 //=======================================================================
1425 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
1426 throw (std::invalid_argument) {
1428 if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
1429 return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
1431 std::ostringstream msg;
1432 msg << "No enforced vertex with entry " << theEnfVertexEntry;
1433 throw std::invalid_argument(msg.str());
1436 //Enable internal enforced vertices on specific face if requested by user
1437 ////=======================================================================
1438 ////function : GetInternalEnforcedVertex
1439 ////=======================================================================
1441 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
1443 // if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
1448 //=======================================================================
1449 //function : ClearEnforcedVertex
1450 //=======================================================================
1452 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
1453 const TEntry& theVertexEntry) throw (std::invalid_argument) {
1455 bool toNotify = false;
1456 std::ostringstream msg;
1457 TEnfVertex *oldEnfVertex;
1458 TEnfVertexCoords coords;
1460 coords.push_back(x);
1461 coords.push_back(y);
1462 coords.push_back(z);
1464 // check that enf vertex with given enf vertex entry exists
1465 TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
1466 if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
1468 oldEnfVertex = it_enfVertexEntry->second;
1470 _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
1472 TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
1473 enfVertexEntryList.erase(theVertexEntry);
1474 if (enfVertexEntryList.size() == 0)
1475 _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
1476 // TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1477 // TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
1478 // it_entry_entry->second.erase(it_entryList);
1479 // if (it_entry_entry->second.size() == 0)
1480 // _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1483 MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
1484 msg << "No enforced vertex with geom entry " << theVertexEntry;
1485 // check that enf vertex with given coords exists
1486 TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
1487 if (it_coords_enf != _coordsEnfVertexMap.end()) {
1489 oldEnfVertex = it_coords_enf->second;
1491 _coordsEnfVertexMap.erase(it_coords_enf);
1493 TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
1494 enfVertexCoordsList.erase(coords);
1495 if (enfVertexCoordsList.size() == 0)
1496 _faceEntryCoordsListMap.erase(theFaceEntry);
1497 // TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1498 // TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
1499 // it_entry_coords->second.erase(it_coordsList);
1500 // if (it_entry_coords->second.size() == 0)
1501 // _faceEntryCoordsListMap.erase(it_entry_coords);
1504 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
1506 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
1507 throw std::invalid_argument(msg.str());
1511 // update _enfVertexList
1512 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1513 if (it != _enfVertexList.end()) {
1514 (*it)->faceEntries.erase(theFaceEntry);
1515 if ((*it)->faceEntries.size() == 0){
1516 _enfVertexList.erase(it);
1521 // update _faceEntryEnfVertexListMap
1522 TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
1523 currentEnfVertexList.erase(oldEnfVertex);
1525 if (currentEnfVertexList.size() == 0) {
1526 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1530 NotifySubMeshesHypothesisModification();
1535 //=======================================================================
1536 //function : ClearEnforcedVertices
1537 //=======================================================================
1539 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
1541 bool toNotify = false;
1542 TEnfVertex *oldEnfVertex;
1544 TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1545 if (it_entry_coords != _faceEntryCoordsListMap.end()) {
1547 TEnfVertexCoordsList coordsList = it_entry_coords->second;
1548 TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
1549 for (; it_coordsList != coordsList.end(); ++it_coordsList) {
1550 TEnfVertexCoords coords = (*it_coordsList);
1551 oldEnfVertex = _coordsEnfVertexMap[coords];
1552 _coordsEnfVertexMap.erase(coords);
1553 // update _enfVertexList
1554 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1555 if (it != _enfVertexList.end()) {
1556 (*it)->faceEntries.erase(theFaceEntry);
1557 if ((*it)->faceEntries.size() == 0){
1558 _enfVertexList.erase(it);
1563 _faceEntryCoordsListMap.erase(it_entry_coords);
1564 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1567 TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1568 if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
1570 TEntryList enfVertexEntryList = it_entry_entry->second;
1571 TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
1572 for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
1573 TEntry enfVertexEntry = (*it_enfVertexEntryList);
1574 oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
1575 _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
1576 // update _enfVertexList
1577 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1578 if (it != _enfVertexList.end()) {
1579 (*it)->faceEntries.erase(theFaceEntry);
1580 if ((*it)->faceEntries.size() == 0){
1581 _enfVertexList.erase(it);
1586 _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1587 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1591 NotifySubMeshesHypothesisModification();
1594 // std::ostringstream msg;
1595 // msg << "No enforced vertex for " << theFaceEntry;
1596 // throw std::invalid_argument(msg.str());
1599 //=======================================================================
1600 //function : ClearAllEnforcedVertices
1601 //=======================================================================
1602 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
1603 _faceEntryEnfVertexListMap.clear();
1604 _enfVertexList.clear();
1605 _faceEntryCoordsListMap.clear();
1606 _coordsEnfVertexMap.clear();
1607 _faceEntryEnfVertexEntryListMap.clear();
1608 _enfVertexEntryEnfVertexMap.clear();
1609 // Enable internal enforced vertices on specific face if requested by user
1610 // _faceEntryInternalVerticesList.clear();
1611 NotifySubMeshesHypothesisModification();
1614 //================================================================================
1616 * \brief Return the enforced vertices
1618 //================================================================================
1621 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1622 const BLSURFPlugin_Hypothesis* hyp) {
1623 return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1626 //Enable internal enforced vertices on specific face if requested by user
1627 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1628 // const BLSURFPlugin_Hypothesis* hyp) {
1629 // return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1632 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1634 return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1637 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1639 return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1642 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1643 const BLSURFPlugin_Hypothesis* hyp) {
1644 return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1647 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1648 const BLSURFPlugin_Hypothesis* hyp) {
1649 return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1652 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1653 const BLSURFPlugin_Hypothesis* hyp) {
1654 return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1657 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1658 const BLSURFPlugin_Hypothesis* hyp) {
1659 return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1662 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1663 const BLSURFPlugin_Hypothesis* hyp) {
1664 return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1667 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1669 TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1670 if (it != _groupNameNodeIDMap.end()) {
1673 std::ostringstream msg;
1674 msg << "No group " << theGroupName;
1675 throw std::invalid_argument(msg.str());
1678 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1680 _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1683 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1685 TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1686 if (it != _groupNameNodeIDMap.end()) {
1687 std::set<int>::iterator IDit = it->second.find(theNodeID);
1688 if (IDit != it->second.end())
1689 it->second.erase(IDit);
1690 std::ostringstream msg;
1691 msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1692 throw std::invalid_argument(msg.str());
1694 std::ostringstream msg;
1695 msg << "No group " << theGroupName;
1696 throw std::invalid_argument(msg.str());
1700 //=============================================================================
1701 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1702 if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1703 _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1704 if (toEnforceInternalVertices)
1705 SetPhysicalMesh(PhysicalLocalSize);
1706 NotifySubMeshesHypothesisModification();
1711 //=============================================================================
1712 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1713 if (std::string(theGroupName) != std::string(_enforcedInternalVerticesAllFacesGroup)) {
1714 _enforcedInternalVerticesAllFacesGroup = theGroupName;
1715 NotifySubMeshesHypothesisModification();
1719 //=============================================================================
1720 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
1721 const BLSURFPlugin_Hypothesis* hyp) {
1722 return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
1725 //=============================================================================
1726 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
1727 const BLSURFPlugin_Hypothesis* hyp) {
1728 return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
1731 //=============================================================================
1732 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
1733 const BLSURFPlugin_Hypothesis* hyp) {
1734 return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
1737 //=============================================================================
1738 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
1739 const BLSURFPlugin_Hypothesis* hyp){
1740 return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
1743 //=============================================================================
1744 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
1745 const BLSURFPlugin_Hypothesis* hyp){
1746 return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
1749 //=======================================================================
1750 //function : ClearAllEnforcedVertices
1751 //=======================================================================
1752 void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
1753 _preCadFacesPeriodicityVector.clear();
1754 _preCadEdgesPeriodicityVector.clear();
1755 NotifySubMeshesHypothesisModification();
1758 //=======================================================================
1759 //function : AddPreCadFacesPeriodicity
1760 //=======================================================================
1761 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
1762 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1764 TPreCadPeriodicity preCadFacesPeriodicity;
1765 preCadFacesPeriodicity.shape1Entry = theFace1Entry;
1766 preCadFacesPeriodicity.shape2Entry = theFace2Entry;
1767 preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1768 preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1770 _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
1772 NotifySubMeshesHypothesisModification();
1775 //=======================================================================
1776 //function : AddPreCadEdgesPeriodicity
1777 //=======================================================================
1778 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
1779 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1781 TPreCadPeriodicity preCadEdgesPeriodicity;
1782 preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
1783 preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
1784 preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1785 preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1787 _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
1789 NotifySubMeshesHypothesisModification();
1792 //=============================================================================
1793 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
1794 // We must keep at least the same number of arguments when increasing the SALOME version
1795 // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
1796 // parameter can be written several times to keep the old global number of parameters.
1798 // Treat old options which are now in the advanced options
1799 TOptionValues::iterator op_val;
1801 int _preCADRemoveNanoEdges = -1;
1802 double _preCADEpsNano = -1.0;
1803 op_val = _option2value.find("respect_geometry");
1804 if (op_val != _option2value.end()) {
1805 std::string value = op_val->second;
1807 _decimesh = value.compare("1") == 0 ? 1 : 0;
1809 op_val = _preCADoption2value.find("remove_tiny_edges");
1810 if (op_val != _preCADoption2value.end()) {
1811 std::string value = op_val->second;
1813 _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
1815 op_val = _preCADoption2value.find("tiny_edge_length");
1816 if (op_val != _preCADoption2value.end()) {
1817 std::string value = op_val->second;
1819 _preCADEpsNano = strtod(value.c_str(), NULL);
1822 save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1823 << _angleMesh << " " << _gradation << " " << (int) _quadAllowed << " " << _decimesh;
1824 save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
1825 save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1826 save << " " << (int) _enforcedInternalVerticesAllFaces;
1827 save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
1828 save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
1829 save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
1830 save << " " << (int) _preCADProcess3DTopology << " " << (int) _preCADRemoveDuplicateCADFaces << " " << (int) _preCADRemoveTinyUVEdges;
1831 save << " " << (int)_optimiseTinyEdges << " " << _tinyEdgeOptimisationLength;
1832 save << " " << (int)_correctSurfaceIntersec << " " << _corrSurfaceIntersCost;
1833 save << " " << (int)_useGradation << " " << (int)_useVolumeGradation << " " << _volumeGradation;
1835 op_val = _option2value.begin();
1836 if (op_val != _option2value.end()) {
1837 save << " " << "__OPTIONS_BEGIN__";
1838 for (; op_val != _option2value.end(); ++op_val) {
1839 if (!op_val->second.empty())
1840 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1842 save << " " << "__OPTIONS_END__";
1845 op_val = _customOption2value.begin();
1846 if (op_val != _customOption2value.end()) {
1847 save << " " << "__CUSTOM_OPTIONS_BEGIN__";
1848 for (; op_val != _customOption2value.end(); ++op_val) {
1849 if (!op_val->second.empty())
1850 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1852 save << " " << "__CUSTOM_OPTIONS_END__";
1855 op_val = _preCADoption2value.begin();
1856 if (op_val != _preCADoption2value.end()) {
1857 save << " " << "__PRECAD_OPTIONS_BEGIN__";
1858 for (; op_val != _preCADoption2value.end(); ++op_val) {
1859 if (!op_val->second.empty())
1860 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1862 save << " " << "__PRECAD_OPTIONS_END__";
1865 TSizeMap::iterator it_sm = _sizeMap.begin();
1866 if (it_sm != _sizeMap.end()) {
1867 save << " " << "__SIZEMAP_BEGIN__";
1868 for (; it_sm != _sizeMap.end(); ++it_sm) {
1869 save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
1871 save << " " << "__SIZEMAP_END__";
1874 TSizeMap::iterator it_at = _attractors.begin();
1875 if (it_at != _attractors.end()) {
1876 save << " " << "__ATTRACTORS_BEGIN__";
1877 for (; it_at != _attractors.end(); ++it_at) {
1878 save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
1880 save << " " << "__ATTRACTORS_END__";
1883 TAttractorMap::iterator it_At = _classAttractors.begin();
1884 if (it_At != _classAttractors.end()) {
1885 std::ostringstream test;
1886 save << " " << "__NEW_ATTRACTORS_BEGIN__";
1887 test << " " << "__NEW_ATTRACTORS_BEGIN__";
1888 for (; it_At != _classAttractors.end(); ++it_At) {
1889 std::vector<double> attParams;
1890 attParams = it_At->second->GetParameters();
1891 // double step = it_At->second->GetStep();
1892 save << " " << it_At->first;
1893 save << " " << it_At->second->GetAttractorEntry();
1894 save << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1895 // save << " " << step;
1896 test << " " << it_At->first;
1897 test << " " << it_At->second->GetAttractorEntry();
1898 test << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1899 // test << " " << step;
1901 save << " " << "__NEW_ATTRACTORS_END__";
1902 test << " " << "__NEW_ATTRACTORS_END__";
1905 TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
1906 if (it_enf != _enfVertexList.end()) {
1907 save << " " << "__ENFORCED_VERTICES_BEGIN__";
1908 for (; it_enf != _enfVertexList.end(); ++it_enf) {
1909 TEnfVertex *enfVertex = (*it_enf);
1910 save << " " << "__BEGIN_VERTEX__";
1911 if (!enfVertex->name.empty()) {
1912 save << " " << "__BEGIN_NAME__";
1913 save << " " << enfVertex->name;
1914 save << " " << "__END_NAME__";
1916 if (!enfVertex->geomEntry.empty()) {
1917 save << " " << "__BEGIN_ENTRY__";
1918 save << " " << enfVertex->geomEntry;
1919 save << " " << "__END_ENTRY__";
1921 if (!enfVertex->grpName.empty()) {
1922 save << " " << "__BEGIN_GROUP__";
1923 save << " " << enfVertex->grpName;
1924 save << " " << "__END_GROUP__";
1926 if (enfVertex->coords.size()) {
1927 save << " " << "__BEGIN_COORDS__";
1928 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1929 save << " " << enfVertex->coords[i];
1930 save << " " << "__END_COORDS__";
1932 TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
1933 bool hasFaces = false;
1934 if (faceEntriesIt != enfVertex->faceEntries.end()) {
1936 save << " " << "__BEGIN_FACELIST__";
1938 for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
1939 if ( faceEntriesIt->empty() )
1940 save << " _no_face_";
1942 save << " " << (*faceEntriesIt);
1944 save << " " << "__END_FACELIST__";
1945 save << " " << "__END_VERTEX__";
1947 save << " " << "__ENFORCED_VERTICES_END__";
1952 SavePreCADPeriodicity(save, "FACES");
1953 SavePreCADPeriodicity(save, "EDGES");
1955 SaveFacesPeriodicity(save);
1956 SaveEdgesPeriodicity(save);
1957 SaveVerticesPeriodicity(save);
1962 void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
1964 TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
1965 if (it_faces_periodicity != _facesPeriodicityVector.end()) {
1966 save << " " << "__FACES_PERIODICITY_BEGIN__";
1967 for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
1968 TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
1969 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1970 save << " " << "__BEGIN_ENTRY1__";
1971 save << " " << periodicity_i.first;
1972 save << " " << "__END_ENTRY1__";
1973 save << " " << "__BEGIN_ENTRY2__";
1974 save << " " << periodicity_i.second;
1975 save << " " << "__END_ENTRY2__";
1976 save << " " << "__END_PERIODICITY_DESCRIPTION__";
1978 save << " " << "__FACES_PERIODICITY_END__";
1982 void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
1984 TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
1985 if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
1986 save << " " << "__EDGES_PERIODICITY_BEGIN__";
1987 for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
1988 TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
1989 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1990 if (! periodicity_i.theFace1Entry.empty()){
1991 save << " " << "__BEGIN_FACE1__";
1992 save << " " << periodicity_i.theFace1Entry;
1993 save << " " << "__END_FACE1__";
1995 save << " " << "__BEGIN_EDGE1__";
1996 save << " " << periodicity_i.theEdge1Entry;
1997 save << " " << "__END_EDGE1__";
1998 if (! periodicity_i.theFace2Entry.empty()){
1999 save << " " << "__BEGIN_FACE2__";
2000 save << " " << periodicity_i.theFace2Entry;
2001 save << " " << "__END_FACE2__";
2003 save << " " << "__BEGIN_EDGE2__";
2004 save << " " << periodicity_i.theEdge2Entry;
2005 save << " " << "__END_EDGE2__";
2006 save << " " << "__BEGIN_EDGE_ORIENTATION__";
2007 save << " " << periodicity_i.edge_orientation;
2008 save << " " << "__END_EDGE_ORIENTATION__";
2009 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2011 save << " " << "__EDGES_PERIODICITY_END__";
2015 void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save){
2017 TVerticesPeriodicityVector::const_iterator it_vertices_periodicity = _verticesPeriodicityVector.begin();
2018 if (it_vertices_periodicity != _verticesPeriodicityVector.end()) {
2019 save << " " << "__VERTICES_PERIODICITY_BEGIN__";
2020 for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
2021 TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
2022 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2023 save << " " << "__BEGIN_EDGE1__";
2024 save << " " << periodicity_i.theEdge1Entry;
2025 save << " " << "__END_EDGE1__";
2026 save << " " << "__BEGIN_VERTEX1__";
2027 save << " " << periodicity_i.theVertex1Entry;
2028 save << " " << "__END_VERTEX1__";
2029 save << " " << "__BEGIN_EDGE2__";
2030 save << " " << periodicity_i.theEdge2Entry;
2031 save << " " << "__END_EDGE2__";
2032 save << " " << "__BEGIN_VERTEX2__";
2033 save << " " << periodicity_i.theVertex2Entry;
2034 save << " " << "__END_VERTEX2__";
2035 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2037 save << " " << "__VERTICES_PERIODICITY_END__";
2041 void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType) {
2042 TPreCadPeriodicityVector precad_periodicity;
2043 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
2044 precad_periodicity = _preCadFacesPeriodicityVector;
2046 precad_periodicity = _preCadEdgesPeriodicityVector;
2047 TPreCadPeriodicityVector::const_iterator it_precad_periodicity = precad_periodicity.begin();
2048 if (it_precad_periodicity != precad_periodicity.end()) {
2049 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_BEGIN__";
2050 for (; it_precad_periodicity != precad_periodicity.end(); ++it_precad_periodicity) {
2051 TPreCadPeriodicity periodicity_i = (*it_precad_periodicity);
2052 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2053 if (!periodicity_i.shape1Entry.empty()) {
2054 save << " " << "__BEGIN_ENTRY1__";
2055 save << " " << periodicity_i.shape1Entry;
2056 save << " " << "__END_ENTRY1__";
2058 if (!periodicity_i.shape2Entry.empty()) {
2059 save << " " << "__BEGIN_ENTRY2__";
2060 save << " " << periodicity_i.shape2Entry;
2061 save << " " << "__END_ENTRY2__";
2064 std::vector<std::string>::const_iterator sourceVerticesEntriesIt = periodicity_i.theSourceVerticesEntries.begin();
2065 bool hasSourceVertices = false;
2066 if (sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end()) {
2067 hasSourceVertices = true;
2068 save << " " << "__BEGIN_SOURCE_VERTICES_LIST__";
2070 for (; sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end(); ++sourceVerticesEntriesIt)
2071 save << " " << (*sourceVerticesEntriesIt);
2072 if (hasSourceVertices)
2073 save << " " << "__END_SOURCE_VERTICES_LIST__";
2075 std::vector<std::string>::const_iterator targetVerticesEntriesIt = periodicity_i.theTargetVerticesEntries.begin();
2076 bool hasTargetVertices = false;
2077 if (targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end()) {
2078 hasTargetVertices = true;
2079 save << " " << "__BEGIN_TARGET_VERTICES_LIST__";
2081 for (; targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end(); ++targetVerticesEntriesIt)
2082 save << " " << (*targetVerticesEntriesIt);
2083 if (hasTargetVertices)
2084 save << " " << "__END_TARGET_VERTICES_LIST__";
2086 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2088 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_END__";
2093 //=============================================================================
2094 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
2098 std::string option_or_sm;
2100 isOK = static_cast<bool>(load >> i);
2102 _topology = (Topology) i;
2104 load.clear(std::ios::badbit | load.rdstate());
2106 isOK = static_cast<bool>(load >> i);
2108 _physicalMesh = (PhysicalMesh) i;
2110 load.clear(std::ios::badbit | load.rdstate());
2112 isOK = static_cast<bool>(load >> i);
2114 _geometricMesh = (GeometricMesh) i;
2116 load.clear(std::ios::badbit | load.rdstate());
2118 isOK = static_cast<bool>(load >> val);
2122 load.clear(std::ios::badbit | load.rdstate());
2124 isOK = static_cast<bool>(load >> val);
2128 load.clear(std::ios::badbit | load.rdstate());
2130 isOK = static_cast<bool>(load >> val);
2134 load.clear(std::ios::badbit | load.rdstate());
2136 isOK = static_cast<bool>(load >> i);
2138 _quadAllowed = (bool) i;
2140 load.clear(std::ios::badbit | load.rdstate());
2142 isOK = static_cast<bool>(load >> i);
2144 if ( i != -1) { // if value is -1, then this is no longer a standard option
2145 std::string & value = _option2value["respect_geometry"];
2146 bool _decimesh = (bool) i;
2147 value = _decimesh ? "1" : "0";
2151 load.clear(std::ios::badbit | load.rdstate());
2153 isOK = static_cast<bool>(load >> val);
2157 load.clear(std::ios::badbit | load.rdstate());
2159 isOK = static_cast<bool>(load >> val);
2163 load.clear(std::ios::badbit | load.rdstate());
2165 isOK = static_cast<bool>(load >> val);
2167 // former parameter: get min value
2168 _angleMesh = std::min(val,_angleMesh);
2170 load.clear(std::ios::badbit | load.rdstate());
2172 isOK = static_cast<bool>(load >> val);
2174 // former parameter: get min value
2175 _minSize = std::min(val,_minSize);
2177 load.clear(std::ios::badbit | load.rdstate());
2179 isOK = static_cast<bool>(load >> val);
2181 // former parameter: get max value
2182 _maxSize = std::max(val,_maxSize);
2184 load.clear(std::ios::badbit | load.rdstate());
2186 isOK = static_cast<bool>(load >> i);
2190 load.clear(std::ios::badbit | load.rdstate());
2192 isOK = static_cast<bool>(load >> i);
2194 _preCADMergeEdges = (bool) i;
2196 load.clear(std::ios::badbit | load.rdstate());
2198 isOK = static_cast<bool>(load >> i);
2200 if ( i != -1) { // if value is -1, then this is no longer a standard option
2201 std::string & value = _preCADoption2value["remove_tiny_edges"];
2202 bool _preCADRemoveNanoEdges = (bool) i;
2203 value = _preCADRemoveNanoEdges ? "1" : "0";
2207 load.clear(std::ios::badbit | load.rdstate());
2209 isOK = static_cast<bool>(load >> i);
2211 _preCADDiscardInput = (bool) i;
2213 load.clear(std::ios::badbit | load.rdstate());
2215 isOK = static_cast<bool>(load >> val);
2216 if (isOK) { // _preCADEpsNano
2217 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
2218 std::string & value = _preCADoption2value["tiny_edge_length"];
2219 std::ostringstream oss;
2225 load.clear(std::ios::badbit | load.rdstate());
2227 isOK = static_cast<bool>(load >> i);
2229 _enforcedInternalVerticesAllFaces = (bool) i;
2231 load.clear(std::ios::badbit | load.rdstate());
2233 // New options with MeshGems-CADSurf
2235 bool hasCADSurfOptions = false;
2236 bool hasOptions = false;
2237 bool hasCustomOptions = false;
2238 bool hasPreCADOptions = false;
2239 bool hasSizeMap = false;
2240 bool hasAttractor = false;
2241 bool hasNewAttractor = false;
2242 bool hasEnforcedVertex = false;
2243 bool hasPreCADFacesPeriodicity = false;
2244 bool hasPreCADEdgesPeriodicity = false;
2245 bool hasFacesPeriodicity = false;
2246 bool hasEdgesPeriodicity = false;
2247 bool hasVerticesPeriodicity = false;
2249 isOK = static_cast<bool>(load >> option_or_sm);
2251 if ( (option_or_sm == "1")||(option_or_sm == "0") ) {
2252 i = atoi(option_or_sm.c_str());
2253 hasCADSurfOptions = true;
2254 _phySizeRel = (bool) i;
2256 if (option_or_sm == "__OPTIONS_BEGIN__")
2258 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2259 hasCustomOptions = true;
2260 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2261 hasPreCADOptions = true;
2262 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2264 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2265 hasAttractor = true;
2266 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2267 hasNewAttractor = true;
2268 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2269 hasEnforcedVertex = true;
2270 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2271 hasPreCADFacesPeriodicity = true;
2272 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2273 hasPreCADEdgesPeriodicity = true;
2274 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2275 hasFacesPeriodicity = true;
2276 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2277 hasEdgesPeriodicity = true;
2278 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2279 hasVerticesPeriodicity = true;
2281 if (isOK && hasCADSurfOptions) {
2282 isOK = static_cast<bool>(load >> i);
2284 _minSizeRel = (bool) i;
2286 load.clear(std::ios::badbit | load.rdstate());
2288 isOK = static_cast<bool>(load >> i);
2290 _maxSizeRel = (bool) i;
2292 load.clear(std::ios::badbit | load.rdstate());
2294 isOK = static_cast<bool>(load >> val);
2296 _chordalError = val;
2298 load.clear(std::ios::badbit | load.rdstate());
2300 isOK = static_cast<bool>(load >> i);
2302 _anisotropic = (bool) i;
2304 load.clear(std::ios::badbit | load.rdstate());
2306 isOK = static_cast<bool>(load >> val);
2308 _anisotropicRatio = val;
2310 load.clear(std::ios::badbit | load.rdstate());
2312 isOK = static_cast<bool>(load >> i);
2314 _removeTinyEdges = (bool) i;
2316 load.clear(std::ios::badbit | load.rdstate());
2318 isOK = static_cast<bool>(load >> val);
2320 _tinyEdgeLength = val;
2322 load.clear(std::ios::badbit | load.rdstate());
2324 isOK = static_cast<bool>(load >> i);
2326 _badElementRemoval = (bool) i;
2328 load.clear(std::ios::badbit | load.rdstate());
2330 isOK = static_cast<bool>(load >> val);
2332 _badElementAspectRatio = val;
2334 load.clear(std::ios::badbit | load.rdstate());
2336 isOK = static_cast<bool>(load >> i);
2338 _optimizeMesh = (bool) i;
2340 load.clear(std::ios::badbit | load.rdstate());
2342 isOK = static_cast<bool>(load >> i);
2344 _quadraticMesh = (bool) i;
2346 load.clear(std::ios::badbit | load.rdstate());
2348 isOK = static_cast<bool>(load >> i);
2350 _preCADProcess3DTopology = (bool) i;
2352 load.clear(std::ios::badbit | load.rdstate());
2354 if (( load >> std::ws).peek() != '_' )
2356 isOK = static_cast<bool>(load >> i);
2358 _preCADRemoveDuplicateCADFaces = (bool) i;
2360 load.clear(std::ios::badbit | load.rdstate());
2362 isOK = static_cast<bool>(load >> i);
2364 _preCADRemoveTinyUVEdges = (bool) i;
2366 load.clear(std::ios::badbit | load.rdstate());
2368 isOK = static_cast<bool>(load >> i);
2370 _optimiseTinyEdges = (bool) i;
2372 load.clear(std::ios::badbit | load.rdstate());
2374 isOK = static_cast<bool>(load >> val);
2376 _tinyEdgeOptimisationLength = val;
2378 load.clear(std::ios::badbit | load.rdstate());
2380 isOK = static_cast<bool>(load >> i);
2382 _correctSurfaceIntersec = (bool) i;
2384 load.clear(std::ios::badbit | load.rdstate());
2386 isOK = static_cast<bool>(load >> val);
2388 _corrSurfaceIntersCost = val;
2390 load.clear(std::ios::badbit | load.rdstate());
2392 isOK = static_cast<bool>(load >> i);
2394 _useGradation = (bool) i;
2396 load.clear(std::ios::badbit | load.rdstate());
2398 isOK = static_cast<bool>(load >> i);
2400 _useVolumeGradation = (bool) i;
2402 load.clear(std::ios::badbit | load.rdstate());
2404 isOK = static_cast<bool>(load >> val);
2406 _volumeGradation = val;
2408 load.clear(std::ios::badbit | load.rdstate());
2413 if (hasCADSurfOptions) {
2414 isOK = static_cast<bool>(load >> option_or_sm);
2416 if (option_or_sm == "__OPTIONS_BEGIN__")
2418 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2419 hasCustomOptions = true;
2420 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2421 hasPreCADOptions = true;
2422 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2424 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2425 hasAttractor = true;
2426 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2427 hasNewAttractor = true;
2428 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2429 hasEnforcedVertex = true;
2430 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2431 hasPreCADFacesPeriodicity = true;
2432 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2433 hasPreCADEdgesPeriodicity = true;
2434 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2435 hasFacesPeriodicity = true;
2436 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2437 hasEdgesPeriodicity = true;
2438 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2439 hasVerticesPeriodicity = true;
2443 std::string optName, optValue;
2444 while (isOK && hasOptions) {
2445 isOK = static_cast<bool>(load >> optName);
2447 if (optName == "__OPTIONS_END__")
2449 isOK = static_cast<bool>(load >> optValue);
2452 std::string & value = _option2value[optName];
2454 int len = value.size();
2455 // continue reading until "%#" encountered
2456 while (value[len - 1] != '#' || value[len - 2] != '%') {
2457 isOK = static_cast<bool>(load >> optValue);
2466 if ( value[ len - 1] == '#' )
2467 value.resize(len - 2); //cut off "%#"
2472 isOK = static_cast<bool>(load >> option_or_sm);
2474 if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2475 hasCustomOptions = true;
2476 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2477 hasPreCADOptions = true;
2478 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2480 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2481 hasAttractor = true;
2482 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2483 hasNewAttractor = true;
2484 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2485 hasEnforcedVertex = true;
2486 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2487 hasPreCADFacesPeriodicity = true;
2488 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2489 hasPreCADEdgesPeriodicity = true;
2490 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2491 hasFacesPeriodicity = true;
2492 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2493 hasEdgesPeriodicity = true;
2494 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2495 hasVerticesPeriodicity = true;
2499 while (isOK && hasCustomOptions) {
2500 isOK = static_cast<bool>(load >> optName);
2502 if (optName == "__CUSTOM_OPTIONS_END__")
2504 isOK = static_cast<bool>(load >> optValue);
2507 std::string& value = optValue;
2508 int len = value.size();
2509 // continue reading until "%#" encountered
2510 while (value[len - 1] != '#' || value[len - 2] != '%') {
2511 isOK = static_cast<bool>(load >> optValue);
2520 if ( value[ len - 1] == '#' )
2521 value.resize(len - 2); //cut off "%#"
2522 _customOption2value[optName] = value;
2526 if (hasCustomOptions) {
2527 isOK = static_cast<bool>(load >> option_or_sm);
2529 if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2530 hasPreCADOptions = true;
2531 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2533 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2534 hasAttractor = true;
2535 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2536 hasNewAttractor = true;
2537 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2538 hasEnforcedVertex = true;
2539 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2540 hasPreCADFacesPeriodicity = true;
2541 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2542 hasPreCADEdgesPeriodicity = true;
2543 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2544 hasFacesPeriodicity = true;
2545 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2546 hasEdgesPeriodicity = true;
2547 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2548 hasVerticesPeriodicity = true;
2552 while (isOK && hasPreCADOptions) {
2553 isOK = static_cast<bool>(load >> optName);
2555 if (optName == "__PRECAD_OPTIONS_END__")
2557 isOK = static_cast<bool>(load >> optValue);
2560 std::string & value = _preCADoption2value[optName];
2562 int len = value.size();
2563 // continue reading until "%#" encountered
2564 while (value[len - 1] != '#' || value[len - 2] != '%') {
2565 isOK = static_cast<bool>(load >> optValue);
2574 if ( value[ len - 1] == '#' )
2575 value.resize(len - 2); //cut off "%#"
2579 if (hasPreCADOptions) {
2580 isOK = static_cast<bool>(load >> option_or_sm);
2582 if (option_or_sm == "__SIZEMAP_BEGIN__")
2584 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2585 hasAttractor = true;
2586 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2587 hasNewAttractor = true;
2588 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2589 hasEnforcedVertex = true;
2590 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2591 hasPreCADFacesPeriodicity = true;
2592 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2593 hasPreCADEdgesPeriodicity = true;
2594 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2595 hasFacesPeriodicity = true;
2596 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2597 hasEdgesPeriodicity = true;
2598 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2599 hasVerticesPeriodicity = true;
2603 std::string smEntry, smValue;
2604 while (isOK && hasSizeMap) {
2605 isOK = static_cast<bool>(load >> smEntry);
2607 if (smEntry == "__SIZEMAP_END__")
2609 isOK = static_cast<bool>(load >> smValue);
2612 std::string & value2 = _sizeMap[smEntry];
2614 int len2 = value2.size();
2615 // continue reading until "%#" encountered
2616 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2617 isOK = static_cast<bool>(load >> smValue);
2621 len2 = value2.size();
2626 value2.resize(len2 - 2); //cut off "%#"
2631 isOK = static_cast<bool>(load >> option_or_sm);
2633 if (option_or_sm == "__ATTRACTORS_BEGIN__")
2634 hasAttractor = true;
2635 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2636 hasNewAttractor = true;
2637 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2638 hasEnforcedVertex = true;
2639 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2640 hasPreCADFacesPeriodicity = true;
2641 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2642 hasPreCADEdgesPeriodicity = true;
2643 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2644 hasFacesPeriodicity = true;
2645 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2646 hasEdgesPeriodicity = true;
2647 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2648 hasVerticesPeriodicity = true;
2651 std::string atEntry, atValue;
2652 while (isOK && hasAttractor) {
2653 isOK = static_cast<bool>(load >> atEntry);
2655 if (atEntry == "__ATTRACTORS_END__")
2657 isOK = static_cast<bool>(load >> atValue);
2660 std::string & value3 = _attractors[atEntry];
2662 int len3 = value3.size();
2663 // continue reading until "%#" encountered
2664 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
2665 isOK = static_cast<bool>(load >> atValue);
2669 len3 = value3.size();
2674 value3.resize(len3 - 2); //cut off "%#"
2679 isOK = static_cast<bool>(load >> option_or_sm);
2681 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2682 hasNewAttractor = true;
2683 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2684 hasEnforcedVertex = true;
2685 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2686 hasPreCADFacesPeriodicity = true;
2687 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2688 hasPreCADEdgesPeriodicity = true;
2689 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2690 hasFacesPeriodicity = true;
2691 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2692 hasEdgesPeriodicity = true;
2693 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2694 hasVerticesPeriodicity = true;
2698 std::string newAtFaceEntry, atTestString;
2699 std::string newAtShapeEntry;
2700 double attParams[4];
2702 while (isOK && hasNewAttractor) {
2703 //std::cout<<"Load new attractor"<<std::endl;
2704 isOK = static_cast<bool>(load >> newAtFaceEntry);
2706 if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
2708 isOK = static_cast<bool>(load >> newAtShapeEntry);
2711 isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
2714 const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
2715 const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
2716 BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
2717 attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
2718 //attractor->BuildMap();
2719 _classAttractors.insert( make_pair( newAtFaceEntry, attractor ));
2724 if (hasNewAttractor) {
2725 isOK = static_cast<bool>(load >> option_or_sm);
2727 if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2728 hasEnforcedVertex = true;
2729 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2730 hasPreCADFacesPeriodicity = true;
2731 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2732 hasPreCADEdgesPeriodicity = true;
2733 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2734 hasFacesPeriodicity = true;
2735 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2736 hasEdgesPeriodicity = true;
2737 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2738 hasVerticesPeriodicity = true;
2744 // Here is a example of the saved stream:
2745 // __ENFORCED_VERTICES_BEGIN__
2746 // __BEGIN_VERTEX__ => no name, no entry
2747 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2748 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__
2749 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__
2751 // __BEGIN_VERTEX__ => no coords
2752 // __BEGIN_NAME__ mes points __END_NAME__
2753 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
2754 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2755 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
2757 // __ENFORCED_VERTICES_END__
2760 std::string enfSeparator;
2761 std::string enfName;
2762 std::string enfGeomEntry;
2763 std::string enfGroup;
2764 TEntryList enfFaceEntryList;
2765 double enfCoords[3];
2766 bool hasCoords = false;
2768 _faceEntryEnfVertexListMap.clear();
2769 _enfVertexList.clear();
2770 _faceEntryCoordsListMap.clear();
2771 _coordsEnfVertexMap.clear();
2772 _faceEntryEnfVertexEntryListMap.clear();
2773 _enfVertexEntryEnfVertexMap.clear();
2776 while (isOK && hasEnforcedVertex) {
2777 isOK = static_cast<bool>(load >> enfSeparator); // __BEGIN_VERTEX__
2778 TEnfVertex *enfVertex = new TEnfVertex();
2779 if (enfSeparator == "__ENFORCED_VERTICES_END__")
2780 break; // __ENFORCED_VERTICES_END__
2781 if (enfSeparator != "__BEGIN_VERTEX__")
2782 throw std::exception();
2785 isOK = static_cast<bool>(load >> enfSeparator);
2786 if (enfSeparator == "__END_VERTEX__") {
2788 enfVertex->name = enfName;
2789 enfVertex->geomEntry = enfGeomEntry;
2790 enfVertex->grpName = enfGroup;
2791 enfVertex->coords.clear();
2793 enfVertex->coords.assign(enfCoords,enfCoords+3);
2794 enfVertex->faceEntries = enfFaceEntryList;
2796 _enfVertexList.insert(enfVertex);
2798 if (enfVertex->coords.size()) {
2799 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
2800 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2801 _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
2802 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2805 if (!enfVertex->geomEntry.empty()) {
2806 _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
2807 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2808 _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
2809 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2814 enfGeomEntry.clear();
2816 enfFaceEntryList.clear();
2818 break; // __END_VERTEX__
2821 if (enfSeparator == "__BEGIN_NAME__") { // __BEGIN_NAME__
2822 while (isOK && (enfSeparator != "__END_NAME__")) {
2823 isOK = static_cast<bool>(load >> enfSeparator);
2824 if (enfSeparator != "__END_NAME__") {
2825 if (!enfName.empty())
2827 enfName += enfSeparator;
2832 if (enfSeparator == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
2833 isOK = static_cast<bool>(load >> enfGeomEntry);
2834 isOK = static_cast<bool>(load >> enfSeparator); // __END_ENTRY__
2835 if (enfSeparator != "__END_ENTRY__")
2836 throw std::exception();
2839 if (enfSeparator == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
2840 while (isOK && (enfSeparator != "__END_GROUP__")) {
2841 isOK = static_cast<bool>(load >> enfSeparator);
2842 if (enfSeparator != "__END_GROUP__") {
2843 if (!enfGroup.empty())
2845 enfGroup += enfSeparator;
2850 if (enfSeparator == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
2852 isOK = static_cast<bool>(load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
2853 isOK = static_cast<bool>(load >> enfSeparator); // __END_COORDS__
2854 if (enfSeparator != "__END_COORDS__")
2855 throw std::exception();
2858 if (enfSeparator == "__BEGIN_FACELIST__") { // __BEGIN_FACELIST__
2859 while (isOK && (enfSeparator != "__END_FACELIST__")) {
2860 isOK = static_cast<bool>(load >> enfSeparator);
2861 if (enfSeparator != "__END_FACELIST__") {
2862 enfFaceEntryList.insert(enfSeparator);
2871 if (hasPreCADFacesPeriodicity){
2872 LoadPreCADPeriodicity(load, "FACES");
2874 isOK = static_cast<bool>(load >> option_or_sm);
2876 if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2877 hasPreCADEdgesPeriodicity = true;
2878 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2879 hasFacesPeriodicity = true;
2880 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2881 hasEdgesPeriodicity = true;
2882 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2883 hasVerticesPeriodicity = true;
2887 if (hasPreCADEdgesPeriodicity){
2888 LoadPreCADPeriodicity(load, "EDGES");
2890 isOK = static_cast<bool>(load >> option_or_sm);
2892 if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2893 hasFacesPeriodicity = true;
2894 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2895 hasEdgesPeriodicity = true;
2896 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2897 hasVerticesPeriodicity = true;
2901 if (hasFacesPeriodicity){
2902 LoadFacesPeriodicity(load);
2904 isOK = static_cast<bool>(load >> option_or_sm);
2906 if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2907 hasEdgesPeriodicity = true;
2908 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2909 hasVerticesPeriodicity = true;
2913 if (hasEdgesPeriodicity){
2914 LoadEdgesPeriodicity(load);
2916 isOK = static_cast<bool>(load >> option_or_sm);
2918 if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2919 hasVerticesPeriodicity = true;
2922 if (hasVerticesPeriodicity)
2923 LoadVerticesPeriodicity(load);
2928 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
2932 std::string periodicitySeparator;
2936 _facesPeriodicityVector.clear();
2939 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2940 TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
2941 if (periodicitySeparator == "__FACES_PERIODICITY_END__")
2942 break; // __FACES_PERIODICITY_END__
2943 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2944 throw std::exception();
2948 isOK = static_cast<bool>(load >> periodicitySeparator);
2949 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2951 periodicity_i->first = shape1Entry;
2952 periodicity_i->second = shape2Entry;
2954 _facesPeriodicityVector.push_back(*periodicity_i);
2956 break; // __END_PERIODICITY_DESCRIPTION__
2959 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
2960 isOK = static_cast<bool>(load >> shape1Entry);
2961 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
2962 if (periodicitySeparator != "__END_ENTRY1__")
2963 throw std::exception();
2966 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
2967 isOK = static_cast<bool>(load >> shape2Entry);
2968 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
2969 if (periodicitySeparator != "__END_ENTRY2__")
2970 throw std::exception();
2977 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
2981 std::string periodicitySeparator;
2982 TEntry theFace1Entry;
2983 TEntry theEdge1Entry;
2984 TEntry theFace2Entry;
2985 TEntry theEdge2Entry;
2986 int edge_orientation = 0;
2988 _edgesPeriodicityVector.clear();
2991 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2992 TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
2993 if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
2994 break; // __EDGES_PERIODICITY_END__
2995 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2996 throw std::exception();
3000 isOK = static_cast<bool>(load >> periodicitySeparator);
3001 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3003 periodicity_i->theFace1Entry = theFace1Entry;
3004 periodicity_i->theEdge1Entry = theEdge1Entry;
3005 periodicity_i->theFace2Entry = theFace2Entry;
3006 periodicity_i->theEdge2Entry = theEdge2Entry;
3007 periodicity_i->edge_orientation = edge_orientation;
3009 _edgesPeriodicityVector.push_back(*periodicity_i);
3011 break; // __END_PERIODICITY_DESCRIPTION__
3014 if (periodicitySeparator == "__BEGIN_FACE1__") { // __BEGIN_FACE1__
3015 isOK = static_cast<bool>(load >> theFace1Entry);
3016 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE1__
3017 if (periodicitySeparator != "__END_FACE1__"){
3018 throw std::exception();
3022 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3023 isOK = static_cast<bool>(load >> theEdge1Entry);
3024 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3025 if (periodicitySeparator != "__END_EDGE1__")
3026 throw std::exception();
3029 if (periodicitySeparator == "__BEGIN_FACE2__") { // __BEGIN_FACE2__
3030 isOK = static_cast<bool>(load >> theFace2Entry);
3031 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE2__
3032 if (periodicitySeparator != "__END_FACE2__")
3033 throw std::exception();
3036 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3037 isOK = static_cast<bool>(load >> theEdge2Entry);
3038 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3039 if (periodicitySeparator != "__END_EDGE2__")
3040 throw std::exception();
3043 if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") { // __BEGIN_EDGE_ORIENTATION__
3044 isOK = static_cast<bool>(load >> edge_orientation);
3045 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
3046 if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
3047 throw std::exception();
3053 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
3057 std::string periodicitySeparator;
3058 TEntry theEdge1Entry;
3059 TEntry theVertex1Entry;
3060 TEntry theEdge2Entry;
3061 TEntry theVertex2Entry;
3063 _verticesPeriodicityVector.clear();
3066 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3067 TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
3068 if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
3069 break; // __VERTICES_PERIODICITY_END__
3070 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3071 throw std::exception();
3075 isOK = static_cast<bool>(load >> periodicitySeparator);
3076 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3078 periodicity_i->theEdge1Entry = theEdge1Entry;
3079 periodicity_i->theVertex1Entry = theVertex1Entry;
3080 periodicity_i->theEdge2Entry = theEdge2Entry;
3081 periodicity_i->theVertex2Entry = theVertex2Entry;
3083 _verticesPeriodicityVector.push_back(*periodicity_i);
3085 break; // __END_PERIODICITY_DESCRIPTION__
3088 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3089 isOK = static_cast<bool>(load >> theEdge1Entry);
3090 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3091 if (periodicitySeparator != "__END_EDGE1__")
3092 throw std::exception();
3095 if (periodicitySeparator == "__BEGIN_VERTEX1__") { // __BEGIN_VERTEX1__
3096 isOK = static_cast<bool>(load >> theVertex1Entry);
3097 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX1__
3098 if (periodicitySeparator != "__END_VERTEX1__")
3099 throw std::exception();
3102 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3103 isOK = static_cast<bool>(load >> theEdge2Entry);
3104 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3105 if (periodicitySeparator != "__END_EDGE2__")
3106 throw std::exception();
3109 if (periodicitySeparator == "__BEGIN_VERTEX2__") { // __BEGIN_VERTEX2__
3110 isOK = static_cast<bool>(load >> theVertex2Entry);
3111 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX2__
3112 if (periodicitySeparator != "__END_VERTEX2__")
3113 throw std::exception();
3119 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
3123 std::string periodicitySeparator;
3126 std::vector<std::string> theSourceVerticesEntries;
3127 std::vector<std::string> theTargetVerticesEntries;
3129 bool hasSourceVertices = false;
3130 bool hasTargetVertices = false;
3132 if ( shapeType && strcmp( shapeType, "FACES") == 0 )
3133 _preCadFacesPeriodicityVector.clear();
3135 _preCadEdgesPeriodicityVector.clear();
3139 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3140 TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
3141 std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
3142 if (periodicitySeparator == endSeparator)
3143 break; // __PRECAD_FACES_PERIODICITY_END__
3144 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3145 throw std::exception();
3149 isOK = static_cast<bool>(load >> periodicitySeparator);
3150 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3152 periodicity_i->shape1Entry = shape1Entry;
3153 periodicity_i->shape2Entry = shape2Entry;
3155 if (hasSourceVertices)
3156 periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
3157 if (hasTargetVertices)
3158 periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
3160 if ( shapeType && strcmp( shapeType, "FACES" ))
3161 _preCadFacesPeriodicityVector.push_back(*periodicity_i);
3163 _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
3165 theSourceVerticesEntries.clear();
3166 theTargetVerticesEntries.clear();
3167 hasSourceVertices = false;
3168 hasTargetVertices = false;
3169 break; // __END_PERIODICITY_DESCRIPTION__
3172 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3173 isOK = static_cast<bool>(load >> shape1Entry);
3174 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3175 if (periodicitySeparator != "__END_ENTRY1__")
3176 throw std::exception();
3179 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3180 isOK = static_cast<bool>(load >> shape2Entry);
3181 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3182 if (periodicitySeparator != "__END_ENTRY2__")
3183 throw std::exception();
3186 if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") { // __BEGIN_SOURCE_VERTICES_LIST__
3187 hasSourceVertices = true;
3188 while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
3189 isOK = static_cast<bool>(load >> periodicitySeparator);
3190 if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
3191 theSourceVerticesEntries.push_back(periodicitySeparator);
3196 if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") { // __BEGIN_TARGET_VERTICES_LIST__
3197 hasTargetVertices = true;
3198 while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
3199 isOK = static_cast<bool>(load >> periodicitySeparator);
3200 if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
3201 theTargetVerticesEntries.push_back(periodicitySeparator);
3209 //=============================================================================
3210 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
3211 return hyp.SaveTo(save);
3214 //=============================================================================
3215 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
3216 return hyp.LoadFrom(load);
3219 //================================================================================
3221 * \brief Does nothing
3223 //================================================================================
3225 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
3229 //================================================================================
3231 * \brief Returns default global constant physical size given a default value of element length ratio
3233 //================================================================================
3235 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
3236 if (bbSegmentation != 0 && diagonal != 0)
3237 return diagonal / bbSegmentation ;
3241 //================================================================================
3243 * \brief Returns default min size given a default value of element length ratio
3245 //================================================================================
3247 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
3249 return diagonal / 1000.0 ;
3250 return undefinedDouble();
3253 //================================================================================
3255 * \brief Returns default max size given a default value of element length ratio
3257 //================================================================================
3259 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
3261 return diagonal / 5.0 ;
3262 return undefinedDouble();
3265 //================================================================================
3267 * \brief Returns default chordal error given a default value of element length ratio
3269 //================================================================================
3271 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
3274 return undefinedDouble();
3277 //================================================================================
3279 * \brief Returns default tiny edge length given a default value of element length ratio
3281 //================================================================================
3283 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
3285 return diagonal * 1e-6 ;
3286 return undefinedDouble();
3289 //================================================================================
3291 * \brief Returns default tiny edge optimisation length given a default value of element length ratio
3293 //================================================================================
3295 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal) {
3297 return diagonal * 1e-6 ;
3298 return undefinedDouble();
3301 //=============================================================================
3303 * \brief Initialize my parameter values by default parameters.
3304 * \retval bool - true if parameter values have been successfully defined
3306 //=============================================================================
3308 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
3309 double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
3310 _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
3311 _minSize = GetDefaultMinSize(diagonal);
3312 _maxSize = GetDefaultMaxSize(diagonal);
3313 _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
3314 _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
3315 _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(diagonal);
3320 //================================================================================
3322 * \brief Converts a string to a bool
3324 //================================================================================
3326 bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
3327 throw (std::invalid_argument)
3329 std::string s = str;
3330 if ( isOk ) *isOk = true;
3332 for ( size_t i = 0; i <= s.size(); ++i )
3333 s[i] = tolower( s[i] );
3335 if ( s == "1" || s == "true" || s == "active" || s == "yes" )
3338 if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
3344 std::string msg = "Not a Boolean value:'" + str + "'";
3345 throw std::invalid_argument(msg);
3350 //================================================================================
3352 * \brief Converts a string to a real value
3354 //================================================================================
3356 double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
3357 throw (std::invalid_argument)
3359 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3362 double val = strtod(&str[0], &endPtr);
3363 bool ok = (&str[0] != endPtr);
3365 if ( isOk ) *isOk = ok;
3369 std::string msg = "Not a real value:'" + str + "'";
3370 throw std::invalid_argument(msg);
3375 //================================================================================
3377 * \brief Converts a string to a integer value
3379 //================================================================================
3381 int BLSURFPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
3382 throw (std::invalid_argument)
3384 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3387 int val = (int)strtol( &str[0], &endPtr, 10);
3388 bool ok = (&str[0] != endPtr);
3390 if ( isOk ) *isOk = ok;
3394 std::string msg = "Not an integer value:'" + str + "'";
3395 throw std::invalid_argument(msg);