ITK  5.2.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  * 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 FixedArray<TComponent, NDimension *(NDimension + 1) / 2>
76 {
77 public:
80  using Superclass = FixedArray<TComponent, NDimension *(NDimension + 1) / 2>;
81 
83  static constexpr unsigned int Dimension = NDimension;
84  static constexpr unsigned int InternalDimension = NDimension * (NDimension + 1) / 2;
85 
88 
91 
95 
97  using ComponentType = TComponent;
98  using ValueType = typename Superclass::ValueType;
101 
104 
106  SymmetricSecondRankTensor() { this->Fill(0); }
110  operator=(const SymmetricSecondRankTensor &) = default;
112  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 
124  using ComponentArrayType = ComponentType[Self::InternalDimension];
125 
128  : BaseArray(r)
129  {}
130 
132  template <typename TCoordRepB>
133  Self &
135  {
136  BaseArray::operator=(pa);
137  return *this;
138  }
140 
142  Self &
143  operator=(const ComponentType & r);
144 
145  Self &
146  operator=(const ComponentArrayType r);
147 
150  Self
151  operator+(const Self & vec) const;
152 
153  Self
154  operator-(const Self & vec) const;
155 
156  const Self &
157  operator+=(const Self & vec);
158 
159  const Self &
160  operator-=(const Self & vec);
161 
163  Self operator*(const RealValueType & scalar) const;
164 
165  Self
166  operator/(const RealValueType & scalar) const;
167 
168  const Self &
169  operator*=(const RealValueType & scalar);
170 
171  const Self &
172  operator/=(const RealValueType & scalar);
173 
175  static unsigned int
177  {
178  return Self::InternalDimension;
179  }
180 
182  ComponentType
183  GetNthComponent(int c) const
184  {
185  return this->operator[](c);
186  }
187 
189  void
190  SetNthComponent(int c, const ComponentType & v)
191  {
192  this->operator[](c) = v;
193  }
194 
196  ValueType &
197  operator()(unsigned int row, unsigned int col);
198 
199  const ValueType &
200  operator()(unsigned int row, unsigned int col) const;
201 
204  void
205  SetIdentity();
206 
208  AccumulateValueType
209  GetTrace() const;
210 
212  void
213  ComputeEigenValues(EigenValuesArrayType & eigenValues) const;
214 
217  void
218  ComputeEigenAnalysis(EigenValuesArrayType & eigenValues, EigenVectorsMatrixType & eigenVectors) const;
219 
223  template <typename TMatrixValueType>
224  Self
225  Rotate(const Matrix<TMatrixValueType, NDimension, NDimension> & m) const;
226  template <typename TMatrixValueType>
227  Self
228  Rotate(const vnl_matrix_fixed<TMatrixValueType, NDimension, NDimension> & m) const
229  {
230  return this->Rotate(static_cast<Matrix<TMatrixValueType, NDimension, NDimension>>(m));
231  }
232  template <typename TMatrixValueType>
233  Self
234  Rotate(const vnl_matrix<TMatrixValueType> & m) const
235  {
236  return this->Rotate(static_cast<Matrix<TMatrixValueType>>(m));
237  }
239 
241  MatrixType
242  PreMultiply(const MatrixType & m) const;
243 
245  MatrixType
246  PostMultiply(const MatrixType & m) const;
247 
248 private:
249 };
250 
253 using OutputStreamType = std::ostream;
254 using InputStreamType = std::istream;
255 
256 template <typename TComponent, unsigned int NDimension>
259 
260 template <typename TComponent, unsigned int NDimension>
263 
264 template <typename T>
265 inline void
267 {
268  a.swap(b);
269 }
270 } // end namespace itk
271 
273 
274 #ifndef ITK_MANUAL_INSTANTIATION
275 # include "itkSymmetricSecondRankTensor.hxx"
276 #endif
277 
278 #endif
itk::SymmetricSecondRankTensor< TComponent, 3 >::ComponentArrayType
ComponentType[Self::InternalDimension] ComponentArrayType
Definition: itkSymmetricSecondRankTensor.h:124
itk::SymmetricSecondRankTensor::operator=
Self & operator=(const SymmetricSecondRankTensor< TCoordRepB, NDimension > &pa)
Definition: itkSymmetricSecondRankTensor.h:134
itk::OutputStreamType
std::ostream OutputStreamType
Definition: itkSymmetricSecondRankTensor.h:253
itkMatrix.h
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:213
itk::SymmetricSecondRankTensor< TComponent, 3 >::AccumulateValueType
typename NumericTraits< ValueType >::RealType AccumulateValueType
Definition: itkSymmetricSecondRankTensor.h:99
itk::SymmetricSecondRankTensor::SymmetricSecondRankTensor
SymmetricSecondRankTensor(const ComponentArrayType r)
Definition: itkSymmetricSecondRankTensor.h:127
itk::SymmetricSecondRankTensor::SymmetricSecondRankTensor
SymmetricSecondRankTensor(const SymmetricSecondRankTensor< TCoordRepB, NDimension > &pa)
Definition: itkSymmetricSecondRankTensor.h:120
itk::swap
void swap(Array< T > &a, Array< T > &b)
Definition: itkArray.h:239
itk::operator-
ConstNeighborhoodIterator< TImage > operator-(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Definition: itkConstNeighborhoodIterator.h:678
itk::SymmetricSecondRankTensor::SymmetricSecondRankTensor
SymmetricSecondRankTensor()
Definition: itkSymmetricSecondRankTensor.h:106
itk::SymmetricSecondRankTensor::GetNumberOfComponents
static unsigned int GetNumberOfComponents()
Definition: itkSymmetricSecondRankTensor.h:176
itkSymmetricEigenAnalysis.h
itk::SymmetricSecondRankTensor::SymmetricSecondRankTensor
SymmetricSecondRankTensor(const ComponentType &r)
Definition: itkSymmetricSecondRankTensor.h:116
itkNumericTraitsTensorPixel.h
itk::SymmetricSecondRankTensor
Represent a symmetric tensor of second rank.
Definition: itkSymmetricSecondRankTensor.h:75
itkIndent.h
itk::SymmetricSecondRankTensor::SetNthComponent
void SetNthComponent(int c, const ComponentType &v)
Definition: itkSymmetricSecondRankTensor.h:190
itkFixedArray.h
itk::SymmetricSecondRankTensor::Rotate
Self Rotate(const vnl_matrix< TMatrixValueType > &m) const
Definition: itkSymmetricSecondRankTensor.h:234
itk::SymmetricSecondRankTensor< TComponent, 3 >::ComponentType
TComponent ComponentType
Definition: itkSymmetricSecondRankTensor.h:97
itk::SymmetricSecondRankTensor::Rotate
Self Rotate(const vnl_matrix_fixed< TMatrixValueType, NDimension, NDimension > &m) const
Definition: itkSymmetricSecondRankTensor.h:228
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:52
itk::Matrix
A templated class holding a M x N size Matrix.
Definition: itkMatrix.h:51
itk::operator*
CovariantVector< T, NVectorDimension > operator*(const T &scalar, const CovariantVector< T, NVectorDimension > &v)
Definition: itkCovariantVector.h:275
itk::SymmetricSecondRankTensor::GetNthComponent
ComponentType GetNthComponent(int c) const
Definition: itkSymmetricSecondRankTensor.h:183
itk::SymmetricSecondRankTensor< TComponent, 3 >::RealValueType
typename NumericTraits< ValueType >::RealType RealValueType
Definition: itkSymmetricSecondRankTensor.h:100
itk::SymmetricEigenAnalysisFixedDimension
Definition: itkSymmetricEigenAnalysis.h:762
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:254
itk::FixedArray< TComponent, NDimension *(NDimension+1)/2 >::swap
void swap(FixedArray &other)
Definition: itkFixedArray.h:441
itk::operator+
ConstNeighborhoodIterator< TImage > operator+(const ConstNeighborhoodIterator< TImage > &it, const typename ConstNeighborhoodIterator< TImage >::OffsetType &ind)
Definition: itkConstNeighborhoodIterator.h:660
itk::operator>>
std::istream & operator>>(std::istream &is, Point< T, NPointDimension > &v)
itk::NumericTraits::RealType
double RealType
Definition: itkNumericTraits.h:84
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itk::FixedArray< TComponent, NDimension *(NDimension+1)/2 >::ValueType
TComponent ValueType
Definition: itkFixedArray.h:62