aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/math/LinearTransformation.h
blob: f51630ef721367bd4afee614bc342458a9c43c75 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#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__