#ifndef math_LinearTransformation_H__
#define math_LinearTransformation_H__
#include "Transformation.h"
#include "Matrix.h"
#include <cstdlib>
namespace meow {
/*!
* @brief A base class for implementing kinds of linear transformations.
*
* Because all linear transformations belong to transformations,
* this class inherit to Transformation.
*
* @author cat_leopard
*/
template<class Scalar>
class LinearTransformation: public Transformation<Scalar> {
private:
Matrix<Scalar> matrix_;
protected:
/*!
* Constructor with input/output size gived
*/
LinearTransformation(size_t inputRows, size_t outputRows, size_t psize):
Transformation<Scalar>(inputRows, 1u, outputRows, 1u, psize),
matrix_(outputRows, inputRows, Scalar(0.0)) {
}
/*!
* Constructor with input/output size gived and a inital matrix
*/
LinearTransformation(size_t inputRows, size_t outputRows, size_t psize,
Matrix<Scalar> const& m):
Transformation<Scalar>(inputRows, 1u, outputRows, 1u, psize),
matrix_(m) {
}
/*!
* Constructor with another LinearTransformation
*
* @param [in] b another LinearTransformation
*/
LinearTransformation(LinearTransformation const& b):
Transformation<Scalar>(b),
matrix_(b.matrix_) {
}
/*!
* @brief Copy settings, matrix from another LinearTransformation
*
* @param [in] b another LinearTransformation
*/
LinearTransformation& copyFrom(LinearTransformation const& b) {
Transformation<Scalar>::copyFrom(b);
matrix_.copyFrom(b.matrix_);
return *this;
}
/*!
* @brief Reference settings, matrix from another LinearTransformation
*
* @param [in] b another LinearTransformation
*/
LinearTransformation& referenceFrom(LinearTransformation const& b) {
Transformation<Scalar>::referenceFrom(b);
matrix_.referenceFrom(b.matrix_);
return *this;
}
/*!
* @brief setup the matrix
*/
virtual Matrix<Scalar> const& matrix(Matrix<Scalar> const& m) {
matrix_.copyFrom(m);
return matrix();
}
public:
/*!
* Destructor
*/
virtual ~LinearTransformation() {
}
/*!
* @brief Return the matrix form of this transformation
*
* @return A matrix
*/
virtual Matrix<Scalar> const& matrix() const {
return matrix_;
}
/*!
* @brief Return the inverse of the matrix form of this transformate
*
* @return A matrix (may be invalid)
*/
virtual Matrix<Scalar> matrixInv() const {
return matrix_.inverse();
}
};
} // meow
#endif // math_LinearTransformation_H__