cctw  0.2.1
Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
CctwMatrix3x3< T > Class Template Reference

#include <cctwmatrix3x3.h>

Inheritance diagram for CctwMatrix3x3< T >:
Inheritance graph
Collaboration diagram for CctwMatrix3x3< T >:
Collaboration graph

Public Member Functions

 CctwMatrix3x3 ()
 
 CctwMatrix3x3 (CctwVector3D< T > c1, CctwVector3D< T > c2, CctwVector3D< T > c3)
 
 CctwMatrix3x3 (T a11, T a12, T a13, T a21, T a22, T a23, T a31, T a32, T a33)
 
T & operator() (int row, int col)
 
const T & operator() (int row, int col) const
 
CctwMatrix3x3 operator+ (const CctwMatrix3x3 &mat) const
 
CctwMatrix3x3 operator+= (const CctwMatrix3x3 &mat)
 
CctwMatrix3x3 operator- (const CctwMatrix3x3 &mat) const
 
CctwMatrix3x3 operator-= (const CctwMatrix3x3 &mat)
 
CctwMatrix3x3 operator* (const CctwMatrix3x3 &mat) const
 
CctwVector3D< T > operator* (const CctwVector3D< T > &vec) const
 
bool operator== (const CctwMatrix3x3 &mat) const
 
bool operator!= (const CctwMatrix3x3 &mat) const
 
double determinant () const
 
CctwMatrix3x3 inverted (bool *invertible=NULL) const
 
CctwMatrix3x3 transposed () const
 
void setToIdentity ()
 
void setSettingsValue (QSettings *settings, QString name)
 
template<>
void customSaver (const QVariant &val, QSettings *settings, QString name)
 

Static Public Member Functions

static CctwMatrix3x3 zero ()
 
static CctwMatrix3x3 identity ()
 
static CctwMatrix3x3 rotationMatrix (double r1, double r2, double r3)
 
static CctwMatrix3x3 rotX (double r)
 
static CctwMatrix3x3 rotY (double r)
 
static CctwMatrix3x3 rotZ (double r)
 
static void customSaver (const QVariant &val, QSettings *settings, QString name)
 

Private Attributes

m_Matrix [3][3]
 

Friends

template<typename T1 >
class CctwMatrix3x3
 
template<typename T1 >
class CctwVector3D
 

Detailed Description

template<typename T>
class CctwMatrix3x3< T >

Definition at line 10 of file cctwmatrix3x3.h.

Constructor & Destructor Documentation

template<typename T >
CctwMatrix3x3< T >::CctwMatrix3x3 ( )

Definition at line 5 of file cctwmatrix3x3.cpp.

6 {
8 }
template<typename T>
CctwMatrix3x3< T >::CctwMatrix3x3 ( CctwVector3D< T >  c1,
CctwVector3D< T >  c2,
CctwVector3D< T >  c3 
)

Definition at line 11 of file cctwmatrix3x3.cpp.

12 {
13  for (int row=0; row<3; ++row) {
14  m_Matrix[row][0]=c1(row);
15  m_Matrix[row][1]=c2(row);
16  m_Matrix[row][2]=c3(row);
17  }
18 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T>
CctwMatrix3x3< T >::CctwMatrix3x3 ( a11,
a12,
a13,
a21,
a22,
a23,
a31,
a32,
a33 
)

Definition at line 21 of file cctwmatrix3x3.cpp.

22 {
23  m_Matrix[0][0] = a11;
24  m_Matrix[0][1] = a12;
25  m_Matrix[0][2] = a13;
26  m_Matrix[1][0] = a21;
27  m_Matrix[1][1] = a22;
28  m_Matrix[1][2] = a23;
29  m_Matrix[2][0] = a31;
30  m_Matrix[2][1] = a32;
31  m_Matrix[2][2] = a33;
32 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55

Member Function Documentation

template<typename T>
static void CctwMatrix3x3< T >::customSaver ( const QVariant &  val,
QSettings *  settings,
QString  name 
)
static
template<>
void CctwMatrix3x3< int >::customSaver ( const QVariant &  val,
QSettings *  settings,
QString  name 
)

Definition at line 329 of file cctwmatrix3x3.cpp.

References CctwMatrix3x3< T >::setSettingsValue().

330 {
331  CctwIntMatrix3x3 mat = val.value<CctwIntMatrix3x3 >();
332 
333  mat.setSettingsValue(settings, name);
334 }
void setSettingsValue(QSettings *settings, QString name)
template<typename T >
double CctwMatrix3x3< T >::determinant ( ) const

Definition at line 167 of file cctwmatrix3x3.cpp.

168 {
169  double
170  a = m_Matrix[0][0],
171  b = m_Matrix[0][1],
172  c = m_Matrix[0][2],
173  d = m_Matrix[1][0],
174  e = m_Matrix[1][1],
175  f = m_Matrix[1][2],
176  g = m_Matrix[2][0],
177  h = m_Matrix[2][1],
178  k = m_Matrix[2][2];
179 
180  return a*(e*k - f*h) + b*(f*g - d*k) + c*(d*h - e*g);
181 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T >
CctwMatrix3x3< T > CctwMatrix3x3< T >::identity ( )
static

Definition at line 301 of file cctwmatrix3x3.cpp.

Referenced by CctwCrystalCoordinateTransform::setCurrentFrame().

302 {
303  return CctwMatrix3x3<T>(1,0,0, 0,1,0, 0,0,1);
304 }
template<typename T >
CctwMatrix3x3< T > CctwMatrix3x3< T >::inverted ( bool *  invertible = NULL) const

Definition at line 184 of file cctwmatrix3x3.cpp.

References CctwMatrix3x3< T >::m_Matrix.

Referenced by CctwCrystalCoordinateTransform::createBMatrix(), CctwCrystalCoordinateTransform::setCurrentFrame(), and CctwCrystalCoordinateTransform::updateFromParameters().

185 {
186  CctwMatrix3x3<T> inv;
187  double det = determinant();
188 
189  if (det != 0.0) {
190  double
191  a = m_Matrix[0][0],
192  b = m_Matrix[1][0],
193  c = m_Matrix[2][0],
194  d = m_Matrix[0][1],
195  e = m_Matrix[1][1],
196  f = m_Matrix[2][1],
197  g = m_Matrix[0][2],
198  h = m_Matrix[1][2],
199  k = m_Matrix[2][2];
200 
201  inv.m_Matrix[0][0] = (e*k - f*h)/det;
202  inv.m_Matrix[1][0] =-(b*k - c*h)/det;
203  inv.m_Matrix[2][0] = (b*f - c*e)/det;
204 
205  inv.m_Matrix[0][1] =-(d*k - f*g)/det;
206  inv.m_Matrix[1][1] = (a*k - c*g)/det;
207  inv.m_Matrix[2][1] =-(a*f - c*d)/det;
208 
209  inv.m_Matrix[0][2] = (d*h - e*g)/det;
210  inv.m_Matrix[1][2] =-(a*h - b*g)/det;
211  inv.m_Matrix[2][2] = (a*e - b*d)/det;
212 
213  if (invertible) {
214  *invertible = true;
215  }
216  } else {
217  if (invertible) {
218  *invertible = false;
219  }
220  }
221 
222  return inv;
223 }
double determinant() const
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T >
bool CctwMatrix3x3< T >::operator!= ( const CctwMatrix3x3< T > &  mat) const

Definition at line 139 of file cctwmatrix3x3.cpp.

References CctwMatrix3x3< T >::m_Matrix.

140 {
141  for (int row = 0; row < 3; ++row) {
142  for (int col = 0; col < 3; ++col) {
143  if (m_Matrix[row][col] != mat.m_Matrix[row][col]) {
144  return true;
145  }
146  }
147  }
148 
149  return false;
150 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T >
T & CctwMatrix3x3< T >::operator() ( int  row,
int  col 
)

Definition at line 35 of file cctwmatrix3x3.cpp.

36 {
37  return m_Matrix[row][col];
38 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T >
const T & CctwMatrix3x3< T >::operator() ( int  row,
int  col 
) const

Definition at line 41 of file cctwmatrix3x3.cpp.

42 {
43  return m_Matrix[row][col];
44 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T >
CctwMatrix3x3< T > CctwMatrix3x3< T >::operator* ( const CctwMatrix3x3< T > &  mat) const

Definition at line 95 of file cctwmatrix3x3.cpp.

References CctwMatrix3x3< T >::m_Matrix.

96 {
97  CctwMatrix3x3<T> result;
98  for (int row = 0; row < 3; ++row) {
99  for (int col = 0; col < 3; ++col) {
100  T sum(0.0f);
101  for (int j = 0; j < 3; ++j) {
102  sum += m_Matrix[row][j] * mat.m_Matrix[j][col];
103  }
104  result.m_Matrix[row][col] = sum;
105  }
106  }
107  return result;
108 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T>
CctwVector3D< T > CctwMatrix3x3< T >::operator* ( const CctwVector3D< T > &  vec) const

Definition at line 111 of file cctwmatrix3x3.cpp.

112 {
113  CctwVector3D<T> result;
114  for (int row = 0; row < 3; ++row) {
115  T sum(0.0f);
116  for (int j = 0; j < 3; ++j) {
117  sum += m_Matrix[row][j] * vec(j);
118  }
119  result(row) = sum;
120  }
121  return result;
122 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T >
CctwMatrix3x3< T > CctwMatrix3x3< T >::operator+ ( const CctwMatrix3x3< T > &  mat) const

Definition at line 47 of file cctwmatrix3x3.cpp.

References CctwMatrix3x3< T >::m_Matrix.

48 {
49  CctwMatrix3x3<T> result;
50  for (int row = 0; row < 3; ++row) {
51  for (int col = 0; col < 3; ++col) {
52  result.m_Matrix[row][col] = m_Matrix[row][col] + mat.m_Matrix[row][col];
53  }
54  }
55  return result;
56 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T >
CctwMatrix3x3< T > CctwMatrix3x3< T >::operator+= ( const CctwMatrix3x3< T > &  mat)

Definition at line 59 of file cctwmatrix3x3.cpp.

References CctwMatrix3x3< T >::m_Matrix.

60 {
61  for (int row = 0; row < 3; ++row) {
62  for (int col = 0; col < 3; ++col) {
63  m_Matrix[row][col] += mat.m_Matrix[row][col];
64  }
65  }
66  return *this;
67 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T >
CctwMatrix3x3< T > CctwMatrix3x3< T >::operator- ( const CctwMatrix3x3< T > &  mat) const

Definition at line 70 of file cctwmatrix3x3.cpp.

References CctwMatrix3x3< T >::m_Matrix.

71 {
72  CctwMatrix3x3<T> result;
73  for (int row = 0; row < 3; ++row) {
74  for (int col = 0; col < 3; ++col) {
75  result.m_Matrix[row][col] = m_Matrix[row][col] - mat.m_Matrix[row][col];
76  }
77  }
78 
79  return result;
80 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T >
CctwMatrix3x3< T > CctwMatrix3x3< T >::operator-= ( const CctwMatrix3x3< T > &  mat)

Definition at line 83 of file cctwmatrix3x3.cpp.

References CctwMatrix3x3< T >::m_Matrix.

84 {
85  for (int row = 0; row < 3; ++row) {
86  for (int col = 0; col < 3; ++col) {
87  m_Matrix[row][col] -= mat.m_Matrix[row][col];
88  }
89  }
90 
91  return *this;
92 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T >
bool CctwMatrix3x3< T >::operator== ( const CctwMatrix3x3< T > &  mat) const

Definition at line 125 of file cctwmatrix3x3.cpp.

References CctwMatrix3x3< T >::m_Matrix.

126 {
127  for (int row = 0; row < 3; ++row) {
128  for (int col = 0; col < 3; ++col) {
129  if (m_Matrix[row][col] != mat.m_Matrix[row][col]) {
130  return false;
131  }
132  }
133  }
134 
135  return true;
136 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T >
CctwMatrix3x3< T > CctwMatrix3x3< T >::rotationMatrix ( double  r1,
double  r2,
double  r3 
)
static

Definition at line 240 of file cctwmatrix3x3.cpp.

References CctwMatrix3x3< T >::rotX(), CctwMatrix3x3< T >::rotY(), and CctwMatrix3x3< T >::rotZ().

241 {
245 
246  return rx*ry*rz;
247 }
static CctwMatrix3x3 rotZ(double r)
static CctwMatrix3x3 rotX(double r)
static CctwMatrix3x3 rotY(double r)
template<typename T >
CctwMatrix3x3< T > CctwMatrix3x3< T >::rotX ( double  r)
static

Definition at line 250 of file cctwmatrix3x3.cpp.

Referenced by CctwMatrix3x3< T >::rotationMatrix(), and CctwCrystalCoordinateTransform::setCurrentFrame().

251 {
252  CctwMatrix3x3<T> res;
253  T cosr = ::cos(r),
254  sinr = ::sin(r);
255 
256  res(1,1) = cosr;
257  res(1,2) = -sinr;
258  res(2,1) = sinr;
259  res(2,2) = cosr;
260 
261  return res;
262 }
template<typename T >
CctwMatrix3x3< T > CctwMatrix3x3< T >::rotY ( double  r)
static

Definition at line 265 of file cctwmatrix3x3.cpp.

Referenced by CctwMatrix3x3< T >::rotationMatrix(), and CctwCrystalCoordinateTransform::setCurrentFrame().

266 {
267  CctwMatrix3x3<T> res;
268  T cosr = ::cos(r),
269  sinr = ::sin(r);
270 
271  res(0,0) = cosr;
272  res(0,2) = sinr;
273  res(2,0) = -sinr;
274  res(2,2) = cosr;
275 
276  return res;
277 }
template<typename T >
CctwMatrix3x3< T > CctwMatrix3x3< T >::rotZ ( double  r)
static

Definition at line 280 of file cctwmatrix3x3.cpp.

Referenced by CctwMatrix3x3< T >::rotationMatrix(), and CctwCrystalCoordinateTransform::setCurrentFrame().

281 {
282  CctwMatrix3x3<T> res;
283  T cosr = ::cos(r),
284  sinr = ::sin(r);
285 
286  res(0,0) = cosr;
287  res(0,1) = -sinr;
288  res(1,0) = sinr;
289  res(1,1) = cosr;
290 
291  return res;
292 }
template<typename T >
void CctwMatrix3x3< T >::setSettingsValue ( QSettings *  settings,
QString  name 
)

Definition at line 307 of file cctwmatrix3x3.cpp.

Referenced by CctwMatrix3x3< double >::customSaver(), and CctwMatrix3x3< T >::customSaver().

308 {
309  settings->beginGroup(name);
310 
311  for (int r=0; r<3; r++) {
312  for (int c=0; c<3; c++) {
313  settings->setValue(QString("r%1c%2").arg(r).arg(c), operator()(r,c));
314  }
315  }
316 
317  settings->endGroup();
318 }
template<typename T >
void CctwMatrix3x3< T >::setToIdentity ( )

Definition at line 153 of file cctwmatrix3x3.cpp.

154 {
155  for (int col = 0; col < 3; ++col) {
156  for (int row = 0; row < 3; ++row) {
157  if (row == col) {
158  m_Matrix[row][col] = 1.0f;
159  } else {
160  m_Matrix[row][col] = 0.0f;
161  }
162  }
163  }
164 }
T m_Matrix[3][3]
Definition: cctwmatrix3x3.h:55
template<typename T >
CctwMatrix3x3< T > CctwMatrix3x3< T >::transposed ( ) const

Definition at line 226 of file cctwmatrix3x3.cpp.

Referenced by CctwCrystalCoordinateTransform::createBMatrix().

227 {
228  CctwMatrix3x3<T> tr;
229 
230  for (int i=0; i<3; i++) {
231  for (int j=0; j<3; j++) {
232  tr(j,i) = operator() (i,j);
233  }
234  }
235 
236  return tr;
237 }
T & operator()(int row, int col)
template<typename T >
CctwMatrix3x3< T > CctwMatrix3x3< T >::zero ( )
static

Definition at line 295 of file cctwmatrix3x3.cpp.

296 {
297  return CctwMatrix3x3<T>(0,0,0,0,0,0,0,0,0);
298 }

Friends And Related Function Documentation

template<typename T>
template<typename T1 >
friend class CctwMatrix3x3
friend

Definition at line 39 of file cctwmatrix3x3.h.

template<typename T>
template<typename T1 >
friend class CctwVector3D
friend

Definition at line 42 of file cctwmatrix3x3.h.

Member Data Documentation

template<typename T>
T CctwMatrix3x3< T >::m_Matrix[3][3]
private

The documentation for this class was generated from the following files: