]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Custom interpolator object interface implemented.
authoradv <adv@opencascade.com>
Mon, 27 Jan 2014 12:05:21 +0000 (12:05 +0000)
committeradv <adv@opencascade.com>
Mon, 27 Jan 2014 12:05:21 +0000 (12:05 +0000)
12 files changed:
CMake/UsePyQt4EXT.cmake
src/HYDROData/CMakeLists.txt
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_IInterpolator.cxx [new file with mode: 0644]
src/HYDROData/HYDROData_IInterpolator.h [new file with mode: 0644]
src/HYDROData/HYDROData_Zone.cxx
src/HYDROData/HYDROData_Zone.h
src/HYDROPy/CMakeLists.txt
src/HYDROPy/HYDROData.sip
src/HYDROPy/HYDROData_IAltitudeObject.sip
src/HYDROPy/HYDROData_IInterpolator.sip [new file with mode: 0644]
src/HYDROPy/HYDROData_Zone.sip

index 32006e70b8f61d411dda6517be378b4c023901e2..27a351e21c5a73701d9c84f291fe0aa85f5fb6fa 100644 (file)
@@ -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)
 
index df55dbc0343d5429724968d3cab6cf29ba105088..e50e85897d165bae3f1035e7856e0ac479cedde9 100644 (file)
@@ -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
index 12b146a048d913cd2eaadbb4465c59f6f52b5aee..a418024d6f5c685a090fa941453d3227fad02b8d 100644 (file)
@@ -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 (file)
index 0000000..fcd1ef1
--- /dev/null
@@ -0,0 +1,35 @@
+
+#include "HYDROData_IInterpolator.h"
+
+#include <gp_XY.hxx>
+
+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 (file)
index 0000000..eba4b8f
--- /dev/null
@@ -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
index 6b14079c24ade55c36dc56193c98eee807e70a13..adde27bf6455f1b278b18a216c87662acced58a9 100644 (file)
@@ -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
index ff06dec5cf2363a02ea2723bbf878871d3cb0e38..30e86cc01c3d7aba3e96b6ff467e144c260d94f7 100644 (file)
@@ -2,7 +2,8 @@
 #ifndef HYDROData_Zone_HeaderFile
 #define HYDROData_Zone_HeaderFile
 
-#include <HYDROData_Entity.h>
+#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
index 1e3ef48acf5366b6e1e4d1ea525b04671d89bb6b..233dd17b808cd6424125622aa29d06753c143c15 100644 (file)
@@ -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
index ecaceb97e7f377ec9a6f0227f792dbcb320bd516..f78a73fe3a057e4dc152bb9b3660bbad02153660 100644 (file)
@@ -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
index b750f4cddbb9d046b2a394f9117276573e0f18ef..a99cc9cc5e31bfabfc3a639f7f4747e6452e3cee 100644 (file)
@@ -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 (file)
index 0000000..a1882ec
--- /dev/null
@@ -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 <HYDROData_IInterpolator.h>
+%End
+
+/**\class HYDROData_IInterpolator
+ * \brief The base class to provide interface for interpolation.
+ */
+class HYDROData_IInterpolator
+{
+%TypeHeaderCode
+#include <HYDROData_IInterpolator.h>
+%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
+};
index 5246a603239382c08caa1bac44849d09e1a440b2..5200984b889075dea5a38b543770ff13b8193611 100644 (file)
@@ -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:
 
   /**