File: itkGPUInterpolatorCopier.h

package info (click to toggle)
elastix 5.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 42,480 kB
  • sloc: cpp: 68,403; lisp: 4,118; python: 1,013; xml: 182; sh: 177; makefile: 33
file content (150 lines) | stat: -rw-r--r-- 6,101 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*=========================================================================
 *
 *  Copyright UMC Utrecht and contributors
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/
#ifndef itkGPUInterpolatorCopier_h
#define itkGPUInterpolatorCopier_h

#include "itkInterpolateImageFunction.h"
#include "itkGPUImage.h"

namespace itk
{
/** \class GPUInterpolatorCopier
 * \brief A helper class which creates an GPU interpolator which
 * is perfect copy of the CPU interpolator.
 *
 * This class is NOT a filter. Although it has an API similar to a filter, this class
 * is not intended to be used in a pipeline. Instead, the typical use will be like
 * it is illustrated in the following code:
 *
 * \code
 *  struct OCLImageDims
 *  {
 *   itkStaticConstMacro( Support1D, bool, true );
 *   itkStaticConstMacro( Support2D, bool, true );
 *   itkStaticConstMacro( Support3D, bool, true );
 *  };
 *
 *  using ImageType = itk::Image< short, 3 >;
 *  using OCLImageTypes = typelist::MakeTypeList< short, float >::Type;
 *  using InterpolatorType = itk::InterpolateImageFunction< ImageType, float >;
 *  using CopierType = itk::GPUInterpolatorCopier< OCLImageTypes, OCLImageDims, InterpolatorType, float >;
 *  auto copier = CopierType::New();
 *  copier->SetInputInterpolator(CPUInterpolator);
 *  copier->Update();
 *  TransformType::Pointer GPUInterpolator = copier->GetModifiableOutput();
 * \endcode
 *
 * Note that the Update() method must be called explicitly in the filter
 * that provides the input to the GPUInterpolatorCopier object. This is needed
 * because the GPUInterpolatorCopier is not a pipeline filter.
 *
 * \author Denis P. Shamonin and Marius Staring. Division of Image Processing,
 * Department of Radiology, Leiden, The Netherlands
 *
 * \note This work was funded by the Netherlands Organisation for
 * Scientific Research (NWO NRG-2010.02 and NWO 639.021.124).
 *
 * \ingroup GPUCommon
 */
template <typename TTypeList, typename NDimensions, typename TInterpolator, typename TOutputCoordRep>
class ITK_TEMPLATE_EXPORT GPUInterpolatorCopier : public Object
{
public:
  ITK_DISALLOW_COPY_AND_MOVE(GPUInterpolatorCopier);

  /** Standard class typedefs. */
  using Self = GPUInterpolatorCopier;
  using Superclass = Object;
  using Pointer = SmartPointer<Self>;
  using ConstPointer = SmartPointer<const Self>;

  /** Method for creation through the object factory. */
  itkNewMacro(Self);

  /** Run-time type information (and related methods). */
  itkTypeMacro(GPUInterpolatorCopier, Object);

  /** Type CPU definitions for the interpolator. */
  using CPUInterpolatorType = TInterpolator;
  using CPUInterpolatorConstPointer = typename CPUInterpolatorType::ConstPointer;
  using CPUInputImageType = typename CPUInterpolatorType::InputImageType;
  using CPUCoordRepType = typename CPUInterpolatorType::CoordRepType;
  using GPUCoordRepType = TOutputCoordRep;

  /** Typedef's for non explicit GPU interpolator definitions. */
  using GPUInterpolatorType = InterpolateImageFunction<CPUInputImageType, GPUCoordRepType>;
  using GPUInterpolatorPointer = typename GPUInterpolatorType::Pointer;
  using GPUInterpolatorConstPointer = typename GPUInterpolatorType::ConstPointer;

  /** Typedef's for explicit GPU interpolator definitions. */
  using CPUInputImagePixelType = typename CPUInputImageType::PixelType;
  using GPUInputImageType = itk::GPUImage<CPUInputImagePixelType, CPUInputImageType::ImageDimension>;
  using GPUExplicitInterpolatorType = InterpolateImageFunction<GPUInputImageType, GPUCoordRepType>;
  using GPUExplicitInterpolatorPointer = typename GPUExplicitInterpolatorType::Pointer;
  using GPUExplicitInterpolatorConstPointer = typename GPUExplicitInterpolatorType::ConstPointer;

  /** Get/Set the input interpolator. */
  itkSetConstObjectMacro(InputInterpolator, CPUInterpolatorType);

  /** Compute of the non explicit output interpolator. */
  itkGetModifiableObjectMacro(Output, GPUInterpolatorType);

  /** Compute of the explicit output interpolator.
   * This output should be used when ExplicitMode has been set to true. */
  itkGetModifiableObjectMacro(ExplicitOutput, GPUExplicitInterpolatorType);

  /** Get/Set the explicit mode. The default is true.
   * If the explicit mode has been set to false that means that early in the
   * code the factories has been created.
   * ObjectFactoryBase::RegisterFactory( GPUNearestNeighborInterpolateImageFunctionFactory::New() );
   * ObjectFactoryBase::RegisterFactory( GPULinearInterpolateImageFunctionFactory::New() );
   * ObjectFactoryBase::RegisterFactory( GPUBSplineInterpolateImageFunctionFactory::New() ); */
  itkGetConstMacro(ExplicitMode, bool);
  itkSetMacro(ExplicitMode, bool);

  /** Update method. */
  void
  Update();

#ifdef ITK_USE_CONCEPT_CHECKING
  // Begin concept checking
  itkConceptMacro(OutputCoordRepIsFloatingPointCheck, (Concept::IsFloatingPoint<TOutputCoordRep>));
  // End concept checking
#endif

protected:
  GPUInterpolatorCopier();
  ~GPUInterpolatorCopier() override = default;
  void
  PrintSelf(std::ostream & os, Indent indent) const override;

private:
  CPUInterpolatorConstPointer    m_InputInterpolator{};
  GPUInterpolatorPointer         m_Output{};
  GPUExplicitInterpolatorPointer m_ExplicitOutput{};
  ModifiedTimeType               m_InternalTransformTime{};
  bool                           m_ExplicitMode{};
};

} // end namespace itk

#ifndef ITK_MANUAL_INSTANTIATION
#  include "itkGPUInterpolatorCopier.hxx"
#endif

#endif /* itkGPUInterpolatorCopier_h */