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"
35
36namespace itk
37{
38
66template <typename TOutputImage>
67class ITK_TEMPLATE_EXPORT ImageSource
68 : public ProcessObject
69 , private ImageSourceCommon
70{
71public:
72 ITK_DISALLOW_COPY_AND_MOVE(ImageSource);
73
79
82
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
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
229 MakeOutput(const ProcessObject::DataObjectIdentifierType &) override;
232protected:
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 *
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
Base class for all data objects in ITK.
SmartPointer< Self > Pointer
Divide an image region into several pieces.
Base class for all process objects that output image data.
OutputImageType * GetOutput()
const OutputImageType * GetOutput() const
typename OutputImageType::PixelType OutputImagePixelType
typename OutputImageType::RegionType OutputImageRegionType
TOutputImage OutputImageType
virtual unsigned int SplitRequestedRegion(unsigned int i, unsigned int pieces, OutputImageRegionType &splitRegion)
virtual const ImageRegionSplitterBase * GetImageRegionSplitter() const
Get the image splitter to split the image for multi-threading.
OutputImageType * GetOutput(unsigned int idx)
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ThreaderCallback(void *arg)
Superclass::DataObjectIdentifierType DataObjectIdentifierType
typename OutputImageType::Pointer OutputImagePointer
static const ImageRegionSplitterBase * GetGlobalDefaultSplitter()
Returns the default image region splitter.
virtual void AfterThreadedGenerateData()
Superclass::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
void PrintSelf(std::ostream &os, Indent indent) const override
Control indentation during Print() invocation.
Definition: itkIndent.h:50
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
DataObject::DataObjectIdentifierType DataObjectIdentifierType
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
void(*)(void *) ThreadFunctionType
itk::ITK_THREAD_RETURN_TYPE ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
Secondary base class of ImageSource common between templates.
static const ImageRegionSplitterBase * GetGlobalDefaultSplitter()