ITK  5.2.0
Insight Toolkit
itkGPUFiniteDifferenceImageFilter.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 itkGPUFiniteDifferenceImageFilter_h
19 #define itkGPUFiniteDifferenceImageFilter_h
20 
24 #include "itkTimeProbe.h"
26 
27 namespace itk
28 {
29 
37 template <typename TInputImage,
38  typename TOutputImage,
39  typename TParentImageFilter = FiniteDifferenceImageFilter<TInputImage, TOutputImage>>
40 class ITK_TEMPLATE_EXPORT GPUFiniteDifferenceImageFilter
41  : public GPUInPlaceImageFilter<TInputImage, TOutputImage, TParentImageFilter>
42 {
43 public:
44  ITK_DISALLOW_COPY_AND_MOVE(GPUFiniteDifferenceImageFilter);
45 
49  using CPUSuperclass = TParentImageFilter;
52 
55 
57  using InputImageType = TInputImage;
58  using OutputImageType = TOutputImage;
59 
61  static constexpr unsigned int ImageDimension = OutputImageType::ImageDimension;
62 
64  using OutputPixelType = typename TOutputImage::PixelType;
65  using InputPixelType = typename TInputImage::PixelType;
67 
71 
76  using TimeStepType = typename FiniteDifferenceFunctionType::TimeStepType;
77  using RadiusType = typename FiniteDifferenceFunctionType::RadiusType;
78  using NeighborhoodScalesType = typename FiniteDifferenceFunctionType::NeighborhoodScalesType;
79 
83  const typename FiniteDifferenceFunctionType::Pointer &
84  GetDifferenceFunction() const override
85  {
86  return this->m_DifferenceFunction;
87  }
88 
92  void
93  SetDifferenceFunction(FiniteDifferenceFunctionType * differenceFunction) override
94  {
95  itkDebugMacro("setting m_DifferenceFunction to " << differenceFunction);
96  if (this->m_DifferenceFunction != differenceFunction)
97  {
98  this->m_DifferenceFunction = differenceFunction;
99  this->Modified();
100  }
101  }
103 
104 #if !defined(ITK_LEGACY_REMOVE)
105 
106  using FilterStateType = GPUFiniteDifferenceFilterEnum;
107  // We need to expose the enum values at the class level for backwards compatibility
110 #endif
111 
113  void
115  {
117  }
118 
120  void
122  {
124  }
125 
127 #if !defined(ITK_WRAPPING_PARSER)
128  itkSetMacro(State, GPUFiniteDifferenceFilterEnum);
129  itkGetConstReferenceMacro(State, GPUFiniteDifferenceFilterEnum);
130 #endif
131 
132 
133 #ifdef ITK_USE_CONCEPT_CHECKING
134  // Begin concept checking
135  itkConceptMacro(OutputPixelIsFloatingPointCheck, (Concept::IsFloatingPoint<OutputPixelValueType>));
136  // End concept checking
137 #endif
138 
140  itkGetConstReferenceMacro(InitTime, TimeProbe);
141  itkGetConstReferenceMacro(ComputeUpdateTime, TimeProbe);
142  itkGetConstReferenceMacro(ApplyUpdateTime, TimeProbe);
143  itkGetConstReferenceMacro(SmoothFieldTime, TimeProbe);
145 
146 protected:
148  ~GPUFiniteDifferenceImageFilter() override;
149 
150  void
151  PrintSelf(std::ostream & os, Indent indent) const override;
152 
154  void
155  AllocateUpdateBuffer() override = 0;
156 
160  virtual void
161  GPUApplyUpdate(const TimeStepType & dt) = 0;
162 
168  virtual TimeStepType
169  GPUCalculateChange() = 0;
170 
174  void
175  CopyInputToOutput() override = 0;
176 
180  void
181  GPUGenerateData() override;
182 
194  void
195  GenerateInputRequestedRegion() override;
196 
199  bool
200  Halt() override;
201 
211  bool
212  ThreadedHalt(void * itkNotUsed(threadInfo)) override
213  {
214  return this->Halt();
215  }
216 
222  void
223  Initialize() override
224  {}
225 
232  void
234  {
235  m_DifferenceFunction->InitializeIteration();
236  }
237 
250  TimeStepType
251  ResolveTimeStep(const std::vector<TimeStepType> & timeStepList, const std::vector<bool> & valid) const override;
252 
255  void
256  PostProcessOutput() override
257  {}
258 
260  TimeProbe m_InitTime, m_ComputeUpdateTime, m_ApplyUpdateTime, m_SmoothFieldTime;
261 
262 private:
266  void
267  InitializeFunctionCoefficients();
268 
270  typename FiniteDifferenceFunctionType::Pointer m_DifferenceFunction;
271 
275 
278 };
279 
280 } // end namespace itk
281 
282 #ifndef ITK_MANUAL_INSTANTIATION
283 # include "itkGPUFiniteDifferenceImageFilter.hxx"
284 #endif
285 
286 #endif
itk::GPUFiniteDifferenceImageFilter::SetStateToInitialized
void SetStateToInitialized()
Definition: itkGPUFiniteDifferenceImageFilter.h:114
itk::GPUInPlaceImageFilter< TDisplacementField, TDisplacementField, TParentImageFilter >::OutputImageType
typename GPUSuperclass::OutputImageType OutputImageType
Definition: itkGPUInPlaceImageFilter.h:56
itkFiniteDifferenceImageFilter.h
itk::GPUFiniteDifferenceImageFilter::InitializeIteration
void InitializeIteration() override
Definition: itkGPUFiniteDifferenceImageFilter.h:233
itk::GPUFiniteDifferenceImageFilter::m_DifferenceFunction
FiniteDifferenceFunctionType::Pointer m_DifferenceFunction
Definition: itkGPUFiniteDifferenceImageFilter.h:270
itkTimeProbe.h
itk::GPUFiniteDifferenceImageFilter::ThreadedHalt
bool ThreadedHalt(void *) override
Definition: itkGPUFiniteDifferenceImageFilter.h:212
itkGPUFiniteDifferenceFunction.h
itk::GPUInPlaceImageFilter
Base class for GPU filters that take an image as input and overwrite that image as the output.
Definition: itkGPUInPlaceImageFilter.h:39
itk::GPUFiniteDifferenceImageFilter::m_SmoothFieldTime
TimeProbe m_SmoothFieldTime
Definition: itkGPUFiniteDifferenceImageFilter.h:260
itk::GPUFiniteDifferenceImageFilter< TDisplacementField, TDisplacementField, TParentImageFilter >::PixelType
OutputPixelType PixelType
Definition: itkGPUFiniteDifferenceImageFilter.h:66
itk::GPUFiniteDifferenceImageFilter< TDisplacementField, TDisplacementField, TParentImageFilter >::OutputPixelType
typename TDisplacementField ::PixelType OutputPixelType
Definition: itkGPUFiniteDifferenceImageFilter.h:64
itk::GPUFiniteDifferenceImageFilter::PostProcessOutput
void PostProcessOutput() override
Definition: itkGPUFiniteDifferenceImageFilter.h:256
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::GPUFiniteDifferenceImageFilter< TDisplacementField, TDisplacementField, TParentImageFilter >::RadiusType
typename FiniteDifferenceFunctionType::RadiusType RadiusType
Definition: itkGPUFiniteDifferenceImageFilter.h:77
itk::GPUFiniteDifferenceImageFilter::Initialize
void Initialize() override
Definition: itkGPUFiniteDifferenceImageFilter.h:223
itk::GPUFiniteDifferenceImageFilter
Base class for GPU Finite Difference Image Filters.
Definition: itkGPUFiniteDifferenceImageFilter.h:40
GPUFiniteDifferenceFilterEnum
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::GPUImageToImageFilter< TDisplacementField, TDisplacementField, TParentImageFilter >::InputImageType
TDisplacementField InputImageType
Definition: itkGPUImageToImageFilter.h:63
itk::GPUFiniteDifferenceImageFilter< TDisplacementField, TDisplacementField, TParentImageFilter >::NeighborhoodScalesType
typename FiniteDifferenceFunctionType::NeighborhoodScalesType NeighborhoodScalesType
Definition: itkGPUFiniteDifferenceImageFilter.h:78
itk::GPUFiniteDifferenceFilterEnum
GPUFiniteDifferenceFilterEnum
Definition: itkGPUFiniteDifferenceFilterEnum.h:30
itk::GPUFiniteDifferenceImageFilter< TDisplacementField, TDisplacementField, TParentImageFilter >::FiniteDifferenceFunctionType
typename GPUFiniteDifferenceFunction< TDisplacementField >::DifferenceFunctionType FiniteDifferenceFunctionType
Definition: itkGPUFiniteDifferenceImageFilter.h:75
itk::GPUFiniteDifferenceImageFilter< TDisplacementField, TDisplacementField, TParentImageFilter >::InputPixelType
typename TDisplacementField ::PixelType InputPixelType
Definition: itkGPUFiniteDifferenceImageFilter.h:65
itk::TimeProbe
Computes the time passed between two points in code.
Definition: itkTimeProbe.h:44
itk::GPUFiniteDifferenceImageFilter::SetStateToUninitialized
void SetStateToUninitialized()
Definition: itkGPUFiniteDifferenceImageFilter.h:121
itk::Concept::IsFloatingPoint
Definition: itkConceptChecking.h:946
itk::GPUImageToImageFilter
class to abstract the behaviour of the GPU filters.
Definition: itkGPUImageToImageFilter.h:41
itk::GPUFiniteDifferenceImageFilter< TDisplacementField, TDisplacementField, TParentImageFilter >::TimeStepType
typename FiniteDifferenceFunctionType::TimeStepType TimeStepType
Definition: itkGPUFiniteDifferenceImageFilter.h:76
itk::GPUFiniteDifferenceImageFilter::m_State
GPUFiniteDifferenceFilterEnum m_State
Definition: itkGPUFiniteDifferenceImageFilter.h:277
itk::GPUFiniteDifferenceImageFilter::GetDifferenceFunction
const FiniteDifferenceFunctionType::Pointer & GetDifferenceFunction() const override
Definition: itkGPUFiniteDifferenceImageFilter.h:84
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::GPUFiniteDifferenceImageFilter< TDisplacementField, TDisplacementField, TParentImageFilter >::InputPixelValueType
typename NumericTraits< InputPixelType >::ValueType InputPixelValueType
Definition: itkGPUFiniteDifferenceImageFilter.h:70
itk::GPUFiniteDifferenceImageFilter::m_UseImageSpacing
bool m_UseImageSpacing
Definition: itkGPUFiniteDifferenceImageFilter.h:274
itkGPUFiniteDifferenceFilterEnum.h
itk::GPUFiniteDifferenceFilterEnum::INITIALIZED
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::GPUFiniteDifferenceImageFilter::SetDifferenceFunction
void SetDifferenceFunction(FiniteDifferenceFunctionType *differenceFunction) override
Definition: itkGPUFiniteDifferenceImageFilter.h:93
itkGPUInPlaceImageFilter.h
itk::GPUFiniteDifferenceImageFilter< TDisplacementField, TDisplacementField, TParentImageFilter >::OutputPixelValueType
typename NumericTraits< OutputPixelType >::ValueType OutputPixelValueType
Definition: itkGPUFiniteDifferenceImageFilter.h:69
itk::GPUFiniteDifferenceFilterEnum::UNINITIALIZED
itk::GPUInPlaceImageFilter< TDisplacementField, TDisplacementField, TParentImageFilter >::CPUSuperclass
TParentImageFilter CPUSuperclass
Definition: itkGPUInPlaceImageFilter.h:48