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
149
151 itkOverrideGetNameOfClassMacro(ProcessObject);
155
157 // using ConstDataObjectPointerArray = std::vector< const DataObject * >;
158
160 using DataObjectPointerArray = std::vector<DataObjectPointer>;
161
163
165 using NameArray = std::vector<DataObjectIdentifierType>;
166
177
181
189
191 bool
193
194 using DataObjectPointerArraySizeType = DataObjectPointerArray::size_type;
195
208
212
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 {
317 }
318#endif
319
325 virtual float
327 {
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
463 virtual void
465 virtual bool
467 void
469 {
470 this->SetReleaseDataFlag(true);
471 }
472 void
474 {
475 this->SetReleaseDataFlag(false);
476 }
477
478
492 itkSetMacro(ReleaseDataBeforeUpdateFlag, bool);
493 itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool);
494 itkBooleanMacro(ReleaseDataBeforeUpdateFlag);
496
499 itkSetClampMacro(NumberOfWorkUnits, ThreadIdType, 1, ITK_MAX_THREADS);
500 itkGetConstReferenceMacro(NumberOfWorkUnits, ThreadIdType);
502
506 {
507 return m_MultiThreader;
508 }
509
511 void
513
520 virtual void
522
523protected:
525 ~ProcessObject() override;
526
527 void
528 PrintSelf(std::ostream & os, Indent indent) const override;
529
530 //
531 // Input Methods
532 //
533
538 DataObject *
540 const DataObject *
542
546 DataObject *
548 {
549 return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : nullptr;
550 }
551 const DataObject *
553 {
554 return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : nullptr;
555 }
556
557
564 virtual void
566 virtual void
568
570 virtual void
572
581 virtual void
582 PushBackInput(const DataObject * input);
583 virtual void
585 virtual void
587 virtual void
589
596 virtual void
599
602 DataObject *
604 {
605 return m_IndexedInputs[0]->second;
606 }
607 const DataObject *
609 {
610 return m_IndexedInputs[0]->second;
611 }
612
613
616 virtual void
618 virtual const char *
620 {
621 return this->m_IndexedInputs[0]->first.c_str();
622 }
623
624
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
706 DataObject *
708 const DataObject *
711
714 virtual void
716 virtual const char *
718 {
719 return this->m_IndexedOutputs[0]->first.c_str();
720 }
721
722
725 DataObject *
727 const DataObject *
730
732 virtual void
734
736 virtual void
738
741 DataObject *
743 {
744 return m_IndexedOutputs[0]->second;
745 }
746 const DataObject *
748 {
749 return m_IndexedOutputs[0]->second;
750 }
751
752
754 virtual void
756
759 virtual void
761
762 virtual void
764
765 virtual void
767
768 itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
769 itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
770
772 void
774
775
784 bool
786 bool
788
789 //
790 // Pipeline Methods
791 //
792
804 virtual void
806
817 virtual void
819
833 virtual void
835
847 virtual void
849
860 virtual void
862
864 virtual void
866 {}
867
869
872 virtual void
874
886 virtual void
888
897 virtual void
899
903 virtual void
905
911 itkGetConstMacro(ThreaderUpdateProgress, bool);
912 itkBooleanMacro(ThreaderUpdateProgress);
913 virtual void
916
920 static inline constexpr float
921 progressFixedToFloat(uint32_t fixed)
922 {
923 return static_cast<double>(fixed) / static_cast<double>(std::numeric_limits<uint32_t>::max());
924 }
925
930 static inline uint32_t
932 {
933 if (f <= 0.0f)
934 {
935 return 0;
936 }
937 if (f >= 1.0f)
938 {
939 return std::numeric_limits<uint32_t>::max();
940 }
941 const double temp = static_cast<double>(f) * std::numeric_limits<uint32_t>::max();
942 return static_cast<uint32_t>(temp);
943 }
944
946 template <typename TSourceObject>
947 static void
948 MakeRequiredOutputs(TSourceObject & sourceObject, const DataObjectPointerArraySizeType numberOfRequiredOutputs)
949 {
950 sourceObject.ProcessObject::SetNumberOfRequiredOutputs(numberOfRequiredOutputs);
951
952 for (unsigned int i{}; i < numberOfRequiredOutputs; ++i)
953 {
954 sourceObject.ProcessObject::SetNthOutput(i, sourceObject.TSourceObject::MakeOutput(i));
955 }
956 }
957
960
964
967
968private:
972
974 using DataObjectPointerMap = std::map<DataObjectIdentifierType, DataObjectPointer>;
975
976
980
981 std::vector<DataObjectPointerMap::iterator> m_IndexedInputs{};
982 std::vector<DataObjectPointerMap::iterator> m_IndexedOutputs{};
983
985 std::map<DataObjectIdentifierType, bool> m_CachedInputReleaseDataFlags{};
986
989
991 using NameSet = std::set<DataObjectIdentifierType>;
992
995
998 std::atomic<uint32_t> m_Progress{};
999
1000
1001 std::thread::id m_UpdateThreadID{};
1002
1007
1009
1012
1014 friend class DataObject;
1015
1016 friend class ProgressReporter;
1018
1022
1026
1027 friend class TestProcessObject;
1028};
1029} // end namespace itk
1030
1031#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.
void SetMultiThreader(MultiThreaderType *threader)
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()
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
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
MultiThreaderType * GetMultiThreader() 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
MultiThreaderBase MultiThreaderType
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.
itk::SmartPointer< MultiThreaderType > m_MultiThreader
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