From 65f70369c2892f8bbc3a1e8ac0e7fd0111133f57 Mon Sep 17 00:00:00 2001 From: eap Date: Thu, 29 Dec 2005 15:05:20 +0000 Subject: [PATCH] PAL10953: add SetParametersByMesh() --- src/SMESH/SMESH_Hypothesis.hxx | 10 +++ src/StdMeshers/StdMeshers_Arithmetic1D.cxx | 68 +++++++++++++- src/StdMeshers/StdMeshers_Arithmetic1D.hxx | 16 +++- src/StdMeshers/StdMeshers_AutomaticLength.cxx | 81 +++++++++++++++-- src/StdMeshers/StdMeshers_AutomaticLength.hxx | 8 ++ src/StdMeshers/StdMeshers_Deflection1D.cxx | 88 +++++++++++++++++++ src/StdMeshers/StdMeshers_Deflection1D.hxx | 16 +++- src/StdMeshers/StdMeshers_LengthFromEdges.cxx | 22 ++++- src/StdMeshers/StdMeshers_LengthFromEdges.hxx | 18 +++- src/StdMeshers/StdMeshers_LocalLength.cxx | 73 +++++++++++++-- src/StdMeshers/StdMeshers_LocalLength.hxx | 30 ++++--- src/StdMeshers/StdMeshers_MaxElementArea.cxx | 55 +++++++++++- src/StdMeshers/StdMeshers_MaxElementArea.hxx | 30 ++++--- .../StdMeshers_MaxElementVolume.cxx | 65 +++++++++++++- .../StdMeshers_MaxElementVolume.hxx | 16 +++- .../StdMeshers_NotConformAllowed.cxx | 16 ++++ .../StdMeshers_NotConformAllowed.hxx | 19 +++- .../StdMeshers_NumberOfSegments.cxx | 58 ++++++++++-- .../StdMeshers_NumberOfSegments.hxx | 17 +++- src/StdMeshers/StdMeshers_Propagation.cxx | 20 ++++- src/StdMeshers/StdMeshers_Propagation.hxx | 18 +++- .../StdMeshers_QuadranglePreference.cxx | 16 ++++ .../StdMeshers_QuadranglePreference.hxx | 11 +++ src/StdMeshers/StdMeshers_Regular_1D.cxx | 9 +- src/StdMeshers/StdMeshers_StartEndLength.cxx | 65 +++++++++++++- src/StdMeshers/StdMeshers_StartEndLength.hxx | 19 ++-- 26 files changed, 764 insertions(+), 100 deletions(-) diff --git a/src/SMESH/SMESH_Hypothesis.hxx b/src/SMESH/SMESH_Hypothesis.hxx index 1d881a680..2edcd141a 100644 --- a/src/SMESH/SMESH_Hypothesis.hxx +++ b/src/SMESH/SMESH_Hypothesis.hxx @@ -32,6 +32,8 @@ #include "SMESHDS_Hypothesis.hxx" class SMESH_Gen; +class TopoDS_Shape; +class SMESH_Mesh; class SMESH_Hypothesis: public SMESHDS_Hypothesis { @@ -61,6 +63,14 @@ public: const char* GetLibName() const; void SetLibName(const char* theLibName); + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape)=0; + protected: SMESH_Gen* _gen; int _studyId; diff --git a/src/StdMeshers/StdMeshers_Arithmetic1D.cxx b/src/StdMeshers/StdMeshers_Arithmetic1D.cxx index c2241c07f..b4953a35a 100644 --- a/src/StdMeshers/StdMeshers_Arithmetic1D.cxx +++ b/src/StdMeshers/StdMeshers_Arithmetic1D.cxx @@ -26,20 +26,34 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_Arithmetic1D.hxx" +#include "SMESH_Algo.hxx" +#include "SMESH_Mesh.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + //============================================================================= /*! * */ //============================================================================= -StdMeshers_Arithmetic1D::StdMeshers_Arithmetic1D(int hypId, int studyId, - SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen) +StdMeshers_Arithmetic1D::StdMeshers_Arithmetic1D(int hypId, int studyId, SMESH_Gen * gen) + :SMESH_Hypothesis(hypId, studyId, gen) { _begLength = 1.; - _endLength = 1.; + _endLength = 10.; _name = "Arithmetic1D"; _param_algo_dim = 1; } @@ -137,3 +151,49 @@ istream & operator >>(istream & load, StdMeshers_Arithmetic1D & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize start and end length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_Arithmetic1D::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _begLength = _endLength = 0.; + + Standard_Real UMin, UMax; + TopLoc_Location L; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int i = 1; i <= edgeMap.Extent(); ++i ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i )); + Handle(Geom_Curve) C = BRep_Tool::Curve(edge, L, UMin, UMax); + GeomAdaptor_Curve AdaptCurve(C); + + vector< double > params; + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params )) + { + nbEdges++; + _begLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[0], params[1]); + int nb = params.size(); + _endLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[nb-2], params[nb-1]); + } + } + if ( nbEdges ) { + _begLength /= nbEdges; + _endLength /= nbEdges; + } + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_Arithmetic1D.hxx b/src/StdMeshers/StdMeshers_Arithmetic1D.hxx index ca49df175..0f5e2e045 100644 --- a/src/StdMeshers/StdMeshers_Arithmetic1D.hxx +++ b/src/StdMeshers/StdMeshers_Arithmetic1D.hxx @@ -43,10 +43,18 @@ public: double GetLength(bool isStartLength) const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream& operator << (ostream & save, StdMeshers_Arithmetic1D & hyp); - friend istream& operator >> (istream & load, StdMeshers_Arithmetic1D & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream& operator << (std::ostream & save, StdMeshers_Arithmetic1D & hyp); + friend std::istream& operator >> (std::istream & load, StdMeshers_Arithmetic1D & hyp); + + /*! + * \brief Initialize start and end length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); protected: double _begLength, _endLength; diff --git a/src/StdMeshers/StdMeshers_AutomaticLength.cxx b/src/StdMeshers/StdMeshers_AutomaticLength.cxx index 1176ebe18..fa74a7dc5 100644 --- a/src/StdMeshers/StdMeshers_AutomaticLength.cxx +++ b/src/StdMeshers/StdMeshers_AutomaticLength.cxx @@ -31,6 +31,7 @@ #include "SMESH_Mesh.hxx" #include "SMESHDS_Mesh.hxx" #include "SMESH_Algo.hxx" +#include "SMESHDS_SubMesh.hxx" #include "utilities.h" @@ -47,8 +48,8 @@ using namespace std; */ //============================================================================= -StdMeshers_AutomaticLength::StdMeshers_AutomaticLength(int hypId, int studyId, - SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen) +StdMeshers_AutomaticLength::StdMeshers_AutomaticLength(int hypId, int studyId, SMESH_Gen * gen) + :SMESH_Hypothesis(hypId, studyId, gen) { _name = "AutomaticLength"; _param_algo_dim = 1; // is used by SMESH_Regular_1D @@ -80,6 +81,9 @@ StdMeshers_AutomaticLength::~StdMeshers_AutomaticLength() */ //================================================================================ +const double theCoarseConst = 0.5; +const double theFineConst = 4.5; + void StdMeshers_AutomaticLength::SetFineness(double theFineness) throw(SALOME_Exception) { @@ -113,12 +117,11 @@ inline const TopoDS_TShape* getTShape(const TopoDS_Shape& theShape) */ //================================================================================ -static void computeLengths( const SMESH_Mesh* theMesh, +static void computeLengths( SMESHDS_Mesh* aMesh, map & theTShapeToLengthMap) { theTShapeToLengthMap.clear(); - SMESHDS_Mesh* aMesh = const_cast< SMESH_Mesh* > ( theMesh )->GetMeshDS(); TopoDS_Shape aMainShape = aMesh->ShapeToMesh(); // Find length of longest and shortest edge @@ -197,8 +200,10 @@ double StdMeshers_AutomaticLength::GetLength(const SMESH_Mesh* theMesh, if ( anEdge.IsNull() || anEdge.ShapeType() != TopAbs_EDGE ) throw SALOME_Exception(LOCALIZED("Bad edge shape")); - if ( theMesh != _mesh ) { - computeLengths( theMesh, _TShapeToLength ); + if ( theMesh != _mesh ) + { + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* > ( theMesh )->GetMeshDS(); + computeLengths( aMeshDS, _TShapeToLength ); _mesh = theMesh; } @@ -208,7 +213,7 @@ double StdMeshers_AutomaticLength::GetLength(const SMESH_Mesh* theMesh, if ( tshape_length == _TShapeToLength.end() ) return 1; // it is a dgenerated edge - return tshape_length->second / (0.5 + 4.5 * _fineness); + return tshape_length->second / (theCoarseConst + theFineConst * _fineness); } //============================================================================= @@ -257,3 +262,65 @@ istream & operator >>(istream & load, StdMeshers_AutomaticLength & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize Fineness by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_AutomaticLength::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _fineness = 0; + + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int i = 1; i <= edgeMap.Extent(); ++i ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i )); + + // assure the base automatic length is stored in _TShapeToLength + if ( i == 1 ) + GetLength( theMesh, edge ); + + // get current segment length + double L = SMESH_Algo::EdgeLength( edge ); + if ( L <= DBL_MIN ) + continue; + SMESHDS_SubMesh * eSubMesh = aMeshDS->MeshElements( edge ); + if ( !eSubMesh ) + return false; + double segLen = L / eSubMesh->NbElements(); + + // get segment length from _TShapeToLength + map::iterator tshape_length = + _TShapeToLength.find( getTShape( edge )); + if ( tshape_length == _TShapeToLength.end() ) + continue; + double autoLen = tshape_length->second; + + // segLen = autoLen / (theCoarseConst + theFineConst * _fineness) --> + _fineness += ( autoLen / segLen - theCoarseConst ) / theFineConst; + + ++nbEdges; + } + if ( nbEdges ) + _fineness /= nbEdges; + + if (_fineness > 1.0) + _fineness = 1.0; + else if (_fineness < 0.0) + _fineness = 0.0; + + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_AutomaticLength.hxx b/src/StdMeshers/StdMeshers_AutomaticLength.hxx index b8234b6db..fcdd63940 100644 --- a/src/StdMeshers/StdMeshers_AutomaticLength.hxx +++ b/src/StdMeshers/StdMeshers_AutomaticLength.hxx @@ -78,6 +78,14 @@ public: friend std::ostream & operator <<(std::ostream & save, StdMeshers_AutomaticLength & hyp); friend std::istream & operator >>(std::istream & load, StdMeshers_AutomaticLength & hyp); + /*! + * \brief Initialize Fineness by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + protected: std::map _TShapeToLength; const SMESH_Mesh* _mesh; diff --git a/src/StdMeshers/StdMeshers_Deflection1D.cxx b/src/StdMeshers/StdMeshers_Deflection1D.cxx index f6e54691c..bc97ab03f 100644 --- a/src/StdMeshers/StdMeshers_Deflection1D.cxx +++ b/src/StdMeshers/StdMeshers_Deflection1D.cxx @@ -30,6 +30,19 @@ using namespace std; #include "StdMeshers_Deflection1D.hxx" #include "utilities.h" +#include "SMESH_Mesh.hxx" +#include "SMESH_Algo.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //============================================================================= /*! @@ -134,3 +147,78 @@ istream & operator >>(istream & load, StdMeshers_Deflection1D & hyp) { return hyp.LoadFrom( load ); } +//================================================================================ +/*! + * \brief Evaluate curve deflection between two points + * \param theCurve - the curve + * \param theU1 - the parameter of the first point + * \param theU2 - the parameter of the second point + * \retval double - deflection value + */ +//================================================================================ + +static double deflection(const GeomAdaptor_Curve & theCurve, + double theU1, + double theU2) +{ + if ( theCurve.GetType() == GeomAbs_Line ) + return 0; + // line between theU1 and theU2 + gp_Pnt p1 = theCurve.Value( theU1 ), p2 = theCurve.Value( theU2 ); + gp_Lin segment( p1, gp_Vec( p1, p2 )); + + // evaluate square distance of theCurve from the segment + Standard_Real dist2 = 0; + const int nbPnt = 7; + const double step = ( theU2 - theU1 ) / nbPnt; + while (( theU1 += step ) < theU2 ) + dist2 = Max( dist2, segment.SquareDistance( theCurve.Value( theU1 ))); + + return sqrt( dist2 ); +} + +//================================================================================ +/*! + * \brief Initialize deflection value by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_Deflection1D::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _value = 0.; + + Standard_Real UMin, UMax; + TopLoc_Location L; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + + for ( int iE = 1; iE <= edgeMap.Extent(); ++iE ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( iE )); + Handle(Geom_Curve) C = BRep_Tool::Curve( edge, L, UMin, UMax ); + GeomAdaptor_Curve AdaptCurve(C); + if ( AdaptCurve.GetType() != GeomAbs_Line ) + { + vector< double > params; + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params )) + { + nbEdges++; + for ( int i = 1; i < params.size(); ++i ) + _value = Max( _value, deflection( AdaptCurve, params[ i-1 ], params[ i ])); + } + } + else + nbEdges++; + } + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_Deflection1D.hxx b/src/StdMeshers/StdMeshers_Deflection1D.hxx index 1ed43cb7d..8aa7112fe 100644 --- a/src/StdMeshers/StdMeshers_Deflection1D.hxx +++ b/src/StdMeshers/StdMeshers_Deflection1D.hxx @@ -41,10 +41,18 @@ class StdMeshers_Deflection1D:public SMESH_Hypothesis double GetDeflection() const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_Deflection1D & hyp); - friend istream & operator >>(istream & load, StdMeshers_Deflection1D & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_Deflection1D & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_Deflection1D & hyp); + + /*! + * \brief Initialize deflection value by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); protected: double _value; diff --git a/src/StdMeshers/StdMeshers_LengthFromEdges.cxx b/src/StdMeshers/StdMeshers_LengthFromEdges.cxx index f21f199f5..55adccca7 100644 --- a/src/StdMeshers/StdMeshers_LengthFromEdges.cxx +++ b/src/StdMeshers/StdMeshers_LengthFromEdges.cxx @@ -27,10 +27,12 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_LengthFromEdges.hxx" + #include "utilities.h" +using namespace std; + //============================================================================= /*! * @@ -42,8 +44,6 @@ StdMeshers_LengthFromEdges::StdMeshers_LengthFromEdges(int hypId, int studyId, S { _mode =1; _name = "LengthFromEdges"; -// SCRUTE(_name); -// SCRUTE(&_name); _param_algo_dim = 2; // is used by SMESH_MEFISTO_2D } @@ -137,3 +137,19 @@ istream & operator >> (istream & load, StdMeshers_LengthFromEdges & hyp) return hyp.LoadFrom( load ); } +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ +//================================================================================ + +bool StdMeshers_LengthFromEdges::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} diff --git a/src/StdMeshers/StdMeshers_LengthFromEdges.hxx b/src/StdMeshers/StdMeshers_LengthFromEdges.hxx index d514e7c94..c7b20a3b3 100644 --- a/src/StdMeshers/StdMeshers_LengthFromEdges.hxx +++ b/src/StdMeshers/StdMeshers_LengthFromEdges.hxx @@ -45,10 +45,20 @@ public: int GetMode(); - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, StdMeshers_LengthFromEdges & hyp); - friend istream & operator >> (istream & load, StdMeshers_LengthFromEdges & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator << (std::ostream & save, StdMeshers_LengthFromEdges & hyp); + friend std::istream & operator >> (std::istream & load, StdMeshers_LengthFromEdges & hyp); + + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); protected: int _mode; diff --git a/src/StdMeshers/StdMeshers_LocalLength.cxx b/src/StdMeshers/StdMeshers_LocalLength.cxx index 457d8d80c..90010a213 100644 --- a/src/StdMeshers/StdMeshers_LocalLength.cxx +++ b/src/StdMeshers/StdMeshers_LocalLength.cxx @@ -27,24 +27,37 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_LocalLength.hxx" + +#include "SMESH_Mesh.hxx" +#include "SMESH_Algo.hxx" + #include "utilities.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + //============================================================================= /*! * */ //============================================================================= -StdMeshers_LocalLength::StdMeshers_LocalLength(int hypId, int studyId, - SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen) +StdMeshers_LocalLength::StdMeshers_LocalLength(int hypId, int studyId, SMESH_Gen * gen) + :SMESH_Hypothesis(hypId, studyId, gen) { - _length = 1.; - _name = "LocalLength"; -// SCRUTE(_name); -// SCRUTE(&_name); - _param_algo_dim = 1; // is used by SMESH_Regular_1D + _length = 1.; + _name = "LocalLength"; + _param_algo_dim = 1; // is used by SMESH_Regular_1D } //============================================================================= @@ -135,3 +148,47 @@ istream & operator >>(istream & load, StdMeshers_LocalLength & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize segment length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_LocalLength::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _length = 0.; + + Standard_Real UMin, UMax; + TopLoc_Location L; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int iE = 1; iE <= edgeMap.Extent(); ++iE ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( iE )); + Handle(Geom_Curve) C = BRep_Tool::Curve( edge, L, UMin, UMax ); + GeomAdaptor_Curve AdaptCurve(C); + + vector< double > params; + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params )) + { + for ( int i = 1; i < params.size(); ++i ) + _length += GCPnts_AbscissaPoint::Length( AdaptCurve, params[ i-1 ], params[ i ]); + nbEdges += params.size() - 1; + } + } + if ( nbEdges ) + _length /= nbEdges; + + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_LocalLength.hxx b/src/StdMeshers/StdMeshers_LocalLength.hxx index aba58e51a..a48d2859b 100644 --- a/src/StdMeshers/StdMeshers_LocalLength.hxx +++ b/src/StdMeshers/StdMeshers_LocalLength.hxx @@ -35,21 +35,29 @@ class StdMeshers_LocalLength:public SMESH_Hypothesis { - public: - StdMeshers_LocalLength(int hypId, int studyId, SMESH_Gen * gen); - virtual ~ StdMeshers_LocalLength(); + public: + StdMeshers_LocalLength(int hypId, int studyId, SMESH_Gen * gen); + virtual ~ StdMeshers_LocalLength(); - void SetLength(double length) throw(SALOME_Exception); + void SetLength(double length) throw(SALOME_Exception); - double GetLength() const; + double GetLength() const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_LocalLength & hyp); - friend istream & operator >>(istream & load, StdMeshers_LocalLength & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_LocalLength & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_LocalLength & hyp); - protected: - double _length; + /*! + * \brief Initialize segment length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + + protected: + double _length; }; #endif diff --git a/src/StdMeshers/StdMeshers_MaxElementArea.cxx b/src/StdMeshers/StdMeshers_MaxElementArea.cxx index c4a2d5e17..08c69e68b 100644 --- a/src/StdMeshers/StdMeshers_MaxElementArea.cxx +++ b/src/StdMeshers/StdMeshers_MaxElementArea.cxx @@ -27,10 +27,20 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_MaxElementArea.hxx" + +#include "SMESH_ControlsDef.hxx" +#include "SMDS_MeshElement.hxx" +#include "SMESHDS_SubMesh.hxx" +#include "SMESH_Mesh.hxx" + +#include +#include + #include "utilities.h" +using namespace std; + //============================================================================= /*! * @@ -42,8 +52,6 @@ StdMeshers_MaxElementArea::StdMeshers_MaxElementArea(int hypId, int studyId, SME { _maxArea =1.; _name = "MaxElementArea"; -// SCRUTE(_name); -// SCRUTE(&_name); _param_algo_dim = 2; } @@ -137,3 +145,44 @@ istream & operator >> (istream & load, StdMeshers_MaxElementArea & hyp) return hyp.LoadFrom( load ); } +//================================================================================ +/*! + * \brief Initialize maximal area by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_MaxElementArea::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _maxArea = 0; + + SMESH::Controls::Area areaControl; + SMESH::Controls::TSequenceOfXYZ nodesCoords; + + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + + TopTools_IndexedMapOfShape faceMap; + TopExp::MapShapes( theShape, TopAbs_FACE, faceMap ); + for ( int iF = 1; iF <= faceMap.Extent(); ++iF ) + { + SMESHDS_SubMesh * subMesh = aMeshDS->MeshElements( faceMap( iF )); + if ( !subMesh ) + return false; + SMDS_ElemIteratorPtr fIt = subMesh->GetElements(); + while ( fIt->more() ) + { + const SMDS_MeshElement* elem = fIt->next(); + if ( elem->GetType() == SMDSAbs_Face ) { + areaControl.GetPoints( elem, nodesCoords ); + _maxArea = max( _maxArea, areaControl.GetValue( nodesCoords )); + } + } + } + return _maxArea > 0; +} diff --git a/src/StdMeshers/StdMeshers_MaxElementArea.hxx b/src/StdMeshers/StdMeshers_MaxElementArea.hxx index 52af887c8..44e8d0921 100644 --- a/src/StdMeshers/StdMeshers_MaxElementArea.hxx +++ b/src/StdMeshers/StdMeshers_MaxElementArea.hxx @@ -35,21 +35,29 @@ class StdMeshers_MaxElementArea:public SMESH_Hypothesis { - public: - StdMeshers_MaxElementArea(int hypId, int studyId, SMESH_Gen * gen); - virtual ~ StdMeshers_MaxElementArea(); +public: + StdMeshers_MaxElementArea(int hypId, int studyId, SMESH_Gen * gen); + virtual ~ StdMeshers_MaxElementArea(); - void SetMaxArea(double maxArea) throw(SALOME_Exception); + void SetMaxArea(double maxArea) throw(SALOME_Exception); - double GetMaxArea() const; + double GetMaxArea() const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_MaxElementArea & hyp); - friend istream & operator >>(istream & load, StdMeshers_MaxElementArea & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_MaxElementArea & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_MaxElementArea & hyp); - protected: - double _maxArea; + /*! + * \brief Initialize maximal area by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + +protected: + double _maxArea; }; #endif diff --git a/src/StdMeshers/StdMeshers_MaxElementVolume.cxx b/src/StdMeshers/StdMeshers_MaxElementVolume.cxx index f9f6b6322..c4e58949f 100644 --- a/src/StdMeshers/StdMeshers_MaxElementVolume.cxx +++ b/src/StdMeshers/StdMeshers_MaxElementVolume.cxx @@ -30,8 +30,18 @@ using namespace std; #include "StdMeshers_MaxElementVolume.hxx" + +#include "SMDS_MeshElement.hxx" +#include "SMESHDS_SubMesh.hxx" +#include "SMESH_ControlsDef.hxx" +#include "SMESH_Mesh.hxx" + #include "utilities.h" +#include +#include +#include + //============================================================================= /*! * @@ -41,10 +51,8 @@ using namespace std; StdMeshers_MaxElementVolume::StdMeshers_MaxElementVolume(int hypId, int studyId, SMESH_Gen* gen) : SMESH_Hypothesis(hypId, studyId, gen) { - _maxVolume =1.; + _maxVolume = 1.; _name = "MaxElementVolume"; -// SCRUTE(_name); - SCRUTE(&_name); _param_algo_dim = 3; } @@ -139,3 +147,54 @@ istream & operator >> (istream & load, StdMeshers_MaxElementVolume & hyp) return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize maximal area by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_MaxElementVolume::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _maxVolume = 0; + + SMESH::Controls::Volume volumeControl; + + TopTools_IndexedMapOfShape volMap; + TopExp::MapShapes( theShape, TopAbs_SOLID, volMap ); + if ( volMap.IsEmpty() ) + TopExp::MapShapes( theShape, TopAbs_SHELL, volMap ); + if ( volMap.IsEmpty() ) + return false; + + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + + for ( int iV = 1; iV <= volMap.Extent(); ++iV ) + { + const TopoDS_Shape& S = volMap( iV ); + SMESHDS_SubMesh * subMesh = aMeshDS->MeshElements( S ); + if ( !subMesh && S.ShapeType() == TopAbs_SOLID ) { + TopExp_Explorer shellExp( S, TopAbs_SHELL ); + if ( shellExp.More() ) + subMesh = aMeshDS->MeshElements( shellExp.Current() ); + } + if ( !subMesh) + return false; + SMDS_ElemIteratorPtr vIt = subMesh->GetElements(); + while ( vIt->more() ) + { + const SMDS_MeshElement* elem = vIt->next(); + if ( elem->GetType() == SMDSAbs_Volume ) { + _maxVolume = max( _maxVolume, volumeControl.GetValue( elem->GetID() )); + } + } + } + return _maxVolume > 0; +} diff --git a/src/StdMeshers/StdMeshers_MaxElementVolume.hxx b/src/StdMeshers/StdMeshers_MaxElementVolume.hxx index ee9986f1f..870aac92a 100644 --- a/src/StdMeshers/StdMeshers_MaxElementVolume.hxx +++ b/src/StdMeshers/StdMeshers_MaxElementVolume.hxx @@ -45,10 +45,18 @@ public: double GetMaxVolume() const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, StdMeshers_MaxElementVolume & hyp); - friend istream & operator >> (istream & load, StdMeshers_MaxElementVolume & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator << (std::ostream & save, StdMeshers_MaxElementVolume & hyp); + friend std::istream & operator >> (std::istream & load, StdMeshers_MaxElementVolume & hyp); + + /*! + * \brief Initialize maximal volume by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); protected: double _maxVolume; diff --git a/src/StdMeshers/StdMeshers_NotConformAllowed.cxx b/src/StdMeshers/StdMeshers_NotConformAllowed.cxx index 5c471b2a0..5799cbce6 100644 --- a/src/StdMeshers/StdMeshers_NotConformAllowed.cxx +++ b/src/StdMeshers/StdMeshers_NotConformAllowed.cxx @@ -96,3 +96,19 @@ istream & operator >> (istream & load, StdMeshers_NotConformAllowed & hyp) { return load; } +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ +//================================================================================ + +bool StdMeshers_NotConformAllowed::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} diff --git a/src/StdMeshers/StdMeshers_NotConformAllowed.hxx b/src/StdMeshers/StdMeshers_NotConformAllowed.hxx index 079742458..3ffb7b71c 100644 --- a/src/StdMeshers/StdMeshers_NotConformAllowed.hxx +++ b/src/StdMeshers/StdMeshers_NotConformAllowed.hxx @@ -39,10 +39,21 @@ public: StdMeshers_NotConformAllowed(int hypId, int studyId, SMESH_Gen* gen); virtual ~StdMeshers_NotConformAllowed(); - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, StdMeshers_NotConformAllowed & hyp); - friend istream & operator >> (istream & load, StdMeshers_NotConformAllowed & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator << (std::ostream & save, StdMeshers_NotConformAllowed & hyp); + friend std::istream & operator >> (std::istream & load, StdMeshers_NotConformAllowed & hyp); + + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + }; #endif diff --git a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx index 0b9d33355..139ea22e6 100644 --- a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx +++ b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx @@ -27,20 +27,27 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_NumberOfSegments.hxx" + #include "StdMeshers_Distribution.hxx" -#include -#include -#include -#include +#include "SMESHDS_SubMesh.hxx" +#include "SMESH_Mesh.hxx" + #include -#include #include -#include +#include +#include #include +#include +#include #include +#include +#include +#include +#include + +using namespace std; const double PRECISION = 1e-7; @@ -640,3 +647,40 @@ istream & operator >>(istream & load, StdMeshers_NumberOfSegments & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize number of segments by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_NumberOfSegments::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _numberOfSegments = 0; + _distrType = DT_Regular; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int i = 1; i <= edgeMap.Extent(); ++i ) + { + // get current segment length + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + SMESHDS_SubMesh * eSubMesh = aMeshDS->MeshElements( edgeMap( i )); + if ( eSubMesh && eSubMesh->NbElements()) + _numberOfSegments += eSubMesh->NbElements(); + + ++nbEdges; + } + if ( nbEdges ) + _numberOfSegments /= nbEdges; + + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_NumberOfSegments.hxx b/src/StdMeshers/StdMeshers_NumberOfSegments.hxx index 28d829b75..3878330c8 100644 --- a/src/StdMeshers/StdMeshers_NumberOfSegments.hxx +++ b/src/StdMeshers/StdMeshers_NumberOfSegments.hxx @@ -161,10 +161,19 @@ public: int ConversionMode() const throw (SALOME_Exception); - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream& operator << (ostream & save, StdMeshers_NumberOfSegments & hyp); - friend istream& operator >> (istream & load, StdMeshers_NumberOfSegments & hyp); + + /*! + * \brief Initialize number of segments by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream& operator << (std::ostream & save, StdMeshers_NumberOfSegments & hyp); + friend std::istream& operator >> (std::istream & load, StdMeshers_NumberOfSegments & hyp); protected: int _numberOfSegments; //!< an edge will be split on to this number of segments diff --git a/src/StdMeshers/StdMeshers_Propagation.cxx b/src/StdMeshers/StdMeshers_Propagation.cxx index f314b4c28..6672e2565 100644 --- a/src/StdMeshers/StdMeshers_Propagation.cxx +++ b/src/StdMeshers/StdMeshers_Propagation.cxx @@ -24,10 +24,12 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_Propagation.hxx" + #include "utilities.h" +using namespace std; + //============================================================================= /*! * @@ -100,3 +102,19 @@ std::string StdMeshers_Propagation::GetName () { return "Propagation"; } +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ +//================================================================================ + +bool StdMeshers_Propagation::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} diff --git a/src/StdMeshers/StdMeshers_Propagation.hxx b/src/StdMeshers/StdMeshers_Propagation.hxx index 4ee7c5628..ef750b9ed 100644 --- a/src/StdMeshers/StdMeshers_Propagation.hxx +++ b/src/StdMeshers/StdMeshers_Propagation.hxx @@ -36,12 +36,22 @@ class StdMeshers_Propagation:public SMESH_Hypothesis StdMeshers_Propagation(int hypId, int studyId, SMESH_Gen * gen); virtual ~ StdMeshers_Propagation(); - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_Propagation & hyp); - friend istream & operator >>(istream & load, StdMeshers_Propagation & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_Propagation & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_Propagation & hyp); static std::string GetName (); + + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); }; #endif diff --git a/src/StdMeshers/StdMeshers_QuadranglePreference.cxx b/src/StdMeshers/StdMeshers_QuadranglePreference.cxx index 4ba3dd8ed..60dc49499 100644 --- a/src/StdMeshers/StdMeshers_QuadranglePreference.cxx +++ b/src/StdMeshers/StdMeshers_QuadranglePreference.cxx @@ -98,3 +98,19 @@ istream & operator >>(istream & load, StdMeshers_QuadranglePreference & hyp) { return hyp.LoadFrom( load ); } +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ +//================================================================================ + +bool StdMeshers_QuadranglePreference::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} diff --git a/src/StdMeshers/StdMeshers_QuadranglePreference.hxx b/src/StdMeshers/StdMeshers_QuadranglePreference.hxx index eb2fdca04..ba6eaef5e 100644 --- a/src/StdMeshers/StdMeshers_QuadranglePreference.hxx +++ b/src/StdMeshers/StdMeshers_QuadranglePreference.hxx @@ -47,6 +47,17 @@ class StdMeshers_QuadranglePreference:public SMESH_Hypothesis virtual std::istream & LoadFrom(std::istream & load); friend std::ostream & operator <<(std::ostream & save, StdMeshers_QuadranglePreference & hyp); friend std::istream & operator >>(std::istream & load, StdMeshers_QuadranglePreference & hyp); + + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + }; #endif diff --git a/src/StdMeshers/StdMeshers_Regular_1D.cxx b/src/StdMeshers/StdMeshers_Regular_1D.cxx index 6bc2ca700..1723d6549 100644 --- a/src/StdMeshers/StdMeshers_Regular_1D.cxx +++ b/src/StdMeshers/StdMeshers_Regular_1D.cxx @@ -27,21 +27,17 @@ // Module : SMESH // $Header$ -using namespace std; - #include "StdMeshers_Regular_1D.hxx" #include "StdMeshers_Distribution.hxx" #include "SMESH_Gen.hxx" #include "SMESH_Mesh.hxx" -#include - #include "StdMeshers_LocalLength.hxx" #include "StdMeshers_NumberOfSegments.hxx" #include "StdMeshers_Arithmetic1D.hxx" #include "StdMeshers_StartEndLength.hxx" #include "StdMeshers_Deflection1D.hxx" -#include +#include "StdMeshers_AutomaticLength.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" @@ -66,10 +62,13 @@ using namespace std; #include #include #include +#include #include #include +using namespace std; + //============================================================================= /*! * diff --git a/src/StdMeshers/StdMeshers_StartEndLength.cxx b/src/StdMeshers/StdMeshers_StartEndLength.cxx index 1d7016206..46320768f 100644 --- a/src/StdMeshers/StdMeshers_StartEndLength.cxx +++ b/src/StdMeshers/StdMeshers_StartEndLength.cxx @@ -25,11 +25,22 @@ // Module : SMESH // $Header$ -using namespace std; - #include "StdMeshers_StartEndLength.hxx" -#include "utilities.h" +#include "SMESH_Algo.hxx" +#include "SMESH_Mesh.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; //============================================================================= /*! @@ -43,7 +54,7 @@ StdMeshers_StartEndLength::StdMeshers_StartEndLength(int hypId, :SMESH_Hypothesis(hypId, studyId, gen) { _begLength = 1.; - _endLength = 1.; + _endLength = 10.; _name = "StartEndLength"; _param_algo_dim = 1; // is used by SMESH_Regular_1D } @@ -141,3 +152,49 @@ istream & operator >>(istream & load, StdMeshers_StartEndLength & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize start and end length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_StartEndLength::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _begLength = _endLength = 0.; + + Standard_Real UMin, UMax; + TopLoc_Location L; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int i = 1; i <= edgeMap.Extent(); ++i ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i )); + Handle(Geom_Curve) C = BRep_Tool::Curve(edge, L, UMin, UMax); + GeomAdaptor_Curve AdaptCurve(C); + + vector< double > params; + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params )) + { + nbEdges++; + _begLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[0], params[1]); + int nb = params.size(); + _endLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[nb-2], params[nb-1]); + } + } + if ( nbEdges ) { + _begLength /= nbEdges; + _endLength /= nbEdges; + } + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_StartEndLength.hxx b/src/StdMeshers/StdMeshers_StartEndLength.hxx index 05bd2e0bb..52a8a58b2 100644 --- a/src/StdMeshers/StdMeshers_StartEndLength.hxx +++ b/src/StdMeshers/StdMeshers_StartEndLength.hxx @@ -41,12 +41,21 @@ class StdMeshers_StartEndLength:public SMESH_Hypothesis double GetLength(bool isStartLength) const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_StartEndLength & hyp); - friend istream & operator >>(istream & load, StdMeshers_StartEndLength & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_StartEndLength & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_StartEndLength & hyp); - protected: + + /*! + * \brief Initialize start and end length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + +protected: double _begLength, _endLength; }; -- 2.30.2