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);
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 {
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
456
462 virtual void
464 virtual bool
466 void
468 {
469 this->SetReleaseDataFlag(true);
470 }
471 void
473 {
474 this->SetReleaseDataFlag(false);
475 }
476
477
490 itkSetMacro(ReleaseDataBeforeUpdateFlag, bool);
491 itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool);
492 itkBooleanMacro(ReleaseDataBeforeUpdateFlag);
494
496 itkSetClampMacro(NumberOfWorkUnits, ThreadIdType, 1, ITK_MAX_THREADS);
497 itkGetConstReferenceMacro(NumberOfWorkUnits, ThreadIdType);
499
503 {
504 return m_MultiThreader;
505 }
506
508 void
510
517 virtual void
519
520protected:
522 ~ProcessObject() override;
523
524 void
525 PrintSelf(std::ostream & os, Indent indent) const override;
526
527 //
528 // Input Methods
529 //
530
535 DataObject *
537 const DataObject *
539
542 DataObject *
544 {
545 return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : nullptr;
546 }
547 const DataObject *
549 {
550 return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : nullptr;
551 }
552
553
560 virtual void
562 virtual void
564
566 virtual void
568
577 virtual void
578 PushBackInput(const DataObject * input);
579 virtual void
581 virtual void
583 virtual void
585
592 virtual void
595
597 DataObject *
599 {
600 return m_IndexedInputs[0]->second;
601 }
602 const DataObject *
604 {
605 return m_IndexedInputs[0]->second;
606 }
607
608
610 virtual void
612 virtual const char *
614 {
615 return this->m_IndexedInputs[0]->first.c_str();
616 }
617
618
620 virtual void
622
629 void
631
642 itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType);
643
644
649 bool
651
653 bool
655
660 void
662
673 bool
675 bool
677
688 void
690 void
692
693
694 //
695 // Output Methods
696 //
697
699 DataObject *
701 const DataObject *
704
706 virtual void
708 virtual const char *
710 {
711 return this->m_IndexedOutputs[0]->first.c_str();
712 }
713
714
716 DataObject *
718 const DataObject *
721
723 virtual void
725
727 virtual void
729
731 DataObject *
733 {
734 return m_IndexedOutputs[0]->second;
735 }
736 const DataObject *
738 {
739 return m_IndexedOutputs[0]->second;
740 }
741
742
744 virtual void
746
749 virtual void
751
752 virtual void
754
755 virtual void
757
758 itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
759 itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
760
762 void
764
765
774 bool
776 bool
778
779 //
780 // Pipeline Methods
781 //
782
794 virtual void
796
807 virtual void
809
823 virtual void
825
837 virtual void
839
850 virtual void
852
854 virtual void
856 {}
857
859
862 virtual void
864
876 virtual void
878
887 virtual void
889
893 virtual void
895
900 itkGetConstMacro(ThreaderUpdateProgress, bool);
901 itkBooleanMacro(ThreaderUpdateProgress);
902 virtual void
905
906
910 static inline constexpr float
911 progressFixedToFloat(uint32_t fixed)
912 {
913 return static_cast<double>(fixed) / static_cast<double>(std::numeric_limits<uint32_t>::max());
914 }
915
920 static inline uint32_t
922 {
923 if (f <= 0.0f)
924 {
925 return 0;
926 }
927 if (f >= 1.0f)
928 {
929 return std::numeric_limits<uint32_t>::max();
930 }
931 const double temp = static_cast<double>(f) * std::numeric_limits<uint32_t>::max();
932 return static_cast<uint32_t>(temp);
933 }
934
935
936
938 template <typename TSourceObject>
939 static void
940 MakeRequiredOutputs(TSourceObject & sourceObject, const DataObjectPointerArraySizeType numberOfRequiredOutputs)
941 {
942 sourceObject.ProcessObject::SetNumberOfRequiredOutputs(numberOfRequiredOutputs);
943
944 for (unsigned int i{}; i < numberOfRequiredOutputs; ++i)
945 {
946 sourceObject.ProcessObject::SetNthOutput(i, sourceObject.TSourceObject::MakeOutput(i));
947 }
948 }
949
952
956
959
960private:
964
966 using DataObjectPointerMap = std::map<DataObjectIdentifierType, DataObjectPointer>;
967
968
972
973 std::vector<DataObjectPointerMap::iterator> m_IndexedInputs{};
974 std::vector<DataObjectPointerMap::iterator> m_IndexedOutputs{};
975
977 std::map<DataObjectIdentifierType, bool> m_CachedInputReleaseDataFlags{};
978
981
983 using NameSet = std::set<DataObjectIdentifierType>;
984
987
990 std::atomic<uint32_t> m_Progress{};
991
992
993 std::thread::id m_UpdateThreadID{};
994
999
1001
1004
1006 friend class DataObject;
1007
1008 friend class ProgressReporter;
1010
1014
1018
1019 friend class TestProcessObject;
1020};
1021} // end namespace itk
1022
1023#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