Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Tensor3D3x3x3.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef __Tensor3D3x3x3_hh__
27 #define __Tensor3D3x3x3_hh__
28 
29 #include "Tensor3D.hh"
30 #include "Matrix3x3.hh"
31 #include "Vector3.hh"
32 
33 namespace BIAS {
34  /**
35  * \class Tensor3D3x3x3
36  * \brief
37  * \author Felix Woelk
38  */
39  template <class T=double>
40  class BIASMathBase_EXPORT Tensor3D3x3x3 : public Tensor3D<T>
41  {
42  public:
44  virtual ~Tensor3D3x3x3<T>();
45 
46  void NewSize(const int i, const int j, const int k,
47  const T& def=(T)0.0);
48  void newsize(const int i, const int j, const int k,
49  const T& def=(T)0.0);
50 
51  /** computes the contraction of index 1 from left with contravariant
52  vector , i.e. res[k][j] = sum_i v[i] * (*this)[k][j]
53  @author woelk 07/2004 */
54  inline void LeftContravariantContraction1(Vector3<T>& v,
55  Matrix3x3<T>& res);
56  inline void LeftContravariantContraction2(Vector3<T>& v,
57  Matrix3x3<T>& res);
58  inline void LeftContravariantContraction3(Vector3<T>& v,
59  Matrix3x3<T>& res);
61  {
62  Matrix3x3<T> M;
63  LeftContravariantContraction1(v,M);
64  return M;
65  }
66 
68  {
69  Matrix3x3<T> M;
70  LeftContravariantContraction2(v,M);
71  return M;
72  }
73 
75  {
76  Matrix3x3<T> M;
77  LeftContravariantContraction3(v,M);
78  return M;
79  }
80 
81  /** @brief Compute S_{ijk} = T_{pjk} M_{pi}
82  @author mdunda */
83  void postmultiply1(const BIAS::Matrix3x3<T> &M,
84  Tensor3D3x3x3<T> &result) const;
85 
86  /** @brief Compute S_{ijk} = T_{ipk} M_{pj}
87  @author mdunda */
88  void postmultiply2(const BIAS::Matrix3x3<T> &M,
89  Tensor3D3x3x3<T> &result) const;
90 
91  /** @brief Compute S_{ijk} = T_{ijp} M_{pk}
92  @author mdunda */
93  void postmultiply3(const BIAS::Matrix3x3<T> &M,
94  Tensor3D3x3x3<T> &result) const;
95 
96  /** @brief compute S_{ijk} = M_{ip} T_{pjk}
97  @author mdunda */
98  void premultiply1(const BIAS::Matrix3x3<T> &M,
99  Tensor3D3x3x3<T> &result) const;
100 
101  /** @brief compute S_{ijk} = M_{jp} T_{ipk}
102  @author mdunda */
103  void premultiply2(const BIAS::Matrix3x3<T> &M,
104  Tensor3D3x3x3<T> &result) const;
105 
106  /** @brief compute S_{ijk} = M_{kp} T_{ijp}
107  @author mdunda */
108  void premultiply3(const BIAS::Matrix3x3<T> &M,
109  Tensor3D3x3x3<T> &result) const;
110 
111  inline void SetFromMatrices(const Matrix3x3<T>& T1, const Matrix3x3<T>& T2,
112  const Matrix3x3<T>& T3);
113 
114  inline void GetMatrices(Matrix3x3<T>& T1, Matrix3x3<T>& T2,
115  Matrix3x3<T>& T3) const;
116 
118  { Tensor3D<T>::operator=(t); return *this; }
119 
120  protected:
121 
122  }; // class
123 
124  //////////////////////////////////////////////////////////////////////////
125  /// implementation
126  //////////////////////////////////////////////////////////////////////////
127 
128  template <class T>
130  const Matrix3x3<T>& T2,
131  const Matrix3x3<T>& T3)
132  {
133  size_t size=9*sizeof(T);
134  memcpy((void *)this->_Data, (void *)T1.GetData(), size);
135  memcpy((void *)(this->_Data+9), (void *)T2.GetData(), size);
136  memcpy((void *)(this->_Data+18), (void *)T3.GetData(), size);
137  }
138 
139  template <class T>
141  Matrix3x3<T>& T3) const
142  {
143  size_t size=9*sizeof(T);
144  memcpy((void *)T1.GetData(), (void *)this->_Data, size);
145  memcpy((void *)T2.GetData(), (void *)(this->_Data+9), size);
146  memcpy((void *)T3.GetData(), (void *)(this->_Data+18), size);
147  }
148 
149  template <class T>
151  Matrix3x3<T>& res)
152  {
153 // res.SetZero();
154 // for(int i=0; i<3; i++)
155 // for(int j=0; j<3; j++)
156 // for(int k=0; k<3; k++)
157 // res[j][k] += v[i] * _DataArray[i][j][k];
158  Matrix3x3<T> T2, T3;
159  GetMatrices(res, T2, T3);
160  res*=v[0];
161  T2*=v[1];
162  T3*=v[2];
163  res+=T2;
164  res+=T3;
165  }
166 
167  template <class T>
169  Matrix3x3<T>& res)
170  {
171  res.SetZero();
172  for(int i=0; i<3; i++)
173  for(int j=0; j<3; j++)
174  for(int k=0; k<3; k++)
175  res[i][k] += v[j] * this->_DataArray[i][j][k];
176  }
177 
178  template <class T>
180  Matrix3x3<T>& res)
181  {
182  res.SetZero();
183  for(int i=0; i<3; i++)
184  for(int j=0; j<3; j++)
185  for(int k=0; k<3; k++)
186  res[i][j] += v[k] * this->_DataArray[i][j][k];
187  }
188 
189 
190 } // namespace
191 
192 
193 
194 #endif // __Tensor3D3x3x3_hh__
Tensor3D< T > & operator=(const Tensor3D< T > &t)
Definition: Tensor3D.cpp:130
Tensor3D3x3x3< T > & operator=(const Tensor3D3x3x3< T > &t)
void LeftContravariantContraction1(Vector3< T > &v, Matrix3x3< T > &res)
computes the contraction of index 1 from left with contravariant vector , i.e.
void LeftContravariantContraction3(Vector3< T > &v, Matrix3x3< T > &res)
Matrix3x3< T > LeftContravariantContraction2(Vector3< T > &v)
Matrix3x3< T > LeftContravariantContraction3(Vector3< T > &v)
is a &#39;fixed size&#39; quadratic matrix of dim.
Definition: Matrix.hh:54
class Vector3 contains a Vector of fixed dim.
Definition: Matrix.hh:53
void LeftContravariantContraction2(Vector3< T > &v, Matrix3x3< T > &res)
void GetMatrices(Matrix3x3< T > &T1, Matrix3x3< T > &T2, Matrix3x3< T > &T3) const
void SetFromMatrices(const Matrix3x3< T > &T1, const Matrix3x3< T > &T2, const Matrix3x3< T > &T3)
implementation
Matrix3x3< T > LeftContravariantContraction1(Vector3< T > &v)