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 // "remove_tiny_edges", // default = 0
147 const char* preCADintOptionNames[] = { // "manifold_geometry", // default = 0
150 const char* preCADdoubleOptionNames[] = { "periodic_tolerance", // default = diag * 1e-5
151 "sewing_tolerance", // default = diag * 5e-4
152 // "tiny_edge_length", // default = diag * 1e-5
155 const char* preCADcharOptionNames[] = { "required_entities", // default = "respect"
156 "tags", // default = "respect"
161 while (boolOptionNames[i][0])
163 _boolOptions.insert( boolOptionNames[i] );
164 _option2value[boolOptionNames[i++]].clear();
167 while (preCADboolOptionNames[i][0])
169 _boolOptions.insert( preCADboolOptionNames[i] );
170 _preCADoption2value[preCADboolOptionNames[i++]].clear();
173 while (intOptionNames[i][0])
174 _option2value[intOptionNames[i++]].clear();
177 while (preCADintOptionNames[i][0])
178 _preCADoption2value[preCADintOptionNames[i++]].clear();
181 while (doubleOptionNames[i][0]) {
182 _doubleOptions.insert(doubleOptionNames[i]);
183 _option2value[doubleOptionNames[i++]].clear();
186 while (preCADdoubleOptionNames[i][0]) {
187 _preCADdoubleOptions.insert(preCADdoubleOptionNames[i]);
188 _preCADoption2value[preCADdoubleOptionNames[i++]].clear();
191 while (charOptionNames[i][0]) {
192 _charOptions.insert(charOptionNames[i]);
193 _option2value[charOptionNames[i++]].clear();
196 while (preCADcharOptionNames[i][0]) {
197 _preCADcharOptions.insert(preCADcharOptionNames[i]);
198 _preCADoption2value[preCADcharOptionNames[i++]].clear();
201 // default values to be used while MG meshing
203 _defaultOptionValues["enforce_cad_edge_sizes" ] = "no";
204 _defaultOptionValues["jacobian_rectification_respect_geometry"] = "yes";
205 _defaultOptionValues["max_number_of_points_per_patch" ] = "0";
206 _defaultOptionValues["rectify_jacobian" ] = "yes";
207 _defaultOptionValues["respect_geometry" ] = "yes";
208 _defaultOptionValues["tiny_edge_avoid_surface_intersections" ] = "yes";
209 _defaultOptionValues["closed_geometry" ] = "no";
210 _defaultOptionValues["debug" ] = "no";
211 _defaultOptionValues["discard_input_topology" ] = "no";
212 _defaultOptionValues["merge_edges" ] = "no";
213 _defaultOptionValues["periodic_tolerance" ] = "1e-5*D";
214 _defaultOptionValues["remove_duplicate_cad_faces" ] = "no";
215 _defaultOptionValues["required_entities" ] = "respect";
216 _defaultOptionValues["sewing_tolerance" ] = "5e-4*D";
217 _defaultOptionValues["tags" ] = "respect";
220 // check validity of option names of _defaultOptionValues
221 TOptionValues::iterator n2v = _defaultOptionValues.begin();
222 for ( ; n2v != _defaultOptionValues.end(); ++n2v )
223 ASSERT( _option2value.count( n2v->first ) || _preCADoption2value.count( n2v->first ));
224 ASSERT( _option2value.size() + _preCADoption2value.size() == _defaultOptionValues.size() );
229 _faceEntryEnfVertexListMap.clear();
230 _enfVertexList.clear();
231 _faceEntryCoordsListMap.clear();
232 _coordsEnfVertexMap.clear();
233 _faceEntryEnfVertexEntryListMap.clear();
234 _enfVertexEntryEnfVertexMap.clear();
235 _groupNameNodeIDMap.clear();
238 _groupNameEnfVertexListMap.clear();
239 _enfVertexGroupNameMap.clear();
243 TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry)
245 MESSAGE("BLSURFPlugin_Hypothesis::entryToShape "<<entry );
246 GEOM::GEOM_Object_var aGeomObj;
247 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
248 SALOMEDS::Study_ptr myStudy = smeshGen_i->GetCurrentStudy();
250 TopoDS_Shape S = TopoDS_Shape();
251 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
252 if (!aSObj->_is_nil() ) {
253 CORBA::Object_var obj = aSObj->GetObject();
254 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
257 if ( !aGeomObj->_is_nil() )
258 S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
262 //=============================================================================
263 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
264 if (thePhysicalMesh != _physicalMesh) {
265 _physicalMesh = thePhysicalMesh;
266 NotifySubMeshesHypothesisModification();
270 //=============================================================================
271 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
272 if (theGeometricMesh != _geometricMesh) {
273 _geometricMesh = theGeometricMesh;
274 // switch (_geometricMesh) {
277 // _angleMesh = GetDefaultAngleMesh();
278 // _gradation = GetDefaultGradation();
281 NotifySubMeshesHypothesisModification();
285 //=============================================================================
286 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal, bool isRelative) {
287 if ((theVal != _phySize) || (isRelative != _phySizeRel)) {
288 _phySizeRel = isRelative;
290 _phySize = GetMaxSize();
291 MESSAGE("Warning: nul physical size is not allowed");
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 != _preCADMergeEdges) {
690 // SetTopology(PreCAD);
691 _preCADMergeEdges = theVal;
692 SetPreCADOptionValue("merge_edges", theVal ? "yes" : "no" );
693 NotifySubMeshesHypothesisModification();
697 //=============================================================================
698 void BLSURFPlugin_Hypothesis::SetPreCADRemoveTinyUVEdges(bool theVal)
700 if (theVal != _preCADRemoveTinyUVEdges) {
701 // SetTopology(PreCAD);
702 _preCADRemoveTinyUVEdges = theVal;
703 NotifySubMeshesHypothesisModification();
707 //=============================================================================
708 void BLSURFPlugin_Hypothesis::SetPreCADRemoveDuplicateCADFaces(bool theVal)
710 if (theVal != _preCADRemoveDuplicateCADFaces) {
711 // SetTopology(PreCAD);
712 _preCADRemoveDuplicateCADFaces = theVal;
713 SetPreCADOptionValue("remove_duplicate_cad_faces", theVal ? "yes" : "no" );
714 NotifySubMeshesHypothesisModification();
718 //=============================================================================
719 void BLSURFPlugin_Hypothesis::SetPreCADProcess3DTopology(bool theVal)
721 if (theVal != _preCADProcess3DTopology) {
722 // SetTopology(PreCAD);
723 _preCADProcess3DTopology = theVal;
724 NotifySubMeshesHypothesisModification();
728 //=============================================================================
729 void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal)
731 if (theVal != _preCADDiscardInput) {
732 // SetTopology(PreCAD);
733 _preCADDiscardInput = theVal;
734 SetPreCADOptionValue("discard_input_topology", theVal ? "yes" : "no" );
735 NotifySubMeshesHypothesisModification();
739 //=============================================================================
740 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
741 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
743 _GMFFileName = theFileName;
744 // _GMFFileMode = isBinary;
745 NotifySubMeshesHypothesisModification();
748 //=============================================================================
749 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
750 throw (std::invalid_argument) {
752 TOptionValues::iterator op_val = _option2value.find(optionName);
753 if (op_val == _option2value.end())
755 op_val = _preCADoption2value.find(optionName);
756 if (op_val == _preCADoption2value.end())
758 std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'. Try SetAdvancedOption()";
759 throw std::invalid_argument(msg);
762 if (op_val->second != optionValue)
764 const char* ptr = optionValue.c_str();
765 // strip white spaces
766 while (ptr[0] == ' ')
769 while (i != 0 && ptr[i - 1] == ' ')
773 std::string typeName;
776 } else if (_charOptions.count(optionName)) {
777 // do not check strings
778 } else if (_doubleOptions.count(optionName)) {
779 // check if value is double
782 } else if (_boolOptions.count(optionName)) {
783 // check if value is bool
784 ToBool(ptr, &typeOk);
787 // check if value is int
789 typeName = "integer";
792 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
793 throw std::invalid_argument(msg);
795 std::string value( ptr, i );
796 if ( _defaultOptionValues[ optionName ] == value )
799 op_val->second = value;
801 NotifySubMeshesHypothesisModification();
805 //=============================================================================
806 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
807 throw (std::invalid_argument) {
809 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
810 if (op_val == _preCADoption2value.end()) {
811 op_val = _option2value.find(optionName);
812 if (op_val == _option2value.end()) {
813 std::string msg = "Unknown MG-PreCAD option: '" + optionName + "'. Try SetAdvancedOption()";
814 throw std::invalid_argument(msg);
817 if (op_val->second != optionValue)
819 const char* ptr = optionValue.c_str();
820 // strip white spaces
821 while (ptr[0] == ' ')
824 while (i != 0 && ptr[i - 1] == ' ')
828 std::string typeName;
831 } else if (_preCADcharOptions.find(optionName) != _preCADcharOptions.end()) {
832 // do not check strings
833 } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
834 // check if value is double
836 strtod(ptr, &endPtr);
837 typeOk = (ptr != endPtr);
839 } else if (_boolOptions.count(optionName)) {
840 // check if value is bool
841 ToBool(ptr, &typeOk);
844 // check if value is int
846 strtol(ptr, &endPtr, 10);
847 typeOk = (ptr != endPtr);
848 typeName = "integer";
851 std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
852 throw std::invalid_argument(msg);
854 std::string value( ptr, i );
855 if ( _defaultOptionValues[ optionName ] == value )
858 op_val->second = value;
860 NotifySubMeshesHypothesisModification();
864 //=============================================================================
865 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
866 bool* isDefault) const
867 throw (std::invalid_argument)
869 TOptionValues::const_iterator op_val = _option2value.find(optionName);
870 if (op_val == _option2value.end())
872 op_val = _preCADoption2value.find(optionName);
873 if (op_val == _preCADoption2value.end())
875 op_val = _customOption2value.find(optionName);
876 if (op_val == _customOption2value.end())
878 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
879 throw std::invalid_argument(msg);
883 std::string val = op_val->second;
884 if ( isDefault ) *isDefault = ( val.empty() );
886 if ( val.empty() && isDefault )
888 op_val = _defaultOptionValues.find( optionName );
889 if (op_val != _defaultOptionValues.end())
890 val = op_val->second;
895 //=============================================================================
896 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName,
897 bool* isDefault) const
898 throw (std::invalid_argument)
900 TOptionValues::const_iterator op_val = _preCADoption2value.find(optionName);
901 if (op_val == _preCADoption2value.end())
903 op_val = _option2value.find(optionName);
904 if (op_val == _option2value.end())
906 op_val = _customOption2value.find(optionName);
907 if (op_val == _customOption2value.end())
909 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
910 throw std::invalid_argument(msg);
914 std::string val = op_val->second;
915 if ( isDefault ) *isDefault = ( val.empty() );
917 if ( val.empty() && isDefault )
919 op_val = _defaultOptionValues.find( optionName );
920 if (op_val != _option2value.end())
921 val = op_val->second;
926 //=============================================================================
927 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
929 TOptionValues::iterator op_val = _customOption2value.find(optionName);
930 if (op_val != _customOption2value.end())
931 _customOption2value.erase(op_val);
933 op_val = _option2value.find(optionName);
934 if (op_val != _option2value.end())
935 op_val->second.clear();
937 op_val = _preCADoption2value.find(optionName);
938 if (op_val != _preCADoption2value.end())
939 op_val->second.clear();
944 //=============================================================================
945 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName)
947 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
948 if (op_val != _preCADoption2value.end())
949 op_val->second.clear();
952 //=============================================================================
953 void BLSURFPlugin_Hypothesis::AddOption(const std::string& optionName, const std::string& optionValue)
956 TOptionValues::iterator op_val = _option2value.find(optionName);
957 if (op_val != _option2value.end())
959 if (op_val->second != optionValue)
960 op_val->second = optionValue;
966 op_val = _preCADoption2value.find(optionName);
967 if (op_val != _preCADoption2value.end())
969 if (op_val->second != optionValue)
970 op_val->second = optionValue;
974 else if ( optionValue.empty() )
976 _customOption2value.erase( optionName );
980 op_val = _customOption2value.find(optionName);
981 if (op_val == _customOption2value.end())
982 _customOption2value[optionName] = optionValue;
983 else if (op_val->second != optionValue)
984 op_val->second = optionValue;
990 NotifySubMeshesHypothesisModification();
993 //=============================================================================
994 void BLSURFPlugin_Hypothesis::AddPreCADOption(const std::string& optionName, const std::string& optionValue)
996 AddOption( optionName, optionValue );
999 //=============================================================================
1000 std::string BLSURFPlugin_Hypothesis::GetOption(const std::string& optionName)
1002 TOptionValues::iterator op_val = _customOption2value.find(optionName);
1003 if (op_val != _customOption2value.end())
1004 return op_val->second;
1009 //=============================================================================
1010 std::string BLSURFPlugin_Hypothesis::GetPreCADOption(const std::string& optionName)
1012 TOptionValues::iterator op_val = _customOption2value.find(optionName);
1013 if (op_val != _customOption2value.end())
1014 return op_val->second;
1019 //=============================================================================
1020 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetOptionValues() const
1023 TOptionValues::const_iterator op_val = _option2value.begin();
1024 for ( ; op_val != _option2value.end(); ++op_val )
1025 vals.insert( make_pair( op_val->first, GetOptionValue( op_val->first, GET_DEFAULT() )));
1030 //=============================================================================
1031 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetPreCADOptionValues() const
1034 TOptionValues::const_iterator op_val = _preCADoption2value.begin();
1035 for ( ; op_val != _preCADoption2value.end(); ++op_val )
1036 vals.insert( make_pair( op_val->first, GetPreCADOptionValue( op_val->first, GET_DEFAULT() )));
1041 //=======================================================================
1042 //function : SetSizeMapEntry
1043 //=======================================================================
1044 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
1045 if (_sizeMap[entry].compare(sizeMap) != 0) {
1046 SetPhysicalMesh(PhysicalLocalSize);
1047 _sizeMap[entry] = sizeMap;
1048 NotifySubMeshesHypothesisModification();
1052 //=======================================================================
1053 //function : GetSizeMapEntry
1054 //=======================================================================
1055 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
1056 TSizeMap::iterator it = _sizeMap.find(entry);
1057 if (it != _sizeMap.end())
1060 return "No_Such_Entry";
1064 * \brief Return the size maps
1066 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
1067 return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
1070 //=======================================================================
1071 //function : SetAttractorEntry
1072 //=======================================================================
1073 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
1074 if (_attractors[entry].compare(attractor) != 0) {
1075 SetPhysicalMesh(PhysicalLocalSize);
1076 _attractors[entry] = attractor;
1077 NotifySubMeshesHypothesisModification();
1081 //=======================================================================
1082 //function : GetAttractorEntry
1083 //=======================================================================
1084 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
1085 TSizeMap::iterator it = _attractors.find(entry);
1086 if (it != _attractors.end())
1089 return "No_Such_Entry";
1093 * \brief Return the attractors
1095 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
1096 return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
1099 //=======================================================================
1100 //function : SetClassAttractorEntry
1101 //=======================================================================
1102 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
1104 SetPhysicalMesh(PhysicalLocalSize);
1106 // The new attractor can't be defined on the same face as another sizemap
1107 TSizeMap::iterator it = _sizeMap.find( entry );
1108 if ( it != _sizeMap.end() ) {
1110 NotifySubMeshesHypothesisModification();
1113 TSizeMap::iterator itAt = _attractors.find( entry );
1114 if ( itAt != _attractors.end() ) {
1115 _attractors.erase(itAt);
1116 NotifySubMeshesHypothesisModification();
1120 const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
1121 const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
1122 TAttractorMap::iterator attIt = _classAttractors.find(entry);
1123 for ( ; attIt != _classAttractors.end(); ++attIt )
1124 if ( attIt->first == entry &&
1125 attIt->second->GetAttractorEntry() == attEntry )
1127 bool attExists = (attIt != _classAttractors.end());
1129 BLSURFPlugin_Attractor* myAttractor;
1131 myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 );
1132 _classAttractors.insert( make_pair( entry, myAttractor ));
1135 myAttractor = attIt->second;
1137 // if (!myAttractor->IsMapBuilt())
1138 // myAttractor->BuildMap();
1139 myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
1141 NotifySubMeshesHypothesisModification();
1144 //=======================================================================
1145 //function : SetConstantSizeOnAdjacentFaces
1146 //=======================================================================
1147 // TODO uncomment and test (include the needed .hxx)
1148 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist ) {
1149 // TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
1150 // TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
1151 // TopTools_IndexedMapOfShapListOdShape::iterator it;
1152 // for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
1153 // SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
1161 //=======================================================================
1162 //function : GetClassAttractorEntry
1163 //=======================================================================
1164 // BLSURFPlugin_Attractor& BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
1166 // TAttractorMap::iterator it = _classAttractors.find( entry );
1167 // if ( it != _classAttractors.end() )
1168 // return it->second;
1170 // return "No_Such_Entry";
1174 * \brief Return the map of attractor instances
1176 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
1178 return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
1181 //=======================================================================
1182 //function : ClearEntry
1183 //=======================================================================
1184 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
1185 const char * attEntry/*=0*/)
1187 TSizeMap::iterator it = _sizeMap.find( entry );
1189 if ( it != _sizeMap.end() ) {
1191 NotifySubMeshesHypothesisModification();
1194 TSizeMap::iterator itAt = _attractors.find( entry );
1195 if ( itAt != _attractors.end() ) {
1196 _attractors.erase(itAt);
1197 NotifySubMeshesHypothesisModification();
1200 TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
1201 if ( it_clAt != _classAttractors.end() ) {
1203 if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
1204 _classAttractors.erase( it_clAt++ );
1208 while ( it_clAt != _classAttractors.end() );
1209 MESSAGE("_classAttractors.size() = "<<_classAttractors.size())
1210 NotifySubMeshesHypothesisModification();
1213 std::cout<<"No_Such_Entry"<<std::endl;
1218 //=======================================================================
1219 //function : ClearSizeMaps
1220 //=======================================================================
1221 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
1223 _attractors.clear();
1224 _classAttractors.clear();
1227 // Enable internal enforced vertices on specific face if requested by user
1229 ////=======================================================================
1230 ////function : SetInternalEnforcedVertex
1231 ////=======================================================================
1232 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
1233 // bool toEnforceInternalVertices,
1234 // TEnfGroupName theGroupName) {
1236 // MESSAGE("BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex("<< theFaceEntry << ", "
1237 // << toEnforceInternalVertices << ", " << theGroupName << ")");
1239 // TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
1240 // if (it != _faceEntryInternalVerticesList.end()) {
1241 // if (!toEnforceInternalVertices) {
1242 // _faceEntryInternalVerticesList.erase(it);
1246 // if (toEnforceInternalVertices) {
1247 // _faceEntryInternalVerticesList.insert(theFaceEntry);
1252 // // Take care of groups
1256 //=======================================================================
1257 //function : SetEnforcedVertex
1258 //=======================================================================
1259 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
1260 TEnfGroupName theGroupName, double x, double y, double z) {
1262 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
1263 << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
1265 SetPhysicalMesh(PhysicalLocalSize);
1267 // TEnfVertexList::iterator it;
1268 bool toNotify = false;
1269 bool toCreate = true;
1271 TEnfVertex *oldEnVertex;
1272 TEnfVertex *newEnfVertex = new TEnfVertex();
1273 newEnfVertex->name = theVertexName;
1274 newEnfVertex->geomEntry = theVertexEntry;
1275 newEnfVertex->coords.clear();
1276 if (theVertexEntry == "") {
1277 newEnfVertex->coords.push_back(x);
1278 newEnfVertex->coords.push_back(y);
1279 newEnfVertex->coords.push_back(z);
1281 newEnfVertex->grpName = theGroupName;
1282 newEnfVertex->faceEntries.clear();
1283 newEnfVertex->faceEntries.insert(theFaceEntry);
1286 // update _enfVertexList
1287 TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
1288 if (it != _enfVertexList.end()) {
1290 oldEnVertex = (*it);
1291 MESSAGE("Enforced Vertex was found => Update");
1292 if (oldEnVertex->name != theVertexName) {
1293 MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
1294 oldEnVertex->name = theVertexName;
1297 if (oldEnVertex->grpName != theGroupName) {
1298 MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
1299 oldEnVertex->grpName = theGroupName;
1302 TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
1303 if (it_faceEntries == oldEnVertex->faceEntries.end()) {
1304 MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
1305 oldEnVertex->faceEntries.insert(theFaceEntry);
1306 _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
1310 // update map coords / enf vertex if needed
1311 if (oldEnVertex->coords.size()) {
1312 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
1313 _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
1316 // update map geom entry / enf vertex if needed
1317 if (oldEnVertex->geomEntry != "") {
1318 _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
1319 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
1324 // //////// CREATE ////////////
1327 MESSAGE("Creating new enforced vertex");
1328 _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
1329 _enfVertexList.insert(newEnfVertex);
1330 if (theVertexEntry == "") {
1331 _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
1332 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
1335 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
1336 _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
1341 NotifySubMeshesHypothesisModification();
1343 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
1348 //=======================================================================
1349 //function : GetEnforcedVertices
1350 //=======================================================================
1352 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
1353 throw (std::invalid_argument) {
1355 if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
1356 return _faceEntryEnfVertexListMap[theFaceEntry];
1358 return GetDefaultEnfVertexList();
1360 std::ostringstream msg;
1361 msg << "No enforced vertex for face entry " << theFaceEntry;
1362 throw std::invalid_argument(msg.str());
1365 //=======================================================================
1366 //function : GetEnfVertexCoordsList
1367 //=======================================================================
1369 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
1370 const TEntry& theFaceEntry) throw (std::invalid_argument) {
1372 if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
1373 return _faceEntryCoordsListMap[theFaceEntry];
1375 std::ostringstream msg;
1376 msg << "No enforced vertex coords for face entry " << theFaceEntry;
1377 throw std::invalid_argument(msg.str());
1380 //=======================================================================
1381 //function : GetEnfVertexEntryList
1382 //=======================================================================
1384 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
1385 throw (std::invalid_argument) {
1387 if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
1388 return _faceEntryEnfVertexEntryListMap[theFaceEntry];
1390 std::ostringstream msg;
1391 msg << "No enforced vertex entry for face entry " << theFaceEntry;
1392 throw std::invalid_argument(msg.str());
1395 //=======================================================================
1396 //function : GetEnfVertex(TEnfVertexCoords coords)
1397 //=======================================================================
1399 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
1400 throw (std::invalid_argument) {
1402 if (_coordsEnfVertexMap.count(coords) > 0)
1403 return _coordsEnfVertexMap[coords];
1405 std::ostringstream msg;
1406 msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
1407 throw std::invalid_argument(msg.str());
1410 //=======================================================================
1411 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
1412 //=======================================================================
1414 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
1415 throw (std::invalid_argument) {
1417 if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
1418 return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
1420 std::ostringstream msg;
1421 msg << "No enforced vertex with entry " << theEnfVertexEntry;
1422 throw std::invalid_argument(msg.str());
1425 //Enable internal enforced vertices on specific face if requested by user
1426 ////=======================================================================
1427 ////function : GetInternalEnforcedVertex
1428 ////=======================================================================
1430 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
1432 // if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
1437 //=======================================================================
1438 //function : ClearEnforcedVertex
1439 //=======================================================================
1441 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
1442 const TEntry& theVertexEntry) throw (std::invalid_argument) {
1444 bool toNotify = false;
1445 std::ostringstream msg;
1446 TEnfVertex *oldEnfVertex;
1447 TEnfVertexCoords coords;
1449 coords.push_back(x);
1450 coords.push_back(y);
1451 coords.push_back(z);
1453 // check that enf vertex with given enf vertex entry exists
1454 TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
1455 if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
1457 MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
1458 oldEnfVertex = it_enfVertexEntry->second;
1460 _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
1462 TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
1463 enfVertexEntryList.erase(theVertexEntry);
1464 if (enfVertexEntryList.size() == 0)
1465 _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
1466 // TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1467 // TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
1468 // it_entry_entry->second.erase(it_entryList);
1469 // if (it_entry_entry->second.size() == 0)
1470 // _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1473 MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
1474 msg << "No enforced vertex with geom entry " << theVertexEntry;
1475 // check that enf vertex with given coords exists
1476 TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
1477 if (it_coords_enf != _coordsEnfVertexMap.end()) {
1479 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
1480 oldEnfVertex = it_coords_enf->second;
1482 _coordsEnfVertexMap.erase(it_coords_enf);
1484 TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
1485 enfVertexCoordsList.erase(coords);
1486 if (enfVertexCoordsList.size() == 0)
1487 _faceEntryCoordsListMap.erase(theFaceEntry);
1488 // TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1489 // TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
1490 // it_entry_coords->second.erase(it_coordsList);
1491 // if (it_entry_coords->second.size() == 0)
1492 // _faceEntryCoordsListMap.erase(it_entry_coords);
1495 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
1497 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
1498 throw std::invalid_argument(msg.str());
1502 MESSAGE("Remove enf vertex from _enfVertexList");
1504 // update _enfVertexList
1505 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1506 if (it != _enfVertexList.end()) {
1507 (*it)->faceEntries.erase(theFaceEntry);
1508 if ((*it)->faceEntries.size() == 0){
1509 _enfVertexList.erase(it);
1515 // update _faceEntryEnfVertexListMap
1516 TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
1517 currentEnfVertexList.erase(oldEnfVertex);
1519 if (currentEnfVertexList.size() == 0) {
1520 MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
1521 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1526 NotifySubMeshesHypothesisModification();
1531 //=======================================================================
1532 //function : ClearEnforcedVertices
1533 //=======================================================================
1535 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
1537 bool toNotify = false;
1538 TEnfVertex *oldEnfVertex;
1540 TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1541 if (it_entry_coords != _faceEntryCoordsListMap.end()) {
1543 TEnfVertexCoordsList coordsList = it_entry_coords->second;
1544 TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
1545 for (; it_coordsList != coordsList.end(); ++it_coordsList) {
1546 TEnfVertexCoords coords = (*it_coordsList);
1547 oldEnfVertex = _coordsEnfVertexMap[coords];
1548 _coordsEnfVertexMap.erase(coords);
1549 // update _enfVertexList
1550 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1551 if (it != _enfVertexList.end()) {
1552 (*it)->faceEntries.erase(theFaceEntry);
1553 if ((*it)->faceEntries.size() == 0){
1554 _enfVertexList.erase(it);
1560 _faceEntryCoordsListMap.erase(it_entry_coords);
1561 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1564 TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1565 if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
1567 TEntryList enfVertexEntryList = it_entry_entry->second;
1568 TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
1569 for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
1570 TEntry enfVertexEntry = (*it_enfVertexEntryList);
1571 oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
1572 _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
1573 // update _enfVertexList
1574 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1575 if (it != _enfVertexList.end()) {
1576 (*it)->faceEntries.erase(theFaceEntry);
1577 if ((*it)->faceEntries.size() == 0){
1578 _enfVertexList.erase(it);
1584 _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1585 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1589 NotifySubMeshesHypothesisModification();
1592 // std::ostringstream msg;
1593 // msg << "No enforced vertex for " << theFaceEntry;
1594 // throw std::invalid_argument(msg.str());
1597 //=======================================================================
1598 //function : ClearAllEnforcedVertices
1599 //=======================================================================
1600 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
1601 _faceEntryEnfVertexListMap.clear();
1602 _enfVertexList.clear();
1603 _faceEntryCoordsListMap.clear();
1604 _coordsEnfVertexMap.clear();
1605 _faceEntryEnfVertexEntryListMap.clear();
1606 _enfVertexEntryEnfVertexMap.clear();
1607 // Enable internal enforced vertices on specific face if requested by user
1608 // _faceEntryInternalVerticesList.clear();
1609 NotifySubMeshesHypothesisModification();
1612 //================================================================================
1614 * \brief Return the enforced vertices
1616 //================================================================================
1619 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1620 const BLSURFPlugin_Hypothesis* hyp) {
1621 return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1624 //Enable internal enforced vertices on specific face if requested by user
1625 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1626 // const BLSURFPlugin_Hypothesis* hyp) {
1627 // return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1630 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1632 return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1635 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1637 return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1640 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1641 const BLSURFPlugin_Hypothesis* hyp) {
1642 return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1645 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1646 const BLSURFPlugin_Hypothesis* hyp) {
1647 return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1650 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1651 const BLSURFPlugin_Hypothesis* hyp) {
1652 return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1655 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1656 const BLSURFPlugin_Hypothesis* hyp) {
1657 return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1660 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1661 const BLSURFPlugin_Hypothesis* hyp) {
1662 return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1665 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1667 TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1668 if (it != _groupNameNodeIDMap.end()) {
1671 std::ostringstream msg;
1672 msg << "No group " << theGroupName;
1673 throw std::invalid_argument(msg.str());
1676 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1678 _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1681 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1683 TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1684 if (it != _groupNameNodeIDMap.end()) {
1685 std::set<int>::iterator IDit = it->second.find(theNodeID);
1686 if (IDit != it->second.end())
1687 it->second.erase(IDit);
1688 std::ostringstream msg;
1689 msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1690 throw std::invalid_argument(msg.str());
1692 std::ostringstream msg;
1693 msg << "No group " << theGroupName;
1694 throw std::invalid_argument(msg.str());
1698 //=============================================================================
1699 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1700 if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1701 _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1702 if (toEnforceInternalVertices)
1703 SetPhysicalMesh(PhysicalLocalSize);
1704 NotifySubMeshesHypothesisModification();
1709 //=============================================================================
1710 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1711 if (std::string(theGroupName) != std::string(_enforcedInternalVerticesAllFacesGroup)) {
1712 _enforcedInternalVerticesAllFacesGroup = theGroupName;
1713 NotifySubMeshesHypothesisModification();
1717 //=============================================================================
1718 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
1719 const BLSURFPlugin_Hypothesis* hyp) {
1720 return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
1723 //=============================================================================
1724 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
1725 const BLSURFPlugin_Hypothesis* hyp) {
1726 return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
1729 //=============================================================================
1730 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
1731 const BLSURFPlugin_Hypothesis* hyp) {
1732 return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
1735 //=============================================================================
1736 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
1737 const BLSURFPlugin_Hypothesis* hyp){
1738 return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
1741 //=============================================================================
1742 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
1743 const BLSURFPlugin_Hypothesis* hyp){
1744 return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
1747 //=======================================================================
1748 //function : ClearAllEnforcedVertices
1749 //=======================================================================
1750 void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
1751 _preCadFacesPeriodicityVector.clear();
1752 _preCadEdgesPeriodicityVector.clear();
1753 NotifySubMeshesHypothesisModification();
1756 //=======================================================================
1757 //function : AddPreCadFacesPeriodicity
1758 //=======================================================================
1759 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
1760 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1762 TPreCadPeriodicity preCadFacesPeriodicity;
1763 preCadFacesPeriodicity.shape1Entry = theFace1Entry;
1764 preCadFacesPeriodicity.shape2Entry = theFace2Entry;
1765 preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1766 preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1768 _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
1770 NotifySubMeshesHypothesisModification();
1773 //=======================================================================
1774 //function : AddPreCadEdgesPeriodicity
1775 //=======================================================================
1776 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
1777 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1779 TPreCadPeriodicity preCadEdgesPeriodicity;
1780 preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
1781 preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
1782 preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1783 preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1785 _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
1787 NotifySubMeshesHypothesisModification();
1790 //=============================================================================
1791 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
1792 // We must keep at least the same number of arguments when increasing the SALOME version
1793 // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
1794 // parameter can be written several times to keep the old global number of parameters.
1796 // Treat old options which are now in the advanced options
1797 TOptionValues::iterator op_val;
1799 int _preCADRemoveNanoEdges = -1;
1800 double _preCADEpsNano = -1.0;
1801 op_val = _option2value.find("respect_geometry");
1802 if (op_val != _option2value.end()) {
1803 std::string value = op_val->second;
1805 _decimesh = value.compare("1") == 0 ? 1 : 0;
1807 op_val = _preCADoption2value.find("remove_tiny_edges");
1808 if (op_val != _preCADoption2value.end()) {
1809 std::string value = op_val->second;
1811 _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
1813 op_val = _preCADoption2value.find("tiny_edge_length");
1814 if (op_val != _preCADoption2value.end()) {
1815 std::string value = op_val->second;
1817 _preCADEpsNano = strtod(value.c_str(), NULL);
1820 save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1821 << _angleMesh << " " << _gradation << " " << (int) _quadAllowed << " " << _decimesh;
1822 save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
1823 save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1824 save << " " << (int) _enforcedInternalVerticesAllFaces;
1825 save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
1826 save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
1827 save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
1828 save << " " << (int) _preCADProcess3DTopology << " " << (int) _preCADRemoveDuplicateCADFaces << " " << (int) _preCADRemoveTinyUVEdges;
1829 save << " " << (int)_optimiseTinyEdges << " " << _tinyEdgeOptimisationLength;
1830 save << " " << (int)_correctSurfaceIntersec << " " << _corrSurfaceIntersCost;
1831 save << " " << (int)_useGradation << " " << (int)_useVolumeGradation << " " << _volumeGradation;
1833 op_val = _option2value.begin();
1834 if (op_val != _option2value.end()) {
1835 save << " " << "__OPTIONS_BEGIN__";
1836 for (; op_val != _option2value.end(); ++op_val) {
1837 if (!op_val->second.empty())
1838 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1840 save << " " << "__OPTIONS_END__";
1843 op_val = _customOption2value.begin();
1844 if (op_val != _customOption2value.end()) {
1845 save << " " << "__CUSTOM_OPTIONS_BEGIN__";
1846 for (; op_val != _customOption2value.end(); ++op_val) {
1847 if (!op_val->second.empty())
1848 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1850 save << " " << "__CUSTOM_OPTIONS_END__";
1853 op_val = _preCADoption2value.begin();
1854 if (op_val != _preCADoption2value.end()) {
1855 save << " " << "__PRECAD_OPTIONS_BEGIN__";
1856 for (; op_val != _preCADoption2value.end(); ++op_val) {
1857 if (!op_val->second.empty())
1858 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1860 save << " " << "__PRECAD_OPTIONS_END__";
1863 TSizeMap::iterator it_sm = _sizeMap.begin();
1864 if (it_sm != _sizeMap.end()) {
1865 save << " " << "__SIZEMAP_BEGIN__";
1866 for (; it_sm != _sizeMap.end(); ++it_sm) {
1867 save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
1869 save << " " << "__SIZEMAP_END__";
1872 TSizeMap::iterator it_at = _attractors.begin();
1873 if (it_at != _attractors.end()) {
1874 save << " " << "__ATTRACTORS_BEGIN__";
1875 for (; it_at != _attractors.end(); ++it_at) {
1876 save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
1878 save << " " << "__ATTRACTORS_END__";
1881 TAttractorMap::iterator it_At = _classAttractors.begin();
1882 if (it_At != _classAttractors.end()) {
1883 std::ostringstream test;
1884 save << " " << "__NEW_ATTRACTORS_BEGIN__";
1885 test << " " << "__NEW_ATTRACTORS_BEGIN__";
1886 for (; it_At != _classAttractors.end(); ++it_At) {
1887 std::vector<double> attParams;
1888 attParams = it_At->second->GetParameters();
1889 // double step = it_At->second->GetStep();
1890 save << " " << it_At->first;
1891 save << " " << it_At->second->GetAttractorEntry();
1892 save << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1893 // save << " " << step;
1894 test << " " << it_At->first;
1895 test << " " << it_At->second->GetAttractorEntry();
1896 test << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1897 // test << " " << step;
1899 save << " " << "__NEW_ATTRACTORS_END__";
1900 test << " " << "__NEW_ATTRACTORS_END__";
1901 MESSAGE(" Attractor hypothesis saved as "<<test.str())
1904 TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
1905 if (it_enf != _enfVertexList.end()) {
1906 save << " " << "__ENFORCED_VERTICES_BEGIN__";
1907 for (; it_enf != _enfVertexList.end(); ++it_enf) {
1908 TEnfVertex *enfVertex = (*it_enf);
1909 save << " " << "__BEGIN_VERTEX__";
1910 if (!enfVertex->name.empty()) {
1911 save << " " << "__BEGIN_NAME__";
1912 save << " " << enfVertex->name;
1913 save << " " << "__END_NAME__";
1915 if (!enfVertex->geomEntry.empty()) {
1916 save << " " << "__BEGIN_ENTRY__";
1917 save << " " << enfVertex->geomEntry;
1918 save << " " << "__END_ENTRY__";
1920 if (!enfVertex->grpName.empty()) {
1921 save << " " << "__BEGIN_GROUP__";
1922 save << " " << enfVertex->grpName;
1923 save << " " << "__END_GROUP__";
1925 if (enfVertex->coords.size()) {
1926 save << " " << "__BEGIN_COORDS__";
1927 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1928 save << " " << enfVertex->coords[i];
1929 save << " " << "__END_COORDS__";
1931 TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
1932 bool hasFaces = false;
1933 if (faceEntriesIt != enfVertex->faceEntries.end()) {
1935 save << " " << "__BEGIN_FACELIST__";
1937 for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
1938 save << " " << (*faceEntriesIt);
1940 save << " " << "__END_FACELIST__";
1941 save << " " << "__END_VERTEX__";
1943 save << " " << "__ENFORCED_VERTICES_END__";
1948 SavePreCADPeriodicity(save, "FACES");
1949 SavePreCADPeriodicity(save, "EDGES");
1951 SaveFacesPeriodicity(save);
1952 SaveEdgesPeriodicity(save);
1953 SaveVerticesPeriodicity(save);
1958 void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
1960 TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
1961 if (it_faces_periodicity != _facesPeriodicityVector.end()) {
1962 MESSAGE("__FACES_PERIODICITY_BEGIN__");
1963 save << " " << "__FACES_PERIODICITY_BEGIN__";
1964 for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
1965 TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
1966 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1967 save << " " << "__BEGIN_ENTRY1__";
1968 save << " " << periodicity_i.first;
1969 save << " " << "__END_ENTRY1__";
1970 save << " " << "__BEGIN_ENTRY2__";
1971 save << " " << periodicity_i.second;
1972 save << " " << "__END_ENTRY2__";
1973 save << " " << "__END_PERIODICITY_DESCRIPTION__";
1975 save << " " << "__FACES_PERIODICITY_END__";
1976 MESSAGE("__FACES_PERIODICITY_END__");
1980 void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
1982 TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
1983 if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
1984 save << " " << "__EDGES_PERIODICITY_BEGIN__";
1985 MESSAGE("__EDGES_PERIODICITY_BEGIN__");
1986 for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
1987 TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
1988 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1989 if (! periodicity_i.theFace1Entry.empty()){
1990 save << " " << "__BEGIN_FACE1__";
1991 save << " " << periodicity_i.theFace1Entry;
1992 save << " " << "__END_FACE1__";
1994 save << " " << "__BEGIN_EDGE1__";
1995 save << " " << periodicity_i.theEdge1Entry;
1996 save << " " << "__END_EDGE1__";
1997 if (! periodicity_i.theFace2Entry.empty()){
1998 save << " " << "__BEGIN_FACE2__";
1999 save << " " << periodicity_i.theFace2Entry;
2000 save << " " << "__END_FACE2__";
2002 save << " " << "__BEGIN_EDGE2__";
2003 save << " " << periodicity_i.theEdge2Entry;
2004 save << " " << "__END_EDGE2__";
2005 save << " " << "__BEGIN_EDGE_ORIENTATION__";
2006 save << " " << periodicity_i.edge_orientation;
2007 save << " " << "__END_EDGE_ORIENTATION__";
2008 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2010 save << " " << "__EDGES_PERIODICITY_END__";
2011 MESSAGE("__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 MESSAGE("__VERTICES_PERIODICITY_BEGIN__");
2020 save << " " << "__VERTICES_PERIODICITY_BEGIN__";
2021 for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
2022 TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
2023 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2024 save << " " << "__BEGIN_EDGE1__";
2025 save << " " << periodicity_i.theEdge1Entry;
2026 save << " " << "__END_EDGE1__";
2027 save << " " << "__BEGIN_VERTEX1__";
2028 save << " " << periodicity_i.theVertex1Entry;
2029 save << " " << "__END_VERTEX1__";
2030 save << " " << "__BEGIN_EDGE2__";
2031 save << " " << periodicity_i.theEdge2Entry;
2032 save << " " << "__END_EDGE2__";
2033 save << " " << "__BEGIN_VERTEX2__";
2034 save << " " << periodicity_i.theVertex2Entry;
2035 save << " " << "__END_VERTEX2__";
2036 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2038 save << " " << "__VERTICES_PERIODICITY_END__";
2039 MESSAGE("__VERTICES_PERIODICITY_END__");
2043 void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType) {
2044 TPreCadPeriodicityVector precad_periodicity;
2045 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
2046 precad_periodicity = _preCadFacesPeriodicityVector;
2048 precad_periodicity = _preCadEdgesPeriodicityVector;
2049 TPreCadPeriodicityVector::const_iterator it_precad_periodicity = precad_periodicity.begin();
2050 if (it_precad_periodicity != precad_periodicity.end()) {
2051 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_BEGIN__";
2052 for (; it_precad_periodicity != precad_periodicity.end(); ++it_precad_periodicity) {
2053 TPreCadPeriodicity periodicity_i = (*it_precad_periodicity);
2054 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2055 if (!periodicity_i.shape1Entry.empty()) {
2056 save << " " << "__BEGIN_ENTRY1__";
2057 save << " " << periodicity_i.shape1Entry;
2058 save << " " << "__END_ENTRY1__";
2060 if (!periodicity_i.shape2Entry.empty()) {
2061 save << " " << "__BEGIN_ENTRY2__";
2062 save << " " << periodicity_i.shape2Entry;
2063 save << " " << "__END_ENTRY2__";
2066 std::vector<std::string>::const_iterator sourceVerticesEntriesIt = periodicity_i.theSourceVerticesEntries.begin();
2067 bool hasSourceVertices = false;
2068 if (sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end()) {
2069 hasSourceVertices = true;
2070 save << " " << "__BEGIN_SOURCE_VERTICES_LIST__";
2072 for (; sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end(); ++sourceVerticesEntriesIt)
2073 save << " " << (*sourceVerticesEntriesIt);
2074 if (hasSourceVertices)
2075 save << " " << "__END_SOURCE_VERTICES_LIST__";
2077 std::vector<std::string>::const_iterator targetVerticesEntriesIt = periodicity_i.theTargetVerticesEntries.begin();
2078 bool hasTargetVertices = false;
2079 if (targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end()) {
2080 hasTargetVertices = true;
2081 save << " " << "__BEGIN_TARGET_VERTICES_LIST__";
2083 for (; targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end(); ++targetVerticesEntriesIt)
2084 save << " " << (*targetVerticesEntriesIt);
2085 if (hasTargetVertices)
2086 save << " " << "__END_TARGET_VERTICES_LIST__";
2088 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2090 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_END__";
2095 //=============================================================================
2096 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
2100 std::string option_or_sm;
2102 isOK = static_cast<bool>(load >> i);
2104 _topology = (Topology) i;
2106 load.clear(std::ios::badbit | load.rdstate());
2108 isOK = static_cast<bool>(load >> i);
2110 _physicalMesh = (PhysicalMesh) i;
2112 load.clear(std::ios::badbit | load.rdstate());
2114 isOK = static_cast<bool>(load >> i);
2116 _geometricMesh = (GeometricMesh) i;
2118 load.clear(std::ios::badbit | load.rdstate());
2120 isOK = static_cast<bool>(load >> val);
2124 load.clear(std::ios::badbit | load.rdstate());
2126 isOK = static_cast<bool>(load >> val);
2130 load.clear(std::ios::badbit | load.rdstate());
2132 isOK = static_cast<bool>(load >> val);
2136 load.clear(std::ios::badbit | load.rdstate());
2138 isOK = static_cast<bool>(load >> i);
2140 _quadAllowed = (bool) i;
2142 load.clear(std::ios::badbit | load.rdstate());
2144 isOK = static_cast<bool>(load >> i);
2146 if ( i != -1) { // if value is -1, then this is no longer a standard option
2147 std::string & value = _option2value["respect_geometry"];
2148 bool _decimesh = (bool) i;
2149 value = _decimesh ? "1" : "0";
2153 load.clear(std::ios::badbit | load.rdstate());
2155 isOK = static_cast<bool>(load >> val);
2159 load.clear(std::ios::badbit | load.rdstate());
2161 isOK = static_cast<bool>(load >> val);
2165 load.clear(std::ios::badbit | load.rdstate());
2167 isOK = static_cast<bool>(load >> val);
2169 // former parameter: get min value
2170 _angleMesh = std::min(val,_angleMesh);
2172 load.clear(std::ios::badbit | load.rdstate());
2174 isOK = static_cast<bool>(load >> val);
2176 // former parameter: get min value
2177 _minSize = std::min(val,_minSize);
2179 load.clear(std::ios::badbit | load.rdstate());
2181 isOK = static_cast<bool>(load >> val);
2183 // former parameter: get max value
2184 _maxSize = std::max(val,_maxSize);
2186 load.clear(std::ios::badbit | load.rdstate());
2188 isOK = static_cast<bool>(load >> i);
2192 load.clear(std::ios::badbit | load.rdstate());
2194 isOK = static_cast<bool>(load >> i);
2196 _preCADMergeEdges = (bool) i;
2198 load.clear(std::ios::badbit | load.rdstate());
2200 isOK = static_cast<bool>(load >> i);
2202 if ( i != -1) { // if value is -1, then this is no longer a standard option
2203 std::string & value = _preCADoption2value["remove_tiny_edges"];
2204 bool _preCADRemoveNanoEdges = (bool) i;
2205 value = _preCADRemoveNanoEdges ? "1" : "0";
2209 load.clear(std::ios::badbit | load.rdstate());
2211 isOK = static_cast<bool>(load >> i);
2213 _preCADDiscardInput = (bool) i;
2215 load.clear(std::ios::badbit | load.rdstate());
2217 isOK = static_cast<bool>(load >> val);
2218 if (isOK) { // _preCADEpsNano
2219 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
2220 std::string & value = _preCADoption2value["tiny_edge_length"];
2221 std::ostringstream oss;
2227 load.clear(std::ios::badbit | load.rdstate());
2229 isOK = static_cast<bool>(load >> i);
2231 _enforcedInternalVerticesAllFaces = (bool) i;
2233 load.clear(std::ios::badbit | load.rdstate());
2235 // New options with MeshGems-CADSurf
2237 bool hasCADSurfOptions = false;
2238 bool hasOptions = false;
2239 bool hasCustomOptions = false;
2240 bool hasPreCADOptions = false;
2241 bool hasSizeMap = false;
2242 bool hasAttractor = false;
2243 bool hasNewAttractor = false;
2244 bool hasEnforcedVertex = false;
2245 bool hasPreCADFacesPeriodicity = false;
2246 bool hasPreCADEdgesPeriodicity = false;
2247 bool hasFacesPeriodicity = false;
2248 bool hasEdgesPeriodicity = false;
2249 bool hasVerticesPeriodicity = false;
2251 isOK = static_cast<bool>(load >> option_or_sm);
2253 if ( (option_or_sm == "1")||(option_or_sm == "0") ) {
2254 i = atoi(option_or_sm.c_str());
2255 hasCADSurfOptions = true;
2256 _phySizeRel = (bool) i;
2258 if (option_or_sm == "__OPTIONS_BEGIN__")
2260 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2261 hasCustomOptions = true;
2262 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2263 hasPreCADOptions = true;
2264 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2266 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2267 hasAttractor = true;
2268 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2269 hasNewAttractor = true;
2270 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2271 hasEnforcedVertex = true;
2272 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2273 hasPreCADFacesPeriodicity = true;
2274 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2275 hasPreCADEdgesPeriodicity = true;
2276 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2277 hasFacesPeriodicity = true;
2278 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2279 hasEdgesPeriodicity = true;
2280 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2281 hasVerticesPeriodicity = true;
2283 if (isOK && hasCADSurfOptions) {
2284 isOK = static_cast<bool>(load >> i);
2286 _minSizeRel = (bool) i;
2288 load.clear(std::ios::badbit | load.rdstate());
2290 isOK = static_cast<bool>(load >> i);
2292 _maxSizeRel = (bool) i;
2294 load.clear(std::ios::badbit | load.rdstate());
2296 isOK = static_cast<bool>(load >> val);
2298 _chordalError = val;
2300 load.clear(std::ios::badbit | load.rdstate());
2302 isOK = static_cast<bool>(load >> i);
2304 _anisotropic = (bool) i;
2306 load.clear(std::ios::badbit | load.rdstate());
2308 isOK = static_cast<bool>(load >> val);
2310 _anisotropicRatio = val;
2312 load.clear(std::ios::badbit | load.rdstate());
2314 isOK = static_cast<bool>(load >> i);
2316 _removeTinyEdges = (bool) i;
2318 load.clear(std::ios::badbit | load.rdstate());
2320 isOK = static_cast<bool>(load >> val);
2322 _tinyEdgeLength = val;
2324 load.clear(std::ios::badbit | load.rdstate());
2326 isOK = static_cast<bool>(load >> i);
2328 _badElementRemoval = (bool) i;
2330 load.clear(std::ios::badbit | load.rdstate());
2332 isOK = static_cast<bool>(load >> val);
2334 _badElementAspectRatio = val;
2336 load.clear(std::ios::badbit | load.rdstate());
2338 isOK = static_cast<bool>(load >> i);
2340 _optimizeMesh = (bool) i;
2342 load.clear(std::ios::badbit | load.rdstate());
2344 isOK = static_cast<bool>(load >> i);
2346 _quadraticMesh = (bool) i;
2348 load.clear(std::ios::badbit | load.rdstate());
2350 isOK = static_cast<bool>(load >> i);
2352 _preCADProcess3DTopology = (bool) i;
2354 load.clear(std::ios::badbit | load.rdstate());
2356 if (( load >> std::ws).peek() != '_' )
2358 isOK = static_cast<bool>(load >> i);
2360 _preCADRemoveDuplicateCADFaces = (bool) i;
2362 load.clear(std::ios::badbit | load.rdstate());
2364 isOK = static_cast<bool>(load >> i);
2366 _preCADRemoveTinyUVEdges = (bool) i;
2368 load.clear(std::ios::badbit | load.rdstate());
2370 isOK = static_cast<bool>(load >> i);
2372 _optimiseTinyEdges = (bool) i;
2374 load.clear(std::ios::badbit | load.rdstate());
2376 isOK = static_cast<bool>(load >> val);
2378 _tinyEdgeOptimisationLength = val;
2380 load.clear(std::ios::badbit | load.rdstate());
2382 isOK = static_cast<bool>(load >> i);
2384 _correctSurfaceIntersec = (bool) i;
2386 load.clear(std::ios::badbit | load.rdstate());
2388 isOK = static_cast<bool>(load >> val);
2390 _corrSurfaceIntersCost = val;
2392 load.clear(std::ios::badbit | load.rdstate());
2394 isOK = static_cast<bool>(load >> i);
2396 _useGradation = (bool) i;
2398 load.clear(std::ios::badbit | load.rdstate());
2400 isOK = static_cast<bool>(load >> i);
2402 _useVolumeGradation = (bool) i;
2404 load.clear(std::ios::badbit | load.rdstate());
2406 isOK = static_cast<bool>(load >> val);
2408 _volumeGradation = val;
2410 load.clear(std::ios::badbit | load.rdstate());
2415 if (hasCADSurfOptions) {
2416 isOK = static_cast<bool>(load >> option_or_sm);
2418 if (option_or_sm == "__OPTIONS_BEGIN__")
2420 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2421 hasCustomOptions = true;
2422 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2423 hasPreCADOptions = true;
2424 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2426 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2427 hasAttractor = true;
2428 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2429 hasNewAttractor = true;
2430 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2431 hasEnforcedVertex = true;
2432 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2433 hasPreCADFacesPeriodicity = true;
2434 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2435 hasPreCADEdgesPeriodicity = true;
2436 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2437 hasFacesPeriodicity = true;
2438 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2439 hasEdgesPeriodicity = true;
2440 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2441 hasVerticesPeriodicity = true;
2445 std::string optName, optValue;
2446 while (isOK && hasOptions) {
2447 isOK = static_cast<bool>(load >> optName);
2449 if (optName == "__OPTIONS_END__")
2451 isOK = static_cast<bool>(load >> optValue);
2454 std::string & value = _option2value[optName];
2456 int len = value.size();
2457 // continue reading until "%#" encountered
2458 while (value[len - 1] != '#' || value[len - 2] != '%') {
2459 isOK = static_cast<bool>(load >> optValue);
2468 value.resize(len - 2); //cut off "%#"
2473 isOK = static_cast<bool>(load >> option_or_sm);
2475 if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2476 hasCustomOptions = true;
2477 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2478 hasPreCADOptions = true;
2479 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2481 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2482 hasAttractor = true;
2483 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2484 hasNewAttractor = true;
2485 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2486 hasEnforcedVertex = true;
2487 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2488 hasPreCADFacesPeriodicity = true;
2489 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2490 hasPreCADEdgesPeriodicity = true;
2491 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2492 hasFacesPeriodicity = true;
2493 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2494 hasEdgesPeriodicity = true;
2495 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2496 hasVerticesPeriodicity = true;
2500 while (isOK && hasCustomOptions) {
2501 isOK = static_cast<bool>(load >> optName);
2503 if (optName == "__CUSTOM_OPTIONS_END__")
2505 isOK = static_cast<bool>(load >> optValue);
2508 std::string& value = optValue;
2509 int len = value.size();
2510 // continue reading until "%#" encountered
2511 while (value[len - 1] != '#' || value[len - 2] != '%') {
2512 isOK = static_cast<bool>(load >> optValue);
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 value.resize(len - 2); //cut off "%#"
2578 if (hasPreCADOptions) {
2579 isOK = static_cast<bool>(load >> option_or_sm);
2581 if (option_or_sm == "__SIZEMAP_BEGIN__")
2583 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2584 hasAttractor = true;
2585 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2586 hasNewAttractor = true;
2587 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2588 hasEnforcedVertex = true;
2589 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2590 hasPreCADFacesPeriodicity = true;
2591 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2592 hasPreCADEdgesPeriodicity = true;
2593 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2594 hasFacesPeriodicity = true;
2595 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2596 hasEdgesPeriodicity = true;
2597 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2598 hasVerticesPeriodicity = true;
2602 std::string smEntry, smValue;
2603 while (isOK && hasSizeMap) {
2604 isOK = static_cast<bool>(load >> smEntry);
2606 if (smEntry == "__SIZEMAP_END__")
2608 isOK = static_cast<bool>(load >> smValue);
2611 std::string & value2 = _sizeMap[smEntry];
2613 int len2 = value2.size();
2614 // continue reading until "%#" encountered
2615 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2616 isOK = static_cast<bool>(load >> smValue);
2620 len2 = value2.size();
2625 value2.resize(len2 - 2); //cut off "%#"
2630 isOK = static_cast<bool>(load >> option_or_sm);
2632 if (option_or_sm == "__ATTRACTORS_BEGIN__")
2633 hasAttractor = true;
2634 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2635 hasNewAttractor = true;
2636 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2637 hasEnforcedVertex = true;
2638 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2639 hasPreCADFacesPeriodicity = true;
2640 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2641 hasPreCADEdgesPeriodicity = true;
2642 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2643 hasFacesPeriodicity = true;
2644 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2645 hasEdgesPeriodicity = true;
2646 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2647 hasVerticesPeriodicity = true;
2650 std::string atEntry, atValue;
2651 while (isOK && hasAttractor) {
2652 isOK = static_cast<bool>(load >> atEntry);
2654 if (atEntry == "__ATTRACTORS_END__")
2656 isOK = static_cast<bool>(load >> atValue);
2659 std::string & value3 = _attractors[atEntry];
2661 int len3 = value3.size();
2662 // continue reading until "%#" encountered
2663 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
2664 isOK = static_cast<bool>(load >> atValue);
2668 len3 = value3.size();
2673 value3.resize(len3 - 2); //cut off "%#"
2678 isOK = static_cast<bool>(load >> option_or_sm);
2680 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2681 hasNewAttractor = true;
2682 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2683 hasEnforcedVertex = true;
2684 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2685 hasPreCADFacesPeriodicity = true;
2686 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2687 hasPreCADEdgesPeriodicity = true;
2688 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2689 hasFacesPeriodicity = true;
2690 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2691 hasEdgesPeriodicity = true;
2692 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2693 hasVerticesPeriodicity = true;
2697 std::string newAtFaceEntry, atTestString;
2698 std::string newAtShapeEntry;
2699 double attParams[4];
2701 while (isOK && hasNewAttractor) {
2702 //std::cout<<"Load new attractor"<<std::endl;
2703 isOK = static_cast<bool>(load >> newAtFaceEntry);
2705 if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
2707 isOK = static_cast<bool>(load >> newAtShapeEntry);
2710 isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
2713 MESSAGE(" LOADING ATTRACTOR HYPOTHESIS ")
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 // MESSAGE("enfSeparator: " <<enfSeparator);
2780 if (enfSeparator == "__ENFORCED_VERTICES_END__")
2781 break; // __ENFORCED_VERTICES_END__
2782 if (enfSeparator != "__BEGIN_VERTEX__")
2783 throw std::exception();
2786 isOK = static_cast<bool>(load >> enfSeparator);
2787 MESSAGE("enfSeparator: " <<enfSeparator);
2788 if (enfSeparator == "__END_VERTEX__") {
2790 enfVertex->name = enfName;
2791 enfVertex->geomEntry = enfGeomEntry;
2792 enfVertex->grpName = enfGroup;
2793 enfVertex->coords.clear();
2795 enfVertex->coords.assign(enfCoords,enfCoords+3);
2796 enfVertex->faceEntries = enfFaceEntryList;
2798 _enfVertexList.insert(enfVertex);
2800 if (enfVertex->coords.size()) {
2801 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
2802 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2803 _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
2804 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2807 if (!enfVertex->geomEntry.empty()) {
2808 _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
2809 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2810 _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
2811 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2816 enfGeomEntry.clear();
2818 enfFaceEntryList.clear();
2820 break; // __END_VERTEX__
2823 if (enfSeparator == "__BEGIN_NAME__") { // __BEGIN_NAME__
2824 while (isOK && (enfSeparator != "__END_NAME__")) {
2825 isOK = static_cast<bool>(load >> enfSeparator);
2826 if (enfSeparator != "__END_NAME__") {
2827 if (!enfName.empty())
2829 enfName += enfSeparator;
2832 MESSAGE("enfName: " <<enfName);
2835 if (enfSeparator == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
2836 isOK = static_cast<bool>(load >> enfGeomEntry);
2837 isOK = static_cast<bool>(load >> enfSeparator); // __END_ENTRY__
2838 if (enfSeparator != "__END_ENTRY__")
2839 throw std::exception();
2840 MESSAGE("enfGeomEntry: " <<enfGeomEntry);
2843 if (enfSeparator == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
2844 while (isOK && (enfSeparator != "__END_GROUP__")) {
2845 isOK = static_cast<bool>(load >> enfSeparator);
2846 if (enfSeparator != "__END_GROUP__") {
2847 if (!enfGroup.empty())
2849 enfGroup += enfSeparator;
2852 MESSAGE("enfGroup: " <<enfGroup);
2855 if (enfSeparator == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
2857 isOK = static_cast<bool>(load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
2858 isOK = static_cast<bool>(load >> enfSeparator); // __END_COORDS__
2859 if (enfSeparator != "__END_COORDS__")
2860 throw std::exception();
2861 MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
2864 if (enfSeparator == "__BEGIN_FACELIST__") { // __BEGIN_FACELIST__
2865 while (isOK && (enfSeparator != "__END_FACELIST__")) {
2866 isOK = static_cast<bool>(load >> enfSeparator);
2867 if (enfSeparator != "__END_FACELIST__") {
2868 enfFaceEntryList.insert(enfSeparator);
2869 MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
2878 if (hasPreCADFacesPeriodicity){
2879 LoadPreCADPeriodicity(load, "FACES");
2881 isOK = static_cast<bool>(load >> option_or_sm);
2883 if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2884 hasPreCADEdgesPeriodicity = true;
2885 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2886 hasFacesPeriodicity = true;
2887 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2888 hasEdgesPeriodicity = true;
2889 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2890 hasVerticesPeriodicity = true;
2894 if (hasPreCADEdgesPeriodicity){
2895 LoadPreCADPeriodicity(load, "EDGES");
2897 isOK = static_cast<bool>(load >> option_or_sm);
2899 if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2900 hasFacesPeriodicity = true;
2901 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2902 hasEdgesPeriodicity = true;
2903 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2904 hasVerticesPeriodicity = true;
2908 if (hasFacesPeriodicity){
2909 LoadFacesPeriodicity(load);
2911 isOK = static_cast<bool>(load >> option_or_sm);
2913 if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2914 hasEdgesPeriodicity = true;
2915 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2916 hasVerticesPeriodicity = true;
2920 if (hasEdgesPeriodicity){
2921 LoadEdgesPeriodicity(load);
2923 isOK = static_cast<bool>(load >> option_or_sm);
2925 if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2926 hasVerticesPeriodicity = true;
2929 if (hasVerticesPeriodicity)
2930 LoadVerticesPeriodicity(load);
2935 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
2939 std::string periodicitySeparator;
2943 _facesPeriodicityVector.clear();
2946 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2947 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2948 TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
2949 if (periodicitySeparator == "__FACES_PERIODICITY_END__")
2950 break; // __FACES_PERIODICITY_END__
2951 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2952 MESSAGE("//" << periodicitySeparator << "//");
2953 throw std::exception();
2957 isOK = static_cast<bool>(load >> periodicitySeparator);
2958 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2959 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2961 periodicity_i->first = shape1Entry;
2962 periodicity_i->second = shape2Entry;
2964 _facesPeriodicityVector.push_back(*periodicity_i);
2966 break; // __END_PERIODICITY_DESCRIPTION__
2969 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
2970 isOK = static_cast<bool>(load >> shape1Entry);
2971 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
2972 if (periodicitySeparator != "__END_ENTRY1__")
2973 throw std::exception();
2974 MESSAGE("shape1Entry: " <<shape1Entry);
2977 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
2978 isOK = static_cast<bool>(load >> shape2Entry);
2979 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
2980 if (periodicitySeparator != "__END_ENTRY2__")
2981 throw std::exception();
2982 MESSAGE("shape2Entry: " <<shape2Entry);
2989 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
2993 std::string periodicitySeparator;
2994 TEntry theFace1Entry;
2995 TEntry theEdge1Entry;
2996 TEntry theFace2Entry;
2997 TEntry theEdge2Entry;
2998 int edge_orientation = 0;
3000 _edgesPeriodicityVector.clear();
3003 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3004 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3005 TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
3006 if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
3007 break; // __EDGES_PERIODICITY_END__
3008 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3009 MESSAGE("//" << periodicitySeparator << "//");
3010 throw std::exception();
3014 isOK = static_cast<bool>(load >> periodicitySeparator);
3015 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3016 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3018 periodicity_i->theFace1Entry = theFace1Entry;
3019 periodicity_i->theEdge1Entry = theEdge1Entry;
3020 periodicity_i->theFace2Entry = theFace2Entry;
3021 periodicity_i->theEdge2Entry = theEdge2Entry;
3022 periodicity_i->edge_orientation = edge_orientation;
3024 _edgesPeriodicityVector.push_back(*periodicity_i);
3026 break; // __END_PERIODICITY_DESCRIPTION__
3029 if (periodicitySeparator == "__BEGIN_FACE1__") { // __BEGIN_FACE1__
3030 isOK = static_cast<bool>(load >> theFace1Entry);
3031 MESSAGE("//" << theFace1Entry << "//");
3032 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE1__
3033 if (periodicitySeparator != "__END_FACE1__"){
3034 MESSAGE("//" << periodicitySeparator << "//");
3035 throw std::exception();
3037 MESSAGE("theFace1Entry: " <<theFace1Entry);
3040 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3041 isOK = static_cast<bool>(load >> theEdge1Entry);
3042 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3043 if (periodicitySeparator != "__END_EDGE1__")
3044 throw std::exception();
3045 MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3048 if (periodicitySeparator == "__BEGIN_FACE2__") { // __BEGIN_FACE2__
3049 isOK = static_cast<bool>(load >> theFace2Entry);
3050 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE2__
3051 if (periodicitySeparator != "__END_FACE2__")
3052 throw std::exception();
3053 MESSAGE("theFace2Entry: " <<theFace2Entry);
3056 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3057 isOK = static_cast<bool>(load >> theEdge2Entry);
3058 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3059 if (periodicitySeparator != "__END_EDGE2__")
3060 throw std::exception();
3061 MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3064 if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") { // __BEGIN_EDGE_ORIENTATION__
3065 isOK = static_cast<bool>(load >> edge_orientation);
3066 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
3067 if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
3068 throw std::exception();
3069 MESSAGE("edge_orientation: " <<edge_orientation);
3075 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
3079 std::string periodicitySeparator;
3080 TEntry theEdge1Entry;
3081 TEntry theVertex1Entry;
3082 TEntry theEdge2Entry;
3083 TEntry theVertex2Entry;
3085 _verticesPeriodicityVector.clear();
3088 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3089 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3090 TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
3091 if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
3092 break; // __VERTICES_PERIODICITY_END__
3093 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3094 MESSAGE("//" << periodicitySeparator << "//");
3095 throw std::exception();
3099 isOK = static_cast<bool>(load >> periodicitySeparator);
3100 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3101 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3103 periodicity_i->theEdge1Entry = theEdge1Entry;
3104 periodicity_i->theVertex1Entry = theVertex1Entry;
3105 periodicity_i->theEdge2Entry = theEdge2Entry;
3106 periodicity_i->theVertex2Entry = theVertex2Entry;
3108 _verticesPeriodicityVector.push_back(*periodicity_i);
3110 break; // __END_PERIODICITY_DESCRIPTION__
3113 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3114 isOK = static_cast<bool>(load >> theEdge1Entry);
3115 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3116 if (periodicitySeparator != "__END_EDGE1__")
3117 throw std::exception();
3118 MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3121 if (periodicitySeparator == "__BEGIN_VERTEX1__") { // __BEGIN_VERTEX1__
3122 isOK = static_cast<bool>(load >> theVertex1Entry);
3123 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX1__
3124 if (periodicitySeparator != "__END_VERTEX1__")
3125 throw std::exception();
3126 MESSAGE("theVertex1Entry: " <<theVertex1Entry);
3129 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3130 isOK = static_cast<bool>(load >> theEdge2Entry);
3131 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3132 if (periodicitySeparator != "__END_EDGE2__")
3133 throw std::exception();
3134 MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3137 if (periodicitySeparator == "__BEGIN_VERTEX2__") { // __BEGIN_VERTEX2__
3138 isOK = static_cast<bool>(load >> theVertex2Entry);
3139 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX2__
3140 if (periodicitySeparator != "__END_VERTEX2__")
3141 throw std::exception();
3142 MESSAGE("theVertex2Entry: " <<theVertex2Entry);
3148 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
3152 std::string periodicitySeparator;
3155 std::vector<std::string> theSourceVerticesEntries;
3156 std::vector<std::string> theTargetVerticesEntries;
3158 bool hasSourceVertices = false;
3159 bool hasTargetVertices = false;
3161 if ( shapeType && strcmp( shapeType, "FACES") == 0 )
3162 _preCadFacesPeriodicityVector.clear();
3164 _preCadEdgesPeriodicityVector.clear();
3168 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3169 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3170 TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
3171 // MESSAGE("periodicitySeparator: " <<periodicitySeparator);
3172 std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
3173 if (periodicitySeparator == endSeparator)
3174 break; // __PRECAD_FACES_PERIODICITY_END__
3175 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3176 MESSAGE("//" << endSeparator << "//");
3177 MESSAGE("//" << periodicitySeparator << "//");
3178 throw std::exception();
3182 isOK = static_cast<bool>(load >> periodicitySeparator);
3183 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3184 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3186 periodicity_i->shape1Entry = shape1Entry;
3187 periodicity_i->shape2Entry = shape2Entry;
3189 MESSAGE("theSourceVerticesEntries.size(): " << theSourceVerticesEntries.size());
3190 MESSAGE("theTargetVerticesEntries.size(): " << theTargetVerticesEntries.size());
3192 if (hasSourceVertices)
3193 periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
3194 if (hasTargetVertices)
3195 periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
3197 if ( shapeType && strcmp( shapeType, "FACES" ))
3198 _preCadFacesPeriodicityVector.push_back(*periodicity_i);
3200 _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
3202 theSourceVerticesEntries.clear();
3203 theTargetVerticesEntries.clear();
3204 hasSourceVertices = false;
3205 hasTargetVertices = false;
3206 break; // __END_PERIODICITY_DESCRIPTION__
3209 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3210 isOK = static_cast<bool>(load >> shape1Entry);
3211 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3212 if (periodicitySeparator != "__END_ENTRY1__")
3213 throw std::exception();
3214 MESSAGE("shape1Entry: " <<shape1Entry);
3217 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3218 isOK = static_cast<bool>(load >> shape2Entry);
3219 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3220 if (periodicitySeparator != "__END_ENTRY2__")
3221 throw std::exception();
3222 MESSAGE("shape2Entry: " <<shape2Entry);
3225 if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") { // __BEGIN_SOURCE_VERTICES_LIST__
3226 hasSourceVertices = true;
3227 while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
3228 isOK = static_cast<bool>(load >> periodicitySeparator);
3229 if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
3230 theSourceVerticesEntries.push_back(periodicitySeparator);
3231 MESSAGE("theSourceVerticesEntries: " <<periodicitySeparator);
3236 if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") { // __BEGIN_TARGET_VERTICES_LIST__
3237 hasTargetVertices = true;
3238 while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
3239 isOK = static_cast<bool>(load >> periodicitySeparator);
3240 if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
3241 theTargetVerticesEntries.push_back(periodicitySeparator);
3242 MESSAGE("theTargetVerticesEntries: " <<periodicitySeparator);
3250 //=============================================================================
3251 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
3252 return hyp.SaveTo(save);
3255 //=============================================================================
3256 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
3257 return hyp.LoadFrom(load);
3260 //================================================================================
3262 * \brief Does nothing
3264 //================================================================================
3266 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
3270 //================================================================================
3272 * \brief Returns default global constant physical size given a default value of element length ratio
3274 //================================================================================
3276 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
3277 if (bbSegmentation != 0 && diagonal != 0)
3278 return diagonal / bbSegmentation ;
3282 //================================================================================
3284 * \brief Returns default min size given a default value of element length ratio
3286 //================================================================================
3288 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
3290 return diagonal / 1000.0 ;
3291 return undefinedDouble();
3294 //================================================================================
3296 * \brief Returns default max size given a default value of element length ratio
3298 //================================================================================
3300 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
3302 return diagonal / 5.0 ;
3303 return undefinedDouble();
3306 //================================================================================
3308 * \brief Returns default chordal error given a default value of element length ratio
3310 //================================================================================
3312 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
3315 return undefinedDouble();
3318 //================================================================================
3320 * \brief Returns default tiny edge length given a default value of element length ratio
3322 //================================================================================
3324 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
3326 return diagonal * 1e-6 ;
3327 return undefinedDouble();
3330 //================================================================================
3332 * \brief Returns default tiny edge optimisation length given a default value of element length ratio
3334 //================================================================================
3336 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal) {
3338 return diagonal * 1e-6 ;
3339 return undefinedDouble();
3342 //=============================================================================
3344 * \brief Initialize my parameter values by default parameters.
3345 * \retval bool - true if parameter values have been successfully defined
3347 //=============================================================================
3349 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
3350 double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
3351 _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
3352 _minSize = GetDefaultMinSize(diagonal);
3353 _maxSize = GetDefaultMaxSize(diagonal);
3354 _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
3355 _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
3356 _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(diagonal);
3361 //================================================================================
3363 * \brief Converts a string to a bool
3365 //================================================================================
3367 bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
3368 throw (std::invalid_argument)
3370 std::string s = str;
3371 if ( isOk ) *isOk = true;
3373 for ( size_t i = 0; i <= s.size(); ++i )
3374 s[i] = tolower( s[i] );
3376 if ( s == "1" || s == "true" || s == "active" || s == "yes" )
3379 if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
3385 std::string msg = "Not a Boolean value:'" + str + "'";
3386 throw std::invalid_argument(msg);
3391 //================================================================================
3393 * \brief Converts a string to a real value
3395 //================================================================================
3397 double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
3398 throw (std::invalid_argument)
3400 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3403 double val = strtod(&str[0], &endPtr);
3404 bool ok = (&str[0] != endPtr);
3406 if ( isOk ) *isOk = ok;
3410 std::string msg = "Not a real value:'" + str + "'";
3411 throw std::invalid_argument(msg);
3416 //================================================================================
3418 * \brief Converts a string to a integer value
3420 //================================================================================
3422 int BLSURFPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
3423 throw (std::invalid_argument)
3425 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3428 int val = (int)strtol( &str[0], &endPtr, 10);
3429 bool ok = (&str[0] != endPtr);
3431 if ( isOk ) *isOk = ok;
3435 std::string msg = "Not an integer value:'" + str + "'";
3436 throw std::invalid_argument(msg);