From ed603f1ed0ce219638737094aa1a603b5a50ceb6 Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Fri, 29 Apr 2016 17:59:28 +0200 Subject: [PATCH] z interpolation parameter on Python script --- src/HYDROData/HYDROData_AltitudeObject.cxx | 3 ++- src/HYDROData/HYDROData_AltitudeObject.h | 3 ++- src/HYDROData/HYDROData_Bathymetry.cxx | 8 ++++--- src/HYDROData/HYDROData_Bathymetry.h | 3 ++- src/HYDROData/HYDROData_CalculationCase.cxx | 24 ++++++++++++-------- src/HYDROData/HYDROData_CalculationCase.h | 14 ++++++++---- src/HYDROData/HYDROData_ChannelAltitude.cxx | 3 ++- src/HYDROData/HYDROData_ChannelAltitude.h | 3 ++- src/HYDROData/HYDROData_IAltitudeObject.h | 2 +- src/HYDROData/HYDROData_IInterpolator.cxx | 2 +- src/HYDROData/HYDROData_ObstacleAltitude.cxx | 3 ++- src/HYDROData/HYDROData_ObstacleAltitude.h | 3 ++- src/HYDROData/HYDROData_StreamAltitude.cxx | 3 ++- src/HYDROData/HYDROData_StreamAltitude.h | 3 ++- src/HYDROPy/HYDROData_CalculationCase.sip | 22 ++++++++++-------- src/HYDROTools/interpolZ.py | 5 ++-- 16 files changed, 64 insertions(+), 40 deletions(-) diff --git a/src/HYDROData/HYDROData_AltitudeObject.cxx b/src/HYDROData/HYDROData_AltitudeObject.cxx index bec22559..0286c1e3 100644 --- a/src/HYDROData/HYDROData_AltitudeObject.cxx +++ b/src/HYDROData/HYDROData_AltitudeObject.cxx @@ -51,7 +51,8 @@ QStringList HYDROData_AltitudeObject::DumpToPython( const QString& thePyScriptPa return aResList; } -double HYDROData_AltitudeObject::GetAltitudeForPoint( const gp_XY& thePoint ) const +double HYDROData_AltitudeObject::GetAltitudeForPoint( const gp_XY& thePoint, + int theMethod) const { DEBTRACE("HYDROData_AltitudeObject::GetAltitudeForPoint"); double aResAltitude = GetInvalidAltitude(); diff --git a/src/HYDROData/HYDROData_AltitudeObject.h b/src/HYDROData/HYDROData_AltitudeObject.h index 3d10f39b..5770be48 100644 --- a/src/HYDROData/HYDROData_AltitudeObject.h +++ b/src/HYDROData/HYDROData_AltitudeObject.h @@ -67,7 +67,8 @@ public: * \param thePoint the point to examine * \return altitude value */ - HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint ) const; + HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint, + int theMethod = 0) const; protected: diff --git a/src/HYDROData/HYDROData_Bathymetry.cxx b/src/HYDROData/HYDROData_Bathymetry.cxx index 05fd2701..34bd4a21 100644 --- a/src/HYDROData/HYDROData_Bathymetry.cxx +++ b/src/HYDROData/HYDROData_Bathymetry.cxx @@ -350,9 +350,9 @@ bool interpolZtriangle(const gp_XY& point, vtkPolyData* delaunay2D, vtkIdList* t return false; } -double HYDROData_Bathymetry::GetAltitudeForPoint(const gp_XY& thePoint) const +double HYDROData_Bathymetry::GetAltitudeForPoint(const gp_XY& thePoint, int theMethod) const { - DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << ")"); + DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << "), interpolation method: " << theMethod); double anInvalidAltitude = GetInvalidAltitude(); double aResAltitude = anInvalidAltitude; @@ -384,7 +384,9 @@ double HYDROData_Bathymetry::GetAltitudeForPoint(const gp_XY& thePoint) const // - get the triangle containing the point in the Delaunay2D mesh, // - interpolate altitude - bool isBathyInterpolRequired = true; + bool isBathyInterpolRequired = false; + if (theMethod) + isBathyInterpolRequired =true; if (isBathyInterpolRequired) { vtkPolyData* aDelaunay2D = GetVtkDelaunay2D(); diff --git a/src/HYDROData/HYDROData_Bathymetry.h b/src/HYDROData/HYDROData_Bathymetry.h index 1d4493b2..6a555afd 100644 --- a/src/HYDROData/HYDROData_Bathymetry.h +++ b/src/HYDROData/HYDROData_Bathymetry.h @@ -101,9 +101,10 @@ public: /** * Returns altitude for given point. * \param thePoint the point to examine + * \param theMethod interpolation model, default 0 = nearest point * \return altitude value */ - HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint ) const; + HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint, int theMethod=0 ) const; public: // Public methods to work with files. diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 5aebfb76..78c2de68 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -719,7 +719,8 @@ double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) c } double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint, - const Handle(HYDROData_Region)& theRegion ) const + const Handle(HYDROData_Region)& theRegion, + int theMethod) const { double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude(); @@ -729,11 +730,11 @@ double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& //DEBTRACE("GetAltitudeForPoint Region " << theRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString()); Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( aZone->GetFatherObject() ); if ( IsEqual( aRefRegion, theRegion ) ) - aResAltitude = GetAltitudeForPoint( thePoint, aZone ); + aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod ); else { DEBTRACE("GetAltitudeForPoint Region " << aRefRegion->GetName().toStdString() << " Zone " << aZone->GetName().toStdString() << " ---------------------------"); - aResAltitude = GetAltitudeForPoint( thePoint, aZone ); + aResAltitude = GetAltitudeForPoint( thePoint, aZone, theMethod ); } } else @@ -745,7 +746,8 @@ double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& } double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint, - const Handle(HYDROData_Zone)& theZone ) const + const Handle(HYDROData_Zone)& theZone, + int theMethod) const { //DEBTRACE("GetAltitudeForPoint Zone " << theZone->GetName().toStdString()); double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude(); @@ -814,7 +816,7 @@ double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& else { //DEBTRACE("aZoneInterpolator == NULL"); - aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint ); + aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint, theMethod ); } if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ) @@ -849,16 +851,17 @@ double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& NCollection_Sequence HYDROData_CalculationCase::GetAltitudesForPoints( const NCollection_Sequence& thePoints, - const Handle(HYDROData_Region)& theRegion ) const + const Handle(HYDROData_Region)& theRegion, + int theMethod) const { - //DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString()); + DEBTRACE("HYDROData_CalculationCase::GetAltitudesForPoints " << theRegion->GetName().toStdString()); NCollection_Sequence aResSeq; for ( int i = 1, n = thePoints.Length(); i <= n; ++i ) { const gp_XY& thePnt = thePoints.Value( i ); - double anAltitude = GetAltitudeForPoint( thePnt, theRegion ); + double anAltitude = GetAltitudeForPoint( thePnt, theRegion, theMethod ); aResSeq.Append( anAltitude ); } @@ -867,7 +870,8 @@ NCollection_Sequence HYDROData_CalculationCase::GetAltitudesForPoints( NCollection_Sequence HYDROData_CalculationCase::GetAltitudesForPoints( const NCollection_Sequence& thePoints, - const Handle(HYDROData_Zone)& theZone ) const + const Handle(HYDROData_Zone)& theZone, + int theMethod) const { NCollection_Sequence aResSeq; @@ -875,7 +879,7 @@ NCollection_Sequence HYDROData_CalculationCase::GetAltitudesForPoints( { const gp_XY& thePnt = thePoints.Value( i ); - double anAltitude = GetAltitudeForPoint( thePnt, theZone ); + double anAltitude = GetAltitudeForPoint( thePnt, theZone, theMethod ); aResSeq.Append( anAltitude ); } diff --git a/src/HYDROData/HYDROData_CalculationCase.h b/src/HYDROData/HYDROData_CalculationCase.h index 88f2c901..1780ca9c 100644 --- a/src/HYDROData/HYDROData_CalculationCase.h +++ b/src/HYDROData/HYDROData_CalculationCase.h @@ -59,7 +59,7 @@ DEFINE_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity) /**\class HYDROData_CalculationCase - * \brief Calculation case is defined by selection of Geometry objects with or without “Zone of water”. + * \brief Calculation case is defined by selection of Geometry objects with or without �Zone of water�. * */ class HYDROData_CalculationCase : public HYDROData_Entity @@ -313,7 +313,8 @@ public: * \return result altitude value */ HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint, - const Handle(HYDROData_Region)& theRegion ) const; + const Handle(HYDROData_Region)& theRegion, + int theMethod = 0) const; /** * Returns altitude for given point on given zone. @@ -322,7 +323,8 @@ public: * \return result altitude value */ HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint, - const Handle(HYDROData_Zone)& theZone ) const; + const Handle(HYDROData_Zone)& theZone, + int theMethod = 0) const; /** * Returns strickler coefficient for given point. @@ -339,7 +341,8 @@ public: */ HYDRODATA_EXPORT virtual NCollection_Sequence GetAltitudesForPoints( const NCollection_Sequence& thePoints, - const Handle(HYDROData_Region)& theRegion ) const; + const Handle(HYDROData_Region)& theRegion, + int theMethod = 0) const; /** * Returns altitudes for given points on given zone. @@ -349,7 +352,8 @@ public: */ HYDRODATA_EXPORT virtual NCollection_Sequence GetAltitudesForPoints( const NCollection_Sequence& thePoints, - const Handle(HYDROData_Zone)& theZone ) const; + const Handle(HYDROData_Zone)& theZone, + int theMethod = 0) const; /** * Returns region to which the point is belongs. diff --git a/src/HYDROData/HYDROData_ChannelAltitude.cxx b/src/HYDROData/HYDROData_ChannelAltitude.cxx index 413685f8..92d4d2fe 100644 --- a/src/HYDROData/HYDROData_ChannelAltitude.cxx +++ b/src/HYDROData/HYDROData_ChannelAltitude.cxx @@ -65,7 +65,8 @@ HYDROData_ChannelAltitude::~HYDROData_ChannelAltitude() { } -double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) const +double HYDROData_ChannelAltitude::GetAltitudeForPoint( const gp_XY& thePoint, + int theMethod) const { DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << ")"); double aResAltitude = GetInvalidAltitude(); diff --git a/src/HYDROData/HYDROData_ChannelAltitude.h b/src/HYDROData/HYDROData_ChannelAltitude.h index 0eb7b701..480e14fc 100644 --- a/src/HYDROData/HYDROData_ChannelAltitude.h +++ b/src/HYDROData/HYDROData_ChannelAltitude.h @@ -60,7 +60,8 @@ public: * \param thePoint the point to examine * \return altitude value */ - HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint ) const; + HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint, + int theMethod =0) const; protected: diff --git a/src/HYDROData/HYDROData_IAltitudeObject.h b/src/HYDROData/HYDROData_IAltitudeObject.h index 50d65d95..a6d36589 100644 --- a/src/HYDROData/HYDROData_IAltitudeObject.h +++ b/src/HYDROData/HYDROData_IAltitudeObject.h @@ -65,7 +65,7 @@ public: * \param thePoint the point to examine * \return altitude value */ - HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint ) const = 0; + HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint, int theMethod=0 ) const = 0; protected: diff --git a/src/HYDROData/HYDROData_IInterpolator.cxx b/src/HYDROData/HYDROData_IInterpolator.cxx index da40d517..2e3f3e87 100644 --- a/src/HYDROData/HYDROData_IInterpolator.cxx +++ b/src/HYDROData/HYDROData_IInterpolator.cxx @@ -48,7 +48,7 @@ double HYDROData_IInterpolator::GetAltitudeForPoint( const double theCoordX, con myAltitudeObject->GetAltitudeForPoint( gp_XY( theCoordX, theCoordY ) ); } -double HYDROData_IInterpolator::GetAltitudeForPoint( const gp_XY& thePoint ) const +double HYDROData_IInterpolator::GetAltitudeForPoint( const gp_XY& thePoint) const { DEBTRACE("HYDROData_IInterpolator::GetAltitudeForPoint"); return GetAltitudeForPoint( thePoint.X(), thePoint.Y() ); diff --git a/src/HYDROData/HYDROData_ObstacleAltitude.cxx b/src/HYDROData/HYDROData_ObstacleAltitude.cxx index a91e8359..cba53dfa 100644 --- a/src/HYDROData/HYDROData_ObstacleAltitude.cxx +++ b/src/HYDROData/HYDROData_ObstacleAltitude.cxx @@ -43,7 +43,8 @@ HYDROData_ObstacleAltitude::~HYDROData_ObstacleAltitude() { } -double HYDROData_ObstacleAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) const +double HYDROData_ObstacleAltitude::GetAltitudeForPoint( const gp_XY& thePoint, + int theMethod) const { DEBTRACE("HYDROData_ObstacleAltitude::GetAltitudeForPoint"); double aResAltitude = GetInvalidAltitude(); diff --git a/src/HYDROData/HYDROData_ObstacleAltitude.h b/src/HYDROData/HYDROData_ObstacleAltitude.h index ba95ba9b..3dc1e2ce 100644 --- a/src/HYDROData/HYDROData_ObstacleAltitude.h +++ b/src/HYDROData/HYDROData_ObstacleAltitude.h @@ -60,7 +60,8 @@ public: * \param thePoint the point to examine * \return altitude value */ - HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint ) const; + HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint, + int theMethod = 0) const; protected: diff --git a/src/HYDROData/HYDROData_StreamAltitude.cxx b/src/HYDROData/HYDROData_StreamAltitude.cxx index 4811380b..d00d47c8 100644 --- a/src/HYDROData/HYDROData_StreamAltitude.cxx +++ b/src/HYDROData/HYDROData_StreamAltitude.cxx @@ -281,7 +281,8 @@ bool HYDROData_StreamAltitude::getBoundaryWiresForPoint( return !theLeftWire.IsNull() && !theRightWire.IsNull(); } -double HYDROData_StreamAltitude::GetAltitudeForPoint( const gp_XY& thePoint ) const +double HYDROData_StreamAltitude::GetAltitudeForPoint( const gp_XY& thePoint, + int theMethod) const { DEBTRACE("GetAltitudeForPoint p(" << thePoint.X() << ", " << thePoint.Y() << ")"); double aResAltitude = GetInvalidAltitude(); diff --git a/src/HYDROData/HYDROData_StreamAltitude.h b/src/HYDROData/HYDROData_StreamAltitude.h index 02cbc308..77bf0b2a 100644 --- a/src/HYDROData/HYDROData_StreamAltitude.h +++ b/src/HYDROData/HYDROData_StreamAltitude.h @@ -61,7 +61,8 @@ public: * \param thePoint the point to examine * \return altitude value */ - HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint ) const; + HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint, + int theMethod = 0) const; protected: diff --git a/src/HYDROPy/HYDROData_CalculationCase.sip b/src/HYDROPy/HYDROData_CalculationCase.sip index d7cd1593..cbca3857 100644 --- a/src/HYDROPy/HYDROData_CalculationCase.sip +++ b/src/HYDROPy/HYDROData_CalculationCase.sip @@ -399,8 +399,9 @@ public: */ NCollection_Sequence GetAltitudesForPoints( const NCollection_Sequence& theCoordsX, const NCollection_Sequence& theCoordsY, - HYDROData_Region theRegion ) const - [NCollection_Sequence ( const NCollection_Sequence&, const Handle_HYDROData_Region& )]; + HYDROData_Region theRegion, + int theMethod = 0) const + [NCollection_Sequence ( const NCollection_Sequence&, const Handle_HYDROData_Region&, int)]; %MethodCode NCollection_Sequence aPnts; @@ -414,11 +415,12 @@ public: Handle(HYDROData_Region) aRefRegion = Handle(HYDROData_Region)::DownCast( createHandle( a2 ) ); - + int aMethod = a3; + NCollection_Sequence aRes; Py_BEGIN_ALLOW_THREADS - aRes = sipSelfWasArg ? sipCpp->HYDROData_CalculationCase::GetAltitudesForPoints( aPnts, aRefRegion ) : - sipCpp->GetAltitudesForPoints( aPnts, aRefRegion ); + aRes = sipSelfWasArg ? sipCpp->HYDROData_CalculationCase::GetAltitudesForPoints( aPnts, aRefRegion, aMethod ) : + sipCpp->GetAltitudesForPoints( aPnts, aRefRegion, aMethod ); Py_END_ALLOW_THREADS sipRes = new NCollection_Sequence( aRes ); @@ -432,8 +434,9 @@ public: */ NCollection_Sequence GetAltitudesForPoints( const NCollection_Sequence& theCoordsX, const NCollection_Sequence& theCoordsY, - HYDROData_Zone theZone ) const - [NCollection_Sequence ( const NCollection_Sequence&, const Handle_HYDROData_Zone& )]; + HYDROData_Zone theZone, + int theMethod = 0) const + [NCollection_Sequence ( const NCollection_Sequence&, const Handle_HYDROData_Zone&, int )]; %MethodCode NCollection_Sequence aPnts; @@ -447,11 +450,12 @@ public: Handle(HYDROData_Zone) aRefZone = Handle(HYDROData_Zone)::DownCast( createHandle( a2 ) ); + int aMethod = a3; NCollection_Sequence aRes; Py_BEGIN_ALLOW_THREADS - aRes = sipSelfWasArg ? sipCpp->HYDROData_CalculationCase::GetAltitudesForPoints( aPnts, aRefZone ) : - sipCpp->GetAltitudesForPoints( aPnts, aRefZone ); + aRes = sipSelfWasArg ? sipCpp->HYDROData_CalculationCase::GetAltitudesForPoints( aPnts, aRefZone, aMethod ) : + sipCpp->GetAltitudesForPoints( aPnts, aRefZone, aMethod ); Py_END_ALLOW_THREADS sipRes = new NCollection_Sequence( aRes ); diff --git a/src/HYDROTools/interpolZ.py b/src/HYDROTools/interpolZ.py index 268c0e35..93daf47b 100644 --- a/src/HYDROTools/interpolZ.py +++ b/src/HYDROTools/interpolZ.py @@ -156,7 +156,7 @@ from salome.smesh import smeshBuilder smesh = smeshBuilder.New(theStudy) -def interpolZ(nomCas, fichierMaillage, dicoGroupeRegion, zUndef): +def interpolZ(nomCas, fichierMaillage, dicoGroupeRegion, zUndef, interpolMethod = 0): """ interpolZ takes a 2D (x,y) mesh and calls the active instance of module HYDRO to interpolate the bathymetry/altimetry on the mesh nodes, to produce the Z value of each node. @@ -166,6 +166,7 @@ def interpolZ(nomCas, fichierMaillage, dicoGroupeRegion, zUndef): dicoGroupeRegion: python dictionary giving the coorespondance of mesh groups to HYDRO regions. Key: face group name, value: region name in the HYDRO Case zUndef: Z value to use for nodes outside the regions (there must be none if the case is correct). + interpolMethod: integer value, default 0 = nearest point on bathymetry, 1 = linear interpolation return Z.med : med file with Z value on nodes return F.med : an exact copy of Z.med """ @@ -220,7 +221,7 @@ def interpolZ(nomCas, fichierMaillage, dicoGroupeRegion, zUndef): #print xyz vx.append(xyz[0]) vy.append(xyz[1]) - vz = cas.GetAltitudesForPoints( vx, vy, region ) + vz = cas.GetAltitudesForPoints( vx, vy, region, interpolMethod ) minz = min(vz) maxz = max(vz) statz[grp.GetName()] = (minz, maxz) -- 2.39.2