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_MaxElementArea.hxx"
00030
00031 #include "SMESH_ControlsDef.hxx"
00032 #include "SMDS_MeshElement.hxx"
00033 #include "SMESHDS_SubMesh.hxx"
00034 #include "SMESH_Mesh.hxx"
00035
00036 #include <TopExp.hxx>
00037 #include <TopTools_IndexedMapOfShape.hxx>
00038
00039 #include "utilities.h"
00040
00041 using namespace std;
00042
00043
00047
00048
00049 StdMeshers_MaxElementArea::StdMeshers_MaxElementArea(int hypId, int studyId, SMESH_Gen* gen)
00050 : SMESH_Hypothesis(hypId, studyId, gen)
00051 {
00052 _maxArea =1.;
00053 _name = "MaxElementArea";
00054 _param_algo_dim = 2;
00055 }
00056
00057
00061
00062
00063 StdMeshers_MaxElementArea::~StdMeshers_MaxElementArea()
00064 {
00065 }
00066
00067
00071
00072
00073 void StdMeshers_MaxElementArea::SetMaxArea(double maxArea)
00074 throw (SALOME_Exception)
00075 {
00076 double oldArea = _maxArea;
00077 if (maxArea <= 0)
00078 throw SALOME_Exception(LOCALIZED("maxArea must be positive"));
00079 _maxArea = maxArea;
00080 if (_maxArea != oldArea)
00081 NotifySubMeshesHypothesisModification();
00082 }
00083
00084
00088
00089
00090 double StdMeshers_MaxElementArea::GetMaxArea() const
00091 {
00092 return _maxArea;
00093 }
00094
00095
00099
00100
00101 ostream & StdMeshers_MaxElementArea::SaveTo(ostream & save)
00102 {
00103 save << this->_maxArea;
00104 return save;
00105 }
00106
00107
00111
00112
00113 istream & StdMeshers_MaxElementArea::LoadFrom(istream & load)
00114 {
00115 bool isOK = true;
00116 double a;
00117 isOK = (load >> a);
00118 if (isOK)
00119 this->_maxArea = a;
00120 else
00121 load.clear(ios::badbit | load.rdstate());
00122 return load;
00123 }
00124
00125
00129
00130
00131 ostream & operator << (ostream & save, StdMeshers_MaxElementArea & hyp)
00132 {
00133 return hyp.SaveTo( save );
00134 }
00135
00136
00140
00141
00142 istream & operator >> (istream & load, StdMeshers_MaxElementArea & hyp)
00143 {
00144 return hyp.LoadFrom( load );
00145 }
00146
00147
00154
00155
00156 bool StdMeshers_MaxElementArea::SetParametersByMesh(const SMESH_Mesh* theMesh,
00157 const TopoDS_Shape& theShape)
00158 {
00159 if ( !theMesh || theShape.IsNull() )
00160 return false;
00161
00162 _maxArea = 0;
00163
00164 SMESH::Controls::Area areaControl;
00165 SMESH::Controls::TSequenceOfXYZ nodesCoords;
00166
00167 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
00168
00169 TopTools_IndexedMapOfShape faceMap;
00170 TopExp::MapShapes( theShape, TopAbs_FACE, faceMap );
00171 for ( int iF = 1; iF <= faceMap.Extent(); ++iF )
00172 {
00173 SMESHDS_SubMesh * subMesh = aMeshDS->MeshElements( faceMap( iF ));
00174 if ( !subMesh )
00175 return false;
00176 SMDS_ElemIteratorPtr fIt = subMesh->GetElements();
00177 while ( fIt->more() )
00178 {
00179 const SMDS_MeshElement* elem = fIt->next();
00180 if ( elem->GetType() == SMDSAbs_Face ) {
00181 areaControl.GetPoints( elem, nodesCoords );
00182 _maxArea = max( _maxArea, areaControl.GetValue( nodesCoords ));
00183 }
00184 }
00185 }
00186 return _maxArea > 0;
00187 }
00188
00193
00194
00195 bool StdMeshers_MaxElementArea::SetParametersByDefaults(const TDefaults& dflts,
00196 const SMESH_Mesh* )
00197 {
00198 return ( _maxArea = dflts._elemLength*dflts._elemLength );
00199 }
00200