ITK  5.1.0
Insight Toolkit
itkProcessObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 "itkDomainThreader.h"
33 #include "itkMultiThreaderBase.h"
34 #include "itkObjectFactory.h"
35 #include "itkNumericTraits.h"
36 #include <vector>
37 #include <map>
38 #include <set>
39 #include <algorithm>
40 
41 namespace itk
42 {
135 class ITKCommon_EXPORT ProcessObject : public Object
136 {
137 public:
138  ITK_DISALLOW_COPY_AND_ASSIGN(ProcessObject);
139 
145 
147  itkTypeMacro(ProcessObject, Object);
148 
151 
153  // using ConstDataObjectPointerArray = std::vector< const DataObject * >;
154 
156  using DataObjectPointerArray = std::vector<DataObjectPointer>;
157 
159 
161  using NameArray = std::vector<DataObjectIdentifierType>;
162 
165 
171  NameArray
172  GetInputNames() const;
173 
175  NameArray
176  GetRequiredInputNames() const;
177 
184  GetInputs();
185 
187  bool
188  HasInput(const DataObjectIdentifierType & key) const;
189 
190  using DataObjectPointerArraySizeType = DataObjectPointerArray::size_type;
191 
203  GetNumberOfInputs() const;
204 
207  GetNumberOfOutputs() const;
208 
214  NameArray
215  GetOutputNames() const;
216 
223  GetOutputs();
224 
226  bool
227  HasOutput(const DataObjectIdentifierType & key) const;
228 
231  GetIndexedInputs();
232 
247  GetNumberOfIndexedInputs() const;
248 
259  GetNumberOfValidRequiredInputs() const;
260 
263  GetIndexedOutputs();
264 
267  GetNumberOfIndexedOutputs() const;
268 
284  virtual DataObjectPointer
285  MakeOutput(DataObjectPointerArraySizeType idx);
286 
292  itkSetMacro(AbortGenerateData, bool);
293 
295  itkGetConstReferenceMacro(AbortGenerateData, bool);
296 
298  itkBooleanMacro(AbortGenerateData);
299 
312 #if !defined(ITK_LEGACY_REMOVE)
313  void
314  SetProgress(float progress)
315  {
316  // Clamp the value to be between 0 and 1.
317  m_Progress = std::max(progress, 0.0f);
318  m_Progress = std::min(m_Progress, 1.0f);
319  }
320 #endif
321 
322 
328  itkGetConstReferenceMacro(Progress, float);
329 
336  void
337  UpdateProgress(float progress);
338 
360  virtual void
361  Update();
362 
372  virtual void
373  UpdateLargestPossibleRegion();
374 
390  virtual void
391  UpdateOutputInformation();
392 
395  virtual void
396  PropagateRequestedRegion(DataObject * output);
397 
399  virtual void
400  UpdateOutputData(DataObject * output);
401 
411  virtual void
413  {}
414 
421  virtual void
422  ResetPipeline();
423 
440  virtual DataObjectPointer
441  MakeOutput(const DataObjectIdentifierType &);
442 
448  virtual void
449  SetReleaseDataFlag(bool flag);
450  virtual bool
451  GetReleaseDataFlag() const;
452  void
454  {
455  this->SetReleaseDataFlag(true);
456  }
457  void
459  {
460  this->SetReleaseDataFlag(false);
461  }
463 
476  itkSetMacro(ReleaseDataBeforeUpdateFlag, bool);
477  itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool);
478  itkBooleanMacro(ReleaseDataBeforeUpdateFlag);
480 
482  itkSetClampMacro(NumberOfWorkUnits, ThreadIdType, 1, ITK_MAX_THREADS);
483  itkGetConstReferenceMacro(NumberOfWorkUnits, ThreadIdType);
485 
486 #if !defined(ITK_LEGACY_REMOVE) || defined(ITKV4_COMPATIBILITY)
487  itkLegacyMacro(void SetNumberOfThreads(ThreadIdType count)) { this->SetNumberOfWorkUnits(count); }
488 
489  itkLegacyMacro(ThreadIdType GetNumberOfThreads() const) { return this->GetNumberOfWorkUnits(); }
490 #endif // !ITK_LEGACY_REMOVE
491 
493  MultiThreaderType *
495  {
496  return m_MultiThreader;
497  }
498 
500  void
501  SetMultiThreader(MultiThreaderType * threader);
502 
509  virtual void
510  PrepareOutputs();
511 
512 protected:
513  ProcessObject();
514  ~ProcessObject() override;
515 
516  void
517  PrintSelf(std::ostream & os, Indent indent) const override;
518 
519  //
520  // Input Methods
521  //
522 
527  DataObject *
528  GetInput(const DataObjectIdentifierType & key);
529  const DataObject *
530  GetInput(const DataObjectIdentifierType & key) const;
531 
534  DataObject *
536  {
537  return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : nullptr;
538  }
539  const DataObject *
541  {
542  return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : nullptr;
543  }
545 
552  virtual void
553  SetInput(const DataObjectIdentifierType & key, DataObject * input);
554  virtual void
555  SetNthInput(DataObjectPointerArraySizeType num, DataObject * input);
556 
558  virtual void
559  AddInput(DataObject * input);
560 
569  virtual void
570  PushBackInput(const DataObject * input);
571  virtual void
572  PopBackInput();
573  virtual void
574  PushFrontInput(const DataObject * input);
575  virtual void
576  PopFrontInput();
577 
584  virtual void
585  RemoveInput(const DataObjectIdentifierType & key);
586  virtual void RemoveInput(DataObjectPointerArraySizeType);
587 
589  DataObject *
591  {
592  return m_IndexedInputs[0]->second;
593  }
594  const DataObject *
596  {
597  return m_IndexedInputs[0]->second;
598  }
600 
602  virtual void
603  SetPrimaryInputName(const DataObjectIdentifierType & key);
604  virtual const char *
606  {
607  return this->m_IndexedInputs[0]->first.c_str();
608  }
610 
612  virtual void
613  SetPrimaryInput(DataObject * input);
614 
621  void
622  SetNumberOfIndexedInputs(DataObjectPointerArraySizeType num);
623 
633  virtual void SetNumberOfRequiredInputs(DataObjectPointerArraySizeType);
634  itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType);
635 
636 
641  bool
642  RemoveRequiredInputName(const DataObjectIdentifierType &);
643 
645  bool
646  IsRequiredInputName(const DataObjectIdentifierType &) const;
647 
652  void
653  SetRequiredInputNames(const NameArray &);
654 
665  bool
666  AddRequiredInputName(const DataObjectIdentifierType &);
667  bool
668  AddRequiredInputName(const DataObjectIdentifierType &, DataObjectPointerArraySizeType idx);
669 
680  void
681  AddOptionalInputName(const DataObjectIdentifierType &);
682  void
683  AddOptionalInputName(const DataObjectIdentifierType &, DataObjectPointerArraySizeType idx);
684 
685 
686  //
687  // Output Methods
688  //
689 
691  DataObject *
692  GetOutput(const DataObjectIdentifierType & key);
693  const DataObject *
694  GetOutput(const DataObjectIdentifierType & key) const;
696 
698  virtual void
699  SetPrimaryOutputName(const DataObjectIdentifierType & key);
700  virtual const char *
702  {
703  return this->m_IndexedOutputs[0]->first.c_str();
704  }
706 
708  DataObject *
709  GetOutput(DataObjectPointerArraySizeType idx);
710  const DataObject *
711  GetOutput(DataObjectPointerArraySizeType idx) const;
713 
715  virtual void
716  SetOutput(const DataObjectIdentifierType & key, DataObject * output);
717 
719  virtual void
720  RemoveOutput(const DataObjectIdentifierType & key);
721 
723  DataObject *
725  {
726  return m_IndexedOutputs[0]->second;
727  }
728  const DataObject *
730  {
731  return m_IndexedOutputs[0]->second;
732  }
734 
736  virtual void
737  SetPrimaryOutput(DataObject * output);
738 
741  virtual void
742  SetNthOutput(DataObjectPointerArraySizeType num, DataObject * output);
743 
744  virtual void
745  AddOutput(DataObject * output);
746 
747  virtual void
748  RemoveOutput(DataObjectPointerArraySizeType idx);
749 
750  itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
751  itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
752 
754  void
755  SetNumberOfIndexedOutputs(DataObjectPointerArraySizeType num);
756 
757 
758  DataObjectIdentifierType
759  MakeNameFromInputIndex(DataObjectPointerArraySizeType idx) const;
760  DataObjectIdentifierType
761  MakeNameFromOutputIndex(DataObjectPointerArraySizeType idx) const;
762  DataObjectPointerArraySizeType
763  MakeIndexFromInputName(const DataObjectIdentifierType & name) const;
764  DataObjectPointerArraySizeType
765  MakeIndexFromOutputName(const DataObjectIdentifierType & name) const;
766  bool
767  IsIndexedInputName(const DataObjectIdentifierType &) const;
768  bool
769  IsIndexedOutputName(const DataObjectIdentifierType &) const;
770 
771  //
772  // Pipeline Methods
773  //
774 
786  virtual void
787  VerifyPreconditions() ITKv5_CONST;
788 
799  virtual void
800  VerifyInputInformation() ITKv5_CONST;
801 
815  virtual void
816  GenerateInputRequestedRegion();
817 
829  virtual void
830  GenerateOutputRequestedRegion(DataObject * output);
831 
842  virtual void
843  GenerateOutputInformation();
844 
846  virtual void
847  GenerateData()
848  {}
849 
854  virtual void
855  PropagateResetPipeline();
856 
868  virtual void
869  ReleaseInputs();
870 
879  virtual void
880  CacheInputReleaseDataFlags();
881 
885  virtual void
886  RestoreInputReleaseDataFlags();
887 
894 
897 
898 private:
901  MakeIndexFromName(const DataObjectIdentifierType &) const;
902 
904  using DataObjectPointerMap = std::map<DataObjectIdentifierType, DataObjectPointer>;
905 
906 
910 
911  std::vector<DataObjectPointerMap::iterator> m_IndexedInputs;
912  std::vector<DataObjectPointerMap::iterator> m_IndexedOutputs;
913 
915  std::map<DataObjectIdentifierType, bool> m_CachedInputReleaseDataFlags;
916 
919 
921  using NameSet = std::set<DataObjectIdentifierType>;
922 
925 
928  float m_Progress;
929 
934 
937 
939  friend class DataObject;
940 
944 
945  friend class DataObjectIterator;
948 
949  friend class TestProcessObject;
950 };
951 } // end namespace itk
952 
953 #endif
itk::ProcessObject::m_ReleaseDataBeforeUpdateFlag
bool m_ReleaseDataBeforeUpdateFlag
Definition: itkProcessObject.h:936
itk::MultiThreaderBase
A class for performing multithreaded execution.
Definition: itkMultiThreaderBase.h:61
itk::ProcessObject::m_Updating
bool m_Updating
Definition: itkProcessObject.h:893
itkObjectFactory.h
itk::ProcessObject::m_IndexedOutputs
std::vector< DataObjectPointerMap::iterator > m_IndexedOutputs
Definition: itkProcessObject.h:912
itk::ProcessObject::DataObjectPointerArray
std::vector< DataObjectPointer > DataObjectPointerArray
Definition: itkProcessObject.h:156
itk::InputDataObjectConstIterator
A forward iterator over inputs of a ProcessObject.
Definition: itkInputDataObjectConstIterator.h:30
itk::ProcessObject::NameArray
std::vector< DataObjectIdentifierType > NameArray
Definition: itkProcessObject.h:161
itk::ProcessObject::m_Progress
float m_Progress
Definition: itkProcessObject.h:928
itk::ProcessObject::GetPrimaryInput
const DataObject * GetPrimaryInput() const
Definition: itkProcessObject.h:595
itk::ProcessObject::m_OutputInformationMTime
TimeStamp m_OutputInformationMTime
Definition: itkProcessObject.h:896
itk::ProcessObject::DataObjectIdentifierType
DataObject::DataObjectIdentifierType DataObjectIdentifierType
Definition: itkProcessObject.h:158
itk::ProcessObject::GetInput
DataObject * GetInput(DataObjectPointerArraySizeType idx)
Definition: itkProcessObject.h:535
itk::DataObjectIterator
A forward iterator over the DataObject of a ProcessObject.
Definition: itkDataObjectIterator.h:30
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ProcessObject::m_NumberOfRequiredInputs
DataObjectPointerArraySizeType m_NumberOfRequiredInputs
Definition: itkProcessObject.h:917
itk::ProcessObject::DataObjectPointerArraySizeType
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
Definition: itkProcessObject.h:190
itkDataObject.h
itk::ProcessObject::m_IndexedInputs
std::vector< DataObjectPointerMap::iterator > m_IndexedInputs
Definition: itkProcessObject.h:911
itk::ProcessObject::m_Outputs
DataObjectPointerMap m_Outputs
Definition: itkProcessObject.h:909
itk::ProcessObject::DataObjectPointerMap
std::map< DataObjectIdentifierType, DataObjectPointer > DataObjectPointerMap
Definition: itkProcessObject.h:904
itk::ThreadIdType
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
itk::ProcessObject::m_MultiThreader
MultiThreaderType::Pointer m_MultiThreader
Definition: itkProcessObject.h:932
itk::ITK_MAX_THREADS
constexpr std::vcl_size_t ITK_MAX_THREADS
Definition: itkThreadSupport.h:74
itk::ProcessObject::NameSet
std::set< DataObjectIdentifierType > NameSet
Definition: itkProcessObject.h:921
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::ProcessObject::m_AbortGenerateData
bool m_AbortGenerateData
Definition: itkProcessObject.h:927
itk::InputDataObjectIterator
A forward iterator over inputs of a ProcessObject.
Definition: itkInputDataObjectIterator.h:30
itk::ProcessObject::ReleaseDataFlagOn
void ReleaseDataFlagOn()
Definition: itkProcessObject.h:453
itk::TimeStamp
Generate a unique, increasing time value.
Definition: itkTimeStamp.h:60
itk::ProcessObject::GetPrimaryOutput
DataObject * GetPrimaryOutput()
Definition: itkProcessObject.h:724
itk::DataObject::DataObjectIdentifierType
std::string DataObjectIdentifierType
Definition: itkDataObject.h:299
itk::DataObjectConstIterator
A forward iterator over the DataObject of a ProcessObject.
Definition: itkDataObjectConstIterator.h:30
itk::ProcessObject::m_CachedInputReleaseDataFlags
std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags
Definition: itkProcessObject.h:915
itk::ProcessObject::GetInput
const DataObject * GetInput(DataObjectPointerArraySizeType idx) const
Definition: itkProcessObject.h:540
itk::ProcessObject::ReleaseDataFlagOff
void ReleaseDataFlagOff()
Definition: itkProcessObject.h:458
itk::OutputDataObjectConstIterator
A forward iterator over outputs of a ProcessObject.
Definition: itkOutputDataObjectConstIterator.h:30
itk::ProcessObject::GetPrimaryOutput
const DataObject * GetPrimaryOutput() const
Definition: itkProcessObject.h:729
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::ProcessObject::EnlargeOutputRequestedRegion
virtual void EnlargeOutputRequestedRegion(DataObject *)
Definition: itkProcessObject.h:412
itkMultiThreaderBase.h
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:135
itk::OutputDataObjectIterator
A forward iterator over outputs of a ProcessObject.
Definition: itkOutputDataObjectIterator.h:30
itk::ProcessObject
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:60
itkNumericTraits.h
itk::ProcessObject::m_RequiredInputNames
NameSet m_RequiredInputNames
Definition: itkProcessObject.h:924
itk::ProcessObject::GetMultiThreader
MultiThreaderType * GetMultiThreader() const
Definition: itkProcessObject.h:494
itk::ProcessObject::m_NumberOfWorkUnits
ThreadIdType m_NumberOfWorkUnits
Definition: itkProcessObject.h:933
itk::ProcessObject::GetPrimaryInputName
virtual const char * GetPrimaryInputName() const
Definition: itkProcessObject.h:605
itk::ProcessObject::m_NumberOfRequiredOutputs
DataObjectPointerArraySizeType m_NumberOfRequiredOutputs
Definition: itkProcessObject.h:918
itk::DataObject::Pointer
SmartPointer< Self > Pointer
Definition: itkDataObject.h:296
itk::ProcessObject::GetPrimaryInput
DataObject * GetPrimaryInput()
Definition: itkProcessObject.h:590
itk::ProcessObject::m_Inputs
DataObjectPointerMap m_Inputs
Definition: itkProcessObject.h:908
itkDomainThreader.h
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:288
itk::ProcessObject::GetPrimaryOutputName
virtual const char * GetPrimaryOutputName() const
Definition: itkProcessObject.h:701