ITK  5.4.0
Insight Toolkit
itkProcessObject.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 itkProcessObject_h
29#define itkProcessObject_h
30
31#include "itkDataObject.h"
32#include "itkObjectFactory.h"
33#include "itkNumericTraits.h"
34#include "itkThreadSupport.h"
35#include "itkIntTypes.h"
36#include <vector>
37#include <map>
38#include <set>
39#include <algorithm>
40#include <thread>
41
42namespace itk
43{
44
45class MultiThreaderBase;
46
139class ITKCommon_EXPORT ProcessObject : public Object
141public:
142 ITK_DISALLOW_COPY_AND_MOVE(ProcessObject);
143
149
151 itkOverrideGetNameOfClassMacro(ProcessObject);
152
155
157 // using ConstDataObjectPointerArray = std::vector< const DataObject * >;
158
160 using DataObjectPointerArray = std::vector<DataObjectPointer>;
161
163
165 using NameArray = std::vector<DataObjectIdentifierType>;
166
169
177
181
189
191 bool
193
194 using DataObjectPointerArraySizeType = DataObjectPointerArray::size_type;
195
208
212
220
228
230 bool
232
236
252
264
268
272
288 virtual DataObjectPointer
290
296 itkSetMacro(AbortGenerateData, bool);
297
299 itkGetConstReferenceMacro(AbortGenerateData, bool);
300
302 itkBooleanMacro(AbortGenerateData);
303
312#if !defined(ITK_LEGACY_REMOVE)
313 void
314 SetProgress(float progress)
315 {
316 m_Progress = progressFloatToFixed(progress);
317 }
318#endif
319
325 virtual float
327 {
328 return progressFixedToFloat(m_Progress);
329 }
330
340 void
341 UpdateProgress(float progress);
342
350 void
351 IncrementProgress(float increment);
352
374 virtual void
376
386 virtual void
388
404 virtual void
406
409 virtual void
411
413 virtual void
415
425 virtual void
427 {}
428
435 virtual void
437
454 virtual DataObjectPointer
456
462 virtual void
464 virtual bool
466 void
468 {
469 this->SetReleaseDataFlag(true);
470 }
471 void
473 {
474 this->SetReleaseDataFlag(false);
475 }
490 itkSetMacro(ReleaseDataBeforeUpdateFlag, bool);
491 itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool);
492 itkBooleanMacro(ReleaseDataBeforeUpdateFlag);
496 itkSetClampMacro(NumberOfWorkUnits, ThreadIdType, 1, ITK_MAX_THREADS);
497 itkGetConstReferenceMacro(NumberOfWorkUnits, ThreadIdType);
500#if !defined(ITK_LEGACY_REMOVE) || defined(ITKV4_COMPATIBILITY)
501 itkLegacyMacro(void SetNumberOfThreads(ThreadIdType count)) { this->SetNumberOfWorkUnits(count); }
502
503 itkLegacyMacro(ThreadIdType GetNumberOfThreads() const) { return this->GetNumberOfWorkUnits(); }
504#endif // !ITK_LEGACY_REMOVE
505
507 MultiThreaderType *
509 {
510 return m_MultiThreader;
511 }
512
514 void
516
523 virtual void
525
526protected:
528 ~ProcessObject() override;
529
530 void
531 PrintSelf(std::ostream & os, Indent indent) const override;
532
533 //
534 // Input Methods
535 //
536
541 DataObject *
543 const DataObject *
545
548 DataObject *
550 {
551 return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : nullptr;
552 }
553 const DataObject *
555 {
556 return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : nullptr;
557 }
566 virtual void
568 virtual void
570
572 virtual void
574
583 virtual void
584 PushBackInput(const DataObject * input);
585 virtual void
587 virtual void
589 virtual void
591
598 virtual void
601
603 DataObject *
605 {
606 return m_IndexedInputs[0]->second;
607 }
608 const DataObject *
610 {
611 return m_IndexedInputs[0]->second;
612 }
616 virtual void
618 virtual const char *
620 {
621 return this->m_IndexedInputs[0]->first.c_str();
622 }
626 virtual void
628
635 void
637
648 itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType);
649
650
655 bool
657
659 bool
661
666 void
668
679 bool
681 bool
683
694 void
696 void
698
699
700 //
701 // Output Methods
702 //
703
705 DataObject *
707 const DataObject *
712 virtual void
714 virtual const char *
716 {
717 return this->m_IndexedOutputs[0]->first.c_str();
718 }
722 DataObject *
724 const DataObject *
729 virtual void
731
733 virtual void
735
737 DataObject *
739 {
740 return m_IndexedOutputs[0]->second;
741 }
742 const DataObject *
744 {
745 return m_IndexedOutputs[0]->second;
746 }
750 virtual void
752
755 virtual void
757
758 virtual void
760
761 virtual void
763
764 itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
765 itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
766
768 void
770
771
780 bool
782 bool
784
785 //
786 // Pipeline Methods
787 //
788
800 virtual void
801 VerifyPreconditions() ITKv5_CONST;
802
813 virtual void
814 VerifyInputInformation() ITKv5_CONST;
815
829 virtual void
830 GenerateInputRequestedRegion();
831
843 virtual void
844 GenerateOutputRequestedRegion(DataObject * output);
845
856 virtual void
857 GenerateOutputInformation();
858
860 virtual void
861 GenerateData()
862 {}
863
868 virtual void
870
882 virtual void
884
893 virtual void
895
899 virtual void
901
906 itkGetConstMacro(ThreaderUpdateProgress, bool);
907 itkBooleanMacro(ThreaderUpdateProgress);
908 virtual void
916 static inline constexpr float
917 progressFixedToFloat(uint32_t fixed)
918 {
919 return static_cast<double>(fixed) / static_cast<double>(std::numeric_limits<uint32_t>::max());
920 };
927 static inline uint32_t
929 {
930 if (f <= 0.0f)
931 {
932 return 0;
933 }
934 if (f >= 1.0f)
935 {
936 return std::numeric_limits<uint32_t>::max();
937 }
938 double temp = static_cast<double>(f) * std::numeric_limits<uint32_t>::max();
939 return static_cast<uint32_t>(temp);
940 };
948 bool m_Updating{};
949
951 TimeStamp m_OutputInformationMTime{};
952
953private:
957
959 using DataObjectPointerMap = std::map<DataObjectIdentifierType, DataObjectPointer>;
960
961
965
966 std::vector<DataObjectPointerMap::iterator> m_IndexedInputs{};
967 std::vector<DataObjectPointerMap::iterator> m_IndexedOutputs{};
968
970 std::map<DataObjectIdentifierType, bool> m_CachedInputReleaseDataFlags{};
971
972 DataObjectPointerArraySizeType m_NumberOfRequiredInputs{};
973 DataObjectPointerArraySizeType m_NumberOfRequiredOutputs{};
974
976 using NameSet = std::set<DataObjectIdentifierType>;
977
979 NameSet m_RequiredInputNames{};
980
982 bool m_AbortGenerateData{};
983 std::atomic<uint32_t> m_Progress{};
984
985
986 std::thread::id m_UpdateThreadID{};
987
991 ThreadIdType m_NumberOfWorkUnits{};
992
993 bool m_ThreaderUpdateProgress{ true };
994
996 bool m_ReleaseDataBeforeUpdateFlag{};
997
999 friend class DataObject;
1000
1001 friend class ProgressReporter;
1003
1007
1011
1012 friend class TestProcessObject;
1013};
1014} // end namespace itk
1015
1016#endif
A forward iterator over the DataObject of a ProcessObject.
A forward iterator over the DataObject of a ProcessObject.
Base class for all data objects in ITK.
SmartPointer< Self > Pointer
std::string DataObjectIdentifierType
Control indentation during Print() invocation.
Definition: itkIndent.h:50
A forward iterator over inputs of a ProcessObject.
A forward iterator over inputs of a ProcessObject.
Light weight base class for most itk classes.
A class for performing multithreaded execution.
Base class for most ITK classes.
Definition: itkObject.h:62
A forward iterator over outputs of a ProcessObject.
A forward iterator over outputs of a ProcessObject.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
static constexpr float progressFixedToFloat(uint32_t fixed)
virtual void SetPrimaryInputName(const DataObjectIdentifierType &key)
virtual void ReleaseInputs()
bool HasOutput(const DataObjectIdentifierType &key) const
Return true if the output with this name is defined.
virtual void PopBackInput()
virtual void SetPrimaryInput(DataObject *object)
static uint32_t progressFloatToFixed(float f)
const DataObject * GetOutput(const DataObjectIdentifierType &key) const
const DataObject * GetPrimaryOutput() const
std::map< DataObjectIdentifierType, DataObjectPointer > DataObjectPointerMap
DataObjectIdentifierType MakeNameFromIndex(DataObjectPointerArraySizeType) const
void AddOptionalInputName(const DataObjectIdentifierType &)
Define a named input that is not required and optionally associate with a numbered index.
const DataObject * GetOutput(DataObjectPointerArraySizeType i) const
void SetRequiredInputNames(const NameArray &)
Set all required named inputs.
virtual const char * GetPrimaryInputName() const
virtual void PrepareOutputs()
virtual bool GetReleaseDataFlag() const
virtual void SetInput(const DataObjectIdentifierType &key, DataObject *input)
Protected method for setting indexed and named inputs.
DataObjectPointerArray GetOutputs()
Return an array with the defined named outputs.
DataObject * GetInput(DataObjectPointerArraySizeType idx)
DataObject * GetOutput(const DataObjectIdentifierType &key)
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
DataObjectPointerArraySizeType GetNumberOfIndexedInputs() const
Get the number of defined Indexed inputs.
void SetMultiThreader(MultiThreaderType *threader)
virtual void Update()
Bring this filter up-to-date.
virtual void RemoveInput(const DataObjectIdentifierType &key)
Remove an input.
virtual void SetOutput(const DataObjectIdentifierType &name, DataObject *output)
NameArray GetOutputNames() const
Return an array with the defined names of the outputs.
virtual void SetThreaderUpdateProgress(bool arg)
virtual void RemoveOutput(const DataObjectIdentifierType &key)
DataObjectPointerArraySizeType MakeIndexFromName(const DataObjectIdentifierType &) const
DataObjectPointerArraySizeType GetNumberOfInputs() const
Get the size of the input container.
void SetNumberOfIndexedInputs(DataObjectPointerArraySizeType num)
Define the number of indexed inputs defined.
const DataObject * GetInput(DataObjectPointerArraySizeType idx) const
virtual void AddOutput(DataObject *output)
virtual const char * GetPrimaryOutputName() const
std::vector< DataObjectIdentifierType > NameArray
virtual void PushFrontInput(const DataObject *input)
virtual void SetPrimaryOutput(DataObject *object)
DataObjectIdentifierType MakeNameFromInputIndex(DataObjectPointerArraySizeType idx) const
virtual DataObjectPointer MakeOutput(const DataObjectIdentifierType &)
Make a DataObject of the correct type to used as the specified output.
bool AddRequiredInputName(const DataObjectIdentifierType &)
Define a required named input and optionally associate it with a numbered index.
virtual DataObjectPointerArraySizeType GetNumberOfValidRequiredInputs() const
Get the number of valid indexed inputs.
virtual void VerifyPreconditions() ITKv5_CONST
Verifies that the process object has been configured correctly, that all required inputs are set,...
DataObject * GetPrimaryOutput()
virtual void RestoreInputReleaseDataFlags()
virtual void PopFrontInput()
DataObjectPointerArray GetInputs()
Return an array of DataObjects with the defined named inputs.
virtual void PushBackInput(const DataObject *input)
Push/Pop an indexed input of this process object.
~ProcessObject() override
NameArray GetRequiredInputNames() const
virtual void SetNumberOfRequiredInputs(DataObjectPointerArraySizeType)
Set the number of required indexed inputs.
DataObjectPointerArraySizeType GetNumberOfIndexedOutputs() const
The number of defined Indexed outputs.
virtual void SetNthInput(DataObjectPointerArraySizeType idx, DataObject *input)
DataObject * GetOutput(DataObjectPointerArraySizeType i)
DataObjectPointerArraySizeType GetNumberOfOutputs() const
Get the size of the output container.
bool IsIndexedInputName(const DataObjectIdentifierType &) const
virtual void ResetPipeline()
Reset the pipeline.
void UpdateProgress(float progress)
Update the progress of the process object.
DataObject::DataObjectIdentifierType DataObjectIdentifierType
bool HasInput(const DataObjectIdentifierType &key) const
bool AddRequiredInputName(const DataObjectIdentifierType &, DataObjectPointerArraySizeType idx)
virtual void UpdateLargestPossibleRegion()
Sets the output requested region to the largest possible region and updates.
DataObjectPointerArraySizeType MakeIndexFromInputName(const DataObjectIdentifierType &name) const
MultiThreaderType * GetMultiThreader() const
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
DataObjectPointerArray GetIndexedInputs()
Return an array with all the indexed inputs.
virtual void SetNthOutput(DataObjectPointerArraySizeType idx, DataObject *output)
virtual void SetReleaseDataFlag(bool val)
virtual void PropagateRequestedRegion(DataObject *output)
void IncrementProgress(float increment)
Increment the progress of the process object.
virtual void SetPrimaryOutputName(const DataObjectIdentifierType &key)
DataObject * GetPrimaryInput()
NameArray GetInputNames() const
Return an array with the names of the inputs defined.
virtual void EnlargeOutputRequestedRegion(DataObject *)
DataObjectPointerArraySizeType MakeIndexFromOutputName(const DataObjectIdentifierType &name) const
virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx)
Make a DataObject of the correct type to used as the specified output.
const DataObject * GetInput(const DataObjectIdentifierType &key) const
std::set< DataObjectIdentifierType > NameSet
bool IsRequiredInputName(const DataObjectIdentifierType &) const
Query if the named input is required by name.
virtual void RemoveOutput(DataObjectPointerArraySizeType idx)
void SetNumberOfIndexedOutputs(DataObjectPointerArraySizeType num)
bool IsIndexedOutputName(const DataObjectIdentifierType &) const
void AddOptionalInputName(const DataObjectIdentifierType &, DataObjectPointerArraySizeType idx)
virtual void AddInput(DataObject *input)
DataObjectIdentifierType MakeNameFromOutputIndex(DataObjectPointerArraySizeType idx) const
virtual void RemoveInput(DataObjectPointerArraySizeType)
virtual float GetProgress() const
Get the execution progress of a process object.
virtual void UpdateOutputInformation()
Update the information describing the output data.
virtual void PropagateResetPipeline()
virtual void UpdateOutputData(DataObject *output)
const DataObject * GetPrimaryInput() const
void PrintSelf(std::ostream &os, Indent indent) const override
virtual void CacheInputReleaseDataFlags()
DataObjectPointerArray GetIndexedOutputs()
Return an array with the indexed outputs.
bool RemoveRequiredInputName(const DataObjectIdentifierType &)
Remove the named input from the required inputs.
itk::SmartPointer< MultiThreaderType > m_MultiThreader
std::vector< DataObjectPointer > DataObjectPointerArray
Implements progress tracking for a filter.
Generate a unique, increasing time value.
Definition: itkTimeStamp.h:61
A progress reporter for concurrent threads.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
constexpr vcl_size_t ITK_MAX_THREADS
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41
unsigned int ThreadIdType
Definition: itkIntTypes.h:99