1 // Copyright (C) 2007-2016 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,
46 : SMESH_Hypothesis(hypId, gen),
47 _maxSize (GetDefaultMaxSize()),
49 _growthRate (GetDefaultGrowthRate()),
50 _nbSegPerEdge (GetDefaultNbSegPerEdge()),
51 _nbSegPerRadius (GetDefaultNbSegPerRadius()),
52 _fineness (GetDefaultFineness()),
53 _chordalErrorEnabled(GetDefaultChordalError() > 0),
54 _chordalError (GetDefaultChordalError() ),
55 _secondOrder (GetDefaultSecondOrder()),
56 _optimize (GetDefaultOptimize()),
57 _localSize (GetDefaultLocalSize()),
58 _quadAllowed (GetDefaultQuadAllowed()),
59 _surfaceCurvature (GetDefaultSurfaceCurvature()),
60 _fuseEdges (GetDefaultFuseEdges())
62 _name = "NETGEN_Parameters";
67 //=============================================================================
71 //=============================================================================
72 void NETGENPlugin_Hypothesis::SetMaxSize(double theSize)
74 if (theSize != _maxSize)
77 NotifySubMeshesHypothesisModification();
81 //=============================================================================
85 //=============================================================================
86 void NETGENPlugin_Hypothesis::SetMinSize(double theSize)
88 if (theSize != _minSize)
91 NotifySubMeshesHypothesisModification();
95 //=============================================================================
99 //=============================================================================
100 void NETGENPlugin_Hypothesis::SetSecondOrder(bool theVal)
102 if (theVal != _secondOrder)
104 _secondOrder = theVal;
105 NotifySubMeshesHypothesisModification();
109 //=============================================================================
113 //=============================================================================
114 void NETGENPlugin_Hypothesis::SetOptimize(bool theVal)
116 if (theVal != _optimize)
119 NotifySubMeshesHypothesisModification();
123 //=============================================================================
127 //=============================================================================
128 void NETGENPlugin_Hypothesis::SetFineness(Fineness theFineness)
130 if (theFineness != _fineness)
132 _fineness = theFineness;
133 // the predefined values are taken from NETGEN 4.5 sources
144 _nbSegPerRadius = 1.5;
165 NotifySubMeshesHypothesisModification();
169 //=============================================================================
173 //=============================================================================
174 void NETGENPlugin_Hypothesis::SetGrowthRate(double theRate)
176 if (theRate != _growthRate)
178 _growthRate = theRate;
179 _fineness = UserDefined;
180 NotifySubMeshesHypothesisModification();
184 //=============================================================================
188 //=============================================================================
189 void NETGENPlugin_Hypothesis::SetNbSegPerEdge(double theVal)
191 if (theVal != _nbSegPerEdge)
193 _nbSegPerEdge = theVal;
194 _fineness = UserDefined;
195 NotifySubMeshesHypothesisModification();
199 //=============================================================================
203 //=============================================================================
204 void NETGENPlugin_Hypothesis::SetNbSegPerRadius(double theVal)
206 if (theVal != _nbSegPerRadius)
208 _nbSegPerRadius = theVal;
209 _fineness = UserDefined;
210 NotifySubMeshesHypothesisModification();
214 //=============================================================================
218 //=============================================================================
219 void NETGENPlugin_Hypothesis::SetChordalErrorEnabled(bool theVal)
221 if (theVal != _chordalErrorEnabled)
223 _chordalErrorEnabled = theVal;
224 NotifySubMeshesHypothesisModification();
228 //=============================================================================
232 //=============================================================================
233 void NETGENPlugin_Hypothesis::SetChordalError(double theVal)
235 if (theVal != _chordalError)
237 _chordalError = theVal;
238 NotifySubMeshesHypothesisModification();
242 //=============================================================================
246 //=============================================================================
247 void NETGENPlugin_Hypothesis::SetLocalSizeOnEntry(const std::string& entry, double localSize)
249 if(_localSize[entry] != localSize)
251 _localSize[entry] = localSize;
252 NotifySubMeshesHypothesisModification();
256 //=============================================================================
260 //=============================================================================
261 double NETGENPlugin_Hypothesis::GetLocalSizeOnEntry(const std::string& entry)
263 TLocalSize::iterator it = _localSize.find( entry );
264 if ( it != _localSize.end() )
270 //=============================================================================
274 //=============================================================================
275 void NETGENPlugin_Hypothesis::UnsetLocalSizeOnEntry(const std::string& entry)
277 _localSize.erase(entry);
278 NotifySubMeshesHypothesisModification();
281 //=============================================================================
285 //=============================================================================
286 void NETGENPlugin_Hypothesis::SetMeshSizeFile(const std::string& fileName)
288 if ( fileName != _meshSizeFile )
290 _meshSizeFile = fileName;
291 NotifySubMeshesHypothesisModification();
295 //=============================================================================
299 //=============================================================================
300 void NETGENPlugin_Hypothesis::SetQuadAllowed(bool theVal)
302 if (theVal != _quadAllowed)
304 _quadAllowed = theVal;
305 NotifySubMeshesHypothesisModification();
309 //=============================================================================
313 //=============================================================================
314 bool NETGENPlugin_Hypothesis::GetDefaultQuadAllowed()
319 //=============================================================================
323 //=============================================================================
324 void NETGENPlugin_Hypothesis::SetSurfaceCurvature(bool theVal)
326 if (theVal != _surfaceCurvature)
328 _surfaceCurvature = theVal;
329 NotifySubMeshesHypothesisModification();
333 //=============================================================================
337 //=============================================================================
338 bool NETGENPlugin_Hypothesis::GetDefaultSurfaceCurvature()
343 //=============================================================================
347 //=============================================================================
348 void NETGENPlugin_Hypothesis::SetFuseEdges(bool theVal)
350 if (theVal != _fuseEdges)
353 NotifySubMeshesHypothesisModification();
357 //=============================================================================
361 //=============================================================================
362 bool NETGENPlugin_Hypothesis::GetDefaultFuseEdges()
364 return true; // false; -- for SALOME_TESTS/Grids/smesh/3D_mesh_NETGEN_05/F6
367 //=============================================================================
371 //=============================================================================
372 ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
374 save << _maxSize << " " << _fineness;
376 if (_fineness == UserDefined)
377 save << " " << _growthRate << " " << _nbSegPerEdge << " " << _nbSegPerRadius;
379 save << " " << (int)_secondOrder << " " << (int)_optimize;
381 TLocalSize::iterator it_sm = _localSize.begin();
382 if (it_sm != _localSize.end()) {
383 save << " " << "__LOCALSIZE_BEGIN__";
384 for ( ; it_sm != _localSize.end(); ++it_sm ) {
385 save << " " << it_sm->first
386 << " " << it_sm->second << "%#"; // "%#" is a mark of value end
388 save << " " << "__LOCALSIZE_END__";
390 save << " " << _minSize;
391 save << " " << _quadAllowed;
392 save << " " << _surfaceCurvature;
393 save << " " << _fuseEdges;
395 save << " " << _meshSizeFile.size() << " " << _meshSizeFile;
397 save << " " << ( _chordalErrorEnabled ? _chordalError : 0. );
402 //=============================================================================
406 //=============================================================================
407 istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
413 isOK = static_cast<bool>(load >> val);
417 load.clear(ios::badbit | load.rdstate());
419 isOK = static_cast<bool>(load >> is);
421 SetFineness((Fineness) is);
423 load.clear(ios::badbit | load.rdstate());
425 if (_fineness == UserDefined)
427 isOK = static_cast<bool>(load >> val);
431 load.clear(ios::badbit | load.rdstate());
433 isOK = static_cast<bool>(load >> val);
437 load.clear(ios::badbit | load.rdstate());
439 isOK = static_cast<bool>(load >> val);
441 _nbSegPerRadius = val;
443 load.clear(ios::badbit | load.rdstate());
446 isOK = static_cast<bool>(load >> is);
448 _secondOrder = (bool) is;
450 load.clear(ios::badbit | load.rdstate());
452 isOK = static_cast<bool>(load >> is);
454 _optimize = (bool) is;
456 load.clear(ios::badbit | load.rdstate());
458 std::string option_or_sm;
459 bool hasLocalSize = false;
461 isOK = static_cast<bool>(load >> option_or_sm);
463 if (option_or_sm == "__LOCALSIZE_BEGIN__")
466 std::string smEntry, smValue;
467 while (isOK && hasLocalSize) {
468 isOK = static_cast<bool>(load >> smEntry);
470 if (smEntry == "__LOCALSIZE_END__")
472 isOK = static_cast<bool>(load >> smValue);
475 std::istringstream tmp(smValue);
478 _localSize[ smEntry ] = val;
482 if ( !hasLocalSize && !option_or_sm.empty() )
483 _minSize = atof( option_or_sm.c_str() );
487 isOK = static_cast<bool>( load >> is );
489 _quadAllowed = (bool) is;
491 _quadAllowed = GetDefaultQuadAllowed();
493 isOK = static_cast<bool>( load >> is );
495 _surfaceCurvature = (bool) is;
497 _surfaceCurvature = GetDefaultSurfaceCurvature();
499 isOK = static_cast<bool>( load >> is );
501 _fuseEdges = (bool) is;
503 _fuseEdges = GetDefaultFuseEdges();
505 isOK = static_cast<bool>( load >> is >> std::ws ); // size of meshSizeFile
506 if ( isOK && is > 0 )
508 _meshSizeFile.resize( is );
509 load.get( &_meshSizeFile[0], is+1 );
512 isOK = static_cast<bool>(load >> val);
516 load.clear(ios::badbit | load.rdstate());
517 _chordalErrorEnabled = ( _chordalError > 0 );
522 //=============================================================================
526 //=============================================================================
527 ostream & operator <<(ostream & save, NETGENPlugin_Hypothesis & hyp)
529 return hyp.SaveTo( save );
532 //=============================================================================
536 //=============================================================================
537 istream & operator >>(istream & load, NETGENPlugin_Hypothesis & hyp)
539 return hyp.LoadFrom( load );
543 //================================================================================
545 * \brief Does nothing
546 * \param theMesh - the built mesh
547 * \param theShape - the geometry of interest
548 * \retval bool - always false
550 //================================================================================
551 bool NETGENPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
552 const TopoDS_Shape& theShape)
557 //================================================================================
559 * \brief Initialize my parameter values by default parameters.
560 * \retval bool - true if parameter values have been successfully defined
562 //================================================================================
564 bool NETGENPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
565 const SMESH_Mesh* theMesh)
567 _nbSegPerEdge = dflts._nbSegments;
568 _maxSize = dflts._elemLength;
570 if ( dflts._shape && !dflts._shape->IsNull() )
571 _minSize = NETGENPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
572 else if ( theMesh && theMesh->HasShapeToMesh() )
573 _minSize = NETGENPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
575 return _nbSegPerEdge && _maxSize > 0;
578 //=============================================================================
582 //=============================================================================
583 double NETGENPlugin_Hypothesis::GetDefaultMaxSize()
588 //=============================================================================
592 //=============================================================================
593 NETGENPlugin_Hypothesis::Fineness NETGENPlugin_Hypothesis::GetDefaultFineness()
598 //=============================================================================
602 //=============================================================================
603 double NETGENPlugin_Hypothesis::GetDefaultGrowthRate()
608 //=============================================================================
612 //=============================================================================
613 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge()
618 //=============================================================================
622 //=============================================================================
623 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerRadius()
627 //=============================================================================
631 //=============================================================================
632 double NETGENPlugin_Hypothesis::GetDefaultChordalError()
634 return -1; // disabled by default
637 //=============================================================================
641 //=============================================================================
642 bool NETGENPlugin_Hypothesis::GetDefaultSecondOrder()
647 //=============================================================================
651 //=============================================================================
652 bool NETGENPlugin_Hypothesis::GetDefaultOptimize()