diff options
Diffstat (limited to 'meowpp/math/Transformation.h')
-rw-r--r-- | meowpp/math/Transformation.h | 272 |
1 files changed, 224 insertions, 48 deletions
diff --git a/meowpp/math/Transformation.h b/meowpp/math/Transformation.h index abf2649..0d9ee05 100644 --- a/meowpp/math/Transformation.h +++ b/meowpp/math/Transformation.h @@ -2,58 +2,234 @@ #define math_Transformation_H__ #include "Matrix.h" +#include "../Self.h" #include <cstdlib> -namespace meow{ - template<class Scalar> - class Transformation{ - private: - size_t _inputRows; - size_t _inputCols; - size_t _outputRows; - size_t _outputCols; - size_t _psize; - protected: - Transformation(size_t __inputRows, size_t __inputCols, - size_t __outputRows, size_t __outputCols, - size_t __psize): - _inputRows (__inputRows), - _inputCols (__inputCols), - _outputRows(__outputRows), - _outputCols(__outputCols), - _psize(__psize){ - } - public: - virtual Transformation(){ } - - size_t inputRows() const{ return _inputRows; } - size_t inputCols() const{ return _inputCols; } - size_t outputRows() const{ return _outputRows; } - size_t outputCols() const{ return _outputCols; } - size_t parameterSize() const{ return _psize; } - - virtual Scalar parameter(size_t __i) const = 0; - virtual Scalar parameter(size_t __i, Scalar const& __s) = 0; - - virtual Matrix<Scalar> transformate(Matrix<Scalar> const& __x) const = 0; - virtual Matrix<Scalar> jacobian (Matrix<Scalar> const& __x) const = 0; - virtual Matrix<Scalar> jacobian (Matrix<Scalar> const& __x, - size_t __i) const = 0; - - virtual bool inversable() const{ return false; } - - virtual Matrix<Scalar> invTransformate(Matrix<Scalar> const& __x) const{ - return Matrix<Scalar>(); - } - virtual Matrix<Scalar> invJacobian(Matrix<Scalar> const& __x) const{ - return Matrix<Scalar>(); - } - virtual Matrix<Scalar> invJacobian(Matrix<Scalar> const& __x, - size_t __i) const{ - return Matrix<Scalar>(); - } +namespace meow { + +/*! + * @brief A base class for implementing kinds of transformations. + * + * We define that the input and output form of our transformations all be + * \b matrix . Some advance methods such as calculating jacobian matrix + * will order that the input form must be a vector. + * @author cat_leopard + */ +template<class Scalar> +class Transformation { +private: + struct Myself { + size_t inputRows_; + size_t inputCols_; + size_t outputRows_; + size_t outputCols_; + size_t psize_; + + Myself& copyFrom(Myself const& b) { + inputRows_ = b. inputRows_; + inputCols_ = b. inputCols_; + outputRows_ = b.outputRows_; + outputCols_ = b.outputCols_; + psize_ = b.psize_; + return *this; + } }; + + Self<Myself> const self; +protected: + /*! + * Construct and setup + * @param [in] inputRows number of rows of the input matrix. + * @param [in] inputCols number of columns of the input matrix. + * @param [in] outputRows number of rows of the output matrix. + * @param [in] outputCols number of columns of the output matrix. + * @param [in] psize number of parameters + */ + Transformation(size_t inputRows, size_t inputCols, + size_t outputRows, size_t outputCols, + size_t psize): self(true) { + self()-> inputRows_ = inputRows; + self()-> inputCols_ = inputCols; + self()->outputRows_ = outputRows; + self()->outputCols_ = outputCols; + self()->psize_ = psize; + } + + /*! + * Construct and copy setings from another transformation class. + * @param [in] b Specify where to copy the informations. + */ + Transformation(Transformation const& b): self(false) { + copyFrom(b); + } + + /*! + * @brief Copy from the specified one + * + * @param [in] b The specified one + * @return \c *this + */ + Transformation& copyFrom(Transformation const& b) { + self().copyFrom(b.self); + return *this; + } + + /*! + * @brief Ceference from the specified one + * + * @param [in] b The specified one + * @return \c *this + */ + Transformation& referenceFrom(Transformation const& b) { + self().referenceFrom(b.self); + return *this; + } +public: + /*! + * Destructor + */ + virtual ~Transformation() { + } + + /*! + * @brief Return the number of rows of the input matrix. + * + * @return Number of rows. + */ + size_t inputRows() const { + return self->inputRows_; + } + + /*! + * @brief Return the number of columns of the input matrix. + * + * @return Number of columns. + */ + size_t inputCols() const { + return self->inputCols_; + } + + /*! + * @brief Return the number of rows of the output matrix. + * + * @return Number of rows. + */ + size_t outputRows() const { + return self->outputRows_; + } + + /*! + * @brief Return the number of columns of the output matrix. + * + * @return Number of columns. + */ + size_t outputCols() const { + return self->outputCols_; + } + + /*! + * @brief Return the number of parameters. + * + * @return Number of parameters. + */ + size_t parameterSize() const { + return self->psize_; + } + + /*! + * @brief Get the \a i -th parameter. + * + * @param [in] i The index of the specified parameter. + * @note It's a pure virtual method. + */ + virtual Scalar parameter(size_t i) const = 0; + + /*! + * @brief Setup the \a i -th parameter. + * + * @param [in] i The index of the specified parameter. + * @param [in] s The new value to the specified parameter. + * @note It's a pure virtual method. + */ + virtual Scalar parameter(size_t i, Scalar const& s) = 0; + + /*! + * @brief Do transformate. + * + * @param [in] x The input matrix. + * @note It's a pure virtual method. + */ + virtual Matrix<Scalar> transformate(Matrix<Scalar> const& x) const = 0; + + /*! + * @brief Calculate the jacobian matrix (derivate by the input matrix) + * of the transformation. + * + * Consider the case of a non-differentiable + * transformation might be implemented, we return an empty matrix + * now instead of making it be a pure virtual method. + * @param [in] x The input matrix. + * @return An empty matrix. + */ + virtual Matrix<Scalar> jacobian(Matrix<Scalar> const& x) const { + return Matrix<Scalar>(); + } + + /*! + * @brief Calculate the jacobian matrix (derivate by the \a i -th parameter) + * of the transformation. + * + * Consider the case of a non-differentiable transformation might be + * implemented, we return an empty matrix now instead of making it be + * a pure virtual method. + * @param [in] x The input matrix. + * @param [in] i The index of the specified parameter. + * @return An empty matrix. + */ + virtual Matrix<Scalar> jacobian(Matrix<Scalar> const& x, size_t i) const { + return Matrix<Scalar>(); + } + + /*! + * @brief Return whether this transformation is inversable or not + * + * @return \c false + */ + virtual bool inversable() const { return false; } + + /*! + * @brief Do the inverse transformation + * + * @param [in] x The input matirx + * @return An empty matrix + */ + virtual Matrix<Scalar> transformateInv(Matrix<Scalar> const& x) const { + return Matrix<Scalar>(); + } + + /*! + * @brief Return the jacobian matrix of the inverse transformation + * + * @param [in] x The input matirx + * @return An empty matrix + */ + virtual Matrix<Scalar> jacobianInv(Matrix<Scalar> const& x) const { + return Matrix<Scalar>(); + } + + /*! + * @brief Return the jacobian matrix of the inverse transformation + * + * @param [in] x The input matirx + * @param [in] i The index of the specified parameter. + * @return An empty matrix + */ + virtual Matrix<Scalar> jacobianInv(Matrix<Scalar> const& x, size_t i) const { + return Matrix<Scalar>(); + } +}; + } #endif // math_Transformation_H__ |