From 5af716c6a81cef716c390b53ac915f8d0fd30887 Mon Sep 17 00:00:00 2001 From: mzn Date: Fri, 27 Mar 2015 17:51:14 +0300 Subject: [PATCH] refs #493: draft implementation of data model part of profiles interpolation --- src/HYDROData/CMakeLists.txt | 6 + src/HYDROData/HYDROData_Document.cxx | 14 ++ src/HYDROData/HYDROData_Document.h | 9 ++ .../HYDROData_IProfilesInterpolator.cxx | 97 ++++++++++++ .../HYDROData_IProfilesInterpolator.h | 142 ++++++++++++++++++ .../HYDROData_InterpolatorsFactory.cxx | 58 +++++++ .../HYDROData_InterpolatorsFactory.h | 78 ++++++++++ .../HYDROData_LinearInterpolator.cxx | 44 ++++++ src/HYDROData/HYDROData_LinearInterpolator.h | 59 ++++++++ 9 files changed, 507 insertions(+) create mode 100644 src/HYDROData/HYDROData_IProfilesInterpolator.cxx create mode 100644 src/HYDROData/HYDROData_IProfilesInterpolator.h create mode 100644 src/HYDROData/HYDROData_InterpolatorsFactory.cxx create mode 100644 src/HYDROData/HYDROData_InterpolatorsFactory.h create mode 100644 src/HYDROData/HYDROData_LinearInterpolator.cxx create mode 100644 src/HYDROData/HYDROData_LinearInterpolator.h diff --git a/src/HYDROData/CMakeLists.txt b/src/HYDROData/CMakeLists.txt index 7459b7c3..b1a830e4 100644 --- a/src/HYDROData/CMakeLists.txt +++ b/src/HYDROData/CMakeLists.txt @@ -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( diff --git a/src/HYDROData/HYDROData_Document.cxx b/src/HYDROData/HYDROData_Document.cxx index eed420ed..a032f025 100644 --- a/src/HYDROData/HYDROData_Document.cxx +++ b/src/HYDROData/HYDROData_Document.cxx @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -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 diff --git a/src/HYDROData/HYDROData_Document.h b/src/HYDROData/HYDROData_Document.h index 2a53899d..bfe81778 100644 --- a/src/HYDROData/HYDROData_Document.h +++ b/src/HYDROData/HYDROData_Document.h @@ -28,6 +28,8 @@ #include +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 index 00000000..6a5ef3b4 --- /dev/null +++ b/src/HYDROData/HYDROData_IProfilesInterpolator.cxx @@ -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 theProfile1, const std::vector 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 HYDROData_IProfilesInterpolator::GetResultProfile( const int theProfileIndex ) const +{ + std::vector 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 index 00000000..da91b2da --- /dev/null +++ b/src/HYDROData/HYDROData_IProfilesInterpolator.h @@ -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 +#include +#include + + +/** + * 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 theProfile1, const std::vector 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, ] + * \return the profile with the given index or empty vector if the index is out of range + */ + std::vector 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 myProfile1, myProfile2; ///< the two input profiles + int myResultProfilesNumber; ///< the number of profiles to compute + std::map myParameters; ///< the map of additional parameters + + InterpolationError myErrorCode; ///< the last error code + std::string myErrorMessage; ///< the last error message + + std::vector> 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 index 00000000..8b11eda0 --- /dev/null +++ b/src/HYDROData/HYDROData_InterpolatorsFactory.cxx @@ -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( "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 HYDROData_InterpolatorsFactory::GetInterpolatorNames() const +{ + std::vector 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 index 00000000..865faea6 --- /dev/null +++ b/src/HYDROData/HYDROData_InterpolatorsFactory.h @@ -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 + +#include +#include +#include + +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 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 GetInterpolatorNames() const; + +private: + //! Map that stores all interpolators, identified by interpolator name (string) + typedef std::map 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 index 00000000..af2eb24c --- /dev/null +++ b/src/HYDROData/HYDROData_LinearInterpolator.cxx @@ -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 index 00000000..df1bacb5 --- /dev/null +++ b/src/HYDROData/HYDROData_LinearInterpolator.h @@ -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 -- 2.39.2