fw4spl
SrcLib/core/fwData/include/fwData/TransformationMatrix3D.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #pragma once
8 
9 #include "fwData/factory/new.hpp"
10 #include "fwData/Object.hpp"
11 
12 #include <array>
13 #include <iostream>
14 
15 fwCampAutoDeclareDataMacro((fwData)(TransformationMatrix3D), FWDATA_API);
16 
17 namespace fwData
18 {
19 
23 class FWDATA_CLASS_API TransformationMatrix3D : public Object
24 {
25 
26 public:
28  (()), ::fwData::factory::New< TransformationMatrix3D >);
29 
30  fwCampMakeFriendDataMacro((fwData)(TransformationMatrix3D));
31 
32  typedef double TM3DType;
33  typedef std::array<TM3DType, 16> TMCoefArray;
34 
40 
42  FWDATA_API virtual ~TransformationMatrix3D();
43 
45  FWDATA_API void shallowCopy( const Object::csptr& _source ) override;
46 
48  FWDATA_API void cachedDeepCopy(const Object::csptr& _source, DeepCopyCacheType& cache) override;
49 
51  TMCoefArray& getCoefficients ();
52  const TMCoefArray& getCoefficients () const;
53  void setCoefficients (const TMCoefArray& _vCoefficients);
54 
59  FWDATA_API TM3DType getCoefficient(size_t l, size_t c) const;
60  FWDATA_API void setCoefficient(size_t l, size_t c, TM3DType val);
62 
64  static const size_t MATRIX_SIZE = 4;
65 
67  friend std::ostream& operator<<(std::ostream& s, const TransformationMatrix3D& mat)
68  {
69  for(size_t l = 0; l < MATRIX_SIZE; l++)
70  {
71  for(size_t c = 0; c < MATRIX_SIZE; c++)
72  {
73  s << mat.getCoefficient(l, c) << "\t";
74  }
75  s << std::endl;
76  }
77  return s;
78  }
79 
80 protected:
81 
83  TMCoefArray m_vCoefficients;
84 };
85 
86 //-----------------------------------------------------------------------------
87 
88 inline TransformationMatrix3D::TMCoefArray& TransformationMatrix3D::getCoefficients()
89 {
90  return this->m_vCoefficients;
91 }
92 
93 //-----------------------------------------------------------------------------
94 
95 inline const TransformationMatrix3D::TMCoefArray& TransformationMatrix3D::getCoefficients() const
96 {
97  return this->m_vCoefficients;
98 }
99 
100 //-----------------------------------------------------------------------------
101 
102 inline void TransformationMatrix3D::setCoefficients(const TransformationMatrix3D::TMCoefArray& _vCoefficients)
103 {
104  this->m_vCoefficients = _vCoefficients;
105 }
106 
107 //------------------------------------------------------------------------------
108 
109 inline TransformationMatrix3D::TM3DType TransformationMatrix3D::getCoefficient(size_t l, size_t c) const
110 {
111  size_t pos = l * MATRIX_SIZE + c;
112  return m_vCoefficients.at(pos);
113 }
114 
115 //------------------------------------------------------------------------------
116 
117 inline void TransformationMatrix3D::setCoefficient(size_t l, size_t c, TransformationMatrix3D::TM3DType val)
118 {
119  size_t pos = l * MATRIX_SIZE + c;
120  m_vCoefficients.at(pos) = val;
121 }
122 
123 //-----------------------------------------------------------------------------
124 
125 } // namespace fwData
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
friend std::ostream & operator<<(std::ostream &s, const TransformationMatrix3D &mat)
Print the coefficients of the matrix.
FWDATA_API TM3DType getCoefficient(size_t l, size_t c) const
Get/Set value of the coefficient in the given position (matrix[l][c])
FWDATA_API void setCoefficient(size_t l, size_t c, TM3DType val)
Get/Set value of the coefficient in the given position (matrix[l][c])
#define fwCoreClassDefinitionsWithFactoryMacro(_classinfo_, _parameters_, _factory_)
Generate common construction methods for classes with one factory.
This class represents a 3D transformation matrix (4x4).
Base class for each data object.
Contains the representation of the data objects used in the framework.
TMCoefArray m_vCoefficients
Matrix coefficient number (4x4). m_vCoefficients[0] to m_vCoefficients[3] is the first row of the mat...