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 AddPreCADOption("process_3d_topology", theVal ? "yes" : "no" );
725 NotifySubMeshesHypothesisModification();
729 //=============================================================================
730 void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal)
732 if (theVal != _preCADDiscardInput) {
733 // SetTopology(PreCAD);
734 _preCADDiscardInput = theVal;
735 SetPreCADOptionValue("discard_input_topology", theVal ? "yes" : "no" );
736 NotifySubMeshesHypothesisModification();
740 //=============================================================================
741 // Return true if any PreCAD option is activated
742 bool BLSURFPlugin_Hypothesis::HasPreCADOptions(const BLSURFPlugin_Hypothesis* hyp)
748 bool orDefault, isOk;
749 return ( ToBool( hyp->GetPreCADOptionValue("closed_geometry" , &orDefault )) ||
750 ToBool( hyp->GetPreCADOptionValue("discard_input_topology" , &orDefault )) ||
751 ToBool( hyp->GetPreCADOptionValue("merge_edges" , &orDefault )) ||
752 ToBool( hyp->GetPreCADOptionValue("remove_duplicate_cad_faces", &orDefault )) ||
753 ToBool( hyp->GetPreCADOption ("process_3d_topology") , &isOk ) ||
754 ToBool( hyp->GetPreCADOption ("manifold_geometry") , &isOk ) ||
755 hyp->GetPreCADOptionValue("sewing_tolerance") != "5e-4*D" ||
756 hyp->GetPreCADProcess3DTopology() );
759 //=============================================================================
760 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
761 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
763 _GMFFileName = theFileName;
764 // _GMFFileMode = isBinary;
765 NotifySubMeshesHypothesisModification();
768 //=============================================================================
769 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
770 throw (std::invalid_argument) {
772 TOptionValues::iterator op_val = _option2value.find(optionName);
773 if (op_val == _option2value.end())
775 op_val = _preCADoption2value.find(optionName);
776 if (op_val == _preCADoption2value.end())
778 std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'. Try SetAdvancedOption()";
779 throw std::invalid_argument(msg);
782 if (op_val->second != optionValue)
784 const char* ptr = optionValue.c_str();
785 // strip white spaces
786 while (ptr[0] == ' ')
789 while (i != 0 && ptr[i - 1] == ' ')
793 std::string typeName;
796 } else if (_charOptions.count(optionName)) {
797 // do not check strings
798 } else if (_doubleOptions.count(optionName)) {
799 // check if value is double
802 } else if (_boolOptions.count(optionName)) {
803 // check if value is bool
804 ToBool(ptr, &typeOk);
807 // check if value is int
809 typeName = "integer";
812 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
813 throw std::invalid_argument(msg);
815 std::string value( ptr, i );
816 if ( _defaultOptionValues[ optionName ] == value )
819 op_val->second = value;
821 NotifySubMeshesHypothesisModification();
825 //=============================================================================
826 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
827 throw (std::invalid_argument) {
829 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
830 if (op_val == _preCADoption2value.end()) {
831 op_val = _option2value.find(optionName);
832 if (op_val == _option2value.end()) {
833 std::string msg = "Unknown MG-PreCAD option: '" + optionName + "'. Try SetAdvancedOption()";
834 throw std::invalid_argument(msg);
837 if (op_val->second != optionValue)
839 const char* ptr = optionValue.c_str();
840 // strip white spaces
841 while (ptr[0] == ' ')
844 while (i != 0 && ptr[i - 1] == ' ')
848 std::string typeName;
851 } else if (_preCADcharOptions.find(optionName) != _preCADcharOptions.end()) {
852 // do not check strings
853 } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
854 // check if value is double
856 strtod(ptr, &endPtr);
857 typeOk = (ptr != endPtr);
859 } else if (_boolOptions.count(optionName)) {
860 // check if value is bool
861 ToBool(ptr, &typeOk);
864 // check if value is int
866 strtol(ptr, &endPtr, 10);
867 typeOk = (ptr != endPtr);
868 typeName = "integer";
871 std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
872 throw std::invalid_argument(msg);
874 std::string value( ptr, i );
875 if ( _defaultOptionValues[ optionName ] == value )
878 op_val->second = value;
880 NotifySubMeshesHypothesisModification();
884 //=============================================================================
885 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
886 bool* isDefault) const
887 throw (std::invalid_argument)
889 TOptionValues::const_iterator op_val = _option2value.find(optionName);
890 if (op_val == _option2value.end())
892 op_val = _preCADoption2value.find(optionName);
893 if (op_val == _preCADoption2value.end())
895 op_val = _customOption2value.find(optionName);
896 if (op_val == _customOption2value.end())
898 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
899 throw std::invalid_argument(msg);
903 std::string val = op_val->second;
904 if ( isDefault ) *isDefault = ( val.empty() );
906 if ( val.empty() && isDefault )
908 op_val = _defaultOptionValues.find( optionName );
909 if (op_val != _defaultOptionValues.end())
910 val = op_val->second;
915 //=============================================================================
916 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName,
917 bool* isDefault) const
918 throw (std::invalid_argument)
920 TOptionValues::const_iterator op_val = _preCADoption2value.find(optionName);
921 if (op_val == _preCADoption2value.end())
923 op_val = _option2value.find(optionName);
924 if (op_val == _option2value.end())
926 op_val = _customOption2value.find(optionName);
927 if (op_val == _customOption2value.end())
929 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
930 throw std::invalid_argument(msg);
934 std::string val = op_val->second;
935 if ( isDefault ) *isDefault = ( val.empty() );
937 if ( val.empty() && isDefault )
939 op_val = _defaultOptionValues.find( optionName );
940 if (op_val != _option2value.end())
941 val = op_val->second;
946 //=============================================================================
947 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
949 TOptionValues::iterator op_val = _customOption2value.find(optionName);
950 if (op_val != _customOption2value.end())
951 _customOption2value.erase(op_val);
953 op_val = _option2value.find(optionName);
954 if (op_val != _option2value.end())
955 op_val->second.clear();
957 op_val = _preCADoption2value.find(optionName);
958 if (op_val != _preCADoption2value.end())
959 op_val->second.clear();
964 //=============================================================================
965 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName)
967 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
968 if (op_val != _preCADoption2value.end())
969 op_val->second.clear();
972 //=============================================================================
973 void BLSURFPlugin_Hypothesis::AddOption(const std::string& optionName, const std::string& optionValue)
976 TOptionValues::iterator op_val = _option2value.find(optionName);
977 if (op_val != _option2value.end())
979 if (op_val->second != optionValue)
980 op_val->second = optionValue;
986 op_val = _preCADoption2value.find(optionName);
987 if (op_val != _preCADoption2value.end())
989 if (op_val->second != optionValue)
990 op_val->second = optionValue;
994 else if ( optionValue.empty() )
996 _customOption2value.erase( optionName );
1000 op_val = _customOption2value.find(optionName);
1001 if (op_val == _customOption2value.end())
1002 _customOption2value[optionName] = optionValue;
1003 else if (op_val->second != optionValue)
1004 op_val->second = optionValue;
1010 NotifySubMeshesHypothesisModification();
1013 //=============================================================================
1014 void BLSURFPlugin_Hypothesis::AddPreCADOption(const std::string& optionName, const std::string& optionValue)
1016 AddOption( optionName, optionValue );
1019 //=============================================================================
1020 std::string BLSURFPlugin_Hypothesis::GetOption(const std::string& optionName) const
1022 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1023 if (op_val != _customOption2value.end())
1024 return op_val->second;
1029 //=============================================================================
1030 std::string BLSURFPlugin_Hypothesis::GetPreCADOption(const std::string& optionName) const
1032 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1033 if (op_val != _customOption2value.end())
1034 return op_val->second;
1039 //=============================================================================
1040 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetOptionValues() const
1043 TOptionValues::const_iterator op_val = _option2value.begin();
1044 for ( ; op_val != _option2value.end(); ++op_val )
1045 vals.insert( make_pair( op_val->first, GetOptionValue( op_val->first, GET_DEFAULT() )));
1050 //=============================================================================
1051 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetPreCADOptionValues() const
1054 TOptionValues::const_iterator op_val = _preCADoption2value.begin();
1055 for ( ; op_val != _preCADoption2value.end(); ++op_val )
1056 vals.insert( make_pair( op_val->first, GetPreCADOptionValue( op_val->first, GET_DEFAULT() )));
1061 //=======================================================================
1062 //function : SetSizeMapEntry
1063 //=======================================================================
1064 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
1065 if (_sizeMap[entry].compare(sizeMap) != 0) {
1066 SetPhysicalMesh(PhysicalLocalSize);
1067 _sizeMap[entry] = sizeMap;
1068 NotifySubMeshesHypothesisModification();
1072 //=======================================================================
1073 //function : GetSizeMapEntry
1074 //=======================================================================
1075 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
1076 TSizeMap::iterator it = _sizeMap.find(entry);
1077 if (it != _sizeMap.end())
1080 return "No_Such_Entry";
1084 * \brief Return the size maps
1086 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
1087 return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
1090 //=======================================================================
1091 //function : SetAttractorEntry
1092 //=======================================================================
1093 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
1094 if (_attractors[entry].compare(attractor) != 0) {
1095 SetPhysicalMesh(PhysicalLocalSize);
1096 _attractors[entry] = attractor;
1097 NotifySubMeshesHypothesisModification();
1101 //=======================================================================
1102 //function : GetAttractorEntry
1103 //=======================================================================
1104 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
1105 TSizeMap::iterator it = _attractors.find(entry);
1106 if (it != _attractors.end())
1109 return "No_Such_Entry";
1113 * \brief Return the attractors
1115 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
1116 return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
1119 //=======================================================================
1120 //function : SetClassAttractorEntry
1121 //=======================================================================
1122 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
1124 SetPhysicalMesh(PhysicalLocalSize);
1126 // The new attractor can't be defined on the same face as another sizemap
1127 TSizeMap::iterator it = _sizeMap.find( entry );
1128 if ( it != _sizeMap.end() ) {
1130 NotifySubMeshesHypothesisModification();
1133 TSizeMap::iterator itAt = _attractors.find( entry );
1134 if ( itAt != _attractors.end() ) {
1135 _attractors.erase(itAt);
1136 NotifySubMeshesHypothesisModification();
1140 const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
1141 const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
1142 TAttractorMap::iterator attIt = _classAttractors.find(entry);
1143 for ( ; attIt != _classAttractors.end(); ++attIt )
1144 if ( attIt->first == entry &&
1145 attIt->second->GetAttractorEntry() == attEntry )
1147 bool attExists = (attIt != _classAttractors.end());
1149 BLSURFPlugin_Attractor* myAttractor;
1151 myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 );
1152 _classAttractors.insert( make_pair( entry, myAttractor ));
1155 myAttractor = attIt->second;
1157 // if (!myAttractor->IsMapBuilt())
1158 // myAttractor->BuildMap();
1159 myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
1161 NotifySubMeshesHypothesisModification();
1164 //=======================================================================
1165 //function : SetConstantSizeOnAdjacentFaces
1166 //=======================================================================
1167 // TODO uncomment and test (include the needed .hxx)
1168 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist ) {
1169 // TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
1170 // TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
1171 // TopTools_IndexedMapOfShapListOdShape::iterator it;
1172 // for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
1173 // SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
1181 //=======================================================================
1182 //function : GetClassAttractorEntry
1183 //=======================================================================
1184 // BLSURFPlugin_Attractor& BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
1186 // TAttractorMap::iterator it = _classAttractors.find( entry );
1187 // if ( it != _classAttractors.end() )
1188 // return it->second;
1190 // return "No_Such_Entry";
1194 * \brief Return the map of attractor instances
1196 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
1198 return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
1201 //=======================================================================
1202 //function : ClearEntry
1203 //=======================================================================
1204 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
1205 const char * attEntry/*=0*/)
1207 TSizeMap::iterator it = _sizeMap.find( entry );
1209 if ( it != _sizeMap.end() ) {
1211 NotifySubMeshesHypothesisModification();
1214 TSizeMap::iterator itAt = _attractors.find( entry );
1215 if ( itAt != _attractors.end() ) {
1216 _attractors.erase(itAt);
1217 NotifySubMeshesHypothesisModification();
1220 TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
1221 if ( it_clAt != _classAttractors.end() ) {
1223 if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
1224 _classAttractors.erase( it_clAt++ );
1228 while ( it_clAt != _classAttractors.end() );
1229 MESSAGE("_classAttractors.size() = "<<_classAttractors.size())
1230 NotifySubMeshesHypothesisModification();
1233 std::cout<<"No_Such_Entry"<<std::endl;
1238 //=======================================================================
1239 //function : ClearSizeMaps
1240 //=======================================================================
1241 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
1243 _attractors.clear();
1244 _classAttractors.clear();
1247 // Enable internal enforced vertices on specific face if requested by user
1249 ////=======================================================================
1250 ////function : SetInternalEnforcedVertex
1251 ////=======================================================================
1252 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
1253 // bool toEnforceInternalVertices,
1254 // TEnfGroupName theGroupName) {
1256 // MESSAGE("BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex("<< theFaceEntry << ", "
1257 // << toEnforceInternalVertices << ", " << theGroupName << ")");
1259 // TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
1260 // if (it != _faceEntryInternalVerticesList.end()) {
1261 // if (!toEnforceInternalVertices) {
1262 // _faceEntryInternalVerticesList.erase(it);
1266 // if (toEnforceInternalVertices) {
1267 // _faceEntryInternalVerticesList.insert(theFaceEntry);
1272 // // Take care of groups
1276 //=======================================================================
1277 //function : SetEnforcedVertex
1278 //=======================================================================
1279 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
1280 TEnfGroupName theGroupName, double x, double y, double z) {
1282 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
1283 << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
1285 SetPhysicalMesh(PhysicalLocalSize);
1287 // TEnfVertexList::iterator it;
1288 bool toNotify = false;
1289 bool toCreate = true;
1291 TEnfVertex *oldEnVertex;
1292 TEnfVertex *newEnfVertex = new TEnfVertex();
1293 newEnfVertex->name = theVertexName;
1294 newEnfVertex->geomEntry = theVertexEntry;
1295 newEnfVertex->coords.clear();
1296 if (theVertexEntry == "") {
1297 newEnfVertex->coords.push_back(x);
1298 newEnfVertex->coords.push_back(y);
1299 newEnfVertex->coords.push_back(z);
1301 newEnfVertex->grpName = theGroupName;
1302 newEnfVertex->faceEntries.clear();
1303 newEnfVertex->faceEntries.insert(theFaceEntry);
1306 // update _enfVertexList
1307 TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
1308 if (it != _enfVertexList.end()) {
1310 oldEnVertex = (*it);
1311 MESSAGE("Enforced Vertex was found => Update");
1312 if (oldEnVertex->name != theVertexName) {
1313 MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
1314 oldEnVertex->name = theVertexName;
1317 if (oldEnVertex->grpName != theGroupName) {
1318 MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
1319 oldEnVertex->grpName = theGroupName;
1322 TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
1323 if (it_faceEntries == oldEnVertex->faceEntries.end()) {
1324 MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
1325 oldEnVertex->faceEntries.insert(theFaceEntry);
1326 _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
1330 // update map coords / enf vertex if needed
1331 if (oldEnVertex->coords.size()) {
1332 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
1333 _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
1336 // update map geom entry / enf vertex if needed
1337 if (oldEnVertex->geomEntry != "") {
1338 _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
1339 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
1344 // //////// CREATE ////////////
1347 MESSAGE("Creating new enforced vertex");
1348 _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
1349 _enfVertexList.insert(newEnfVertex);
1350 if (theVertexEntry == "") {
1351 _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
1352 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
1355 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
1356 _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
1361 NotifySubMeshesHypothesisModification();
1363 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
1368 //=======================================================================
1369 //function : GetEnforcedVertices
1370 //=======================================================================
1372 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
1373 throw (std::invalid_argument) {
1375 if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
1376 return _faceEntryEnfVertexListMap[theFaceEntry];
1378 return GetDefaultEnfVertexList();
1380 std::ostringstream msg;
1381 msg << "No enforced vertex for face entry " << theFaceEntry;
1382 throw std::invalid_argument(msg.str());
1385 //=======================================================================
1386 //function : GetEnfVertexCoordsList
1387 //=======================================================================
1389 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
1390 const TEntry& theFaceEntry) throw (std::invalid_argument) {
1392 if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
1393 return _faceEntryCoordsListMap[theFaceEntry];
1395 std::ostringstream msg;
1396 msg << "No enforced vertex coords for face entry " << theFaceEntry;
1397 throw std::invalid_argument(msg.str());
1400 //=======================================================================
1401 //function : GetEnfVertexEntryList
1402 //=======================================================================
1404 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
1405 throw (std::invalid_argument) {
1407 if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
1408 return _faceEntryEnfVertexEntryListMap[theFaceEntry];
1410 std::ostringstream msg;
1411 msg << "No enforced vertex entry for face entry " << theFaceEntry;
1412 throw std::invalid_argument(msg.str());
1415 //=======================================================================
1416 //function : GetEnfVertex(TEnfVertexCoords coords)
1417 //=======================================================================
1419 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
1420 throw (std::invalid_argument) {
1422 if (_coordsEnfVertexMap.count(coords) > 0)
1423 return _coordsEnfVertexMap[coords];
1425 std::ostringstream msg;
1426 msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
1427 throw std::invalid_argument(msg.str());
1430 //=======================================================================
1431 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
1432 //=======================================================================
1434 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
1435 throw (std::invalid_argument) {
1437 if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
1438 return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
1440 std::ostringstream msg;
1441 msg << "No enforced vertex with entry " << theEnfVertexEntry;
1442 throw std::invalid_argument(msg.str());
1445 //Enable internal enforced vertices on specific face if requested by user
1446 ////=======================================================================
1447 ////function : GetInternalEnforcedVertex
1448 ////=======================================================================
1450 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
1452 // if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
1457 //=======================================================================
1458 //function : ClearEnforcedVertex
1459 //=======================================================================
1461 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
1462 const TEntry& theVertexEntry) throw (std::invalid_argument) {
1464 bool toNotify = false;
1465 std::ostringstream msg;
1466 TEnfVertex *oldEnfVertex;
1467 TEnfVertexCoords coords;
1469 coords.push_back(x);
1470 coords.push_back(y);
1471 coords.push_back(z);
1473 // check that enf vertex with given enf vertex entry exists
1474 TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
1475 if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
1477 MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
1478 oldEnfVertex = it_enfVertexEntry->second;
1480 _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
1482 TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
1483 enfVertexEntryList.erase(theVertexEntry);
1484 if (enfVertexEntryList.size() == 0)
1485 _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
1486 // TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1487 // TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
1488 // it_entry_entry->second.erase(it_entryList);
1489 // if (it_entry_entry->second.size() == 0)
1490 // _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1493 MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
1494 msg << "No enforced vertex with geom entry " << theVertexEntry;
1495 // check that enf vertex with given coords exists
1496 TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
1497 if (it_coords_enf != _coordsEnfVertexMap.end()) {
1499 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
1500 oldEnfVertex = it_coords_enf->second;
1502 _coordsEnfVertexMap.erase(it_coords_enf);
1504 TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
1505 enfVertexCoordsList.erase(coords);
1506 if (enfVertexCoordsList.size() == 0)
1507 _faceEntryCoordsListMap.erase(theFaceEntry);
1508 // TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1509 // TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
1510 // it_entry_coords->second.erase(it_coordsList);
1511 // if (it_entry_coords->second.size() == 0)
1512 // _faceEntryCoordsListMap.erase(it_entry_coords);
1515 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
1517 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
1518 throw std::invalid_argument(msg.str());
1522 MESSAGE("Remove enf vertex from _enfVertexList");
1524 // update _enfVertexList
1525 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1526 if (it != _enfVertexList.end()) {
1527 (*it)->faceEntries.erase(theFaceEntry);
1528 if ((*it)->faceEntries.size() == 0){
1529 _enfVertexList.erase(it);
1535 // update _faceEntryEnfVertexListMap
1536 TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
1537 currentEnfVertexList.erase(oldEnfVertex);
1539 if (currentEnfVertexList.size() == 0) {
1540 MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
1541 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1546 NotifySubMeshesHypothesisModification();
1551 //=======================================================================
1552 //function : ClearEnforcedVertices
1553 //=======================================================================
1555 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
1557 bool toNotify = false;
1558 TEnfVertex *oldEnfVertex;
1560 TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1561 if (it_entry_coords != _faceEntryCoordsListMap.end()) {
1563 TEnfVertexCoordsList coordsList = it_entry_coords->second;
1564 TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
1565 for (; it_coordsList != coordsList.end(); ++it_coordsList) {
1566 TEnfVertexCoords coords = (*it_coordsList);
1567 oldEnfVertex = _coordsEnfVertexMap[coords];
1568 _coordsEnfVertexMap.erase(coords);
1569 // update _enfVertexList
1570 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1571 if (it != _enfVertexList.end()) {
1572 (*it)->faceEntries.erase(theFaceEntry);
1573 if ((*it)->faceEntries.size() == 0){
1574 _enfVertexList.erase(it);
1580 _faceEntryCoordsListMap.erase(it_entry_coords);
1581 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1584 TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1585 if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
1587 TEntryList enfVertexEntryList = it_entry_entry->second;
1588 TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
1589 for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
1590 TEntry enfVertexEntry = (*it_enfVertexEntryList);
1591 oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
1592 _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
1593 // update _enfVertexList
1594 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1595 if (it != _enfVertexList.end()) {
1596 (*it)->faceEntries.erase(theFaceEntry);
1597 if ((*it)->faceEntries.size() == 0){
1598 _enfVertexList.erase(it);
1604 _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1605 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1609 NotifySubMeshesHypothesisModification();
1612 // std::ostringstream msg;
1613 // msg << "No enforced vertex for " << theFaceEntry;
1614 // throw std::invalid_argument(msg.str());
1617 //=======================================================================
1618 //function : ClearAllEnforcedVertices
1619 //=======================================================================
1620 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
1621 _faceEntryEnfVertexListMap.clear();
1622 _enfVertexList.clear();
1623 _faceEntryCoordsListMap.clear();
1624 _coordsEnfVertexMap.clear();
1625 _faceEntryEnfVertexEntryListMap.clear();
1626 _enfVertexEntryEnfVertexMap.clear();
1627 // Enable internal enforced vertices on specific face if requested by user
1628 // _faceEntryInternalVerticesList.clear();
1629 NotifySubMeshesHypothesisModification();
1632 //================================================================================
1634 * \brief Return the enforced vertices
1636 //================================================================================
1639 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1640 const BLSURFPlugin_Hypothesis* hyp) {
1641 return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1644 //Enable internal enforced vertices on specific face if requested by user
1645 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1646 // const BLSURFPlugin_Hypothesis* hyp) {
1647 // return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1650 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1652 return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1655 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1657 return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1660 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1661 const BLSURFPlugin_Hypothesis* hyp) {
1662 return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1665 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1666 const BLSURFPlugin_Hypothesis* hyp) {
1667 return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1670 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1671 const BLSURFPlugin_Hypothesis* hyp) {
1672 return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1675 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1676 const BLSURFPlugin_Hypothesis* hyp) {
1677 return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1680 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1681 const BLSURFPlugin_Hypothesis* hyp) {
1682 return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1685 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1687 TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1688 if (it != _groupNameNodeIDMap.end()) {
1691 std::ostringstream msg;
1692 msg << "No group " << theGroupName;
1693 throw std::invalid_argument(msg.str());
1696 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1698 _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1701 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1703 TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1704 if (it != _groupNameNodeIDMap.end()) {
1705 std::set<int>::iterator IDit = it->second.find(theNodeID);
1706 if (IDit != it->second.end())
1707 it->second.erase(IDit);
1708 std::ostringstream msg;
1709 msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1710 throw std::invalid_argument(msg.str());
1712 std::ostringstream msg;
1713 msg << "No group " << theGroupName;
1714 throw std::invalid_argument(msg.str());
1718 //=============================================================================
1719 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1720 if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1721 _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1722 if (toEnforceInternalVertices)
1723 SetPhysicalMesh(PhysicalLocalSize);
1724 NotifySubMeshesHypothesisModification();
1729 //=============================================================================
1730 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1731 if (std::string(theGroupName) != std::string(_enforcedInternalVerticesAllFacesGroup)) {
1732 _enforcedInternalVerticesAllFacesGroup = theGroupName;
1733 NotifySubMeshesHypothesisModification();
1737 //=============================================================================
1738 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
1739 const BLSURFPlugin_Hypothesis* hyp) {
1740 return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
1743 //=============================================================================
1744 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
1745 const BLSURFPlugin_Hypothesis* hyp) {
1746 return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
1749 //=============================================================================
1750 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
1751 const BLSURFPlugin_Hypothesis* hyp) {
1752 return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
1755 //=============================================================================
1756 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
1757 const BLSURFPlugin_Hypothesis* hyp){
1758 return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
1761 //=============================================================================
1762 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
1763 const BLSURFPlugin_Hypothesis* hyp){
1764 return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
1767 //=======================================================================
1768 //function : ClearAllEnforcedVertices
1769 //=======================================================================
1770 void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
1771 _preCadFacesPeriodicityVector.clear();
1772 _preCadEdgesPeriodicityVector.clear();
1773 NotifySubMeshesHypothesisModification();
1776 //=======================================================================
1777 //function : AddPreCadFacesPeriodicity
1778 //=======================================================================
1779 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
1780 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1782 TPreCadPeriodicity preCadFacesPeriodicity;
1783 preCadFacesPeriodicity.shape1Entry = theFace1Entry;
1784 preCadFacesPeriodicity.shape2Entry = theFace2Entry;
1785 preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1786 preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1788 _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
1790 NotifySubMeshesHypothesisModification();
1793 //=======================================================================
1794 //function : AddPreCadEdgesPeriodicity
1795 //=======================================================================
1796 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
1797 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1799 TPreCadPeriodicity preCadEdgesPeriodicity;
1800 preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
1801 preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
1802 preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1803 preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1805 _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
1807 NotifySubMeshesHypothesisModification();
1810 //=============================================================================
1811 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
1812 // We must keep at least the same number of arguments when increasing the SALOME version
1813 // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
1814 // parameter can be written several times to keep the old global number of parameters.
1816 // Treat old options which are now in the advanced options
1817 TOptionValues::iterator op_val;
1819 int _preCADRemoveNanoEdges = -1;
1820 double _preCADEpsNano = -1.0;
1821 op_val = _option2value.find("respect_geometry");
1822 if (op_val != _option2value.end()) {
1823 std::string value = op_val->second;
1825 _decimesh = value.compare("1") == 0 ? 1 : 0;
1827 op_val = _preCADoption2value.find("remove_tiny_edges");
1828 if (op_val != _preCADoption2value.end()) {
1829 std::string value = op_val->second;
1831 _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
1833 op_val = _preCADoption2value.find("tiny_edge_length");
1834 if (op_val != _preCADoption2value.end()) {
1835 std::string value = op_val->second;
1837 _preCADEpsNano = strtod(value.c_str(), NULL);
1840 save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1841 << _angleMesh << " " << _gradation << " " << (int) _quadAllowed << " " << _decimesh;
1842 save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
1843 save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1844 save << " " << (int) _enforcedInternalVerticesAllFaces;
1845 save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
1846 save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
1847 save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
1848 save << " " << (int) _preCADProcess3DTopology << " " << (int) _preCADRemoveDuplicateCADFaces << " " << (int) _preCADRemoveTinyUVEdges;
1849 save << " " << (int)_optimiseTinyEdges << " " << _tinyEdgeOptimisationLength;
1850 save << " " << (int)_correctSurfaceIntersec << " " << _corrSurfaceIntersCost;
1851 save << " " << (int)_useGradation << " " << (int)_useVolumeGradation << " " << _volumeGradation;
1853 op_val = _option2value.begin();
1854 if (op_val != _option2value.end()) {
1855 save << " " << "__OPTIONS_BEGIN__";
1856 for (; op_val != _option2value.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 << " " << "__OPTIONS_END__";
1863 op_val = _customOption2value.begin();
1864 if (op_val != _customOption2value.end()) {
1865 save << " " << "__CUSTOM_OPTIONS_BEGIN__";
1866 for (; op_val != _customOption2value.end(); ++op_val) {
1867 if (!op_val->second.empty())
1868 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1870 save << " " << "__CUSTOM_OPTIONS_END__";
1873 op_val = _preCADoption2value.begin();
1874 if (op_val != _preCADoption2value.end()) {
1875 save << " " << "__PRECAD_OPTIONS_BEGIN__";
1876 for (; op_val != _preCADoption2value.end(); ++op_val) {
1877 if (!op_val->second.empty())
1878 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1880 save << " " << "__PRECAD_OPTIONS_END__";
1883 TSizeMap::iterator it_sm = _sizeMap.begin();
1884 if (it_sm != _sizeMap.end()) {
1885 save << " " << "__SIZEMAP_BEGIN__";
1886 for (; it_sm != _sizeMap.end(); ++it_sm) {
1887 save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
1889 save << " " << "__SIZEMAP_END__";
1892 TSizeMap::iterator it_at = _attractors.begin();
1893 if (it_at != _attractors.end()) {
1894 save << " " << "__ATTRACTORS_BEGIN__";
1895 for (; it_at != _attractors.end(); ++it_at) {
1896 save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
1898 save << " " << "__ATTRACTORS_END__";
1901 TAttractorMap::iterator it_At = _classAttractors.begin();
1902 if (it_At != _classAttractors.end()) {
1903 std::ostringstream test;
1904 save << " " << "__NEW_ATTRACTORS_BEGIN__";
1905 test << " " << "__NEW_ATTRACTORS_BEGIN__";
1906 for (; it_At != _classAttractors.end(); ++it_At) {
1907 std::vector<double> attParams;
1908 attParams = it_At->second->GetParameters();
1909 // double step = it_At->second->GetStep();
1910 save << " " << it_At->first;
1911 save << " " << it_At->second->GetAttractorEntry();
1912 save << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1913 // save << " " << step;
1914 test << " " << it_At->first;
1915 test << " " << it_At->second->GetAttractorEntry();
1916 test << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1917 // test << " " << step;
1919 save << " " << "__NEW_ATTRACTORS_END__";
1920 test << " " << "__NEW_ATTRACTORS_END__";
1921 MESSAGE(" Attractor hypothesis saved as "<<test.str())
1924 TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
1925 if (it_enf != _enfVertexList.end()) {
1926 save << " " << "__ENFORCED_VERTICES_BEGIN__";
1927 for (; it_enf != _enfVertexList.end(); ++it_enf) {
1928 TEnfVertex *enfVertex = (*it_enf);
1929 save << " " << "__BEGIN_VERTEX__";
1930 if (!enfVertex->name.empty()) {
1931 save << " " << "__BEGIN_NAME__";
1932 save << " " << enfVertex->name;
1933 save << " " << "__END_NAME__";
1935 if (!enfVertex->geomEntry.empty()) {
1936 save << " " << "__BEGIN_ENTRY__";
1937 save << " " << enfVertex->geomEntry;
1938 save << " " << "__END_ENTRY__";
1940 if (!enfVertex->grpName.empty()) {
1941 save << " " << "__BEGIN_GROUP__";
1942 save << " " << enfVertex->grpName;
1943 save << " " << "__END_GROUP__";
1945 if (enfVertex->coords.size()) {
1946 save << " " << "__BEGIN_COORDS__";
1947 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1948 save << " " << enfVertex->coords[i];
1949 save << " " << "__END_COORDS__";
1951 TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
1952 bool hasFaces = false;
1953 if (faceEntriesIt != enfVertex->faceEntries.end()) {
1955 save << " " << "__BEGIN_FACELIST__";
1957 for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
1958 save << " " << (*faceEntriesIt);
1960 save << " " << "__END_FACELIST__";
1961 save << " " << "__END_VERTEX__";
1963 save << " " << "__ENFORCED_VERTICES_END__";
1968 SavePreCADPeriodicity(save, "FACES");
1969 SavePreCADPeriodicity(save, "EDGES");
1971 SaveFacesPeriodicity(save);
1972 SaveEdgesPeriodicity(save);
1973 SaveVerticesPeriodicity(save);
1978 void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
1980 TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
1981 if (it_faces_periodicity != _facesPeriodicityVector.end()) {
1982 MESSAGE("__FACES_PERIODICITY_BEGIN__");
1983 save << " " << "__FACES_PERIODICITY_BEGIN__";
1984 for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
1985 TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
1986 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1987 save << " " << "__BEGIN_ENTRY1__";
1988 save << " " << periodicity_i.first;
1989 save << " " << "__END_ENTRY1__";
1990 save << " " << "__BEGIN_ENTRY2__";
1991 save << " " << periodicity_i.second;
1992 save << " " << "__END_ENTRY2__";
1993 save << " " << "__END_PERIODICITY_DESCRIPTION__";
1995 save << " " << "__FACES_PERIODICITY_END__";
1996 MESSAGE("__FACES_PERIODICITY_END__");
2000 void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
2002 TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
2003 if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
2004 save << " " << "__EDGES_PERIODICITY_BEGIN__";
2005 MESSAGE("__EDGES_PERIODICITY_BEGIN__");
2006 for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
2007 TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
2008 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2009 if (! periodicity_i.theFace1Entry.empty()){
2010 save << " " << "__BEGIN_FACE1__";
2011 save << " " << periodicity_i.theFace1Entry;
2012 save << " " << "__END_FACE1__";
2014 save << " " << "__BEGIN_EDGE1__";
2015 save << " " << periodicity_i.theEdge1Entry;
2016 save << " " << "__END_EDGE1__";
2017 if (! periodicity_i.theFace2Entry.empty()){
2018 save << " " << "__BEGIN_FACE2__";
2019 save << " " << periodicity_i.theFace2Entry;
2020 save << " " << "__END_FACE2__";
2022 save << " " << "__BEGIN_EDGE2__";
2023 save << " " << periodicity_i.theEdge2Entry;
2024 save << " " << "__END_EDGE2__";
2025 save << " " << "__BEGIN_EDGE_ORIENTATION__";
2026 save << " " << periodicity_i.edge_orientation;
2027 save << " " << "__END_EDGE_ORIENTATION__";
2028 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2030 save << " " << "__EDGES_PERIODICITY_END__";
2031 MESSAGE("__EDGES_PERIODICITY_END__");
2035 void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save){
2037 TVerticesPeriodicityVector::const_iterator it_vertices_periodicity = _verticesPeriodicityVector.begin();
2038 if (it_vertices_periodicity != _verticesPeriodicityVector.end()) {
2039 MESSAGE("__VERTICES_PERIODICITY_BEGIN__");
2040 save << " " << "__VERTICES_PERIODICITY_BEGIN__";
2041 for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
2042 TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
2043 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2044 save << " " << "__BEGIN_EDGE1__";
2045 save << " " << periodicity_i.theEdge1Entry;
2046 save << " " << "__END_EDGE1__";
2047 save << " " << "__BEGIN_VERTEX1__";
2048 save << " " << periodicity_i.theVertex1Entry;
2049 save << " " << "__END_VERTEX1__";
2050 save << " " << "__BEGIN_EDGE2__";
2051 save << " " << periodicity_i.theEdge2Entry;
2052 save << " " << "__END_EDGE2__";
2053 save << " " << "__BEGIN_VERTEX2__";
2054 save << " " << periodicity_i.theVertex2Entry;
2055 save << " " << "__END_VERTEX2__";
2056 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2058 save << " " << "__VERTICES_PERIODICITY_END__";
2059 MESSAGE("__VERTICES_PERIODICITY_END__");
2063 void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType) {
2064 TPreCadPeriodicityVector precad_periodicity;
2065 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
2066 precad_periodicity = _preCadFacesPeriodicityVector;
2068 precad_periodicity = _preCadEdgesPeriodicityVector;
2069 TPreCadPeriodicityVector::const_iterator it_precad_periodicity = precad_periodicity.begin();
2070 if (it_precad_periodicity != precad_periodicity.end()) {
2071 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_BEGIN__";
2072 for (; it_precad_periodicity != precad_periodicity.end(); ++it_precad_periodicity) {
2073 TPreCadPeriodicity periodicity_i = (*it_precad_periodicity);
2074 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2075 if (!periodicity_i.shape1Entry.empty()) {
2076 save << " " << "__BEGIN_ENTRY1__";
2077 save << " " << periodicity_i.shape1Entry;
2078 save << " " << "__END_ENTRY1__";
2080 if (!periodicity_i.shape2Entry.empty()) {
2081 save << " " << "__BEGIN_ENTRY2__";
2082 save << " " << periodicity_i.shape2Entry;
2083 save << " " << "__END_ENTRY2__";
2086 std::vector<std::string>::const_iterator sourceVerticesEntriesIt = periodicity_i.theSourceVerticesEntries.begin();
2087 bool hasSourceVertices = false;
2088 if (sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end()) {
2089 hasSourceVertices = true;
2090 save << " " << "__BEGIN_SOURCE_VERTICES_LIST__";
2092 for (; sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end(); ++sourceVerticesEntriesIt)
2093 save << " " << (*sourceVerticesEntriesIt);
2094 if (hasSourceVertices)
2095 save << " " << "__END_SOURCE_VERTICES_LIST__";
2097 std::vector<std::string>::const_iterator targetVerticesEntriesIt = periodicity_i.theTargetVerticesEntries.begin();
2098 bool hasTargetVertices = false;
2099 if (targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end()) {
2100 hasTargetVertices = true;
2101 save << " " << "__BEGIN_TARGET_VERTICES_LIST__";
2103 for (; targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end(); ++targetVerticesEntriesIt)
2104 save << " " << (*targetVerticesEntriesIt);
2105 if (hasTargetVertices)
2106 save << " " << "__END_TARGET_VERTICES_LIST__";
2108 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2110 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_END__";
2115 //=============================================================================
2116 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
2120 std::string option_or_sm;
2122 isOK = static_cast<bool>(load >> i);
2124 _topology = (Topology) i;
2126 load.clear(std::ios::badbit | load.rdstate());
2128 isOK = static_cast<bool>(load >> i);
2130 _physicalMesh = (PhysicalMesh) i;
2132 load.clear(std::ios::badbit | load.rdstate());
2134 isOK = static_cast<bool>(load >> i);
2136 _geometricMesh = (GeometricMesh) i;
2138 load.clear(std::ios::badbit | load.rdstate());
2140 isOK = static_cast<bool>(load >> val);
2144 load.clear(std::ios::badbit | load.rdstate());
2146 isOK = static_cast<bool>(load >> val);
2150 load.clear(std::ios::badbit | load.rdstate());
2152 isOK = static_cast<bool>(load >> val);
2156 load.clear(std::ios::badbit | load.rdstate());
2158 isOK = static_cast<bool>(load >> i);
2160 _quadAllowed = (bool) i;
2162 load.clear(std::ios::badbit | load.rdstate());
2164 isOK = static_cast<bool>(load >> i);
2166 if ( i != -1) { // if value is -1, then this is no longer a standard option
2167 std::string & value = _option2value["respect_geometry"];
2168 bool _decimesh = (bool) i;
2169 value = _decimesh ? "1" : "0";
2173 load.clear(std::ios::badbit | load.rdstate());
2175 isOK = static_cast<bool>(load >> val);
2179 load.clear(std::ios::badbit | load.rdstate());
2181 isOK = static_cast<bool>(load >> val);
2185 load.clear(std::ios::badbit | load.rdstate());
2187 isOK = static_cast<bool>(load >> val);
2189 // former parameter: get min value
2190 _angleMesh = std::min(val,_angleMesh);
2192 load.clear(std::ios::badbit | load.rdstate());
2194 isOK = static_cast<bool>(load >> val);
2196 // former parameter: get min value
2197 _minSize = std::min(val,_minSize);
2199 load.clear(std::ios::badbit | load.rdstate());
2201 isOK = static_cast<bool>(load >> val);
2203 // former parameter: get max value
2204 _maxSize = std::max(val,_maxSize);
2206 load.clear(std::ios::badbit | load.rdstate());
2208 isOK = static_cast<bool>(load >> i);
2212 load.clear(std::ios::badbit | load.rdstate());
2214 isOK = static_cast<bool>(load >> i);
2216 _preCADMergeEdges = (bool) i;
2218 load.clear(std::ios::badbit | load.rdstate());
2220 isOK = static_cast<bool>(load >> i);
2222 if ( i != -1) { // if value is -1, then this is no longer a standard option
2223 std::string & value = _preCADoption2value["remove_tiny_edges"];
2224 bool _preCADRemoveNanoEdges = (bool) i;
2225 value = _preCADRemoveNanoEdges ? "1" : "0";
2229 load.clear(std::ios::badbit | load.rdstate());
2231 isOK = static_cast<bool>(load >> i);
2233 _preCADDiscardInput = (bool) i;
2235 load.clear(std::ios::badbit | load.rdstate());
2237 isOK = static_cast<bool>(load >> val);
2238 if (isOK) { // _preCADEpsNano
2239 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
2240 std::string & value = _preCADoption2value["tiny_edge_length"];
2241 std::ostringstream oss;
2247 load.clear(std::ios::badbit | load.rdstate());
2249 isOK = static_cast<bool>(load >> i);
2251 _enforcedInternalVerticesAllFaces = (bool) i;
2253 load.clear(std::ios::badbit | load.rdstate());
2255 // New options with MeshGems-CADSurf
2257 bool hasCADSurfOptions = false;
2258 bool hasOptions = false;
2259 bool hasCustomOptions = false;
2260 bool hasPreCADOptions = false;
2261 bool hasSizeMap = false;
2262 bool hasAttractor = false;
2263 bool hasNewAttractor = false;
2264 bool hasEnforcedVertex = false;
2265 bool hasPreCADFacesPeriodicity = false;
2266 bool hasPreCADEdgesPeriodicity = false;
2267 bool hasFacesPeriodicity = false;
2268 bool hasEdgesPeriodicity = false;
2269 bool hasVerticesPeriodicity = false;
2271 isOK = static_cast<bool>(load >> option_or_sm);
2273 if ( (option_or_sm == "1")||(option_or_sm == "0") ) {
2274 i = atoi(option_or_sm.c_str());
2275 hasCADSurfOptions = true;
2276 _phySizeRel = (bool) i;
2278 if (option_or_sm == "__OPTIONS_BEGIN__")
2280 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2281 hasCustomOptions = true;
2282 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2283 hasPreCADOptions = true;
2284 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2286 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2287 hasAttractor = true;
2288 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2289 hasNewAttractor = true;
2290 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2291 hasEnforcedVertex = true;
2292 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2293 hasPreCADFacesPeriodicity = true;
2294 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2295 hasPreCADEdgesPeriodicity = true;
2296 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2297 hasFacesPeriodicity = true;
2298 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2299 hasEdgesPeriodicity = true;
2300 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2301 hasVerticesPeriodicity = true;
2303 if (isOK && hasCADSurfOptions) {
2304 isOK = static_cast<bool>(load >> i);
2306 _minSizeRel = (bool) i;
2308 load.clear(std::ios::badbit | load.rdstate());
2310 isOK = static_cast<bool>(load >> i);
2312 _maxSizeRel = (bool) i;
2314 load.clear(std::ios::badbit | load.rdstate());
2316 isOK = static_cast<bool>(load >> val);
2318 _chordalError = val;
2320 load.clear(std::ios::badbit | load.rdstate());
2322 isOK = static_cast<bool>(load >> i);
2324 _anisotropic = (bool) i;
2326 load.clear(std::ios::badbit | load.rdstate());
2328 isOK = static_cast<bool>(load >> val);
2330 _anisotropicRatio = val;
2332 load.clear(std::ios::badbit | load.rdstate());
2334 isOK = static_cast<bool>(load >> i);
2336 _removeTinyEdges = (bool) i;
2338 load.clear(std::ios::badbit | load.rdstate());
2340 isOK = static_cast<bool>(load >> val);
2342 _tinyEdgeLength = val;
2344 load.clear(std::ios::badbit | load.rdstate());
2346 isOK = static_cast<bool>(load >> i);
2348 _badElementRemoval = (bool) i;
2350 load.clear(std::ios::badbit | load.rdstate());
2352 isOK = static_cast<bool>(load >> val);
2354 _badElementAspectRatio = val;
2356 load.clear(std::ios::badbit | load.rdstate());
2358 isOK = static_cast<bool>(load >> i);
2360 _optimizeMesh = (bool) i;
2362 load.clear(std::ios::badbit | load.rdstate());
2364 isOK = static_cast<bool>(load >> i);
2366 _quadraticMesh = (bool) i;
2368 load.clear(std::ios::badbit | load.rdstate());
2370 isOK = static_cast<bool>(load >> i);
2372 _preCADProcess3DTopology = (bool) i;
2374 load.clear(std::ios::badbit | load.rdstate());
2376 if (( load >> std::ws).peek() != '_' )
2378 isOK = static_cast<bool>(load >> i);
2380 _preCADRemoveDuplicateCADFaces = (bool) i;
2382 load.clear(std::ios::badbit | load.rdstate());
2384 isOK = static_cast<bool>(load >> i);
2386 _preCADRemoveTinyUVEdges = (bool) i;
2388 load.clear(std::ios::badbit | load.rdstate());
2390 isOK = static_cast<bool>(load >> i);
2392 _optimiseTinyEdges = (bool) i;
2394 load.clear(std::ios::badbit | load.rdstate());
2396 isOK = static_cast<bool>(load >> val);
2398 _tinyEdgeOptimisationLength = val;
2400 load.clear(std::ios::badbit | load.rdstate());
2402 isOK = static_cast<bool>(load >> i);
2404 _correctSurfaceIntersec = (bool) i;
2406 load.clear(std::ios::badbit | load.rdstate());
2408 isOK = static_cast<bool>(load >> val);
2410 _corrSurfaceIntersCost = val;
2412 load.clear(std::ios::badbit | load.rdstate());
2414 isOK = static_cast<bool>(load >> i);
2416 _useGradation = (bool) i;
2418 load.clear(std::ios::badbit | load.rdstate());
2420 isOK = static_cast<bool>(load >> i);
2422 _useVolumeGradation = (bool) i;
2424 load.clear(std::ios::badbit | load.rdstate());
2426 isOK = static_cast<bool>(load >> val);
2428 _volumeGradation = val;
2430 load.clear(std::ios::badbit | load.rdstate());
2435 if (hasCADSurfOptions) {
2436 isOK = static_cast<bool>(load >> option_or_sm);
2438 if (option_or_sm == "__OPTIONS_BEGIN__")
2440 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2441 hasCustomOptions = true;
2442 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2443 hasPreCADOptions = true;
2444 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2446 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2447 hasAttractor = true;
2448 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2449 hasNewAttractor = true;
2450 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2451 hasEnforcedVertex = true;
2452 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2453 hasPreCADFacesPeriodicity = true;
2454 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2455 hasPreCADEdgesPeriodicity = true;
2456 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2457 hasFacesPeriodicity = true;
2458 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2459 hasEdgesPeriodicity = true;
2460 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2461 hasVerticesPeriodicity = true;
2465 std::string optName, optValue;
2466 while (isOK && hasOptions) {
2467 isOK = static_cast<bool>(load >> optName);
2469 if (optName == "__OPTIONS_END__")
2471 isOK = static_cast<bool>(load >> optValue);
2474 std::string & value = _option2value[optName];
2476 int len = value.size();
2477 // continue reading until "%#" encountered
2478 while (value[len - 1] != '#' || value[len - 2] != '%') {
2479 isOK = static_cast<bool>(load >> optValue);
2488 value.resize(len - 2); //cut off "%#"
2493 isOK = static_cast<bool>(load >> option_or_sm);
2495 if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2496 hasCustomOptions = true;
2497 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2498 hasPreCADOptions = true;
2499 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2501 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2502 hasAttractor = true;
2503 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2504 hasNewAttractor = true;
2505 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2506 hasEnforcedVertex = true;
2507 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2508 hasPreCADFacesPeriodicity = true;
2509 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2510 hasPreCADEdgesPeriodicity = true;
2511 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2512 hasFacesPeriodicity = true;
2513 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2514 hasEdgesPeriodicity = true;
2515 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2516 hasVerticesPeriodicity = true;
2520 while (isOK && hasCustomOptions) {
2521 isOK = static_cast<bool>(load >> optName);
2523 if (optName == "__CUSTOM_OPTIONS_END__")
2525 isOK = static_cast<bool>(load >> optValue);
2528 std::string& value = optValue;
2529 int len = value.size();
2530 // continue reading until "%#" encountered
2531 while (value[len - 1] != '#' || value[len - 2] != '%') {
2532 isOK = static_cast<bool>(load >> optValue);
2541 value.resize(len - 2); //cut off "%#"
2542 _customOption2value[optName] = value;
2546 if (hasCustomOptions) {
2547 isOK = static_cast<bool>(load >> option_or_sm);
2549 if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2550 hasPreCADOptions = true;
2551 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2553 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2554 hasAttractor = true;
2555 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2556 hasNewAttractor = true;
2557 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2558 hasEnforcedVertex = true;
2559 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2560 hasPreCADFacesPeriodicity = true;
2561 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2562 hasPreCADEdgesPeriodicity = true;
2563 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2564 hasFacesPeriodicity = true;
2565 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2566 hasEdgesPeriodicity = true;
2567 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2568 hasVerticesPeriodicity = true;
2572 while (isOK && hasPreCADOptions) {
2573 isOK = static_cast<bool>(load >> optName);
2575 if (optName == "__PRECAD_OPTIONS_END__")
2577 isOK = static_cast<bool>(load >> optValue);
2580 std::string & value = _preCADoption2value[optName];
2582 int len = value.size();
2583 // continue reading until "%#" encountered
2584 while (value[len - 1] != '#' || value[len - 2] != '%') {
2585 isOK = static_cast<bool>(load >> optValue);
2594 value.resize(len - 2); //cut off "%#"
2598 if (hasPreCADOptions) {
2599 isOK = static_cast<bool>(load >> option_or_sm);
2601 if (option_or_sm == "__SIZEMAP_BEGIN__")
2603 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2604 hasAttractor = true;
2605 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2606 hasNewAttractor = true;
2607 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2608 hasEnforcedVertex = true;
2609 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2610 hasPreCADFacesPeriodicity = true;
2611 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2612 hasPreCADEdgesPeriodicity = true;
2613 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2614 hasFacesPeriodicity = true;
2615 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2616 hasEdgesPeriodicity = true;
2617 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2618 hasVerticesPeriodicity = true;
2622 std::string smEntry, smValue;
2623 while (isOK && hasSizeMap) {
2624 isOK = static_cast<bool>(load >> smEntry);
2626 if (smEntry == "__SIZEMAP_END__")
2628 isOK = static_cast<bool>(load >> smValue);
2631 std::string & value2 = _sizeMap[smEntry];
2633 int len2 = value2.size();
2634 // continue reading until "%#" encountered
2635 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2636 isOK = static_cast<bool>(load >> smValue);
2640 len2 = value2.size();
2645 value2.resize(len2 - 2); //cut off "%#"
2650 isOK = static_cast<bool>(load >> option_or_sm);
2652 if (option_or_sm == "__ATTRACTORS_BEGIN__")
2653 hasAttractor = true;
2654 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2655 hasNewAttractor = true;
2656 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2657 hasEnforcedVertex = true;
2658 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2659 hasPreCADFacesPeriodicity = true;
2660 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2661 hasPreCADEdgesPeriodicity = true;
2662 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2663 hasFacesPeriodicity = true;
2664 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2665 hasEdgesPeriodicity = true;
2666 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2667 hasVerticesPeriodicity = true;
2670 std::string atEntry, atValue;
2671 while (isOK && hasAttractor) {
2672 isOK = static_cast<bool>(load >> atEntry);
2674 if (atEntry == "__ATTRACTORS_END__")
2676 isOK = static_cast<bool>(load >> atValue);
2679 std::string & value3 = _attractors[atEntry];
2681 int len3 = value3.size();
2682 // continue reading until "%#" encountered
2683 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
2684 isOK = static_cast<bool>(load >> atValue);
2688 len3 = value3.size();
2693 value3.resize(len3 - 2); //cut off "%#"
2698 isOK = static_cast<bool>(load >> option_or_sm);
2700 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2701 hasNewAttractor = true;
2702 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2703 hasEnforcedVertex = true;
2704 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2705 hasPreCADFacesPeriodicity = true;
2706 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2707 hasPreCADEdgesPeriodicity = true;
2708 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2709 hasFacesPeriodicity = true;
2710 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2711 hasEdgesPeriodicity = true;
2712 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2713 hasVerticesPeriodicity = true;
2717 std::string newAtFaceEntry, atTestString;
2718 std::string newAtShapeEntry;
2719 double attParams[4];
2721 while (isOK && hasNewAttractor) {
2722 //std::cout<<"Load new attractor"<<std::endl;
2723 isOK = static_cast<bool>(load >> newAtFaceEntry);
2725 if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
2727 isOK = static_cast<bool>(load >> newAtShapeEntry);
2730 isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
2733 MESSAGE(" LOADING ATTRACTOR HYPOTHESIS ")
2734 const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
2735 const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
2736 BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
2737 attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
2738 //attractor->BuildMap();
2739 _classAttractors.insert( make_pair( newAtFaceEntry, attractor ));
2744 if (hasNewAttractor) {
2745 isOK = static_cast<bool>(load >> option_or_sm);
2747 if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2748 hasEnforcedVertex = true;
2749 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2750 hasPreCADFacesPeriodicity = true;
2751 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2752 hasPreCADEdgesPeriodicity = true;
2753 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2754 hasFacesPeriodicity = true;
2755 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2756 hasEdgesPeriodicity = true;
2757 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2758 hasVerticesPeriodicity = true;
2764 // Here is a example of the saved stream:
2765 // __ENFORCED_VERTICES_BEGIN__
2766 // __BEGIN_VERTEX__ => no name, no entry
2767 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2768 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__
2769 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__
2771 // __BEGIN_VERTEX__ => no coords
2772 // __BEGIN_NAME__ mes points __END_NAME__
2773 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
2774 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2775 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
2777 // __ENFORCED_VERTICES_END__
2780 std::string enfSeparator;
2781 std::string enfName;
2782 std::string enfGeomEntry;
2783 std::string enfGroup;
2784 TEntryList enfFaceEntryList;
2785 double enfCoords[3];
2786 bool hasCoords = false;
2788 _faceEntryEnfVertexListMap.clear();
2789 _enfVertexList.clear();
2790 _faceEntryCoordsListMap.clear();
2791 _coordsEnfVertexMap.clear();
2792 _faceEntryEnfVertexEntryListMap.clear();
2793 _enfVertexEntryEnfVertexMap.clear();
2796 while (isOK && hasEnforcedVertex) {
2797 isOK = static_cast<bool>(load >> enfSeparator); // __BEGIN_VERTEX__
2798 TEnfVertex *enfVertex = new TEnfVertex();
2799 // MESSAGE("enfSeparator: " <<enfSeparator);
2800 if (enfSeparator == "__ENFORCED_VERTICES_END__")
2801 break; // __ENFORCED_VERTICES_END__
2802 if (enfSeparator != "__BEGIN_VERTEX__")
2803 throw std::exception();
2806 isOK = static_cast<bool>(load >> enfSeparator);
2807 MESSAGE("enfSeparator: " <<enfSeparator);
2808 if (enfSeparator == "__END_VERTEX__") {
2810 enfVertex->name = enfName;
2811 enfVertex->geomEntry = enfGeomEntry;
2812 enfVertex->grpName = enfGroup;
2813 enfVertex->coords.clear();
2815 enfVertex->coords.assign(enfCoords,enfCoords+3);
2816 enfVertex->faceEntries = enfFaceEntryList;
2818 _enfVertexList.insert(enfVertex);
2820 if (enfVertex->coords.size()) {
2821 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
2822 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2823 _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
2824 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2827 if (!enfVertex->geomEntry.empty()) {
2828 _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
2829 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2830 _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
2831 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2836 enfGeomEntry.clear();
2838 enfFaceEntryList.clear();
2840 break; // __END_VERTEX__
2843 if (enfSeparator == "__BEGIN_NAME__") { // __BEGIN_NAME__
2844 while (isOK && (enfSeparator != "__END_NAME__")) {
2845 isOK = static_cast<bool>(load >> enfSeparator);
2846 if (enfSeparator != "__END_NAME__") {
2847 if (!enfName.empty())
2849 enfName += enfSeparator;
2852 MESSAGE("enfName: " <<enfName);
2855 if (enfSeparator == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
2856 isOK = static_cast<bool>(load >> enfGeomEntry);
2857 isOK = static_cast<bool>(load >> enfSeparator); // __END_ENTRY__
2858 if (enfSeparator != "__END_ENTRY__")
2859 throw std::exception();
2860 MESSAGE("enfGeomEntry: " <<enfGeomEntry);
2863 if (enfSeparator == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
2864 while (isOK && (enfSeparator != "__END_GROUP__")) {
2865 isOK = static_cast<bool>(load >> enfSeparator);
2866 if (enfSeparator != "__END_GROUP__") {
2867 if (!enfGroup.empty())
2869 enfGroup += enfSeparator;
2872 MESSAGE("enfGroup: " <<enfGroup);
2875 if (enfSeparator == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
2877 isOK = static_cast<bool>(load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
2878 isOK = static_cast<bool>(load >> enfSeparator); // __END_COORDS__
2879 if (enfSeparator != "__END_COORDS__")
2880 throw std::exception();
2881 MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
2884 if (enfSeparator == "__BEGIN_FACELIST__") { // __BEGIN_FACELIST__
2885 while (isOK && (enfSeparator != "__END_FACELIST__")) {
2886 isOK = static_cast<bool>(load >> enfSeparator);
2887 if (enfSeparator != "__END_FACELIST__") {
2888 enfFaceEntryList.insert(enfSeparator);
2889 MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
2898 if (hasPreCADFacesPeriodicity){
2899 LoadPreCADPeriodicity(load, "FACES");
2901 isOK = static_cast<bool>(load >> option_or_sm);
2903 if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2904 hasPreCADEdgesPeriodicity = true;
2905 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2906 hasFacesPeriodicity = true;
2907 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2908 hasEdgesPeriodicity = true;
2909 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2910 hasVerticesPeriodicity = true;
2914 if (hasPreCADEdgesPeriodicity){
2915 LoadPreCADPeriodicity(load, "EDGES");
2917 isOK = static_cast<bool>(load >> option_or_sm);
2919 if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2920 hasFacesPeriodicity = true;
2921 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2922 hasEdgesPeriodicity = true;
2923 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2924 hasVerticesPeriodicity = true;
2928 if (hasFacesPeriodicity){
2929 LoadFacesPeriodicity(load);
2931 isOK = static_cast<bool>(load >> option_or_sm);
2933 if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2934 hasEdgesPeriodicity = true;
2935 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2936 hasVerticesPeriodicity = true;
2940 if (hasEdgesPeriodicity){
2941 LoadEdgesPeriodicity(load);
2943 isOK = static_cast<bool>(load >> option_or_sm);
2945 if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2946 hasVerticesPeriodicity = true;
2949 if (hasVerticesPeriodicity)
2950 LoadVerticesPeriodicity(load);
2955 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
2959 std::string periodicitySeparator;
2963 _facesPeriodicityVector.clear();
2966 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2967 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2968 TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
2969 if (periodicitySeparator == "__FACES_PERIODICITY_END__")
2970 break; // __FACES_PERIODICITY_END__
2971 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2972 MESSAGE("//" << periodicitySeparator << "//");
2973 throw std::exception();
2977 isOK = static_cast<bool>(load >> periodicitySeparator);
2978 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2979 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2981 periodicity_i->first = shape1Entry;
2982 periodicity_i->second = shape2Entry;
2984 _facesPeriodicityVector.push_back(*periodicity_i);
2986 break; // __END_PERIODICITY_DESCRIPTION__
2989 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
2990 isOK = static_cast<bool>(load >> shape1Entry);
2991 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
2992 if (periodicitySeparator != "__END_ENTRY1__")
2993 throw std::exception();
2994 MESSAGE("shape1Entry: " <<shape1Entry);
2997 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
2998 isOK = static_cast<bool>(load >> shape2Entry);
2999 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3000 if (periodicitySeparator != "__END_ENTRY2__")
3001 throw std::exception();
3002 MESSAGE("shape2Entry: " <<shape2Entry);
3009 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
3013 std::string periodicitySeparator;
3014 TEntry theFace1Entry;
3015 TEntry theEdge1Entry;
3016 TEntry theFace2Entry;
3017 TEntry theEdge2Entry;
3018 int edge_orientation = 0;
3020 _edgesPeriodicityVector.clear();
3023 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3024 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3025 TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
3026 if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
3027 break; // __EDGES_PERIODICITY_END__
3028 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3029 MESSAGE("//" << periodicitySeparator << "//");
3030 throw std::exception();
3034 isOK = static_cast<bool>(load >> periodicitySeparator);
3035 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3036 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3038 periodicity_i->theFace1Entry = theFace1Entry;
3039 periodicity_i->theEdge1Entry = theEdge1Entry;
3040 periodicity_i->theFace2Entry = theFace2Entry;
3041 periodicity_i->theEdge2Entry = theEdge2Entry;
3042 periodicity_i->edge_orientation = edge_orientation;
3044 _edgesPeriodicityVector.push_back(*periodicity_i);
3046 break; // __END_PERIODICITY_DESCRIPTION__
3049 if (periodicitySeparator == "__BEGIN_FACE1__") { // __BEGIN_FACE1__
3050 isOK = static_cast<bool>(load >> theFace1Entry);
3051 MESSAGE("//" << theFace1Entry << "//");
3052 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE1__
3053 if (periodicitySeparator != "__END_FACE1__"){
3054 MESSAGE("//" << periodicitySeparator << "//");
3055 throw std::exception();
3057 MESSAGE("theFace1Entry: " <<theFace1Entry);
3060 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3061 isOK = static_cast<bool>(load >> theEdge1Entry);
3062 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3063 if (periodicitySeparator != "__END_EDGE1__")
3064 throw std::exception();
3065 MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3068 if (periodicitySeparator == "__BEGIN_FACE2__") { // __BEGIN_FACE2__
3069 isOK = static_cast<bool>(load >> theFace2Entry);
3070 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE2__
3071 if (periodicitySeparator != "__END_FACE2__")
3072 throw std::exception();
3073 MESSAGE("theFace2Entry: " <<theFace2Entry);
3076 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3077 isOK = static_cast<bool>(load >> theEdge2Entry);
3078 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3079 if (periodicitySeparator != "__END_EDGE2__")
3080 throw std::exception();
3081 MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3084 if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") { // __BEGIN_EDGE_ORIENTATION__
3085 isOK = static_cast<bool>(load >> edge_orientation);
3086 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
3087 if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
3088 throw std::exception();
3089 MESSAGE("edge_orientation: " <<edge_orientation);
3095 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
3099 std::string periodicitySeparator;
3100 TEntry theEdge1Entry;
3101 TEntry theVertex1Entry;
3102 TEntry theEdge2Entry;
3103 TEntry theVertex2Entry;
3105 _verticesPeriodicityVector.clear();
3108 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3109 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3110 TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
3111 if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
3112 break; // __VERTICES_PERIODICITY_END__
3113 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3114 MESSAGE("//" << periodicitySeparator << "//");
3115 throw std::exception();
3119 isOK = static_cast<bool>(load >> periodicitySeparator);
3120 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3121 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3123 periodicity_i->theEdge1Entry = theEdge1Entry;
3124 periodicity_i->theVertex1Entry = theVertex1Entry;
3125 periodicity_i->theEdge2Entry = theEdge2Entry;
3126 periodicity_i->theVertex2Entry = theVertex2Entry;
3128 _verticesPeriodicityVector.push_back(*periodicity_i);
3130 break; // __END_PERIODICITY_DESCRIPTION__
3133 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3134 isOK = static_cast<bool>(load >> theEdge1Entry);
3135 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3136 if (periodicitySeparator != "__END_EDGE1__")
3137 throw std::exception();
3138 MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3141 if (periodicitySeparator == "__BEGIN_VERTEX1__") { // __BEGIN_VERTEX1__
3142 isOK = static_cast<bool>(load >> theVertex1Entry);
3143 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX1__
3144 if (periodicitySeparator != "__END_VERTEX1__")
3145 throw std::exception();
3146 MESSAGE("theVertex1Entry: " <<theVertex1Entry);
3149 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3150 isOK = static_cast<bool>(load >> theEdge2Entry);
3151 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3152 if (periodicitySeparator != "__END_EDGE2__")
3153 throw std::exception();
3154 MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3157 if (periodicitySeparator == "__BEGIN_VERTEX2__") { // __BEGIN_VERTEX2__
3158 isOK = static_cast<bool>(load >> theVertex2Entry);
3159 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX2__
3160 if (periodicitySeparator != "__END_VERTEX2__")
3161 throw std::exception();
3162 MESSAGE("theVertex2Entry: " <<theVertex2Entry);
3168 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
3172 std::string periodicitySeparator;
3175 std::vector<std::string> theSourceVerticesEntries;
3176 std::vector<std::string> theTargetVerticesEntries;
3178 bool hasSourceVertices = false;
3179 bool hasTargetVertices = false;
3181 if ( shapeType && strcmp( shapeType, "FACES") == 0 )
3182 _preCadFacesPeriodicityVector.clear();
3184 _preCadEdgesPeriodicityVector.clear();
3188 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3189 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3190 TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
3191 // MESSAGE("periodicitySeparator: " <<periodicitySeparator);
3192 std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
3193 if (periodicitySeparator == endSeparator)
3194 break; // __PRECAD_FACES_PERIODICITY_END__
3195 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3196 MESSAGE("//" << endSeparator << "//");
3197 MESSAGE("//" << periodicitySeparator << "//");
3198 throw std::exception();
3202 isOK = static_cast<bool>(load >> periodicitySeparator);
3203 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3204 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3206 periodicity_i->shape1Entry = shape1Entry;
3207 periodicity_i->shape2Entry = shape2Entry;
3209 MESSAGE("theSourceVerticesEntries.size(): " << theSourceVerticesEntries.size());
3210 MESSAGE("theTargetVerticesEntries.size(): " << theTargetVerticesEntries.size());
3212 if (hasSourceVertices)
3213 periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
3214 if (hasTargetVertices)
3215 periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
3217 if ( shapeType && strcmp( shapeType, "FACES" ))
3218 _preCadFacesPeriodicityVector.push_back(*periodicity_i);
3220 _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
3222 theSourceVerticesEntries.clear();
3223 theTargetVerticesEntries.clear();
3224 hasSourceVertices = false;
3225 hasTargetVertices = false;
3226 break; // __END_PERIODICITY_DESCRIPTION__
3229 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3230 isOK = static_cast<bool>(load >> shape1Entry);
3231 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3232 if (periodicitySeparator != "__END_ENTRY1__")
3233 throw std::exception();
3234 MESSAGE("shape1Entry: " <<shape1Entry);
3237 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3238 isOK = static_cast<bool>(load >> shape2Entry);
3239 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3240 if (periodicitySeparator != "__END_ENTRY2__")
3241 throw std::exception();
3242 MESSAGE("shape2Entry: " <<shape2Entry);
3245 if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") { // __BEGIN_SOURCE_VERTICES_LIST__
3246 hasSourceVertices = true;
3247 while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
3248 isOK = static_cast<bool>(load >> periodicitySeparator);
3249 if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
3250 theSourceVerticesEntries.push_back(periodicitySeparator);
3251 MESSAGE("theSourceVerticesEntries: " <<periodicitySeparator);
3256 if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") { // __BEGIN_TARGET_VERTICES_LIST__
3257 hasTargetVertices = true;
3258 while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
3259 isOK = static_cast<bool>(load >> periodicitySeparator);
3260 if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
3261 theTargetVerticesEntries.push_back(periodicitySeparator);
3262 MESSAGE("theTargetVerticesEntries: " <<periodicitySeparator);
3270 //=============================================================================
3271 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
3272 return hyp.SaveTo(save);
3275 //=============================================================================
3276 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
3277 return hyp.LoadFrom(load);
3280 //================================================================================
3282 * \brief Does nothing
3284 //================================================================================
3286 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
3290 //================================================================================
3292 * \brief Returns default global constant physical size given a default value of element length ratio
3294 //================================================================================
3296 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
3297 if (bbSegmentation != 0 && diagonal != 0)
3298 return diagonal / bbSegmentation ;
3302 //================================================================================
3304 * \brief Returns default min size given a default value of element length ratio
3306 //================================================================================
3308 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
3310 return diagonal / 1000.0 ;
3311 return undefinedDouble();
3314 //================================================================================
3316 * \brief Returns default max size given a default value of element length ratio
3318 //================================================================================
3320 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
3322 return diagonal / 5.0 ;
3323 return undefinedDouble();
3326 //================================================================================
3328 * \brief Returns default chordal error given a default value of element length ratio
3330 //================================================================================
3332 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
3335 return undefinedDouble();
3338 //================================================================================
3340 * \brief Returns default tiny edge length given a default value of element length ratio
3342 //================================================================================
3344 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
3346 return diagonal * 1e-6 ;
3347 return undefinedDouble();
3350 //================================================================================
3352 * \brief Returns default tiny edge optimisation length given a default value of element length ratio
3354 //================================================================================
3356 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal) {
3358 return diagonal * 1e-6 ;
3359 return undefinedDouble();
3362 //=============================================================================
3364 * \brief Initialize my parameter values by default parameters.
3365 * \retval bool - true if parameter values have been successfully defined
3367 //=============================================================================
3369 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
3370 double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
3371 _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
3372 _minSize = GetDefaultMinSize(diagonal);
3373 _maxSize = GetDefaultMaxSize(diagonal);
3374 _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
3375 _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
3376 _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(diagonal);
3381 //================================================================================
3383 * \brief Converts a string to a bool
3385 //================================================================================
3387 bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
3388 throw (std::invalid_argument)
3390 std::string s = str;
3391 if ( isOk ) *isOk = true;
3393 for ( size_t i = 0; i <= s.size(); ++i )
3394 s[i] = tolower( s[i] );
3396 if ( s == "1" || s == "true" || s == "active" || s == "yes" )
3399 if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
3405 std::string msg = "Not a Boolean value:'" + str + "'";
3406 throw std::invalid_argument(msg);
3411 //================================================================================
3413 * \brief Converts a string to a real value
3415 //================================================================================
3417 double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
3418 throw (std::invalid_argument)
3420 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3423 double val = strtod(&str[0], &endPtr);
3424 bool ok = (&str[0] != endPtr);
3426 if ( isOk ) *isOk = ok;
3430 std::string msg = "Not a real value:'" + str + "'";
3431 throw std::invalid_argument(msg);
3436 //================================================================================
3438 * \brief Converts a string to a integer value
3440 //================================================================================
3442 int BLSURFPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
3443 throw (std::invalid_argument)
3445 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3448 int val = (int)strtol( &str[0], &endPtr, 10);
3449 bool ok = (&str[0] != endPtr);
3451 if ( isOk ) *isOk = ok;
3455 std::string msg = "Not an integer value:'" + str + "'";
3456 throw std::invalid_argument(msg);