1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : BLSURFPlugin_Hypothesis.cxx
22 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
23 // & Aurelien ALLEAUME (DISTENE)
24 // Size maps development: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
27 #include "BLSURFPlugin_Hypothesis.hxx"
28 #include "BLSURFPlugin_Attractor.hxx"
29 #include "SMESH_Gen_i.hxx"
30 #include <utilities.h>
36 #include "ShapeAnalysis.hxx"
39 #include CORBA_CLIENT_HEADER(SALOMEDS)
40 #include CORBA_CLIENT_HEADER(GEOM_Gen)
44 struct GET_DEFAULT // struct used to get default value from GetOptionValue()
47 operator bool* () { return &isDefault; }
51 //=============================================================================
52 BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen) :
53 SMESH_Hypothesis(hypId, studyId, gen),
54 _physicalMesh(GetDefaultPhysicalMesh()),
55 _geometricMesh(GetDefaultGeometricMesh()),
56 _phySize(GetDefaultPhySize()),
57 _phySizeRel(GetDefaultPhySizeRel()),
58 _minSize(GetDefaultMinSize()),
59 _maxSize(GetDefaultMaxSize()),
60 _minSizeRel(GetDefaultMinSizeRel()),
61 _maxSizeRel(GetDefaultMaxSizeRel()),
62 _useGradation(GetDefaultUseGradation()),
63 _gradation(GetDefaultGradation()),
64 _useVolumeGradation(GetDefaultUseVolumeGradation()),
65 _volumeGradation(GetDefaultVolumeGradation()),
66 _quadAllowed(GetDefaultQuadAllowed()),
67 _angleMesh(GetDefaultAngleMesh()),
68 _chordalError(GetDefaultChordalError()),
69 _anisotropic(GetDefaultAnisotropic()),
70 _anisotropicRatio(GetDefaultAnisotropicRatio()),
71 _removeTinyEdges(GetDefaultRemoveTinyEdges()),
72 _tinyEdgeLength(GetDefaultTinyEdgeLength()),
73 _optimiseTinyEdges(GetDefaultOptimiseTinyEdges()),
74 _tinyEdgeOptimisationLength(GetDefaultTinyEdgeOptimisationLength()),
75 _correctSurfaceIntersec(GetDefaultCorrectSurfaceIntersection()),
76 _corrSurfaceIntersCost(GetDefaultCorrectSurfaceIntersectionMaxCost()),
77 _badElementRemoval(GetDefaultBadElementRemoval()),
78 _badElementAspectRatio(GetDefaultBadElementAspectRatio()),
79 _optimizeMesh(GetDefaultOptimizeMesh()),
80 _quadraticMesh(GetDefaultQuadraticMesh()),
81 _verb(GetDefaultVerbosity()),
82 _topology(GetDefaultTopology()),
83 _preCADMergeEdges(GetDefaultPreCADMergeEdges()),
84 _preCADRemoveTinyUVEdges(GetDefaultPreCADRemoveTinyUVEdges()),
85 _preCADRemoveDuplicateCADFaces(GetDefaultPreCADRemoveDuplicateCADFaces()),
86 _preCADProcess3DTopology(GetDefaultPreCADProcess3DTopology()),
87 _preCADDiscardInput(GetDefaultPreCADDiscardInput()),
88 _sizeMap(GetDefaultSizeMap()),
89 _attractors(GetDefaultSizeMap()),
90 _classAttractors(GetDefaultAttractorMap()),
91 _faceEntryEnfVertexListMap(GetDefaultFaceEntryEnfVertexListMap()),
92 _enfVertexList(GetDefaultEnfVertexList()),
93 _faceEntryCoordsListMap(GetDefaultFaceEntryCoordsListMap()),
94 _coordsEnfVertexMap(GetDefaultCoordsEnfVertexMap()),
95 _faceEntryEnfVertexEntryListMap(GetDefaultFaceEntryEnfVertexEntryListMap()),
96 _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()),
97 _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap()),
98 _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex()),
99 _preCadFacesPeriodicityVector(GetDefaultPreCadFacesPeriodicityVector()),
100 _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector()),
101 _GMFFileName(GetDefaultGMFFile())
103 _name = GetHypType();
106 // _GMFFileMode = false; // GMF ascii mode
108 // Advanced options with their defaults according to MG User Manual
110 const char* boolOptionNames[] = { "enforce_cad_edge_sizes", // default = 0
111 // "correct_surface_intersections", // default = 1
112 // "create_tag_on_collision", // default = 1
113 "jacobian_rectification_respect_geometry", // default = 1
114 "rectify_jacobian", // default = 1
115 "respect_geometry", // default = 1
116 // "optimise_tiny_edges", // default = 0
117 // "remove_duplicate_cad_faces", // default = 1
118 "tiny_edge_avoid_surface_intersections", // default = 1
119 // "tiny_edge_respect_geometry", // default = 0
123 const char* intOptionNames[] = { "max_number_of_points_per_patch", // default = 100000
126 const char* doubleOptionNames[] = { // "surface_intersections_processing_max_cost",// default = 15
127 // "periodic_tolerance", // default = diag/100
128 // "volume_gradation",
129 // "tiny_edge_optimisation_length", // default = diag * 1e-6
132 const char* charOptionNames[] = { // "required_entities", // default = "respect"
133 // "tags", // default = "respect"
137 // PreCAD advanced options
138 const char* preCADboolOptionNames[] = { "closed_geometry", // default = 0
139 "discard_input_topology", // default = 0
140 "merge_edges", // default = = 1
141 "remove_duplicate_cad_faces", // default = 1
142 // "create_tag_on_collision", // default = 1
143 "debug", // default = 0
144 "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->GetCurrentStudy();
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" );
755 //=============================================================================
756 // void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName, bool isBinary)
757 void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
759 _GMFFileName = theFileName;
760 // _GMFFileMode = isBinary;
761 NotifySubMeshesHypothesisModification();
764 //=============================================================================
765 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
766 throw (std::invalid_argument) {
768 TOptionValues::iterator op_val = _option2value.find(optionName);
769 if (op_val == _option2value.end())
771 op_val = _preCADoption2value.find(optionName);
772 if (op_val == _preCADoption2value.end())
774 std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'. Try SetAdvancedOption()";
775 throw std::invalid_argument(msg);
778 if (op_val->second != optionValue)
780 const char* ptr = optionValue.c_str();
781 // strip white spaces
782 while (ptr[0] == ' ')
785 while (i != 0 && ptr[i - 1] == ' ')
789 std::string typeName;
792 } else if (_charOptions.count(optionName)) {
793 // do not check strings
794 } else if (_doubleOptions.count(optionName)) {
795 // check if value is double
798 } else if (_boolOptions.count(optionName)) {
799 // check if value is bool
800 ToBool(ptr, &typeOk);
803 // check if value is int
805 typeName = "integer";
808 std::string msg = "Advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
809 throw std::invalid_argument(msg);
811 std::string value( ptr, i );
812 if ( _defaultOptionValues[ optionName ] == value )
815 op_val->second = value;
817 NotifySubMeshesHypothesisModification();
821 //=============================================================================
822 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
823 throw (std::invalid_argument) {
825 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
826 if (op_val == _preCADoption2value.end()) {
827 op_val = _option2value.find(optionName);
828 if (op_val == _option2value.end()) {
829 std::string msg = "Unknown MG-PreCAD option: '" + optionName + "'. Try SetAdvancedOption()";
830 throw std::invalid_argument(msg);
833 if (op_val->second != optionValue)
835 const char* ptr = optionValue.c_str();
836 // strip white spaces
837 while (ptr[0] == ' ')
840 while (i != 0 && ptr[i - 1] == ' ')
844 std::string typeName;
847 } else if (_preCADcharOptions.find(optionName) != _preCADcharOptions.end()) {
848 // do not check strings
849 } else if (_preCADdoubleOptions.find(optionName) != _preCADdoubleOptions.end()) {
850 // check if value is double
852 strtod(ptr, &endPtr);
853 typeOk = (ptr != endPtr);
855 } else if (_boolOptions.count(optionName)) {
856 // check if value is bool
857 ToBool(ptr, &typeOk);
860 // check if value is int
862 strtol(ptr, &endPtr, 10);
863 typeOk = (ptr != endPtr);
864 typeName = "integer";
867 std::string msg = "PreCAD advanced option '" + optionName + "' = '" + optionValue + "' but must be " + typeName;
868 throw std::invalid_argument(msg);
870 std::string value( ptr, i );
871 if ( _defaultOptionValues[ optionName ] == value )
874 op_val->second = value;
876 NotifySubMeshesHypothesisModification();
880 //=============================================================================
881 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
882 bool* isDefault) const
883 throw (std::invalid_argument)
885 TOptionValues::const_iterator op_val = _option2value.find(optionName);
886 if (op_val == _option2value.end())
888 op_val = _preCADoption2value.find(optionName);
889 if (op_val == _preCADoption2value.end())
891 op_val = _customOption2value.find(optionName);
892 if (op_val == _customOption2value.end())
894 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
895 throw std::invalid_argument(msg);
899 std::string val = op_val->second;
900 if ( isDefault ) *isDefault = ( val.empty() );
902 if ( val.empty() && isDefault )
904 op_val = _defaultOptionValues.find( optionName );
905 if (op_val != _defaultOptionValues.end())
906 val = op_val->second;
911 //=============================================================================
912 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName,
913 bool* isDefault) const
914 throw (std::invalid_argument)
916 TOptionValues::const_iterator op_val = _preCADoption2value.find(optionName);
917 if (op_val == _preCADoption2value.end())
919 op_val = _option2value.find(optionName);
920 if (op_val == _option2value.end())
922 op_val = _customOption2value.find(optionName);
923 if (op_val == _customOption2value.end())
925 std::string msg = "Unknown MG-CADSurf option: <" + optionName + ">";
926 throw std::invalid_argument(msg);
930 std::string val = op_val->second;
931 if ( isDefault ) *isDefault = ( val.empty() );
933 if ( val.empty() && isDefault )
935 op_val = _defaultOptionValues.find( optionName );
936 if (op_val != _option2value.end())
937 val = op_val->second;
942 //=============================================================================
943 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName)
945 TOptionValues::iterator op_val = _customOption2value.find(optionName);
946 if (op_val != _customOption2value.end())
947 _customOption2value.erase(op_val);
949 op_val = _option2value.find(optionName);
950 if (op_val != _option2value.end())
951 op_val->second.clear();
953 op_val = _preCADoption2value.find(optionName);
954 if (op_val != _preCADoption2value.end())
955 op_val->second.clear();
960 //=============================================================================
961 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName)
963 TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
964 if (op_val != _preCADoption2value.end())
965 op_val->second.clear();
968 //=============================================================================
969 void BLSURFPlugin_Hypothesis::AddOption(const std::string& optionName, const std::string& optionValue)
972 TOptionValues::iterator op_val = _option2value.find(optionName);
973 if (op_val != _option2value.end())
975 if (op_val->second != optionValue)
976 op_val->second = optionValue;
982 op_val = _preCADoption2value.find(optionName);
983 if (op_val != _preCADoption2value.end())
985 if (op_val->second != optionValue)
986 op_val->second = optionValue;
990 else if ( optionValue.empty() )
992 _customOption2value.erase( optionName );
996 op_val = _customOption2value.find(optionName);
997 if (op_val == _customOption2value.end())
998 _customOption2value[optionName] = optionValue;
999 else if (op_val->second != optionValue)
1000 op_val->second = optionValue;
1006 NotifySubMeshesHypothesisModification();
1009 //=============================================================================
1010 void BLSURFPlugin_Hypothesis::AddPreCADOption(const std::string& optionName, const std::string& optionValue)
1012 AddOption( optionName, optionValue );
1015 //=============================================================================
1016 std::string BLSURFPlugin_Hypothesis::GetOption(const std::string& optionName) const
1018 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1019 if (op_val != _customOption2value.end())
1020 return op_val->second;
1025 //=============================================================================
1026 std::string BLSURFPlugin_Hypothesis::GetPreCADOption(const std::string& optionName) const
1028 TOptionValues::const_iterator op_val = _customOption2value.find(optionName);
1029 if (op_val != _customOption2value.end())
1030 return op_val->second;
1035 //=============================================================================
1036 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetOptionValues() const
1039 TOptionValues::const_iterator op_val = _option2value.begin();
1040 for ( ; op_val != _option2value.end(); ++op_val )
1041 vals.insert( make_pair( op_val->first, GetOptionValue( op_val->first, GET_DEFAULT() )));
1046 //=============================================================================
1047 BLSURFPlugin_Hypothesis::TOptionValues BLSURFPlugin_Hypothesis::GetPreCADOptionValues() const
1050 TOptionValues::const_iterator op_val = _preCADoption2value.begin();
1051 for ( ; op_val != _preCADoption2value.end(); ++op_val )
1052 vals.insert( make_pair( op_val->first, GetPreCADOptionValue( op_val->first, GET_DEFAULT() )));
1057 //=======================================================================
1058 //function : SetSizeMapEntry
1059 //=======================================================================
1060 void BLSURFPlugin_Hypothesis::SetSizeMapEntry(const std::string& entry, const std::string& sizeMap) {
1061 if (_sizeMap[entry].compare(sizeMap) != 0) {
1062 SetPhysicalMesh(PhysicalLocalSize);
1063 _sizeMap[entry] = sizeMap;
1064 NotifySubMeshesHypothesisModification();
1068 //=======================================================================
1069 //function : GetSizeMapEntry
1070 //=======================================================================
1071 std::string BLSURFPlugin_Hypothesis::GetSizeMapEntry(const std::string& entry) {
1072 TSizeMap::iterator it = _sizeMap.find(entry);
1073 if (it != _sizeMap.end())
1076 return "No_Such_Entry";
1080 * \brief Return the size maps
1082 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetSizeMapEntries(const BLSURFPlugin_Hypothesis* hyp) {
1083 return hyp ? hyp->_GetSizeMapEntries() : GetDefaultSizeMap();
1086 //=======================================================================
1087 //function : SetAttractorEntry
1088 //=======================================================================
1089 void BLSURFPlugin_Hypothesis::SetAttractorEntry(const std::string& entry, const std::string& attractor) {
1090 if (_attractors[entry].compare(attractor) != 0) {
1091 SetPhysicalMesh(PhysicalLocalSize);
1092 _attractors[entry] = attractor;
1093 NotifySubMeshesHypothesisModification();
1097 //=======================================================================
1098 //function : GetAttractorEntry
1099 //=======================================================================
1100 std::string BLSURFPlugin_Hypothesis::GetAttractorEntry(const std::string& entry) {
1101 TSizeMap::iterator it = _attractors.find(entry);
1102 if (it != _attractors.end())
1105 return "No_Such_Entry";
1109 * \brief Return the attractors
1111 BLSURFPlugin_Hypothesis::TSizeMap BLSURFPlugin_Hypothesis::GetAttractorEntries(const BLSURFPlugin_Hypothesis* hyp) {
1112 return hyp ? hyp->_GetAttractorEntries() : GetDefaultSizeMap();
1115 //=======================================================================
1116 //function : SetClassAttractorEntry
1117 //=======================================================================
1118 void BLSURFPlugin_Hypothesis::SetClassAttractorEntry(const std::string& entry, const std::string& attEntry, double StartSize, double EndSize, double ActionRadius, double ConstantRadius)
1120 SetPhysicalMesh(PhysicalLocalSize);
1122 // The new attractor can't be defined on the same face as another sizemap
1123 TSizeMap::iterator it = _sizeMap.find( entry );
1124 if ( it != _sizeMap.end() ) {
1126 NotifySubMeshesHypothesisModification();
1129 TSizeMap::iterator itAt = _attractors.find( entry );
1130 if ( itAt != _attractors.end() ) {
1131 _attractors.erase(itAt);
1132 NotifySubMeshesHypothesisModification();
1136 const TopoDS_Shape AttractorShape = BLSURFPlugin_Hypothesis::entryToShape(attEntry);
1137 const TopoDS_Face FaceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(entry));
1138 TAttractorMap::iterator attIt = _classAttractors.find(entry);
1139 for ( ; attIt != _classAttractors.end(); ++attIt )
1140 if ( attIt->first == entry &&
1141 attIt->second->GetAttractorEntry() == attEntry )
1143 bool attExists = (attIt != _classAttractors.end());
1145 BLSURFPlugin_Attractor* myAttractor;
1147 myAttractor = new BLSURFPlugin_Attractor(FaceShape, AttractorShape, attEntry);//, 0.1 );
1148 _classAttractors.insert( make_pair( entry, myAttractor ));
1151 myAttractor = attIt->second;
1153 // if (!myAttractor->IsMapBuilt())
1154 // myAttractor->BuildMap();
1155 myAttractor->SetParameters(StartSize, EndSize, ActionRadius, ConstantRadius);
1157 NotifySubMeshesHypothesisModification();
1160 //=======================================================================
1161 //function : SetConstantSizeOnAdjacentFaces
1162 //=======================================================================
1163 // TODO uncomment and test (include the needed .hxx)
1164 // SetConstantSizeOnAdjacentFaces(myShape, att_entry, startSize, endSize = user_size, const_dist ) {
1165 // TopTools_IndexedMapOfShapListOdShape anEdge2FaceMap;
1166 // TopExp::MapShapesAnAncestors(myShape,TopAbs_EDGE, TopAbs_FACE, anEdge2FaceMap);
1167 // TopTools_IndexedMapOfShapListOdShape::iterator it;
1168 // for (it = anEdge2FaceMap.begin();it != anEdge2FaceMap.end();it++){
1169 // SetClassAttractorEntry((*it).first, att_entry, startSize, endSize, 0, const_dist)
1177 //=======================================================================
1178 //function : GetClassAttractorEntry
1179 //=======================================================================
1180 // BLSURFPlugin_Attractor& BLSURFPlugin_Hypothesis::GetClassAttractorEntry(const std::string& entry)
1182 // TAttractorMap::iterator it = _classAttractors.find( entry );
1183 // if ( it != _classAttractors.end() )
1184 // return it->second;
1186 // return "No_Such_Entry";
1190 * \brief Return the map of attractor instances
1192 BLSURFPlugin_Hypothesis::TAttractorMap BLSURFPlugin_Hypothesis::GetClassAttractorEntries(const BLSURFPlugin_Hypothesis* hyp)
1194 return hyp ? hyp->_GetClassAttractorEntries():GetDefaultAttractorMap();
1197 //=======================================================================
1198 //function : ClearEntry
1199 //=======================================================================
1200 void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
1201 const char * attEntry/*=0*/)
1203 TSizeMap::iterator it = _sizeMap.find( entry );
1205 if ( it != _sizeMap.end() ) {
1207 NotifySubMeshesHypothesisModification();
1210 TSizeMap::iterator itAt = _attractors.find( entry );
1211 if ( itAt != _attractors.end() ) {
1212 _attractors.erase(itAt);
1213 NotifySubMeshesHypothesisModification();
1216 TAttractorMap::iterator it_clAt = _classAttractors.find( entry );
1217 if ( it_clAt != _classAttractors.end() ) {
1219 if ( !attEntry || it_clAt->second->GetAttractorEntry() == attEntry )
1220 _classAttractors.erase( it_clAt++ );
1224 while ( it_clAt != _classAttractors.end() );
1225 MESSAGE("_classAttractors.size() = "<<_classAttractors.size())
1226 NotifySubMeshesHypothesisModification();
1229 std::cout<<"No_Such_Entry"<<std::endl;
1234 //=======================================================================
1235 //function : ClearSizeMaps
1236 //=======================================================================
1237 void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
1239 _attractors.clear();
1240 _classAttractors.clear();
1243 // Enable internal enforced vertices on specific face if requested by user
1245 ////=======================================================================
1246 ////function : SetInternalEnforcedVertex
1247 ////=======================================================================
1248 //void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex(TEntry theFaceEntry,
1249 // bool toEnforceInternalVertices,
1250 // TEnfGroupName theGroupName) {
1252 // MESSAGE("BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex("<< theFaceEntry << ", "
1253 // << toEnforceInternalVertices << ", " << theGroupName << ")");
1255 // TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
1256 // if (it != _faceEntryInternalVerticesList.end()) {
1257 // if (!toEnforceInternalVertices) {
1258 // _faceEntryInternalVerticesList.erase(it);
1262 // if (toEnforceInternalVertices) {
1263 // _faceEntryInternalVerticesList.insert(theFaceEntry);
1268 // // Take care of groups
1272 //=======================================================================
1273 //function : SetEnforcedVertex
1274 //=======================================================================
1275 bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
1276 TEnfGroupName theGroupName, double x, double y, double z) {
1278 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
1279 << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
1281 SetPhysicalMesh(PhysicalLocalSize);
1283 // TEnfVertexList::iterator it;
1284 bool toNotify = false;
1285 bool toCreate = true;
1287 TEnfVertex *oldEnVertex;
1288 TEnfVertex *newEnfVertex = new TEnfVertex();
1289 newEnfVertex->name = theVertexName;
1290 newEnfVertex->geomEntry = theVertexEntry;
1291 newEnfVertex->coords.clear();
1292 if (theVertexEntry == "") {
1293 newEnfVertex->coords.push_back(x);
1294 newEnfVertex->coords.push_back(y);
1295 newEnfVertex->coords.push_back(z);
1297 newEnfVertex->grpName = theGroupName;
1298 newEnfVertex->faceEntries.clear();
1299 newEnfVertex->faceEntries.insert(theFaceEntry);
1302 // update _enfVertexList
1303 TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
1304 if (it != _enfVertexList.end()) {
1306 oldEnVertex = (*it);
1307 MESSAGE("Enforced Vertex was found => Update");
1308 if (oldEnVertex->name != theVertexName) {
1309 MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
1310 oldEnVertex->name = theVertexName;
1313 if (oldEnVertex->grpName != theGroupName) {
1314 MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
1315 oldEnVertex->grpName = theGroupName;
1318 TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
1319 if (it_faceEntries == oldEnVertex->faceEntries.end()) {
1320 MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
1321 oldEnVertex->faceEntries.insert(theFaceEntry);
1322 _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
1326 // update map coords / enf vertex if needed
1327 if (oldEnVertex->coords.size()) {
1328 _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex;
1329 _faceEntryCoordsListMap[theFaceEntry].insert(oldEnVertex->coords);
1332 // update map geom entry / enf vertex if needed
1333 if (oldEnVertex->geomEntry != "") {
1334 _enfVertexEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex;
1335 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(oldEnVertex->geomEntry);
1340 // //////// CREATE ////////////
1343 MESSAGE("Creating new enforced vertex");
1344 _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
1345 _enfVertexList.insert(newEnfVertex);
1346 if (theVertexEntry == "") {
1347 _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
1348 _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
1351 _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
1352 _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
1357 NotifySubMeshesHypothesisModification();
1359 MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
1364 //=======================================================================
1365 //function : GetEnforcedVertices
1366 //=======================================================================
1368 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
1369 throw (std::invalid_argument) {
1371 if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
1372 return _faceEntryEnfVertexListMap[theFaceEntry];
1374 return GetDefaultEnfVertexList();
1376 std::ostringstream msg;
1377 msg << "No enforced vertex for face entry " << theFaceEntry;
1378 throw std::invalid_argument(msg.str());
1381 //=======================================================================
1382 //function : GetEnfVertexCoordsList
1383 //=======================================================================
1385 BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
1386 const TEntry& theFaceEntry) throw (std::invalid_argument) {
1388 if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
1389 return _faceEntryCoordsListMap[theFaceEntry];
1391 std::ostringstream msg;
1392 msg << "No enforced vertex coords for face entry " << theFaceEntry;
1393 throw std::invalid_argument(msg.str());
1396 //=======================================================================
1397 //function : GetEnfVertexEntryList
1398 //=======================================================================
1400 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
1401 throw (std::invalid_argument) {
1403 if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
1404 return _faceEntryEnfVertexEntryListMap[theFaceEntry];
1406 std::ostringstream msg;
1407 msg << "No enforced vertex entry for face entry " << theFaceEntry;
1408 throw std::invalid_argument(msg.str());
1411 //=======================================================================
1412 //function : GetEnfVertex(TEnfVertexCoords coords)
1413 //=======================================================================
1415 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
1416 throw (std::invalid_argument) {
1418 if (_coordsEnfVertexMap.count(coords) > 0)
1419 return _coordsEnfVertexMap[coords];
1421 std::ostringstream msg;
1422 msg << "No enforced vertex with coords (" << coords[0] << ", " << coords[1] << ", " << coords[2] << ")";
1423 throw std::invalid_argument(msg.str());
1426 //=======================================================================
1427 //function : GetEnfVertex(const TEntry& theEnfVertexEntry)
1428 //=======================================================================
1430 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
1431 throw (std::invalid_argument) {
1433 if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
1434 return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
1436 std::ostringstream msg;
1437 msg << "No enforced vertex with entry " << theEnfVertexEntry;
1438 throw std::invalid_argument(msg.str());
1441 //Enable internal enforced vertices on specific face if requested by user
1442 ////=======================================================================
1443 ////function : GetInternalEnforcedVertex
1444 ////=======================================================================
1446 //bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertex(const TEntry& theFaceEntry)
1448 // if (_faceEntryInternalVerticesList.count(theFaceEntry) > 0)
1453 //=======================================================================
1454 //function : ClearEnforcedVertex
1455 //=======================================================================
1457 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
1458 const TEntry& theVertexEntry) throw (std::invalid_argument) {
1460 bool toNotify = false;
1461 std::ostringstream msg;
1462 TEnfVertex *oldEnfVertex;
1463 TEnfVertexCoords coords;
1465 coords.push_back(x);
1466 coords.push_back(y);
1467 coords.push_back(z);
1469 // check that enf vertex with given enf vertex entry exists
1470 TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
1471 if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
1473 MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
1474 oldEnfVertex = it_enfVertexEntry->second;
1476 _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
1478 TEntryList& enfVertexEntryList = _faceEntryEnfVertexEntryListMap[theFaceEntry];
1479 enfVertexEntryList.erase(theVertexEntry);
1480 if (enfVertexEntryList.size() == 0)
1481 _faceEntryEnfVertexEntryListMap.erase(theFaceEntry);
1482 // TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1483 // TEntryList::iterator it_entryList = it_entry_entry->second.find(theVertexEntry);
1484 // it_entry_entry->second.erase(it_entryList);
1485 // if (it_entry_entry->second.size() == 0)
1486 // _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1489 MESSAGE("Enforced vertex with geom entry " << theVertexEntry << " not found");
1490 msg << "No enforced vertex with geom entry " << theVertexEntry;
1491 // check that enf vertex with given coords exists
1492 TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
1493 if (it_coords_enf != _coordsEnfVertexMap.end()) {
1495 MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
1496 oldEnfVertex = it_coords_enf->second;
1498 _coordsEnfVertexMap.erase(it_coords_enf);
1500 TEnfVertexCoordsList& enfVertexCoordsList = _faceEntryCoordsListMap[theFaceEntry];
1501 enfVertexCoordsList.erase(coords);
1502 if (enfVertexCoordsList.size() == 0)
1503 _faceEntryCoordsListMap.erase(theFaceEntry);
1504 // TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1505 // TEnfVertexCoordsList::iterator it_coordsList = it_entry_coords->second.find(coords);
1506 // it_entry_coords->second.erase(it_coordsList);
1507 // if (it_entry_coords->second.size() == 0)
1508 // _faceEntryCoordsListMap.erase(it_entry_coords);
1511 MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found");
1513 msg << "No enforced vertex at " << x << ", " << y << ", " << z;
1514 throw std::invalid_argument(msg.str());
1518 MESSAGE("Remove enf vertex from _enfVertexList");
1520 // update _enfVertexList
1521 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1522 if (it != _enfVertexList.end()) {
1523 (*it)->faceEntries.erase(theFaceEntry);
1524 if ((*it)->faceEntries.size() == 0){
1525 _enfVertexList.erase(it);
1531 // update _faceEntryEnfVertexListMap
1532 TEnfVertexList& currentEnfVertexList = _faceEntryEnfVertexListMap[theFaceEntry];
1533 currentEnfVertexList.erase(oldEnfVertex);
1535 if (currentEnfVertexList.size() == 0) {
1536 MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
1537 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1542 NotifySubMeshesHypothesisModification();
1547 //=======================================================================
1548 //function : ClearEnforcedVertices
1549 //=======================================================================
1551 bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
1553 bool toNotify = false;
1554 TEnfVertex *oldEnfVertex;
1556 TFaceEntryCoordsListMap::iterator it_entry_coords = _faceEntryCoordsListMap.find(theFaceEntry);
1557 if (it_entry_coords != _faceEntryCoordsListMap.end()) {
1559 TEnfVertexCoordsList coordsList = it_entry_coords->second;
1560 TEnfVertexCoordsList::iterator it_coordsList = coordsList.begin();
1561 for (; it_coordsList != coordsList.end(); ++it_coordsList) {
1562 TEnfVertexCoords coords = (*it_coordsList);
1563 oldEnfVertex = _coordsEnfVertexMap[coords];
1564 _coordsEnfVertexMap.erase(coords);
1565 // update _enfVertexList
1566 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1567 if (it != _enfVertexList.end()) {
1568 (*it)->faceEntries.erase(theFaceEntry);
1569 if ((*it)->faceEntries.size() == 0){
1570 _enfVertexList.erase(it);
1576 _faceEntryCoordsListMap.erase(it_entry_coords);
1577 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1580 TFaceEntryEnfVertexEntryListMap::iterator it_entry_entry = _faceEntryEnfVertexEntryListMap.find(theFaceEntry);
1581 if (it_entry_entry != _faceEntryEnfVertexEntryListMap.end()) {
1583 TEntryList enfVertexEntryList = it_entry_entry->second;
1584 TEntryList::iterator it_enfVertexEntryList = enfVertexEntryList.begin();
1585 for (; it_enfVertexEntryList != enfVertexEntryList.end(); ++it_enfVertexEntryList) {
1586 TEntry enfVertexEntry = (*it_enfVertexEntryList);
1587 oldEnfVertex = _enfVertexEntryEnfVertexMap[enfVertexEntry];
1588 _enfVertexEntryEnfVertexMap.erase(enfVertexEntry);
1589 // update _enfVertexList
1590 TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
1591 if (it != _enfVertexList.end()) {
1592 (*it)->faceEntries.erase(theFaceEntry);
1593 if ((*it)->faceEntries.size() == 0){
1594 _enfVertexList.erase(it);
1600 _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
1601 _faceEntryEnfVertexListMap.erase(theFaceEntry);
1605 NotifySubMeshesHypothesisModification();
1608 // std::ostringstream msg;
1609 // msg << "No enforced vertex for " << theFaceEntry;
1610 // throw std::invalid_argument(msg.str());
1613 //=======================================================================
1614 //function : ClearAllEnforcedVertices
1615 //=======================================================================
1616 void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
1617 _faceEntryEnfVertexListMap.clear();
1618 _enfVertexList.clear();
1619 _faceEntryCoordsListMap.clear();
1620 _coordsEnfVertexMap.clear();
1621 _faceEntryEnfVertexEntryListMap.clear();
1622 _enfVertexEntryEnfVertexMap.clear();
1623 // Enable internal enforced vertices on specific face if requested by user
1624 // _faceEntryInternalVerticesList.clear();
1625 NotifySubMeshesHypothesisModification();
1628 //================================================================================
1630 * \brief Return the enforced vertices
1632 //================================================================================
1635 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
1636 const BLSURFPlugin_Hypothesis* hyp) {
1637 return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
1640 //Enable internal enforced vertices on specific face if requested by user
1641 //BLSURFPlugin_Hypothesis::TFaceEntryInternalVerticesList BLSURFPlugin_Hypothesis::GetAllInternalEnforcedVerticesByFace(
1642 // const BLSURFPlugin_Hypothesis* hyp) {
1643 // return hyp ? hyp->_GetAllInternalEnforcedVerticesByFace() : GetDefaultFaceEntryInternalVerticesMap();
1646 bool BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFaces(const BLSURFPlugin_Hypothesis* hyp)
1648 return hyp ? hyp->_GetInternalEnforcedVertexAllFaces() : GetDefaultInternalEnforcedVertex();
1651 BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnforcedVertexAllFacesGroup(const BLSURFPlugin_Hypothesis* hyp)
1653 return hyp ? hyp->_GetInternalEnforcedVertexAllFacesGroup() : BLSURFPlugin_Hypothesis::TEnfGroupName();
1656 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
1657 const BLSURFPlugin_Hypothesis* hyp) {
1658 return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
1661 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
1662 const BLSURFPlugin_Hypothesis* hyp) {
1663 return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
1666 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
1667 const BLSURFPlugin_Hypothesis* hyp) {
1668 return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
1671 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
1672 const BLSURFPlugin_Hypothesis* hyp) {
1673 return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
1676 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
1677 const BLSURFPlugin_Hypothesis* hyp) {
1678 return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
1681 std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
1683 TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
1684 if (it != _groupNameNodeIDMap.end()) {
1687 std::ostringstream msg;
1688 msg << "No group " << theGroupName;
1689 throw std::invalid_argument(msg.str());
1692 void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
1694 _groupNameNodeIDMap[theGroupName].insert(theNodeID);
1697 void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
1699 TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
1700 if (it != _groupNameNodeIDMap.end()) {
1701 std::set<int>::iterator IDit = it->second.find(theNodeID);
1702 if (IDit != it->second.end())
1703 it->second.erase(IDit);
1704 std::ostringstream msg;
1705 msg << "No node IDs " << theNodeID << " for group " << theGroupName;
1706 throw std::invalid_argument(msg.str());
1708 std::ostringstream msg;
1709 msg << "No group " << theGroupName;
1710 throw std::invalid_argument(msg.str());
1714 //=============================================================================
1715 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
1716 if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
1717 _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
1718 if (toEnforceInternalVertices)
1719 SetPhysicalMesh(PhysicalLocalSize);
1720 NotifySubMeshesHypothesisModification();
1725 //=============================================================================
1726 void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
1727 if (std::string(theGroupName) != std::string(_enforcedInternalVerticesAllFacesGroup)) {
1728 _enforcedInternalVerticesAllFacesGroup = theGroupName;
1729 NotifySubMeshesHypothesisModification();
1733 //=============================================================================
1734 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
1735 const BLSURFPlugin_Hypothesis* hyp) {
1736 return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
1739 //=============================================================================
1740 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
1741 const BLSURFPlugin_Hypothesis* hyp) {
1742 return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
1745 //=============================================================================
1746 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
1747 const BLSURFPlugin_Hypothesis* hyp) {
1748 return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
1751 //=============================================================================
1752 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
1753 const BLSURFPlugin_Hypothesis* hyp){
1754 return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
1757 //=============================================================================
1758 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
1759 const BLSURFPlugin_Hypothesis* hyp){
1760 return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
1763 //=======================================================================
1764 //function : ClearAllEnforcedVertices
1765 //=======================================================================
1766 void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
1767 _preCadFacesPeriodicityVector.clear();
1768 _preCadEdgesPeriodicityVector.clear();
1769 NotifySubMeshesHypothesisModification();
1772 //=======================================================================
1773 //function : AddPreCadFacesPeriodicity
1774 //=======================================================================
1775 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
1776 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1778 TPreCadPeriodicity preCadFacesPeriodicity;
1779 preCadFacesPeriodicity.shape1Entry = theFace1Entry;
1780 preCadFacesPeriodicity.shape2Entry = theFace2Entry;
1781 preCadFacesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1782 preCadFacesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1784 _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity);
1786 NotifySubMeshesHypothesisModification();
1789 //=======================================================================
1790 //function : AddPreCadEdgesPeriodicity
1791 //=======================================================================
1792 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
1793 std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
1795 TPreCadPeriodicity preCadEdgesPeriodicity;
1796 preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
1797 preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
1798 preCadEdgesPeriodicity.theSourceVerticesEntries = theSourceVerticesEntries;
1799 preCadEdgesPeriodicity.theTargetVerticesEntries = theTargetVerticesEntries;
1801 _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity);
1803 NotifySubMeshesHypothesisModification();
1806 //=============================================================================
1807 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
1808 // We must keep at least the same number of arguments when increasing the SALOME version
1809 // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
1810 // parameter can be written several times to keep the old global number of parameters.
1812 // Treat old options which are now in the advanced options
1813 TOptionValues::iterator op_val;
1815 int _preCADRemoveNanoEdges = -1;
1816 double _preCADEpsNano = -1.0;
1817 op_val = _option2value.find("respect_geometry");
1818 if (op_val != _option2value.end()) {
1819 std::string value = op_val->second;
1821 _decimesh = value.compare("1") == 0 ? 1 : 0;
1823 op_val = _preCADoption2value.find("remove_tiny_edges");
1824 if (op_val != _preCADoption2value.end()) {
1825 std::string value = op_val->second;
1827 _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
1829 op_val = _preCADoption2value.find("tiny_edge_length");
1830 if (op_val != _preCADoption2value.end()) {
1831 std::string value = op_val->second;
1833 _preCADEpsNano = strtod(value.c_str(), NULL);
1836 save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
1837 << _angleMesh << " " << _gradation << " " << (int) _quadAllowed << " " << _decimesh;
1838 save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
1839 save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
1840 save << " " << (int) _enforcedInternalVerticesAllFaces;
1841 save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
1842 save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
1843 save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
1844 save << " " << (int) _preCADProcess3DTopology << " " << (int) _preCADRemoveDuplicateCADFaces << " " << (int) _preCADRemoveTinyUVEdges;
1845 save << " " << (int)_optimiseTinyEdges << " " << _tinyEdgeOptimisationLength;
1846 save << " " << (int)_correctSurfaceIntersec << " " << _corrSurfaceIntersCost;
1847 save << " " << (int)_useGradation << " " << (int)_useVolumeGradation << " " << _volumeGradation;
1849 op_val = _option2value.begin();
1850 if (op_val != _option2value.end()) {
1851 save << " " << "__OPTIONS_BEGIN__";
1852 for (; op_val != _option2value.end(); ++op_val) {
1853 if (!op_val->second.empty())
1854 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1856 save << " " << "__OPTIONS_END__";
1859 op_val = _customOption2value.begin();
1860 if (op_val != _customOption2value.end()) {
1861 save << " " << "__CUSTOM_OPTIONS_BEGIN__";
1862 for (; op_val != _customOption2value.end(); ++op_val) {
1863 if (!op_val->second.empty())
1864 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1866 save << " " << "__CUSTOM_OPTIONS_END__";
1869 op_val = _preCADoption2value.begin();
1870 if (op_val != _preCADoption2value.end()) {
1871 save << " " << "__PRECAD_OPTIONS_BEGIN__";
1872 for (; op_val != _preCADoption2value.end(); ++op_val) {
1873 if (!op_val->second.empty())
1874 save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
1876 save << " " << "__PRECAD_OPTIONS_END__";
1879 TSizeMap::iterator it_sm = _sizeMap.begin();
1880 if (it_sm != _sizeMap.end()) {
1881 save << " " << "__SIZEMAP_BEGIN__";
1882 for (; it_sm != _sizeMap.end(); ++it_sm) {
1883 save << " " << it_sm->first << " " << it_sm->second << "%#"; // "%#" is a mark of value end
1885 save << " " << "__SIZEMAP_END__";
1888 TSizeMap::iterator it_at = _attractors.begin();
1889 if (it_at != _attractors.end()) {
1890 save << " " << "__ATTRACTORS_BEGIN__";
1891 for (; it_at != _attractors.end(); ++it_at) {
1892 save << " " << it_at->first << " " << it_at->second << "%#"; // "%#" is a mark of value end
1894 save << " " << "__ATTRACTORS_END__";
1897 TAttractorMap::iterator it_At = _classAttractors.begin();
1898 if (it_At != _classAttractors.end()) {
1899 std::ostringstream test;
1900 save << " " << "__NEW_ATTRACTORS_BEGIN__";
1901 test << " " << "__NEW_ATTRACTORS_BEGIN__";
1902 for (; it_At != _classAttractors.end(); ++it_At) {
1903 std::vector<double> attParams;
1904 attParams = it_At->second->GetParameters();
1905 // double step = it_At->second->GetStep();
1906 save << " " << it_At->first;
1907 save << " " << it_At->second->GetAttractorEntry();
1908 save << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1909 // save << " " << step;
1910 test << " " << it_At->first;
1911 test << " " << it_At->second->GetAttractorEntry();
1912 test << " " << attParams[0] << " " << attParams[1] << " " << attParams[2] << " " << attParams[3];
1913 // test << " " << step;
1915 save << " " << "__NEW_ATTRACTORS_END__";
1916 test << " " << "__NEW_ATTRACTORS_END__";
1917 MESSAGE(" Attractor hypothesis saved as "<<test.str())
1920 TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
1921 if (it_enf != _enfVertexList.end()) {
1922 save << " " << "__ENFORCED_VERTICES_BEGIN__";
1923 for (; it_enf != _enfVertexList.end(); ++it_enf) {
1924 TEnfVertex *enfVertex = (*it_enf);
1925 save << " " << "__BEGIN_VERTEX__";
1926 if (!enfVertex->name.empty()) {
1927 save << " " << "__BEGIN_NAME__";
1928 save << " " << enfVertex->name;
1929 save << " " << "__END_NAME__";
1931 if (!enfVertex->geomEntry.empty()) {
1932 save << " " << "__BEGIN_ENTRY__";
1933 save << " " << enfVertex->geomEntry;
1934 save << " " << "__END_ENTRY__";
1936 if (!enfVertex->grpName.empty()) {
1937 save << " " << "__BEGIN_GROUP__";
1938 save << " " << enfVertex->grpName;
1939 save << " " << "__END_GROUP__";
1941 if (enfVertex->coords.size()) {
1942 save << " " << "__BEGIN_COORDS__";
1943 for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
1944 save << " " << enfVertex->coords[i];
1945 save << " " << "__END_COORDS__";
1947 TEntryList::const_iterator faceEntriesIt = enfVertex->faceEntries.begin();
1948 bool hasFaces = false;
1949 if (faceEntriesIt != enfVertex->faceEntries.end()) {
1951 save << " " << "__BEGIN_FACELIST__";
1953 for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
1954 save << " " << (*faceEntriesIt);
1956 save << " " << "__END_FACELIST__";
1957 save << " " << "__END_VERTEX__";
1959 save << " " << "__ENFORCED_VERTICES_END__";
1964 SavePreCADPeriodicity(save, "FACES");
1965 SavePreCADPeriodicity(save, "EDGES");
1967 SaveFacesPeriodicity(save);
1968 SaveEdgesPeriodicity(save);
1969 SaveVerticesPeriodicity(save);
1974 void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
1976 TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
1977 if (it_faces_periodicity != _facesPeriodicityVector.end()) {
1978 MESSAGE("__FACES_PERIODICITY_BEGIN__");
1979 save << " " << "__FACES_PERIODICITY_BEGIN__";
1980 for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
1981 TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
1982 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
1983 save << " " << "__BEGIN_ENTRY1__";
1984 save << " " << periodicity_i.first;
1985 save << " " << "__END_ENTRY1__";
1986 save << " " << "__BEGIN_ENTRY2__";
1987 save << " " << periodicity_i.second;
1988 save << " " << "__END_ENTRY2__";
1989 save << " " << "__END_PERIODICITY_DESCRIPTION__";
1991 save << " " << "__FACES_PERIODICITY_END__";
1992 MESSAGE("__FACES_PERIODICITY_END__");
1996 void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
1998 TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
1999 if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
2000 save << " " << "__EDGES_PERIODICITY_BEGIN__";
2001 MESSAGE("__EDGES_PERIODICITY_BEGIN__");
2002 for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
2003 TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
2004 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2005 if (! periodicity_i.theFace1Entry.empty()){
2006 save << " " << "__BEGIN_FACE1__";
2007 save << " " << periodicity_i.theFace1Entry;
2008 save << " " << "__END_FACE1__";
2010 save << " " << "__BEGIN_EDGE1__";
2011 save << " " << periodicity_i.theEdge1Entry;
2012 save << " " << "__END_EDGE1__";
2013 if (! periodicity_i.theFace2Entry.empty()){
2014 save << " " << "__BEGIN_FACE2__";
2015 save << " " << periodicity_i.theFace2Entry;
2016 save << " " << "__END_FACE2__";
2018 save << " " << "__BEGIN_EDGE2__";
2019 save << " " << periodicity_i.theEdge2Entry;
2020 save << " " << "__END_EDGE2__";
2021 save << " " << "__BEGIN_EDGE_ORIENTATION__";
2022 save << " " << periodicity_i.edge_orientation;
2023 save << " " << "__END_EDGE_ORIENTATION__";
2024 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2026 save << " " << "__EDGES_PERIODICITY_END__";
2027 MESSAGE("__EDGES_PERIODICITY_END__");
2031 void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save){
2033 TVerticesPeriodicityVector::const_iterator it_vertices_periodicity = _verticesPeriodicityVector.begin();
2034 if (it_vertices_periodicity != _verticesPeriodicityVector.end()) {
2035 MESSAGE("__VERTICES_PERIODICITY_BEGIN__");
2036 save << " " << "__VERTICES_PERIODICITY_BEGIN__";
2037 for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
2038 TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
2039 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2040 save << " " << "__BEGIN_EDGE1__";
2041 save << " " << periodicity_i.theEdge1Entry;
2042 save << " " << "__END_EDGE1__";
2043 save << " " << "__BEGIN_VERTEX1__";
2044 save << " " << periodicity_i.theVertex1Entry;
2045 save << " " << "__END_VERTEX1__";
2046 save << " " << "__BEGIN_EDGE2__";
2047 save << " " << periodicity_i.theEdge2Entry;
2048 save << " " << "__END_EDGE2__";
2049 save << " " << "__BEGIN_VERTEX2__";
2050 save << " " << periodicity_i.theVertex2Entry;
2051 save << " " << "__END_VERTEX2__";
2052 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2054 save << " " << "__VERTICES_PERIODICITY_END__";
2055 MESSAGE("__VERTICES_PERIODICITY_END__");
2059 void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType) {
2060 TPreCadPeriodicityVector precad_periodicity;
2061 if ( shapeType && strcmp( shapeType, "FACES" ) == 0 )
2062 precad_periodicity = _preCadFacesPeriodicityVector;
2064 precad_periodicity = _preCadEdgesPeriodicityVector;
2065 TPreCadPeriodicityVector::const_iterator it_precad_periodicity = precad_periodicity.begin();
2066 if (it_precad_periodicity != precad_periodicity.end()) {
2067 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_BEGIN__";
2068 for (; it_precad_periodicity != precad_periodicity.end(); ++it_precad_periodicity) {
2069 TPreCadPeriodicity periodicity_i = (*it_precad_periodicity);
2070 save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
2071 if (!periodicity_i.shape1Entry.empty()) {
2072 save << " " << "__BEGIN_ENTRY1__";
2073 save << " " << periodicity_i.shape1Entry;
2074 save << " " << "__END_ENTRY1__";
2076 if (!periodicity_i.shape2Entry.empty()) {
2077 save << " " << "__BEGIN_ENTRY2__";
2078 save << " " << periodicity_i.shape2Entry;
2079 save << " " << "__END_ENTRY2__";
2082 std::vector<std::string>::const_iterator sourceVerticesEntriesIt = periodicity_i.theSourceVerticesEntries.begin();
2083 bool hasSourceVertices = false;
2084 if (sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end()) {
2085 hasSourceVertices = true;
2086 save << " " << "__BEGIN_SOURCE_VERTICES_LIST__";
2088 for (; sourceVerticesEntriesIt != periodicity_i.theSourceVerticesEntries.end(); ++sourceVerticesEntriesIt)
2089 save << " " << (*sourceVerticesEntriesIt);
2090 if (hasSourceVertices)
2091 save << " " << "__END_SOURCE_VERTICES_LIST__";
2093 std::vector<std::string>::const_iterator targetVerticesEntriesIt = periodicity_i.theTargetVerticesEntries.begin();
2094 bool hasTargetVertices = false;
2095 if (targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end()) {
2096 hasTargetVertices = true;
2097 save << " " << "__BEGIN_TARGET_VERTICES_LIST__";
2099 for (; targetVerticesEntriesIt != periodicity_i.theTargetVerticesEntries.end(); ++targetVerticesEntriesIt)
2100 save << " " << (*targetVerticesEntriesIt);
2101 if (hasTargetVertices)
2102 save << " " << "__END_TARGET_VERTICES_LIST__";
2104 save << " " << "__END_PERIODICITY_DESCRIPTION__";
2106 save << " " << "__PRECAD_" << shapeType << "_PERIODICITY_END__";
2111 //=============================================================================
2112 std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
2116 std::string option_or_sm;
2118 isOK = static_cast<bool>(load >> i);
2120 _topology = (Topology) i;
2122 load.clear(std::ios::badbit | load.rdstate());
2124 isOK = static_cast<bool>(load >> i);
2126 _physicalMesh = (PhysicalMesh) i;
2128 load.clear(std::ios::badbit | load.rdstate());
2130 isOK = static_cast<bool>(load >> i);
2132 _geometricMesh = (GeometricMesh) i;
2134 load.clear(std::ios::badbit | load.rdstate());
2136 isOK = static_cast<bool>(load >> val);
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 >> i);
2156 _quadAllowed = (bool) i;
2158 load.clear(std::ios::badbit | load.rdstate());
2160 isOK = static_cast<bool>(load >> i);
2162 if ( i != -1) { // if value is -1, then this is no longer a standard option
2163 std::string & value = _option2value["respect_geometry"];
2164 bool _decimesh = (bool) i;
2165 value = _decimesh ? "1" : "0";
2169 load.clear(std::ios::badbit | load.rdstate());
2171 isOK = static_cast<bool>(load >> val);
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);
2185 // former parameter: get min value
2186 _angleMesh = std::min(val,_angleMesh);
2188 load.clear(std::ios::badbit | load.rdstate());
2190 isOK = static_cast<bool>(load >> val);
2192 // former parameter: get min value
2193 _minSize = std::min(val,_minSize);
2195 load.clear(std::ios::badbit | load.rdstate());
2197 isOK = static_cast<bool>(load >> val);
2199 // former parameter: get max value
2200 _maxSize = std::max(val,_maxSize);
2202 load.clear(std::ios::badbit | load.rdstate());
2204 isOK = static_cast<bool>(load >> i);
2208 load.clear(std::ios::badbit | load.rdstate());
2210 isOK = static_cast<bool>(load >> i);
2212 _preCADMergeEdges = (bool) i;
2214 load.clear(std::ios::badbit | load.rdstate());
2216 isOK = static_cast<bool>(load >> i);
2218 if ( i != -1) { // if value is -1, then this is no longer a standard option
2219 std::string & value = _preCADoption2value["remove_tiny_edges"];
2220 bool _preCADRemoveNanoEdges = (bool) i;
2221 value = _preCADRemoveNanoEdges ? "1" : "0";
2225 load.clear(std::ios::badbit | load.rdstate());
2227 isOK = static_cast<bool>(load >> i);
2229 _preCADDiscardInput = (bool) i;
2231 load.clear(std::ios::badbit | load.rdstate());
2233 isOK = static_cast<bool>(load >> val);
2234 if (isOK) { // _preCADEpsNano
2235 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
2236 std::string & value = _preCADoption2value["tiny_edge_length"];
2237 std::ostringstream oss;
2243 load.clear(std::ios::badbit | load.rdstate());
2245 isOK = static_cast<bool>(load >> i);
2247 _enforcedInternalVerticesAllFaces = (bool) i;
2249 load.clear(std::ios::badbit | load.rdstate());
2251 // New options with MeshGems-CADSurf
2253 bool hasCADSurfOptions = false;
2254 bool hasOptions = false;
2255 bool hasCustomOptions = false;
2256 bool hasPreCADOptions = false;
2257 bool hasSizeMap = false;
2258 bool hasAttractor = false;
2259 bool hasNewAttractor = false;
2260 bool hasEnforcedVertex = false;
2261 bool hasPreCADFacesPeriodicity = false;
2262 bool hasPreCADEdgesPeriodicity = false;
2263 bool hasFacesPeriodicity = false;
2264 bool hasEdgesPeriodicity = false;
2265 bool hasVerticesPeriodicity = false;
2267 isOK = static_cast<bool>(load >> option_or_sm);
2269 if ( (option_or_sm == "1")||(option_or_sm == "0") ) {
2270 i = atoi(option_or_sm.c_str());
2271 hasCADSurfOptions = true;
2272 _phySizeRel = (bool) i;
2274 if (option_or_sm == "__OPTIONS_BEGIN__")
2276 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2277 hasCustomOptions = true;
2278 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2279 hasPreCADOptions = true;
2280 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2282 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2283 hasAttractor = true;
2284 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2285 hasNewAttractor = true;
2286 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2287 hasEnforcedVertex = true;
2288 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2289 hasPreCADFacesPeriodicity = true;
2290 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2291 hasPreCADEdgesPeriodicity = true;
2292 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2293 hasFacesPeriodicity = true;
2294 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2295 hasEdgesPeriodicity = true;
2296 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2297 hasVerticesPeriodicity = true;
2299 if (isOK && hasCADSurfOptions) {
2300 isOK = static_cast<bool>(load >> i);
2302 _minSizeRel = (bool) i;
2304 load.clear(std::ios::badbit | load.rdstate());
2306 isOK = static_cast<bool>(load >> i);
2308 _maxSizeRel = (bool) i;
2310 load.clear(std::ios::badbit | load.rdstate());
2312 isOK = static_cast<bool>(load >> val);
2314 _chordalError = val;
2316 load.clear(std::ios::badbit | load.rdstate());
2318 isOK = static_cast<bool>(load >> i);
2320 _anisotropic = (bool) i;
2322 load.clear(std::ios::badbit | load.rdstate());
2324 isOK = static_cast<bool>(load >> val);
2326 _anisotropicRatio = val;
2328 load.clear(std::ios::badbit | load.rdstate());
2330 isOK = static_cast<bool>(load >> i);
2332 _removeTinyEdges = (bool) i;
2334 load.clear(std::ios::badbit | load.rdstate());
2336 isOK = static_cast<bool>(load >> val);
2338 _tinyEdgeLength = val;
2340 load.clear(std::ios::badbit | load.rdstate());
2342 isOK = static_cast<bool>(load >> i);
2344 _badElementRemoval = (bool) i;
2346 load.clear(std::ios::badbit | load.rdstate());
2348 isOK = static_cast<bool>(load >> val);
2350 _badElementAspectRatio = val;
2352 load.clear(std::ios::badbit | load.rdstate());
2354 isOK = static_cast<bool>(load >> i);
2356 _optimizeMesh = (bool) i;
2358 load.clear(std::ios::badbit | load.rdstate());
2360 isOK = static_cast<bool>(load >> i);
2362 _quadraticMesh = (bool) i;
2364 load.clear(std::ios::badbit | load.rdstate());
2366 isOK = static_cast<bool>(load >> i);
2368 _preCADProcess3DTopology = (bool) i;
2370 load.clear(std::ios::badbit | load.rdstate());
2372 if (( load >> std::ws).peek() != '_' )
2374 isOK = static_cast<bool>(load >> i);
2376 _preCADRemoveDuplicateCADFaces = (bool) i;
2378 load.clear(std::ios::badbit | load.rdstate());
2380 isOK = static_cast<bool>(load >> i);
2382 _preCADRemoveTinyUVEdges = (bool) i;
2384 load.clear(std::ios::badbit | load.rdstate());
2386 isOK = static_cast<bool>(load >> i);
2388 _optimiseTinyEdges = (bool) i;
2390 load.clear(std::ios::badbit | load.rdstate());
2392 isOK = static_cast<bool>(load >> val);
2394 _tinyEdgeOptimisationLength = val;
2396 load.clear(std::ios::badbit | load.rdstate());
2398 isOK = static_cast<bool>(load >> i);
2400 _correctSurfaceIntersec = (bool) i;
2402 load.clear(std::ios::badbit | load.rdstate());
2404 isOK = static_cast<bool>(load >> val);
2406 _corrSurfaceIntersCost = val;
2408 load.clear(std::ios::badbit | load.rdstate());
2410 isOK = static_cast<bool>(load >> i);
2412 _useGradation = (bool) i;
2414 load.clear(std::ios::badbit | load.rdstate());
2416 isOK = static_cast<bool>(load >> i);
2418 _useVolumeGradation = (bool) i;
2420 load.clear(std::ios::badbit | load.rdstate());
2422 isOK = static_cast<bool>(load >> val);
2424 _volumeGradation = val;
2426 load.clear(std::ios::badbit | load.rdstate());
2431 if (hasCADSurfOptions) {
2432 isOK = static_cast<bool>(load >> option_or_sm);
2434 if (option_or_sm == "__OPTIONS_BEGIN__")
2436 else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2437 hasCustomOptions = true;
2438 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2439 hasPreCADOptions = true;
2440 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2442 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2443 hasAttractor = true;
2444 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2445 hasNewAttractor = true;
2446 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2447 hasEnforcedVertex = true;
2448 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2449 hasPreCADFacesPeriodicity = true;
2450 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2451 hasPreCADEdgesPeriodicity = true;
2452 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2453 hasFacesPeriodicity = true;
2454 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2455 hasEdgesPeriodicity = true;
2456 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2457 hasVerticesPeriodicity = true;
2461 std::string optName, optValue;
2462 while (isOK && hasOptions) {
2463 isOK = static_cast<bool>(load >> optName);
2465 if (optName == "__OPTIONS_END__")
2467 isOK = static_cast<bool>(load >> optValue);
2470 std::string & value = _option2value[optName];
2472 int len = value.size();
2473 // continue reading until "%#" encountered
2474 while (value[len - 1] != '#' || value[len - 2] != '%') {
2475 isOK = static_cast<bool>(load >> optValue);
2484 if ( value[ len - 1] == '#' )
2485 value.resize(len - 2); //cut off "%#"
2490 isOK = static_cast<bool>(load >> option_or_sm);
2492 if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
2493 hasCustomOptions = true;
2494 else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2495 hasPreCADOptions = true;
2496 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2498 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2499 hasAttractor = true;
2500 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2501 hasNewAttractor = true;
2502 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2503 hasEnforcedVertex = true;
2504 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2505 hasPreCADFacesPeriodicity = true;
2506 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2507 hasPreCADEdgesPeriodicity = true;
2508 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2509 hasFacesPeriodicity = true;
2510 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2511 hasEdgesPeriodicity = true;
2512 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2513 hasVerticesPeriodicity = true;
2517 while (isOK && hasCustomOptions) {
2518 isOK = static_cast<bool>(load >> optName);
2520 if (optName == "__CUSTOM_OPTIONS_END__")
2522 isOK = static_cast<bool>(load >> optValue);
2525 std::string& value = optValue;
2526 int len = value.size();
2527 // continue reading until "%#" encountered
2528 while (value[len - 1] != '#' || value[len - 2] != '%') {
2529 isOK = static_cast<bool>(load >> optValue);
2538 if ( value[ len - 1] == '#' )
2539 value.resize(len - 2); //cut off "%#"
2540 _customOption2value[optName] = value;
2544 if (hasCustomOptions) {
2545 isOK = static_cast<bool>(load >> option_or_sm);
2547 if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
2548 hasPreCADOptions = true;
2549 else if (option_or_sm == "__SIZEMAP_BEGIN__")
2551 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2552 hasAttractor = true;
2553 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2554 hasNewAttractor = true;
2555 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2556 hasEnforcedVertex = true;
2557 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2558 hasPreCADFacesPeriodicity = true;
2559 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2560 hasPreCADEdgesPeriodicity = true;
2561 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2562 hasFacesPeriodicity = true;
2563 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2564 hasEdgesPeriodicity = true;
2565 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2566 hasVerticesPeriodicity = true;
2570 while (isOK && hasPreCADOptions) {
2571 isOK = static_cast<bool>(load >> optName);
2573 if (optName == "__PRECAD_OPTIONS_END__")
2575 isOK = static_cast<bool>(load >> optValue);
2578 std::string & value = _preCADoption2value[optName];
2580 int len = value.size();
2581 // continue reading until "%#" encountered
2582 while (value[len - 1] != '#' || value[len - 2] != '%') {
2583 isOK = static_cast<bool>(load >> optValue);
2592 if ( value[ len - 1] == '#' )
2593 value.resize(len - 2); //cut off "%#"
2597 if (hasPreCADOptions) {
2598 isOK = static_cast<bool>(load >> option_or_sm);
2600 if (option_or_sm == "__SIZEMAP_BEGIN__")
2602 else if (option_or_sm == "__ATTRACTORS_BEGIN__")
2603 hasAttractor = true;
2604 else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2605 hasNewAttractor = true;
2606 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2607 hasEnforcedVertex = true;
2608 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2609 hasPreCADFacesPeriodicity = true;
2610 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2611 hasPreCADEdgesPeriodicity = true;
2612 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2613 hasFacesPeriodicity = true;
2614 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2615 hasEdgesPeriodicity = true;
2616 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2617 hasVerticesPeriodicity = true;
2621 std::string smEntry, smValue;
2622 while (isOK && hasSizeMap) {
2623 isOK = static_cast<bool>(load >> smEntry);
2625 if (smEntry == "__SIZEMAP_END__")
2627 isOK = static_cast<bool>(load >> smValue);
2630 std::string & value2 = _sizeMap[smEntry];
2632 int len2 = value2.size();
2633 // continue reading until "%#" encountered
2634 while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
2635 isOK = static_cast<bool>(load >> smValue);
2639 len2 = value2.size();
2644 value2.resize(len2 - 2); //cut off "%#"
2649 isOK = static_cast<bool>(load >> option_or_sm);
2651 if (option_or_sm == "__ATTRACTORS_BEGIN__")
2652 hasAttractor = true;
2653 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2654 hasNewAttractor = true;
2655 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2656 hasEnforcedVertex = true;
2657 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2658 hasPreCADFacesPeriodicity = true;
2659 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2660 hasPreCADEdgesPeriodicity = true;
2661 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2662 hasFacesPeriodicity = true;
2663 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2664 hasEdgesPeriodicity = true;
2665 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2666 hasVerticesPeriodicity = true;
2669 std::string atEntry, atValue;
2670 while (isOK && hasAttractor) {
2671 isOK = static_cast<bool>(load >> atEntry);
2673 if (atEntry == "__ATTRACTORS_END__")
2675 isOK = static_cast<bool>(load >> atValue);
2678 std::string & value3 = _attractors[atEntry];
2680 int len3 = value3.size();
2681 // continue reading until "%#" encountered
2682 while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
2683 isOK = static_cast<bool>(load >> atValue);
2687 len3 = value3.size();
2692 value3.resize(len3 - 2); //cut off "%#"
2697 isOK = static_cast<bool>(load >> option_or_sm);
2699 if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
2700 hasNewAttractor = true;
2701 else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2702 hasEnforcedVertex = true;
2703 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2704 hasPreCADFacesPeriodicity = true;
2705 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2706 hasPreCADEdgesPeriodicity = true;
2707 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2708 hasFacesPeriodicity = true;
2709 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2710 hasEdgesPeriodicity = true;
2711 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2712 hasVerticesPeriodicity = true;
2716 std::string newAtFaceEntry, atTestString;
2717 std::string newAtShapeEntry;
2718 double attParams[4];
2720 while (isOK && hasNewAttractor) {
2721 //std::cout<<"Load new attractor"<<std::endl;
2722 isOK = static_cast<bool>(load >> newAtFaceEntry);
2724 if (newAtFaceEntry == "__NEW_ATTRACTORS_END__")
2726 isOK = static_cast<bool>(load >> newAtShapeEntry);
2729 isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
2732 MESSAGE(" LOADING ATTRACTOR HYPOTHESIS ")
2733 const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
2734 const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
2735 BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
2736 attractor->SetParameters(attParams[0], attParams[1], attParams[2], attParams[3]);
2737 //attractor->BuildMap();
2738 _classAttractors.insert( make_pair( newAtFaceEntry, attractor ));
2743 if (hasNewAttractor) {
2744 isOK = static_cast<bool>(load >> option_or_sm);
2746 if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
2747 hasEnforcedVertex = true;
2748 else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
2749 hasPreCADFacesPeriodicity = true;
2750 else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2751 hasPreCADEdgesPeriodicity = true;
2752 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2753 hasFacesPeriodicity = true;
2754 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2755 hasEdgesPeriodicity = true;
2756 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2757 hasVerticesPeriodicity = true;
2763 // Here is a example of the saved stream:
2764 // __ENFORCED_VERTICES_BEGIN__
2765 // __BEGIN_VERTEX__ => no name, no entry
2766 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2767 // __BEGIN_COORDS__ 10 10 10 __END_COORDS__
2768 // __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__
2770 // __BEGIN_VERTEX__ => no coords
2771 // __BEGIN_NAME__ mes points __END_NAME__
2772 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
2773 // __BEGIN_GROUP__ mon groupe __END_GROUP__
2774 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
2776 // __ENFORCED_VERTICES_END__
2779 std::string enfSeparator;
2780 std::string enfName;
2781 std::string enfGeomEntry;
2782 std::string enfGroup;
2783 TEntryList enfFaceEntryList;
2784 double enfCoords[3];
2785 bool hasCoords = false;
2787 _faceEntryEnfVertexListMap.clear();
2788 _enfVertexList.clear();
2789 _faceEntryCoordsListMap.clear();
2790 _coordsEnfVertexMap.clear();
2791 _faceEntryEnfVertexEntryListMap.clear();
2792 _enfVertexEntryEnfVertexMap.clear();
2795 while (isOK && hasEnforcedVertex) {
2796 isOK = static_cast<bool>(load >> enfSeparator); // __BEGIN_VERTEX__
2797 TEnfVertex *enfVertex = new TEnfVertex();
2798 // MESSAGE("enfSeparator: " <<enfSeparator);
2799 if (enfSeparator == "__ENFORCED_VERTICES_END__")
2800 break; // __ENFORCED_VERTICES_END__
2801 if (enfSeparator != "__BEGIN_VERTEX__")
2802 throw std::exception();
2805 isOK = static_cast<bool>(load >> enfSeparator);
2806 MESSAGE("enfSeparator: " <<enfSeparator);
2807 if (enfSeparator == "__END_VERTEX__") {
2809 enfVertex->name = enfName;
2810 enfVertex->geomEntry = enfGeomEntry;
2811 enfVertex->grpName = enfGroup;
2812 enfVertex->coords.clear();
2814 enfVertex->coords.assign(enfCoords,enfCoords+3);
2815 enfVertex->faceEntries = enfFaceEntryList;
2817 _enfVertexList.insert(enfVertex);
2819 if (enfVertex->coords.size()) {
2820 _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
2821 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2822 _faceEntryCoordsListMap[(*it)].insert(enfVertex->coords);
2823 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2826 if (!enfVertex->geomEntry.empty()) {
2827 _enfVertexEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex;
2828 for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
2829 _faceEntryEnfVertexEntryListMap[(*it)].insert(enfVertex->geomEntry);
2830 _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
2835 enfGeomEntry.clear();
2837 enfFaceEntryList.clear();
2839 break; // __END_VERTEX__
2842 if (enfSeparator == "__BEGIN_NAME__") { // __BEGIN_NAME__
2843 while (isOK && (enfSeparator != "__END_NAME__")) {
2844 isOK = static_cast<bool>(load >> enfSeparator);
2845 if (enfSeparator != "__END_NAME__") {
2846 if (!enfName.empty())
2848 enfName += enfSeparator;
2851 MESSAGE("enfName: " <<enfName);
2854 if (enfSeparator == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__
2855 isOK = static_cast<bool>(load >> enfGeomEntry);
2856 isOK = static_cast<bool>(load >> enfSeparator); // __END_ENTRY__
2857 if (enfSeparator != "__END_ENTRY__")
2858 throw std::exception();
2859 MESSAGE("enfGeomEntry: " <<enfGeomEntry);
2862 if (enfSeparator == "__BEGIN_GROUP__") { // __BEGIN_GROUP__
2863 while (isOK && (enfSeparator != "__END_GROUP__")) {
2864 isOK = static_cast<bool>(load >> enfSeparator);
2865 if (enfSeparator != "__END_GROUP__") {
2866 if (!enfGroup.empty())
2868 enfGroup += enfSeparator;
2871 MESSAGE("enfGroup: " <<enfGroup);
2874 if (enfSeparator == "__BEGIN_COORDS__") { // __BEGIN_COORDS__
2876 isOK = static_cast<bool>(load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
2877 isOK = static_cast<bool>(load >> enfSeparator); // __END_COORDS__
2878 if (enfSeparator != "__END_COORDS__")
2879 throw std::exception();
2880 MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
2883 if (enfSeparator == "__BEGIN_FACELIST__") { // __BEGIN_FACELIST__
2884 while (isOK && (enfSeparator != "__END_FACELIST__")) {
2885 isOK = static_cast<bool>(load >> enfSeparator);
2886 if (enfSeparator != "__END_FACELIST__") {
2887 enfFaceEntryList.insert(enfSeparator);
2888 MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
2897 if (hasPreCADFacesPeriodicity){
2898 LoadPreCADPeriodicity(load, "FACES");
2900 isOK = static_cast<bool>(load >> option_or_sm);
2902 if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
2903 hasPreCADEdgesPeriodicity = true;
2904 else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2905 hasFacesPeriodicity = true;
2906 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2907 hasEdgesPeriodicity = true;
2908 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2909 hasVerticesPeriodicity = true;
2913 if (hasPreCADEdgesPeriodicity){
2914 LoadPreCADPeriodicity(load, "EDGES");
2916 isOK = static_cast<bool>(load >> option_or_sm);
2918 if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
2919 hasFacesPeriodicity = true;
2920 else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2921 hasEdgesPeriodicity = true;
2922 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2923 hasVerticesPeriodicity = true;
2927 if (hasFacesPeriodicity){
2928 LoadFacesPeriodicity(load);
2930 isOK = static_cast<bool>(load >> option_or_sm);
2932 if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
2933 hasEdgesPeriodicity = true;
2934 else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2935 hasVerticesPeriodicity = true;
2939 if (hasEdgesPeriodicity){
2940 LoadEdgesPeriodicity(load);
2942 isOK = static_cast<bool>(load >> option_or_sm);
2944 if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
2945 hasVerticesPeriodicity = true;
2948 if (hasVerticesPeriodicity)
2949 LoadVerticesPeriodicity(load);
2954 void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
2958 std::string periodicitySeparator;
2962 _facesPeriodicityVector.clear();
2965 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
2966 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
2967 TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
2968 if (periodicitySeparator == "__FACES_PERIODICITY_END__")
2969 break; // __FACES_PERIODICITY_END__
2970 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
2971 MESSAGE("//" << periodicitySeparator << "//");
2972 throw std::exception();
2976 isOK = static_cast<bool>(load >> periodicitySeparator);
2977 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
2978 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
2980 periodicity_i->first = shape1Entry;
2981 periodicity_i->second = shape2Entry;
2983 _facesPeriodicityVector.push_back(*periodicity_i);
2985 break; // __END_PERIODICITY_DESCRIPTION__
2988 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
2989 isOK = static_cast<bool>(load >> shape1Entry);
2990 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
2991 if (periodicitySeparator != "__END_ENTRY1__")
2992 throw std::exception();
2993 MESSAGE("shape1Entry: " <<shape1Entry);
2996 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
2997 isOK = static_cast<bool>(load >> shape2Entry);
2998 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
2999 if (periodicitySeparator != "__END_ENTRY2__")
3000 throw std::exception();
3001 MESSAGE("shape2Entry: " <<shape2Entry);
3008 void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
3012 std::string periodicitySeparator;
3013 TEntry theFace1Entry;
3014 TEntry theEdge1Entry;
3015 TEntry theFace2Entry;
3016 TEntry theEdge2Entry;
3017 int edge_orientation = 0;
3019 _edgesPeriodicityVector.clear();
3022 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3023 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3024 TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
3025 if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
3026 break; // __EDGES_PERIODICITY_END__
3027 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3028 MESSAGE("//" << periodicitySeparator << "//");
3029 throw std::exception();
3033 isOK = static_cast<bool>(load >> periodicitySeparator);
3034 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3035 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3037 periodicity_i->theFace1Entry = theFace1Entry;
3038 periodicity_i->theEdge1Entry = theEdge1Entry;
3039 periodicity_i->theFace2Entry = theFace2Entry;
3040 periodicity_i->theEdge2Entry = theEdge2Entry;
3041 periodicity_i->edge_orientation = edge_orientation;
3043 _edgesPeriodicityVector.push_back(*periodicity_i);
3045 break; // __END_PERIODICITY_DESCRIPTION__
3048 if (periodicitySeparator == "__BEGIN_FACE1__") { // __BEGIN_FACE1__
3049 isOK = static_cast<bool>(load >> theFace1Entry);
3050 MESSAGE("//" << theFace1Entry << "//");
3051 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE1__
3052 if (periodicitySeparator != "__END_FACE1__"){
3053 MESSAGE("//" << periodicitySeparator << "//");
3054 throw std::exception();
3056 MESSAGE("theFace1Entry: " <<theFace1Entry);
3059 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3060 isOK = static_cast<bool>(load >> theEdge1Entry);
3061 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3062 if (periodicitySeparator != "__END_EDGE1__")
3063 throw std::exception();
3064 MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3067 if (periodicitySeparator == "__BEGIN_FACE2__") { // __BEGIN_FACE2__
3068 isOK = static_cast<bool>(load >> theFace2Entry);
3069 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE2__
3070 if (periodicitySeparator != "__END_FACE2__")
3071 throw std::exception();
3072 MESSAGE("theFace2Entry: " <<theFace2Entry);
3075 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3076 isOK = static_cast<bool>(load >> theEdge2Entry);
3077 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3078 if (periodicitySeparator != "__END_EDGE2__")
3079 throw std::exception();
3080 MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3083 if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") { // __BEGIN_EDGE_ORIENTATION__
3084 isOK = static_cast<bool>(load >> edge_orientation);
3085 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
3086 if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
3087 throw std::exception();
3088 MESSAGE("edge_orientation: " <<edge_orientation);
3094 void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
3098 std::string periodicitySeparator;
3099 TEntry theEdge1Entry;
3100 TEntry theVertex1Entry;
3101 TEntry theEdge2Entry;
3102 TEntry theVertex2Entry;
3104 _verticesPeriodicityVector.clear();
3107 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3108 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3109 TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
3110 if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
3111 break; // __VERTICES_PERIODICITY_END__
3112 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3113 MESSAGE("//" << periodicitySeparator << "//");
3114 throw std::exception();
3118 isOK = static_cast<bool>(load >> periodicitySeparator);
3119 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3120 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3122 periodicity_i->theEdge1Entry = theEdge1Entry;
3123 periodicity_i->theVertex1Entry = theVertex1Entry;
3124 periodicity_i->theEdge2Entry = theEdge2Entry;
3125 periodicity_i->theVertex2Entry = theVertex2Entry;
3127 _verticesPeriodicityVector.push_back(*periodicity_i);
3129 break; // __END_PERIODICITY_DESCRIPTION__
3132 if (periodicitySeparator == "__BEGIN_EDGE1__") { // __BEGIN_EDGE1__
3133 isOK = static_cast<bool>(load >> theEdge1Entry);
3134 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
3135 if (periodicitySeparator != "__END_EDGE1__")
3136 throw std::exception();
3137 MESSAGE("theEdge1Entry: " <<theEdge1Entry);
3140 if (periodicitySeparator == "__BEGIN_VERTEX1__") { // __BEGIN_VERTEX1__
3141 isOK = static_cast<bool>(load >> theVertex1Entry);
3142 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX1__
3143 if (periodicitySeparator != "__END_VERTEX1__")
3144 throw std::exception();
3145 MESSAGE("theVertex1Entry: " <<theVertex1Entry);
3148 if (periodicitySeparator == "__BEGIN_EDGE2__") { // __BEGIN_EDGE2__
3149 isOK = static_cast<bool>(load >> theEdge2Entry);
3150 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
3151 if (periodicitySeparator != "__END_EDGE2__")
3152 throw std::exception();
3153 MESSAGE("theEdge2Entry: " <<theEdge2Entry);
3156 if (periodicitySeparator == "__BEGIN_VERTEX2__") { // __BEGIN_VERTEX2__
3157 isOK = static_cast<bool>(load >> theVertex2Entry);
3158 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX2__
3159 if (periodicitySeparator != "__END_VERTEX2__")
3160 throw std::exception();
3161 MESSAGE("theVertex2Entry: " <<theVertex2Entry);
3167 void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
3171 std::string periodicitySeparator;
3174 std::vector<std::string> theSourceVerticesEntries;
3175 std::vector<std::string> theTargetVerticesEntries;
3177 bool hasSourceVertices = false;
3178 bool hasTargetVertices = false;
3180 if ( shapeType && strcmp( shapeType, "FACES") == 0 )
3181 _preCadFacesPeriodicityVector.clear();
3183 _preCadEdgesPeriodicityVector.clear();
3187 isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
3188 MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
3189 TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
3190 // MESSAGE("periodicitySeparator: " <<periodicitySeparator);
3191 std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
3192 if (periodicitySeparator == endSeparator)
3193 break; // __PRECAD_FACES_PERIODICITY_END__
3194 if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
3195 MESSAGE("//" << endSeparator << "//");
3196 MESSAGE("//" << periodicitySeparator << "//");
3197 throw std::exception();
3201 isOK = static_cast<bool>(load >> periodicitySeparator);
3202 MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
3203 if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
3205 periodicity_i->shape1Entry = shape1Entry;
3206 periodicity_i->shape2Entry = shape2Entry;
3208 MESSAGE("theSourceVerticesEntries.size(): " << theSourceVerticesEntries.size());
3209 MESSAGE("theTargetVerticesEntries.size(): " << theTargetVerticesEntries.size());
3211 if (hasSourceVertices)
3212 periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
3213 if (hasTargetVertices)
3214 periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
3216 if ( shapeType && strcmp( shapeType, "FACES" ))
3217 _preCadFacesPeriodicityVector.push_back(*periodicity_i);
3219 _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
3221 theSourceVerticesEntries.clear();
3222 theTargetVerticesEntries.clear();
3223 hasSourceVertices = false;
3224 hasTargetVertices = false;
3225 break; // __END_PERIODICITY_DESCRIPTION__
3228 if (periodicitySeparator == "__BEGIN_ENTRY1__") { // __BEGIN_ENTRY1__
3229 isOK = static_cast<bool>(load >> shape1Entry);
3230 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
3231 if (periodicitySeparator != "__END_ENTRY1__")
3232 throw std::exception();
3233 MESSAGE("shape1Entry: " <<shape1Entry);
3236 if (periodicitySeparator == "__BEGIN_ENTRY2__") { // __BEGIN_ENTRY2__
3237 isOK = static_cast<bool>(load >> shape2Entry);
3238 isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
3239 if (periodicitySeparator != "__END_ENTRY2__")
3240 throw std::exception();
3241 MESSAGE("shape2Entry: " <<shape2Entry);
3244 if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") { // __BEGIN_SOURCE_VERTICES_LIST__
3245 hasSourceVertices = true;
3246 while (isOK && (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__")) {
3247 isOK = static_cast<bool>(load >> periodicitySeparator);
3248 if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
3249 theSourceVerticesEntries.push_back(periodicitySeparator);
3250 MESSAGE("theSourceVerticesEntries: " <<periodicitySeparator);
3255 if (periodicitySeparator == "__BEGIN_TARGET_VERTICES_LIST__") { // __BEGIN_TARGET_VERTICES_LIST__
3256 hasTargetVertices = true;
3257 while (isOK && (periodicitySeparator != "__END_TARGET_VERTICES_LIST__")) {
3258 isOK = static_cast<bool>(load >> periodicitySeparator);
3259 if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
3260 theTargetVerticesEntries.push_back(periodicitySeparator);
3261 MESSAGE("theTargetVerticesEntries: " <<periodicitySeparator);
3269 //=============================================================================
3270 std::ostream & operator <<(std::ostream & save, BLSURFPlugin_Hypothesis & hyp) {
3271 return hyp.SaveTo(save);
3274 //=============================================================================
3275 std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
3276 return hyp.LoadFrom(load);
3279 //================================================================================
3281 * \brief Does nothing
3283 //================================================================================
3285 bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
3289 //================================================================================
3291 * \brief Returns default global constant physical size given a default value of element length ratio
3293 //================================================================================
3295 double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
3296 if (bbSegmentation != 0 && diagonal != 0)
3297 return diagonal / bbSegmentation ;
3301 //================================================================================
3303 * \brief Returns default min size given a default value of element length ratio
3305 //================================================================================
3307 double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
3309 return diagonal / 1000.0 ;
3310 return undefinedDouble();
3313 //================================================================================
3315 * \brief Returns default max size given a default value of element length ratio
3317 //================================================================================
3319 double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
3321 return diagonal / 5.0 ;
3322 return undefinedDouble();
3325 //================================================================================
3327 * \brief Returns default chordal error given a default value of element length ratio
3329 //================================================================================
3331 double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
3334 return undefinedDouble();
3337 //================================================================================
3339 * \brief Returns default tiny edge length given a default value of element length ratio
3341 //================================================================================
3343 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
3345 return diagonal * 1e-6 ;
3346 return undefinedDouble();
3349 //================================================================================
3351 * \brief Returns default tiny edge optimisation length given a default value of element length ratio
3353 //================================================================================
3355 double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal) {
3357 return diagonal * 1e-6 ;
3358 return undefinedDouble();
3361 //=============================================================================
3363 * \brief Initialize my parameter values by default parameters.
3364 * \retval bool - true if parameter values have been successfully defined
3366 //=============================================================================
3368 bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
3369 double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
3370 _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
3371 _minSize = GetDefaultMinSize(diagonal);
3372 _maxSize = GetDefaultMaxSize(diagonal);
3373 _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
3374 _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
3375 _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(diagonal);
3380 //================================================================================
3382 * \brief Converts a string to a bool
3384 //================================================================================
3386 bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
3387 throw (std::invalid_argument)
3389 std::string s = str;
3390 if ( isOk ) *isOk = true;
3392 for ( size_t i = 0; i <= s.size(); ++i )
3393 s[i] = tolower( s[i] );
3395 if ( s == "1" || s == "true" || s == "active" || s == "yes" )
3398 if ( s == "0" || s == "false" || s == "inactive" || s == "no" )
3404 std::string msg = "Not a Boolean value:'" + str + "'";
3405 throw std::invalid_argument(msg);
3410 //================================================================================
3412 * \brief Converts a string to a real value
3414 //================================================================================
3416 double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
3417 throw (std::invalid_argument)
3419 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3422 double val = strtod(&str[0], &endPtr);
3423 bool ok = (&str[0] != endPtr);
3425 if ( isOk ) *isOk = ok;
3429 std::string msg = "Not a real value:'" + str + "'";
3430 throw std::invalid_argument(msg);
3435 //================================================================================
3437 * \brief Converts a string to a integer value
3439 //================================================================================
3441 int BLSURFPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
3442 throw (std::invalid_argument)
3444 if ( str.empty() ) throw std::invalid_argument("Empty value provided");
3447 int val = (int)strtol( &str[0], &endPtr, 10);
3448 bool ok = (&str[0] != endPtr);
3450 if ( isOk ) *isOk = ok;
3454 std::string msg = "Not an integer value:'" + str + "'";
3455 throw std::invalid_argument(msg);