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 itkDemonsImageToImageMetricv4GetValueAndDerivativeThreader_h
19 #define itkDemonsImageToImageMetricv4GetValueAndDerivativeThreader_h
20 
21 #include "itkImageToImageMetricv4GetValueAndDerivativeThreader.h"
22 
23 namespace itk
24 {
25 
26 /** \class DemonsImageToImageMetricv4GetValueAndDerivativeThreader
27  * \brief Processes points for DemonsImageToImageMetricv4 \c
28  * GetValueAndDerivative.
29  *
30  * \ingroup ITKMetricsv4
31  */
32 template < typename TDomainPartitioner, typename TImageToImageMetric, typename TDemonsMetric >
33 class ITK_TEMPLATE_EXPORT DemonsImageToImageMetricv4GetValueAndDerivativeThreader
34   : public ImageToImageMetricv4GetValueAndDerivativeThreader< TDomainPartitioner, TImageToImageMetric >
35 {
36 public:
37   ITK_DISALLOW_COPY_AND_ASSIGN(DemonsImageToImageMetricv4GetValueAndDerivativeThreader);
38 
39   /** Standard class type aliases. */
40   using Self = DemonsImageToImageMetricv4GetValueAndDerivativeThreader;
41   using Superclass = ImageToImageMetricv4GetValueAndDerivativeThreader< TDomainPartitioner, TImageToImageMetric >;
42   using Pointer = SmartPointer< Self >;
43   using ConstPointer = SmartPointer< const Self >;
44 
45   itkTypeMacro( DemonsImageToImageMetricv4GetValueAndDerivativeThreader, ImageToImageMetricv4GetValueAndDerivativeThreader );
46 
47   itkNewMacro( Self );
48 
49   using DomainType = typename Superclass::DomainType;
50   using AssociateType = typename Superclass::AssociateType;
51 
52   using ImageToImageMetricv4Type = typename Superclass::ImageToImageMetricv4Type;
53   using VirtualPointType = typename Superclass::VirtualPointType;
54   using VirtualIndexType = typename Superclass::VirtualIndexType;
55   using FixedImagePointType = typename Superclass::FixedImagePointType;
56   using FixedImagePixelType = typename Superclass::FixedImagePixelType;
57   using FixedImageGradientType = typename Superclass::FixedImageGradientType;
58   using MovingImagePointType = typename Superclass::MovingImagePointType;
59   using MovingImagePixelType = typename Superclass::MovingImagePixelType;
60   using MovingImageGradientType = typename Superclass::MovingImageGradientType;
61   using MeasureType = typename Superclass::MeasureType;
62   using DerivativeType = typename Superclass::DerivativeType;
63   using DerivativeValueType = typename Superclass::DerivativeValueType;
64   using InternalComputationValueType = typename Superclass::InternalComputationValueType;
65   using NumberOfParametersType = typename Superclass::NumberOfParametersType;
66   using ImageDimensionType = typename Superclass::ImageDimensionType;
67 
68 protected:
DemonsImageToImageMetricv4GetValueAndDerivativeThreader()69   DemonsImageToImageMetricv4GetValueAndDerivativeThreader() :
70     m_DemonsAssociate(nullptr)
71   {}
72 
73   /** Overload.
74    *  Get pointer to metric object.
75    */
76   void BeforeThreadedExecution() override;
77 
78   /** This function computes the local voxel-wise contribution of
79    *  the metric to the global integral of the metric/derivative.
80    */
81   bool ProcessPoint(
82         const VirtualIndexType &          virtualIndex,
83         const VirtualPointType &          virtualPoint,
84         const FixedImagePointType &       mappedFixedPoint,
85         const FixedImagePixelType &       mappedFixedPixelValue,
86         const FixedImageGradientType &    mappedFixedImageGradient,
87         const MovingImagePointType &      mappedMovingPoint,
88         const MovingImagePixelType &      mappedMovingPixelValue,
89         const MovingImageGradientType &   mappedMovingImageGradient,
90         MeasureType &                     metricValueReturn,
91         DerivativeType &                  localDerivativeReturn,
92         const ThreadIdType                threadId ) const override;
93 
94 private:
95   /** Internal pointer to the Mattes metric object in use by this threader.
96    *  This will avoid costly dynamic casting in tight loops. */
97   TDemonsMetric * m_DemonsAssociate;
98 };
99 
100 } // end namespace itk
101 
102 #ifndef ITK_MANUAL_INSTANTIATION
103 #include "itkDemonsImageToImageMetricv4GetValueAndDerivativeThreader.hxx"
104 #endif
105 
106 #endif
107