Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "StdMeshers_MaxElementVolume.hxx"
00030
00031 #include "SMDS_MeshElement.hxx"
00032 #include "SMESHDS_SubMesh.hxx"
00033 #include "SMESH_ControlsDef.hxx"
00034 #include "SMESH_Mesh.hxx"
00035
00036 #include "utilities.h"
00037
00038 #include <TopExp.hxx>
00039 #include <TopExp_Explorer.hxx>
00040 #include <TopTools_IndexedMapOfShape.hxx>
00041
00042 using namespace std;
00043
00044
00048
00049
00050 StdMeshers_MaxElementVolume::StdMeshers_MaxElementVolume(int hypId, int studyId, SMESH_Gen* gen)
00051 : SMESH_Hypothesis(hypId, studyId, gen)
00052 {
00053 _maxVolume = 1.;
00054 _name = "MaxElementVolume";
00055 _param_algo_dim = 3;
00056 }
00057
00058
00062
00063
00064 StdMeshers_MaxElementVolume::~StdMeshers_MaxElementVolume()
00065 {
00066 MESSAGE("StdMeshers_MaxElementVolume::~StdMeshers_MaxElementVolume");
00067 }
00068
00069
00073
00074
00075 void StdMeshers_MaxElementVolume::SetMaxVolume(double maxVolume)
00076 throw (SALOME_Exception)
00077 {
00078 double oldVolume = _maxVolume;
00079 if (maxVolume <= 0)
00080 throw SALOME_Exception(LOCALIZED("maxVolume must be positive"));
00081 _maxVolume = maxVolume;
00082 if (_maxVolume != oldVolume)
00083 NotifySubMeshesHypothesisModification();
00084 }
00085
00086
00090
00091
00092 double StdMeshers_MaxElementVolume::GetMaxVolume() const
00093 {
00094 return _maxVolume;
00095 }
00096
00097
00101
00102
00103 ostream & StdMeshers_MaxElementVolume::SaveTo(ostream & save)
00104 {
00105 save << this->_maxVolume;
00106 return save;
00107 }
00108
00109
00113
00114
00115 istream & StdMeshers_MaxElementVolume::LoadFrom(istream & load)
00116 {
00117 bool isOK = true;
00118 double a;
00119 isOK = (load >> a);
00120 if (isOK)
00121 this->_maxVolume = a;
00122 else
00123 load.clear(ios::badbit | load.rdstate());
00124 return load;
00125 }
00126
00127
00131
00132
00133 ostream & operator << (ostream & save, StdMeshers_MaxElementVolume & hyp)
00134 {
00135 return hyp.SaveTo( save );
00136 }
00137
00138
00142
00143
00144 istream & operator >> (istream & load, StdMeshers_MaxElementVolume & hyp)
00145 {
00146 return hyp.LoadFrom( load );
00147 }
00148
00149
00150
00157
00158
00159 bool StdMeshers_MaxElementVolume::SetParametersByMesh(const SMESH_Mesh* theMesh,
00160 const TopoDS_Shape& theShape)
00161 {
00162 if ( !theMesh || theShape.IsNull() )
00163 return false;
00164
00165 _maxVolume = 0;
00166
00167 SMESH::Controls::Volume volumeControl;
00168
00169 TopTools_IndexedMapOfShape volMap;
00170 TopExp::MapShapes( theShape, TopAbs_SOLID, volMap );
00171 if ( volMap.IsEmpty() )
00172 TopExp::MapShapes( theShape, TopAbs_SHELL, volMap );
00173 if ( volMap.IsEmpty() )
00174 return false;
00175
00176 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
00177
00178 for ( int iV = 1; iV <= volMap.Extent(); ++iV )
00179 {
00180 const TopoDS_Shape& S = volMap( iV );
00181 SMESHDS_SubMesh * subMesh = aMeshDS->MeshElements( S );
00182 if ( !subMesh && S.ShapeType() == TopAbs_SOLID ) {
00183 TopExp_Explorer shellExp( S, TopAbs_SHELL );
00184 if ( shellExp.More() )
00185 subMesh = aMeshDS->MeshElements( shellExp.Current() );
00186 }
00187 if ( !subMesh)
00188 return false;
00189 SMDS_ElemIteratorPtr vIt = subMesh->GetElements();
00190 while ( vIt->more() )
00191 {
00192 const SMDS_MeshElement* elem = vIt->next();
00193 if ( elem->GetType() == SMDSAbs_Volume ) {
00194 _maxVolume = max( _maxVolume, volumeControl.GetValue( elem->GetID() ));
00195 }
00196 }
00197 }
00198 return _maxVolume > 0;
00199 }
00200
00205
00206
00207 bool StdMeshers_MaxElementVolume::SetParametersByDefaults(const TDefaults& dflts,
00208 const SMESH_Mesh* )
00209 {
00210 return ( _maxVolume = dflts._elemLength*dflts._elemLength*dflts._elemLength );
00211 }
00212