ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkGPUFiniteDifferenceImageFilter.h
Go to the documentation of this file.
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 itkGPUFiniteDifferenceImageFilter_h
19 #define itkGPUFiniteDifferenceImageFilter_h
20 
24 #include "itkTimeProbe.h"
25 
26 namespace itk
27 {
35 template< typename TInputImage, typename TOutputImage, typename TParentImageFilter =
36  FiniteDifferenceImageFilter< TInputImage, TOutputImage > >
37 class ITK_TEMPLATE_EXPORT GPUFiniteDifferenceImageFilter :
38  public GPUInPlaceImageFilter< TInputImage, TOutputImage, TParentImageFilter >
39 {
40 public:
41  ITK_DISALLOW_COPY_AND_ASSIGN(GPUFiniteDifferenceImageFilter);
42 
46  using CPUSuperclass = TParentImageFilter;
49 
52 
54  using InputImageType = TInputImage;
55  using OutputImageType = TOutputImage;
56 
58  static constexpr unsigned int ImageDimension = OutputImageType::ImageDimension;
59 
61  using OutputPixelType = typename TOutputImage::PixelType;
62  using InputPixelType = typename TInputImage::PixelType;
64 
68 
73  using TimeStepType = typename FiniteDifferenceFunctionType::TimeStepType;
74  using RadiusType = typename FiniteDifferenceFunctionType::RadiusType;
75  using NeighborhoodScalesType = typename FiniteDifferenceFunctionType::NeighborhoodScalesType;
76 
80  const typename FiniteDifferenceFunctionType::Pointer &GetDifferenceFunction() const override
81  {
82  return this->m_DifferenceFunction;
83  }
84 
88  void SetDifferenceFunction ( FiniteDifferenceFunctionType *differenceFunction ) override
89  {
90  itkDebugMacro("setting m_DifferenceFunction to " << differenceFunction);
91  if ( this->m_DifferenceFunction != differenceFunction )
92  {
93  this->m_DifferenceFunction = differenceFunction;
94  this->Modified();
95  }
96  }
98 
99  typedef enum { UNINITIALIZED = 0, INITIALIZED = 1 } FilterStateType;
100 
103  {
104  this->SetState(INITIALIZED);
105  }
106 
109  {
110  this->SetState(UNINITIALIZED);
111  }
112 
114 #if !defined( ITK_WRAPPING_PARSER )
115  itkSetMacro(State, FilterStateType);
116  itkGetConstReferenceMacro(State, FilterStateType);
117 #endif
118 
119 
120 #ifdef ITK_USE_CONCEPT_CHECKING
121  // Begin concept checking
122  itkConceptMacro( OutputPixelIsFloatingPointCheck,
124  // End concept checking
125 #endif
126 
128  itkGetConstReferenceMacro(InitTime, TimeProbe);
129  itkGetConstReferenceMacro(ComputeUpdateTime, TimeProbe);
130  itkGetConstReferenceMacro(ApplyUpdateTime, TimeProbe);
131  itkGetConstReferenceMacro(SmoothFieldTime, TimeProbe);
133 
134 protected:
136  ~GPUFiniteDifferenceImageFilter() override;
137 
138  void PrintSelf(std::ostream & os, Indent indent) const override;
139 
141  void AllocateUpdateBuffer() override = 0;
142 
146  virtual void GPUApplyUpdate(const TimeStepType& dt) = 0;
147 
153  virtual TimeStepType GPUCalculateChange() = 0;
154 
158  void CopyInputToOutput() override = 0;
159 
163  void GPUGenerateData() override;
164 
176  void GenerateInputRequestedRegion() override;
177 
180  bool Halt() override;
181 
191  bool ThreadedHalt( void *itkNotUsed(threadInfo) ) override {
192  return this->Halt();
193  }
194 
200  void Initialize() override {
201  }
202 
209  void InitializeIteration() override
210  {
211  m_DifferenceFunction->InitializeIteration();
212  }
213 
226  virtual TimeStepType ResolveTimeStep(const std::vector<TimeStepType >& timeStepList,
227  const std::vector< bool >& valid) const override;
228 
231  void PostProcessOutput() override {
232  }
233 
236  //unsigned int m_NumberOfIterations;
237 
240  //unsigned int m_ElapsedIterations;
241 
245 
246  double m_RMSChange;
248 
250  TimeProbe m_InitTime, m_ComputeUpdateTime, m_ApplyUpdateTime, m_SmoothFieldTime;
251 
252 private:
253 
257  void InitializeFunctionCoefficients();
258 
260  typename FiniteDifferenceFunctionType::Pointer m_DifferenceFunction;
261 
265 
268 };
269 } // end namespace itk
270 
271 #ifndef ITK_MANUAL_INSTANTIATION
272 #include "itkGPUFiniteDifferenceImageFilter.hxx"
273 #endif
274 
275 #endif
class to abstract the behaviour of the GPU filters.
Light weight base class for most itk classes.
Computes the time passed between two points in code.
Definition: itkTimeProbe.h:44
Define numeric traits for std::vector.
Base class for GPU Finite Difference Image Filters.
Base class for GPU filters that take an image as input and overwrite that image as the output...
const FiniteDifferenceFunctionType::Pointer & GetDifferenceFunction() const override
typename GPUFiniteDifferenceFunction< TDisplacementField >::DifferenceFunctionType FiniteDifferenceFunctionType
FiniteDifferenceFunctionType::Pointer m_DifferenceFunction
Control indentation during Print() invocation.
Definition: itkIndent.h:49
#define itkConceptMacro(name, concept)
void SetDifferenceFunction(FiniteDifferenceFunctionType *differenceFunction) override