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 #include "StdMeshers_MaxLength.hxx"
00025
00026 #include "SMESH_Mesh.hxx"
00027 #include "SMESH_Algo.hxx"
00028
00029 #include "utilities.h"
00030
00031 #include <BRep_Tool.hxx>
00032 #include <GCPnts_AbscissaPoint.hxx>
00033 #include <GeomAdaptor_Curve.hxx>
00034 #include <Geom_Curve.hxx>
00035 #include <TopExp.hxx>
00036 #include <TopLoc_Location.hxx>
00037 #include <TopTools_IndexedMapOfShape.hxx>
00038 #include <TopoDS.hxx>
00039 #include <TopoDS_Edge.hxx>
00040 #include <Precision.hxx>
00041
00042 using namespace std;
00043
00044
00048
00049
00050 StdMeshers_MaxLength::StdMeshers_MaxLength(int hypId, int studyId, SMESH_Gen * gen)
00051 :SMESH_Hypothesis(hypId, studyId, gen)
00052 {
00053 _length = 1.;
00054 _preestimated = 0.;
00055 _preestimation = false;
00056 _name = "MaxLength";
00057 _param_algo_dim = 1;
00058 }
00059
00060
00064
00065
00066 StdMeshers_MaxLength::~StdMeshers_MaxLength()
00067 {
00068 }
00069
00070
00074
00075
00076 void StdMeshers_MaxLength::SetLength(double length) throw(SALOME_Exception)
00077 {
00078 if (length <= 0)
00079 throw SALOME_Exception(LOCALIZED("length must be positive"));
00080 if ( _length != length ) {
00081 _length = length;
00082 NotifySubMeshesHypothesisModification();
00083 }
00084 }
00085
00086
00090
00091
00092 double StdMeshers_MaxLength::GetLength() const
00093 {
00094 return ( _preestimation && _preestimated > 0. ) ? _preestimated : _length;
00095 }
00096
00097
00102
00103
00104 void StdMeshers_MaxLength::SetUsePreestimatedLength(bool toUse)
00105 {
00106 if ( toUse != _preestimation )
00107 {
00108 _preestimation = toUse;
00109
00110
00111 }
00112 }
00113
00114
00118
00119
00120 void StdMeshers_MaxLength::SetPreestimatedLength(double length)
00121 {
00122 if ( length > 0 )
00123 _preestimated = length;
00124 }
00125
00126
00131
00132
00133 bool StdMeshers_MaxLength::GetUsePreestimatedLength() const
00134 {
00135 return _preestimation;
00136 }
00137
00138
00142
00143
00144 ostream & StdMeshers_MaxLength::SaveTo(ostream & save)
00145 {
00146 save << _length << " " << _preestimated << " " << _preestimation;
00147 return save;
00148 }
00149
00150
00154
00155
00156 istream & StdMeshers_MaxLength::LoadFrom(istream & load)
00157 {
00158 bool isOK = true;
00159 double a;
00160
00161 isOK = (load >> a);
00162 if (isOK)
00163 _length = a;
00164 else
00165 load.clear(ios::badbit | load.rdstate());
00166
00167 isOK = (load >> a);
00168 if (isOK)
00169 _preestimated = a;
00170 else
00171 load.clear(ios::badbit | load.rdstate());
00172
00173 bool pre;
00174 isOK = (load >> pre);
00175 if ( isOK )
00176 _preestimation = pre;
00177 else
00178 load.clear(ios::badbit | load.rdstate());
00179
00180 return load;
00181 }
00182
00183
00190
00191
00192 bool StdMeshers_MaxLength::SetParametersByMesh(const SMESH_Mesh* theMesh,
00193 const TopoDS_Shape& theShape)
00194 {
00195 if ( !theMesh || theShape.IsNull() )
00196 return false;
00197
00198 _length = 0.;
00199
00200 Standard_Real UMin, UMax;
00201 TopLoc_Location L;
00202
00203 int nbEdges = 0;
00204 TopTools_IndexedMapOfShape edgeMap;
00205 TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap );
00206 for ( int iE = 1; iE <= edgeMap.Extent(); ++iE )
00207 {
00208 const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( iE ));
00209 Handle(Geom_Curve) C = BRep_Tool::Curve( edge, L, UMin, UMax );
00210 GeomAdaptor_Curve AdaptCurve(C);
00211
00212 vector< double > params;
00213 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
00214 if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params ))
00215 {
00216 for ( int i = 1; i < params.size(); ++i )
00217 _length += GCPnts_AbscissaPoint::Length( AdaptCurve, params[ i-1 ], params[ i ]);
00218 nbEdges += params.size() - 1;
00219 }
00220 }
00221 if ( nbEdges )
00222 _length /= nbEdges;
00223
00224 return nbEdges;
00225 }
00226
00231
00232
00233 bool StdMeshers_MaxLength::SetParametersByDefaults(const TDefaults& dflts,
00234 const SMESH_Mesh* )
00235 {
00236
00237 if ( dflts._elemLength > 0. )
00238 _preestimated = dflts._elemLength;
00239 return ( _length = dflts._elemLength );
00240 }
00241