1 // Copyright (C) 2007-2013 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.
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_NETGEN_2D3D.cxx
25 // Author : Michael Sazonov (OCN)
28 //=============================================================================
30 #include "NETGENPlugin_NETGEN_2D3D.hxx"
31 #include "NETGENPlugin_Hypothesis.hxx"
32 #include "NETGENPlugin_SimpleHypothesis_3D.hxx"
33 #include "NETGENPlugin_Mesher.hxx"
35 #include <SMESH_Gen.hxx>
36 #include <SMESH_Mesh.hxx>
37 #include <SMESH_ControlsDef.hxx>
38 #include <SMESHDS_Mesh.hxx>
39 #include <utilities.h>
46 #include <meshing.hpp>
50 //=============================================================================
54 //=============================================================================
56 NETGENPlugin_NETGEN_2D3D::NETGENPlugin_NETGEN_2D3D(int hypId, int studyId,
58 : SMESH_3D_Algo(hypId, studyId, gen)
60 MESSAGE("NETGENPlugin_NETGEN_2D3D::NETGENPlugin_NETGEN_2D3D");
61 _name = "NETGEN_2D3D";
62 _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type
63 _compatibleHypothesis.push_back("NETGEN_Parameters");
64 _compatibleHypothesis.push_back("NETGEN_SimpleParameters_3D");
65 _requireDiscreteBoundary = false;
66 _onlyUnaryInput = false;
68 _supportSubmeshes = true;
71 //=============================================================================
75 //=============================================================================
77 NETGENPlugin_NETGEN_2D3D::~NETGENPlugin_NETGEN_2D3D()
79 MESSAGE("NETGENPlugin_NETGEN_2D3D::~NETGENPlugin_NETGEN_2D3D");
82 //=============================================================================
86 //=============================================================================
88 bool NETGENPlugin_NETGEN_2D3D::CheckHypothesis
90 const TopoDS_Shape& aShape,
91 SMESH_Hypothesis::Hypothesis_Status& aStatus)
93 MESSAGE("NETGENPlugin_NETGEN_2D3D::CheckHypothesis");
98 const list<const SMESHDS_Hypothesis*>& hyps = GetUsedHypothesis(aMesh, aShape);
99 int nbHyp = hyps.size();
102 aStatus = SMESH_Hypothesis::HYP_OK;
103 return true; // can work with no hypothesis
106 const SMESHDS_Hypothesis* theHyp = hyps.front(); // use only the first hypothesis
108 string hypName = theHyp->GetName();
110 if ( find( _compatibleHypothesis.begin(), _compatibleHypothesis.end(),
111 hypName ) != _compatibleHypothesis.end() )
113 _hypothesis = theHyp;
114 aStatus = SMESH_Hypothesis::HYP_OK;
118 aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
121 return aStatus == SMESH_Hypothesis::HYP_OK;
124 //=============================================================================
126 * Here we are going to use the NETGEN mesher
128 //=============================================================================
130 bool NETGENPlugin_NETGEN_2D3D::Compute(SMESH_Mesh& aMesh,
131 const TopoDS_Shape& aShape)
133 netgen::multithread.terminate = 0;
135 NETGENPlugin_Mesher mesher(&aMesh, aShape, true);
136 mesher.SetParameters(dynamic_cast<const NETGENPlugin_Hypothesis*>(_hypothesis));
137 mesher.SetParameters(dynamic_cast<const NETGENPlugin_SimpleHypothesis_3D*>(_hypothesis));
138 mesher.SetSelfPointer( &_mesher );
139 return mesher.Compute();
142 //=============================================================================
146 //=============================================================================
148 void NETGENPlugin_NETGEN_2D3D::CancelCompute()
150 SMESH_Algo::CancelCompute();
151 netgen::multithread.terminate = 1;
154 //================================================================================
156 * \brief Return progress of Compute() [0.,1]
158 //================================================================================
160 double NETGENPlugin_NETGEN_2D3D::GetProgress() const
162 double & progress = (double &)_progress;
164 progress = _mesher->GetProgress(this, &_progressTic, &_progress);
165 else if ( _progress > 0.001 )
171 //=============================================================================
175 //=============================================================================
177 bool NETGENPlugin_NETGEN_2D3D::Evaluate(SMESH_Mesh& aMesh,
178 const TopoDS_Shape& aShape,
179 MapShapeNbElems& aResMap)
181 NETGENPlugin_Mesher mesher(&aMesh, aShape, true);
182 mesher.SetParameters(dynamic_cast<const NETGENPlugin_Hypothesis*>(_hypothesis));
183 mesher.SetParameters(dynamic_cast<const NETGENPlugin_SimpleHypothesis_2D*>(_hypothesis));
184 return mesher.Evaluate(aResMap);