1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : BLSURFPlugin_Hypothesis.cxx
22 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
23 // & Aurelien ALLEAUME (DISTENE)
24 // Size maps development: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
27 #include "BLSURFPlugin_Hypothesis.hxx"
28 #include "BLSURFPlugin_Attractor.hxx"
29 #include "SMESH_Gen_i.hxx"
30 #include <utilities.h>
36 #include "ShapeAnalysis.hxx"
39 #include CORBA_CLIENT_HEADER(SALOMEDS)
40 #include CORBA_CLIENT_HEADER(GEOM_Gen)
44 struct GET_DEFAULT // struct used to get default value from GetOptionValue()
47 operator bool* () { return &isDefault; }
51 //=============================================================================
52 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen) :
53 SMESH_Hypothesis(hypId, studyId, gen),
54 _physicalMesh(GetDefaultPhysicalMesh()),
55 _geometricMesh(GetDefaultGeometricMesh()),
56 _phySize(GetDefaultPhySize()),
57 _phySizeRel(GetDefaultPhySizeRel()),
58 _minSize(GetDefaultMinSize()),
59 _maxSize(GetDefaultMaxSize()),
60 _minSizeRel(GetDefaultMinSizeRel()),
61 _maxSizeRel(GetDefaultMaxSizeRel()),
62 _useGradation(GetDefaultUseGradation()),
63 _gradation(GetDefaultGradation()),
64 _useVolumeGradation(GetDefaultUseVolumeGradation()),
65 _volumeGradation(GetDefaultVolumeGradation()),
66 _quadAllowed(GetDefaultQuadAllowed()),
67 _angleMesh(GetDefaultAngleMesh()),
68 _chordalError(GetDefaultChordalError()),
69 _anisotropic(GetDefaultAnisotropic()),
70 _anisotropicRatio(GetDefaultAnisotropicRatio()),
71 _removeTinyEdges(GetDefaultRemoveTinyEdges()),
72 _tinyEdgeLength(GetDefaultTinyEdgeLength()),
73 _optimiseTinyEdges(GetDefaultOptimiseTinyEdges()),
74 _tinyEdgeOptimisationLength(GetDefaultTinyEdgeOptimisationLength()),
75 _correctSurfaceIntersec(GetDefaultCorrectSurfaceIntersection()),
76 _corrSurfaceIntersCost(GetDefaultCorrectSurfaceIntersectionMaxCost()),
77 _badElementRemoval(GetDefaultBadElementRemoval()),
78 _badElementAspectRatio(GetDefaultBadElementAspectRatio()),
79 _optimizeMesh(GetDefaultOptimizeMesh()),
80 _quadraticMesh(GetDefaultQuadraticMesh()),
81 _verb(GetDefaultVerbosity()),
82 _topology(GetDefaultTopology()),
83 _preCADMergeEdges(GetDefaultPreCADMergeEdges()),
84 _preCADRemoveTinyUVEdges(GetDefaultPreCADRemoveTinyUVEdges()),
85 _preCADRemoveDuplicateCADFaces(GetDefaultPreCADRemoveDuplicateCADFaces()),
86 _preCADProcess3DTopology(GetDefaultPreCADProcess3DTopology()),
87 _preCADDiscardInput(GetDefaultPreCADDiscardInput()),
88 _sizeMap(GetDefaultSizeMap()),
89 _attractors(GetDefaultSizeMap()),
90 _classAttractors(GetDefaultAttractorMap()),
91 _faceEntryEnfVertexListMap(GetDefaultFaceEntryEnfVertexListMap()),
92 _enfVertexList(GetDefaultEnfVertexList()),
93 _faceEntryCoordsListMap(GetDefaultFaceEntryCoordsListMap()),
94 _coordsEnfVertexMap(GetDefaultCoordsEnfVertexMap()),
95 _faceEntryEnfVertexEntryListMap(GetDefaultFaceEntryEnfVertexEntryListMap()),
96 _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
97 _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap()),
98 _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex()),
99 _preCadFacesPeriodicityVector(GetDefaultPreCadFacesPeriodicityVector()),
100 _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector()),
101 _GMFFileName(GetDefaultGMFFile())
103 _name = GetHypType();
106 // _GMFFileMode = false; // GMF ascii mode
108 // Advanced options with their defaults according to MG User Manual
110 const char* boolOptionNames[] = { "enforce_cad_edge_sizes", // default = 0
111 // "correct_surface_intersections", // default = 1
112 // "create_tag_on_collision", // default = 1
113 "jacobian_rectification_respect_geometry", // default = 1
114 "rectify_jacobian", // default = 1
115 "respect_geometry", // default = 1
116 // "optimise_tiny_edges", // default = 0
117 // "remove_duplicate_cad_faces", // default = 1
118 "tiny_edge_avoid_surface_intersections", // default = 1
119 // "tiny_edge_respect_geometry", // default = 0
123 const char* intOptionNames[] = { "max_number_of_points_per_patch", // default = 100000
126 const char* doubleOptionNames[] = { // "surface_intersections_processing_max_cost",// default = 15
127 // "periodic_tolerance", // default = diag/100
128 // "volume_gradation",
129 // "tiny_edge_optimisation_length", // default = diag * 1e-6
132 const char* charOptionNames[] = { // "required_entities", // default = "respect"
133 // "tags", // default = "respect"
137 // PreCAD advanced options
138 const char* preCADboolOptionNames[] = { "closed_geometry", // default = 0
139 "discard_input_topology", // default = 0
140 "merge_edges", // default = = 1
141 "remove_duplicate_cad_faces", // default = 1
142 // "create_tag_on_collision", // default = 1
143 "debug", // default = 0
144 // "remove_tiny_edges", // default = 0
147 const char* preCADintOptionNames[] = { // "manifold_geometry", // default = 0
150 const char* preCADdoubleOptionNames[] = { "periodic_tolerance", // default = diag * 1e-5
151 "sewing_tolerance", // default = diag * 5e-4
152 // "tiny_edge_length", // default = diag * 1e-5
155 const char* preCADcharOptionNames[] = { "required_entities", // default = "respect"
156 "tags", // default = "respect"
161 while (boolOptionNames[i][0])
163 _boolOptions.insert( boolOptionNames[i] );
164 _option2value[boolOptionNames[i++]].clear();
167 while (preCADboolOptionNames[i][0])
169 _boolOptions.insert( preCADboolOptionNames[i] );
170 _preCADoption2value[preCADboolOptionNames[i++]].clear();
173 while (intOptionNames[i][0])
174 _option2value[intOptionNames[i++]].clear();
177 while (preCADintOptionNames[i][0])
178 _preCADoption2value[preCADintOptionNames[i++]].clear();
181 while (doubleOptionNames[i][0]) {
182 _doubleOptions.insert(doubleOptionNames[i]);
183 _option2value[doubleOptionNames[i++]].clear();
186 while (preCADdoubleOptionNames[i][0]) {
187 _preCADdoubleOptions.insert(preCADdoubleOptionNames[i]);
188 _preCADoption2value[preCADdoubleOptionNames[i++]].clear();
191 while (charOptionNames[i][0]) {
192 _charOptions.insert(charOptionNames[i]);
193 _option2value[charOptionNames[i++]].clear();
196 while (preCADcharOptionNames[i][0]) {
197 _preCADcharOptions.insert(preCADcharOptionNames[i]);
198 _preCADoption2value[preCADcharOptionNames[i++]].clear();
201 // default values to be used while MG meshing
203 _defaultOptionValues["enforce_cad_edge_sizes" ] = "no";
204 _defaultOptionValues["jacobian_rectification_respect_geometry"] = "yes";
205 _defaultOptionValues["max_number_of_points_per_patch" ] = "0";
206 _defaultOptionValues["rectify_jacobian" ] = "yes";
207 _defaultOptionValues["respect_geometry" ] = "yes";
208 _defaultOptionValues["tiny_edge_avoid_surface_intersections" ] = "yes";
209 _defaultOptionValues["closed_geometry" ] = "no";
210 _defaultOptionValues["debug" ] = "no";
211 _defaultOptionValues["discard_input_topology" ] = "no";
212 _defaultOptionValues["merge_edges" ] = "no";
213 _defaultOptionValues["periodic_tolerance" ] = "1e-5*D";
214 _defaultOptionValues["remove_duplicate_cad_faces" ] = "no";
215 _defaultOptionValues["required_entities" ] = "respect";
216 _defaultOptionValues["sewing_tolerance" ] = "5e-4*D";
217 _defaultOptionValues["tags" ] = "respect";
220 // check validity of option names of _defaultOptionValues
221 TOptionValues::iterator n2v = _defaultOptionValues.begin();
222 for ( ; n2v != _defaultOptionValues.end(); ++n2v )
223 ASSERT( _option2value.count( n2v->first ) || _preCADoption2value.count( n2v->first ));
224 ASSERT( _option2value.size() + _preCADoption2value.size() == _defaultOptionValues.size() );
229 _faceEntryEnfVertexListMap.clear();
230 _enfVertexList.clear();
231 _faceEntryCoordsListMap.clear();
232 _coordsEnfVertexMap.clear();
233 _faceEntryEnfVertexEntryListMap.clear();
234 _enfVertexEntryEnfVertexMap.clear();
235 _groupNameNodeIDMap.clear();
238 _groupNameEnfVertexListMap.clear();
239 _enfVertexGroupNameMap.clear();
243 TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry)
245 MESSAGE("BLSURFPlugin_Hypothesis::entryToShape "<<entry );
246 GEOM::GEOM_Object_var aGeomObj;
247 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
248 SALOMEDS::Study_ptr myStudy = smeshGen_i->GetCurrentStudy();
250 TopoDS_Shape S = TopoDS_Shape();
251 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
252 if (!aSObj->_is_nil() ) {
253 CORBA::Object_var obj = aSObj->GetObject();
254 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
257 if ( !aGeomObj->_is_nil() )
258 S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
262 //=============================================================================
263 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
264 if (thePhysicalMesh != _physicalMesh) {
265 _physicalMesh = thePhysicalMesh;
266 NotifySubMeshesHypothesisModification();
270 //=============================================================================
271 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
272 if (theGeometricMesh != _geometricMesh) {
273 _geometricMesh = theGeometricMesh;
274 // switch (_geometricMesh) {
277 // _angleMesh = GetDefaultAngleMesh();
278 // _gradation = GetDefaultGradation();
281 NotifySubMeshesHypothesisModification();
285 //=============================================================================
286 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal, bool isRelative) {
287 if ((theVal != _phySize) || (isRelative != _phySizeRel)) {
288 _phySizeRel = isRelative;
290 _phySize = GetMaxSize();
291 MESSAGE("Warning: nul physical size is not allowed");
295 NotifySubMeshesHypothesisModification();
299 //=============================================================================
300 void BLSURFPlugin_Hypothesis::SetMinSize(double theMinSize, bool isRelative) {
301 if ((theMinSize != _minSize) || (isRelative != _minSizeRel)) {
302 _minSizeRel = isRelative;
303 _minSize = theMinSize;
304 NotifySubMeshesHypothesisModification();
308 //=============================================================================
309 void BLSURFPlugin_Hypothesis::SetMaxSize(double theMaxSize, bool isRelative) {
310 if ((theMaxSize != _maxSize) || (isRelative != _maxSizeRel)) {
311 _maxSizeRel = isRelative;
312 _maxSize = theMaxSize;
313 NotifySubMeshesHypothesisModification();
317 //=============================================================================
318 void BLSURFPlugin_Hypothesis::SetUseGradation(bool theVal) {
319 if (theVal != _useGradation) {
320 _useGradation = theVal;
321 NotifySubMeshesHypothesisModification();
325 //=============================================================================
326 void BLSURFPlugin_Hypothesis::SetGradation(double theVal) {
327 if (theVal != _gradation) {
329 NotifySubMeshesHypothesisModification();
333 //=============================================================================
334 void BLSURFPlugin_Hypothesis::SetUseVolumeGradation(bool theVal) {
335 if (theVal != _useVolumeGradation) {
336 _useVolumeGradation = theVal;
337 NotifySubMeshesHypothesisModification();
341 //=============================================================================
342 void BLSURFPlugin_Hypothesis::SetVolumeGradation(double theVal) {
343 if (theVal != _volumeGradation) {
344 _volumeGradation = theVal;
345 NotifySubMeshesHypothesisModification();
349 //=============================================================================
350 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal) {
351 if (theVal != _quadAllowed) {
352 _quadAllowed = theVal;
353 NotifySubMeshesHypothesisModification();
357 //=============================================================================
358 void BLSURFPlugin_Hypothesis::SetAngleMesh(double theVal) {
359 if (theVal != _angleMesh) {
361 NotifySubMeshesHypothesisModification();
365 //=============================================================================
366 void BLSURFPlugin_Hypothesis::SetChordalError(double theDistance) {
367 if (theDistance != _chordalError) {
368 _chordalError = theDistance;
369 NotifySubMeshesHypothesisModification();
373 //=============================================================================
374 void BLSURFPlugin_Hypothesis::SetAnisotropic(bool theVal) {
375 if (theVal != _anisotropic) {
376 _anisotropic = theVal;
377 NotifySubMeshesHypothesisModification();
381 //=============================================================================
382 void BLSURFPlugin_Hypothesis::SetAnisotropicRatio(double theVal) {
383 if (theVal != _anisotropicRatio) {
384 _anisotropicRatio = theVal;
385 NotifySubMeshesHypothesisModification();
389 //=============================================================================
390 void BLSURFPlugin_Hypothesis::SetRemoveTinyEdges(bool theVal) {
391 if (theVal != _removeTinyEdges) {
392 _removeTinyEdges = theVal;
393 NotifySubMeshesHypothesisModification();
397 //=============================================================================
398 void BLSURFPlugin_Hypothesis::SetTinyEdgeLength(double theVal) {
399 if (theVal != _tinyEdgeLength) {
400 _tinyEdgeLength = theVal;
401 NotifySubMeshesHypothesisModification();
405 //=============================================================================
406 void BLSURFPlugin_Hypothesis::SetOptimiseTinyEdges(bool theVal) {
407 if (theVal != _optimiseTinyEdges) {
408 _optimiseTinyEdges = theVal;
409 NotifySubMeshesHypothesisModification();
413 //=============================================================================
414 void BLSURFPlugin_Hypothesis::SetTinyEdgeOptimisationLength(double theVal) {
415 if (theVal != _tinyEdgeOptimisationLength) {
416 _tinyEdgeOptimisationLength = theVal;
417 NotifySubMeshesHypothesisModification();
421 //=============================================================================
422 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersection(bool theVal) {
423 if (theVal != _correctSurfaceIntersec) {
424 _correctSurfaceIntersec = theVal;
425 NotifySubMeshesHypothesisModification();
429 //=============================================================================
430 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersectionMaxCost(double theVal) {
431 if (theVal != _corrSurfaceIntersCost) {
432 _corrSurfaceIntersCost = theVal;
433 NotifySubMeshesHypothesisModification();
437 //=============================================================================
438 void BLSURFPlugin_Hypothesis::SetBadElementRemoval(bool theVal) {
439 if (theVal != _badElementRemoval) {
440 _badElementRemoval = theVal;
441 NotifySubMeshesHypothesisModification();
445 //=============================================================================
446 void BLSURFPlugin_Hypothesis::SetBadElementAspectRatio(double theVal) {
447 if (theVal != _badElementAspectRatio) {
448 _badElementAspectRatio = theVal;
449 NotifySubMeshesHypothesisModification();
453 //=============================================================================
454 void BLSURFPlugin_Hypothesis::SetOptimizeMesh(bool theVal) {
455 if (theVal != _optimizeMesh) {
456 _optimizeMesh = theVal;
457 NotifySubMeshesHypothesisModification();
461 //=============================================================================
462 void BLSURFPlugin_Hypothesis::SetQuadraticMesh(bool theVal) {
463 if (theVal != _quadraticMesh) {
464 _quadraticMesh = theVal;
465 NotifySubMeshesHypothesisModification();
469 //=============================================================================
470 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology) {
471 if (theTopology != _topology) {
472 _topology = theTopology;
473 NotifySubMeshesHypothesisModification();
477 //=============================================================================
478 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
479 if (theVal != _verb) {
481 NotifySubMeshesHypothesisModification();
485 //=============================================================================
486 void BLSURFPlugin_Hypothesis::SetEnforceCadEdgesSize( bool toEnforce )
488 if ( GetEnforceCadEdgesSize() != toEnforce )
490 SetOptionValue( "enforce_cad_edge_sizes", toEnforce ? "yes" : "no" );
491 NotifySubMeshesHypothesisModification();
494 //=============================================================================
495 bool BLSURFPlugin_Hypothesis::GetEnforceCadEdgesSize()
497 return ToBool( GetOptionValue( "enforce_cad_edge_sizes" ), GET_DEFAULT() );
499 //=============================================================================
501 void BLSURFPlugin_Hypothesis::SetJacobianRectificationRespectGeometry( bool allowRectification )
503 if ( GetJacobianRectificationRespectGeometry() != allowRectification )
505 SetOptionValue("jacobian_rectification_respect_geometry", allowRectification ? "yes" : "no" );
506 NotifySubMeshesHypothesisModification();
509 //=============================================================================
510 bool BLSURFPlugin_Hypothesis::GetJacobianRectificationRespectGeometry()
512 return ToBool( GetOptionValue("jacobian_rectification_respect_geometry", GET_DEFAULT()));
514 //=============================================================================
516 void BLSURFPlugin_Hypothesis::SetJacobianRectification( bool allowRectification )
518 if ( GetJacobianRectification() != allowRectification )
520 SetOptionValue( "rectify_jacobian", allowRectification ? "yes" : "no" );
521 NotifySubMeshesHypothesisModification();
524 //=============================================================================
525 bool BLSURFPlugin_Hypothesis::GetJacobianRectification()
527 return ToBool( GetOptionValue("rectify_jacobian", GET_DEFAULT()));
529 //=============================================================================
531 void BLSURFPlugin_Hypothesis::SetMaxNumberOfPointsPerPatch( CORBA::Long nb )
532 throw (std::invalid_argument)
535 throw std::invalid_argument( SMESH_Comment("Invalid number of points: ") << nb );
537 if ( GetMaxNumberOfPointsPerPatch() != nb )
539 SetOptionValue("max_number_of_points_per_patch", SMESH_Comment( nb ));
540 NotifySubMeshesHypothesisModification();
543 //=============================================================================
544 int BLSURFPlugin_Hypothesis::GetMaxNumberOfPointsPerPatch()
546 return ToInt( GetOptionValue("max_number_of_points_per_patch", GET_DEFAULT()));
548 //=============================================================================
550 void BLSURFPlugin_Hypothesis::SetRespectGeometry( bool toRespect )
552 if ( GetRespectGeometry() != toRespect )
554 SetOptionValue("respect_geometry", toRespect ? "yes" : "no" );
555 NotifySubMeshesHypothesisModification();
558 //=============================================================================
559 bool BLSURFPlugin_Hypothesis::GetRespectGeometry()
561 return ToBool( GetOptionValue( "respect_geometry", GET_DEFAULT()));
563 //=============================================================================
565 void BLSURFPlugin_Hypothesis::SetTinyEdgesAvoidSurfaceIntersections( bool toAvoidIntersection )
567 if ( GetTinyEdgesAvoidSurfaceIntersections() != toAvoidIntersection )
569 SetOptionValue("tiny_edge_avoid_surface_intersections", toAvoidIntersection ? "yes" : "no" );
570 NotifySubMeshesHypothesisModification();
573 //=============================================================================
574 bool BLSURFPlugin_Hypothesis::GetTinyEdgesAvoidSurfaceIntersections()
576 return ToBool( GetOptionValue("tiny_edge_avoid_surface_intersections", GET_DEFAULT()));
578 //=============================================================================
580 void BLSURFPlugin_Hypothesis::SetClosedGeometry( bool isClosed )
582 if ( GetClosedGeometry() != isClosed )
584 SetPreCADOptionValue("closed_geometry", isClosed ? "yes" : "no" );
585 NotifySubMeshesHypothesisModification();
588 //=============================================================================
589 bool BLSURFPlugin_Hypothesis::GetClosedGeometry()
591 return ToBool( GetPreCADOptionValue( "closed_geometry", GET_DEFAULT()));
593 //=============================================================================
595 void BLSURFPlugin_Hypothesis::SetDebug( bool isDebug )
597 if ( GetDebug() != isDebug )
599 SetPreCADOptionValue("debug", isDebug ? "yes" : "no" );
600 NotifySubMeshesHypothesisModification();
603 //=============================================================================
604 bool BLSURFPlugin_Hypothesis::GetDebug()
606 return ToBool( GetPreCADOptionValue("debug", GET_DEFAULT()));
608 //=============================================================================
610 void BLSURFPlugin_Hypothesis::SetPeriodicTolerance( CORBA::Double tol )
611 throw (std::invalid_argument)
614 throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
615 if ( GetPeriodicTolerance() != tol )
617 SetPreCADOptionValue("periodic_tolerance", SMESH_Comment( tol ) );
618 NotifySubMeshesHypothesisModification();
621 //=============================================================================
622 double BLSURFPlugin_Hypothesis::GetPeriodicTolerance()
624 return ToDbl( GetPreCADOptionValue( "periodic_tolerance", GET_DEFAULT()));
626 //=============================================================================
628 void BLSURFPlugin_Hypothesis::SetRequiredEntities( const std::string& howToTreat )
629 throw (std::invalid_argument)
631 if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear" )
632 throw std::invalid_argument
633 ( SMESH_Comment("required_entities must be in ['respect','ignore','clear'] "));
635 if ( GetRequiredEntities() != howToTreat )
637 SetPreCADOptionValue("required_entities", howToTreat );
638 NotifySubMeshesHypothesisModification();
641 //=============================================================================
642 std::string BLSURFPlugin_Hypothesis::GetRequiredEntities()
644 return GetPreCADOptionValue("required_entities", GET_DEFAULT());
646 //=============================================================================
648 void BLSURFPlugin_Hypothesis::SetSewingTolerance( CORBA::Double tol )
649 throw (std::invalid_argument)
652 throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
653 if ( GetSewingTolerance() != tol )
655 SetPreCADOptionValue("sewing_tolerance", SMESH_Comment( tol ) );
656 NotifySubMeshesHypothesisModification();
659 //=============================================================================
660 CORBA::Double BLSURFPlugin_Hypothesis::GetSewingTolerance()
662 return ToDbl( GetPreCADOptionValue("sewing_tolerance", GET_DEFAULT()));
664 //=============================================================================
666 void BLSURFPlugin_Hypothesis::SetTags( const std::string& howToTreat )
667 throw (std::invalid_argument)
669 if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear" )
670 throw std::invalid_argument
671 ( SMESH_Comment("'tags' must be in ['respect','ignore','clear'] "));
673 if ( GetTags() != howToTreat )
675 SetPreCADOptionValue("tags", howToTreat );
676 NotifySubMeshesHypothesisModification();
679 //=============================================================================
680 std::string BLSURFPlugin_Hypothesis::GetTags()
682 return GetPreCADOptionValue("tags", GET_DEFAULT());
684 //=============================================================================
685 void BLSURFPlugin_Hypothesis::SetPreCADMergeEdges(bool theVal)
687 if (theVal != _preCADMergeEdges) {
688 // SetTopology(PreCAD);
689 _preCADMergeEdges = theVal;
690 SetPreCADOptionValue("merge_edges", theVal ? "yes" : "no" );
691 NotifySubMeshesHypothesisModification();
695 //=============================================================================
696 void BLSURFPlugin_Hypothesis::SetPreCADRemoveTinyUVEdges(bool theVal)
698 if (theVal != _preCADRemoveTinyUVEdges) {
699 // SetTopology(PreCAD);
700 _preCADRemoveTinyUVEdges = theVal;
701 NotifySubMeshesHypothesisModification();
705 //=============================================================================
706 void BLSURFPlugin_Hypothesis::SetPreCADRemoveDuplicateCADFaces(bool theVal)
708 if (theVal != _preCADRemoveDuplicateCADFaces) {
709 // SetTopology(PreCAD);
710 _preCADRemoveDuplicateCADFaces = theVal;
711 SetPreCADOptionValue("remove_duplicate_cad_faces", theVal ? "yes" : "no" );
712 NotifySubMeshesHypothesisModification();
716 //=============================================================================
717 void BLSURFPlugin_Hypothesis::SetPreCADProcess3DTopology(bool theVal)
719 if (theVal != _preCADProcess3DTopology) {
720 // SetTopology(PreCAD);
721 _preCADProcess3DTopology = theVal;
722 NotifySubMeshesHypothesisModification();
726 //=============================================================================
727 void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal)
729 if (theVal != _preCADDiscardInput) {
730 // SetTopology(PreCAD);
731 _preCADDiscardInput = theVal;
732 SetPreCADOptionValue("discard_input_topology", theVal ? "yes" : "no" );
733 NotifySubMeshesHypothesisModification();
737 //=============================================================================
738 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
739 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
741 _GMFFileName = theFileName;
742 // _GMFFileMode = isBinary;
743 NotifySubMeshesHypothesisModification();
746 //=============================================================================
747 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
748 throw (std::invalid_argument) {
750 TOptionValues::iterator op_val = _option2value.find(optionName);
751 if (op_val == _option2value.end())
753 op_val = _preCADoption2value.find(optionName);
754 if (op_val == _preCADoption2value.end())
756 std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'. Try SetAdvancedOption()";
757 throw std::invalid_argument(msg);
760 if (op_val->second != optionValue)
762 const char* ptr = optionValue.c_str();
763 // strip white spaces
764 while (ptr[0] == ' ')
767 while (i != 0 && ptr[i - 1] == ' ')
771 std::string typeName;
774 } else if (_charOptions.count(optionName)) {
775 // do not check strings
776 } else if (_doubleOptions.count(optionName)) {
777 // check if value is double
780 } else if (_boolOptions.count(optionName)) {
781 // check if value is bool
782 ToBool(ptr, &typeOk);
785 // check if value is int
787 typeName = "integer";
790 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
791 throw std::invalid_argument(msg);
793 std::string value( ptr, i );
794 if ( _defaultOptionValues[ optionName ] == value )
797 op_val->second = value;
799 NotifySubMeshesHypothesisModification();
803 //=============================================================================
804 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
805 throw (std::invalid_argument) {
807 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
808 if (op_val == _preCADoption2value.end()) {
809 op_val = _option2value.find(optionName);
810 if (op_val == _option2value.end()) {
811 std::string msg = "Unknown MG-PreCAD option: '" + optionName + "'. Try SetAdvancedOption()";
812 throw std::invalid_argument(msg);
815 if (op_val->second != optionValue)
817 const char* ptr = optionValue.c_str();
818 // strip white spaces
819 while (ptr[0] == ' ')
822 while (i != 0 && ptr[i - 1] == ' ')
826 std::string typeName;
829 } else if (_preCADcharOptions.find(optionName) != _preCADcharOptions.end()) {
830 // do not check strings
831 } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
832 // check if value is double
834 strtod(ptr, &endPtr);
835 typeOk = (ptr != endPtr);
837 } else if (_boolOptions.count(optionName)) {
838 // check if value is bool
839 ToBool(ptr, &typeOk);
842 // check if value is int
844 strtol(ptr, &endPtr, 10);
845 typeOk = (ptr != endPtr);
846 typeName = "integer";
849 std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
850 throw std::invalid_argument(msg);
852 std::string value( ptr, i );
853 if ( _defaultOptionValues[ optionName ] == value )
856 op_val->second = value;
858 NotifySubMeshesHypothesisModification();
862 //=============================================================================
863 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
864 bool* isDefault) const
865 throw (std::invalid_argument)
867 TOptionValues::const_iterator op_val = _option2value.find(optionName);
868 if (op_val == _option2value.end())
870 op_val = _preCADoption2value.find(optionName);
871 if (op_val == _preCADoption2value.end())
873 op_val = _customOption2value.find(optionName);
874 if (op_val == _customOption2value.end())
876 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
877 throw std::invalid_argument(msg);
881 std::string val = op_val->second;
882 if ( isDefault ) *isDefault = ( val.empty() );
884 if ( val.empty() && isDefault )
886 op_val = _defaultOptionValues.find( optionName );
887 if (op_val != _defaultOptionValues.end())
888 val = op_val->second;
893 //=============================================================================
894 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName,
895 bool* isDefault) const
896 throw (std::invalid_argument)
898 TOptionValues::const_iterator op_val = _preCADoption2value.find(optionName);
899 if (op_val == _preCADoption2value.end())
901 op_val = _option2value.find(optionName);
902 if (op_val == _option2value.end())
904 op_val = _customOption2value.find(optionName);
905 if (op_val == _customOption2value.end())
907 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
908 throw std::invalid_argument(msg);
912 std::string val = op_val->second;
913 if ( isDefault ) *isDefault = ( val.empty() );
915 if ( val.empty() && isDefault )
917 op_val = _defaultOptionValues.find( optionName );
918 if (op_val != _option2value.end())
919 val = op_val->second;
924 //=============================================================================
925 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
927 TOptionValues::iterator op_val = _customOption2value.find(optionName);
928 if (op_val != _customOption2value.end())
929 _customOption2value.erase(op_val);
931 op_val = _option2value.find(optionName);
932 if (op_val != _option2value.end())
933 op_val->second.clear();
935 op_val = _preCADoption2value.find(optionName);
936 if (op_val != _preCADoption2value.end())
937 op_val->second.clear();
942 //=============================================================================
943 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName)
945 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
946 if (op_val != _preCADoption2value.end())
947 op_val->second.clear();
950 //=============================================================================
951 void BLSURFPlugin_Hypothesis::AddOption(const std::string& optionName, const std::string& optionValue)
954 TOptionValues::iterator op_val = _option2value.find(optionName);
955 if (op_val != _option2value.end())
957 if (op_val->second != optionValue)
958 op_val->second = optionValue;
964 op_val = _preCADoption2value.find(optionName);
965 if (op_val != _preCADoption2value.end())
967 if (op_val->second != optionValue)
968 op_val->second = optionValue;
972 else if ( optionValue.empty() )
974 _customOption2value.erase( optionName );
978 op_val = _customOption2value.find(optionName);
979 if (op_val == _customOption2value.end())
980 _customOption2value[optionName] = optionValue;
981 else if (op_val->second != optionValue)
982 op_val->second = optionValue;
988 NotifySubMeshesHypothesisModification();
991 //=============================================================================
992 void BLSURFPlugin_Hypothesis::AddPreCADOption(const std::string& optionName, const std::string& optionValue)
994 AddOption( optionName, optionValue );
997 //=============================================================================
998 std::string BLSURFPlugin_Hypothesis::GetOption(const std::string& optionName)
1000 TOptionValues::iterator op_val = _customOption2value.find(optionName);
1001 if (op_val != _customOption2value.end())
1002 return op_val->second;
1007 //=============================================================================
1008 std::string BLSURFPlugin_Hypothesis::GetPreCADOption(const std::string& optionName)
1010 TOptionValues::iterator op_val = _customOption2value.find(optionName);
1011 if (op_val != _customOption2value.end())
1012 return op_val->second;
1017 //=============================================================================
1018 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetOptionValues() const
1021 TOptionValues::const_iterator op_val = _option2value.begin();
1022 for ( ; op_val != _option2value.end(); ++op_val )
1023 vals.insert( make_pair( op_val->first, GetOptionValue( op_val->first, GET_DEFAULT() )));
1028 //=============================================================================
1029 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetPreCADOptionValues() const
1032 TOptionValues::const_iterator op_val = _preCADoption2value.begin();
1033 for ( ; op_val != _preCADoption2value.end(); ++op_val )
1034 vals.insert( make_pair( op_val->first, GetPreCADOptionValue( op_val->first, GET_DEFAULT() )));
1039 //=======================================================================
1040 //function : SetSizeMapEntry
1041 //=======================================================================
1042 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
1043 if (_sizeMap[entry].compare(sizeMap) != 0) {
1044 SetPhysicalMesh(PhysicalLocalSize);
1045 _sizeMap[entry] = sizeMap;
1046 NotifySubMeshesHypothesisModification();
1050 //=======================================================================
1051 //function : GetSizeMapEntry
1052 //=======================================================================
1053 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
1054 TSizeMap::iterator it = _sizeMap.find(entry);
1055 if (it != _sizeMap.end())
1058 return "No_Such_Entry";
1062 * \brief Return the size maps
1064 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
1065 return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
1068 //=======================================================================
1069 //function : SetAttractorEntry
1070 //=======================================================================
1071 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
1072 if (_attractors[entry].compare(attractor) != 0) {
1073 SetPhysicalMesh(PhysicalLocalSize);
1074 _attractors[entry] = attractor;
1075 NotifySubMeshesHypothesisModification();
1079 //=======================================================================
1080 //function : GetAttractorEntry
1081 //=======================================================================
1082 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
1083 TSizeMap::iterator it = _attractors.find(entry);
1084 if (it != _attractors.end())
1087 return "No_Such_Entry";
1091 * \brief Return the attractors
1093 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
1094 return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
1097 //=======================================================================
1098 //function : SetClassAttractorEntry
1099 //=======================================================================
1100 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
1102 SetPhysicalMesh(PhysicalLocalSize);
1104 // The new attractor can't be defined on the same face as another sizemap
1105 TSizeMap::iterator it = _sizeMap.find( entry );
1106 if ( it != _sizeMap.end() ) {
1108 NotifySubMeshesHypothesisModification();
1111 TSizeMap::iterator itAt = _attractors.find( entry );
1112 if ( itAt != _attractors.end() ) {
1113 _attractors.erase(itAt);
1114 NotifySubMeshesHypothesisModification();
1118 const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
1119 const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
1120 TAttractorMap::iterator attIt = _classAttractors.find(entry);
1121 for ( ; attIt != _classAttractors.end(); ++attIt )
1122 if ( attIt->first == entry &&
1123 attIt->second->GetAttractorEntry() == attEntry )
1125 bool attExists = (attIt != _classAttractors.end());
1127 BLSURFPlugin_Attractor* myAttractor;
1129 myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 );
1130 _classAttractors.insert( make_pair( entry, myAttractor ));
1133 myAttractor = attIt->second;
1135 // if (!myAttractor->IsMapBuilt())
1136 // myAttractor->BuildMap();
1137 myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
1139 NotifySubMeshesHypothesisModification();
1142 //=======================================================================
1143 //function : SetConstantSizeOnAdjacentFaces
1144 //=======================================================================
1145 // TODO uncomment and test (include the needed .hxx)
1146 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist ) {
1147 // TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
1148 // TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
1149 // TopTools_IndexedMapOfShapListOdShape::iterator it;
1150 // for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
1151 // SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
1159 //=======================================================================
1160 //function : GetClassAttractorEntry
1161 //=======================================================================
1162 // BLSURFPlugin_Attractor& BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
1164 // TAttractorMap::iterator it = _classAttractors.find( entry );
1165 // if ( it != _classAttractors.end() )
1166 // return it->second;
1168 // return "No_Such_Entry";
1172 * \brief Return the map of attractor instances
1174 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
1176 return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
1179 //=======================================================================
1180 //function : ClearEntry
1181 //=======================================================================
1182 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
1183 const char * attEntry/*=0*/)
1185 TSizeMap::iterator it = _sizeMap.find( entry );
1187 if ( it != _sizeMap.end() ) {
1189 NotifySubMeshesHypothesisModification();
1192 TSizeMap::iterator itAt = _attractors.find( entry );
1193 if ( itAt != _attractors.end() ) {
1194 _attractors.erase(itAt);
1195 NotifySubMeshesHypothesisModification();
1198 TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
1199 if ( it_clAt != _classAttractors.end() ) {
1201 if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
1202 _classAttractors.erase( it_clAt++ );
1206 while ( it_clAt != _classAttractors.end() );
1207 MESSAGE("_classAttractors.size() = "<<_classAttractors.size())
1208 NotifySubMeshesHypothesisModification();
1211 std::cout<<"No_Such_Entry"<<std::endl;
1216 //=======================================================================
1217 //function : ClearSizeMaps
1218 //=======================================================================
1219 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
1221 _attractors.clear();
1222 _classAttractors.clear();
1225 // Enable internal enforced vertices on specific face if requested by user
1227 ////=======================================================================
1228 ////function : SetInternalEnforcedVertex
1229 ////=======================================================================
1230 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
1231 // bool toEnforceInternalVertices,
1232 // TEnfGroupName theGroupName) {
1234 // MESSAGE("BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex("<< theFaceEntry << ", "
1235 // << toEnforceInternalVertices << ", " << theGroupName << ")");
1237 // TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
1238 // if (it != _faceEntryInternalVerticesList.end()) {
1239 // if (!toEnforceInternalVertices) {
1240 // _faceEntryInternalVerticesList.erase(it);
1244 // if (toEnforceInternalVertices) {
1245 // _faceEntryInternalVerticesList.insert(theFaceEntry);
1250 // // Take care of groups
1254 //=======================================================================
1255 //function : SetEnforcedVertex
1256 //=======================================================================
1257 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
1258 TEnfGroupName theGroupName, double x, double y, double z) {
1260 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
1261 << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
1263 SetPhysicalMesh(PhysicalLocalSize);
1265 // TEnfVertexList::iterator it;
1266 bool toNotify = false;
1267 bool toCreate = true;
1269 TEnfVertex *oldEnVertex;
1270 TEnfVertex *newEnfVertex = new TEnfVertex();
1271 newEnfVertex->name = theVertexName;
1272 newEnfVertex->geomEntry = theVertexEntry;
1273 newEnfVertex->coords.clear();
1274 if (theVertexEntry == "") {
1275 newEnfVertex->coords.push_back(x);
1276 newEnfVertex->coords.push_back(y);
1277 newEnfVertex->coords.push_back(z);
1279 newEnfVertex->grpName = theGroupName;
1280 newEnfVertex->faceEntries.clear();
1281 newEnfVertex->faceEntries.insert(theFaceEntry);
1284 // update _enfVertexList
1285 TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
1286 if (it != _enfVertexList.end()) {
1288 oldEnVertex = (*it);
1289 MESSAGE("Enforced Vertex was found => Update");
1290 if (oldEnVertex->name != theVertexName) {
1291 MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
1292 oldEnVertex->name = theVertexName;
1295 if (oldEnVertex->grpName != theGroupName) {
1296 MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
1297 oldEnVertex->grpName = theGroupName;
1300 TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
1301 if (it_faceEntries == oldEnVertex->faceEntries.end()) {
1302 MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
1303 oldEnVertex->faceEntries.insert(theFaceEntry);
1304 _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
1308 // update map coords / enf vertex if needed
1309 if (oldEnVertex->coords.size()) {
1310 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
1311 _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
1314 // update map geom entry / enf vertex if needed
1315 if (oldEnVertex->geomEntry != "") {
1316 _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
1317 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
1322 // //////// CREATE ////////////
1325 MESSAGE("Creating new enforced vertex");
1326 _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
1327 _enfVertexList.insert(newEnfVertex);
1328 if (theVertexEntry == "") {
1329 _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
1330 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
1333 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
1334 _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
1339 NotifySubMeshesHypothesisModification();
1341 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
1346 //=======================================================================
1347 //function : GetEnforcedVertices
1348 //=======================================================================
1350 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
1351 throw (std::invalid_argument) {
1353 if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
1354 return _faceEntryEnfVertexListMap[theFaceEntry];
1356 return GetDefaultEnfVertexList();
1358 std::ostringstream msg;
1359 msg << "No enforced vertex for face entry " << theFaceEntry;
1360 throw std::invalid_argument(msg.str());
1363 //=======================================================================
1364 //function : GetEnfVertexCoordsList
1365 //=======================================================================
1367 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
1368 const TEntry& theFaceEntry) throw (std::invalid_argument) {
1370 if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
1371 return _faceEntryCoordsListMap[theFaceEntry];
1373 std::ostringstream msg;
1374 msg << "No enforced vertex coords for face entry " << theFaceEntry;
1375 throw std::invalid_argument(msg.str());
1378 //=======================================================================
1379 //function : GetEnfVertexEntryList
1380 //=======================================================================
1382 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
1383 throw (std::invalid_argument) {
1385 if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
1386 return _faceEntryEnfVertexEntryListMap[theFaceEntry];
1388 std::ostringstream msg;
1389 msg << "No enforced vertex entry for face entry " << theFaceEntry;
1390 throw std::invalid_argument(msg.str());
1393 //=======================================================================
1394 //function : GetEnfVertex(TEnfVertexCoords coords)
1395 //=======================================================================
1397 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
1398 throw (std::invalid_argument) {
1400 if (_coordsEnfVertexMap.count(coords) > 0)
1401 return _coordsEnfVertexMap[coords];
1403 std::ostringstream msg;
1404 msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
1405 throw std::invalid_argument(msg.str());
1408 //=======================================================================
1409 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
1410 //=======================================================================
1412 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
1413 throw (std::invalid_argument) {
1415 if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
1416 return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
1418 std::ostringstream msg;
1419 msg << "No enforced vertex with entry " << theEnfVertexEntry;
1420 throw std::invalid_argument(msg.str());
1423 //Enable internal enforced vertices on specific face if requested by user
1424 ////=======================================================================
1425 ////function : GetInternalEnforcedVertex
1426 ////=======================================================================
1428 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
1430 // if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
1435 //=======================================================================
1436 //function : ClearEnforcedVertex
1437 //=======================================================================
1439 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
1440 const TEntry& theVertexEntry) throw (std::invalid_argument) {
1442 bool toNotify = false;
1443 std::ostringstream msg;
1444 TEnfVertex *oldEnfVertex;
1445 TEnfVertexCoords coords;
1447 coords.push_back(x);
1448 coords.push_back(y);
1449 coords.push_back(z);
1451 // check that enf vertex with given enf vertex entry exists
1452 TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
1453 if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
1455 MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
1456 oldEnfVertex = it_enfVertexEntry->second;
1458 _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
1460 TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
1461 enfVertexEntryList.erase(theVertexEntry);
1462 if (enfVertexEntryList.size() == 0)
1463 _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
1464 // TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1465 // TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
1466 // it_entry_entry->second.erase(it_entryList);
1467 // if (it_entry_entry->second.size() == 0)
1468 // _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1471 MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
1472 msg << "No enforced vertex with geom entry " << theVertexEntry;
1473 // check that enf vertex with given coords exists
1474 TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
1475 if (it_coords_enf != _coordsEnfVertexMap.end()) {
1477 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
1478 oldEnfVertex = it_coords_enf->second;
1480 _coordsEnfVertexMap.erase(it_coords_enf);
1482 TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
1483 enfVertexCoordsList.erase(coords);
1484 if (enfVertexCoordsList.size() == 0)
1485 _faceEntryCoordsListMap.erase(theFaceEntry);
1486 // TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1487 // TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
1488 // it_entry_coords->second.erase(it_coordsList);
1489 // if (it_entry_coords->second.size() == 0)
1490 // _faceEntryCoordsListMap.erase(it_entry_coords);
1493 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
1495 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
1496 throw std::invalid_argument(msg.str());
1500 MESSAGE("Remove enf vertex from _enfVertexList");
1502 // update _enfVertexList
1503 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1504 if (it != _enfVertexList.end()) {
1505 (*it)->faceEntries.erase(theFaceEntry);
1506 if ((*it)->faceEntries.size() == 0){
1507 _enfVertexList.erase(it);
1513 // update _faceEntryEnfVertexListMap
1514 TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
1515 currentEnfVertexList.erase(oldEnfVertex);
1517 if (currentEnfVertexList.size() == 0) {
1518 MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
1519 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1524 NotifySubMeshesHypothesisModification();
1529 //=======================================================================
1530 //function : ClearEnforcedVertices
1531 //=======================================================================
1533 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
1535 bool toNotify = false;
1536 TEnfVertex *oldEnfVertex;
1538 TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1539 if (it_entry_coords != _faceEntryCoordsListMap.end()) {
1541 TEnfVertexCoordsList coordsList = it_entry_coords->second;
1542 TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
1543 for (; it_coordsList != coordsList.end(); ++it_coordsList) {
1544 TEnfVertexCoords coords = (*it_coordsList);
1545 oldEnfVertex = _coordsEnfVertexMap[coords];
1546 _coordsEnfVertexMap.erase(coords);
1547 // update _enfVertexList
1548 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1549 if (it != _enfVertexList.end()) {
1550 (*it)->faceEntries.erase(theFaceEntry);
1551 if ((*it)->faceEntries.size() == 0){
1552 _enfVertexList.erase(it);
1558 _faceEntryCoordsListMap.erase(it_entry_coords);
1559 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1562 TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1563 if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
1565 TEntryList enfVertexEntryList = it_entry_entry->second;
1566 TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
1567 for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
1568 TEntry enfVertexEntry = (*it_enfVertexEntryList);
1569 oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
1570 _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
1571 // update _enfVertexList
1572 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1573 if (it != _enfVertexList.end()) {
1574 (*it)->faceEntries.erase(theFaceEntry);
1575 if ((*it)->faceEntries.size() == 0){
1576 _enfVertexList.erase(it);
1582 _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1583 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1587 NotifySubMeshesHypothesisModification();
1590 // std::ostringstream msg;
1591 // msg << "No enforced vertex for " << theFaceEntry;
1592 // throw std::invalid_argument(msg.str());
1595 //=======================================================================
1596 //function : ClearAllEnforcedVertices
1597 //=======================================================================
1598 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
1599 _faceEntryEnfVertexListMap.clear();
1600 _enfVertexList.clear();
1601 _faceEntryCoordsListMap.clear();
1602 _coordsEnfVertexMap.clear();
1603 _faceEntryEnfVertexEntryListMap.clear();
1604 _enfVertexEntryEnfVertexMap.clear();
1605 // Enable internal enforced vertices on specific face if requested by user
1606 // _faceEntryInternalVerticesList.clear();
1607 NotifySubMeshesHypothesisModification();
1610 //================================================================================
1612 * \brief Return the enforced vertices
1614 //================================================================================
1617 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1618 const BLSURFPlugin_Hypothesis* hyp) {
1619 return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1622 //Enable internal enforced vertices on specific face if requested by user
1623 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1624 // const BLSURFPlugin_Hypothesis* hyp) {
1625 // return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1628 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1630 return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1633 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1635 return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1638 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1639 const BLSURFPlugin_Hypothesis* hyp) {
1640 return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1643 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1644 const BLSURFPlugin_Hypothesis* hyp) {
1645 return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1648 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1649 const BLSURFPlugin_Hypothesis* hyp) {
1650 return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1653 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1654 const BLSURFPlugin_Hypothesis* hyp) {
1655 return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1658 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1659 const BLSURFPlugin_Hypothesis* hyp) {
1660 return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1663 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1665 TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1666 if (it != _groupNameNodeIDMap.end()) {
1669 std::ostringstream msg;
1670 msg << "No group " << theGroupName;
1671 throw std::invalid_argument(msg.str());
1674 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1676 _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1679 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1681 TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1682 if (it != _groupNameNodeIDMap.end()) {
1683 std::set<int>::iterator IDit = it->second.find(theNodeID);
1684 if (IDit != it->second.end())
1685 it->second.erase(IDit);
1686 std::ostringstream msg;
1687 msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1688 throw std::invalid_argument(msg.str());
1690 std::ostringstream msg;
1691 msg << "No group " << theGroupName;
1692 throw std::invalid_argument(msg.str());
1696 //=============================================================================
1697 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1698 if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1699 _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1700 if (toEnforceInternalVertices)
1701 SetPhysicalMesh(PhysicalLocalSize);
1702 NotifySubMeshesHypothesisModification();
1707 //=============================================================================
1708 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1709 if (std::string(theGroupName) != std::string(_enforcedInternalVerticesAllFacesGroup)) {
1710 _enforcedInternalVerticesAllFacesGroup = theGroupName;
1711 NotifySubMeshesHypothesisModification();
1715 //=============================================================================
1716 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
1717 const BLSURFPlugin_Hypothesis* hyp) {
1718 return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
1721 //=============================================================================
1722 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
1723 const BLSURFPlugin_Hypothesis* hyp) {
1724 return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
1727 //=============================================================================
1728 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
1729 const BLSURFPlugin_Hypothesis* hyp) {
1730 return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
1733 //=============================================================================
1734 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
1735 const BLSURFPlugin_Hypothesis* hyp){
1736 return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
1739 //=============================================================================
1740 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
1741 const BLSURFPlugin_Hypothesis* hyp){
1742 return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
1745 //=======================================================================
1746 //function : ClearAllEnforcedVertices
1747 //=======================================================================
1748 void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
1749 _preCadFacesPeriodicityVector.clear();
1750 _preCadEdgesPeriodicityVector.clear();
1751 NotifySubMeshesHypothesisModification();
1754 //=======================================================================
1755 //function : AddPreCadFacesPeriodicity
1756 //=======================================================================
1757 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
1758 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1760 TPreCadPeriodicity preCadFacesPeriodicity;
1761 preCadFacesPeriodicity.shape1Entry = theFace1Entry;
1762 preCadFacesPeriodicity.shape2Entry = theFace2Entry;
1763 preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1764 preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1766 _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
1768 NotifySubMeshesHypothesisModification();
1771 //=======================================================================
1772 //function : AddPreCadEdgesPeriodicity
1773 //=======================================================================
1774 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
1775 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1777 TPreCadPeriodicity preCadEdgesPeriodicity;
1778 preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
1779 preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
1780 preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1781 preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1783 _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
1785 NotifySubMeshesHypothesisModification();
1788 //=============================================================================
1789 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
1790 // We must keep at least the same number of arguments when increasing the SALOME version
1791 // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
1792 // parameter can be written several times to keep the old global number of parameters.
1794 // Treat old options which are now in the advanced options
1795 TOptionValues::iterator op_val;
1797 int _preCADRemoveNanoEdges = -1;
1798 double _preCADEpsNano = -1.0;
1799 op_val = _option2value.find("respect_geometry");
1800 if (op_val != _option2value.end()) {
1801 std::string value = op_val->second;
1803 _decimesh = value.compare("1") == 0 ? 1 : 0;
1805 op_val = _preCADoption2value.find("remove_tiny_edges");
1806 if (op_val != _preCADoption2value.end()) {
1807 std::string value = op_val->second;
1809 _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
1811 op_val = _preCADoption2value.find("tiny_edge_length");
1812 if (op_val != _preCADoption2value.end()) {
1813 std::string value = op_val->second;
1815 _preCADEpsNano = strtod(value.c_str(), NULL);
1818 save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1819 << _angleMesh << " " << _gradation << " " << (int) _quadAllowed << " " << _decimesh;
1820 save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
1821 save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1822 save << " " << (int) _enforcedInternalVerticesAllFaces;
1823 save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
1824 save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
1825 save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
1826 save << " " << (int) _preCADProcess3DTopology << " " << (int) _preCADRemoveDuplicateCADFaces << " " << (int) _preCADRemoveTinyUVEdges;
1827 save << " " << (int)_optimiseTinyEdges << " " << _tinyEdgeOptimisationLength;
1828 save << " " << (int)_correctSurfaceIntersec << " " << _corrSurfaceIntersCost;
1829 save << " " << (int)_useGradation << " " << (int)_useVolumeGradation << " " << _volumeGradation;
1831 op_val = _option2value.begin();
1832 if (op_val != _option2value.end()) {
1833 save << " " << "__OPTIONS_BEGIN__";
1834 for (; op_val != _option2value.end(); ++op_val) {
1835 if (!op_val->second.empty())
1836 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1838 save << " " << "__OPTIONS_END__";
1841 op_val = _customOption2value.begin();
1842 if (op_val != _customOption2value.end()) {
1843 save << " " << "__CUSTOM_OPTIONS_BEGIN__";
1844 for (; op_val != _customOption2value.end(); ++op_val) {
1845 if (!op_val->second.empty())
1846 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1848 save << " " << "__CUSTOM_OPTIONS_END__";
1851 op_val = _preCADoption2value.begin();
1852 if (op_val != _preCADoption2value.end()) {
1853 save << " " << "__PRECAD_OPTIONS_BEGIN__";
1854 for (; op_val != _preCADoption2value.end(); ++op_val) {
1855 if (!op_val->second.empty())
1856 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1858 save << " " << "__PRECAD_OPTIONS_END__";
1861 TSizeMap::iterator it_sm = _sizeMap.begin();
1862 if (it_sm != _sizeMap.end()) {
1863 save << " " << "__SIZEMAP_BEGIN__";
1864 for (; it_sm != _sizeMap.end(); ++it_sm) {
1865 save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
1867 save << " " << "__SIZEMAP_END__";
1870 TSizeMap::iterator it_at = _attractors.begin();
1871 if (it_at != _attractors.end()) {
1872 save << " " << "__ATTRACTORS_BEGIN__";
1873 for (; it_at != _attractors.end(); ++it_at) {
1874 save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
1876 save << " " << "__ATTRACTORS_END__";
1879 TAttractorMap::iterator it_At = _classAttractors.begin();
1880 if (it_At != _classAttractors.end()) {
1881 std::ostringstream test;
1882 save << " " << "__NEW_ATTRACTORS_BEGIN__";
1883 test << " " << "__NEW_ATTRACTORS_BEGIN__";
1884 for (; it_At != _classAttractors.end(); ++it_At) {
1885 std::vector<double> attParams;
1886 attParams = it_At->second->GetParameters();
1887 // double step = it_At->second->GetStep();
1888 save << " " << it_At->first;
1889 save << " " << it_At->second->GetAttractorEntry();
1890 save << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1891 // save << " " << step;
1892 test << " " << it_At->first;
1893 test << " " << it_At->second->GetAttractorEntry();
1894 test << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1895 // test << " " << step;
1897 save << " " << "__NEW_ATTRACTORS_END__";
1898 test << " " << "__NEW_ATTRACTORS_END__";
1899 MESSAGE(" Attractor hypothesis saved as "<<test.str())
1902 TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
1903 if (it_enf != _enfVertexList.end()) {
1904 save << " " << "__ENFORCED_VERTICES_BEGIN__";
1905 for (; it_enf != _enfVertexList.end(); ++it_enf) {
1906 TEnfVertex *enfVertex = (*it_enf);
1907 save << " " << "__BEGIN_VERTEX__";
1908 if (!enfVertex->name.empty()) {
1909 save << " " << "__BEGIN_NAME__";
1910 save << " " << enfVertex->name;
1911 save << " " << "__END_NAME__";
1913 if (!enfVertex->geomEntry.empty()) {
1914 save << " " << "__BEGIN_ENTRY__";
1915 save << " " << enfVertex->geomEntry;
1916 save << " " << "__END_ENTRY__";
1918 if (!enfVertex->grpName.empty()) {
1919 save << " " << "__BEGIN_GROUP__";
1920 save << " " << enfVertex->grpName;
1921 save << " " << "__END_GROUP__";
1923 if (enfVertex->coords.size()) {
1924 save << " " << "__BEGIN_COORDS__";
1925 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1926 save << " " << enfVertex->coords[i];
1927 save << " " << "__END_COORDS__";
1929 TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
1930 bool hasFaces = false;
1931 if (faceEntriesIt != enfVertex->faceEntries.end()) {
1933 save << " " << "__BEGIN_FACELIST__";
1935 for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
1936 save << " " << (*faceEntriesIt);
1938 save << " " << "__END_FACELIST__";
1939 save << " " << "__END_VERTEX__";
1941 save << " " << "__ENFORCED_VERTICES_END__";
1946 SavePreCADPeriodicity(save, "FACES");
1947 SavePreCADPeriodicity(save, "EDGES");
1949 SaveFacesPeriodicity(save);
1950 SaveEdgesPeriodicity(save);
1951 SaveVerticesPeriodicity(save);
1956 void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
1958 TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
1959 if (it_faces_periodicity != _facesPeriodicityVector.end()) {
1960 MESSAGE("__FACES_PERIODICITY_BEGIN__");
1961 save << " " << "__FACES_PERIODICITY_BEGIN__";
1962 for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
1963 TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
1964 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1965 save << " " << "__BEGIN_ENTRY1__";
1966 save << " " << periodicity_i.first;
1967 save << " " << "__END_ENTRY1__";
1968 save << " " << "__BEGIN_ENTRY2__";
1969 save << " " << periodicity_i.second;
1970 save << " " << "__END_ENTRY2__";
1971 save << " " << "__END_PERIODICITY_DESCRIPTION__";
1973 save << " " << "__FACES_PERIODICITY_END__";
1974 MESSAGE("__FACES_PERIODICITY_END__");
1978 void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
1980 TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
1981 if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
1982 save << " " << "__EDGES_PERIODICITY_BEGIN__";
1983 MESSAGE("__EDGES_PERIODICITY_BEGIN__");
1984 for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
1985 TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
1986 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1987 if (! periodicity_i.theFace1Entry.empty()){
1988 save << " " << "__BEGIN_FACE1__";
1989 save << " " << periodicity_i.theFace1Entry;
1990 save << " " << "__END_FACE1__";
1992 save << " " << "__BEGIN_EDGE1__";
1993 save << " " << periodicity_i.theEdge1Entry;
1994 save << " " << "__END_EDGE1__";
1995 if (! periodicity_i.theFace2Entry.empty()){
1996 save << " " << "__BEGIN_FACE2__";
1997 save << " " << periodicity_i.theFace2Entry;
1998 save << " " << "__END_FACE2__";
2000 save << " " << "__BEGIN_EDGE2__";
2001 save << " " << periodicity_i.theEdge2Entry;
2002 save << " " << "__END_EDGE2__";
2003 save << " " << "__BEGIN_EDGE_ORIENTATION__";
2004 save << " " << periodicity_i.edge_orientation;
2005 save << " " << "__END_EDGE_ORIENTATION__";
2006 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2008 save << " " << "__EDGES_PERIODICITY_END__";
2009 MESSAGE("__EDGES_PERIODICITY_END__");
2013 void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save){
2015 TVerticesPeriodicityVector::const_iterator it_vertices_periodicity = _verticesPeriodicityVector.begin();
2016 if (it_vertices_periodicity != _verticesPeriodicityVector.end()) {
2017 MESSAGE("__VERTICES_PERIODICITY_BEGIN__");
2018 save << " " << "__VERTICES_PERIODICITY_BEGIN__";
2019 for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
2020 TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
2021 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2022 save << " " << "__BEGIN_EDGE1__";
2023 save << " " << periodicity_i.theEdge1Entry;
2024 save << " " << "__END_EDGE1__";
2025 save << " " << "__BEGIN_VERTEX1__";
2026 save << " " << periodicity_i.theVertex1Entry;
2027 save << " " << "__END_VERTEX1__";
2028 save << " " << "__BEGIN_EDGE2__";
2029 save << " " << periodicity_i.theEdge2Entry;
2030 save << " " << "__END_EDGE2__";
2031 save << " " << "__BEGIN_VERTEX2__";
2032 save << " " << periodicity_i.theVertex2Entry;
2033 save << " " << "__END_VERTEX2__";
2034 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2036 save << " " << "__VERTICES_PERIODICITY_END__";
2037 MESSAGE("__VERTICES_PERIODICITY_END__");
2041 void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType) {
2042 TPreCadPeriodicityVector precad_periodicity;
2043 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
2044 precad_periodicity = _preCadFacesPeriodicityVector;
2046 precad_periodicity = _preCadEdgesPeriodicityVector;
2047 TPreCadPeriodicityVector::const_iterator it_precad_periodicity = precad_periodicity.begin();
2048 if (it_precad_periodicity != precad_periodicity.end()) {
2049 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_BEGIN__";
2050 for (; it_precad_periodicity != precad_periodicity.end(); ++it_precad_periodicity) {
2051 TPreCadPeriodicity periodicity_i = (*it_precad_periodicity);
2052 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2053 if (!periodicity_i.shape1Entry.empty()) {
2054 save << " " << "__BEGIN_ENTRY1__";
2055 save << " " << periodicity_i.shape1Entry;
2056 save << " " << "__END_ENTRY1__";
2058 if (!periodicity_i.shape2Entry.empty()) {
2059 save << " " << "__BEGIN_ENTRY2__";
2060 save << " " << periodicity_i.shape2Entry;
2061 save << " " << "__END_ENTRY2__";
2064 std::vector<std::string>::const_iterator sourceVerticesEntriesIt = periodicity_i.theSourceVerticesEntries.begin();
2065 bool hasSourceVertices = false;
2066 if (sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end()) {
2067 hasSourceVertices = true;
2068 save << " " << "__BEGIN_SOURCE_VERTICES_LIST__";
2070 for (; sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end(); ++sourceVerticesEntriesIt)
2071 save << " " << (*sourceVerticesEntriesIt);
2072 if (hasSourceVertices)
2073 save << " " << "__END_SOURCE_VERTICES_LIST__";
2075 std::vector<std::string>::const_iterator targetVerticesEntriesIt = periodicity_i.theTargetVerticesEntries.begin();
2076 bool hasTargetVertices = false;
2077 if (targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end()) {
2078 hasTargetVertices = true;
2079 save << " " << "__BEGIN_TARGET_VERTICES_LIST__";
2081 for (; targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end(); ++targetVerticesEntriesIt)
2082 save << " " << (*targetVerticesEntriesIt);
2083 if (hasTargetVertices)
2084 save << " " << "__END_TARGET_VERTICES_LIST__";
2086 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2088 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_END__";
2093 //=============================================================================
2094 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
2098 std::string option_or_sm;
2100 isOK = static_cast<bool>(load >> i);
2102 _topology = (Topology) i;
2104 load.clear(std::ios::badbit | load.rdstate());
2106 isOK = static_cast<bool>(load >> i);
2108 _physicalMesh = (PhysicalMesh) i;
2110 load.clear(std::ios::badbit | load.rdstate());
2112 isOK = static_cast<bool>(load >> i);
2114 _geometricMesh = (GeometricMesh) i;
2116 load.clear(std::ios::badbit | load.rdstate());
2118 isOK = static_cast<bool>(load >> val);
2122 load.clear(std::ios::badbit | load.rdstate());
2124 isOK = static_cast<bool>(load >> val);
2128 load.clear(std::ios::badbit | load.rdstate());
2130 isOK = static_cast<bool>(load >> val);
2134 load.clear(std::ios::badbit | load.rdstate());
2136 isOK = static_cast<bool>(load >> i);
2138 _quadAllowed = (bool) i;
2140 load.clear(std::ios::badbit | load.rdstate());
2142 isOK = static_cast<bool>(load >> i);
2144 if ( i != -1) { // if value is -1, then this is no longer a standard option
2145 std::string & value = _option2value["respect_geometry"];
2146 bool _decimesh = (bool) i;
2147 value = _decimesh ? "1" : "0";
2151 load.clear(std::ios::badbit | load.rdstate());
2153 isOK = static_cast<bool>(load >> val);
2157 load.clear(std::ios::badbit | load.rdstate());
2159 isOK = static_cast<bool>(load >> val);
2163 load.clear(std::ios::badbit | load.rdstate());
2165 isOK = static_cast<bool>(load >> val);
2167 // former parameter: get min value
2168 _angleMesh = std::min(val,_angleMesh);
2170 load.clear(std::ios::badbit | load.rdstate());
2172 isOK = static_cast<bool>(load >> val);
2174 // former parameter: get min value
2175 _minSize = std::min(val,_minSize);
2177 load.clear(std::ios::badbit | load.rdstate());
2179 isOK = static_cast<bool>(load >> val);
2181 // former parameter: get max value
2182 _maxSize = std::max(val,_maxSize);
2184 load.clear(std::ios::badbit | load.rdstate());
2186 isOK = static_cast<bool>(load >> i);
2190 load.clear(std::ios::badbit | load.rdstate());
2192 isOK = static_cast<bool>(load >> i);
2194 _preCADMergeEdges = (bool) i;
2196 load.clear(std::ios::badbit | load.rdstate());
2198 isOK = static_cast<bool>(load >> i);
2200 if ( i != -1) { // if value is -1, then this is no longer a standard option
2201 std::string & value = _preCADoption2value["remove_tiny_edges"];
2202 bool _preCADRemoveNanoEdges = (bool) i;
2203 value = _preCADRemoveNanoEdges ? "1" : "0";
2207 load.clear(std::ios::badbit | load.rdstate());
2209 isOK = static_cast<bool>(load >> i);
2211 _preCADDiscardInput = (bool) i;
2213 load.clear(std::ios::badbit | load.rdstate());
2215 isOK = static_cast<bool>(load >> val);
2216 if (isOK) { // _preCADEpsNano
2217 if ( (i + 1.0) < 1e-6 ) { // if value is -1, then this is no longer a standard option: get optional value "tiny_edge_length" instead
2218 std::string & value = _preCADoption2value["tiny_edge_length"];
2219 std::ostringstream oss;
2225 load.clear(std::ios::badbit | load.rdstate());
2227 isOK = static_cast<bool>(load >> i);
2229 _enforcedInternalVerticesAllFaces = (bool) i;
2231 load.clear(std::ios::badbit | load.rdstate());
2233 // New options with MeshGems-CADSurf
2235 bool hasCADSurfOptions = false;
2236 bool hasOptions = false;
2237 bool hasCustomOptions = false;
2238 bool hasPreCADOptions = false;
2239 bool hasSizeMap = false;
2240 bool hasAttractor = false;
2241 bool hasNewAttractor = false;
2242 bool hasEnforcedVertex = false;
2243 bool hasPreCADFacesPeriodicity = false;
2244 bool hasPreCADEdgesPeriodicity = false;
2245 bool hasFacesPeriodicity = false;
2246 bool hasEdgesPeriodicity = false;
2247 bool hasVerticesPeriodicity = false;
2249 isOK = static_cast<bool>(load >> option_or_sm);
2251 if ( (option_or_sm == "1")||(option_or_sm == "0") ) {
2252 i = atoi(option_or_sm.c_str());
2253 hasCADSurfOptions = true;
2254 _phySizeRel = (bool) i;
2256 if (option_or_sm == "__OPTIONS_BEGIN__")
2258 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2259 hasCustomOptions = true;
2260 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2261 hasPreCADOptions = true;
2262 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2264 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2265 hasAttractor = true;
2266 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2267 hasNewAttractor = true;
2268 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2269 hasEnforcedVertex = true;
2270 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2271 hasPreCADFacesPeriodicity = true;
2272 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2273 hasPreCADEdgesPeriodicity = true;
2274 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2275 hasFacesPeriodicity = true;
2276 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2277 hasEdgesPeriodicity = true;
2278 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2279 hasVerticesPeriodicity = true;
2281 if (isOK && hasCADSurfOptions) {
2282 isOK = static_cast<bool>(load >> i);
2284 _minSizeRel = (bool) i;
2286 load.clear(std::ios::badbit | load.rdstate());
2288 isOK = static_cast<bool>(load >> i);
2290 _maxSizeRel = (bool) i;
2292 load.clear(std::ios::badbit | load.rdstate());
2294 isOK = static_cast<bool>(load >> val);
2296 _chordalError = val;
2298 load.clear(std::ios::badbit | load.rdstate());
2300 isOK = static_cast<bool>(load >> i);
2302 _anisotropic = (bool) i;
2304 load.clear(std::ios::badbit | load.rdstate());
2306 isOK = static_cast<bool>(load >> val);
2308 _anisotropicRatio = val;
2310 load.clear(std::ios::badbit | load.rdstate());
2312 isOK = static_cast<bool>(load >> i);
2314 _removeTinyEdges = (bool) i;
2316 load.clear(std::ios::badbit | load.rdstate());
2318 isOK = static_cast<bool>(load >> val);
2320 _tinyEdgeLength = val;
2322 load.clear(std::ios::badbit | load.rdstate());
2324 isOK = static_cast<bool>(load >> i);
2326 _badElementRemoval = (bool) i;
2328 load.clear(std::ios::badbit | load.rdstate());
2330 isOK = static_cast<bool>(load >> val);
2332 _badElementAspectRatio = val;
2334 load.clear(std::ios::badbit | load.rdstate());
2336 isOK = static_cast<bool>(load >> i);
2338 _optimizeMesh = (bool) i;
2340 load.clear(std::ios::badbit | load.rdstate());
2342 isOK = static_cast<bool>(load >> i);
2344 _quadraticMesh = (bool) i;
2346 load.clear(std::ios::badbit | load.rdstate());
2348 isOK = static_cast<bool>(load >> i);
2350 _preCADProcess3DTopology = (bool) i;
2352 load.clear(std::ios::badbit | load.rdstate());
2354 if (( load >> std::ws).peek() != '_' )
2356 isOK = static_cast<bool>(load >> i);
2358 _preCADRemoveDuplicateCADFaces = (bool) i;
2360 load.clear(std::ios::badbit | load.rdstate());
2362 isOK = static_cast<bool>(load >> i);
2364 _preCADRemoveTinyUVEdges = (bool) i;
2366 load.clear(std::ios::badbit | load.rdstate());
2368 isOK = static_cast<bool>(load >> i);
2370 _optimiseTinyEdges = (bool) i;
2372 load.clear(std::ios::badbit | load.rdstate());
2374 isOK = static_cast<bool>(load >> val);
2376 _tinyEdgeOptimisationLength = val;
2378 load.clear(std::ios::badbit | load.rdstate());
2380 isOK = static_cast<bool>(load >> i);
2382 _correctSurfaceIntersec = (bool) i;
2384 load.clear(std::ios::badbit | load.rdstate());
2386 isOK = static_cast<bool>(load >> val);
2388 _corrSurfaceIntersCost = val;
2390 load.clear(std::ios::badbit | load.rdstate());
2392 isOK = static_cast<bool>(load >> i);
2394 _useGradation = (bool) i;
2396 load.clear(std::ios::badbit | load.rdstate());
2398 isOK = static_cast<bool>(load >> i);
2400 _useVolumeGradation = (bool) i;
2402 load.clear(std::ios::badbit | load.rdstate());
2404 isOK = static_cast<bool>(load >> val);
2406 _volumeGradation = val;
2408 load.clear(std::ios::badbit | load.rdstate());
2413 if (hasCADSurfOptions) {
2414 isOK = static_cast<bool>(load >> option_or_sm);
2416 if (option_or_sm == "__OPTIONS_BEGIN__")
2418 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2419 hasCustomOptions = true;
2420 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2421 hasPreCADOptions = true;
2422 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2424 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2425 hasAttractor = true;
2426 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2427 hasNewAttractor = true;
2428 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2429 hasEnforcedVertex = true;
2430 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2431 hasPreCADFacesPeriodicity = true;
2432 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2433 hasPreCADEdgesPeriodicity = true;
2434 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2435 hasFacesPeriodicity = true;
2436 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2437 hasEdgesPeriodicity = true;
2438 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2439 hasVerticesPeriodicity = true;
2443 std::string optName, optValue;
2444 while (isOK && hasOptions) {
2445 isOK = static_cast<bool>(load >> optName);
2447 if (optName == "__OPTIONS_END__")
2449 isOK = static_cast<bool>(load >> optValue);
2452 std::string & value = _option2value[optName];
2454 int len = value.size();
2455 // continue reading until "%#" encountered
2456 while (value[len - 1] != '#' || value[len - 2] != '%') {
2457 isOK = static_cast<bool>(load >> optValue);
2466 value.resize(len - 2); //cut off "%#"
2471 isOK = static_cast<bool>(load >> option_or_sm);
2473 if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2474 hasCustomOptions = true;
2475 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2476 hasPreCADOptions = true;
2477 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2479 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2480 hasAttractor = true;
2481 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2482 hasNewAttractor = true;
2483 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2484 hasEnforcedVertex = true;
2485 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2486 hasPreCADFacesPeriodicity = true;
2487 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2488 hasPreCADEdgesPeriodicity = true;
2489 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2490 hasFacesPeriodicity = true;
2491 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2492 hasEdgesPeriodicity = true;
2493 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2494 hasVerticesPeriodicity = true;
2498 while (isOK && hasCustomOptions) {
2499 isOK = static_cast<bool>(load >> optName);
2501 if (optName == "__CUSTOM_OPTIONS_END__")
2503 isOK = static_cast<bool>(load >> optValue);
2506 std::string& value = optValue;
2507 int len = value.size();
2508 // continue reading until "%#" encountered
2509 while (value[len - 1] != '#' || value[len - 2] != '%') {
2510 isOK = static_cast<bool>(load >> optValue);
2519 value.resize(len - 2); //cut off "%#"
2520 _customOption2value[optName] = value;
2524 if (hasCustomOptions) {
2525 isOK = static_cast<bool>(load >> option_or_sm);
2527 if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2528 hasPreCADOptions = true;
2529 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2531 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2532 hasAttractor = true;
2533 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2534 hasNewAttractor = true;
2535 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2536 hasEnforcedVertex = true;
2537 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2538 hasPreCADFacesPeriodicity = true;
2539 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2540 hasPreCADEdgesPeriodicity = true;
2541 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2542 hasFacesPeriodicity = true;
2543 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2544 hasEdgesPeriodicity = true;
2545 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2546 hasVerticesPeriodicity = true;
2550 while (isOK && hasPreCADOptions) {
2551 isOK = static_cast<bool>(load >> optName);
2553 if (optName == "__PRECAD_OPTIONS_END__")
2555 isOK = static_cast<bool>(load >> optValue);
2558 std::string & value = _preCADoption2value[optName];
2560 int len = value.size();
2561 // continue reading until "%#" encountered
2562 while (value[len - 1] != '#' || value[len - 2] != '%') {
2563 isOK = static_cast<bool>(load >> optValue);
2572 value.resize(len - 2); //cut off "%#"
2576 if (hasPreCADOptions) {
2577 isOK = static_cast<bool>(load >> option_or_sm);
2579 if (option_or_sm == "__SIZEMAP_BEGIN__")
2581 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2582 hasAttractor = true;
2583 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2584 hasNewAttractor = true;
2585 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2586 hasEnforcedVertex = true;
2587 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2588 hasPreCADFacesPeriodicity = true;
2589 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2590 hasPreCADEdgesPeriodicity = true;
2591 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2592 hasFacesPeriodicity = true;
2593 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2594 hasEdgesPeriodicity = true;
2595 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2596 hasVerticesPeriodicity = true;
2600 std::string smEntry, smValue;
2601 while (isOK && hasSizeMap) {
2602 isOK = static_cast<bool>(load >> smEntry);
2604 if (smEntry == "__SIZEMAP_END__")
2606 isOK = static_cast<bool>(load >> smValue);
2609 std::string & value2 = _sizeMap[smEntry];
2611 int len2 = value2.size();
2612 // continue reading until "%#" encountered
2613 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2614 isOK = static_cast<bool>(load >> smValue);
2618 len2 = value2.size();
2623 value2.resize(len2 - 2); //cut off "%#"
2628 isOK = static_cast<bool>(load >> option_or_sm);
2630 if (option_or_sm == "__ATTRACTORS_BEGIN__")
2631 hasAttractor = true;
2632 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2633 hasNewAttractor = true;
2634 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2635 hasEnforcedVertex = true;
2636 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2637 hasPreCADFacesPeriodicity = true;
2638 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2639 hasPreCADEdgesPeriodicity = true;
2640 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2641 hasFacesPeriodicity = true;
2642 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2643 hasEdgesPeriodicity = true;
2644 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2645 hasVerticesPeriodicity = true;
2648 std::string atEntry, atValue;
2649 while (isOK && hasAttractor) {
2650 isOK = static_cast<bool>(load >> atEntry);
2652 if (atEntry == "__ATTRACTORS_END__")
2654 isOK = static_cast<bool>(load >> atValue);
2657 std::string & value3 = _attractors[atEntry];
2659 int len3 = value3.size();
2660 // continue reading until "%#" encountered
2661 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
2662 isOK = static_cast<bool>(load >> atValue);
2666 len3 = value3.size();
2671 value3.resize(len3 - 2); //cut off "%#"
2676 isOK = static_cast<bool>(load >> option_or_sm);
2678 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2679 hasNewAttractor = true;
2680 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2681 hasEnforcedVertex = true;
2682 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2683 hasPreCADFacesPeriodicity = true;
2684 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2685 hasPreCADEdgesPeriodicity = true;
2686 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2687 hasFacesPeriodicity = true;
2688 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2689 hasEdgesPeriodicity = true;
2690 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2691 hasVerticesPeriodicity = true;
2695 std::string newAtFaceEntry, atTestString;
2696 std::string newAtShapeEntry;
2697 double attParams[4];
2699 while (isOK && hasNewAttractor) {
2700 //std::cout<<"Load new attractor"<<std::endl;
2701 isOK = static_cast<bool>(load >> newAtFaceEntry);
2703 if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
2705 isOK = static_cast<bool>(load >> newAtShapeEntry);
2708 isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
2711 MESSAGE(" LOADING ATTRACTOR HYPOTHESIS ")
2712 const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
2713 const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
2714 BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
2715 attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
2716 //attractor->BuildMap();
2717 _classAttractors.insert( make_pair( newAtFaceEntry, attractor ));
2722 if (hasNewAttractor) {
2723 isOK = static_cast<bool>(load >> option_or_sm);
2725 if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2726 hasEnforcedVertex = true;
2727 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2728 hasPreCADFacesPeriodicity = true;
2729 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2730 hasPreCADEdgesPeriodicity = true;
2731 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2732 hasFacesPeriodicity = true;
2733 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2734 hasEdgesPeriodicity = true;
2735 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2736 hasVerticesPeriodicity = true;
2742 // Here is a example of the saved stream:
2743 // __ENFORCED_VERTICES_BEGIN__
2744 // __BEGIN_VERTEX__ => no name, no entry
2745 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2746 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__
2747 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__
2749 // __BEGIN_VERTEX__ => no coords
2750 // __BEGIN_NAME__ mes points __END_NAME__
2751 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
2752 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2753 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
2755 // __ENFORCED_VERTICES_END__
2758 std::string enfSeparator;
2759 std::string enfName;
2760 std::string enfGeomEntry;
2761 std::string enfGroup;
2762 TEntryList enfFaceEntryList;
2763 double enfCoords[3];
2764 bool hasCoords = false;
2766 _faceEntryEnfVertexListMap.clear();
2767 _enfVertexList.clear();
2768 _faceEntryCoordsListMap.clear();
2769 _coordsEnfVertexMap.clear();
2770 _faceEntryEnfVertexEntryListMap.clear();
2771 _enfVertexEntryEnfVertexMap.clear();
2774 while (isOK && hasEnforcedVertex) {
2775 isOK = static_cast<bool>(load >> enfSeparator); // __BEGIN_VERTEX__
2776 TEnfVertex *enfVertex = new TEnfVertex();
2777 // MESSAGE("enfSeparator: " <<enfSeparator);
2778 if (enfSeparator == "__ENFORCED_VERTICES_END__")
2779 break; // __ENFORCED_VERTICES_END__
2780 if (enfSeparator != "__BEGIN_VERTEX__")
2781 throw std::exception();
2784 isOK = static_cast<bool>(load >> enfSeparator);
2785 MESSAGE("enfSeparator: " <<enfSeparator);
2786 if (enfSeparator == "__END_VERTEX__") {
2788 enfVertex->name = enfName;
2789 enfVertex->geomEntry = enfGeomEntry;
2790 enfVertex->grpName = enfGroup;
2791 enfVertex->coords.clear();
2793 enfVertex->coords.assign(enfCoords,enfCoords+3);
2794 enfVertex->faceEntries = enfFaceEntryList;
2796 _enfVertexList.insert(enfVertex);
2798 if (enfVertex->coords.size()) {
2799 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
2800 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2801 _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
2802 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2805 if (!enfVertex->geomEntry.empty()) {
2806 _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
2807 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2808 _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
2809 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2814 enfGeomEntry.clear();
2816 enfFaceEntryList.clear();
2818 break; // __END_VERTEX__
2821 if (enfSeparator == "__BEGIN_NAME__") { // __BEGIN_NAME__
2822 while (isOK && (enfSeparator != "__END_NAME__")) {
2823 isOK = static_cast<bool>(load >> enfSeparator);
2824 if (enfSeparator != "__END_NAME__") {
2825 if (!enfName.empty())
2827 enfName += enfSeparator;
2830 MESSAGE("enfName: " <<enfName);
2833 if (enfSeparator == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
2834 isOK = static_cast<bool>(load >> enfGeomEntry);
2835 isOK = static_cast<bool>(load >> enfSeparator); // __END_ENTRY__
2836 if (enfSeparator != "__END_ENTRY__")
2837 throw std::exception();
2838 MESSAGE("enfGeomEntry: " <<enfGeomEntry);
2841 if (enfSeparator == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
2842 while (isOK && (enfSeparator != "__END_GROUP__")) {
2843 isOK = static_cast<bool>(load >> enfSeparator);
2844 if (enfSeparator != "__END_GROUP__") {
2845 if (!enfGroup.empty())
2847 enfGroup += enfSeparator;
2850 MESSAGE("enfGroup: " <<enfGroup);
2853 if (enfSeparator == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
2855 isOK = static_cast<bool>(load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
2856 isOK = static_cast<bool>(load >> enfSeparator); // __END_COORDS__
2857 if (enfSeparator != "__END_COORDS__")
2858 throw std::exception();
2859 MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
2862 if (enfSeparator == "__BEGIN_FACELIST__") { // __BEGIN_FACELIST__
2863 while (isOK && (enfSeparator != "__END_FACELIST__")) {
2864 isOK = static_cast<bool>(load >> enfSeparator);
2865 if (enfSeparator != "__END_FACELIST__") {
2866 enfFaceEntryList.insert(enfSeparator);
2867 MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
2876 if (hasPreCADFacesPeriodicity){
2877 LoadPreCADPeriodicity(load, "FACES");
2879 isOK = static_cast<bool>(load >> option_or_sm);
2881 if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2882 hasPreCADEdgesPeriodicity = true;
2883 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2884 hasFacesPeriodicity = true;
2885 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2886 hasEdgesPeriodicity = true;
2887 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2888 hasVerticesPeriodicity = true;
2892 if (hasPreCADEdgesPeriodicity){
2893 LoadPreCADPeriodicity(load, "EDGES");
2895 isOK = static_cast<bool>(load >> option_or_sm);
2897 if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2898 hasFacesPeriodicity = true;
2899 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2900 hasEdgesPeriodicity = true;
2901 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2902 hasVerticesPeriodicity = true;
2906 if (hasFacesPeriodicity){
2907 LoadFacesPeriodicity(load);
2909 isOK = static_cast<bool>(load >> option_or_sm);
2911 if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2912 hasEdgesPeriodicity = true;
2913 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2914 hasVerticesPeriodicity = true;
2918 if (hasEdgesPeriodicity){
2919 LoadEdgesPeriodicity(load);
2921 isOK = static_cast<bool>(load >> option_or_sm);
2923 if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2924 hasVerticesPeriodicity = true;
2927 if (hasVerticesPeriodicity)
2928 LoadVerticesPeriodicity(load);
2933 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
2937 std::string periodicitySeparator;
2941 _facesPeriodicityVector.clear();
2944 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2945 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2946 TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
2947 if (periodicitySeparator == "__FACES_PERIODICITY_END__")
2948 break; // __FACES_PERIODICITY_END__
2949 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2950 MESSAGE("//" << periodicitySeparator << "//");
2951 throw std::exception();
2955 isOK = static_cast<bool>(load >> periodicitySeparator);
2956 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2957 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2959 periodicity_i->first = shape1Entry;
2960 periodicity_i->second = shape2Entry;
2962 _facesPeriodicityVector.push_back(*periodicity_i);
2964 break; // __END_PERIODICITY_DESCRIPTION__
2967 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
2968 isOK = static_cast<bool>(load >> shape1Entry);
2969 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
2970 if (periodicitySeparator != "__END_ENTRY1__")
2971 throw std::exception();
2972 MESSAGE("shape1Entry: " <<shape1Entry);
2975 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
2976 isOK = static_cast<bool>(load >> shape2Entry);
2977 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
2978 if (periodicitySeparator != "__END_ENTRY2__")
2979 throw std::exception();
2980 MESSAGE("shape2Entry: " <<shape2Entry);
2987 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
2991 std::string periodicitySeparator;
2992 TEntry theFace1Entry;
2993 TEntry theEdge1Entry;
2994 TEntry theFace2Entry;
2995 TEntry theEdge2Entry;
2996 int edge_orientation = 0;
2998 _edgesPeriodicityVector.clear();
3001 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3002 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3003 TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
3004 if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
3005 break; // __EDGES_PERIODICITY_END__
3006 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3007 MESSAGE("//" << periodicitySeparator << "//");
3008 throw std::exception();
3012 isOK = static_cast<bool>(load >> periodicitySeparator);
3013 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3014 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3016 periodicity_i->theFace1Entry = theFace1Entry;
3017 periodicity_i->theEdge1Entry = theEdge1Entry;
3018 periodicity_i->theFace2Entry = theFace2Entry;
3019 periodicity_i->theEdge2Entry = theEdge2Entry;
3020 periodicity_i->edge_orientation = edge_orientation;
3022 _edgesPeriodicityVector.push_back(*periodicity_i);
3024 break; // __END_PERIODICITY_DESCRIPTION__
3027 if (periodicitySeparator == "__BEGIN_FACE1__") { // __BEGIN_FACE1__
3028 isOK = static_cast<bool>(load >> theFace1Entry);
3029 MESSAGE("//" << theFace1Entry << "//");
3030 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE1__
3031 if (periodicitySeparator != "__END_FACE1__"){
3032 MESSAGE("//" << periodicitySeparator << "//");
3033 throw std::exception();
3035 MESSAGE("theFace1Entry: " <<theFace1Entry);
3038 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3039 isOK = static_cast<bool>(load >> theEdge1Entry);
3040 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3041 if (periodicitySeparator != "__END_EDGE1__")
3042 throw std::exception();
3043 MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3046 if (periodicitySeparator == "__BEGIN_FACE2__") { // __BEGIN_FACE2__
3047 isOK = static_cast<bool>(load >> theFace2Entry);
3048 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE2__
3049 if (periodicitySeparator != "__END_FACE2__")
3050 throw std::exception();
3051 MESSAGE("theFace2Entry: " <<theFace2Entry);
3054 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3055 isOK = static_cast<bool>(load >> theEdge2Entry);
3056 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3057 if (periodicitySeparator != "__END_EDGE2__")
3058 throw std::exception();
3059 MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3062 if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") { // __BEGIN_EDGE_ORIENTATION__
3063 isOK = static_cast<bool>(load >> edge_orientation);
3064 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
3065 if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
3066 throw std::exception();
3067 MESSAGE("edge_orientation: " <<edge_orientation);
3073 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
3077 std::string periodicitySeparator;
3078 TEntry theEdge1Entry;
3079 TEntry theVertex1Entry;
3080 TEntry theEdge2Entry;
3081 TEntry theVertex2Entry;
3083 _verticesPeriodicityVector.clear();
3086 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3087 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3088 TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
3089 if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
3090 break; // __VERTICES_PERIODICITY_END__
3091 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3092 MESSAGE("//" << periodicitySeparator << "//");
3093 throw std::exception();
3097 isOK = static_cast<bool>(load >> periodicitySeparator);
3098 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3099 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3101 periodicity_i->theEdge1Entry = theEdge1Entry;
3102 periodicity_i->theVertex1Entry = theVertex1Entry;
3103 periodicity_i->theEdge2Entry = theEdge2Entry;
3104 periodicity_i->theVertex2Entry = theVertex2Entry;
3106 _verticesPeriodicityVector.push_back(*periodicity_i);
3108 break; // __END_PERIODICITY_DESCRIPTION__
3111 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3112 isOK = static_cast<bool>(load >> theEdge1Entry);
3113 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3114 if (periodicitySeparator != "__END_EDGE1__")
3115 throw std::exception();
3116 MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3119 if (periodicitySeparator == "__BEGIN_VERTEX1__") { // __BEGIN_VERTEX1__
3120 isOK = static_cast<bool>(load >> theVertex1Entry);
3121 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX1__
3122 if (periodicitySeparator != "__END_VERTEX1__")
3123 throw std::exception();
3124 MESSAGE("theVertex1Entry: " <<theVertex1Entry);
3127 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3128 isOK = static_cast<bool>(load >> theEdge2Entry);
3129 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3130 if (periodicitySeparator != "__END_EDGE2__")
3131 throw std::exception();
3132 MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3135 if (periodicitySeparator == "__BEGIN_VERTEX2__") { // __BEGIN_VERTEX2__
3136 isOK = static_cast<bool>(load >> theVertex2Entry);
3137 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX2__
3138 if (periodicitySeparator != "__END_VERTEX2__")
3139 throw std::exception();
3140 MESSAGE("theVertex2Entry: " <<theVertex2Entry);
3146 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
3150 std::string periodicitySeparator;
3153 std::vector<std::string> theSourceVerticesEntries;
3154 std::vector<std::string> theTargetVerticesEntries;
3156 bool hasSourceVertices = false;
3157 bool hasTargetVertices = false;
3159 if ( shapeType && strcmp( shapeType, "FACES") == 0 )
3160 _preCadFacesPeriodicityVector.clear();
3162 _preCadEdgesPeriodicityVector.clear();
3166 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3167 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3168 TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
3169 // MESSAGE("periodicitySeparator: " <<periodicitySeparator);
3170 std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
3171 if (periodicitySeparator == endSeparator)
3172 break; // __PRECAD_FACES_PERIODICITY_END__
3173 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3174 MESSAGE("//" << endSeparator << "//");
3175 MESSAGE("//" << periodicitySeparator << "//");
3176 throw std::exception();
3180 isOK = static_cast<bool>(load >> periodicitySeparator);
3181 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3182 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3184 periodicity_i->shape1Entry = shape1Entry;
3185 periodicity_i->shape2Entry = shape2Entry;
3187 MESSAGE("theSourceVerticesEntries.size(): " << theSourceVerticesEntries.size());
3188 MESSAGE("theTargetVerticesEntries.size(): " << theTargetVerticesEntries.size());
3190 if (hasSourceVertices)
3191 periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
3192 if (hasTargetVertices)
3193 periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
3195 if ( shapeType && strcmp( shapeType, "FACES" ))
3196 _preCadFacesPeriodicityVector.push_back(*periodicity_i);
3198 _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
3200 theSourceVerticesEntries.clear();
3201 theTargetVerticesEntries.clear();
3202 hasSourceVertices = false;
3203 hasTargetVertices = false;
3204 break; // __END_PERIODICITY_DESCRIPTION__
3207 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3208 isOK = static_cast<bool>(load >> shape1Entry);
3209 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3210 if (periodicitySeparator != "__END_ENTRY1__")
3211 throw std::exception();
3212 MESSAGE("shape1Entry: " <<shape1Entry);
3215 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3216 isOK = static_cast<bool>(load >> shape2Entry);
3217 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3218 if (periodicitySeparator != "__END_ENTRY2__")
3219 throw std::exception();
3220 MESSAGE("shape2Entry: " <<shape2Entry);
3223 if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") { // __BEGIN_SOURCE_VERTICES_LIST__
3224 hasSourceVertices = true;
3225 while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
3226 isOK = static_cast<bool>(load >> periodicitySeparator);
3227 if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
3228 theSourceVerticesEntries.push_back(periodicitySeparator);
3229 MESSAGE("theSourceVerticesEntries: " <<periodicitySeparator);
3234 if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") { // __BEGIN_TARGET_VERTICES_LIST__
3235 hasTargetVertices = true;
3236 while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
3237 isOK = static_cast<bool>(load >> periodicitySeparator);
3238 if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
3239 theTargetVerticesEntries.push_back(periodicitySeparator);
3240 MESSAGE("theTargetVerticesEntries: " <<periodicitySeparator);
3248 //=============================================================================
3249 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
3250 return hyp.SaveTo(save);
3253 //=============================================================================
3254 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
3255 return hyp.LoadFrom(load);
3258 //================================================================================
3260 * \brief Does nothing
3262 //================================================================================
3264 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
3268 //================================================================================
3270 * \brief Returns default global constant physical size given a default value of element length ratio
3272 //================================================================================
3274 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
3275 if (bbSegmentation != 0 && diagonal != 0)
3276 return diagonal / bbSegmentation ;
3280 //================================================================================
3282 * \brief Returns default min size given a default value of element length ratio
3284 //================================================================================
3286 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
3288 return diagonal / 1000.0 ;
3289 return undefinedDouble();
3292 //================================================================================
3294 * \brief Returns default max size given a default value of element length ratio
3296 //================================================================================
3298 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
3300 return diagonal / 5.0 ;
3301 return undefinedDouble();
3304 //================================================================================
3306 * \brief Returns default chordal error given a default value of element length ratio
3308 //================================================================================
3310 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
3313 return undefinedDouble();
3316 //================================================================================
3318 * \brief Returns default tiny edge length given a default value of element length ratio
3320 //================================================================================
3322 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
3324 return diagonal * 1e-6 ;
3325 return undefinedDouble();
3328 //================================================================================
3330 * \brief Returns default tiny edge optimisation length given a default value of element length ratio
3332 //================================================================================
3334 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal) {
3336 return diagonal * 1e-6 ;
3337 return undefinedDouble();
3340 //=============================================================================
3342 * \brief Initialize my parameter values by default parameters.
3343 * \retval bool - true if parameter values have been successfully defined
3345 //=============================================================================
3347 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
3348 double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
3349 _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
3350 _minSize = GetDefaultMinSize(diagonal);
3351 _maxSize = GetDefaultMaxSize(diagonal);
3352 _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
3353 _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
3354 _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(diagonal);
3359 //================================================================================
3361 * \brief Converts a string to a bool
3363 //================================================================================
3365 bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
3366 throw (std::invalid_argument)
3368 std::string s = str;
3369 if ( isOk ) *isOk = true;
3371 for ( size_t i = 0; i <= s.size(); ++i )
3372 s[i] = tolower( s[i] );
3374 if ( s == "1" || s == "true" || s == "active" || s == "yes" )
3377 if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
3383 std::string msg = "Not a Boolean value:'" + str + "'";
3384 throw std::invalid_argument(msg);
3389 //================================================================================
3391 * \brief Converts a string to a real value
3393 //================================================================================
3395 double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
3396 throw (std::invalid_argument)
3398 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3401 double val = strtod(&str[0], &endPtr);
3402 bool ok = (&str[0] != endPtr);
3404 if ( isOk ) *isOk = ok;
3408 std::string msg = "Not a real value:'" + str + "'";
3409 throw std::invalid_argument(msg);
3414 //================================================================================
3416 * \brief Converts a string to a integer value
3418 //================================================================================
3420 int BLSURFPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
3421 throw (std::invalid_argument)
3423 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3426 int val = (int)strtol( &str[0], &endPtr, 10);
3427 bool ok = (&str[0] != endPtr);
3429 if ( isOk ) *isOk = ok;
3433 std::string msg = "Not an integer value:'" + str + "'";
3434 throw std::invalid_argument(msg);