ITK  5.4.0
Insight Toolkit
itkImageSource.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  * https://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 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkImageSource_h
29 #define itkImageSource_h
30 
31 #include "itkProcessObject.h"
32 #include "itkImage.h"
34 #include "itkImageSourceCommon.h"
35 
36 namespace itk
37 {
38 
66 template <typename TOutputImage>
67 class ITK_TEMPLATE_EXPORT ImageSource
68  : public ProcessObject
69  , private ImageSourceCommon
70 {
71 public:
72  ITK_DISALLOW_COPY_AND_MOVE(ImageSource);
73 
75  using Self = ImageSource;
79 
82 
83  using DataObjectIdentifierType = Superclass::DataObjectIdentifierType;
84  using DataObjectPointerArraySizeType = Superclass::DataObjectPointerArraySizeType;
85 
87  itkOverrideGetNameOfClassMacro(ImageSource);
88 
90  using OutputImageType = TOutputImage;
93  using OutputImagePixelType = typename OutputImageType::PixelType;
94 
96  static constexpr unsigned int OutputImageDimension = TOutputImage::ImageDimension;
97 
146  GetOutput();
147  const OutputImageType *
148  GetOutput() const;
152  GetOutput(unsigned int idx);
153 
173  // setup the mini-pipeline to calculate the correct regions
174  // and write to the appropriate bulk data block
175  lastFilterInMiniPipeline->GraftOutput( this->GetOutput() );
176 
177  // execute the mini-pipeline
178  lastFilterInMiniPipeline->Update();
179 
180  // graft the mini-pipeline output back onto this filter's output.
181  // this is needed to get the appropriate regions passed back.
182  this->GraftOutput( lastFilterInMiniPipeline->GetOutput() );
183  \endcode
184  *
185  * For proper pipeline execution, a filter using a mini-pipeline
186  * must implement the GenerateInputRequestedRegion(),
187  * GenerateOutputRequestedRegion(), GenerateOutputInformation() and
188  * EnlargeOutputRequestedRegion() methods as necessary to reflect
189  * how the mini-pipeline will execute (in other words, the outer
190  * filter's pipeline mechanism must be consistent with what the
191  * mini-pipeline will do).
192  * */
193  virtual void
194  GraftOutput(DataObject * graft);
195 
201  virtual void
202  GraftOutput(const DataObjectIdentifierType & key, DataObject * graft);
203 
210  virtual void
211  GraftNthOutput(unsigned int idx, DataObject * graft);
212 
227  MakeOutput(ProcessObject::DataObjectPointerArraySizeType idx) override;
229  MakeOutput(const ProcessObject::DataObjectIdentifierType &) override;
232 protected:
233  ImageSource();
234  ~ImageSource() override = default;
235 
251  void
252  GenerateData() override;
253 
257  void
258  ClassicMultiThread(ThreadFunctionType callbackFunction);
259 
301  virtual void
302  ThreadedGenerateData(const OutputImageRegionType & region, ThreadIdType threadId);
303  virtual void
304  DynamicThreadedGenerateData(const OutputImageRegionType & outputRegionForThread);
312  virtual void
313  AllocateOutputs();
314 
325  virtual void
326  BeforeThreadedGenerateData()
327  {}
328 
339  virtual void
341  {}
342 
348  static const ImageRegionSplitterBase *
350  {
352  }
353 
364  virtual const ImageRegionSplitterBase *
365  GetImageRegionSplitter() const;
366 
381  virtual unsigned int
382  SplitRequestedRegion(unsigned int i, unsigned int pieces, OutputImageRegionType & splitRegion);
383 
388  ThreaderCallback(void * arg);
389 
392  {
394  };
395 
396  void
397  PrintSelf(std::ostream & os, Indent indent) const override;
398 
402  itkGetConstMacro(DynamicMultiThreading, bool);
403  itkSetMacro(DynamicMultiThreading, bool);
404  itkBooleanMacro(DynamicMultiThreading);
407  bool m_DynamicMultiThreading{};
408 };
409 } // end namespace itk
410 
411 #ifndef ITK_MANUAL_INSTANTIATION
412 # include "itkImageSource.hxx"
413 #endif
414 
415 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::ImageSource< TIntensityImage >::OutputImagePointer
typename OutputImageType::Pointer OutputImagePointer
Definition: itkImageSource.h:91
itk::ProcessObject::DataObjectIdentifierType
DataObject::DataObjectIdentifierType DataObjectIdentifierType
Definition: itkProcessObject.h:162
itk::ImageSource::AfterThreadedGenerateData
virtual void AfterThreadedGenerateData()
Definition: itkImageSource.h:340
itk::ImageSource::GetGlobalDefaultSplitter
static const ImageRegionSplitterBase * GetGlobalDefaultSplitter()
Returns the default image region splitter.
Definition: itkImageSource.h:349
itkImage.h
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ProcessObject::DataObjectPointerArraySizeType
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
Definition: itkProcessObject.h:194
itk::ThreadFunctionType
void(*)(void *) ThreadFunctionType
Definition: itkThreadSupport.h:82
itk::ThreadIdType
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
itk::ITK_THREAD_RETURN_TYPE ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
Definition: itkThreadSupport.h:89
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkImageSourceCommon.h
itk::ImageSource::ThreadStruct::Filter
Pointer Filter
Definition: itkImageSource.h:393
itk::ImageRegionSplitterBase
Divide an image region into several pieces.
Definition: itkImageRegionSplitterBase.h:58
itkProcessObject.h
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itkImageRegionSplitterBase.h
itk::ImageSourceCommon::GetGlobalDefaultSplitter
static const ImageRegionSplitterBase * GetGlobalDefaultSplitter()
itk::ImageSource< TIntensityImage >::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSource.h:92
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::ProcessObject
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41
itk::ImageSource< TIntensityImage >::OutputImagePixelType
typename OutputImageType::PixelType OutputImagePixelType
Definition: itkImageSource.h:93
itk::ImageSource::ThreadStruct
Definition: itkImageSource.h:391
itk::ImageSourceCommon
Secondary base class of ImageSource common between templates.
Definition: itkImageSourceCommon.h:42
itk::DataObject::Pointer
SmartPointer< Self > Pointer
Definition: itkDataObject.h:301
itk::ImageSource< TIntensityImage >::OutputImageType
TIntensityImage OutputImageType
Definition: itkImageSource.h:90
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293