ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkSymmetricSecondRankTensor.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkSymmetricSecondRankTensor_h
00019 #define __itkSymmetricSecondRankTensor_h
00020 
00021 // Undefine an eventual SymmetricSecondRankTensor macro
00022 #ifdef SymmetricSecondRankTensor
00023 #undef SymmetricSecondRankTensor
00024 #endif
00025 
00026 #include "itkIndent.h"
00027 #include "itkFixedArray.h"
00028 #include "itkMatrix.h"
00029 #include "itkSymmetricEigenAnalysis.h"
00030 
00031 namespace itk
00032 {
00074 template< typename TComponent, unsigned int NDimension = 3 >
00075 class SymmetricSecondRankTensor:public
00076   FixedArray< TComponent, NDimension *( NDimension + 1 ) / 2 >
00077 {
00078 public:
00080   typedef SymmetricSecondRankTensor                                    Self;
00081   typedef FixedArray< TComponent, NDimension *( NDimension + 1 ) / 2 > Superclass;
00082 
00084   itkStaticConstMacro(Dimension, unsigned int, NDimension);
00085   itkStaticConstMacro( InternalDimension, unsigned int, ( NDimension * ( NDimension + 1 ) / 2 ) );
00087 
00089   typedef FixedArray< TComponent,
00090                       itkGetStaticConstMacro(InternalDimension) > BaseArray;
00091 
00093   typedef FixedArray< TComponent, NDimension > EigenValuesArrayType;
00094 
00096   typedef Matrix< TComponent, NDimension, NDimension > MatrixType;
00097   typedef Matrix< TComponent, NDimension, NDimension > EigenVectorsMatrixType;
00098 
00100   typedef TComponent                                    ComponentType;
00101   typedef typename Superclass::ValueType                ValueType;
00102   typedef typename NumericTraits< ValueType >::RealType AccumulateValueType;
00103   typedef typename NumericTraits< ValueType >::RealType RealValueType;
00104 
00105   typedef SymmetricEigenAnalysis< MatrixType,
00106                                   EigenValuesArrayType, EigenVectorsMatrixType >  SymmetricEigenAnalysisType;
00107 
00109   SymmetricSecondRankTensor() { this->Fill(0); }
00110 
00111   SymmetricSecondRankTensor (const ComponentType & r) { this->Fill(r); }
00112 
00114   template< typename TCoordRepB >
00115   SymmetricSecondRankTensor(const SymmetricSecondRankTensor< TCoordRepB, NDimension > & pa):
00116     BaseArray(pa) {}
00117 
00118   typedef ComponentType ComponentArrayType[itkGetStaticConstMacro(InternalDimension)];
00119 
00121   SymmetricSecondRankTensor(const ComponentArrayType r):BaseArray(r) {}
00122 
00124   template< typename TCoordRepB >
00125   Self & operator=(const SymmetricSecondRankTensor< TCoordRepB, NDimension > & pa)
00126   {
00127     BaseArray::operator=(pa);
00128     return *this;
00129   }
00131 
00133   Self & operator=(const ComponentType & r);
00134 
00135   Self & operator=(const ComponentArrayType r);
00136 
00139   Self operator+(const Self & vec) const;
00140 
00141   Self operator-(const Self & vec) const;
00142 
00143   const Self & operator+=(const Self & vec);
00144 
00145   const Self & operator-=(const Self & vec);
00146 
00148   Self operator *(const RealValueType & scalar) const;
00149 
00150   Self operator/(const RealValueType & scalar) const;
00151 
00152   const Self & operator*=(const RealValueType & scalar);
00153 
00154   const Self & operator/=(const RealValueType & scalar);
00155 
00157   static unsigned int GetNumberOfComponents()
00158   {
00159     return itkGetStaticConstMacro(InternalDimension);
00160   }
00161 
00163   ComponentType GetNthComponent(int c) const { return this->operator[](c); }
00164 
00166   void SetNthComponent(int c, const ComponentType & v) {  this->operator[](c) = v; }
00167 
00169   ValueType & operator()(unsigned int row, unsigned int col);
00170 
00171   const ValueType & operator()(unsigned int row, unsigned int col) const;
00172 
00175   void SetIdentity();
00176 
00178   AccumulateValueType GetTrace() const;
00179 
00181   void ComputeEigenValues(EigenValuesArrayType & eigenValues) const;
00182 
00185   void ComputeEigenAnalysis(EigenValuesArrayType & eigenValues,
00186                             EigenVectorsMatrixType & eigenVectors) const;
00187 
00189   Self PreMultiply(const MatrixType & m) const;
00190 
00192   Self PostMultiply(const MatrixType & m) const;
00193 
00194 private:
00195 };
00196 
00199 typedef std::ostream OutputStreamType;
00200 typedef std::istream InputStreamType;
00201 
00202 template< typename TComponent, unsigned int NDimension  >
00203 ITK_EXPORT OutputStreamType & operator<<(OutputStreamType & os,
00204                                          const SymmetricSecondRankTensor< TComponent, NDimension > & c);
00205 
00206 template< typename TComponent, unsigned int NDimension  >
00207 ITK_EXPORT InputStreamType & operator>>(InputStreamType & is,
00208                                         SymmetricSecondRankTensor< TComponent, NDimension > & c);
00209 } // end namespace itk
00210 
00211 #include "itkNumericTraitsTensorPixel.h"
00212 
00213 // Define instantiation macro for this template.
00214 #define ITK_TEMPLATE_SymmetricSecondRankTensor(_, EXPORT, TypeX, TypeY)     \
00215   namespace itk                                                             \
00216   {                                                                         \
00217   _( 2 ( class EXPORT SymmetricSecondRankTensor< ITK_TEMPLATE_2 TypeX > ) ) \
00218   namespace Templates                                                       \
00219   {                                                                         \
00220   typedef SymmetricSecondRankTensor< ITK_TEMPLATE_2 TypeX >                 \
00221   SymmetricSecondRankTensor##TypeY;                                       \
00222   }                                                                         \
00223   }
00224 
00225 #if ITK_TEMPLATE_EXPLICIT
00226 //template < typename TComponent, unsigned int NDimension> const unsigned int
00227 // itk::SymmetricSecondRankTensor<TComponent,NDimension>::InternalDimension;
00228 
00229 #include "Templates/itkSymmetricSecondRankTensor+-.h"
00230 #endif
00231 
00232 #if ITK_TEMPLATE_TXX
00233 #include "itkSymmetricSecondRankTensor.hxx"
00234 #endif
00235 
00236 #endif
00237