ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkSymmetricSecondRankTensor.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkSymmetricSecondRankTensor_h
19 #define itkSymmetricSecondRankTensor_h
20 
21 // Undefine an eventual SymmetricSecondRankTensor macro
22 #ifdef SymmetricSecondRankTensor
23 #undef SymmetricSecondRankTensor
24 #endif
25 
26 #include "itkIndent.h"
27 #include "itkFixedArray.h"
28 #include "itkMatrix.h"
30 
31 namespace itk
32 {
74 template< typename TComponent, unsigned int NDimension = 3 >
75 class ITK_TEMPLATE_EXPORT SymmetricSecondRankTensor:public
76  FixedArray< TComponent, NDimension *( NDimension + 1 ) / 2 >
77 {
78 public:
81  using Superclass = FixedArray< TComponent, NDimension *( NDimension + 1 ) / 2 >;
82 
84  static constexpr unsigned int Dimension = NDimension;
85  static constexpr unsigned int InternalDimension = NDimension * ( NDimension + 1 ) / 2;
86 
88  using BaseArray = FixedArray< TComponent,
89  Self::InternalDimension >;
90 
93 
97 
99  using ComponentType = TComponent;
103 
106 
108  SymmetricSecondRankTensor() { this->Fill(0); }
111  SymmetricSecondRankTensor& operator=(const SymmetricSecondRankTensor &) = default;
112  SymmetricSecondRankTensor& operator=(SymmetricSecondRankTensor &&) = default;
113  ~SymmetricSecondRankTensor() = default;
115 
116  SymmetricSecondRankTensor (const ComponentType & r) { this->Fill(r); }
117 
119  template< typename TCoordRepB >
121  BaseArray(pa) {}
122 
123  typedef ComponentType ComponentArrayType[Self::InternalDimension];
124 
126  SymmetricSecondRankTensor(const ComponentArrayType r):BaseArray(r) {}
127 
129  template< typename TCoordRepB >
131  {
132  BaseArray::operator=(pa);
133  return *this;
134  }
136 
138  Self & operator=(const ComponentType & r);
139 
140  Self & operator=(const ComponentArrayType r);
141 
144  Self operator+(const Self & vec) const;
145 
146  Self operator-(const Self & vec) const;
147 
148  const Self & operator+=(const Self & vec);
149 
150  const Self & operator-=(const Self & vec);
151 
153  Self operator *(const RealValueType & scalar) const;
154 
155  Self operator/(const RealValueType & scalar) const;
156 
157  const Self & operator*=(const RealValueType & scalar);
158 
159  const Self & operator/=(const RealValueType & scalar);
160 
162  static unsigned int GetNumberOfComponents()
163  {
164  return Self::InternalDimension;
165  }
166 
168  ComponentType GetNthComponent(int c) const { return this->operator[](c); }
169 
171  void SetNthComponent(int c, const ComponentType & v) { this->operator[](c) = v; }
172 
174  ValueType & operator()(unsigned int row, unsigned int col);
175 
176  const ValueType & operator()(unsigned int row, unsigned int col) const;
177 
180  void SetIdentity();
181 
183  AccumulateValueType GetTrace() const;
184 
186  void ComputeEigenValues(EigenValuesArrayType & eigenValues) const;
187 
190  void ComputeEigenAnalysis(EigenValuesArrayType & eigenValues,
191  EigenVectorsMatrixType & eigenVectors) const;
192 
196  template<typename TMatrixValueType>
197  Self Rotate( const Matrix<TMatrixValueType, NDimension, NDimension> & m) const;
198  template<typename TMatrixValueType>
199  Self Rotate( const vnl_matrix_fixed<TMatrixValueType, NDimension, NDimension> & m) const
200  {
201  return this->Rotate( static_cast<Matrix<TMatrixValueType, NDimension, NDimension> >(m) );
202  }
203  template<typename TMatrixValueType>
204  Self Rotate( const vnl_matrix<TMatrixValueType> & m) const
205  {
206  return this->Rotate( static_cast<Matrix<TMatrixValueType> >(m) );
207  }
209 
211  MatrixType PreMultiply(const MatrixType & m) const;
212 
214  MatrixType PostMultiply(const MatrixType & m) const;
215 
216 private:
217 };
218 
221 using OutputStreamType = std::ostream;
222 using InputStreamType = std::istream;
223 
224 template< typename TComponent, unsigned int NDimension >
227 
228 template< typename TComponent, unsigned int NDimension >
231 
232 template<typename T>
234 {
235  a.swap(b);
236 }
237 } // end namespace itk
238 
240 
241 #ifndef ITK_MANUAL_INSTANTIATION
242 #include "itkSymmetricSecondRankTensor.hxx"
243 #endif
244 
245 #endif
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:49
Self & operator=(const SymmetricSecondRankTensor< TCoordRepB, NDimension > &pa)
typename NumericTraits< ValueType >::RealType AccumulateValueType
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Define numeric traits for std::vector.
Represent a symmetric tensor of second rank.
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &v)
SymmetricSecondRankTensor(const ComponentArrayType r)
void SetNthComponent(int c, const ComponentType &v)
typename NumericTraits< ValueType >::RealType RealValueType
CovariantVector< T, NVectorDimension > operator*(const T &scalar, const CovariantVector< T, NVectorDimension > &v)
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:188
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:51
std::ostream OutputStreamType
SymmetricSecondRankTensor(const ComponentType &r)
void swap(Array< T > &a, Array< T > &b)
Definition: itkArray.h:211
ComponentType GetNthComponent(int c) const
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
std::istream InputStreamType
Self Rotate(const vnl_matrix_fixed< TMatrixValueType, NDimension, NDimension > &m) const
SymmetricSecondRankTensor(const SymmetricSecondRankTensor< TCoordRepB, NDimension > &pa)
Self Rotate(const vnl_matrix< TMatrixValueType > &m) const