From 64bd0bb694b4fe44c62d401bc1368337cff2631b Mon Sep 17 00:00:00 2001 From: adv Date: Mon, 27 Jan 2014 12:05:21 +0000 Subject: [PATCH] Custom interpolator object interface implemented. --- CMake/UsePyQt4EXT.cmake | 3 + src/HYDROData/CMakeLists.txt | 2 + src/HYDROData/HYDROData_CalculationCase.cxx | 21 ++++- src/HYDROData/HYDROData_IInterpolator.cxx | 35 ++++++++ src/HYDROData/HYDROData_IInterpolator.h | 58 +++++++++++++ src/HYDROData/HYDROData_Zone.cxx | 21 +++-- src/HYDROData/HYDROData_Zone.h | 20 ++++- src/HYDROPy/CMakeLists.txt | 1 + src/HYDROPy/HYDROData.sip | 1 + src/HYDROPy/HYDROData_IAltitudeObject.sip | 17 +++- src/HYDROPy/HYDROData_IInterpolator.sip | 93 +++++++++++++++++++++ src/HYDROPy/HYDROData_Zone.sip | 14 ++++ 12 files changed, 272 insertions(+), 14 deletions(-) create mode 100644 src/HYDROData/HYDROData_IInterpolator.cxx create mode 100644 src/HYDROData/HYDROData_IInterpolator.h create mode 100644 src/HYDROPy/HYDROData_IInterpolator.sip diff --git a/CMake/UsePyQt4EXT.cmake b/CMake/UsePyQt4EXT.cmake index 32006e70..27a351e2 100644 --- a/CMake/UsePyQt4EXT.cmake +++ b/CMake/UsePyQt4EXT.cmake @@ -130,6 +130,9 @@ MACRO(PYQT4_WRAP_SIP_EXT outfiles) LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Zone.cc) SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_Zone.cc) + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_IInterpolator.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyHYDROData_IInterpolator.cc) + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPygp_XYZ.cc) SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPygp_XYZ.cc) diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index df55dbc0..e50e8589 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -15,6 +15,7 @@ set(PROJECT_HEADERS HYDROData_DummyObject3D.h HYDROData_Entity.h HYDROData_IAltitudeObject.h + HYDROData_IInterpolator.h HYDROData_Image.h HYDROData_ImmersibleZone.h HYDROData_IPolyline.h @@ -59,6 +60,7 @@ set(PROJECT_SOURCES HYDROData_DummyObject3D.cxx HYDROData_Entity.cxx HYDROData_IAltitudeObject.cxx + HYDROData_IInterpolator.cxx HYDROData_Image.cxx HYDROData_ImmersibleZone.cxx HYDROData_IPolyline.cxx diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 12b146a0..a418024d 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -540,11 +540,20 @@ double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& return aResAltitude; } + HYDROData_IInterpolator* aZoneInterpolator = theZone->GetInterpolator(); if ( aZoneMergeType == HYDROData_Zone::Merge_Object ) { Handle(HYDROData_IAltitudeObject) aMergeAltitude = theZone->GetMergeAltitude(); if ( !aMergeAltitude.IsNull() ) - aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint ); + { + if ( aZoneInterpolator != NULL ) + { + aZoneInterpolator->SetAltitudeObject( aMergeAltitude ); + aResAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint ); + } + else + aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint ); + } } else { @@ -561,7 +570,15 @@ double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& if ( anObjAltitude.IsNull() ) continue; - double aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint ); + double aPointAltitude = 0.0; + if ( aZoneInterpolator != NULL ) + { + aZoneInterpolator->SetAltitudeObject( anObjAltitude ); + aPointAltitude = aZoneInterpolator->GetAltitudeForPoint( thePoint ); + } + else + aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint ); + if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ) continue; diff --git a/src/HYDROData/HYDROData_IInterpolator.cxx b/src/HYDROData/HYDROData_IInterpolator.cxx new file mode 100644 index 00000000..fcd1ef1c --- /dev/null +++ b/src/HYDROData/HYDROData_IInterpolator.cxx @@ -0,0 +1,35 @@ + +#include "HYDROData_IInterpolator.h" + +#include + +HYDROData_IInterpolator::HYDROData_IInterpolator() +{ +} + +HYDROData_IInterpolator::~HYDROData_IInterpolator() +{ +} + +void HYDROData_IInterpolator::SetAltitudeObject( + const Handle(HYDROData_IAltitudeObject)& theAltitude ) +{ + myAltitudeObject = theAltitude; +} + +Handle(HYDROData_IAltitudeObject) HYDROData_IInterpolator::GetAltitudeObject() const +{ + return myAltitudeObject; +} + +double HYDROData_IInterpolator::GetAltitudeForPoint( + const double theCoordX, const double theCoordY ) const +{ + return myAltitudeObject.IsNull() ? HYDROData_IAltitudeObject::GetInvalidAltitude() : + myAltitudeObject->GetAltitudeForPoint( gp_XY( theCoordX, theCoordY ) ); +} + +double HYDROData_IInterpolator::GetAltitudeForPoint( const gp_XY& thePoint ) const +{ + return GetAltitudeForPoint( thePoint.X(), thePoint.Y() ); +} \ No newline at end of file diff --git a/src/HYDROData/HYDROData_IInterpolator.h b/src/HYDROData/HYDROData_IInterpolator.h new file mode 100644 index 00000000..eba4b8f5 --- /dev/null +++ b/src/HYDROData/HYDROData_IInterpolator.h @@ -0,0 +1,58 @@ + +#ifndef HYDROData_IInterpolator_HeaderFile +#define HYDROData_IInterpolator_HeaderFile + +#include "HYDROData_IAltitudeObject.h" + +class gp_XY; + +/**\class HYDROData_IInterpolator + * \brief The base class to provide interface for interpolation. + */ +class HYDROData_IInterpolator +{ +public: + + /** + * Public empty constructor. + */ + HYDRODATA_EXPORT HYDROData_IInterpolator(); + + /** + * Public virtual destructor. + */ + virtual HYDRODATA_EXPORT ~HYDROData_IInterpolator(); + +public: + + /** + * Returns the altitude value for given point. + * Reimplement this method in order to change the interpolation algorithm. + */ + virtual HYDRODATA_EXPORT double GetAltitudeForPoint( + const double theCoordX, const double theCoordY ) const; + + /** + * Returns the altitude value for given point. + */ + HYDRODATA_EXPORT double GetAltitudeForPoint( const gp_XY& thePoint ) const; + + +public: + + /** + * Sets the altitude object for interpolation. + */ + HYDRODATA_EXPORT void SetAltitudeObject( + const Handle(HYDROData_IAltitudeObject)& theAltitude ); + + /** + * Returns the altitude object for interpolation. + */ + HYDRODATA_EXPORT Handle(HYDROData_IAltitudeObject) GetAltitudeObject() const; + +private: + Handle(HYDROData_IAltitudeObject) myAltitudeObject; +}; + +#endif diff --git a/src/HYDROData/HYDROData_Zone.cxx b/src/HYDROData/HYDROData_Zone.cxx index 6b14079c..adde27bf 100644 --- a/src/HYDROData/HYDROData_Zone.cxx +++ b/src/HYDROData/HYDROData_Zone.cxx @@ -22,6 +22,7 @@ IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Zone, HYDROData_Entity) HYDROData_Zone::HYDROData_Zone() : HYDROData_Entity() { + myInterpolator = NULL; } HYDROData_Zone::~HYDROData_Zone() @@ -97,17 +98,19 @@ bool HYDROData_Zone::IsMergingNeed() const return false; } +void HYDROData_Zone::SetInterpolator( HYDROData_IInterpolator* theInter ) +{ + myInterpolator = theInter; +} + +HYDROData_IInterpolator* HYDROData_Zone::GetInterpolator() const +{ + return myInterpolator; +} + void HYDROData_Zone::SetMergeType( const MergeAltitudesType& theType ) { - Handle(TDataStd_Integer) anInt; - if ( myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) ) - { - anInt->Set( (int)theType ); - } - else - { - anInt = TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType ); - } + TDataStd_Integer::Set( myLab.FindChild( DataTag_MergeType ), (int)theType ); } HYDROData_Zone::MergeAltitudesType HYDROData_Zone::GetMergeType() const diff --git a/src/HYDROData/HYDROData_Zone.h b/src/HYDROData/HYDROData_Zone.h index ff06dec5..30e86cc0 100644 --- a/src/HYDROData/HYDROData_Zone.h +++ b/src/HYDROData/HYDROData_Zone.h @@ -2,7 +2,8 @@ #ifndef HYDROData_Zone_HeaderFile #define HYDROData_Zone_HeaderFile -#include +#include "HYDROData_Entity.h" +#include "HYDROData_IInterpolator.h" class Handle(HYDROData_Object); class Handle(HYDROData_IAltitudeObject); @@ -84,6 +85,20 @@ public: HYDRODATA_EXPORT virtual bool IsMergingNeed() const; + /** + * Sets the interpolator for zone. By default it is NULL and original + * interpolation algorithms are used to calculate points altitudes. + * If you set interpolator it won't be stored in the data model structure, + * it will be deleted during that time as this zone will be freed. + */ + HYDRODATA_EXPORT virtual void SetInterpolator( HYDROData_IInterpolator* theInter ); + + /** + * * Returns the interpolator of zone object. + */ + HYDRODATA_EXPORT virtual HYDROData_IInterpolator* GetInterpolator() const; + + /** * Sets the merging type for conflict altitudes. * By default it is set to Merge_UNKNOWN. @@ -145,6 +160,9 @@ protected: */ HYDRODATA_EXPORT ~HYDROData_Zone(); +private: + HYDROData_IInterpolator* myInterpolator; + }; #endif diff --git a/src/HYDROPy/CMakeLists.txt b/src/HYDROPy/CMakeLists.txt index 1e3ef48a..233dd17b 100644 --- a/src/HYDROPy/CMakeLists.txt +++ b/src/HYDROPy/CMakeLists.txt @@ -59,6 +59,7 @@ SET(_sip_files2 CAS/TCollection_AsciiString.sip CAS/NCollection_Sequence.sip HYDROData_SequenceOfObjects.sip + HYDROData_IInterpolator.sip HYDROData_Entity.sip HYDROData_ShapesGroup.sip HYDROData_SplittedShapesGroup.sip diff --git a/src/HYDROPy/HYDROData.sip b/src/HYDROPy/HYDROData.sip index ecaceb97..f78a73fe 100644 --- a/src/HYDROPy/HYDROData.sip +++ b/src/HYDROPy/HYDROData.sip @@ -56,6 +56,7 @@ See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com %Include CAS/TCollection_AsciiString.sip %Include CAS/NCollection_Sequence.sip %Include HYDROData_SequenceOfObjects.sip +%Include HYDROData_IInterpolator.sip %Include HYDROData_Entity.sip %Include HYDROData_ShapesGroup.sip %Include HYDROData_SplittedShapesGroup.sip diff --git a/src/HYDROPy/HYDROData_IAltitudeObject.sip b/src/HYDROPy/HYDROData_IAltitudeObject.sip index b750f4cd..a99cc9cc 100644 --- a/src/HYDROPy/HYDROData_IAltitudeObject.sip +++ b/src/HYDROPy/HYDROData_IAltitudeObject.sip @@ -63,15 +63,28 @@ public: * Returns altitude points list. * \return points list */ - static double GetInvalidAltitude(); + static double GetInvalidAltitude(); /** * Returns altitude for given point. * \param thePoint the point to examine * \return altitude value */ - virtual double GetAltitudeForPoint( const gp_XY& thePoint ) const = 0; + virtual double GetAltitudeForPoint( const double theCoordX, + const double theCoordX ) const = 0 [double ( const gp_XY& )]; + %MethodCode + gp_XY aPnt( a0, a1 ); + + Py_BEGIN_ALLOW_THREADS + sipRes = sipCpp->GetAltitudeForPoint( aPnt ); + Py_END_ALLOW_THREADS + %End + %VirtualCatcherCode + PyObject *sipResObj = sipCallMethod(0, sipMethod, "dd",a0.X(),a0.Y()); + sipParseResultEx(sipGILState, sipErrorHandler, sipPySelf, sipMethod, sipResObj, "d", &sipRes); + %End + protected: /** diff --git a/src/HYDROPy/HYDROData_IInterpolator.sip b/src/HYDROPy/HYDROData_IInterpolator.sip new file mode 100644 index 00000000..a1882ec1 --- /dev/null +++ b/src/HYDROPy/HYDROData_IInterpolator.sip @@ -0,0 +1,93 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + + +%ExportedHeaderCode +#include +%End + +/**\class HYDROData_IInterpolator + * \brief The base class to provide interface for interpolation. + */ +class HYDROData_IInterpolator +{ +%TypeHeaderCode +#include +%End + +public: + + /** + * Public empty constructor. + */ + HYDROData_IInterpolator(); + + /** + * Public virtual destructor. + */ + virtual ~HYDROData_IInterpolator(); + +public: + + /** + * Returns the altitude value for given point. + * Reimplement this method in order to change the interpolation algorithm. + */ + virtual double GetAltitudeForPoint( const double theCoordX, + const double theCoordY ) const; + +public: + + /** + * Sets the altitude object for interpolation. + */ + void SetAltitudeObject( HYDROData_IAltitudeObject theAltitude ) + [void ( const Handle_HYDROData_IAltitudeObject& )]; + %MethodCode + Handle(HYDROData_IAltitudeObject) anAltitude = + Handle(HYDROData_IAltitudeObject)::DownCast( createHandle( a0 ) ); + if ( !anAltitude.IsNull() ) + { + Py_BEGIN_ALLOW_THREADS + sipSelfWasArg ? sipCpp->HYDROData_IInterpolator::SetAltitudeObject( anAltitude ): + sipCpp->SetAltitudeObject( anAltitude ); + Py_END_ALLOW_THREADS + + } + %End + + + /** + * Returns the altitude object for interpolation. + */ + HYDROData_IAltitudeObject GetAltitudeObject() const [Handle_HYDROData_IAltitudeObject ()]; + %MethodCode + Handle(HYDROData_IAltitudeObject) aRes; + + Py_BEGIN_ALLOW_THREADS + aRes = sipSelfWasArg ? sipCpp->HYDROData_IInterpolator::GetAltitudeObject() : + sipCpp->GetAltitudeObject(); + Py_END_ALLOW_THREADS + + sipRes = (HYDROData_IAltitudeObject*)createPointer( aRes ); + %End +}; diff --git a/src/HYDROPy/HYDROData_Zone.sip b/src/HYDROPy/HYDROData_Zone.sip index 5246a603..5200984b 100644 --- a/src/HYDROPy/HYDROData_Zone.sip +++ b/src/HYDROPy/HYDROData_Zone.sip @@ -138,6 +138,20 @@ public: */ void RemoveGeometryObjects(); + + /** + * Sets the interpolator for zone. By default it is NULL and original + * interpolation algorithms are used to calculate points altitudes. + * If you set interpolator it won't be stored in the data model structure, + * it will be deleted during that time as this zone will be freed. + */ + void SetInterpolator( HYDROData_IInterpolator* theInter ); + + /** + * * Returns the interpolator of zone object. + */ + HYDROData_IInterpolator* GetInterpolator() const; + protected: /** -- 2.39.2