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 #include "StdMeshers_Deflection1D.hxx"
00028 #include "utilities.h"
00029
00030 #include "SMESH_Mesh.hxx"
00031 #include "SMESH_Algo.hxx"
00032
00033 #include <BRep_Tool.hxx>
00034 #include <GeomAdaptor_Curve.hxx>
00035 #include <Geom_Curve.hxx>
00036 #include <TopExp.hxx>
00037 #include <TopLoc_Location.hxx>
00038 #include <TopTools_IndexedMapOfShape.hxx>
00039 #include <TopoDS.hxx>
00040 #include <TopoDS_Edge.hxx>
00041 #include <gp_Lin.hxx>
00042 #include <gp_Pnt.hxx>
00043
00044 using namespace std;
00045
00046
00050
00051
00052 StdMeshers_Deflection1D::StdMeshers_Deflection1D(int hypId,
00053 int studyId,
00054 SMESH_Gen * gen)
00055 :SMESH_Hypothesis(hypId, studyId, gen)
00056 {
00057 _value = 1.;
00058 _name = "Deflection1D";
00059 _param_algo_dim = 1;
00060 }
00061
00062
00066
00067
00068 StdMeshers_Deflection1D::~StdMeshers_Deflection1D()
00069 {
00070 }
00071
00072
00076
00077
00078 void StdMeshers_Deflection1D::SetDeflection(double value)
00079 throw(SALOME_Exception)
00080 {
00081 if (_value != value) {
00082 if (value <= 0.)
00083 throw SALOME_Exception(LOCALIZED("Value must be positive"));
00084
00085 NotifySubMeshesHypothesisModification();
00086
00087 _value = value;
00088 }
00089 }
00090
00091
00095
00096
00097 double StdMeshers_Deflection1D::GetDeflection() const
00098 {
00099 return _value;
00100 }
00101
00102
00106
00107
00108 ostream & StdMeshers_Deflection1D::SaveTo(ostream & save)
00109 {
00110 save << _value;
00111 return save;
00112 }
00113
00114
00118
00119
00120 istream & StdMeshers_Deflection1D::LoadFrom(istream & load)
00121 {
00122 bool isOK = (load >> _value);
00123 if (!isOK)
00124 load.clear(ios::badbit | load.rdstate());
00125 return load;
00126 }
00127
00128
00132
00133
00134 ostream & operator <<(ostream & save, StdMeshers_Deflection1D & hyp)
00135 {
00136 return hyp.SaveTo( save );
00137 }
00138
00139
00143
00144
00145 istream & operator >>(istream & load, StdMeshers_Deflection1D & hyp)
00146 {
00147 return hyp.LoadFrom( load );
00148 }
00149
00157
00158
00159 static double deflection(const GeomAdaptor_Curve & theCurve,
00160 double theU1,
00161 double theU2)
00162 {
00163 if ( theCurve.GetType() == GeomAbs_Line )
00164 return 0;
00165
00166 gp_Pnt p1 = theCurve.Value( theU1 ), p2 = theCurve.Value( theU2 );
00167 gp_Lin segment( p1, gp_Vec( p1, p2 ));
00168
00169
00170 Standard_Real dist2 = 0;
00171 const int nbPnt = 7;
00172 const double step = ( theU2 - theU1 ) / nbPnt;
00173 while (( theU1 += step ) < theU2 )
00174 dist2 = Max( dist2, segment.SquareDistance( theCurve.Value( theU1 )));
00175
00176 return sqrt( dist2 );
00177 }
00178
00179
00186
00187
00188 bool StdMeshers_Deflection1D::SetParametersByMesh(const SMESH_Mesh* theMesh,
00189 const TopoDS_Shape& theShape)
00190 {
00191 if ( !theMesh || theShape.IsNull() )
00192 return false;
00193
00194 _value = 0.;
00195
00196 Standard_Real UMin, UMax;
00197 TopLoc_Location L;
00198
00199 int nbEdges = 0;
00200 TopTools_IndexedMapOfShape edgeMap;
00201 TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap );
00202
00203 for ( int iE = 1; iE <= edgeMap.Extent(); ++iE )
00204 {
00205 const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( iE ));
00206 Handle(Geom_Curve) C = BRep_Tool::Curve( edge, L, UMin, UMax );
00207 GeomAdaptor_Curve AdaptCurve(C);
00208 if ( AdaptCurve.GetType() != GeomAbs_Line )
00209 {
00210 vector< double > params;
00211 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
00212 if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params ))
00213 {
00214 nbEdges++;
00215 for ( int i = 1; i < params.size(); ++i )
00216 _value = Max( _value, deflection( AdaptCurve, params[ i-1 ], params[ i ]));
00217 }
00218 }
00219 else
00220 nbEdges++;
00221 }
00222 return nbEdges;
00223 }
00224
00225
00230
00231
00232 bool StdMeshers_Deflection1D::SetParametersByDefaults(const TDefaults& ,
00233 const SMESH_Mesh* )
00234 {
00235 return false;
00236 }