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, int studyId,
45 : SMESH_Hypothesis(hypId, studyId, gen),
46 _maxSize (GetDefaultMaxSize()),
48 _growthRate (GetDefaultGrowthRate()),
49 _nbSegPerEdge (GetDefaultNbSegPerEdge()),
50 _nbSegPerRadius (GetDefaultNbSegPerRadius()),
51 _fineness (GetDefaultFineness()),
52 _chordalErrorEnabled(GetDefaultChordalError() > 0),
53 _chordalError (GetDefaultChordalError() ),
54 _secondOrder (GetDefaultSecondOrder()),
55 _optimize (GetDefaultOptimize()),
56 _localSize (GetDefaultLocalSize()),
57 _quadAllowed (GetDefaultQuadAllowed()),
58 _surfaceCurvature (GetDefaultSurfaceCurvature()),
59 _fuseEdges (GetDefaultFuseEdges())
61 _name = "NETGEN_Parameters";
66 //=============================================================================
70 //=============================================================================
71 void NETGENPlugin_Hypothesis::SetMaxSize(double theSize)
73 if (theSize != _maxSize)
76 NotifySubMeshesHypothesisModification();
80 //=============================================================================
84 //=============================================================================
85 void NETGENPlugin_Hypothesis::SetMinSize(double theSize)
87 if (theSize != _minSize)
90 NotifySubMeshesHypothesisModification();
94 //=============================================================================
98 //=============================================================================
99 void NETGENPlugin_Hypothesis::SetSecondOrder(bool theVal)
101 if (theVal != _secondOrder)
103 _secondOrder = theVal;
104 NotifySubMeshesHypothesisModification();
108 //=============================================================================
112 //=============================================================================
113 void NETGENPlugin_Hypothesis::SetOptimize(bool theVal)
115 if (theVal != _optimize)
118 NotifySubMeshesHypothesisModification();
122 //=============================================================================
126 //=============================================================================
127 void NETGENPlugin_Hypothesis::SetFineness(Fineness theFineness)
129 if (theFineness != _fineness)
131 _fineness = theFineness;
132 // the predefined values are taken from NETGEN 4.5 sources
143 _nbSegPerRadius = 1.5;
164 NotifySubMeshesHypothesisModification();
168 //=============================================================================
172 //=============================================================================
173 void NETGENPlugin_Hypothesis::SetGrowthRate(double theRate)
175 if (theRate != _growthRate)
177 _growthRate = theRate;
178 _fineness = UserDefined;
179 NotifySubMeshesHypothesisModification();
183 //=============================================================================
187 //=============================================================================
188 void NETGENPlugin_Hypothesis::SetNbSegPerEdge(double theVal)
190 if (theVal != _nbSegPerEdge)
192 _nbSegPerEdge = theVal;
193 _fineness = UserDefined;
194 NotifySubMeshesHypothesisModification();
198 //=============================================================================
202 //=============================================================================
203 void NETGENPlugin_Hypothesis::SetNbSegPerRadius(double theVal)
205 if (theVal != _nbSegPerRadius)
207 _nbSegPerRadius = theVal;
208 _fineness = UserDefined;
209 NotifySubMeshesHypothesisModification();
213 //=============================================================================
217 //=============================================================================
218 void NETGENPlugin_Hypothesis::SetChordalErrorEnabled(bool theVal)
220 if (theVal != _chordalErrorEnabled)
222 _chordalErrorEnabled = theVal;
223 NotifySubMeshesHypothesisModification();
227 //=============================================================================
231 //=============================================================================
232 void NETGENPlugin_Hypothesis::SetChordalError(double theVal)
234 if (theVal != _chordalError)
236 _chordalError = theVal;
237 NotifySubMeshesHypothesisModification();
241 //=============================================================================
245 //=============================================================================
246 void NETGENPlugin_Hypothesis::SetLocalSizeOnEntry(const std::string& entry, double localSize)
248 if(_localSize[entry] != localSize)
250 _localSize[entry] = localSize;
251 NotifySubMeshesHypothesisModification();
255 //=============================================================================
259 //=============================================================================
260 double NETGENPlugin_Hypothesis::GetLocalSizeOnEntry(const std::string& entry)
262 TLocalSize::iterator it = _localSize.find( entry );
263 if ( it != _localSize.end() )
269 //=============================================================================
273 //=============================================================================
274 void NETGENPlugin_Hypothesis::UnsetLocalSizeOnEntry(const std::string& entry)
276 _localSize.erase(entry);
277 NotifySubMeshesHypothesisModification();
280 //=============================================================================
284 //=============================================================================
285 void NETGENPlugin_Hypothesis::SetMeshSizeFile(const std::string& fileName)
287 if ( fileName != _meshSizeFile )
289 _meshSizeFile = fileName;
290 NotifySubMeshesHypothesisModification();
294 //=============================================================================
298 //=============================================================================
299 void NETGENPlugin_Hypothesis::SetQuadAllowed(bool theVal)
301 if (theVal != _quadAllowed)
303 _quadAllowed = theVal;
304 NotifySubMeshesHypothesisModification();
308 //=============================================================================
312 //=============================================================================
313 bool NETGENPlugin_Hypothesis::GetDefaultQuadAllowed()
318 //=============================================================================
322 //=============================================================================
323 void NETGENPlugin_Hypothesis::SetSurfaceCurvature(bool theVal)
325 if (theVal != _surfaceCurvature)
327 _surfaceCurvature = theVal;
328 NotifySubMeshesHypothesisModification();
332 //=============================================================================
336 //=============================================================================
337 bool NETGENPlugin_Hypothesis::GetDefaultSurfaceCurvature()
342 //=============================================================================
346 //=============================================================================
347 void NETGENPlugin_Hypothesis::SetFuseEdges(bool theVal)
349 if (theVal != _fuseEdges)
352 NotifySubMeshesHypothesisModification();
356 //=============================================================================
360 //=============================================================================
361 bool NETGENPlugin_Hypothesis::GetDefaultFuseEdges()
363 return true; // false; -- for SALOME_TESTS/Grids/smesh/3D_mesh_NETGEN_05/F6
366 //=============================================================================
370 //=============================================================================
371 ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
373 save << _maxSize << " " << _fineness;
375 if (_fineness == UserDefined)
376 save << " " << _growthRate << " " << _nbSegPerEdge << " " << _nbSegPerRadius;
378 save << " " << (int)_secondOrder << " " << (int)_optimize;
380 TLocalSize::iterator it_sm = _localSize.begin();
381 if (it_sm != _localSize.end()) {
382 save << " " << "__LOCALSIZE_BEGIN__";
383 for ( ; it_sm != _localSize.end(); ++it_sm ) {
384 save << " " << it_sm->first
385 << " " << it_sm->second << "%#"; // "%#" is a mark of value end
387 save << " " << "__LOCALSIZE_END__";
389 save << " " << _minSize;
390 save << " " << _quadAllowed;
391 save << " " << _surfaceCurvature;
392 save << " " << _fuseEdges;
394 save << " " << _meshSizeFile.size() << " " << _meshSizeFile;
396 save << " " << ( _chordalErrorEnabled ? _chordalError : 0. );
401 //=============================================================================
405 //=============================================================================
406 istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
412 isOK = static_cast<bool>(load >> val);
416 load.clear(ios::badbit | load.rdstate());
418 isOK = static_cast<bool>(load >> is);
420 SetFineness((Fineness) is);
422 load.clear(ios::badbit | load.rdstate());
424 if (_fineness == UserDefined)
426 isOK = static_cast<bool>(load >> val);
430 load.clear(ios::badbit | load.rdstate());
432 isOK = static_cast<bool>(load >> val);
436 load.clear(ios::badbit | load.rdstate());
438 isOK = static_cast<bool>(load >> val);
440 _nbSegPerRadius = val;
442 load.clear(ios::badbit | load.rdstate());
445 isOK = static_cast<bool>(load >> is);
447 _secondOrder = (bool) is;
449 load.clear(ios::badbit | load.rdstate());
451 isOK = static_cast<bool>(load >> is);
453 _optimize = (bool) is;
455 load.clear(ios::badbit | load.rdstate());
457 std::string option_or_sm;
458 bool hasLocalSize = false;
460 isOK = static_cast<bool>(load >> option_or_sm);
462 if (option_or_sm == "__LOCALSIZE_BEGIN__")
465 std::string smEntry, smValue;
466 while (isOK && hasLocalSize) {
467 isOK = static_cast<bool>(load >> smEntry);
469 if (smEntry == "__LOCALSIZE_END__")
471 isOK = static_cast<bool>(load >> smValue);
474 std::istringstream tmp(smValue);
477 _localSize[ smEntry ] = val;
481 if ( !hasLocalSize && !option_or_sm.empty() )
482 _minSize = atof( option_or_sm.c_str() );
486 isOK = static_cast<bool>( load >> is );
488 _quadAllowed = (bool) is;
490 _quadAllowed = GetDefaultQuadAllowed();
492 isOK = static_cast<bool>( load >> is );
494 _surfaceCurvature = (bool) is;
496 _surfaceCurvature = GetDefaultSurfaceCurvature();
498 isOK = static_cast<bool>( load >> is );
500 _fuseEdges = (bool) is;
502 _fuseEdges = GetDefaultFuseEdges();
504 isOK = static_cast<bool>( load >> is >> std::ws ); // size of meshSizeFile
505 if ( isOK && is > 0 )
507 _meshSizeFile.resize( is );
508 load.get( &_meshSizeFile[0], is+1 );
511 isOK = static_cast<bool>(load >> val);
515 load.clear(ios::badbit | load.rdstate());
516 _chordalErrorEnabled = ( _chordalError > 0 );
521 //=============================================================================
525 //=============================================================================
526 ostream & operator <<(ostream & save, NETGENPlugin_Hypothesis & hyp)
528 return hyp.SaveTo( save );
531 //=============================================================================
535 //=============================================================================
536 istream & operator >>(istream & load, NETGENPlugin_Hypothesis & hyp)
538 return hyp.LoadFrom( load );
542 //================================================================================
544 * \brief Does nothing
545 * \param theMesh - the built mesh
546 * \param theShape - the geometry of interest
547 * \retval bool - always false
549 //================================================================================
550 bool NETGENPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
551 const TopoDS_Shape& theShape)
556 //================================================================================
558 * \brief Initialize my parameter values by default parameters.
559 * \retval bool - true if parameter values have been successfully defined
561 //================================================================================
563 bool NETGENPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
564 const SMESH_Mesh* theMesh)
566 _nbSegPerEdge = dflts._nbSegments;
567 _maxSize = dflts._elemLength;
569 if ( dflts._shape && !dflts._shape->IsNull() )
570 _minSize = NETGENPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
571 else if ( theMesh && theMesh->HasShapeToMesh() )
572 _minSize = NETGENPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
574 return _nbSegPerEdge && _maxSize > 0;
577 //=============================================================================
581 //=============================================================================
582 double NETGENPlugin_Hypothesis::GetDefaultMaxSize()
587 //=============================================================================
591 //=============================================================================
592 NETGENPlugin_Hypothesis::Fineness NETGENPlugin_Hypothesis::GetDefaultFineness()
597 //=============================================================================
601 //=============================================================================
602 double NETGENPlugin_Hypothesis::GetDefaultGrowthRate()
607 //=============================================================================
611 //=============================================================================
612 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge()
617 //=============================================================================
621 //=============================================================================
622 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerRadius()
626 //=============================================================================
630 //=============================================================================
631 double NETGENPlugin_Hypothesis::GetDefaultChordalError()
633 return -1; // disabled by default
636 //=============================================================================
640 //=============================================================================
641 bool NETGENPlugin_Hypothesis::GetDefaultSecondOrder()
646 //=============================================================================
650 //=============================================================================
651 bool NETGENPlugin_Hypothesis::GetDefaultOptimize()