]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #493: draft implementation of data model part of profiles interpolation
authormzn <mzn@opencascade.com>
Fri, 27 Mar 2015 14:51:14 +0000 (17:51 +0300)
committermzn <mzn@opencascade.com>
Fri, 27 Mar 2015 14:51:14 +0000 (17:51 +0300)
src/HYDROData/CMakeLists.txt
src/HYDROData/HYDROData_Document.cxx
src/HYDROData/HYDROData_Document.h
src/HYDROData/HYDROData_IProfilesInterpolator.cxx [new file with mode: 0644]
src/HYDROData/HYDROData_IProfilesInterpolator.h [new file with mode: 0644]
src/HYDROData/HYDROData_InterpolatorsFactory.cxx [new file with mode: 0644]
src/HYDROData/HYDROData_InterpolatorsFactory.h [new file with mode: 0644]
src/HYDROData/HYDROData_LinearInterpolator.cxx [new file with mode: 0644]
src/HYDROData/HYDROData_LinearInterpolator.h [new file with mode: 0644]

index 7459b7c3c0da50c0e5b0108f0b9168c6c6c91b2e..b1a830e4e73f25c8b67d5f3c3d69fd4e672d9bfa 100644 (file)
@@ -47,6 +47,9 @@ set(PROJECT_HEADERS
     HYDROData_Warning.h
     HYDROData_Zone.h
        HYDROData_GeomTool.h
+       HYDROData_IProfilesInterpolator.h
+       HYDROData_LinearInterpolator.h
+       HYDROData_InterpolatorsFactory.h
 )
 
 set(PROJECT_SOURCES 
@@ -94,6 +97,9 @@ set(PROJECT_SOURCES
     HYDROData_VisualState.cxx
     HYDROData_Zone.cxx
        HYDROData_GeomTool.cxx
+       HYDROData_IProfilesInterpolator.cxx
+       HYDROData_LinearInterpolator.cxx
+       HYDROData_InterpolatorsFactory.cxx
 )
 
 add_definitions(
index eed420ed5ee83edfae6b908d96071406125c579b..a032f025aec0be4f4f3446c401b76e80f953065f 100644 (file)
@@ -24,6 +24,7 @@
 #include <HYDROData_Application.h>
 #include <HYDROData_Iterator.h>
 #include <HYDROData_Tool.h>
+#include <HYDROData_InterpolatorsFactory.h>
 
 #include <TDataStd_Integer.hxx>
 #include <TDataXtd_Position.hxx>
@@ -668,6 +669,8 @@ HYDROData_Document::HYDROData_Document()
   myTransactionsAfterSave = 0;
   myLX = -1;
   myLY = -1;
+
+  myInterpolatorsFactory = 0;
 }
 
 HYDROData_Document::HYDROData_Document(const Handle(TDocStd_Document)& theDoc)
@@ -676,6 +679,8 @@ HYDROData_Document::HYDROData_Document(const Handle(TDocStd_Document)& theDoc)
   myTransactionsAfterSave = 0;
   myLX = -1;
   myLY = -1;
+
+  myInterpolatorsFactory = 0;
 }
 
 HYDROData_Document::~HYDROData_Document()
@@ -802,3 +807,12 @@ void HYDROData_Document::Transform( gp_XY& thePnt, bool IsToLocalCS ) const
   Transform( X, Y, IsToLocalCS );
   thePnt = gp_XY( X, Y ); 
 }
+
+HYDROData_InterpolatorsFactory* HYDROData_Document::GetInterpolatorsFactory()
+{
+  if ( !myInterpolatorsFactory ) {
+    myInterpolatorsFactory = new HYDROData_InterpolatorsFactory();
+  }
+
+  return myInterpolatorsFactory;
+}
\ No newline at end of file
index 2a53899df0faef5699bf49ab57e937771703ee01..bfe81778a026093ea6dbdb4f94d9fee6efa10257 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <TDocStd_Document.hxx>
 
+class HYDROData_InterpolatorsFactory;
+
 class QFile;
 class gp_Pnt2d;
 class gp_Pnt;
@@ -208,6 +210,11 @@ public:
     const QStringList& theNames, 
     const ObjectKind   theObjectKind = KIND_UNKNOWN ) const;
 
+public:
+  
+  //! Returns interpolator factory instance
+  HYDROData_InterpolatorsFactory* GetInterpolatorsFactory();
+
 protected:
 
   friend class HYDROData_Iterator;
@@ -245,6 +252,8 @@ private:
   Handle(TDocStd_Document) myDoc; ///< OCAF document instance corresponding for keeping all persistent data
   int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method
   double myLX, myLY;
+
+  HYDROData_InterpolatorsFactory* myInterpolatorsFactory; ///< iterpolators factory
 };
 
 #endif
diff --git a/src/HYDROData/HYDROData_IProfilesInterpolator.cxx b/src/HYDROData/HYDROData_IProfilesInterpolator.cxx
new file mode 100644 (file)
index 0000000..6a5ef3b
--- /dev/null
@@ -0,0 +1,97 @@
+// Copyright (C) 2007-2015  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, or (at your option) any later version.
+//
+// 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
+//
+
+#include "HYDROData_IProfilesInterpolator.h"
+
+
+const int DEFAULT_RESULT_PROFILES_NB = 1; ///< default number of results profiles
+
+HYDROData_IProfilesInterpolator::HYDROData_IProfilesInterpolator()
+  : myResultProfilesNumber( DEFAULT_RESULT_PROFILES_NB ),
+    myErrorCode( OK )
+{
+}
+
+HYDROData_IProfilesInterpolator::~HYDROData_IProfilesInterpolator()
+{
+}
+
+void HYDROData_IProfilesInterpolator::SetProfiles( const std::vector<double> theProfile1, const std::vector<double> theProfile2 )
+{
+  myProfile1 = theProfile1;
+  myProfile2 = theProfile2;
+}
+
+void HYDROData_IProfilesInterpolator::SetParameter( const std::string& theName, const std::string& theValue )
+{
+  myParameters[theName] = theValue;
+}
+
+InterpolationError HYDROData_IProfilesInterpolator::GetErrorCode() const
+{
+  return myErrorCode;
+}
+
+void HYDROData_IProfilesInterpolator::SetErrorCode( const InterpolationError& theError )
+{
+  myErrorCode = theError;
+}
+
+std::string HYDROData_IProfilesInterpolator::GetErrorMessage() const
+{
+  return myErrorMessage;
+}
+
+void HYDROData_IProfilesInterpolator::SetErrorMessage( const std::string& theMessage )
+{
+  myErrorMessage = theMessage;
+}
+
+void HYDROData_IProfilesInterpolator::SetResultProfilesNumber( const int theNumber )
+{
+  myResultProfilesNumber = theNumber;
+}
+
+std::vector<double> HYDROData_IProfilesInterpolator::GetResultProfile( const int theProfileIndex ) const
+{
+  std::vector<double> aResultProfile;
+
+  if ( theProfileIndex > 0 && theProfileIndex < (int) myResultProfiles.size() ) {
+    aResultProfile = myResultProfiles.at( theProfileIndex );
+  }
+
+  return aResultProfile;
+}
+
+void HYDROData_IProfilesInterpolator::Reset()
+{
+  myProfile1.clear();  
+  myProfile2.clear();  
+  myParameters.clear();
+
+  SetResultProfilesNumber( DEFAULT_RESULT_PROFILES_NB );
+  
+  myResultProfiles.clear();
+
+  SetErrorCode( OK );
+  SetErrorMessage( "" );
+}
\ No newline at end of file
diff --git a/src/HYDROData/HYDROData_IProfilesInterpolator.h b/src/HYDROData/HYDROData_IProfilesInterpolator.h
new file mode 100644 (file)
index 0000000..da91b2d
--- /dev/null
@@ -0,0 +1,142 @@
+// Copyright (C) 2007-2015  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, or (at your option) any later version.
+//
+// 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
+//
+
+#ifndef HYDROData_IProfilesInterpolator_HeaderFile
+#define HYDROData_IProfilesInterpolator_HeaderFile
+
+#include "HYDROData.h"
+
+#include <string>
+#include <vector>
+#include <map>
+
+
+/**
+ * Errors that could appear on interpolation calculations.
+ * If there is no error, it is "OK".
+ */
+enum InterpolationError {
+  OK = 0, ///< success
+  InvalidParametersError, ///< input parameters are invalid
+  UnknownError ///< problem has unknown nature
+};
+
+/**\class HYDROData_IProfilesInterpolator
+ * \brief The base class to provide interface for profiles interpolation.
+ */
+class HYDROData_IProfilesInterpolator
+{
+public:
+
+  /**
+   * Public constructor.
+   */
+  HYDRODATA_EXPORT HYDROData_IProfilesInterpolator();
+
+  /**
+   * Public virtual destructor.
+   */
+  virtual HYDRODATA_EXPORT ~HYDROData_IProfilesInterpolator();
+
+public:
+
+  /**
+   * Get description of the interpolation algorithm.
+   * \return the description string
+   */
+  HYDRODATA_EXPORT virtual std::string GetDescription() const = 0;
+
+  /**
+   * Set profiles as vectors of point coordinates [x1, y1, z1, x2, y2, z2, ...].
+   * \param theProfile1 the first profile points
+   * \param theProfile1 the second profile points
+   */
+  HYDRODATA_EXPORT virtual void SetProfiles( const std::vector<double> theProfile1, const std::vector<double> theProfile2 );
+
+  /**
+   * Set number of profiles to compute.
+   * \param theNumber the number of profiles to be computed
+   */
+  HYDRODATA_EXPORT virtual void SetResultProfilesNumber( const int theNumber );
+
+  /**
+   * Set the additional parameter.
+   * \param the parameter name
+   * \param the parameter value
+   */
+  HYDRODATA_EXPORT virtual void SetParameter( const std::string& theName, const std::string& theValue );
+
+  /**
+   * Get the last error code.
+   * \return the error code from InterpolationError enumeration
+   */
+  HYDRODATA_EXPORT virtual InterpolationError GetErrorCode() const;
+
+  /**
+   * Get string description of the last error.
+   * \return the string description
+   */
+  HYDRODATA_EXPORT virtual std::string GetErrorMessage() const;
+
+  /**
+   * Reset interpolator state: both input and output data are reset.
+   */
+  HYDRODATA_EXPORT virtual void Reset();
+
+public:
+  /**
+   * Perform interpolation calculations.
+   */
+  HYDRODATA_EXPORT virtual InterpolationError Calculate() = 0;
+
+  /**
+   * Get result profile by index.
+   * \param theProfileIndex the profile index [0, <number of profiles to compute>]
+   * \return the profile with the given index or empty vector if the index is out of range
+   */
+  std::vector<double> GetResultProfile( const int theProfileIndex ) const;
+
+protected:
+  /**
+   * Set the error code.
+   * \param theError the error code from InterpolationError enumeration
+   */
+  HYDRODATA_EXPORT virtual void SetErrorCode( const InterpolationError& theError );
+
+  /**
+   * Set the error string description.
+   * \param the string description
+   */
+  HYDRODATA_EXPORT virtual void SetErrorMessage( const std::string& theMessage );
+
+private:
+  std::vector<double> myProfile1, myProfile2; ///< the two input profiles
+  int myResultProfilesNumber; ///< the number of profiles to compute
+  std::map<std::string, std::string> myParameters; ///< the map of additional parameters
+
+  InterpolationError myErrorCode; ///< the last error code
+  std::string myErrorMessage; ///< the last error message
+
+  std::vector<std::vector<double>> myResultProfiles; ///< the list of result profiles
+};
+
+#endif
diff --git a/src/HYDROData/HYDROData_InterpolatorsFactory.cxx b/src/HYDROData/HYDROData_InterpolatorsFactory.cxx
new file mode 100644 (file)
index 0000000..8b11eda
--- /dev/null
@@ -0,0 +1,58 @@
+// Copyright (C) 2007-2015  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, or (at your option) any later version.
+//
+// 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
+//
+
+#include "HYDROData_InterpolatorsFactory.h"
+
+#include "HYDROData_LinearInterpolator.h"
+
+HYDROData_InterpolatorsFactory::HYDROData_InterpolatorsFactory()
+{
+  Register<HYDROData_LinearInterpolator>( "Linear" );
+}
+
+HYDROData_InterpolatorsFactory::~HYDROData_InterpolatorsFactory()
+{
+}
+
+HYDROData_IProfilesInterpolator* HYDROData_InterpolatorsFactory::GetInterpolator( const std::string& theName ) const
+{
+  HYDROData_IProfilesInterpolator* anInterpolator = NULL;
+
+  FactoryInterpolators::const_iterator anIt = myInterpolators.find(theName);
+  if ( anIt != myInterpolators.end() ) {
+    anInterpolator = anIt->second;
+  }
+
+  return anInterpolator;
+}
+
+std::vector<std::string> HYDROData_InterpolatorsFactory::GetInterpolatorNames() const
+{
+  std::vector<std::string> aNames;
+
+  FactoryInterpolators::const_iterator anIt = myInterpolators.begin();
+  for ( ; anIt != myInterpolators.end(); anIt++ ) {
+    aNames.push_back( anIt->first );
+  }
+
+  return aNames;
+}
\ No newline at end of file
diff --git a/src/HYDROData/HYDROData_InterpolatorsFactory.h b/src/HYDROData/HYDROData_InterpolatorsFactory.h
new file mode 100644 (file)
index 0000000..865faea
--- /dev/null
@@ -0,0 +1,78 @@
+// Copyright (C) 2007-2015  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, or (at your option) any later version.
+//
+// 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
+//
+
+#ifndef HYDROData_InterpolatorsFactory_HeaderFile
+#define HYDROData_InterpolatorsFactory_HeaderFile
+
+#include <HYDROData.h>
+
+#include <string>
+#include <vector>
+#include <map>
+
+class HYDROData_IProfilesInterpolator;
+
+/**\class HYDROData_InterpolatorsFactory
+ *
+ * \brief Profile interpolators factory.
+ *
+ * Allows to register different types of interpolatotors (these interpolators should inherit HYDROData_IProfilesInterpolator).
+ * Once the interpolator of a certain type is registered it should be got by its name.
+ */
+
+class HYDROData_InterpolatorsFactory
+{
+public:
+
+  HYDROData_InterpolatorsFactory();
+  virtual ~HYDROData_InterpolatorsFactory();
+
+  /**
+   * Registers the interpolator of a certain type with the given name.
+   * \param theName the interpolator name used as identifier
+   */
+  template <class T> HYDRODATA_EXPORT void Register( const std::string& theName )
+  {
+    myInterpolators[theName] = new T();
+  }
+
+  /**
+   * Get the appropriate interpolator by the name.
+   * \param theName name of the interpolator
+   * \returns the appropriate interpolator or NULL if interpolator with such name is not registered
+   */
+  HYDRODATA_EXPORT HYDROData_IProfilesInterpolator* GetInterpolator( const std::string& theName ) const;
+
+  /**
+   * Get list of registered interpolator names.
+   * \return the list of unique names
+   */
+  std::vector<std::string> GetInterpolatorNames() const;
+  
+private:
+  //! Map that stores all interpolators, identified by interpolator name (string)
+  typedef std::map<std::string, HYDROData_IProfilesInterpolator*> FactoryInterpolators;
+  
+  FactoryInterpolators myInterpolators; ///< all interpolators stored by factory
+};
+
+#endif
\ No newline at end of file
diff --git a/src/HYDROData/HYDROData_LinearInterpolator.cxx b/src/HYDROData/HYDROData_LinearInterpolator.cxx
new file mode 100644 (file)
index 0000000..af2eb24
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2007-2015  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, or (at your option) any later version.
+//
+// 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
+//
+
+#include "HYDROData_LinearInterpolator.h"
+
+
+HYDROData_LinearInterpolator::HYDROData_LinearInterpolator()
+{
+}
+
+HYDROData_LinearInterpolator::~HYDROData_LinearInterpolator()
+{
+}
+
+std::string HYDROData_LinearInterpolator::GetDescription() const
+{
+  std::string aDescription( "Simple linear interpolator" );
+
+  return aDescription;
+}
+
+InterpolationError HYDROData_LinearInterpolator::Calculate()
+{
+  return OK;
+}
\ No newline at end of file
diff --git a/src/HYDROData/HYDROData_LinearInterpolator.h b/src/HYDROData/HYDROData_LinearInterpolator.h
new file mode 100644 (file)
index 0000000..df1bacb
--- /dev/null
@@ -0,0 +1,59 @@
+// Copyright (C) 2007-2015  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, or (at your option) any later version.
+//
+// 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
+//
+
+#ifndef HYDROData_LinearInterpolator_HeaderFile
+#define HYDROData_LinearInterpolator_HeaderFile
+
+#include "HYDROData_IProfilesInterpolator.h"
+
+
+/**\class HYDROData_LinearInterpolator
+ * \brief The class implementing the linear interpolation of profiles.
+ */
+class HYDROData_LinearInterpolator : public HYDROData_IProfilesInterpolator
+{
+public:
+
+  /**
+   * Public constructor.
+   */
+  HYDRODATA_EXPORT HYDROData_LinearInterpolator();
+
+  /**
+   * Public virtual destructor.
+   */
+  virtual HYDRODATA_EXPORT ~HYDROData_LinearInterpolator();
+
+public:
+
+  /**
+   *
+   */
+  HYDRODATA_EXPORT virtual std::string GetDescription() const;
+
+  /**
+   *
+   */
+  HYDRODATA_EXPORT virtual InterpolationError Calculate();
+};
+
+#endif