ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkDirectionAlgorithm.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 itkDirectionAlgorithm_h
19#define itkDirectionAlgorithm_h
20
21#include "itkFixedArray.h"
22#include "itkMatrix.h"
24#include "ITKCommonExport.h"
25#include "itk_eigen.h"
26#include ITK_EIGEN(Core)
27
28#include <cstdint>
29#include <ostream>
30#include <vector>
31
32namespace itk
33{
34
56
58extern ITKCommon_EXPORT std::ostream &
60
67struct ITKCommon_EXPORT DirectionAlgorithm
68{
70
84 template <unsigned int VOutputDimension, typename TValue, unsigned int VInputDimension>
87 const FixedArray<bool, VInputDimension> & collapseDimensions,
88 const CollapseStrategyEnum strategy)
89 {
90 const Eigen::Map<const RowMajorMatrix<TValue>> directionView(
91 direction.GetVnlMatrix().data_block(), VInputDimension, VInputDimension);
92 const Eigen::Map<const FlagArray> collapseView(collapseDimensions.data(), VInputDimension);
94 Eigen::Map<RowMajorMatrix<TValue>> resultView(
95 result.GetVnlMatrix().data_block(), VOutputDimension, VOutputDimension);
96 CollapseDirectionInternal(directionView.template cast<double>(), collapseView, strategy, resultView);
97 return result;
98 }
99
102 template <unsigned int VOutputDimension, typename TValue = double>
105 const std::vector<bool> & collapseDimensions,
106 const CollapseStrategyEnum strategy)
107 {
108 const auto & vnlDirection = direction.GetVnlMatrix();
109 const Eigen::Map<const RowMajorMatrix<double>> directionView(
110 vnlDirection.data_block(), vnlDirection.rows(), vnlDirection.cols());
111 FlagArray collapseFlags(collapseDimensions.size());
112 for (size_t i = 0; i < collapseDimensions.size(); ++i)
113 {
114 collapseFlags[i] = collapseDimensions[i];
115 }
117 Eigen::Map<RowMajorMatrix<TValue>> resultView(
118 result.GetVnlMatrix().data_block(), VOutputDimension, VOutputDimension);
119 CollapseDirectionInternal(directionView, collapseFlags, strategy, resultView);
120 return result;
121 }
122
123private:
124 template <typename TValue>
125 using RowMajorMatrix = Eigen::Matrix<TValue, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
126 using FlagArray = Eigen::Array<bool, Eigen::Dynamic, 1>;
127
128 static void
129 CollapseDirectionInternal(const Eigen::Ref<const RowMajorMatrix<double>> & direction,
130 const Eigen::Ref<const FlagArray> & collapseDimensions,
131 CollapseStrategyEnum strategy,
132 Eigen::Ref<RowMajorMatrix<double>> result);
133 static void
134 CollapseDirectionInternal(const Eigen::Ref<const RowMajorMatrix<double>> & direction,
135 const Eigen::Ref<const FlagArray> & collapseDimensions,
136 CollapseStrategyEnum strategy,
137 Eigen::Ref<RowMajorMatrix<float>> result);
138};
139
140} // namespace itk
141
142#endif
enums for itk::ExtractImageFilter
Simulate a standard C array with copy semantics.
ValueType * data()
A templated class holding a M x N size Matrix.
Definition itkMatrix.h:71
InternalMatrixType & GetVnlMatrix()
Definition itkMatrix.h:232
A templated class holding a M x N size Matrix.
InternalMatrixType & GetVnlMatrix()
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, AnatomicalOrientation::CoordinateEnum value)
Functions that operate on image direction matrices.
static Matrix< TValue, VOutputDimension, VOutputDimension > CollapseDirection(const VariableSizeMatrix< double > &direction, const std::vector< bool > &collapseDimensions, const CollapseStrategyEnum strategy)
Eigen::Array< bool, Eigen::Dynamic, 1 > FlagArray
static void CollapseDirectionInternal(const Eigen::Ref< const RowMajorMatrix< double > > &direction, const Eigen::Ref< const FlagArray > &collapseDimensions, CollapseStrategyEnum strategy, Eigen::Ref< RowMajorMatrix< double > > result)
ExtractImageFilterEnums::DirectionCollapseStrategy CollapseStrategyEnum
Eigen::Matrix< TValue, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > RowMajorMatrix
static void CollapseDirectionInternal(const Eigen::Ref< const RowMajorMatrix< double > > &direction, const Eigen::Ref< const FlagArray > &collapseDimensions, CollapseStrategyEnum strategy, Eigen::Ref< RowMajorMatrix< float > > result)
static Matrix< TValue, VOutputDimension, VOutputDimension > CollapseDirection(const Matrix< TValue, VInputDimension, VInputDimension > &direction, const FixedArray< bool, VInputDimension > &collapseDimensions, const CollapseStrategyEnum strategy)