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, SMESH_Gen * gen) :
53 SMESH_Hypothesis(hypId, gen),
54 _physicalMesh(GetDefaultPhysicalMesh()),
55 _geometricMesh(GetDefaultGeometricMesh()),
56 _phySize(GetDefaultPhySize()),
57 _phySizeRel(GetDefaultPhySizeRel()),
58 _minSize(GetDefaultMinSize()),
59 _maxSize(GetDefaultMaxSize()),
60 _minSizeRel(GetDefaultMinSizeRel()),
61 _maxSizeRel(GetDefaultMaxSizeRel()),
62 _useGradation(GetDefaultUseGradation()),
63 _gradation(GetDefaultGradation()),
64 _useVolumeGradation(GetDefaultUseVolumeGradation()),
65 _volumeGradation(GetDefaultVolumeGradation()),
66 _quadAllowed(GetDefaultQuadAllowed()),
67 _angleMesh(GetDefaultAngleMesh()),
68 _chordalError(GetDefaultChordalError()),
69 _anisotropic(GetDefaultAnisotropic()),
70 _anisotropicRatio(GetDefaultAnisotropicRatio()),
71 _removeTinyEdges(GetDefaultRemoveTinyEdges()),
72 _tinyEdgeLength(GetDefaultTinyEdgeLength()),
73 _optimiseTinyEdges(GetDefaultOptimiseTinyEdges()),
74 _tinyEdgeOptimisationLength(GetDefaultTinyEdgeOptimisationLength()),
75 _correctSurfaceIntersec(GetDefaultCorrectSurfaceIntersection()),
76 _corrSurfaceIntersCost(GetDefaultCorrectSurfaceIntersectionMaxCost()),
77 _badElementRemoval(GetDefaultBadElementRemoval()),
78 _badElementAspectRatio(GetDefaultBadElementAspectRatio()),
79 _optimizeMesh(GetDefaultOptimizeMesh()),
80 _quadraticMesh(GetDefaultQuadraticMesh()),
81 _verb(GetDefaultVerbosity()),
82 _topology(GetDefaultTopology()),
83 _preCADMergeEdges(GetDefaultPreCADMergeEdges()),
84 _preCADRemoveTinyUVEdges(GetDefaultPreCADRemoveTinyUVEdges()),
85 _preCADRemoveDuplicateCADFaces(GetDefaultPreCADRemoveDuplicateCADFaces()),
86 _preCADProcess3DTopology(GetDefaultPreCADProcess3DTopology()),
87 _preCADDiscardInput(GetDefaultPreCADDiscardInput()),
88 _sizeMap(GetDefaultSizeMap()),
89 _attractors(GetDefaultSizeMap()),
90 _classAttractors(GetDefaultAttractorMap()),
91 _faceEntryEnfVertexListMap(GetDefaultFaceEntryEnfVertexListMap()),
92 _enfVertexList(GetDefaultEnfVertexList()),
93 _faceEntryCoordsListMap(GetDefaultFaceEntryCoordsListMap()),
94 _coordsEnfVertexMap(GetDefaultCoordsEnfVertexMap()),
95 _faceEntryEnfVertexEntryListMap(GetDefaultFaceEntryEnfVertexEntryListMap()),
96 _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
97 _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap()),
98 _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex()),
99 _preCadFacesPeriodicityVector(GetDefaultPreCadFacesPeriodicityVector()),
100 _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector()),
101 _GMFFileName(GetDefaultGMFFile())
103 _name = GetHypType();
106 // _GMFFileMode = false; // GMF ascii mode
108 // Advanced options with their defaults according to MG User Manual
110 const char* boolOptionNames[] = { "enforce_cad_edge_sizes", // default = 0
111 // "correct_surface_intersections", // default = 1
112 // "create_tag_on_collision", // default = 1
113 "jacobian_rectification_respect_geometry", // default = 1
114 "rectify_jacobian", // default = 1
115 "respect_geometry", // default = 1
116 // "optimise_tiny_edges", // default = 0
117 // "remove_duplicate_cad_faces", // default = 1
118 "tiny_edge_avoid_surface_intersections", // default = 1
119 // "tiny_edge_respect_geometry", // default = 0
123 const char* intOptionNames[] = { "max_number_of_points_per_patch", // default = 100000
126 const char* doubleOptionNames[] = { // "surface_intersections_processing_max_cost",// default = 15
127 // "periodic_tolerance", // default = diag/100
128 // "volume_gradation",
129 // "tiny_edge_optimisation_length", // default = diag * 1e-6
132 const char* charOptionNames[] = { // "required_entities", // default = "respect"
133 // "tags", // default = "respect"
137 // PreCAD advanced options
138 const char* preCADboolOptionNames[] = { "closed_geometry", // default = 0
139 "discard_input_topology", // default = 0
140 "merge_edges", // default = = 1
141 "remove_duplicate_cad_faces", // default = 1
142 // "create_tag_on_collision", // default = 1
143 "debug", // default = 0
144 "process_3d_topology", // default = 1
145 // "remove_tiny_edges", // default = 0
148 const char* preCADintOptionNames[] = { // "manifold_geometry", // default = 0
151 const char* preCADdoubleOptionNames[] = { "periodic_tolerance", // default = diag * 1e-5
152 "sewing_tolerance", // default = diag * 5e-4
153 // "tiny_edge_length", // default = diag * 1e-5
156 const char* preCADcharOptionNames[] = { "required_entities", // default = "respect"
157 "tags", // default = "respect"
162 while (boolOptionNames[i][0])
164 _boolOptions.insert( boolOptionNames[i] );
165 _option2value[boolOptionNames[i++]].clear();
168 while (preCADboolOptionNames[i][0])
170 _boolOptions.insert( preCADboolOptionNames[i] );
171 _preCADoption2value[preCADboolOptionNames[i++]].clear();
174 while (intOptionNames[i][0])
175 _option2value[intOptionNames[i++]].clear();
178 while (preCADintOptionNames[i][0])
179 _preCADoption2value[preCADintOptionNames[i++]].clear();
182 while (doubleOptionNames[i][0]) {
183 _doubleOptions.insert(doubleOptionNames[i]);
184 _option2value[doubleOptionNames[i++]].clear();
187 while (preCADdoubleOptionNames[i][0]) {
188 _preCADdoubleOptions.insert(preCADdoubleOptionNames[i]);
189 _preCADoption2value[preCADdoubleOptionNames[i++]].clear();
192 while (charOptionNames[i][0]) {
193 _charOptions.insert(charOptionNames[i]);
194 _option2value[charOptionNames[i++]].clear();
197 while (preCADcharOptionNames[i][0]) {
198 _preCADcharOptions.insert(preCADcharOptionNames[i]);
199 _preCADoption2value[preCADcharOptionNames[i++]].clear();
202 // default values to be used while MG meshing
204 _defaultOptionValues["enforce_cad_edge_sizes" ] = "no";
205 _defaultOptionValues["jacobian_rectification_respect_geometry"] = "yes";
206 _defaultOptionValues["max_number_of_points_per_patch" ] = "0";
207 _defaultOptionValues["rectify_jacobian" ] = "yes";
208 _defaultOptionValues["respect_geometry" ] = "yes";
209 _defaultOptionValues["tiny_edge_avoid_surface_intersections" ] = "yes";
210 _defaultOptionValues["process_3d_topology" ] = "no";
211 _defaultOptionValues["closed_geometry" ] = "no";
212 _defaultOptionValues["debug" ] = "no";
213 _defaultOptionValues["discard_input_topology" ] = "no";
214 _defaultOptionValues["merge_edges" ] = "no";
215 _defaultOptionValues["periodic_tolerance" ] = "1e-5*D";
216 _defaultOptionValues["remove_duplicate_cad_faces" ] = "no";
217 _defaultOptionValues["required_entities" ] = "respect";
218 _defaultOptionValues["sewing_tolerance" ] = "5e-4*D";
219 _defaultOptionValues["tags" ] = "respect";
222 // check validity of option names of _defaultOptionValues
223 TOptionValues::iterator n2v = _defaultOptionValues.begin();
224 for ( ; n2v != _defaultOptionValues.end(); ++n2v )
225 ASSERT( _option2value.count( n2v->first ) || _preCADoption2value.count( n2v->first ));
226 ASSERT( _option2value.size() + _preCADoption2value.size() == _defaultOptionValues.size() );
231 _faceEntryEnfVertexListMap.clear();
232 _enfVertexList.clear();
233 _faceEntryCoordsListMap.clear();
234 _coordsEnfVertexMap.clear();
235 _faceEntryEnfVertexEntryListMap.clear();
236 _enfVertexEntryEnfVertexMap.clear();
237 _groupNameNodeIDMap.clear();
240 _groupNameEnfVertexListMap.clear();
241 _enfVertexGroupNameMap.clear();
245 TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry)
247 MESSAGE("BLSURFPlugin_Hypothesis::entryToShape "<<entry );
248 GEOM::GEOM_Object_var aGeomObj;
250 TopoDS_Shape S = TopoDS_Shape();
251 SALOMEDS::SObject_var aSObj = SMESH_Gen_i::getStudyServant()->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 = SMESH_Gen_i::GetSMESHGen()->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 != ToBool( GetPreCADOptionValue("merge_edges", GET_DEFAULT()))) {
690 _preCADMergeEdges = theVal;
691 SetPreCADOptionValue("merge_edges", theVal ? "yes" : "no" );
692 NotifySubMeshesHypothesisModification();
696 //=============================================================================
697 void BLSURFPlugin_Hypothesis::SetPreCADRemoveTinyUVEdges(bool theVal)
699 if (theVal != _preCADRemoveTinyUVEdges) {
700 _preCADRemoveTinyUVEdges = theVal;
701 NotifySubMeshesHypothesisModification();
705 //=============================================================================
706 void BLSURFPlugin_Hypothesis::SetPreCADRemoveDuplicateCADFaces(bool theVal)
708 if (theVal != ToBool( GetPreCADOptionValue("remove_duplicate_cad_faces", GET_DEFAULT()))) {
709 _preCADRemoveDuplicateCADFaces = theVal;
710 SetPreCADOptionValue("remove_duplicate_cad_faces", theVal ? "yes" : "no" );
711 NotifySubMeshesHypothesisModification();
715 //=============================================================================
716 void BLSURFPlugin_Hypothesis::SetPreCADProcess3DTopology(bool theVal)
718 if (theVal != ToBool( GetPreCADOptionValue("process_3d_topology", GET_DEFAULT()))) {
719 _preCADProcess3DTopology = theVal;
720 SetPreCADOptionValue("process_3d_topology", theVal ? "yes" : "no" );
721 NotifySubMeshesHypothesisModification();
725 //=============================================================================
726 void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal)
728 if (theVal != ToBool( GetPreCADOptionValue("discard_input_topology", GET_DEFAULT()))) {
729 _preCADDiscardInput = theVal;
730 SetPreCADOptionValue("discard_input_topology", theVal ? "yes" : "no" );
731 NotifySubMeshesHypothesisModification();
735 //=============================================================================
736 // Return true if any PreCAD option is activated
737 bool BLSURFPlugin_Hypothesis::HasPreCADOptions(const BLSURFPlugin_Hypothesis* hyp)
743 bool orDefault, isOk;
744 return ( ToBool( hyp->GetPreCADOptionValue("closed_geometry" , &orDefault )) ||
745 ToBool( hyp->GetPreCADOptionValue("discard_input_topology" , &orDefault )) ||
746 ToBool( hyp->GetPreCADOptionValue("merge_edges" , &orDefault )) ||
747 ToBool( hyp->GetPreCADOptionValue("remove_duplicate_cad_faces", &orDefault )) ||
748 ToBool( hyp->GetPreCADOptionValue("process_3d_topology" , &orDefault )) ||
749 ToBool( hyp->GetPreCADOption ("manifold_geometry") , &isOk ) ||
750 hyp->GetPreCADOptionValue("sewing_tolerance", &orDefault ) != "5e-4*D" ||
751 !hyp->_preCadFacesPeriodicityVector.empty() ||
752 !hyp->_preCadEdgesPeriodicityVector.empty() ||
753 !hyp->_facesPeriodicityVector.empty() ||
754 !hyp->_edgesPeriodicityVector.empty() ||
755 !hyp->_verticesPeriodicityVector.empty() ||
756 hyp->GetTopology() != FromCAD );
759 //=============================================================================
760 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
761 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
763 _GMFFileName = theFileName;
764 // _GMFFileMode = isBinary;
765 NotifySubMeshesHypothesisModification();
768 //=============================================================================
769 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
770 throw (std::invalid_argument) {
772 TOptionValues::iterator op_val = _option2value.find(optionName);
773 if (op_val == _option2value.end())
775 op_val = _preCADoption2value.find(optionName);
776 if (op_val == _preCADoption2value.end())
778 std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'. Try SetAdvancedOption()";
779 throw std::invalid_argument(msg);
782 if (op_val->second != optionValue)
784 const char* ptr = optionValue.c_str();
785 // strip white spaces
786 while (ptr[0] == ' ')
789 while (i != 0 && ptr[i - 1] == ' ')
793 std::string typeName;
796 } else if (_charOptions.count(optionName)) {
797 // do not check strings
798 } else if (_doubleOptions.count(optionName)) {
799 // check if value is double
802 } else if (_boolOptions.count(optionName)) {
803 // check if value is bool
804 ToBool(ptr, &typeOk);
807 // check if value is int
809 typeName = "integer";
812 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
813 throw std::invalid_argument(msg);
815 std::string value( ptr, i );
816 if ( _defaultOptionValues[ optionName ] == value )
819 op_val->second = value;
821 NotifySubMeshesHypothesisModification();
825 //=============================================================================
826 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
827 throw (std::invalid_argument) {
829 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
830 if (op_val == _preCADoption2value.end()) {
831 op_val = _option2value.find(optionName);
832 if (op_val == _option2value.end()) {
833 std::string msg = "Unknown MG-PreCAD option: '" + optionName + "'. Try SetAdvancedOption()";
834 throw std::invalid_argument(msg);
837 if (op_val->second != optionValue)
839 const char* ptr = optionValue.c_str();
840 // strip white spaces
841 while (ptr[0] == ' ')
844 while (i != 0 && ptr[i - 1] == ' ')
848 std::string typeName;
851 } else if (_preCADcharOptions.find(optionName) != _preCADcharOptions.end()) {
852 // do not check strings
853 } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
854 // check if value is double
856 strtod(ptr, &endPtr);
857 typeOk = (ptr != endPtr);
859 } else if (_boolOptions.count(optionName)) {
860 // check if value is bool
861 ToBool(ptr, &typeOk);
864 // check if value is int
866 strtol(ptr, &endPtr, 10);
867 typeOk = (ptr != endPtr);
868 typeName = "integer";
871 std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
872 throw std::invalid_argument(msg);
874 std::string value( ptr, i );
875 if ( _defaultOptionValues[ optionName ] == value )
878 op_val->second = value;
880 NotifySubMeshesHypothesisModification();
884 //=============================================================================
885 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
886 bool* isDefault) const
887 throw (std::invalid_argument)
889 TOptionValues::const_iterator op_val = _option2value.find(optionName);
890 if (op_val == _option2value.end())
892 op_val = _preCADoption2value.find(optionName);
893 if (op_val == _preCADoption2value.end())
895 op_val = _customOption2value.find(optionName);
896 if (op_val == _customOption2value.end())
898 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
899 throw std::invalid_argument(msg);
903 std::string val = op_val->second;
904 if ( isDefault ) *isDefault = ( val.empty() );
906 if ( val.empty() && isDefault )
908 op_val = _defaultOptionValues.find( optionName );
909 if (op_val != _defaultOptionValues.end())
910 val = op_val->second;
915 //=============================================================================
916 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName,
917 bool* isDefault) const
918 throw (std::invalid_argument)
920 TOptionValues::const_iterator op_val = _preCADoption2value.find(optionName);
921 if (op_val == _preCADoption2value.end())
923 op_val = _option2value.find(optionName);
924 if (op_val == _option2value.end())
926 op_val = _customOption2value.find(optionName);
927 if (op_val == _customOption2value.end())
929 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
930 throw std::invalid_argument(msg);
934 std::string val = op_val->second;
935 if ( isDefault ) *isDefault = ( val.empty() );
937 if ( val.empty() && isDefault )
939 op_val = _defaultOptionValues.find( optionName );
940 if (op_val != _option2value.end())
941 val = op_val->second;
946 //=============================================================================
947 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
949 TOptionValues::iterator op_val = _customOption2value.find(optionName);
950 if (op_val != _customOption2value.end())
951 _customOption2value.erase(op_val);
953 op_val = _option2value.find(optionName);
954 if (op_val != _option2value.end())
955 op_val->second.clear();
957 op_val = _preCADoption2value.find(optionName);
958 if (op_val != _preCADoption2value.end())
959 op_val->second.clear();
964 //=============================================================================
965 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName)
967 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
968 if (op_val != _preCADoption2value.end())
969 op_val->second.clear();
972 //=============================================================================
973 void BLSURFPlugin_Hypothesis::AddOption(const std::string& optionName, const std::string& optionValue)
976 TOptionValues::iterator op_val = _option2value.find(optionName);
977 if (op_val != _option2value.end())
979 if (op_val->second != optionValue)
980 op_val->second = optionValue;
986 op_val = _preCADoption2value.find(optionName);
987 if (op_val != _preCADoption2value.end())
989 if (op_val->second != optionValue)
990 op_val->second = optionValue;
994 else if ( optionValue.empty() )
996 _customOption2value.erase( optionName );
1000 op_val = _customOption2value.find(optionName);
1001 if (op_val == _customOption2value.end())
1002 _customOption2value[optionName] = optionValue;
1003 else if (op_val->second != optionValue)
1004 op_val->second = optionValue;
1010 NotifySubMeshesHypothesisModification();
1013 //=============================================================================
1014 void BLSURFPlugin_Hypothesis::AddPreCADOption(const std::string& optionName, const std::string& optionValue)
1016 AddOption( optionName, optionValue );
1019 //=============================================================================
1020 std::string BLSURFPlugin_Hypothesis::GetOption(const std::string& optionName) const
1022 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1023 if (op_val != _customOption2value.end())
1024 return op_val->second;
1029 //=============================================================================
1030 std::string BLSURFPlugin_Hypothesis::GetPreCADOption(const std::string& optionName) const
1032 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1033 if (op_val != _customOption2value.end())
1034 return op_val->second;
1039 //=============================================================================
1040 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetOptionValues() const
1043 TOptionValues::const_iterator op_val = _option2value.begin();
1044 for ( ; op_val != _option2value.end(); ++op_val )
1045 vals.insert( make_pair( op_val->first, GetOptionValue( op_val->first, GET_DEFAULT() )));
1050 //=============================================================================
1051 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetPreCADOptionValues() const
1054 TOptionValues::const_iterator op_val = _preCADoption2value.begin();
1055 for ( ; op_val != _preCADoption2value.end(); ++op_val )
1056 vals.insert( make_pair( op_val->first, GetPreCADOptionValue( op_val->first, GET_DEFAULT() )));
1061 //=======================================================================
1062 //function : SetSizeMapEntry
1063 //=======================================================================
1064 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
1065 if (_sizeMap[entry].compare(sizeMap) != 0) {
1066 SetPhysicalMesh(PhysicalLocalSize);
1067 _sizeMap[entry] = sizeMap;
1068 NotifySubMeshesHypothesisModification();
1072 //=======================================================================
1073 //function : GetSizeMapEntry
1074 //=======================================================================
1075 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
1076 TSizeMap::iterator it = _sizeMap.find(entry);
1077 if (it != _sizeMap.end())
1080 return "No_Such_Entry";
1084 * \brief Return the size maps
1086 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
1087 return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
1090 //=======================================================================
1091 //function : SetAttractorEntry
1092 //=======================================================================
1093 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
1094 if (_attractors[entry].compare(attractor) != 0) {
1095 SetPhysicalMesh(PhysicalLocalSize);
1096 _attractors[entry] = attractor;
1097 NotifySubMeshesHypothesisModification();
1101 //=======================================================================
1102 //function : GetAttractorEntry
1103 //=======================================================================
1104 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
1105 TSizeMap::iterator it = _attractors.find(entry);
1106 if (it != _attractors.end())
1109 return "No_Such_Entry";
1113 * \brief Return the attractors
1115 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
1116 return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
1119 //=======================================================================
1120 //function : SetClassAttractorEntry
1121 //=======================================================================
1122 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
1124 SetPhysicalMesh(PhysicalLocalSize);
1126 // The new attractor can't be defined on the same face as another sizemap
1127 TSizeMap::iterator it = _sizeMap.find( entry );
1128 if ( it != _sizeMap.end() ) {
1130 NotifySubMeshesHypothesisModification();
1133 TSizeMap::iterator itAt = _attractors.find( entry );
1134 if ( itAt != _attractors.end() ) {
1135 _attractors.erase(itAt);
1136 NotifySubMeshesHypothesisModification();
1140 const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
1141 const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
1142 TAttractorMap::iterator attIt = _classAttractors.find(entry);
1143 for ( ; attIt != _classAttractors.end(); ++attIt )
1144 if ( attIt->first == entry &&
1145 attIt->second->GetAttractorEntry() == attEntry )
1147 bool attExists = (attIt != _classAttractors.end());
1149 BLSURFPlugin_Attractor* myAttractor;
1151 myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 );
1152 _classAttractors.insert( make_pair( entry, myAttractor ));
1155 myAttractor = attIt->second;
1157 // if (!myAttractor->IsMapBuilt())
1158 // myAttractor->BuildMap();
1159 myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
1161 NotifySubMeshesHypothesisModification();
1164 //=======================================================================
1165 //function : SetConstantSizeOnAdjacentFaces
1166 //=======================================================================
1167 // TODO uncomment and test (include the needed .hxx)
1168 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist ) {
1169 // TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
1170 // TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
1171 // TopTools_IndexedMapOfShapListOdShape::iterator it;
1172 // for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
1173 // SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
1181 //=======================================================================
1182 //function : GetClassAttractorEntry
1183 //=======================================================================
1184 // BLSURFPlugin_Attractor& BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
1186 // TAttractorMap::iterator it = _classAttractors.find( entry );
1187 // if ( it != _classAttractors.end() )
1188 // return it->second;
1190 // return "No_Such_Entry";
1194 * \brief Return the map of attractor instances
1196 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
1198 return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
1201 //=======================================================================
1202 //function : ClearEntry
1203 //=======================================================================
1204 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
1205 const char * attEntry/*=0*/)
1207 TSizeMap::iterator it = _sizeMap.find( entry );
1209 if ( it != _sizeMap.end() ) {
1211 NotifySubMeshesHypothesisModification();
1214 TSizeMap::iterator itAt = _attractors.find( entry );
1215 if ( itAt != _attractors.end() ) {
1216 _attractors.erase(itAt);
1217 NotifySubMeshesHypothesisModification();
1220 TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
1221 if ( it_clAt != _classAttractors.end() ) {
1223 if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
1224 _classAttractors.erase( it_clAt++ );
1228 while ( it_clAt != _classAttractors.end() );
1229 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 if ( value[ len - 1] == '#' )
2489 value.resize(len - 2); //cut off "%#"
2494 isOK = static_cast<bool>(load >> option_or_sm);
2496 if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2497 hasCustomOptions = true;
2498 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2499 hasPreCADOptions = true;
2500 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2502 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2503 hasAttractor = true;
2504 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2505 hasNewAttractor = true;
2506 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2507 hasEnforcedVertex = true;
2508 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2509 hasPreCADFacesPeriodicity = true;
2510 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2511 hasPreCADEdgesPeriodicity = true;
2512 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2513 hasFacesPeriodicity = true;
2514 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2515 hasEdgesPeriodicity = true;
2516 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2517 hasVerticesPeriodicity = true;
2521 while (isOK && hasCustomOptions) {
2522 isOK = static_cast<bool>(load >> optName);
2524 if (optName == "__CUSTOM_OPTIONS_END__")
2526 isOK = static_cast<bool>(load >> optValue);
2529 std::string& value = optValue;
2530 int len = value.size();
2531 // continue reading until "%#" encountered
2532 while (value[len - 1] != '#' || value[len - 2] != '%') {
2533 isOK = static_cast<bool>(load >> optValue);
2542 if ( value[ len - 1] == '#' )
2543 value.resize(len - 2); //cut off "%#"
2544 _customOption2value[optName] = value;
2548 if (hasCustomOptions) {
2549 isOK = static_cast<bool>(load >> option_or_sm);
2551 if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2552 hasPreCADOptions = true;
2553 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2555 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2556 hasAttractor = true;
2557 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2558 hasNewAttractor = true;
2559 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2560 hasEnforcedVertex = true;
2561 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2562 hasPreCADFacesPeriodicity = true;
2563 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2564 hasPreCADEdgesPeriodicity = true;
2565 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2566 hasFacesPeriodicity = true;
2567 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2568 hasEdgesPeriodicity = true;
2569 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2570 hasVerticesPeriodicity = true;
2574 while (isOK && hasPreCADOptions) {
2575 isOK = static_cast<bool>(load >> optName);
2577 if (optName == "__PRECAD_OPTIONS_END__")
2579 isOK = static_cast<bool>(load >> optValue);
2582 std::string & value = _preCADoption2value[optName];
2584 int len = value.size();
2585 // continue reading until "%#" encountered
2586 while (value[len - 1] != '#' || value[len - 2] != '%') {
2587 isOK = static_cast<bool>(load >> optValue);
2596 if ( value[ len - 1] == '#' )
2597 value.resize(len - 2); //cut off "%#"
2601 if (hasPreCADOptions) {
2602 isOK = static_cast<bool>(load >> option_or_sm);
2604 if (option_or_sm == "__SIZEMAP_BEGIN__")
2606 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2607 hasAttractor = true;
2608 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2609 hasNewAttractor = true;
2610 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2611 hasEnforcedVertex = true;
2612 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2613 hasPreCADFacesPeriodicity = true;
2614 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2615 hasPreCADEdgesPeriodicity = true;
2616 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2617 hasFacesPeriodicity = true;
2618 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2619 hasEdgesPeriodicity = true;
2620 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2621 hasVerticesPeriodicity = true;
2625 std::string smEntry, smValue;
2626 while (isOK && hasSizeMap) {
2627 isOK = static_cast<bool>(load >> smEntry);
2629 if (smEntry == "__SIZEMAP_END__")
2631 isOK = static_cast<bool>(load >> smValue);
2634 std::string & value2 = _sizeMap[smEntry];
2636 int len2 = value2.size();
2637 // continue reading until "%#" encountered
2638 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2639 isOK = static_cast<bool>(load >> smValue);
2643 len2 = value2.size();
2648 value2.resize(len2 - 2); //cut off "%#"
2653 isOK = static_cast<bool>(load >> option_or_sm);
2655 if (option_or_sm == "__ATTRACTORS_BEGIN__")
2656 hasAttractor = true;
2657 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2658 hasNewAttractor = true;
2659 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2660 hasEnforcedVertex = true;
2661 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2662 hasPreCADFacesPeriodicity = true;
2663 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2664 hasPreCADEdgesPeriodicity = true;
2665 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2666 hasFacesPeriodicity = true;
2667 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2668 hasEdgesPeriodicity = true;
2669 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2670 hasVerticesPeriodicity = true;
2673 std::string atEntry, atValue;
2674 while (isOK && hasAttractor) {
2675 isOK = static_cast<bool>(load >> atEntry);
2677 if (atEntry == "__ATTRACTORS_END__")
2679 isOK = static_cast<bool>(load >> atValue);
2682 std::string & value3 = _attractors[atEntry];
2684 int len3 = value3.size();
2685 // continue reading until "%#" encountered
2686 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
2687 isOK = static_cast<bool>(load >> atValue);
2691 len3 = value3.size();
2696 value3.resize(len3 - 2); //cut off "%#"
2701 isOK = static_cast<bool>(load >> option_or_sm);
2703 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2704 hasNewAttractor = true;
2705 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2706 hasEnforcedVertex = true;
2707 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2708 hasPreCADFacesPeriodicity = true;
2709 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2710 hasPreCADEdgesPeriodicity = true;
2711 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2712 hasFacesPeriodicity = true;
2713 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2714 hasEdgesPeriodicity = true;
2715 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2716 hasVerticesPeriodicity = true;
2720 std::string newAtFaceEntry, atTestString;
2721 std::string newAtShapeEntry;
2722 double attParams[4];
2724 while (isOK && hasNewAttractor) {
2725 //std::cout<<"Load new attractor"<<std::endl;
2726 isOK = static_cast<bool>(load >> newAtFaceEntry);
2728 if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
2730 isOK = static_cast<bool>(load >> newAtShapeEntry);
2733 isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
2736 MESSAGE(" LOADING ATTRACTOR HYPOTHESIS ")
2737 const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
2738 const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
2739 BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
2740 attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
2741 //attractor->BuildMap();
2742 _classAttractors.insert( make_pair( newAtFaceEntry, attractor ));
2747 if (hasNewAttractor) {
2748 isOK = static_cast<bool>(load >> option_or_sm);
2750 if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2751 hasEnforcedVertex = true;
2752 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2753 hasPreCADFacesPeriodicity = true;
2754 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2755 hasPreCADEdgesPeriodicity = true;
2756 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2757 hasFacesPeriodicity = true;
2758 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2759 hasEdgesPeriodicity = true;
2760 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2761 hasVerticesPeriodicity = true;
2767 // Here is a example of the saved stream:
2768 // __ENFORCED_VERTICES_BEGIN__
2769 // __BEGIN_VERTEX__ => no name, no entry
2770 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2771 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__
2772 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__
2774 // __BEGIN_VERTEX__ => no coords
2775 // __BEGIN_NAME__ mes points __END_NAME__
2776 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
2777 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2778 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
2780 // __ENFORCED_VERTICES_END__
2783 std::string enfSeparator;
2784 std::string enfName;
2785 std::string enfGeomEntry;
2786 std::string enfGroup;
2787 TEntryList enfFaceEntryList;
2788 double enfCoords[3];
2789 bool hasCoords = false;
2791 _faceEntryEnfVertexListMap.clear();
2792 _enfVertexList.clear();
2793 _faceEntryCoordsListMap.clear();
2794 _coordsEnfVertexMap.clear();
2795 _faceEntryEnfVertexEntryListMap.clear();
2796 _enfVertexEntryEnfVertexMap.clear();
2799 while (isOK && hasEnforcedVertex) {
2800 isOK = static_cast<bool>(load >> enfSeparator); // __BEGIN_VERTEX__
2801 TEnfVertex *enfVertex = new TEnfVertex();
2802 // MESSAGE("enfSeparator: " <<enfSeparator);
2803 if (enfSeparator == "__ENFORCED_VERTICES_END__")
2804 break; // __ENFORCED_VERTICES_END__
2805 if (enfSeparator != "__BEGIN_VERTEX__")
2806 throw std::exception();
2809 isOK = static_cast<bool>(load >> enfSeparator);
2810 MESSAGE("enfSeparator: " <<enfSeparator);
2811 if (enfSeparator == "__END_VERTEX__") {
2813 enfVertex->name = enfName;
2814 enfVertex->geomEntry = enfGeomEntry;
2815 enfVertex->grpName = enfGroup;
2816 enfVertex->coords.clear();
2818 enfVertex->coords.assign(enfCoords,enfCoords+3);
2819 enfVertex->faceEntries = enfFaceEntryList;
2821 _enfVertexList.insert(enfVertex);
2823 if (enfVertex->coords.size()) {
2824 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
2825 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2826 _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
2827 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2830 if (!enfVertex->geomEntry.empty()) {
2831 _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
2832 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2833 _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
2834 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2839 enfGeomEntry.clear();
2841 enfFaceEntryList.clear();
2843 break; // __END_VERTEX__
2846 if (enfSeparator == "__BEGIN_NAME__") { // __BEGIN_NAME__
2847 while (isOK && (enfSeparator != "__END_NAME__")) {
2848 isOK = static_cast<bool>(load >> enfSeparator);
2849 if (enfSeparator != "__END_NAME__") {
2850 if (!enfName.empty())
2852 enfName += enfSeparator;
2855 MESSAGE("enfName: " <<enfName);
2858 if (enfSeparator == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
2859 isOK = static_cast<bool>(load >> enfGeomEntry);
2860 isOK = static_cast<bool>(load >> enfSeparator); // __END_ENTRY__
2861 if (enfSeparator != "__END_ENTRY__")
2862 throw std::exception();
2863 MESSAGE("enfGeomEntry: " <<enfGeomEntry);
2866 if (enfSeparator == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
2867 while (isOK && (enfSeparator != "__END_GROUP__")) {
2868 isOK = static_cast<bool>(load >> enfSeparator);
2869 if (enfSeparator != "__END_GROUP__") {
2870 if (!enfGroup.empty())
2872 enfGroup += enfSeparator;
2875 MESSAGE("enfGroup: " <<enfGroup);
2878 if (enfSeparator == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
2880 isOK = static_cast<bool>(load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
2881 isOK = static_cast<bool>(load >> enfSeparator); // __END_COORDS__
2882 if (enfSeparator != "__END_COORDS__")
2883 throw std::exception();
2884 MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
2887 if (enfSeparator == "__BEGIN_FACELIST__") { // __BEGIN_FACELIST__
2888 while (isOK && (enfSeparator != "__END_FACELIST__")) {
2889 isOK = static_cast<bool>(load >> enfSeparator);
2890 if (enfSeparator != "__END_FACELIST__") {
2891 enfFaceEntryList.insert(enfSeparator);
2892 MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
2901 if (hasPreCADFacesPeriodicity){
2902 LoadPreCADPeriodicity(load, "FACES");
2904 isOK = static_cast<bool>(load >> option_or_sm);
2906 if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2907 hasPreCADEdgesPeriodicity = true;
2908 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2909 hasFacesPeriodicity = true;
2910 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2911 hasEdgesPeriodicity = true;
2912 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2913 hasVerticesPeriodicity = true;
2917 if (hasPreCADEdgesPeriodicity){
2918 LoadPreCADPeriodicity(load, "EDGES");
2920 isOK = static_cast<bool>(load >> option_or_sm);
2922 if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2923 hasFacesPeriodicity = true;
2924 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2925 hasEdgesPeriodicity = true;
2926 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2927 hasVerticesPeriodicity = true;
2931 if (hasFacesPeriodicity){
2932 LoadFacesPeriodicity(load);
2934 isOK = static_cast<bool>(load >> option_or_sm);
2936 if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2937 hasEdgesPeriodicity = true;
2938 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2939 hasVerticesPeriodicity = true;
2943 if (hasEdgesPeriodicity){
2944 LoadEdgesPeriodicity(load);
2946 isOK = static_cast<bool>(load >> option_or_sm);
2948 if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2949 hasVerticesPeriodicity = true;
2952 if (hasVerticesPeriodicity)
2953 LoadVerticesPeriodicity(load);
2958 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
2962 std::string periodicitySeparator;
2966 _facesPeriodicityVector.clear();
2969 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2970 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2971 TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
2972 if (periodicitySeparator == "__FACES_PERIODICITY_END__")
2973 break; // __FACES_PERIODICITY_END__
2974 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2975 MESSAGE("//" << periodicitySeparator << "//");
2976 throw std::exception();
2980 isOK = static_cast<bool>(load >> periodicitySeparator);
2981 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2982 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2984 periodicity_i->first = shape1Entry;
2985 periodicity_i->second = shape2Entry;
2987 _facesPeriodicityVector.push_back(*periodicity_i);
2989 break; // __END_PERIODICITY_DESCRIPTION__
2992 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
2993 isOK = static_cast<bool>(load >> shape1Entry);
2994 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
2995 if (periodicitySeparator != "__END_ENTRY1__")
2996 throw std::exception();
2997 MESSAGE("shape1Entry: " <<shape1Entry);
3000 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3001 isOK = static_cast<bool>(load >> shape2Entry);
3002 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3003 if (periodicitySeparator != "__END_ENTRY2__")
3004 throw std::exception();
3005 MESSAGE("shape2Entry: " <<shape2Entry);
3012 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
3016 std::string periodicitySeparator;
3017 TEntry theFace1Entry;
3018 TEntry theEdge1Entry;
3019 TEntry theFace2Entry;
3020 TEntry theEdge2Entry;
3021 int edge_orientation = 0;
3023 _edgesPeriodicityVector.clear();
3026 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3027 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3028 TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
3029 if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
3030 break; // __EDGES_PERIODICITY_END__
3031 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3032 MESSAGE("//" << periodicitySeparator << "//");
3033 throw std::exception();
3037 isOK = static_cast<bool>(load >> periodicitySeparator);
3038 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3039 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3041 periodicity_i->theFace1Entry = theFace1Entry;
3042 periodicity_i->theEdge1Entry = theEdge1Entry;
3043 periodicity_i->theFace2Entry = theFace2Entry;
3044 periodicity_i->theEdge2Entry = theEdge2Entry;
3045 periodicity_i->edge_orientation = edge_orientation;
3047 _edgesPeriodicityVector.push_back(*periodicity_i);
3049 break; // __END_PERIODICITY_DESCRIPTION__
3052 if (periodicitySeparator == "__BEGIN_FACE1__") { // __BEGIN_FACE1__
3053 isOK = static_cast<bool>(load >> theFace1Entry);
3054 MESSAGE("//" << theFace1Entry << "//");
3055 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE1__
3056 if (periodicitySeparator != "__END_FACE1__"){
3057 MESSAGE("//" << periodicitySeparator << "//");
3058 throw std::exception();
3060 MESSAGE("theFace1Entry: " <<theFace1Entry);
3063 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3064 isOK = static_cast<bool>(load >> theEdge1Entry);
3065 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3066 if (periodicitySeparator != "__END_EDGE1__")
3067 throw std::exception();
3068 MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3071 if (periodicitySeparator == "__BEGIN_FACE2__") { // __BEGIN_FACE2__
3072 isOK = static_cast<bool>(load >> theFace2Entry);
3073 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE2__
3074 if (periodicitySeparator != "__END_FACE2__")
3075 throw std::exception();
3076 MESSAGE("theFace2Entry: " <<theFace2Entry);
3079 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3080 isOK = static_cast<bool>(load >> theEdge2Entry);
3081 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3082 if (periodicitySeparator != "__END_EDGE2__")
3083 throw std::exception();
3084 MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3087 if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") { // __BEGIN_EDGE_ORIENTATION__
3088 isOK = static_cast<bool>(load >> edge_orientation);
3089 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
3090 if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
3091 throw std::exception();
3092 MESSAGE("edge_orientation: " <<edge_orientation);
3098 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
3102 std::string periodicitySeparator;
3103 TEntry theEdge1Entry;
3104 TEntry theVertex1Entry;
3105 TEntry theEdge2Entry;
3106 TEntry theVertex2Entry;
3108 _verticesPeriodicityVector.clear();
3111 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3112 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3113 TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
3114 if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
3115 break; // __VERTICES_PERIODICITY_END__
3116 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3117 MESSAGE("//" << periodicitySeparator << "//");
3118 throw std::exception();
3122 isOK = static_cast<bool>(load >> periodicitySeparator);
3123 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3124 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3126 periodicity_i->theEdge1Entry = theEdge1Entry;
3127 periodicity_i->theVertex1Entry = theVertex1Entry;
3128 periodicity_i->theEdge2Entry = theEdge2Entry;
3129 periodicity_i->theVertex2Entry = theVertex2Entry;
3131 _verticesPeriodicityVector.push_back(*periodicity_i);
3133 break; // __END_PERIODICITY_DESCRIPTION__
3136 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3137 isOK = static_cast<bool>(load >> theEdge1Entry);
3138 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3139 if (periodicitySeparator != "__END_EDGE1__")
3140 throw std::exception();
3141 MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3144 if (periodicitySeparator == "__BEGIN_VERTEX1__") { // __BEGIN_VERTEX1__
3145 isOK = static_cast<bool>(load >> theVertex1Entry);
3146 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX1__
3147 if (periodicitySeparator != "__END_VERTEX1__")
3148 throw std::exception();
3149 MESSAGE("theVertex1Entry: " <<theVertex1Entry);
3152 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3153 isOK = static_cast<bool>(load >> theEdge2Entry);
3154 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3155 if (periodicitySeparator != "__END_EDGE2__")
3156 throw std::exception();
3157 MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3160 if (periodicitySeparator == "__BEGIN_VERTEX2__") { // __BEGIN_VERTEX2__
3161 isOK = static_cast<bool>(load >> theVertex2Entry);
3162 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX2__
3163 if (periodicitySeparator != "__END_VERTEX2__")
3164 throw std::exception();
3165 MESSAGE("theVertex2Entry: " <<theVertex2Entry);
3171 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
3175 std::string periodicitySeparator;
3178 std::vector<std::string> theSourceVerticesEntries;
3179 std::vector<std::string> theTargetVerticesEntries;
3181 bool hasSourceVertices = false;
3182 bool hasTargetVertices = false;
3184 if ( shapeType && strcmp( shapeType, "FACES") == 0 )
3185 _preCadFacesPeriodicityVector.clear();
3187 _preCadEdgesPeriodicityVector.clear();
3191 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3192 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3193 TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
3194 // MESSAGE("periodicitySeparator: " <<periodicitySeparator);
3195 std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
3196 if (periodicitySeparator == endSeparator)
3197 break; // __PRECAD_FACES_PERIODICITY_END__
3198 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3199 MESSAGE("//" << endSeparator << "//");
3200 MESSAGE("//" << periodicitySeparator << "//");
3201 throw std::exception();
3205 isOK = static_cast<bool>(load >> periodicitySeparator);
3206 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3207 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3209 periodicity_i->shape1Entry = shape1Entry;
3210 periodicity_i->shape2Entry = shape2Entry;
3212 MESSAGE("theSourceVerticesEntries.size(): " << theSourceVerticesEntries.size());
3213 MESSAGE("theTargetVerticesEntries.size(): " << theTargetVerticesEntries.size());
3215 if (hasSourceVertices)
3216 periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
3217 if (hasTargetVertices)
3218 periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
3220 if ( shapeType && strcmp( shapeType, "FACES" ))
3221 _preCadFacesPeriodicityVector.push_back(*periodicity_i);
3223 _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
3225 theSourceVerticesEntries.clear();
3226 theTargetVerticesEntries.clear();
3227 hasSourceVertices = false;
3228 hasTargetVertices = false;
3229 break; // __END_PERIODICITY_DESCRIPTION__
3232 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3233 isOK = static_cast<bool>(load >> shape1Entry);
3234 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3235 if (periodicitySeparator != "__END_ENTRY1__")
3236 throw std::exception();
3237 MESSAGE("shape1Entry: " <<shape1Entry);
3240 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3241 isOK = static_cast<bool>(load >> shape2Entry);
3242 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3243 if (periodicitySeparator != "__END_ENTRY2__")
3244 throw std::exception();
3245 MESSAGE("shape2Entry: " <<shape2Entry);
3248 if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") { // __BEGIN_SOURCE_VERTICES_LIST__
3249 hasSourceVertices = true;
3250 while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
3251 isOK = static_cast<bool>(load >> periodicitySeparator);
3252 if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
3253 theSourceVerticesEntries.push_back(periodicitySeparator);
3254 MESSAGE("theSourceVerticesEntries: " <<periodicitySeparator);
3259 if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") { // __BEGIN_TARGET_VERTICES_LIST__
3260 hasTargetVertices = true;
3261 while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
3262 isOK = static_cast<bool>(load >> periodicitySeparator);
3263 if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
3264 theTargetVerticesEntries.push_back(periodicitySeparator);
3265 MESSAGE("theTargetVerticesEntries: " <<periodicitySeparator);
3273 //=============================================================================
3274 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
3275 return hyp.SaveTo(save);
3278 //=============================================================================
3279 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
3280 return hyp.LoadFrom(load);
3283 //================================================================================
3285 * \brief Does nothing
3287 //================================================================================
3289 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
3293 //================================================================================
3295 * \brief Returns default global constant physical size given a default value of element length ratio
3297 //================================================================================
3299 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
3300 if (bbSegmentation != 0 && diagonal != 0)
3301 return diagonal / bbSegmentation ;
3305 //================================================================================
3307 * \brief Returns default min size given a default value of element length ratio
3309 //================================================================================
3311 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
3313 return diagonal / 1000.0 ;
3314 return undefinedDouble();
3317 //================================================================================
3319 * \brief Returns default max size given a default value of element length ratio
3321 //================================================================================
3323 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
3325 return diagonal / 5.0 ;
3326 return undefinedDouble();
3329 //================================================================================
3331 * \brief Returns default chordal error given a default value of element length ratio
3333 //================================================================================
3335 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
3338 return undefinedDouble();
3341 //================================================================================
3343 * \brief Returns default tiny edge length given a default value of element length ratio
3345 //================================================================================
3347 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
3349 return diagonal * 1e-6 ;
3350 return undefinedDouble();
3353 //================================================================================
3355 * \brief Returns default tiny edge optimisation length given a default value of element length ratio
3357 //================================================================================
3359 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal) {
3361 return diagonal * 1e-6 ;
3362 return undefinedDouble();
3365 //=============================================================================
3367 * \brief Initialize my parameter values by default parameters.
3368 * \retval bool - true if parameter values have been successfully defined
3370 //=============================================================================
3372 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
3373 double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
3374 _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
3375 _minSize = GetDefaultMinSize(diagonal);
3376 _maxSize = GetDefaultMaxSize(diagonal);
3377 _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
3378 _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
3379 _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(diagonal);
3384 //================================================================================
3386 * \brief Converts a string to a bool
3388 //================================================================================
3390 bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
3391 throw (std::invalid_argument)
3393 std::string s = str;
3394 if ( isOk ) *isOk = true;
3396 for ( size_t i = 0; i <= s.size(); ++i )
3397 s[i] = tolower( s[i] );
3399 if ( s == "1" || s == "true" || s == "active" || s == "yes" )
3402 if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
3408 std::string msg = "Not a Boolean value:'" + str + "'";
3409 throw std::invalid_argument(msg);
3414 //================================================================================
3416 * \brief Converts a string to a real value
3418 //================================================================================
3420 double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
3421 throw (std::invalid_argument)
3423 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3426 double val = strtod(&str[0], &endPtr);
3427 bool ok = (&str[0] != endPtr);
3429 if ( isOk ) *isOk = ok;
3433 std::string msg = "Not a real value:'" + str + "'";
3434 throw std::invalid_argument(msg);
3439 //================================================================================
3441 * \brief Converts a string to a integer value
3443 //================================================================================
3445 int BLSURFPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
3446 throw (std::invalid_argument)
3448 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3451 int val = (int)strtol( &str[0], &endPtr, 10);
3452 bool ok = (&str[0] != endPtr);
3454 if ( isOk ) *isOk = ok;
3458 std::string msg = "Not an integer value:'" + str + "'";
3459 throw std::invalid_argument(msg);