1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // NETGENPlugin : C++ implementation
24 // File : NETGENPlugin_Hypothesis.cxx
25 // Author : Michael Sazonov (OCN)
29 #include "NETGENPlugin_Hypothesis.hxx"
31 #include "NETGENPlugin_Mesher.hxx"
32 #include "SMESH_Mesh.hxx"
34 #include <utilities.h>
38 //=============================================================================
42 //=============================================================================
43 NETGENPlugin_Hypothesis::NETGENPlugin_Hypothesis (int hypId, SMESH_Gen * gen)
45 : SMESH_Hypothesis(hypId, gen),
46 _fineness (GetDefaultFineness()),
47 _secondOrder (GetDefaultSecondOrder()),
48 _quadAllowed (GetDefaultQuadAllowed()),
49 _maxSize (GetDefaultMaxSize()),
51 _growthRate (GetDefaultGrowthRate()),
52 _nbSegPerRadius (GetDefaultNbSegPerRadius()),
53 _nbSegPerEdge (GetDefaultNbSegPerEdge()),
54 _chordalErrorEnabled(GetDefaultChordalError() > 0),
55 _chordalError (GetDefaultChordalError() ),
56 _optimize (GetDefaultOptimize()),
57 _nbSurfOptSteps (GetDefaultNbSurfOptSteps()),
58 _nbVolOptSteps (GetDefaultNbVolOptSteps()),
59 _elemSizeWeight (GetDefaultElemSizeWeight()),
60 _worstElemMeasure (GetDefaultWorstElemMeasure()),
61 _surfaceCurvature (GetDefaultSurfaceCurvature()),
62 _useDelauney (GetDefaultUseDelauney()),
63 _checkOverlapping (GetDefaultCheckOverlapping()),
64 _checkChartBoundary (GetDefaultCheckChartBoundary()),
65 _fuseEdges (GetDefaultFuseEdges())
67 _name = "NETGEN_Parameters";
71 //=============================================================================
75 //=============================================================================
76 void NETGENPlugin_Hypothesis::SetMaxSize(double theSize)
78 if (theSize != _maxSize)
81 NotifySubMeshesHypothesisModification();
85 //=============================================================================
89 //=============================================================================
90 void NETGENPlugin_Hypothesis::SetMinSize(double theSize)
92 if (theSize != _minSize)
95 NotifySubMeshesHypothesisModification();
99 //=============================================================================
103 //=============================================================================
104 void NETGENPlugin_Hypothesis::SetSecondOrder(bool theVal)
106 if (theVal != _secondOrder)
108 _secondOrder = theVal;
109 NotifySubMeshesHypothesisModification();
113 //=============================================================================
117 //=============================================================================
118 void NETGENPlugin_Hypothesis::SetOptimize(bool theVal)
120 if (theVal != _optimize)
123 NotifySubMeshesHypothesisModification();
127 //=============================================================================
131 //=============================================================================
132 void NETGENPlugin_Hypothesis::SetFineness(Fineness theFineness)
134 if (theFineness != _fineness)
136 _fineness = theFineness;
137 // the predefined values are taken from NETGEN 4.5 sources
148 _nbSegPerRadius = 1.5;
169 NotifySubMeshesHypothesisModification();
173 //=============================================================================
177 //=============================================================================
178 void NETGENPlugin_Hypothesis::SetGrowthRate(double theRate)
180 if (theRate != _growthRate)
182 _growthRate = theRate;
183 _fineness = UserDefined;
184 NotifySubMeshesHypothesisModification();
188 //=============================================================================
192 //=============================================================================
193 void NETGENPlugin_Hypothesis::SetNbSegPerEdge(double theVal)
195 if (theVal != _nbSegPerEdge)
197 _nbSegPerEdge = theVal;
198 _fineness = UserDefined;
199 NotifySubMeshesHypothesisModification();
203 //=============================================================================
207 //=============================================================================
208 void NETGENPlugin_Hypothesis::SetNbSegPerRadius(double theVal)
210 if (theVal != _nbSegPerRadius)
212 _nbSegPerRadius = theVal;
213 _fineness = UserDefined;
214 NotifySubMeshesHypothesisModification();
218 //=============================================================================
222 //=============================================================================
223 void NETGENPlugin_Hypothesis::SetChordalErrorEnabled(bool theVal)
225 if (theVal != _chordalErrorEnabled)
227 _chordalErrorEnabled = theVal;
228 NotifySubMeshesHypothesisModification();
232 //=============================================================================
236 //=============================================================================
237 void NETGENPlugin_Hypothesis::SetChordalError(double theVal)
239 if (theVal != _chordalError)
241 _chordalError = theVal;
242 NotifySubMeshesHypothesisModification();
246 //=============================================================================
250 //=============================================================================
251 void NETGENPlugin_Hypothesis::SetLocalSizeOnEntry(const std::string& entry, double localSize)
253 if(_localSize[entry] != localSize)
255 _localSize[entry] = localSize;
256 NotifySubMeshesHypothesisModification();
260 //=============================================================================
264 //=============================================================================
265 double NETGENPlugin_Hypothesis::GetLocalSizeOnEntry(const std::string& entry)
267 TLocalSize::iterator it = _localSize.find( entry );
268 if ( it != _localSize.end() )
274 //=============================================================================
278 //=============================================================================
279 void NETGENPlugin_Hypothesis::UnsetLocalSizeOnEntry(const std::string& entry)
281 _localSize.erase(entry);
282 NotifySubMeshesHypothesisModification();
285 //=============================================================================
289 //=============================================================================
290 void NETGENPlugin_Hypothesis::SetMeshSizeFile(const std::string& fileName)
292 if ( fileName != _meshSizeFile )
294 _meshSizeFile = fileName;
295 NotifySubMeshesHypothesisModification();
299 //=============================================================================
303 //=============================================================================
304 void NETGENPlugin_Hypothesis::SetQuadAllowed(bool theVal)
306 if (theVal != _quadAllowed)
308 _quadAllowed = theVal;
309 NotifySubMeshesHypothesisModification();
313 //=============================================================================
317 //=============================================================================
318 void NETGENPlugin_Hypothesis::SetSurfaceCurvature(bool theVal)
320 if (theVal != _surfaceCurvature)
322 _surfaceCurvature = theVal;
323 NotifySubMeshesHypothesisModification();
327 //=============================================================================
331 //=============================================================================
332 void NETGENPlugin_Hypothesis::SetFuseEdges(bool theVal)
334 if (theVal != _fuseEdges)
337 NotifySubMeshesHypothesisModification();
341 //=======================================================================
342 //function : SetNbSurfOptSteps
344 //=======================================================================
346 void NETGENPlugin_Hypothesis::SetNbSurfOptSteps( int theVal )
348 if (theVal != _nbSurfOptSteps)
350 _nbSurfOptSteps = theVal;
351 NotifySubMeshesHypothesisModification();
355 //=======================================================================
356 //function : SetNbVolOptSteps
358 //=======================================================================
360 void NETGENPlugin_Hypothesis::SetNbVolOptSteps( int theVal )
362 if (theVal != _nbVolOptSteps)
364 _nbVolOptSteps = theVal;
365 NotifySubMeshesHypothesisModification();
369 //=======================================================================
370 //function : SetElemSizeWeight
372 //=======================================================================
374 void NETGENPlugin_Hypothesis::SetElemSizeWeight( double theVal )
376 if (theVal != _elemSizeWeight)
378 _elemSizeWeight = theVal;
379 NotifySubMeshesHypothesisModification();
383 //=======================================================================
384 //function : SetWorstElemMeasure
386 //=======================================================================
388 void NETGENPlugin_Hypothesis::SetWorstElemMeasure( int theVal )
390 if (theVal != _worstElemMeasure)
392 _worstElemMeasure = theVal;
393 NotifySubMeshesHypothesisModification();
397 //=======================================================================
398 //function : SetUseDelauney
400 //=======================================================================
402 void NETGENPlugin_Hypothesis::SetUseDelauney( bool theVal )
404 if (theVal != _useDelauney )
406 _useDelauney = theVal;
407 NotifySubMeshesHypothesisModification();
411 //=======================================================================
412 //function : SetCheckOverlapping
414 //=======================================================================
416 void NETGENPlugin_Hypothesis::SetCheckOverlapping( bool theVal )
418 if (theVal != _checkOverlapping )
420 _checkOverlapping = theVal;
421 NotifySubMeshesHypothesisModification();
425 //=======================================================================
426 //function : SetCheckChartBoundary
428 //=======================================================================
430 void NETGENPlugin_Hypothesis::SetCheckChartBoundary( bool theVal )
432 if (theVal != _checkChartBoundary)
434 _checkChartBoundary = theVal;
435 NotifySubMeshesHypothesisModification();
439 //=============================================================================
443 //=============================================================================
444 ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
446 save << _maxSize << " " << _fineness;
448 if (_fineness == UserDefined)
449 save << " " << _growthRate << " " << _nbSegPerEdge << " " << _nbSegPerRadius;
451 save << " " << (int)_secondOrder << " " << (int)_optimize;
453 TLocalSize::iterator it_sm = _localSize.begin();
454 if (it_sm != _localSize.end()) {
455 save << " " << "__LOCALSIZE_BEGIN__";
456 for ( ; it_sm != _localSize.end(); ++it_sm ) {
457 save << " " << it_sm->first
458 << " " << it_sm->second << "%#"; // "%#" is a mark of value end
460 save << " " << "__LOCALSIZE_END__";
462 save << " " << _minSize;
463 save << " " << _quadAllowed;
464 save << " " << _surfaceCurvature;
465 save << " " << _fuseEdges;
467 save << " " << _meshSizeFile.size() << " " << _meshSizeFile;
469 save << " " << ( _chordalErrorEnabled ? _chordalError : 0. );
472 // added for option set completion
474 save << " " << _nbSurfOptSteps;
475 save << " " << _nbVolOptSteps;
476 save << " " << _elemSizeWeight;
477 save << " " << _worstElemMeasure;
479 save << " " << _useDelauney;
480 save << " " << _checkOverlapping;
481 save << " " << _checkChartBoundary;
486 //=============================================================================
490 //=============================================================================
491 istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
497 isOK = static_cast<bool>(load >> val);
501 load.clear(ios::badbit | load.rdstate());
503 isOK = static_cast<bool>(load >> is);
505 SetFineness((Fineness) is);
507 load.clear(ios::badbit | load.rdstate());
509 if (_fineness == UserDefined)
511 isOK = static_cast<bool>(load >> val);
515 load.clear(ios::badbit | load.rdstate());
517 isOK = static_cast<bool>(load >> val);
521 load.clear(ios::badbit | load.rdstate());
523 isOK = static_cast<bool>(load >> val);
525 _nbSegPerRadius = val;
527 load.clear(ios::badbit | load.rdstate());
530 isOK = static_cast<bool>(load >> is);
532 _secondOrder = (bool) is;
534 load.clear(ios::badbit | load.rdstate());
536 isOK = static_cast<bool>(load >> is);
538 _optimize = (bool) is;
540 load.clear(ios::badbit | load.rdstate());
542 std::string option_or_sm;
543 bool hasLocalSize = false;
545 isOK = static_cast<bool>(load >> option_or_sm);
547 if (option_or_sm == "__LOCALSIZE_BEGIN__")
550 std::string smEntry, smValue;
551 while (isOK && hasLocalSize) {
552 isOK = static_cast<bool>(load >> smEntry);
554 if (smEntry == "__LOCALSIZE_END__")
556 isOK = static_cast<bool>(load >> smValue);
559 std::istringstream tmp(smValue);
562 _localSize[ smEntry ] = val;
566 if ( !hasLocalSize && !option_or_sm.empty() )
567 _minSize = atof( option_or_sm.c_str() );
571 isOK = static_cast<bool>( load >> is );
573 _quadAllowed = (bool) is;
575 _quadAllowed = GetDefaultQuadAllowed();
577 isOK = static_cast<bool>( load >> is );
579 _surfaceCurvature = (bool) is;
581 _surfaceCurvature = GetDefaultSurfaceCurvature();
583 isOK = static_cast<bool>( load >> is );
585 _fuseEdges = (bool) is;
587 _fuseEdges = GetDefaultFuseEdges();
589 isOK = static_cast<bool>( load >> is >> std::ws ); // size of meshSizeFile
590 if ( isOK && is > 0 )
592 _meshSizeFile.resize( is );
593 load.get( &_meshSizeFile[0], is+1 );
596 isOK = static_cast<bool>(load >> val);
600 load.clear(ios::badbit | load.rdstate());
601 _chordalErrorEnabled = ( _chordalError > 0 );
604 // added for option set completion
606 isOK = static_cast<bool>( load >> is );
608 _nbSurfOptSteps = is;
610 isOK = static_cast<bool>( load >> is );
614 isOK = static_cast<bool>( load >> val );
616 _elemSizeWeight = val;
618 isOK = static_cast<bool>( load >> is );
620 _worstElemMeasure = is;
622 isOK = static_cast<bool>( load >> is );
624 _useDelauney = (bool) is;
626 isOK = static_cast<bool>( load >> is );
628 _checkOverlapping = (bool) is;
630 isOK = static_cast<bool>( load >> is );
632 _checkChartBoundary = (bool) is;
637 //================================================================================
639 * \brief Does nothing
640 * \param theMesh - the built mesh
641 * \param theShape - the geometry of interest
642 * \retval bool - always false
644 //================================================================================
645 bool NETGENPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
646 const TopoDS_Shape& theShape)
651 //================================================================================
653 * \brief Initialize my parameter values by default parameters.
654 * \retval bool - true if parameter values have been successfully defined
656 //================================================================================
658 bool NETGENPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
659 const SMESH_Mesh* theMesh)
661 _nbSegPerEdge = dflts._nbSegments;
662 _maxSize = dflts._elemLength;
664 if ( dflts._shape && !dflts._shape->IsNull() )
665 _minSize = NETGENPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
666 else if ( theMesh && theMesh->HasShapeToMesh() )
667 _minSize = NETGENPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
669 return _nbSegPerEdge && _maxSize > 0;