ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
46
139class ITKCommon_EXPORT ProcessObject : public Object
140{
141public:
142 ITK_DISALLOW_COPY_AND_MOVE(ProcessObject);
143
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
167#ifndef ITK_FUTURE_LEGACY_REMOVE
171 using MultiThreaderType [[deprecated("Please use `itk::MultiThreaderBase` directly.")]] = MultiThreaderBase;
172#endif
173
181
185
193
195 bool
197
198 using DataObjectPointerArraySizeType = DataObjectPointerArray::size_type;
199
212
216
224
232
234 bool
236
240
256
268
272
276
292 virtual DataObjectPointer
294
300 itkSetMacro(AbortGenerateData, bool);
301
303 itkGetConstReferenceMacro(AbortGenerateData, bool);
304
306 itkBooleanMacro(AbortGenerateData);
307
316#if !defined(ITK_LEGACY_REMOVE)
317 void
318 SetProgress(float progress)
319 {
321 }
322#endif
323
329 virtual float
331 {
333 }
334
344 void
345 UpdateProgress(float progress);
346
354 void
355 IncrementProgress(float increment);
356
378 virtual void
380
390 virtual void
392
408 virtual void
410
413 virtual void
415
417 virtual void
419
429 virtual void
431 {}
432
439 virtual void
441
458 virtual DataObjectPointer
460
467 virtual void
469 virtual bool
471 void
473 {
474 this->SetReleaseDataFlag(true);
475 }
476 void
478 {
479 this->SetReleaseDataFlag(false);
480 }
481
482
496 itkSetMacro(ReleaseDataBeforeUpdateFlag, bool);
497 itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool);
498 itkBooleanMacro(ReleaseDataBeforeUpdateFlag);
500
503 itkSetClampMacro(NumberOfWorkUnits, ThreadIdType, 1, ITK_MAX_THREADS);
504 itkGetConstReferenceMacro(NumberOfWorkUnits, ThreadIdType);
506
510 {
511 return m_MultiThreader;
512 }
513
515 void
517
524 virtual void
526
527protected:
529 ~ProcessObject() override;
530
531 void
532 PrintSelf(std::ostream & os, Indent indent) const override;
533
534 //
535 // Input Methods
536 //
537
542 DataObject *
544 const DataObject *
546
550 DataObject *
552 {
553 return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : nullptr;
554 }
555 const DataObject *
557 {
558 return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : nullptr;
559 }
560
561
568 virtual void
570 virtual void
572
574 virtual void
576
585 virtual void
586 PushBackInput(const DataObject * input);
587 virtual void
589 virtual void
591 virtual void
593
600 virtual void
603
606 DataObject *
608 {
609 return m_IndexedInputs[0]->second;
610 }
611 const DataObject *
613 {
614 return m_IndexedInputs[0]->second;
615 }
616
617
620 virtual void
622 virtual const char *
624 {
625 return this->m_IndexedInputs[0]->first.c_str();
626 }
627
628
630 virtual void
632
639 void
641
652 itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType);
653
654
659 bool
661
663 bool
665
670 void
672
683 bool
685 bool
687
698 void
700 void
702
703
704 //
705 // Output Methods
706 //
707
710 DataObject *
712 const DataObject *
715
718 virtual void
720 virtual const char *
722 {
723 return this->m_IndexedOutputs[0]->first.c_str();
724 }
725
726
729 DataObject *
731 const DataObject *
734
736 virtual void
738
740 virtual void
742
745 DataObject *
747 {
748 return m_IndexedOutputs[0]->second;
749 }
750 const DataObject *
752 {
753 return m_IndexedOutputs[0]->second;
754 }
755
756
758 virtual void
760
763 virtual void
765
766 virtual void
768
769 virtual void
771
772 itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
773 itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
774
776 void
778
779
788 bool
790 bool
792
793 //
794 // Pipeline Methods
795 //
796
808 virtual void
810
821 virtual void
823
837 virtual void
839
851 virtual void
853
864 virtual void
866
868 virtual void
870 {}
871
873
876 virtual void
878
890 virtual void
892
901 virtual void
903
907 virtual void
909
915 itkGetConstMacro(ThreaderUpdateProgress, bool);
916 itkBooleanMacro(ThreaderUpdateProgress);
917 virtual void
920
924 static inline constexpr float
925 progressFixedToFloat(uint32_t fixed)
926 {
927 return static_cast<double>(fixed) / static_cast<double>(std::numeric_limits<uint32_t>::max());
928 }
929
934 static inline uint32_t
936 {
937 if (f <= 0.0f)
938 {
939 return 0;
940 }
941 if (f >= 1.0f)
942 {
943 return std::numeric_limits<uint32_t>::max();
944 }
945 const double temp = static_cast<double>(f) * std::numeric_limits<uint32_t>::max();
946 return static_cast<uint32_t>(temp);
947 }
948
950 template <typename TSourceObject>
951 static void
952 MakeRequiredOutputs(TSourceObject & sourceObject, const DataObjectPointerArraySizeType numberOfRequiredOutputs)
953 {
954 sourceObject.ProcessObject::SetNumberOfRequiredOutputs(numberOfRequiredOutputs);
955
956 for (unsigned int i{}; i < numberOfRequiredOutputs; ++i)
957 {
958 sourceObject.ProcessObject::SetNthOutput(i, sourceObject.TSourceObject::MakeOutput(i));
959 }
960 }
961
964
968
971
972private:
976
978 using DataObjectPointerMap = std::map<DataObjectIdentifierType, DataObjectPointer>;
979
980
984
985 std::vector<DataObjectPointerMap::iterator> m_IndexedInputs{};
986 std::vector<DataObjectPointerMap::iterator> m_IndexedOutputs{};
987
989 std::map<DataObjectIdentifierType, bool> m_CachedInputReleaseDataFlags{};
990
993
995 using NameSet = std::set<DataObjectIdentifierType>;
996
999
1002 std::atomic<uint32_t> m_Progress{};
1003
1004
1005 std::thread::id m_UpdateThreadID{};
1006
1011
1013
1016
1018 friend class DataObject;
1019
1020 friend class ProgressReporter;
1022
1026
1030
1031 friend class TestProcessObject;
1032};
1033} // end namespace itk
1034
1035#endif
Base class for all data objects in ITK.
SmartPointer< Self > Pointer
std::string DataObjectIdentifierType
Control indentation during Print() invocation.
Definition itkIndent.h:50
A class for performing multithreaded execution.
DataObjectPointerArraySizeType m_NumberOfRequiredOutputs
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()
SmartPointer< const Self > ConstPointer
std::vector< DataObjectPointerMap::iterator > m_IndexedInputs
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 void GenerateOutputRequestedRegion(DataObject *output)
virtual bool GetReleaseDataFlag() const
virtual void SetInput(const DataObjectIdentifierType &key, DataObject *input)
Protected method for setting indexed and named inputs.
friend class TotalProgressReporter
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.
virtual void Update()
Bring this filter up-to-date.
virtual void RemoveInput(const DataObjectIdentifierType &key)
Remove an input.
friend class TestProcessObject
virtual void SetOutput(const DataObjectIdentifierType &name, DataObject *output)
NameArray GetOutputNames() const
Return an array with the defined names of the outputs.
virtual void VerifyPreconditions() const
Verifies that the process object has been configured correctly, that all required inputs are set,...
virtual void SetThreaderUpdateProgress(bool arg)
DataObject::Pointer DataObjectPointer
virtual void RemoveOutput(const DataObjectIdentifierType &key)
DataObjectPointerArraySizeType MakeIndexFromName(const DataObjectIdentifierType &) const
virtual void VerifyInputInformation() const
Verifies that the inputs meta-data is consistent and valid for continued execution of the pipeline,...
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
friend class InputDataObjectIterator
virtual void PushFrontInput(const DataObject *input)
TimeStamp m_OutputInformationMTime
virtual void EnlargeOutputRequestedRegion(DataObject *output)
virtual void SetPrimaryOutput(DataObject *object)
virtual void GenerateData()
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.
DataObject * GetPrimaryOutput()
itk::SmartPointer< MultiThreaderBase > m_MultiThreader
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.
void SetMultiThreader(MultiThreaderBase *threader)
~ProcessObject() override
SmartPointer< Self > Pointer
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)
std::atomic< uint32_t > m_Progress
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)
friend class DataObjectConstIterator
virtual void UpdateLargestPossibleRegion()
Sets the output requested region to the largest possible region and updates.
DataObjectPointerArraySizeType MakeIndexFromInputName(const DataObjectIdentifierType &name) const
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
static void MakeRequiredOutputs(TSourceObject &sourceObject, const DataObjectPointerArraySizeType numberOfRequiredOutputs)
DataObjectPointerArray GetIndexedInputs()
Return an array with all the indexed inputs.
friend class DataObjectIterator
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 GenerateOutputInformation()
DataObjectPointerMap m_Outputs
DataObjectPointerArraySizeType MakeIndexFromOutputName(const DataObjectIdentifierType &name) const
ThreadIdType m_NumberOfWorkUnits
std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags
std::vector< DataObjectPointerMap::iterator > m_IndexedOutputs
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
DataObjectPointerArraySizeType m_NumberOfRequiredInputs
std::set< DataObjectIdentifierType > NameSet
DataObjectPointerMap m_Inputs
friend class InputDataObjectConstIterator
std::thread::id m_UpdateThreadID
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
virtual void GenerateInputRequestedRegion()
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()
friend class OutputDataObjectConstIterator
virtual void UpdateOutputData(DataObject *output)
const DataObject * GetPrimaryInput() const
void PrintSelf(std::ostream &os, Indent indent) const override
virtual void CacheInputReleaseDataFlags()
friend class OutputDataObjectIterator
DataObjectPointerArray GetIndexedOutputs()
Return an array with the indexed outputs.
friend class ProgressReporter
bool RemoveRequiredInputName(const DataObjectIdentifierType &)
Remove the named input from the required inputs.
MultiThreaderBase * GetMultiThreader() const
std::vector< DataObjectPointer > DataObjectPointerArray
Implements transparent reference counting.
Generate a unique, increasing time value.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned int ThreadIdType
constexpr vcl_size_t ITK_MAX_THREADS