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 itkVectorImageToImageMetricTraitsv4_h
19 #define itkVectorImageToImageMetricTraitsv4_h
20 
21 #include "itkImage.h"
22 #include "itkCovariantVector.h"
23 #include "itkObjectToObjectMetricBase.h"
24 #include "itkDefaultConvertPixelTraits.h"
25 #include "itkGradientRecursiveGaussianImageFilter.h"
26 #include "itkCentralDifferenceImageFunction.h"
27 
28 namespace itk
29 {
30 /** \class VectorImageToImageMetricTraitsv4
31  * \brief A simple structure holding type information for ImageToImageMetricv4 classes
32  *
33  * This class provides type information for class members and methods
34  * used in gradient calculation. This class is used for images with
35  * vector pixel types, including VectorImage. For images with scalar pixel types, see
36  * itkDefaultImageToImageMetricTraitsv4.
37  *
38  * \sa itkDefaultImageToImageMetricTraitsv4
39  *
40  * \ingroup ITKMetricsv4
41  */
42 template<
43   typename    TFixedImageType,
44   typename    TMovingImageType,
45   typename    TVirtualImageType,
46   unsigned int NumberOfComponents,
47   typename TCoordRep = typename ObjectToObjectMetricBase::CoordinateRepresentationType
48   >
49 class VectorImageToImageMetricTraitsv4
50 {
51 public:
52   /** Standard class type aliases. */
53   using Self = VectorImageToImageMetricTraitsv4;
54 
55   using FixedImageType = TFixedImageType;
56   using MovingImageType = TMovingImageType;
57   using VirtualImageType = TVirtualImageType;
58 
59   using FixedImagePixelType = typename FixedImageType::PixelType;
60   using MovingImagePixelType = typename MovingImageType::PixelType;
61 
62   using CoordinateRepresentationType = TCoordRep;
63 
64   /* Image dimension accessors */
65   using ImageDimensionType = unsigned int;
66   static constexpr ImageDimensionType FixedImageDimension = FixedImageType::ImageDimension;
67   static constexpr ImageDimensionType MovingImageDimension = MovingImageType::ImageDimension;
68   static constexpr ImageDimensionType VirtualImageDimension = VirtualImageType::ImageDimension;
69 
70   using FixedImageGradientType = Vector< CoordinateRepresentationType, FixedImageDimension*NumberOfComponents >;
71   using MovingImageGradientType = Vector< CoordinateRepresentationType, MovingImageDimension*NumberOfComponents >;
72   using VirtualImageGradientType = Vector< CoordinateRepresentationType, VirtualImageDimension*NumberOfComponents >;
73 
74   using FixedImageGradientConvertType = DefaultConvertPixelTraits< FixedImageGradientType >;
75   using MovingImageGradientConvertType = DefaultConvertPixelTraits< MovingImageGradientType >;
76 
77   /** Type of the filter used to calculate the gradients. */
78   using FixedRealType = typename NumericTraits< FixedImagePixelType >::RealType;
79   using MovingRealType = typename NumericTraits< MovingImagePixelType >::RealType;
80 
81   using FixedGradientPixelType = FixedImageGradientType;
82   using MovingGradientPixelType = MovingImageGradientType;
83 
84   using FixedImageGradientImageType = Image< FixedGradientPixelType,
85                  Self::FixedImageDimension >;
86 
87   using FixedImageGradientFilterType =
88       ImageToImageFilter< FixedImageType, FixedImageGradientImageType >;
89 
90   using MovingImageGradientImageType = Image< MovingGradientPixelType,
91                  Self::MovingImageDimension >;
92 
93   using MovingImageGradientFilterType =
94       ImageToImageFilter< MovingImageType, MovingImageGradientImageType >;
95 
96   using FixedImageComponentGradientType = CovariantVector<CoordinateRepresentationType, FixedImageDimension>;
97   using MovingImageComponentGradientType = CovariantVector<CoordinateRepresentationType, MovingImageDimension>;
98   using VirtualImageComponentGradientType = CovariantVector<CoordinateRepresentationType, VirtualImageDimension>;
99 
100   /** Default image gradient filter types */
101   using DefaultFixedImageGradientFilter = GradientRecursiveGaussianImageFilter< FixedImageType,
102                                                 FixedImageGradientImageType >;
103   using DefaultMovingImageGradientFilter = GradientRecursiveGaussianImageFilter< MovingImageType,
104                                                 MovingImageGradientImageType >;
105 
106   /** Image gradient calculator types. The TOutput template parameter
107    * is chosen to match that of CentralDiffererenceImageFunction. */
108   using FixedImageGradientCalculatorType = ImageFunction<FixedImageType,
109                         FixedImageGradientType,
110                         CoordinateRepresentationType>;
111   using MovingImageGradientCalculatorType = ImageFunction<MovingImageType,
112                         MovingImageGradientType,
113                         CoordinateRepresentationType>;
114 
115   using DefaultFixedImageGradientCalculator = CentralDifferenceImageFunction<FixedImageType,
116                                          CoordinateRepresentationType,
117                                          FixedImageGradientType>;
118   using DefaultMovingImageGradientCalculator = CentralDifferenceImageFunction<MovingImageType,
119                                          CoordinateRepresentationType,
120                                          MovingImageGradientType>;
121 };
122 } // end namespace itk
123 
124 #endif
125