KWStyle - itkSymmetricSecondRankTensor.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkSymmetricSecondRankTensor.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:48 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 #ifndef __itkSymmetricSecondRankTensor_h
18 #define __itkSymmetricSecondRankTensor_h
19
20 // Undefine an eventual SymmetricSecondRankTensor macro
21 #ifdef SymmetricSecondRankTensor
22 #undef SymmetricSecondRankTensor
23 #endif
24
25 #include <itkIndent.h>
26 #include <itkFixedArray.h>
27 #include <itkMatrix.h>
28 #include "itkSymmetricEigenAnalysis.h"
29
30 namespace itk
31 {
32
33 /** \class SymmetricSecondRankTensor
34  * \brief Represent a symmetric tensor of second rank.
35  *
36  * This class implements a ND symmetric tensor of second rank.
37  *
38  * Since SymmetricSecondRankTensor is a subclass of FixedArray,
39  * you can access its components as:
40  *
41  * typedef itk::SymmetricSecondRankTensor< float >    TensorPixelType;
42  * TensorPixelType tensor;
43  *
44  *   tensor[0] = 1.233;
45  *   tensor[1] = 1.456;
46  *
47  * for convenience the indexed access is also available as
48  *
49  *   tensor(0,0) = 1.233;
50  *   tensor(2,0) = 1.233;
51  *
52  * The Tensor in principle represents a NxN matrix, but given that it is always
53  * symmetric the representation can be compacted into a N*(N+1)/2 elements
54  * array that derives from the itk::FixedArray<T>
55  *
56  * \author Jeffrey Duda from School of Engineering at University of Pennsylvania
57  * \author Torsten Rohlfing from SRI International Neuroscience Program.
58  *
59  * This class was mostly based on files that Jeffrey Duda, Torsten Rohlfing and
60  * Martin Styner contributed to the ITK users list during a discussion on
61  * support for DiffusionTensorImages. The funding for creating this class was
62  * largely provided by NAMIC (National Alliance for Medical Image Computing)
63  * (http://www.na-mic.org). A discussion on the design of this class can be
64  * found in the WIKI pages of NAMIC:
65  *
66 LEN  * http://www.na-mic.org/Wiki/index.php/NAMIC_Wiki:DTI:ITK-DiffusionTensorPixelType
67  *
68  * \sa DiffusionTensor3D
69  *
70  * \ingroup ImageObjects   TensorObjects   Geometry
71  */
72
73 template < typename TComponent, unsigned int NDimension=3 >
74 class SymmetricSecondRankTensor: public 
75 IND ********FixedArray<TComponent,NDimension*(NDimension+1)/2>
76 {
77 public:
78   /** Standard class typedefs. */
79   typedef SymmetricSecondRankTensor  Self;
80 TDA   typedef FixedArray<TComponent,NDimension*(NDimension+1)/2> Superclass;
81   
82   /** Dimension of the vector space. */
83   itkStaticConstMacro(Dimension, unsigned int, NDimension);
84 LEN   itkStaticConstMacro(InternalDimension, unsigned int, NDimension*(NDimension+1)/2);
85
86   /** Convenience typedefs. */
87   typedef FixedArray<TComponent,
88           itkGetStaticConstMacro(InternalDimension)> BaseArray;
89   
90   /** Array of eigen-values. */
91   typedef FixedArray<TComponent, NDimension> EigenValuesArrayType;
92   
93   /** Matrix of eigen-vectors. */
94   typedef Matrix<TComponent, NDimension, NDimension> MatrixType;
95   typedef Matrix<TComponent, NDimension, NDimension> EigenVectorsMatrixType;
96   
97   /**  Define the component type. */
98   typedef TComponent ComponentType;
99 TDA   typedef typename Superclass::ValueType ValueType;
100 TDA   typedef typename NumericTraits<ValueType>::RealType AccumulateValueType;
101 TDA   typedef typename NumericTraits<ValueType>::RealType RealValueType;
102   
103   typedef SymmetricEigenAnalysis< MatrixType, 
104 LEN             EigenValuesArrayType, EigenVectorsMatrixType >  SymmetricEigenAnalysisType;
105
106   /** Default constructor has nothing to do. */
107   SymmetricSecondRankTensor() {this->Fill(0);}
108   
109   SymmetricSecondRankTensor (const ComponentType& r) { this->Fill(r); }
110   
111 LEN,TDR   typedef ComponentType ComponentArrayType[ itkGetStaticConstMacro(InternalDimension) ];
112
113   /** Pass-through constructor for the Array base class. */
114   SymmetricSecondRankTensor(const Self& r): BaseArray(r) {}
115   SymmetricSecondRankTensor(const ComponentArrayType r): BaseArray(r) {}    
116   
117   /** Pass-through assignment operator for the Array base class. */
118   Self& operator= (const Self& r);
119   Self& operator= (const ComponentType& r);
120   Self& operator= (const ComponentArrayType r);
121
122 LEN   /** Aritmetic operations between pixels. Return a new SymmetricSecondRankTensor. */
123   Self operator+(const Self &vec) const;
124   Self operator-(const Self &vec) const;
125   const Self & operator+=(const Self &vec);
126   const Self & operator-=(const Self &vec);
127
128   /** Arithmetic operations between tensors and scalars */
129   Self operator*(const RealValueType & scalar ) const;
130   Self operator/(const RealValueType & scalar ) const;
131   const Self & operator*=(const RealValueType & scalar );
132   const Self & operator/=(const RealValueType & scalar );
133  
134   /** Return the number of components. */
135   static unsigned int GetNumberOfComponents() 
136     { 
137     return itkGetStaticConstMacro(InternalDimension);
138     }
139
140   /** Return the value for the Nth component. */
141   ComponentType GetNthComponent(int c) const
142     { return this->operator[](c); }
143
144   /** Set the Nth component to v. */
145   void SetNthComponent(int c, const ComponentType& v)  
146     {  this->operator[](c) = v; }
147
148   /** Matrix notation, in const and non-const forms. */
149   ValueType & operator()( unsigned int row, unsigned int col );
150   const ValueType & operator()( unsigned int row, unsigned int col ) const;
151
152   /** Set the tensor to an identity tensor. This has 1 in its diagonal elements
153    * zero elsewhere */
154   void SetIdentity();
155
156   /** Get Trace value */
157   AccumulateValueType GetTrace() const;
158
159   /** Return an array containing EigenValues. */
160   void ComputeEigenValues( EigenValuesArrayType & eigenValues ) const;
161  
162   /** Return an array containing EigenValues, and a matrix containing Eigen
163    * vectors. */
164   void ComputeEigenAnalysis( EigenValuesArrayType & eigenValues,
165                              EigenVectorsMatrixType & eigenVectors ) const;
166
167 private:
168
169   
170 };
171
172 /** This extra typedef is necessary for preventing an Internal Compiler Error in
173 LEN  * Microsoft Visual C++ 6.0. This typedef is not needed for any other compiler. */
174 typedef std::ostream               OutputStreamType;
175 typedef std::istream               InputStreamType;
176
177 template< typename TComponent, unsigned int NDimension  >  
178 ITK_EXPORT OutputStreamType& operator<<(OutputStreamType& os, 
179               const SymmetricSecondRankTensor<TComponent,NDimension> & c); 
180 template< typename TComponent, unsigned int NDimension  >  
181 ITK_EXPORT InputStreamType& operator>>(InputStreamType& is, 
182                     SymmetricSecondRankTensor<TComponent,NDimension> & c); 
183
184 template <typename TValueType, unsigned int VLength>
185 inline SymmetricSecondRankTensor< TValueType, VLength> operator* 
186 IND ****(double d, const SymmetricSecondRankTensor< TValueType, VLength > & f)
187 {
188   return f * d;
189 }
190
191
192 EML
193 // end namespace itk
194
195 #ifndef ITK_MANUAL_INSTANTIATION
196 #include "itkSymmetricSecondRankTensor.txx"
197 #endif
198
199 #endif
200

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:49PM
© Kitware Inc.