1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : BLSURFPlugin_Hypothesis.cxx
22 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
23 // & Aurelien ALLEAUME (DISTENE)
24 // Size maps development: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
27 #include "BLSURFPlugin_Hypothesis.hxx"
28 #include "BLSURFPlugin_Attractor.hxx"
29 #include "SMESH_Gen_i.hxx"
30 #include <utilities.h>
36 #include "ShapeAnalysis.hxx"
39 #include CORBA_CLIENT_HEADER(SALOMEDS)
40 #include CORBA_CLIENT_HEADER(GEOM_Gen)
44 struct GET_DEFAULT // struct used to get default value from GetOptionValue()
47 operator bool* () { return &isDefault; }
51 //=============================================================================
52 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, SMESH_Gen * gen) :
53 SMESH_Hypothesis(hypId, gen),
54 _physicalMesh(GetDefaultPhysicalMesh()),
55 _geometricMesh(GetDefaultGeometricMesh()),
56 _phySize(GetDefaultPhySize()),
57 _phySizeRel(GetDefaultPhySizeRel()),
58 _minSize(GetDefaultMinSize()),
59 _maxSize(GetDefaultMaxSize()),
60 _minSizeRel(GetDefaultMinSizeRel()),
61 _maxSizeRel(GetDefaultMaxSizeRel()),
62 _useGradation(GetDefaultUseGradation()),
63 _gradation(GetDefaultGradation()),
64 _useVolumeGradation(GetDefaultUseVolumeGradation()),
65 _volumeGradation(GetDefaultVolumeGradation()),
66 _quadAllowed(GetDefaultQuadAllowed()),
67 _angleMesh(GetDefaultAngleMesh()),
68 _chordalError(GetDefaultChordalError()),
69 _anisotropic(GetDefaultAnisotropic()),
70 _anisotropicRatio(GetDefaultAnisotropicRatio()),
71 _removeTinyEdges(GetDefaultRemoveTinyEdges()),
72 _tinyEdgeLength(GetDefaultTinyEdgeLength()),
73 _optimiseTinyEdges(GetDefaultOptimiseTinyEdges()),
74 _tinyEdgeOptimisationLength(GetDefaultTinyEdgeOptimisationLength()),
75 _correctSurfaceIntersec(GetDefaultCorrectSurfaceIntersection()),
76 _corrSurfaceIntersCost(GetDefaultCorrectSurfaceIntersectionMaxCost()),
77 _badElementRemoval(GetDefaultBadElementRemoval()),
78 _badElementAspectRatio(GetDefaultBadElementAspectRatio()),
79 _optimizeMesh(GetDefaultOptimizeMesh()),
80 _quadraticMesh(GetDefaultQuadraticMesh()),
81 _verb(GetDefaultVerbosity()),
82 _topology(GetDefaultTopology()),
83 _preCADMergeEdges(GetDefaultPreCADMergeEdges()),
84 _preCADRemoveTinyUVEdges(GetDefaultPreCADRemoveTinyUVEdges()),
85 _preCADRemoveDuplicateCADFaces(GetDefaultPreCADRemoveDuplicateCADFaces()),
86 _preCADProcess3DTopology(GetDefaultPreCADProcess3DTopology()),
87 _preCADDiscardInput(GetDefaultPreCADDiscardInput()),
88 _sizeMap(GetDefaultSizeMap()),
89 _attractors(GetDefaultSizeMap()),
90 _classAttractors(GetDefaultAttractorMap()),
91 _faceEntryEnfVertexListMap(GetDefaultFaceEntryEnfVertexListMap()),
92 _enfVertexList(GetDefaultEnfVertexList()),
93 _faceEntryCoordsListMap(GetDefaultFaceEntryCoordsListMap()),
94 _coordsEnfVertexMap(GetDefaultCoordsEnfVertexMap()),
95 _faceEntryEnfVertexEntryListMap(GetDefaultFaceEntryEnfVertexEntryListMap()),
96 _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
97 _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap()),
98 _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex()),
99 _preCadFacesPeriodicityVector(GetDefaultPreCadFacesPeriodicityVector()),
100 _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector()),
101 _GMFFileName(GetDefaultGMFFile())
103 _name = GetHypType();
106 // _GMFFileMode = false; // GMF ascii mode
108 // Advanced options with their defaults according to MG User Manual
110 const char* boolOptionNames[] = { "enforce_cad_edge_sizes", // default = 0
111 // "correct_surface_intersections", // default = 1
112 // "create_tag_on_collision", // default = 1
113 "jacobian_rectification_respect_geometry", // default = 1
114 "rectify_jacobian", // default = 1
115 "respect_geometry", // default = 1
116 // "optimise_tiny_edges", // default = 0
117 // "remove_duplicate_cad_faces", // default = 1
118 "tiny_edge_avoid_surface_intersections", // default = 1
119 // "tiny_edge_respect_geometry", // default = 0
123 const char* intOptionNames[] = { "max_number_of_points_per_patch", // default = 100000
126 const char* doubleOptionNames[] = { // "surface_intersections_processing_max_cost",// default = 15
127 // "periodic_tolerance", // default = diag/100
128 // "volume_gradation",
129 // "tiny_edge_optimisation_length", // default = diag * 1e-6
132 const char* charOptionNames[] = { // "required_entities", // default = "respect"
133 // "tags", // default = "respect"
137 // PreCAD advanced options
138 const char* preCADboolOptionNames[] = { "closed_geometry", // default = 0
139 "discard_input_topology", // default = 0
140 "merge_edges", // default = = 1
141 "remove_duplicate_cad_faces", // default = 1
142 // "create_tag_on_collision", // default = 1
143 "debug", // default = 0
144 "process_3d_topology", // default = 1
145 // "remove_tiny_edges", // default = 0
148 const char* preCADintOptionNames[] = { // "manifold_geometry", // default = 0
151 const char* preCADdoubleOptionNames[] = { "periodic_tolerance", // default = diag * 1e-5
152 "sewing_tolerance", // default = diag * 5e-4
153 // "tiny_edge_length", // default = diag * 1e-5
156 const char* preCADcharOptionNames[] = { "required_entities", // default = "respect"
157 "tags", // default = "respect"
162 while (boolOptionNames[i][0])
164 _boolOptions.insert( boolOptionNames[i] );
165 _option2value[boolOptionNames[i++]].clear();
168 while (preCADboolOptionNames[i][0])
170 _boolOptions.insert( preCADboolOptionNames[i] );
171 _preCADoption2value[preCADboolOptionNames[i++]].clear();
174 while (intOptionNames[i][0])
175 _option2value[intOptionNames[i++]].clear();
178 while (preCADintOptionNames[i][0])
179 _preCADoption2value[preCADintOptionNames[i++]].clear();
182 while (doubleOptionNames[i][0]) {
183 _doubleOptions.insert(doubleOptionNames[i]);
184 _option2value[doubleOptionNames[i++]].clear();
187 while (preCADdoubleOptionNames[i][0]) {
188 _preCADdoubleOptions.insert(preCADdoubleOptionNames[i]);
189 _preCADoption2value[preCADdoubleOptionNames[i++]].clear();
192 while (charOptionNames[i][0]) {
193 _charOptions.insert(charOptionNames[i]);
194 _option2value[charOptionNames[i++]].clear();
197 while (preCADcharOptionNames[i][0]) {
198 _preCADcharOptions.insert(preCADcharOptionNames[i]);
199 _preCADoption2value[preCADcharOptionNames[i++]].clear();
202 // default values to be used while MG meshing
204 _defaultOptionValues["enforce_cad_edge_sizes" ] = "no";
205 _defaultOptionValues["jacobian_rectification_respect_geometry"] = "yes";
206 _defaultOptionValues["max_number_of_points_per_patch" ] = "0";
207 _defaultOptionValues["rectify_jacobian" ] = "yes";
208 _defaultOptionValues["respect_geometry" ] = "yes";
209 _defaultOptionValues["tiny_edge_avoid_surface_intersections" ] = "yes";
210 _defaultOptionValues["process_3d_topology" ] = "no";
211 _defaultOptionValues["closed_geometry" ] = "no";
212 _defaultOptionValues["debug" ] = "no";
213 _defaultOptionValues["discard_input_topology" ] = "no";
214 _defaultOptionValues["merge_edges" ] = "no";
215 _defaultOptionValues["periodic_tolerance" ] = "1e-5*D";
216 _defaultOptionValues["remove_duplicate_cad_faces" ] = "no";
217 _defaultOptionValues["required_entities" ] = "respect";
218 _defaultOptionValues["sewing_tolerance" ] = "5e-4*D";
219 _defaultOptionValues["tags" ] = "respect";
222 // check validity of option names of _defaultOptionValues
223 TOptionValues::iterator n2v = _defaultOptionValues.begin();
224 for ( ; n2v != _defaultOptionValues.end(); ++n2v )
225 ASSERT( _option2value.count( n2v->first ) || _preCADoption2value.count( n2v->first ));
226 ASSERT( _option2value.size() + _preCADoption2value.size() == _defaultOptionValues.size() );
231 _faceEntryEnfVertexListMap.clear();
232 _enfVertexList.clear();
233 _faceEntryCoordsListMap.clear();
234 _coordsEnfVertexMap.clear();
235 _faceEntryEnfVertexEntryListMap.clear();
236 _enfVertexEntryEnfVertexMap.clear();
237 _groupNameNodeIDMap.clear();
240 _groupNameEnfVertexListMap.clear();
241 _enfVertexGroupNameMap.clear();
245 TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry)
247 MESSAGE("BLSURFPlugin_Hypothesis::entryToShape "<<entry );
248 GEOM::GEOM_Object_var aGeomObj;
249 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
250 SALOMEDS::Study_ptr myStudy = smeshGen_i->GetStudy();
252 TopoDS_Shape S = TopoDS_Shape();
253 SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
254 if (!aSObj->_is_nil() ) {
255 CORBA::Object_var obj = aSObj->GetObject();
256 aGeomObj = GEOM::GEOM_Object::_narrow(obj);
259 if ( !aGeomObj->_is_nil() )
260 S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
264 //=============================================================================
265 void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
266 if (thePhysicalMesh != _physicalMesh) {
267 _physicalMesh = thePhysicalMesh;
268 NotifySubMeshesHypothesisModification();
272 //=============================================================================
273 void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
274 if (theGeometricMesh != _geometricMesh) {
275 _geometricMesh = theGeometricMesh;
276 // switch (_geometricMesh) {
279 // _angleMesh = GetDefaultAngleMesh();
280 // _gradation = GetDefaultGradation();
283 NotifySubMeshesHypothesisModification();
287 //=============================================================================
288 void BLSURFPlugin_Hypothesis::SetPhySize(double theVal, bool isRelative) {
289 if ((theVal != _phySize) || (isRelative != _phySizeRel)) {
290 _phySizeRel = isRelative;
292 _phySize = GetMaxSize();
293 MESSAGE("Warning: nul physical size is not allowed");
297 NotifySubMeshesHypothesisModification();
301 //=============================================================================
302 void BLSURFPlugin_Hypothesis::SetMinSize(double theMinSize, bool isRelative) {
303 if ((theMinSize != _minSize) || (isRelative != _minSizeRel)) {
304 _minSizeRel = isRelative;
305 _minSize = theMinSize;
306 NotifySubMeshesHypothesisModification();
310 //=============================================================================
311 void BLSURFPlugin_Hypothesis::SetMaxSize(double theMaxSize, bool isRelative) {
312 if ((theMaxSize != _maxSize) || (isRelative != _maxSizeRel)) {
313 _maxSizeRel = isRelative;
314 _maxSize = theMaxSize;
315 NotifySubMeshesHypothesisModification();
319 //=============================================================================
320 void BLSURFPlugin_Hypothesis::SetUseGradation(bool theVal) {
321 if (theVal != _useGradation) {
322 _useGradation = theVal;
323 NotifySubMeshesHypothesisModification();
327 //=============================================================================
328 void BLSURFPlugin_Hypothesis::SetGradation(double theVal) {
329 _useGradation = ( theVal > 0 );
330 if (theVal != _gradation) {
332 NotifySubMeshesHypothesisModification();
336 //=============================================================================
337 void BLSURFPlugin_Hypothesis::SetUseVolumeGradation(bool theVal) {
338 if (theVal != _useVolumeGradation) {
339 _useVolumeGradation = theVal;
340 NotifySubMeshesHypothesisModification();
344 //=============================================================================
345 void BLSURFPlugin_Hypothesis::SetVolumeGradation(double theVal) {
346 _useVolumeGradation = ( theVal > 0 );
347 if (theVal != _volumeGradation) {
348 _volumeGradation = theVal;
349 NotifySubMeshesHypothesisModification();
353 //=============================================================================
354 void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal) {
355 if (theVal != _quadAllowed) {
356 _quadAllowed = theVal;
357 NotifySubMeshesHypothesisModification();
361 //=============================================================================
362 void BLSURFPlugin_Hypothesis::SetAngleMesh(double theVal) {
363 if (theVal != _angleMesh) {
365 NotifySubMeshesHypothesisModification();
369 //=============================================================================
370 void BLSURFPlugin_Hypothesis::SetChordalError(double theDistance) {
371 if (theDistance != _chordalError) {
372 _chordalError = theDistance;
373 NotifySubMeshesHypothesisModification();
377 //=============================================================================
378 void BLSURFPlugin_Hypothesis::SetAnisotropic(bool theVal) {
379 if (theVal != _anisotropic) {
380 _anisotropic = theVal;
381 NotifySubMeshesHypothesisModification();
385 //=============================================================================
386 void BLSURFPlugin_Hypothesis::SetAnisotropicRatio(double theVal) {
387 if (theVal != _anisotropicRatio) {
388 _anisotropicRatio = theVal;
389 NotifySubMeshesHypothesisModification();
393 //=============================================================================
394 void BLSURFPlugin_Hypothesis::SetRemoveTinyEdges(bool theVal) {
395 if (theVal != _removeTinyEdges) {
396 _removeTinyEdges = theVal;
397 NotifySubMeshesHypothesisModification();
401 //=============================================================================
402 void BLSURFPlugin_Hypothesis::SetTinyEdgeLength(double theVal) {
403 if (theVal != _tinyEdgeLength) {
404 _tinyEdgeLength = theVal;
405 NotifySubMeshesHypothesisModification();
409 //=============================================================================
410 void BLSURFPlugin_Hypothesis::SetOptimiseTinyEdges(bool theVal) {
411 if (theVal != _optimiseTinyEdges) {
412 _optimiseTinyEdges = theVal;
413 NotifySubMeshesHypothesisModification();
417 //=============================================================================
418 void BLSURFPlugin_Hypothesis::SetTinyEdgeOptimisationLength(double theVal) {
419 if (theVal != _tinyEdgeOptimisationLength) {
420 _tinyEdgeOptimisationLength = theVal;
421 NotifySubMeshesHypothesisModification();
425 //=============================================================================
426 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersection(bool theVal) {
427 if (theVal != _correctSurfaceIntersec) {
428 _correctSurfaceIntersec = theVal;
429 NotifySubMeshesHypothesisModification();
433 //=============================================================================
434 void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersectionMaxCost(double theVal) {
435 if (theVal != _corrSurfaceIntersCost) {
436 _corrSurfaceIntersCost = theVal;
437 NotifySubMeshesHypothesisModification();
441 //=============================================================================
442 void BLSURFPlugin_Hypothesis::SetBadElementRemoval(bool theVal) {
443 if (theVal != _badElementRemoval) {
444 _badElementRemoval = theVal;
445 NotifySubMeshesHypothesisModification();
449 //=============================================================================
450 void BLSURFPlugin_Hypothesis::SetBadElementAspectRatio(double theVal) {
451 if (theVal != _badElementAspectRatio) {
452 _badElementAspectRatio = theVal;
453 NotifySubMeshesHypothesisModification();
457 //=============================================================================
458 void BLSURFPlugin_Hypothesis::SetOptimizeMesh(bool theVal) {
459 if (theVal != _optimizeMesh) {
460 _optimizeMesh = theVal;
461 NotifySubMeshesHypothesisModification();
465 //=============================================================================
466 void BLSURFPlugin_Hypothesis::SetQuadraticMesh(bool theVal) {
467 if (theVal != _quadraticMesh) {
468 _quadraticMesh = theVal;
469 NotifySubMeshesHypothesisModification();
473 //=============================================================================
474 void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology) {
475 if (theTopology != _topology) {
476 _topology = theTopology;
477 NotifySubMeshesHypothesisModification();
481 //=============================================================================
482 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
483 if (theVal != _verb) {
485 NotifySubMeshesHypothesisModification();
489 //=============================================================================
490 void BLSURFPlugin_Hypothesis::SetEnforceCadEdgesSize( bool toEnforce )
492 if ( GetEnforceCadEdgesSize() != toEnforce )
494 SetOptionValue( "enforce_cad_edge_sizes", toEnforce ? "yes" : "no" );
495 NotifySubMeshesHypothesisModification();
498 //=============================================================================
499 bool BLSURFPlugin_Hypothesis::GetEnforceCadEdgesSize()
501 return ToBool( GetOptionValue( "enforce_cad_edge_sizes" ), GET_DEFAULT() );
503 //=============================================================================
505 void BLSURFPlugin_Hypothesis::SetJacobianRectificationRespectGeometry( bool allowRectification )
507 if ( GetJacobianRectificationRespectGeometry() != allowRectification )
509 SetOptionValue("jacobian_rectification_respect_geometry", allowRectification ? "yes" : "no" );
510 NotifySubMeshesHypothesisModification();
513 //=============================================================================
514 bool BLSURFPlugin_Hypothesis::GetJacobianRectificationRespectGeometry()
516 return ToBool( GetOptionValue("jacobian_rectification_respect_geometry", GET_DEFAULT()));
518 //=============================================================================
520 void BLSURFPlugin_Hypothesis::SetJacobianRectification( bool allowRectification )
522 if ( GetJacobianRectification() != allowRectification )
524 SetOptionValue( "rectify_jacobian", allowRectification ? "yes" : "no" );
525 NotifySubMeshesHypothesisModification();
528 //=============================================================================
529 bool BLSURFPlugin_Hypothesis::GetJacobianRectification()
531 return ToBool( GetOptionValue("rectify_jacobian", GET_DEFAULT()));
533 //=============================================================================
535 void BLSURFPlugin_Hypothesis::SetMaxNumberOfPointsPerPatch( int nb )
536 throw (std::invalid_argument)
539 throw std::invalid_argument( SMESH_Comment("Invalid number of points: ") << nb );
541 if ( GetMaxNumberOfPointsPerPatch() != nb )
543 SetOptionValue("max_number_of_points_per_patch", SMESH_Comment( nb ));
544 NotifySubMeshesHypothesisModification();
547 //=============================================================================
548 int BLSURFPlugin_Hypothesis::GetMaxNumberOfPointsPerPatch()
550 return ToInt( GetOptionValue("max_number_of_points_per_patch", GET_DEFAULT()));
552 //=============================================================================
554 void BLSURFPlugin_Hypothesis::SetRespectGeometry( bool toRespect )
556 if ( GetRespectGeometry() != toRespect )
558 SetOptionValue("respect_geometry", toRespect ? "yes" : "no" );
559 NotifySubMeshesHypothesisModification();
562 //=============================================================================
563 bool BLSURFPlugin_Hypothesis::GetRespectGeometry()
565 return ToBool( GetOptionValue( "respect_geometry", GET_DEFAULT()));
567 //=============================================================================
569 void BLSURFPlugin_Hypothesis::SetTinyEdgesAvoidSurfaceIntersections( bool toAvoidIntersection )
571 if ( GetTinyEdgesAvoidSurfaceIntersections() != toAvoidIntersection )
573 SetOptionValue("tiny_edge_avoid_surface_intersections", toAvoidIntersection ? "yes" : "no" );
574 NotifySubMeshesHypothesisModification();
577 //=============================================================================
578 bool BLSURFPlugin_Hypothesis::GetTinyEdgesAvoidSurfaceIntersections()
580 return ToBool( GetOptionValue("tiny_edge_avoid_surface_intersections", GET_DEFAULT()));
582 //=============================================================================
584 void BLSURFPlugin_Hypothesis::SetClosedGeometry( bool isClosed )
586 if ( GetClosedGeometry() != isClosed )
588 SetPreCADOptionValue("closed_geometry", isClosed ? "yes" : "no" );
589 NotifySubMeshesHypothesisModification();
592 //=============================================================================
593 bool BLSURFPlugin_Hypothesis::GetClosedGeometry()
595 return ToBool( GetPreCADOptionValue( "closed_geometry", GET_DEFAULT()));
597 //=============================================================================
599 void BLSURFPlugin_Hypothesis::SetDebug( bool isDebug )
601 if ( GetDebug() != isDebug )
603 SetPreCADOptionValue("debug", isDebug ? "yes" : "no" );
604 NotifySubMeshesHypothesisModification();
607 //=============================================================================
608 bool BLSURFPlugin_Hypothesis::GetDebug()
610 return ToBool( GetPreCADOptionValue("debug", GET_DEFAULT()));
612 //=============================================================================
614 void BLSURFPlugin_Hypothesis::SetPeriodicTolerance( CORBA::Double tol )
615 throw (std::invalid_argument)
618 throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
619 if ( GetPeriodicTolerance() != tol )
621 SetPreCADOptionValue("periodic_tolerance", SMESH_Comment( tol ) );
622 NotifySubMeshesHypothesisModification();
625 //=============================================================================
626 double BLSURFPlugin_Hypothesis::GetPeriodicTolerance()
628 return ToDbl( GetPreCADOptionValue( "periodic_tolerance", GET_DEFAULT()));
630 //=============================================================================
632 void BLSURFPlugin_Hypothesis::SetRequiredEntities( const std::string& howToTreat )
633 throw (std::invalid_argument)
635 if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear" )
636 throw std::invalid_argument
637 ( SMESH_Comment("required_entities must be in ['respect','ignore','clear'] "));
639 if ( GetRequiredEntities() != howToTreat )
641 SetPreCADOptionValue("required_entities", howToTreat );
642 NotifySubMeshesHypothesisModification();
645 //=============================================================================
646 std::string BLSURFPlugin_Hypothesis::GetRequiredEntities()
648 return GetPreCADOptionValue("required_entities", GET_DEFAULT());
650 //=============================================================================
652 void BLSURFPlugin_Hypothesis::SetSewingTolerance( CORBA::Double tol )
653 throw (std::invalid_argument)
656 throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
657 if ( GetSewingTolerance() != tol )
659 SetPreCADOptionValue("sewing_tolerance", SMESH_Comment( tol ) );
660 NotifySubMeshesHypothesisModification();
663 //=============================================================================
664 CORBA::Double BLSURFPlugin_Hypothesis::GetSewingTolerance()
666 return ToDbl( GetPreCADOptionValue("sewing_tolerance", GET_DEFAULT()));
668 //=============================================================================
670 void BLSURFPlugin_Hypothesis::SetTags( const std::string& howToTreat )
671 throw (std::invalid_argument)
673 if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear" )
674 throw std::invalid_argument
675 ( SMESH_Comment("'tags' must be in ['respect','ignore','clear'] "));
677 if ( GetTags() != howToTreat )
679 SetPreCADOptionValue("tags", howToTreat );
680 NotifySubMeshesHypothesisModification();
683 //=============================================================================
684 std::string BLSURFPlugin_Hypothesis::GetTags()
686 return GetPreCADOptionValue("tags", GET_DEFAULT());
688 //=============================================================================
689 void BLSURFPlugin_Hypothesis::SetPreCADMergeEdges(bool theVal)
691 if (theVal != ToBool( GetPreCADOptionValue("merge_edges", GET_DEFAULT()))) {
692 _preCADMergeEdges = theVal;
693 SetPreCADOptionValue("merge_edges", theVal ? "yes" : "no" );
694 NotifySubMeshesHypothesisModification();
698 //=============================================================================
699 void BLSURFPlugin_Hypothesis::SetPreCADRemoveTinyUVEdges(bool theVal)
701 if (theVal != _preCADRemoveTinyUVEdges) {
702 _preCADRemoveTinyUVEdges = theVal;
703 NotifySubMeshesHypothesisModification();
707 //=============================================================================
708 void BLSURFPlugin_Hypothesis::SetPreCADRemoveDuplicateCADFaces(bool theVal)
710 if (theVal != ToBool( GetPreCADOptionValue("remove_duplicate_cad_faces", GET_DEFAULT()))) {
711 _preCADRemoveDuplicateCADFaces = theVal;
712 SetPreCADOptionValue("remove_duplicate_cad_faces", theVal ? "yes" : "no" );
713 NotifySubMeshesHypothesisModification();
717 //=============================================================================
718 void BLSURFPlugin_Hypothesis::SetPreCADProcess3DTopology(bool theVal)
720 if (theVal != ToBool( GetPreCADOptionValue("process_3d_topology", GET_DEFAULT()))) {
721 _preCADProcess3DTopology = theVal;
722 SetPreCADOptionValue("process_3d_topology", theVal ? "yes" : "no" );
723 NotifySubMeshesHypothesisModification();
727 //=============================================================================
728 void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal)
730 if (theVal != ToBool( GetPreCADOptionValue("discard_input_topology", GET_DEFAULT()))) {
731 _preCADDiscardInput = theVal;
732 SetPreCADOptionValue("discard_input_topology", theVal ? "yes" : "no" );
733 NotifySubMeshesHypothesisModification();
737 //=============================================================================
738 // Return true if any PreCAD option is activated
739 bool BLSURFPlugin_Hypothesis::HasPreCADOptions(const BLSURFPlugin_Hypothesis* hyp)
745 bool orDefault, isOk;
746 return ( ToBool( hyp->GetPreCADOptionValue("closed_geometry" , &orDefault )) ||
747 ToBool( hyp->GetPreCADOptionValue("discard_input_topology" , &orDefault )) ||
748 ToBool( hyp->GetPreCADOptionValue("merge_edges" , &orDefault )) ||
749 ToBool( hyp->GetPreCADOptionValue("remove_duplicate_cad_faces", &orDefault )) ||
750 ToBool( hyp->GetPreCADOptionValue("process_3d_topology" , &orDefault )) ||
751 ToBool( hyp->GetPreCADOption ("manifold_geometry") , &isOk ) ||
752 hyp->GetPreCADOptionValue("sewing_tolerance", &orDefault ) != "5e-4*D" ||
753 !hyp->_preCadFacesPeriodicityVector.empty() ||
754 !hyp->_preCadEdgesPeriodicityVector.empty() ||
755 !hyp->_facesPeriodicityVector.empty() ||
756 !hyp->_edgesPeriodicityVector.empty() ||
757 !hyp->_verticesPeriodicityVector.empty() ||
758 hyp->GetTopology() != FromCAD );
761 //=============================================================================
762 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
763 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
765 _GMFFileName = theFileName;
766 // _GMFFileMode = isBinary;
767 NotifySubMeshesHypothesisModification();
770 //=============================================================================
771 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
772 throw (std::invalid_argument) {
774 TOptionValues::iterator op_val = _option2value.find(optionName);
775 if (op_val == _option2value.end())
777 op_val = _preCADoption2value.find(optionName);
778 if (op_val == _preCADoption2value.end())
780 std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'. Try SetAdvancedOption()";
781 throw std::invalid_argument(msg);
784 if (op_val->second != optionValue)
786 const char* ptr = optionValue.c_str();
787 // strip white spaces
788 while (ptr[0] == ' ')
791 while (i != 0 && ptr[i - 1] == ' ')
795 std::string typeName;
798 } else if (_charOptions.count(optionName)) {
799 // do not check strings
800 } else if (_doubleOptions.count(optionName)) {
801 // check if value is double
804 } else if (_boolOptions.count(optionName)) {
805 // check if value is bool
806 ToBool(ptr, &typeOk);
809 // check if value is int
811 typeName = "integer";
814 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
815 throw std::invalid_argument(msg);
817 std::string value( ptr, i );
818 if ( _defaultOptionValues[ optionName ] == value )
821 op_val->second = value;
823 NotifySubMeshesHypothesisModification();
827 //=============================================================================
828 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
829 throw (std::invalid_argument) {
831 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
832 if (op_val == _preCADoption2value.end()) {
833 op_val = _option2value.find(optionName);
834 if (op_val == _option2value.end()) {
835 std::string msg = "Unknown MG-PreCAD option: '" + optionName + "'. Try SetAdvancedOption()";
836 throw std::invalid_argument(msg);
839 if (op_val->second != optionValue)
841 const char* ptr = optionValue.c_str();
842 // strip white spaces
843 while (ptr[0] == ' ')
846 while (i != 0 && ptr[i - 1] == ' ')
850 std::string typeName;
853 } else if (_preCADcharOptions.find(optionName) != _preCADcharOptions.end()) {
854 // do not check strings
855 } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
856 // check if value is double
858 strtod(ptr, &endPtr);
859 typeOk = (ptr != endPtr);
861 } else if (_boolOptions.count(optionName)) {
862 // check if value is bool
863 ToBool(ptr, &typeOk);
866 // check if value is int
868 strtol(ptr, &endPtr, 10);
869 typeOk = (ptr != endPtr);
870 typeName = "integer";
873 std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
874 throw std::invalid_argument(msg);
876 std::string value( ptr, i );
877 if ( _defaultOptionValues[ optionName ] == value )
880 op_val->second = value;
882 NotifySubMeshesHypothesisModification();
886 //=============================================================================
887 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
888 bool* isDefault) const
889 throw (std::invalid_argument)
891 TOptionValues::const_iterator op_val = _option2value.find(optionName);
892 if (op_val == _option2value.end())
894 op_val = _preCADoption2value.find(optionName);
895 if (op_val == _preCADoption2value.end())
897 op_val = _customOption2value.find(optionName);
898 if (op_val == _customOption2value.end())
900 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
901 throw std::invalid_argument(msg);
905 std::string val = op_val->second;
906 if ( isDefault ) *isDefault = ( val.empty() );
908 if ( val.empty() && isDefault )
910 op_val = _defaultOptionValues.find( optionName );
911 if (op_val != _defaultOptionValues.end())
912 val = op_val->second;
917 //=============================================================================
918 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName,
919 bool* isDefault) const
920 throw (std::invalid_argument)
922 TOptionValues::const_iterator op_val = _preCADoption2value.find(optionName);
923 if (op_val == _preCADoption2value.end())
925 op_val = _option2value.find(optionName);
926 if (op_val == _option2value.end())
928 op_val = _customOption2value.find(optionName);
929 if (op_val == _customOption2value.end())
931 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
932 throw std::invalid_argument(msg);
936 std::string val = op_val->second;
937 if ( isDefault ) *isDefault = ( val.empty() );
939 if ( val.empty() && isDefault )
941 op_val = _defaultOptionValues.find( optionName );
942 if (op_val != _option2value.end())
943 val = op_val->second;
948 //=============================================================================
949 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
951 TOptionValues::iterator op_val = _customOption2value.find(optionName);
952 if (op_val != _customOption2value.end())
953 _customOption2value.erase(op_val);
955 op_val = _option2value.find(optionName);
956 if (op_val != _option2value.end())
957 op_val->second.clear();
959 op_val = _preCADoption2value.find(optionName);
960 if (op_val != _preCADoption2value.end())
961 op_val->second.clear();
966 //=============================================================================
967 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName)
969 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
970 if (op_val != _preCADoption2value.end())
971 op_val->second.clear();
974 //=============================================================================
975 void BLSURFPlugin_Hypothesis::AddOption(const std::string& optionName, const std::string& optionValue)
978 TOptionValues::iterator op_val = _option2value.find(optionName);
979 if (op_val != _option2value.end())
981 if (op_val->second != optionValue)
982 op_val->second = optionValue;
988 op_val = _preCADoption2value.find(optionName);
989 if (op_val != _preCADoption2value.end())
991 if (op_val->second != optionValue)
992 op_val->second = optionValue;
996 else if ( optionValue.empty() )
998 _customOption2value.erase( optionName );
1002 op_val = _customOption2value.find(optionName);
1003 if (op_val == _customOption2value.end())
1004 _customOption2value[optionName] = optionValue;
1005 else if (op_val->second != optionValue)
1006 op_val->second = optionValue;
1012 NotifySubMeshesHypothesisModification();
1015 //=============================================================================
1016 void BLSURFPlugin_Hypothesis::AddPreCADOption(const std::string& optionName, const std::string& optionValue)
1018 AddOption( optionName, optionValue );
1021 //=============================================================================
1022 std::string BLSURFPlugin_Hypothesis::GetOption(const std::string& optionName) const
1024 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1025 if (op_val != _customOption2value.end())
1026 return op_val->second;
1031 //=============================================================================
1032 std::string BLSURFPlugin_Hypothesis::GetPreCADOption(const std::string& optionName) const
1034 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1035 if (op_val != _customOption2value.end())
1036 return op_val->second;
1041 //=============================================================================
1042 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetOptionValues() const
1045 TOptionValues::const_iterator op_val = _option2value.begin();
1046 for ( ; op_val != _option2value.end(); ++op_val )
1047 vals.insert( make_pair( op_val->first, GetOptionValue( op_val->first, GET_DEFAULT() )));
1052 //=============================================================================
1053 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetPreCADOptionValues() const
1056 TOptionValues::const_iterator op_val = _preCADoption2value.begin();
1057 for ( ; op_val != _preCADoption2value.end(); ++op_val )
1058 vals.insert( make_pair( op_val->first, GetPreCADOptionValue( op_val->first, GET_DEFAULT() )));
1063 //=======================================================================
1064 //function : SetSizeMapEntry
1065 //=======================================================================
1066 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
1067 if (_sizeMap[entry].compare(sizeMap) != 0) {
1068 SetPhysicalMesh(PhysicalLocalSize);
1069 _sizeMap[entry] = sizeMap;
1070 NotifySubMeshesHypothesisModification();
1074 //=======================================================================
1075 //function : GetSizeMapEntry
1076 //=======================================================================
1077 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
1078 TSizeMap::iterator it = _sizeMap.find(entry);
1079 if (it != _sizeMap.end())
1082 return "No_Such_Entry";
1086 * \brief Return the size maps
1088 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
1089 return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
1092 //=======================================================================
1093 //function : SetAttractorEntry
1094 //=======================================================================
1095 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
1096 if (_attractors[entry].compare(attractor) != 0) {
1097 SetPhysicalMesh(PhysicalLocalSize);
1098 _attractors[entry] = attractor;
1099 NotifySubMeshesHypothesisModification();
1103 //=======================================================================
1104 //function : GetAttractorEntry
1105 //=======================================================================
1106 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
1107 TSizeMap::iterator it = _attractors.find(entry);
1108 if (it != _attractors.end())
1111 return "No_Such_Entry";
1115 * \brief Return the attractors
1117 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
1118 return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
1121 //=======================================================================
1122 //function : SetClassAttractorEntry
1123 //=======================================================================
1124 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
1126 SetPhysicalMesh(PhysicalLocalSize);
1128 // The new attractor can't be defined on the same face as another sizemap
1129 TSizeMap::iterator it = _sizeMap.find( entry );
1130 if ( it != _sizeMap.end() ) {
1132 NotifySubMeshesHypothesisModification();
1135 TSizeMap::iterator itAt = _attractors.find( entry );
1136 if ( itAt != _attractors.end() ) {
1137 _attractors.erase(itAt);
1138 NotifySubMeshesHypothesisModification();
1142 const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
1143 const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
1144 TAttractorMap::iterator attIt = _classAttractors.find(entry);
1145 for ( ; attIt != _classAttractors.end(); ++attIt )
1146 if ( attIt->first == entry &&
1147 attIt->second->GetAttractorEntry() == attEntry )
1149 bool attExists = (attIt != _classAttractors.end());
1151 BLSURFPlugin_Attractor* myAttractor;
1153 myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 );
1154 _classAttractors.insert( make_pair( entry, myAttractor ));
1157 myAttractor = attIt->second;
1159 // if (!myAttractor->IsMapBuilt())
1160 // myAttractor->BuildMap();
1161 myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
1163 NotifySubMeshesHypothesisModification();
1166 //=======================================================================
1167 //function : SetConstantSizeOnAdjacentFaces
1168 //=======================================================================
1169 // TODO uncomment and test (include the needed .hxx)
1170 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist ) {
1171 // TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
1172 // TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
1173 // TopTools_IndexedMapOfShapListOdShape::iterator it;
1174 // for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
1175 // SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
1183 //=======================================================================
1184 //function : GetClassAttractorEntry
1185 //=======================================================================
1186 // BLSURFPlugin_Attractor& BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
1188 // TAttractorMap::iterator it = _classAttractors.find( entry );
1189 // if ( it != _classAttractors.end() )
1190 // return it->second;
1192 // return "No_Such_Entry";
1196 * \brief Return the map of attractor instances
1198 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
1200 return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
1203 //=======================================================================
1204 //function : ClearEntry
1205 //=======================================================================
1206 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
1207 const char * attEntry/*=0*/)
1209 TSizeMap::iterator it = _sizeMap.find( entry );
1211 if ( it != _sizeMap.end() ) {
1213 NotifySubMeshesHypothesisModification();
1216 TSizeMap::iterator itAt = _attractors.find( entry );
1217 if ( itAt != _attractors.end() ) {
1218 _attractors.erase(itAt);
1219 NotifySubMeshesHypothesisModification();
1222 TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
1223 if ( it_clAt != _classAttractors.end() ) {
1225 if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
1226 _classAttractors.erase( it_clAt++ );
1230 while ( it_clAt != _classAttractors.end() );
1231 MESSAGE("_classAttractors.size() = "<<_classAttractors.size())
1232 NotifySubMeshesHypothesisModification();
1235 std::cout<<"No_Such_Entry"<<std::endl;
1240 //=======================================================================
1241 //function : ClearSizeMaps
1242 //=======================================================================
1243 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
1245 _attractors.clear();
1246 _classAttractors.clear();
1249 // Enable internal enforced vertices on specific face if requested by user
1251 ////=======================================================================
1252 ////function : SetInternalEnforcedVertex
1253 ////=======================================================================
1254 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
1255 // bool toEnforceInternalVertices,
1256 // TEnfGroupName theGroupName) {
1258 // MESSAGE("BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex("<< theFaceEntry << ", "
1259 // << toEnforceInternalVertices << ", " << theGroupName << ")");
1261 // TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
1262 // if (it != _faceEntryInternalVerticesList.end()) {
1263 // if (!toEnforceInternalVertices) {
1264 // _faceEntryInternalVerticesList.erase(it);
1268 // if (toEnforceInternalVertices) {
1269 // _faceEntryInternalVerticesList.insert(theFaceEntry);
1274 // // Take care of groups
1278 //=======================================================================
1279 //function : SetEnforcedVertex
1280 //=======================================================================
1281 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
1282 TEnfGroupName theGroupName, double x, double y, double z) {
1284 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
1285 << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
1287 SetPhysicalMesh(PhysicalLocalSize);
1289 // TEnfVertexList::iterator it;
1290 bool toNotify = false;
1291 bool toCreate = true;
1293 TEnfVertex *oldEnVertex;
1294 TEnfVertex *newEnfVertex = new TEnfVertex();
1295 newEnfVertex->name = theVertexName;
1296 newEnfVertex->geomEntry = theVertexEntry;
1297 newEnfVertex->coords.clear();
1298 if (theVertexEntry == "") {
1299 newEnfVertex->coords.push_back(x);
1300 newEnfVertex->coords.push_back(y);
1301 newEnfVertex->coords.push_back(z);
1303 newEnfVertex->grpName = theGroupName;
1304 newEnfVertex->faceEntries.clear();
1305 newEnfVertex->faceEntries.insert(theFaceEntry);
1308 // update _enfVertexList
1309 TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
1310 if (it != _enfVertexList.end()) {
1312 oldEnVertex = (*it);
1313 MESSAGE("Enforced Vertex was found => Update");
1314 if (oldEnVertex->name != theVertexName) {
1315 MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
1316 oldEnVertex->name = theVertexName;
1319 if (oldEnVertex->grpName != theGroupName) {
1320 MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
1321 oldEnVertex->grpName = theGroupName;
1324 TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
1325 if (it_faceEntries == oldEnVertex->faceEntries.end()) {
1326 MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
1327 oldEnVertex->faceEntries.insert(theFaceEntry);
1328 _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
1332 // update map coords / enf vertex if needed
1333 if (oldEnVertex->coords.size()) {
1334 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
1335 _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
1338 // update map geom entry / enf vertex if needed
1339 if (oldEnVertex->geomEntry != "") {
1340 _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
1341 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
1346 // //////// CREATE ////////////
1349 MESSAGE("Creating new enforced vertex");
1350 _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
1351 _enfVertexList.insert(newEnfVertex);
1352 if (theVertexEntry == "") {
1353 _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
1354 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
1357 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
1358 _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
1363 NotifySubMeshesHypothesisModification();
1365 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
1370 //=======================================================================
1371 //function : GetEnforcedVertices
1372 //=======================================================================
1374 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
1375 throw (std::invalid_argument) {
1377 if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
1378 return _faceEntryEnfVertexListMap[theFaceEntry];
1380 return GetDefaultEnfVertexList();
1382 std::ostringstream msg;
1383 msg << "No enforced vertex for face entry " << theFaceEntry;
1384 throw std::invalid_argument(msg.str());
1387 //=======================================================================
1388 //function : GetEnfVertexCoordsList
1389 //=======================================================================
1391 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
1392 const TEntry& theFaceEntry) throw (std::invalid_argument) {
1394 if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
1395 return _faceEntryCoordsListMap[theFaceEntry];
1397 std::ostringstream msg;
1398 msg << "No enforced vertex coords for face entry " << theFaceEntry;
1399 throw std::invalid_argument(msg.str());
1402 //=======================================================================
1403 //function : GetEnfVertexEntryList
1404 //=======================================================================
1406 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
1407 throw (std::invalid_argument) {
1409 if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
1410 return _faceEntryEnfVertexEntryListMap[theFaceEntry];
1412 std::ostringstream msg;
1413 msg << "No enforced vertex entry for face entry " << theFaceEntry;
1414 throw std::invalid_argument(msg.str());
1417 //=======================================================================
1418 //function : GetEnfVertex(TEnfVertexCoords coords)
1419 //=======================================================================
1421 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
1422 throw (std::invalid_argument) {
1424 if (_coordsEnfVertexMap.count(coords) > 0)
1425 return _coordsEnfVertexMap[coords];
1427 std::ostringstream msg;
1428 msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
1429 throw std::invalid_argument(msg.str());
1432 //=======================================================================
1433 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
1434 //=======================================================================
1436 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
1437 throw (std::invalid_argument) {
1439 if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
1440 return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
1442 std::ostringstream msg;
1443 msg << "No enforced vertex with entry " << theEnfVertexEntry;
1444 throw std::invalid_argument(msg.str());
1447 //Enable internal enforced vertices on specific face if requested by user
1448 ////=======================================================================
1449 ////function : GetInternalEnforcedVertex
1450 ////=======================================================================
1452 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
1454 // if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
1459 //=======================================================================
1460 //function : ClearEnforcedVertex
1461 //=======================================================================
1463 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
1464 const TEntry& theVertexEntry) throw (std::invalid_argument) {
1466 bool toNotify = false;
1467 std::ostringstream msg;
1468 TEnfVertex *oldEnfVertex;
1469 TEnfVertexCoords coords;
1471 coords.push_back(x);
1472 coords.push_back(y);
1473 coords.push_back(z);
1475 // check that enf vertex with given enf vertex entry exists
1476 TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
1477 if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
1479 MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
1480 oldEnfVertex = it_enfVertexEntry->second;
1482 _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
1484 TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
1485 enfVertexEntryList.erase(theVertexEntry);
1486 if (enfVertexEntryList.size() == 0)
1487 _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
1488 // TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1489 // TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
1490 // it_entry_entry->second.erase(it_entryList);
1491 // if (it_entry_entry->second.size() == 0)
1492 // _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1495 MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
1496 msg << "No enforced vertex with geom entry " << theVertexEntry;
1497 // check that enf vertex with given coords exists
1498 TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
1499 if (it_coords_enf != _coordsEnfVertexMap.end()) {
1501 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
1502 oldEnfVertex = it_coords_enf->second;
1504 _coordsEnfVertexMap.erase(it_coords_enf);
1506 TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
1507 enfVertexCoordsList.erase(coords);
1508 if (enfVertexCoordsList.size() == 0)
1509 _faceEntryCoordsListMap.erase(theFaceEntry);
1510 // TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1511 // TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
1512 // it_entry_coords->second.erase(it_coordsList);
1513 // if (it_entry_coords->second.size() == 0)
1514 // _faceEntryCoordsListMap.erase(it_entry_coords);
1517 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
1519 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
1520 throw std::invalid_argument(msg.str());
1524 MESSAGE("Remove enf vertex from _enfVertexList");
1526 // update _enfVertexList
1527 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1528 if (it != _enfVertexList.end()) {
1529 (*it)->faceEntries.erase(theFaceEntry);
1530 if ((*it)->faceEntries.size() == 0){
1531 _enfVertexList.erase(it);
1537 // update _faceEntryEnfVertexListMap
1538 TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
1539 currentEnfVertexList.erase(oldEnfVertex);
1541 if (currentEnfVertexList.size() == 0) {
1542 MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
1543 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1548 NotifySubMeshesHypothesisModification();
1553 //=======================================================================
1554 //function : ClearEnforcedVertices
1555 //=======================================================================
1557 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
1559 bool toNotify = false;
1560 TEnfVertex *oldEnfVertex;
1562 TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1563 if (it_entry_coords != _faceEntryCoordsListMap.end()) {
1565 TEnfVertexCoordsList coordsList = it_entry_coords->second;
1566 TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
1567 for (; it_coordsList != coordsList.end(); ++it_coordsList) {
1568 TEnfVertexCoords coords = (*it_coordsList);
1569 oldEnfVertex = _coordsEnfVertexMap[coords];
1570 _coordsEnfVertexMap.erase(coords);
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 _faceEntryCoordsListMap.erase(it_entry_coords);
1583 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1586 TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1587 if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
1589 TEntryList enfVertexEntryList = it_entry_entry->second;
1590 TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
1591 for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
1592 TEntry enfVertexEntry = (*it_enfVertexEntryList);
1593 oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
1594 _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
1595 // update _enfVertexList
1596 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1597 if (it != _enfVertexList.end()) {
1598 (*it)->faceEntries.erase(theFaceEntry);
1599 if ((*it)->faceEntries.size() == 0){
1600 _enfVertexList.erase(it);
1606 _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1607 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1611 NotifySubMeshesHypothesisModification();
1614 // std::ostringstream msg;
1615 // msg << "No enforced vertex for " << theFaceEntry;
1616 // throw std::invalid_argument(msg.str());
1619 //=======================================================================
1620 //function : ClearAllEnforcedVertices
1621 //=======================================================================
1622 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
1623 _faceEntryEnfVertexListMap.clear();
1624 _enfVertexList.clear();
1625 _faceEntryCoordsListMap.clear();
1626 _coordsEnfVertexMap.clear();
1627 _faceEntryEnfVertexEntryListMap.clear();
1628 _enfVertexEntryEnfVertexMap.clear();
1629 // Enable internal enforced vertices on specific face if requested by user
1630 // _faceEntryInternalVerticesList.clear();
1631 NotifySubMeshesHypothesisModification();
1634 //================================================================================
1636 * \brief Return the enforced vertices
1638 //================================================================================
1641 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1642 const BLSURFPlugin_Hypothesis* hyp) {
1643 return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1646 //Enable internal enforced vertices on specific face if requested by user
1647 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1648 // const BLSURFPlugin_Hypothesis* hyp) {
1649 // return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1652 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1654 return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1657 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1659 return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1662 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1663 const BLSURFPlugin_Hypothesis* hyp) {
1664 return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1667 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1668 const BLSURFPlugin_Hypothesis* hyp) {
1669 return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1672 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1673 const BLSURFPlugin_Hypothesis* hyp) {
1674 return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1677 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1678 const BLSURFPlugin_Hypothesis* hyp) {
1679 return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1682 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1683 const BLSURFPlugin_Hypothesis* hyp) {
1684 return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1687 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1689 TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1690 if (it != _groupNameNodeIDMap.end()) {
1693 std::ostringstream msg;
1694 msg << "No group " << theGroupName;
1695 throw std::invalid_argument(msg.str());
1698 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1700 _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1703 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1705 TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1706 if (it != _groupNameNodeIDMap.end()) {
1707 std::set<int>::iterator IDit = it->second.find(theNodeID);
1708 if (IDit != it->second.end())
1709 it->second.erase(IDit);
1710 std::ostringstream msg;
1711 msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1712 throw std::invalid_argument(msg.str());
1714 std::ostringstream msg;
1715 msg << "No group " << theGroupName;
1716 throw std::invalid_argument(msg.str());
1720 //=============================================================================
1721 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1722 if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1723 _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1724 if (toEnforceInternalVertices)
1725 SetPhysicalMesh(PhysicalLocalSize);
1726 NotifySubMeshesHypothesisModification();
1731 //=============================================================================
1732 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1733 if (std::string(theGroupName) != std::string(_enforcedInternalVerticesAllFacesGroup)) {
1734 _enforcedInternalVerticesAllFacesGroup = theGroupName;
1735 NotifySubMeshesHypothesisModification();
1739 //=============================================================================
1740 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
1741 const BLSURFPlugin_Hypothesis* hyp) {
1742 return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
1745 //=============================================================================
1746 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
1747 const BLSURFPlugin_Hypothesis* hyp) {
1748 return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
1751 //=============================================================================
1752 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
1753 const BLSURFPlugin_Hypothesis* hyp) {
1754 return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
1757 //=============================================================================
1758 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
1759 const BLSURFPlugin_Hypothesis* hyp){
1760 return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
1763 //=============================================================================
1764 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
1765 const BLSURFPlugin_Hypothesis* hyp){
1766 return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
1769 //=======================================================================
1770 //function : ClearAllEnforcedVertices
1771 //=======================================================================
1772 void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
1773 _preCadFacesPeriodicityVector.clear();
1774 _preCadEdgesPeriodicityVector.clear();
1775 NotifySubMeshesHypothesisModification();
1778 //=======================================================================
1779 //function : AddPreCadFacesPeriodicity
1780 //=======================================================================
1781 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
1782 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1784 TPreCadPeriodicity preCadFacesPeriodicity;
1785 preCadFacesPeriodicity.shape1Entry = theFace1Entry;
1786 preCadFacesPeriodicity.shape2Entry = theFace2Entry;
1787 preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1788 preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1790 _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
1792 NotifySubMeshesHypothesisModification();
1795 //=======================================================================
1796 //function : AddPreCadEdgesPeriodicity
1797 //=======================================================================
1798 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
1799 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1801 TPreCadPeriodicity preCadEdgesPeriodicity;
1802 preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
1803 preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
1804 preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1805 preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1807 _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
1809 NotifySubMeshesHypothesisModification();
1812 //=============================================================================
1813 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
1814 // We must keep at least the same number of arguments when increasing the SALOME version
1815 // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
1816 // parameter can be written several times to keep the old global number of parameters.
1818 // Treat old options which are now in the advanced options
1819 TOptionValues::iterator op_val;
1821 int _preCADRemoveNanoEdges = -1;
1822 double _preCADEpsNano = -1.0;
1823 op_val = _option2value.find("respect_geometry");
1824 if (op_val != _option2value.end()) {
1825 std::string value = op_val->second;
1827 _decimesh = value.compare("1") == 0 ? 1 : 0;
1829 op_val = _preCADoption2value.find("remove_tiny_edges");
1830 if (op_val != _preCADoption2value.end()) {
1831 std::string value = op_val->second;
1833 _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
1835 op_val = _preCADoption2value.find("tiny_edge_length");
1836 if (op_val != _preCADoption2value.end()) {
1837 std::string value = op_val->second;
1839 _preCADEpsNano = strtod(value.c_str(), NULL);
1842 save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1843 << _angleMesh << " " << _gradation << " " << (int) _quadAllowed << " " << _decimesh;
1844 save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
1845 save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1846 save << " " << (int) _enforcedInternalVerticesAllFaces;
1847 save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
1848 save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
1849 save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
1850 save << " " << (int) _preCADProcess3DTopology << " " << (int) _preCADRemoveDuplicateCADFaces << " " << (int) _preCADRemoveTinyUVEdges;
1851 save << " " << (int)_optimiseTinyEdges << " " << _tinyEdgeOptimisationLength;
1852 save << " " << (int)_correctSurfaceIntersec << " " << _corrSurfaceIntersCost;
1853 save << " " << (int)_useGradation << " " << (int)_useVolumeGradation << " " << _volumeGradation;
1855 op_val = _option2value.begin();
1856 if (op_val != _option2value.end()) {
1857 save << " " << "__OPTIONS_BEGIN__";
1858 for (; op_val != _option2value.end(); ++op_val) {
1859 if (!op_val->second.empty())
1860 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1862 save << " " << "__OPTIONS_END__";
1865 op_val = _customOption2value.begin();
1866 if (op_val != _customOption2value.end()) {
1867 save << " " << "__CUSTOM_OPTIONS_BEGIN__";
1868 for (; op_val != _customOption2value.end(); ++op_val) {
1869 if (!op_val->second.empty())
1870 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1872 save << " " << "__CUSTOM_OPTIONS_END__";
1875 op_val = _preCADoption2value.begin();
1876 if (op_val != _preCADoption2value.end()) {
1877 save << " " << "__PRECAD_OPTIONS_BEGIN__";
1878 for (; op_val != _preCADoption2value.end(); ++op_val) {
1879 if (!op_val->second.empty())
1880 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1882 save << " " << "__PRECAD_OPTIONS_END__";
1885 TSizeMap::iterator it_sm = _sizeMap.begin();
1886 if (it_sm != _sizeMap.end()) {
1887 save << " " << "__SIZEMAP_BEGIN__";
1888 for (; it_sm != _sizeMap.end(); ++it_sm) {
1889 save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
1891 save << " " << "__SIZEMAP_END__";
1894 TSizeMap::iterator it_at = _attractors.begin();
1895 if (it_at != _attractors.end()) {
1896 save << " " << "__ATTRACTORS_BEGIN__";
1897 for (; it_at != _attractors.end(); ++it_at) {
1898 save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
1900 save << " " << "__ATTRACTORS_END__";
1903 TAttractorMap::iterator it_At = _classAttractors.begin();
1904 if (it_At != _classAttractors.end()) {
1905 std::ostringstream test;
1906 save << " " << "__NEW_ATTRACTORS_BEGIN__";
1907 test << " " << "__NEW_ATTRACTORS_BEGIN__";
1908 for (; it_At != _classAttractors.end(); ++it_At) {
1909 std::vector<double> attParams;
1910 attParams = it_At->second->GetParameters();
1911 // double step = it_At->second->GetStep();
1912 save << " " << it_At->first;
1913 save << " " << it_At->second->GetAttractorEntry();
1914 save << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1915 // save << " " << step;
1916 test << " " << it_At->first;
1917 test << " " << it_At->second->GetAttractorEntry();
1918 test << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1919 // test << " " << step;
1921 save << " " << "__NEW_ATTRACTORS_END__";
1922 test << " " << "__NEW_ATTRACTORS_END__";
1923 MESSAGE(" Attractor hypothesis saved as "<<test.str())
1926 TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
1927 if (it_enf != _enfVertexList.end()) {
1928 save << " " << "__ENFORCED_VERTICES_BEGIN__";
1929 for (; it_enf != _enfVertexList.end(); ++it_enf) {
1930 TEnfVertex *enfVertex = (*it_enf);
1931 save << " " << "__BEGIN_VERTEX__";
1932 if (!enfVertex->name.empty()) {
1933 save << " " << "__BEGIN_NAME__";
1934 save << " " << enfVertex->name;
1935 save << " " << "__END_NAME__";
1937 if (!enfVertex->geomEntry.empty()) {
1938 save << " " << "__BEGIN_ENTRY__";
1939 save << " " << enfVertex->geomEntry;
1940 save << " " << "__END_ENTRY__";
1942 if (!enfVertex->grpName.empty()) {
1943 save << " " << "__BEGIN_GROUP__";
1944 save << " " << enfVertex->grpName;
1945 save << " " << "__END_GROUP__";
1947 if (enfVertex->coords.size()) {
1948 save << " " << "__BEGIN_COORDS__";
1949 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1950 save << " " << enfVertex->coords[i];
1951 save << " " << "__END_COORDS__";
1953 TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
1954 bool hasFaces = false;
1955 if (faceEntriesIt != enfVertex->faceEntries.end()) {
1957 save << " " << "__BEGIN_FACELIST__";
1959 for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
1960 save << " " << (*faceEntriesIt);
1962 save << " " << "__END_FACELIST__";
1963 save << " " << "__END_VERTEX__";
1965 save << " " << "__ENFORCED_VERTICES_END__";
1970 SavePreCADPeriodicity(save, "FACES");
1971 SavePreCADPeriodicity(save, "EDGES");
1973 SaveFacesPeriodicity(save);
1974 SaveEdgesPeriodicity(save);
1975 SaveVerticesPeriodicity(save);
1980 void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
1982 TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
1983 if (it_faces_periodicity != _facesPeriodicityVector.end()) {
1984 MESSAGE("__FACES_PERIODICITY_BEGIN__");
1985 save << " " << "__FACES_PERIODICITY_BEGIN__";
1986 for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
1987 TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
1988 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1989 save << " " << "__BEGIN_ENTRY1__";
1990 save << " " << periodicity_i.first;
1991 save << " " << "__END_ENTRY1__";
1992 save << " " << "__BEGIN_ENTRY2__";
1993 save << " " << periodicity_i.second;
1994 save << " " << "__END_ENTRY2__";
1995 save << " " << "__END_PERIODICITY_DESCRIPTION__";
1997 save << " " << "__FACES_PERIODICITY_END__";
1998 MESSAGE("__FACES_PERIODICITY_END__");
2002 void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
2004 TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
2005 if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
2006 save << " " << "__EDGES_PERIODICITY_BEGIN__";
2007 MESSAGE("__EDGES_PERIODICITY_BEGIN__");
2008 for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
2009 TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
2010 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2011 if (! periodicity_i.theFace1Entry.empty()){
2012 save << " " << "__BEGIN_FACE1__";
2013 save << " " << periodicity_i.theFace1Entry;
2014 save << " " << "__END_FACE1__";
2016 save << " " << "__BEGIN_EDGE1__";
2017 save << " " << periodicity_i.theEdge1Entry;
2018 save << " " << "__END_EDGE1__";
2019 if (! periodicity_i.theFace2Entry.empty()){
2020 save << " " << "__BEGIN_FACE2__";
2021 save << " " << periodicity_i.theFace2Entry;
2022 save << " " << "__END_FACE2__";
2024 save << " " << "__BEGIN_EDGE2__";
2025 save << " " << periodicity_i.theEdge2Entry;
2026 save << " " << "__END_EDGE2__";
2027 save << " " << "__BEGIN_EDGE_ORIENTATION__";
2028 save << " " << periodicity_i.edge_orientation;
2029 save << " " << "__END_EDGE_ORIENTATION__";
2030 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2032 save << " " << "__EDGES_PERIODICITY_END__";
2033 MESSAGE("__EDGES_PERIODICITY_END__");
2037 void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save){
2039 TVerticesPeriodicityVector::const_iterator it_vertices_periodicity = _verticesPeriodicityVector.begin();
2040 if (it_vertices_periodicity != _verticesPeriodicityVector.end()) {
2041 MESSAGE("__VERTICES_PERIODICITY_BEGIN__");
2042 save << " " << "__VERTICES_PERIODICITY_BEGIN__";
2043 for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
2044 TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
2045 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2046 save << " " << "__BEGIN_EDGE1__";
2047 save << " " << periodicity_i.theEdge1Entry;
2048 save << " " << "__END_EDGE1__";
2049 save << " " << "__BEGIN_VERTEX1__";
2050 save << " " << periodicity_i.theVertex1Entry;
2051 save << " " << "__END_VERTEX1__";
2052 save << " " << "__BEGIN_EDGE2__";
2053 save << " " << periodicity_i.theEdge2Entry;
2054 save << " " << "__END_EDGE2__";
2055 save << " " << "__BEGIN_VERTEX2__";
2056 save << " " << periodicity_i.theVertex2Entry;
2057 save << " " << "__END_VERTEX2__";
2058 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2060 save << " " << "__VERTICES_PERIODICITY_END__";
2061 MESSAGE("__VERTICES_PERIODICITY_END__");
2065 void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType) {
2066 TPreCadPeriodicityVector precad_periodicity;
2067 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
2068 precad_periodicity = _preCadFacesPeriodicityVector;
2070 precad_periodicity = _preCadEdgesPeriodicityVector;
2071 TPreCadPeriodicityVector::const_iterator it_precad_periodicity = precad_periodicity.begin();
2072 if (it_precad_periodicity != precad_periodicity.end()) {
2073 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_BEGIN__";
2074 for (; it_precad_periodicity != precad_periodicity.end(); ++it_precad_periodicity) {
2075 TPreCadPeriodicity periodicity_i = (*it_precad_periodicity);
2076 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2077 if (!periodicity_i.shape1Entry.empty()) {
2078 save << " " << "__BEGIN_ENTRY1__";
2079 save << " " << periodicity_i.shape1Entry;
2080 save << " " << "__END_ENTRY1__";
2082 if (!periodicity_i.shape2Entry.empty()) {
2083 save << " " << "__BEGIN_ENTRY2__";
2084 save << " " << periodicity_i.shape2Entry;
2085 save << " " << "__END_ENTRY2__";
2088 std::vector<std::string>::const_iterator sourceVerticesEntriesIt = periodicity_i.theSourceVerticesEntries.begin();
2089 bool hasSourceVertices = false;
2090 if (sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end()) {
2091 hasSourceVertices = true;
2092 save << " " << "__BEGIN_SOURCE_VERTICES_LIST__";
2094 for (; sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end(); ++sourceVerticesEntriesIt)
2095 save << " " << (*sourceVerticesEntriesIt);
2096 if (hasSourceVertices)
2097 save << " " << "__END_SOURCE_VERTICES_LIST__";
2099 std::vector<std::string>::const_iterator targetVerticesEntriesIt = periodicity_i.theTargetVerticesEntries.begin();
2100 bool hasTargetVertices = false;
2101 if (targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end()) {
2102 hasTargetVertices = true;
2103 save << " " << "__BEGIN_TARGET_VERTICES_LIST__";
2105 for (; targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end(); ++targetVerticesEntriesIt)
2106 save << " " << (*targetVerticesEntriesIt);
2107 if (hasTargetVertices)
2108 save << " " << "__END_TARGET_VERTICES_LIST__";
2110 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2112 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_END__";
2117 //=============================================================================
2118 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
2122 std::string option_or_sm;
2124 isOK = static_cast<bool>(load >> i);
2126 _topology = (Topology) i;
2128 load.clear(std::ios::badbit | load.rdstate());
2130 isOK = static_cast<bool>(load >> i);
2132 _physicalMesh = (PhysicalMesh) i;
2134 load.clear(std::ios::badbit | load.rdstate());
2136 isOK = static_cast<bool>(load >> i);
2138 _geometricMesh = (GeometricMesh) i;
2140 load.clear(std::ios::badbit | load.rdstate());
2142 isOK = static_cast<bool>(load >> val);
2146 load.clear(std::ios::badbit | load.rdstate());
2148 isOK = static_cast<bool>(load >> val);
2152 load.clear(std::ios::badbit | load.rdstate());
2154 isOK = static_cast<bool>(load >> val);
2158 load.clear(std::ios::badbit | load.rdstate());
2160 isOK = static_cast<bool>(load >> i);
2162 _quadAllowed = (bool) i;
2164 load.clear(std::ios::badbit | load.rdstate());
2166 isOK = static_cast<bool>(load >> i);
2168 if ( i != -1) { // if value is -1, then this is no longer a standard option
2169 std::string & value = _option2value["respect_geometry"];
2170 bool _decimesh = (bool) i;
2171 value = _decimesh ? "1" : "0";
2175 load.clear(std::ios::badbit | load.rdstate());
2177 isOK = static_cast<bool>(load >> val);
2181 load.clear(std::ios::badbit | load.rdstate());
2183 isOK = static_cast<bool>(load >> val);
2187 load.clear(std::ios::badbit | load.rdstate());
2189 isOK = static_cast<bool>(load >> val);
2191 // former parameter: get min value
2192 _angleMesh = std::min(val,_angleMesh);
2194 load.clear(std::ios::badbit | load.rdstate());
2196 isOK = static_cast<bool>(load >> val);
2198 // former parameter: get min value
2199 _minSize = std::min(val,_minSize);
2201 load.clear(std::ios::badbit | load.rdstate());
2203 isOK = static_cast<bool>(load >> val);
2205 // former parameter: get max value
2206 _maxSize = std::max(val,_maxSize);
2208 load.clear(std::ios::badbit | load.rdstate());
2210 isOK = static_cast<bool>(load >> i);
2214 load.clear(std::ios::badbit | load.rdstate());
2216 isOK = static_cast<bool>(load >> i);
2218 _preCADMergeEdges = (bool) i;
2220 load.clear(std::ios::badbit | load.rdstate());
2222 isOK = static_cast<bool>(load >> i);
2224 if ( i != -1) { // if value is -1, then this is no longer a standard option
2225 std::string & value = _preCADoption2value["remove_tiny_edges"];
2226 bool _preCADRemoveNanoEdges = (bool) i;
2227 value = _preCADRemoveNanoEdges ? "1" : "0";
2231 load.clear(std::ios::badbit | load.rdstate());
2233 isOK = static_cast<bool>(load >> i);
2235 _preCADDiscardInput = (bool) i;
2237 load.clear(std::ios::badbit | load.rdstate());
2239 isOK = static_cast<bool>(load >> val);
2240 if (isOK) { // _preCADEpsNano
2241 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
2242 std::string & value = _preCADoption2value["tiny_edge_length"];
2243 std::ostringstream oss;
2249 load.clear(std::ios::badbit | load.rdstate());
2251 isOK = static_cast<bool>(load >> i);
2253 _enforcedInternalVerticesAllFaces = (bool) i;
2255 load.clear(std::ios::badbit | load.rdstate());
2257 // New options with MeshGems-CADSurf
2259 bool hasCADSurfOptions = false;
2260 bool hasOptions = false;
2261 bool hasCustomOptions = false;
2262 bool hasPreCADOptions = false;
2263 bool hasSizeMap = false;
2264 bool hasAttractor = false;
2265 bool hasNewAttractor = false;
2266 bool hasEnforcedVertex = false;
2267 bool hasPreCADFacesPeriodicity = false;
2268 bool hasPreCADEdgesPeriodicity = false;
2269 bool hasFacesPeriodicity = false;
2270 bool hasEdgesPeriodicity = false;
2271 bool hasVerticesPeriodicity = false;
2273 isOK = static_cast<bool>(load >> option_or_sm);
2275 if ( (option_or_sm == "1")||(option_or_sm == "0") ) {
2276 i = atoi(option_or_sm.c_str());
2277 hasCADSurfOptions = true;
2278 _phySizeRel = (bool) i;
2280 if (option_or_sm == "__OPTIONS_BEGIN__")
2282 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2283 hasCustomOptions = true;
2284 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2285 hasPreCADOptions = true;
2286 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2288 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2289 hasAttractor = true;
2290 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2291 hasNewAttractor = true;
2292 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2293 hasEnforcedVertex = true;
2294 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2295 hasPreCADFacesPeriodicity = true;
2296 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2297 hasPreCADEdgesPeriodicity = true;
2298 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2299 hasFacesPeriodicity = true;
2300 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2301 hasEdgesPeriodicity = true;
2302 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2303 hasVerticesPeriodicity = true;
2305 if (isOK && hasCADSurfOptions) {
2306 isOK = static_cast<bool>(load >> i);
2308 _minSizeRel = (bool) i;
2310 load.clear(std::ios::badbit | load.rdstate());
2312 isOK = static_cast<bool>(load >> i);
2314 _maxSizeRel = (bool) i;
2316 load.clear(std::ios::badbit | load.rdstate());
2318 isOK = static_cast<bool>(load >> val);
2320 _chordalError = val;
2322 load.clear(std::ios::badbit | load.rdstate());
2324 isOK = static_cast<bool>(load >> i);
2326 _anisotropic = (bool) i;
2328 load.clear(std::ios::badbit | load.rdstate());
2330 isOK = static_cast<bool>(load >> val);
2332 _anisotropicRatio = val;
2334 load.clear(std::ios::badbit | load.rdstate());
2336 isOK = static_cast<bool>(load >> i);
2338 _removeTinyEdges = (bool) i;
2340 load.clear(std::ios::badbit | load.rdstate());
2342 isOK = static_cast<bool>(load >> val);
2344 _tinyEdgeLength = val;
2346 load.clear(std::ios::badbit | load.rdstate());
2348 isOK = static_cast<bool>(load >> i);
2350 _badElementRemoval = (bool) i;
2352 load.clear(std::ios::badbit | load.rdstate());
2354 isOK = static_cast<bool>(load >> val);
2356 _badElementAspectRatio = val;
2358 load.clear(std::ios::badbit | load.rdstate());
2360 isOK = static_cast<bool>(load >> i);
2362 _optimizeMesh = (bool) i;
2364 load.clear(std::ios::badbit | load.rdstate());
2366 isOK = static_cast<bool>(load >> i);
2368 _quadraticMesh = (bool) i;
2370 load.clear(std::ios::badbit | load.rdstate());
2372 isOK = static_cast<bool>(load >> i);
2374 _preCADProcess3DTopology = (bool) i;
2376 load.clear(std::ios::badbit | load.rdstate());
2378 if (( load >> std::ws).peek() != '_' )
2380 isOK = static_cast<bool>(load >> i);
2382 _preCADRemoveDuplicateCADFaces = (bool) i;
2384 load.clear(std::ios::badbit | load.rdstate());
2386 isOK = static_cast<bool>(load >> i);
2388 _preCADRemoveTinyUVEdges = (bool) i;
2390 load.clear(std::ios::badbit | load.rdstate());
2392 isOK = static_cast<bool>(load >> i);
2394 _optimiseTinyEdges = (bool) i;
2396 load.clear(std::ios::badbit | load.rdstate());
2398 isOK = static_cast<bool>(load >> val);
2400 _tinyEdgeOptimisationLength = val;
2402 load.clear(std::ios::badbit | load.rdstate());
2404 isOK = static_cast<bool>(load >> i);
2406 _correctSurfaceIntersec = (bool) i;
2408 load.clear(std::ios::badbit | load.rdstate());
2410 isOK = static_cast<bool>(load >> val);
2412 _corrSurfaceIntersCost = val;
2414 load.clear(std::ios::badbit | load.rdstate());
2416 isOK = static_cast<bool>(load >> i);
2418 _useGradation = (bool) i;
2420 load.clear(std::ios::badbit | load.rdstate());
2422 isOK = static_cast<bool>(load >> i);
2424 _useVolumeGradation = (bool) i;
2426 load.clear(std::ios::badbit | load.rdstate());
2428 isOK = static_cast<bool>(load >> val);
2430 _volumeGradation = val;
2432 load.clear(std::ios::badbit | load.rdstate());
2437 if (hasCADSurfOptions) {
2438 isOK = static_cast<bool>(load >> option_or_sm);
2440 if (option_or_sm == "__OPTIONS_BEGIN__")
2442 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2443 hasCustomOptions = true;
2444 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2445 hasPreCADOptions = true;
2446 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2448 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2449 hasAttractor = true;
2450 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2451 hasNewAttractor = true;
2452 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2453 hasEnforcedVertex = true;
2454 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2455 hasPreCADFacesPeriodicity = true;
2456 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2457 hasPreCADEdgesPeriodicity = true;
2458 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2459 hasFacesPeriodicity = true;
2460 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2461 hasEdgesPeriodicity = true;
2462 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2463 hasVerticesPeriodicity = true;
2467 std::string optName, optValue;
2468 while (isOK && hasOptions) {
2469 isOK = static_cast<bool>(load >> optName);
2471 if (optName == "__OPTIONS_END__")
2473 isOK = static_cast<bool>(load >> optValue);
2476 std::string & value = _option2value[optName];
2478 int len = value.size();
2479 // continue reading until "%#" encountered
2480 while (value[len - 1] != '#' || value[len - 2] != '%') {
2481 isOK = static_cast<bool>(load >> optValue);
2490 if ( value[ len - 1] == '#' )
2491 value.resize(len - 2); //cut off "%#"
2496 isOK = static_cast<bool>(load >> option_or_sm);
2498 if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2499 hasCustomOptions = true;
2500 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2501 hasPreCADOptions = true;
2502 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2504 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2505 hasAttractor = true;
2506 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2507 hasNewAttractor = true;
2508 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2509 hasEnforcedVertex = true;
2510 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2511 hasPreCADFacesPeriodicity = true;
2512 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2513 hasPreCADEdgesPeriodicity = true;
2514 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2515 hasFacesPeriodicity = true;
2516 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2517 hasEdgesPeriodicity = true;
2518 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2519 hasVerticesPeriodicity = true;
2523 while (isOK && hasCustomOptions) {
2524 isOK = static_cast<bool>(load >> optName);
2526 if (optName == "__CUSTOM_OPTIONS_END__")
2528 isOK = static_cast<bool>(load >> optValue);
2531 std::string& value = optValue;
2532 int len = value.size();
2533 // continue reading until "%#" encountered
2534 while (value[len - 1] != '#' || value[len - 2] != '%') {
2535 isOK = static_cast<bool>(load >> optValue);
2544 if ( value[ len - 1] == '#' )
2545 value.resize(len - 2); //cut off "%#"
2546 _customOption2value[optName] = value;
2550 if (hasCustomOptions) {
2551 isOK = static_cast<bool>(load >> option_or_sm);
2553 if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2554 hasPreCADOptions = true;
2555 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2557 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2558 hasAttractor = true;
2559 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2560 hasNewAttractor = true;
2561 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2562 hasEnforcedVertex = true;
2563 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2564 hasPreCADFacesPeriodicity = true;
2565 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2566 hasPreCADEdgesPeriodicity = true;
2567 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2568 hasFacesPeriodicity = true;
2569 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2570 hasEdgesPeriodicity = true;
2571 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2572 hasVerticesPeriodicity = true;
2576 while (isOK && hasPreCADOptions) {
2577 isOK = static_cast<bool>(load >> optName);
2579 if (optName == "__PRECAD_OPTIONS_END__")
2581 isOK = static_cast<bool>(load >> optValue);
2584 std::string & value = _preCADoption2value[optName];
2586 int len = value.size();
2587 // continue reading until "%#" encountered
2588 while (value[len - 1] != '#' || value[len - 2] != '%') {
2589 isOK = static_cast<bool>(load >> optValue);
2598 if ( value[ len - 1] == '#' )
2599 value.resize(len - 2); //cut off "%#"
2603 if (hasPreCADOptions) {
2604 isOK = static_cast<bool>(load >> option_or_sm);
2606 if (option_or_sm == "__SIZEMAP_BEGIN__")
2608 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2609 hasAttractor = true;
2610 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2611 hasNewAttractor = true;
2612 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2613 hasEnforcedVertex = true;
2614 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2615 hasPreCADFacesPeriodicity = true;
2616 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2617 hasPreCADEdgesPeriodicity = true;
2618 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2619 hasFacesPeriodicity = true;
2620 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2621 hasEdgesPeriodicity = true;
2622 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2623 hasVerticesPeriodicity = true;
2627 std::string smEntry, smValue;
2628 while (isOK && hasSizeMap) {
2629 isOK = static_cast<bool>(load >> smEntry);
2631 if (smEntry == "__SIZEMAP_END__")
2633 isOK = static_cast<bool>(load >> smValue);
2636 std::string & value2 = _sizeMap[smEntry];
2638 int len2 = value2.size();
2639 // continue reading until "%#" encountered
2640 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2641 isOK = static_cast<bool>(load >> smValue);
2645 len2 = value2.size();
2650 value2.resize(len2 - 2); //cut off "%#"
2655 isOK = static_cast<bool>(load >> option_or_sm);
2657 if (option_or_sm == "__ATTRACTORS_BEGIN__")
2658 hasAttractor = true;
2659 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2660 hasNewAttractor = true;
2661 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2662 hasEnforcedVertex = true;
2663 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2664 hasPreCADFacesPeriodicity = true;
2665 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2666 hasPreCADEdgesPeriodicity = true;
2667 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2668 hasFacesPeriodicity = true;
2669 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2670 hasEdgesPeriodicity = true;
2671 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2672 hasVerticesPeriodicity = true;
2675 std::string atEntry, atValue;
2676 while (isOK && hasAttractor) {
2677 isOK = static_cast<bool>(load >> atEntry);
2679 if (atEntry == "__ATTRACTORS_END__")
2681 isOK = static_cast<bool>(load >> atValue);
2684 std::string & value3 = _attractors[atEntry];
2686 int len3 = value3.size();
2687 // continue reading until "%#" encountered
2688 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
2689 isOK = static_cast<bool>(load >> atValue);
2693 len3 = value3.size();
2698 value3.resize(len3 - 2); //cut off "%#"
2703 isOK = static_cast<bool>(load >> option_or_sm);
2705 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2706 hasNewAttractor = true;
2707 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2708 hasEnforcedVertex = true;
2709 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2710 hasPreCADFacesPeriodicity = true;
2711 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2712 hasPreCADEdgesPeriodicity = true;
2713 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2714 hasFacesPeriodicity = true;
2715 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2716 hasEdgesPeriodicity = true;
2717 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2718 hasVerticesPeriodicity = true;
2722 std::string newAtFaceEntry, atTestString;
2723 std::string newAtShapeEntry;
2724 double attParams[4];
2726 while (isOK && hasNewAttractor) {
2727 //std::cout<<"Load new attractor"<<std::endl;
2728 isOK = static_cast<bool>(load >> newAtFaceEntry);
2730 if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
2732 isOK = static_cast<bool>(load >> newAtShapeEntry);
2735 isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
2738 MESSAGE(" LOADING ATTRACTOR HYPOTHESIS ")
2739 const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
2740 const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
2741 BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
2742 attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
2743 //attractor->BuildMap();
2744 _classAttractors.insert( make_pair( newAtFaceEntry, attractor ));
2749 if (hasNewAttractor) {
2750 isOK = static_cast<bool>(load >> option_or_sm);
2752 if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2753 hasEnforcedVertex = true;
2754 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2755 hasPreCADFacesPeriodicity = true;
2756 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2757 hasPreCADEdgesPeriodicity = true;
2758 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2759 hasFacesPeriodicity = true;
2760 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2761 hasEdgesPeriodicity = true;
2762 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2763 hasVerticesPeriodicity = true;
2769 // Here is a example of the saved stream:
2770 // __ENFORCED_VERTICES_BEGIN__
2771 // __BEGIN_VERTEX__ => no name, no entry
2772 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2773 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__
2774 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__
2776 // __BEGIN_VERTEX__ => no coords
2777 // __BEGIN_NAME__ mes points __END_NAME__
2778 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
2779 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2780 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
2782 // __ENFORCED_VERTICES_END__
2785 std::string enfSeparator;
2786 std::string enfName;
2787 std::string enfGeomEntry;
2788 std::string enfGroup;
2789 TEntryList enfFaceEntryList;
2790 double enfCoords[3];
2791 bool hasCoords = false;
2793 _faceEntryEnfVertexListMap.clear();
2794 _enfVertexList.clear();
2795 _faceEntryCoordsListMap.clear();
2796 _coordsEnfVertexMap.clear();
2797 _faceEntryEnfVertexEntryListMap.clear();
2798 _enfVertexEntryEnfVertexMap.clear();
2801 while (isOK && hasEnforcedVertex) {
2802 isOK = static_cast<bool>(load >> enfSeparator); // __BEGIN_VERTEX__
2803 TEnfVertex *enfVertex = new TEnfVertex();
2804 // MESSAGE("enfSeparator: " <<enfSeparator);
2805 if (enfSeparator == "__ENFORCED_VERTICES_END__")
2806 break; // __ENFORCED_VERTICES_END__
2807 if (enfSeparator != "__BEGIN_VERTEX__")
2808 throw std::exception();
2811 isOK = static_cast<bool>(load >> enfSeparator);
2812 MESSAGE("enfSeparator: " <<enfSeparator);
2813 if (enfSeparator == "__END_VERTEX__") {
2815 enfVertex->name = enfName;
2816 enfVertex->geomEntry = enfGeomEntry;
2817 enfVertex->grpName = enfGroup;
2818 enfVertex->coords.clear();
2820 enfVertex->coords.assign(enfCoords,enfCoords+3);
2821 enfVertex->faceEntries = enfFaceEntryList;
2823 _enfVertexList.insert(enfVertex);
2825 if (enfVertex->coords.size()) {
2826 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
2827 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2828 _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
2829 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2832 if (!enfVertex->geomEntry.empty()) {
2833 _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
2834 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2835 _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
2836 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2841 enfGeomEntry.clear();
2843 enfFaceEntryList.clear();
2845 break; // __END_VERTEX__
2848 if (enfSeparator == "__BEGIN_NAME__") { // __BEGIN_NAME__
2849 while (isOK && (enfSeparator != "__END_NAME__")) {
2850 isOK = static_cast<bool>(load >> enfSeparator);
2851 if (enfSeparator != "__END_NAME__") {
2852 if (!enfName.empty())
2854 enfName += enfSeparator;
2857 MESSAGE("enfName: " <<enfName);
2860 if (enfSeparator == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
2861 isOK = static_cast<bool>(load >> enfGeomEntry);
2862 isOK = static_cast<bool>(load >> enfSeparator); // __END_ENTRY__
2863 if (enfSeparator != "__END_ENTRY__")
2864 throw std::exception();
2865 MESSAGE("enfGeomEntry: " <<enfGeomEntry);
2868 if (enfSeparator == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
2869 while (isOK && (enfSeparator != "__END_GROUP__")) {
2870 isOK = static_cast<bool>(load >> enfSeparator);
2871 if (enfSeparator != "__END_GROUP__") {
2872 if (!enfGroup.empty())
2874 enfGroup += enfSeparator;
2877 MESSAGE("enfGroup: " <<enfGroup);
2880 if (enfSeparator == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
2882 isOK = static_cast<bool>(load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
2883 isOK = static_cast<bool>(load >> enfSeparator); // __END_COORDS__
2884 if (enfSeparator != "__END_COORDS__")
2885 throw std::exception();
2886 MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
2889 if (enfSeparator == "__BEGIN_FACELIST__") { // __BEGIN_FACELIST__
2890 while (isOK && (enfSeparator != "__END_FACELIST__")) {
2891 isOK = static_cast<bool>(load >> enfSeparator);
2892 if (enfSeparator != "__END_FACELIST__") {
2893 enfFaceEntryList.insert(enfSeparator);
2894 MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
2903 if (hasPreCADFacesPeriodicity){
2904 LoadPreCADPeriodicity(load, "FACES");
2906 isOK = static_cast<bool>(load >> option_or_sm);
2908 if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2909 hasPreCADEdgesPeriodicity = true;
2910 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2911 hasFacesPeriodicity = true;
2912 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2913 hasEdgesPeriodicity = true;
2914 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2915 hasVerticesPeriodicity = true;
2919 if (hasPreCADEdgesPeriodicity){
2920 LoadPreCADPeriodicity(load, "EDGES");
2922 isOK = static_cast<bool>(load >> option_or_sm);
2924 if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2925 hasFacesPeriodicity = true;
2926 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2927 hasEdgesPeriodicity = true;
2928 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2929 hasVerticesPeriodicity = true;
2933 if (hasFacesPeriodicity){
2934 LoadFacesPeriodicity(load);
2936 isOK = static_cast<bool>(load >> option_or_sm);
2938 if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2939 hasEdgesPeriodicity = true;
2940 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2941 hasVerticesPeriodicity = true;
2945 if (hasEdgesPeriodicity){
2946 LoadEdgesPeriodicity(load);
2948 isOK = static_cast<bool>(load >> option_or_sm);
2950 if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2951 hasVerticesPeriodicity = true;
2954 if (hasVerticesPeriodicity)
2955 LoadVerticesPeriodicity(load);
2960 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
2964 std::string periodicitySeparator;
2968 _facesPeriodicityVector.clear();
2971 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2972 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2973 TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
2974 if (periodicitySeparator == "__FACES_PERIODICITY_END__")
2975 break; // __FACES_PERIODICITY_END__
2976 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2977 MESSAGE("//" << periodicitySeparator << "//");
2978 throw std::exception();
2982 isOK = static_cast<bool>(load >> periodicitySeparator);
2983 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2984 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2986 periodicity_i->first = shape1Entry;
2987 periodicity_i->second = shape2Entry;
2989 _facesPeriodicityVector.push_back(*periodicity_i);
2991 break; // __END_PERIODICITY_DESCRIPTION__
2994 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
2995 isOK = static_cast<bool>(load >> shape1Entry);
2996 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
2997 if (periodicitySeparator != "__END_ENTRY1__")
2998 throw std::exception();
2999 MESSAGE("shape1Entry: " <<shape1Entry);
3002 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3003 isOK = static_cast<bool>(load >> shape2Entry);
3004 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3005 if (periodicitySeparator != "__END_ENTRY2__")
3006 throw std::exception();
3007 MESSAGE("shape2Entry: " <<shape2Entry);
3014 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
3018 std::string periodicitySeparator;
3019 TEntry theFace1Entry;
3020 TEntry theEdge1Entry;
3021 TEntry theFace2Entry;
3022 TEntry theEdge2Entry;
3023 int edge_orientation = 0;
3025 _edgesPeriodicityVector.clear();
3028 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3029 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3030 TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
3031 if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
3032 break; // __EDGES_PERIODICITY_END__
3033 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3034 MESSAGE("//" << periodicitySeparator << "//");
3035 throw std::exception();
3039 isOK = static_cast<bool>(load >> periodicitySeparator);
3040 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3041 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3043 periodicity_i->theFace1Entry = theFace1Entry;
3044 periodicity_i->theEdge1Entry = theEdge1Entry;
3045 periodicity_i->theFace2Entry = theFace2Entry;
3046 periodicity_i->theEdge2Entry = theEdge2Entry;
3047 periodicity_i->edge_orientation = edge_orientation;
3049 _edgesPeriodicityVector.push_back(*periodicity_i);
3051 break; // __END_PERIODICITY_DESCRIPTION__
3054 if (periodicitySeparator == "__BEGIN_FACE1__") { // __BEGIN_FACE1__
3055 isOK = static_cast<bool>(load >> theFace1Entry);
3056 MESSAGE("//" << theFace1Entry << "//");
3057 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE1__
3058 if (periodicitySeparator != "__END_FACE1__"){
3059 MESSAGE("//" << periodicitySeparator << "//");
3060 throw std::exception();
3062 MESSAGE("theFace1Entry: " <<theFace1Entry);
3065 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3066 isOK = static_cast<bool>(load >> theEdge1Entry);
3067 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3068 if (periodicitySeparator != "__END_EDGE1__")
3069 throw std::exception();
3070 MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3073 if (periodicitySeparator == "__BEGIN_FACE2__") { // __BEGIN_FACE2__
3074 isOK = static_cast<bool>(load >> theFace2Entry);
3075 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE2__
3076 if (periodicitySeparator != "__END_FACE2__")
3077 throw std::exception();
3078 MESSAGE("theFace2Entry: " <<theFace2Entry);
3081 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3082 isOK = static_cast<bool>(load >> theEdge2Entry);
3083 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3084 if (periodicitySeparator != "__END_EDGE2__")
3085 throw std::exception();
3086 MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3089 if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") { // __BEGIN_EDGE_ORIENTATION__
3090 isOK = static_cast<bool>(load >> edge_orientation);
3091 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
3092 if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
3093 throw std::exception();
3094 MESSAGE("edge_orientation: " <<edge_orientation);
3100 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
3104 std::string periodicitySeparator;
3105 TEntry theEdge1Entry;
3106 TEntry theVertex1Entry;
3107 TEntry theEdge2Entry;
3108 TEntry theVertex2Entry;
3110 _verticesPeriodicityVector.clear();
3113 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3114 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3115 TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
3116 if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
3117 break; // __VERTICES_PERIODICITY_END__
3118 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3119 MESSAGE("//" << periodicitySeparator << "//");
3120 throw std::exception();
3124 isOK = static_cast<bool>(load >> periodicitySeparator);
3125 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3126 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3128 periodicity_i->theEdge1Entry = theEdge1Entry;
3129 periodicity_i->theVertex1Entry = theVertex1Entry;
3130 periodicity_i->theEdge2Entry = theEdge2Entry;
3131 periodicity_i->theVertex2Entry = theVertex2Entry;
3133 _verticesPeriodicityVector.push_back(*periodicity_i);
3135 break; // __END_PERIODICITY_DESCRIPTION__
3138 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3139 isOK = static_cast<bool>(load >> theEdge1Entry);
3140 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3141 if (periodicitySeparator != "__END_EDGE1__")
3142 throw std::exception();
3143 MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3146 if (periodicitySeparator == "__BEGIN_VERTEX1__") { // __BEGIN_VERTEX1__
3147 isOK = static_cast<bool>(load >> theVertex1Entry);
3148 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX1__
3149 if (periodicitySeparator != "__END_VERTEX1__")
3150 throw std::exception();
3151 MESSAGE("theVertex1Entry: " <<theVertex1Entry);
3154 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3155 isOK = static_cast<bool>(load >> theEdge2Entry);
3156 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3157 if (periodicitySeparator != "__END_EDGE2__")
3158 throw std::exception();
3159 MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3162 if (periodicitySeparator == "__BEGIN_VERTEX2__") { // __BEGIN_VERTEX2__
3163 isOK = static_cast<bool>(load >> theVertex2Entry);
3164 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX2__
3165 if (periodicitySeparator != "__END_VERTEX2__")
3166 throw std::exception();
3167 MESSAGE("theVertex2Entry: " <<theVertex2Entry);
3173 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
3177 std::string periodicitySeparator;
3180 std::vector<std::string> theSourceVerticesEntries;
3181 std::vector<std::string> theTargetVerticesEntries;
3183 bool hasSourceVertices = false;
3184 bool hasTargetVertices = false;
3186 if ( shapeType && strcmp( shapeType, "FACES") == 0 )
3187 _preCadFacesPeriodicityVector.clear();
3189 _preCadEdgesPeriodicityVector.clear();
3193 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3194 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3195 TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
3196 // MESSAGE("periodicitySeparator: " <<periodicitySeparator);
3197 std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
3198 if (periodicitySeparator == endSeparator)
3199 break; // __PRECAD_FACES_PERIODICITY_END__
3200 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3201 MESSAGE("//" << endSeparator << "//");
3202 MESSAGE("//" << periodicitySeparator << "//");
3203 throw std::exception();
3207 isOK = static_cast<bool>(load >> periodicitySeparator);
3208 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3209 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3211 periodicity_i->shape1Entry = shape1Entry;
3212 periodicity_i->shape2Entry = shape2Entry;
3214 MESSAGE("theSourceVerticesEntries.size(): " << theSourceVerticesEntries.size());
3215 MESSAGE("theTargetVerticesEntries.size(): " << theTargetVerticesEntries.size());
3217 if (hasSourceVertices)
3218 periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
3219 if (hasTargetVertices)
3220 periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
3222 if ( shapeType && strcmp( shapeType, "FACES" ))
3223 _preCadFacesPeriodicityVector.push_back(*periodicity_i);
3225 _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
3227 theSourceVerticesEntries.clear();
3228 theTargetVerticesEntries.clear();
3229 hasSourceVertices = false;
3230 hasTargetVertices = false;
3231 break; // __END_PERIODICITY_DESCRIPTION__
3234 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3235 isOK = static_cast<bool>(load >> shape1Entry);
3236 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3237 if (periodicitySeparator != "__END_ENTRY1__")
3238 throw std::exception();
3239 MESSAGE("shape1Entry: " <<shape1Entry);
3242 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3243 isOK = static_cast<bool>(load >> shape2Entry);
3244 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3245 if (periodicitySeparator != "__END_ENTRY2__")
3246 throw std::exception();
3247 MESSAGE("shape2Entry: " <<shape2Entry);
3250 if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") { // __BEGIN_SOURCE_VERTICES_LIST__
3251 hasSourceVertices = true;
3252 while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
3253 isOK = static_cast<bool>(load >> periodicitySeparator);
3254 if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
3255 theSourceVerticesEntries.push_back(periodicitySeparator);
3256 MESSAGE("theSourceVerticesEntries: " <<periodicitySeparator);
3261 if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") { // __BEGIN_TARGET_VERTICES_LIST__
3262 hasTargetVertices = true;
3263 while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
3264 isOK = static_cast<bool>(load >> periodicitySeparator);
3265 if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
3266 theTargetVerticesEntries.push_back(periodicitySeparator);
3267 MESSAGE("theTargetVerticesEntries: " <<periodicitySeparator);
3275 //=============================================================================
3276 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
3277 return hyp.SaveTo(save);
3280 //=============================================================================
3281 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
3282 return hyp.LoadFrom(load);
3285 //================================================================================
3287 * \brief Does nothing
3289 //================================================================================
3291 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
3295 //================================================================================
3297 * \brief Returns default global constant physical size given a default value of element length ratio
3299 //================================================================================
3301 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
3302 if (bbSegmentation != 0 && diagonal != 0)
3303 return diagonal / bbSegmentation ;
3307 //================================================================================
3309 * \brief Returns default min size given a default value of element length ratio
3311 //================================================================================
3313 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
3315 return diagonal / 1000.0 ;
3316 return undefinedDouble();
3319 //================================================================================
3321 * \brief Returns default max size given a default value of element length ratio
3323 //================================================================================
3325 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
3327 return diagonal / 5.0 ;
3328 return undefinedDouble();
3331 //================================================================================
3333 * \brief Returns default chordal error given a default value of element length ratio
3335 //================================================================================
3337 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
3340 return undefinedDouble();
3343 //================================================================================
3345 * \brief Returns default tiny edge length given a default value of element length ratio
3347 //================================================================================
3349 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
3351 return diagonal * 1e-6 ;
3352 return undefinedDouble();
3355 //================================================================================
3357 * \brief Returns default tiny edge optimisation length given a default value of element length ratio
3359 //================================================================================
3361 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal) {
3363 return diagonal * 1e-6 ;
3364 return undefinedDouble();
3367 //=============================================================================
3369 * \brief Initialize my parameter values by default parameters.
3370 * \retval bool - true if parameter values have been successfully defined
3372 //=============================================================================
3374 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
3375 double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
3376 _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
3377 _minSize = GetDefaultMinSize(diagonal);
3378 _maxSize = GetDefaultMaxSize(diagonal);
3379 _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
3380 _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
3381 _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(diagonal);
3386 //================================================================================
3388 * \brief Converts a string to a bool
3390 //================================================================================
3392 bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
3393 throw (std::invalid_argument)
3395 std::string s = str;
3396 if ( isOk ) *isOk = true;
3398 for ( size_t i = 0; i <= s.size(); ++i )
3399 s[i] = tolower( s[i] );
3401 if ( s == "1" || s == "true" || s == "active" || s == "yes" )
3404 if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
3410 std::string msg = "Not a Boolean value:'" + str + "'";
3411 throw std::invalid_argument(msg);
3416 //================================================================================
3418 * \brief Converts a string to a real value
3420 //================================================================================
3422 double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
3423 throw (std::invalid_argument)
3425 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3428 double val = strtod(&str[0], &endPtr);
3429 bool ok = (&str[0] != endPtr);
3431 if ( isOk ) *isOk = ok;
3435 std::string msg = "Not a real value:'" + str + "'";
3436 throw std::invalid_argument(msg);
3441 //================================================================================
3443 * \brief Converts a string to a integer value
3445 //================================================================================
3447 int BLSURFPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
3448 throw (std::invalid_argument)
3450 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3453 int val = (int)strtol( &str[0], &endPtr, 10);
3454 bool ok = (&str[0] != endPtr);
3456 if ( isOk ) *isOk = ok;
3460 std::string msg = "Not an integer value:'" + str + "'";
3461 throw std::invalid_argument(msg);