ITK  5.3.0
Insight Toolkit
itkSymmetricSecondRankTensor.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 VDimension = 3>
75 class ITK_TEMPLATE_EXPORT SymmetricSecondRankTensor : public FixedArray<TComponent, VDimension *(VDimension + 1) / 2>
76 {
77 public:
80  using Superclass = FixedArray<TComponent, VDimension *(VDimension + 1) / 2>;
81 
83  static constexpr unsigned int Dimension = VDimension;
84  static constexpr unsigned int InternalDimension = VDimension * (VDimension + 1) / 2;
85 
88 
91 
95 
97  using ComponentType = TComponent;
98  using typename Superclass::ValueType;
101 
104 
107  SymmetricSecondRankTensor() { this->Fill(0); }
108 
109  SymmetricSecondRankTensor(const ComponentType & r) { this->Fill(r); }
110 
112  template <typename TCoordRepB>
114  : BaseArray(pa)
115  {}
116 
117  using ComponentArrayType = ComponentType[Self::InternalDimension];
118 
121  : BaseArray(r)
122  {}
123 
125  template <typename TCoordRepB>
126  Self &
128  {
129  BaseArray::operator=(pa);
130  return *this;
131  }
135  Self &
136  operator=(const ComponentType & r);
137 
138  Self &
139  operator=(const ComponentArrayType r);
140 
143  Self
144  operator+(const Self & r) const;
145 
146  Self
147  operator-(const Self & r) const;
148 
149  const Self &
150  operator+=(const Self & r);
151 
152  const Self &
153  operator-=(const Self & r);
154 
156  Self operator*(const RealValueType & r) const;
157 
158  Self
159  operator/(const RealValueType & r) const;
160 
161  const Self &
162  operator*=(const RealValueType & r);
163 
164  const Self &
165  operator/=(const RealValueType & r);
166 
168  static unsigned int
170  {
171  return Self::InternalDimension;
172  }
173 
175  ComponentType
176  GetNthComponent(int c) const
177  {
178  return this->operator[](c);
179  }
180 
182  void
183  SetNthComponent(int c, const ComponentType & v)
184  {
185  this->operator[](c) = v;
186  }
187 
189  ValueType &
190  operator()(unsigned int row, unsigned int col);
191 
192  const ValueType &
193  operator()(unsigned int row, unsigned int col) const;
194 
197  void
198  SetIdentity();
199 
201  AccumulateValueType
202  GetTrace() const;
203 
205  void
206  ComputeEigenValues(EigenValuesArrayType & eigenValues) const;
207 
210  void
211  ComputeEigenAnalysis(EigenValuesArrayType & eigenValues, EigenVectorsMatrixType & eigenVectors) const;
212 
216  template <typename TMatrixValueType>
217  Self
218  Rotate(const Matrix<TMatrixValueType, VDimension, VDimension> & m) const;
219  template <typename TMatrixValueType>
220  Self
221  Rotate(const vnl_matrix_fixed<TMatrixValueType, VDimension, VDimension> & m) const
222  {
223  return this->Rotate(static_cast<Matrix<TMatrixValueType, VDimension, VDimension>>(m));
224  }
225  template <typename TMatrixValueType>
226  Self
227  Rotate(const vnl_matrix<TMatrixValueType> & m) const
228  {
229  return this->Rotate(static_cast<Matrix<TMatrixValueType>>(m));
230  }
234  MatrixType
235  PreMultiply(const MatrixType & m) const;
236 
238  MatrixType
239  PostMultiply(const MatrixType & m) const;
240 
241 private:
242 };
243 
246 using OutputStreamType = std::ostream;
247 using InputStreamType = std::istream;
248 
249 template <typename TComponent, unsigned int VDimension>
252 
253 template <typename TComponent, unsigned int VDimension>
256 
257 template <typename T>
258 inline void
260 {
261  a.swap(b);
262 }
263 } // end namespace itk
264 
266 
267 #ifndef ITK_MANUAL_INSTANTIATION
268 # include "itkSymmetricSecondRankTensor.hxx"
269 #endif
270 
271 #endif
itk::OutputStreamType
std::ostream OutputStreamType
Definition: itkSymmetricSecondRankTensor.h:246
itk::SymmetricSecondRankTensor::SymmetricSecondRankTensor
SymmetricSecondRankTensor()
Definition: itkSymmetricSecondRankTensor.h:107
itk::SymmetricSecondRankTensor::Rotate
Self Rotate(const vnl_matrix< TMatrixValueType > &m) const
Definition: itkSymmetricSecondRankTensor.h:227
itkMatrix.h
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:216
itk::operator*
CovariantVector< T, VVectorDimension > operator*(const T &scalar, const CovariantVector< T, VVectorDimension > &v)
Definition: itkCovariantVector.h:268
itk::SymmetricSecondRankTensor::GetNthComponent
ComponentType GetNthComponent(int c) const
Definition: itkSymmetricSecondRankTensor.h:176
itk::swap
void swap(Array< T > &a, Array< T > &b)
Definition: itkArray.h:242
itk::operator-
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Definition: itkConstNeighborhoodIterator.h:672
itkSymmetricEigenAnalysis.h
itk::SymmetricSecondRankTensor::SymmetricSecondRankTensor
SymmetricSecondRankTensor(const SymmetricSecondRankTensor< TCoordRepB, VDimension > &pa)
Definition: itkSymmetricSecondRankTensor.h:113
itkNumericTraitsTensorPixel.h
itk::SymmetricSecondRankTensor::Rotate
Self Rotate(const vnl_matrix_fixed< TMatrixValueType, VDimension, VDimension > &m) const
Definition: itkSymmetricSecondRankTensor.h:221
itk::SymmetricSecondRankTensor
Represent a symmetric tensor of second rank.
Definition: itkSymmetricSecondRankTensor.h:75
itk::SymmetricSecondRankTensor::SetNthComponent
void SetNthComponent(int c, const ComponentType &v)
Definition: itkSymmetricSecondRankTensor.h:183
itk::SymmetricSecondRankTensor< TComponent, 3 >::RealValueType
typename NumericTraits< ValueType >::RealType RealValueType
Definition: itkSymmetricSecondRankTensor.h:100
itk::SymmetricSecondRankTensor::operator=
Self & operator=(const SymmetricSecondRankTensor< TCoordRepB, VDimension > &pa)
Definition: itkSymmetricSecondRankTensor.h:127
itkIndent.h
itk::SymmetricSecondRankTensor::GetNumberOfComponents
static unsigned int GetNumberOfComponents()
Definition: itkSymmetricSecondRankTensor.h:169
itkFixedArray.h
itk::SymmetricSecondRankTensor< TComponent, 3 >::ComponentArrayType
ComponentType[Self::InternalDimension] ComponentArrayType
Definition: itkSymmetricSecondRankTensor.h:117
itk::SymmetricSecondRankTensor::SymmetricSecondRankTensor
SymmetricSecondRankTensor(const ComponentType &r)
Definition: itkSymmetricSecondRankTensor.h:109
itk::SymmetricSecondRankTensor< TComponent, 3 >::ComponentType
TComponent ComponentType
Definition: itkSymmetricSecondRankTensor.h:97
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:53
itk::Matrix
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:52
itk::SymmetricSecondRankTensor< TComponent, 3 >::AccumulateValueType
typename NumericTraits< ValueType >::RealType AccumulateValueType
Definition: itkSymmetricSecondRankTensor.h:99
itk::SymmetricEigenAnalysisFixedDimension
Definition: itkSymmetricEigenAnalysis.h:758
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::InputStreamType
std::istream InputStreamType
Definition: itkSymmetricSecondRankTensor.h:247
itk::FixedArray< TComponent, VDimension *(VDimension+1)/2 >::swap
void swap(FixedArray &other)
Definition: itkFixedArray.h:416
itk::operator+
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Definition: itkConstNeighborhoodIterator.h:654
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:84
AddImageFilter
Definition: itkAddImageFilter.h:80
itk::SymmetricSecondRankTensor::SymmetricSecondRankTensor
SymmetricSecondRankTensor(const ComponentArrayType r)
Definition: itkSymmetricSecondRankTensor.h:120
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itk::operator>>
std::istream & operator>>(std::istream &is, Point< T, VPointDimension > &vct)
itk::FixedArray< TComponent, VDimension *(VDimension+1)/2 >::ValueType
TComponent ValueType
Definition: itkFixedArray.h:63