ITK  5.0.0
Insight Segmentation and Registration 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 GetInputNames() const;
172 
174  NameArray GetRequiredInputNames() const;
175 
181  DataObjectPointerArray GetInputs();
182 
184  bool HasInput( const DataObjectIdentifierType & key ) const;
185 
186  using DataObjectPointerArraySizeType = DataObjectPointerArray::size_type;
187 
198  DataObjectPointerArraySizeType GetNumberOfInputs() const;
199 
201  DataObjectPointerArraySizeType GetNumberOfOutputs() const;
202 
208  NameArray GetOutputNames() const;
209 
215  DataObjectPointerArray GetOutputs();
216 
218  bool HasOutput( const DataObjectIdentifierType & key ) const;
219 
221  DataObjectPointerArray GetIndexedInputs();
222 
236  DataObjectPointerArraySizeType GetNumberOfIndexedInputs() const;
237 
247  virtual DataObjectPointerArraySizeType GetNumberOfValidRequiredInputs() const;
248 
250  DataObjectPointerArray GetIndexedOutputs();
251 
253  DataObjectPointerArraySizeType GetNumberOfIndexedOutputs() const;
254 
270  virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx);
271 
277  itkSetMacro(AbortGenerateData, bool);
278 
280  itkGetConstReferenceMacro(AbortGenerateData, bool);
281 
283  itkBooleanMacro(AbortGenerateData);
284 
297 #if ! defined ( ITK_LEGACY_REMOVE )
298  void SetProgress(float progress)
299  {
300  // Clamp the value to be between 0 and 1.
301  m_Progress = std::max(progress, 0.0f);
302  m_Progress = std::min(m_Progress, 1.0f);
303  }
304 #endif
305 
306 
312  itkGetConstReferenceMacro(Progress, float);
313 
320  void UpdateProgress(float progress);
321 
343  virtual void Update();
344 
354  virtual void UpdateLargestPossibleRegion();
355 
371  virtual void UpdateOutputInformation();
372 
375  virtual void PropagateRequestedRegion(DataObject *output);
376 
378  virtual void UpdateOutputData(DataObject *output);
379 
389  virtual void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) ){}
390 
397  virtual void ResetPipeline();
398 
415  virtual DataObjectPointer MakeOutput( const DataObjectIdentifierType & );
416 
422  virtual void SetReleaseDataFlag(bool flag);
423  virtual bool GetReleaseDataFlag() const;
424  void ReleaseDataFlagOn() { this->SetReleaseDataFlag(true); }
425  void ReleaseDataFlagOff() { this->SetReleaseDataFlag(false); }
427 
440  itkSetMacro(ReleaseDataBeforeUpdateFlag, bool);
441  itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool);
442  itkBooleanMacro(ReleaseDataBeforeUpdateFlag);
444 
446  itkSetClampMacro(NumberOfWorkUnits, ThreadIdType, 1, ITK_MAX_THREADS);
447  itkGetConstReferenceMacro(NumberOfWorkUnits, ThreadIdType);
449 
450 #if !defined( ITK_LEGACY_REMOVE ) || defined( ITKV4_COMPATIBILITY )
451  itkLegacyMacro(void SetNumberOfThreads(ThreadIdType count))
452  {
453  this->SetNumberOfWorkUnits(count);
454  }
455 
456  itkLegacyMacro(ThreadIdType GetNumberOfThreads() const)
457  {
458  return this->GetNumberOfWorkUnits();
459  }
460 #endif // !ITK_LEGACY_REMOVE
461 
464  { return m_MultiThreader; }
465 
467  void SetMultiThreader(MultiThreaderType* threader);
468 
475  virtual void PrepareOutputs();
476 
477 protected:
478  ProcessObject();
479  ~ProcessObject() override;
480 
481  void PrintSelf(std::ostream & os, Indent indent) const override;
482 
483  //
484  // Input Methods
485  //
486 
491  DataObject * GetInput(const DataObjectIdentifierType & key);
492  const DataObject * GetInput(const DataObjectIdentifierType & key) const;
493 
497  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : nullptr; }
499  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : nullptr; }
501 
508  virtual void SetInput(const DataObjectIdentifierType & key, DataObject *input);
509  virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input);
510 
512  virtual void AddInput(DataObject *input);
513 
522  virtual void PushBackInput(const DataObject *input);
523  virtual void PopBackInput();
524  virtual void PushFrontInput(const DataObject *input);
525  virtual void PopFrontInput();
526 
533  virtual void RemoveInput(const DataObjectIdentifierType & key);
534  virtual void RemoveInput(DataObjectPointerArraySizeType);
535 
538  { return m_IndexedInputs[0]->second; }
539  const DataObject * GetPrimaryInput() const
540  { return m_IndexedInputs[0]->second; }
542 
544  virtual void SetPrimaryInputName(const DataObjectIdentifierType & key);
545  virtual const char *GetPrimaryInputName() const
546  { return this->m_IndexedInputs[0]->first.c_str(); }
548 
550  virtual void SetPrimaryInput(DataObject *input);
551 
558  void SetNumberOfIndexedInputs(DataObjectPointerArraySizeType num);
559 
569  virtual void SetNumberOfRequiredInputs(DataObjectPointerArraySizeType);
570  itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType);
571 
572 
577  bool RemoveRequiredInputName( const DataObjectIdentifierType & );
578 
580  bool IsRequiredInputName( const DataObjectIdentifierType & ) const;
581 
586  void SetRequiredInputNames( const NameArray & );
587 
598  bool AddRequiredInputName( const DataObjectIdentifierType & );
599  bool AddRequiredInputName( const DataObjectIdentifierType &, DataObjectPointerArraySizeType idx );
600 
611  void AddOptionalInputName( const DataObjectIdentifierType & );
612  void AddOptionalInputName( const DataObjectIdentifierType &, DataObjectPointerArraySizeType idx );
613 
614 
615  //
616  // Output Methods
617  //
618 
620  DataObject * GetOutput(const DataObjectIdentifierType & key);
621  const DataObject * GetOutput(const DataObjectIdentifierType & key) const;
623 
625  virtual void SetPrimaryOutputName(const DataObjectIdentifierType & key);
626  virtual const char *GetPrimaryOutputName() const
627  { return this->m_IndexedOutputs[0]->first.c_str(); }
629 
631  DataObject * GetOutput(DataObjectPointerArraySizeType idx);
632  const DataObject * GetOutput(DataObjectPointerArraySizeType idx) const;
634 
636  virtual void SetOutput(const DataObjectIdentifierType & key, DataObject *output);
637 
639  virtual void RemoveOutput(const DataObjectIdentifierType & key);
640 
643  { return m_IndexedOutputs[0]->second; }
644  const DataObject * GetPrimaryOutput() const
645  { return m_IndexedOutputs[0]->second; }
647 
649  virtual void SetPrimaryOutput(DataObject *output);
650 
653  virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output);
654 
655  virtual void AddOutput(DataObject *output);
656 
657  virtual void RemoveOutput(DataObjectPointerArraySizeType idx);
658 
659  itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
660  itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
661 
663  void SetNumberOfIndexedOutputs(DataObjectPointerArraySizeType num);
664 
665 
666  DataObjectIdentifierType MakeNameFromInputIndex( DataObjectPointerArraySizeType idx ) const;
667  DataObjectIdentifierType MakeNameFromOutputIndex( DataObjectPointerArraySizeType idx ) const;
668  DataObjectPointerArraySizeType MakeIndexFromInputName( const DataObjectIdentifierType & name ) const;
669  DataObjectPointerArraySizeType MakeIndexFromOutputName( const DataObjectIdentifierType & name ) const;
670  bool IsIndexedInputName( const DataObjectIdentifierType & ) const;
671  bool IsIndexedOutputName( const DataObjectIdentifierType & ) const;
672 
673  //
674  // Pipeline Methods
675  //
676 
688  virtual void VerifyPreconditions() ITKv5_CONST;
689 
700  virtual void VerifyInputInformation() ITKv5_CONST;
701 
715  virtual void GenerateInputRequestedRegion();
716 
728  virtual void GenerateOutputRequestedRegion(DataObject *output);
729 
740  virtual void GenerateOutputInformation();
741 
743  virtual void GenerateData() {}
744 
749  virtual void PropagateResetPipeline();
750 
762  virtual void ReleaseInputs();
763 
772  virtual void CacheInputReleaseDataFlags();
773 
777  virtual void RestoreInputReleaseDataFlags();
778 
785 
788 
789 private:
790  DataObjectIdentifierType MakeNameFromIndex( DataObjectPointerArraySizeType ) const;
791  DataObjectPointerArraySizeType MakeIndexFromName( const DataObjectIdentifierType & ) const;
792 
794  using DataObjectPointerMap = std::map< DataObjectIdentifierType, DataObjectPointer >;
795 
796 
800 
801  std::vector< DataObjectPointerMap::iterator > m_IndexedInputs;
802  std::vector< DataObjectPointerMap::iterator > m_IndexedOutputs;
803 
805  std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags;
806 
809 
811  using NameSet = std::set< DataObjectIdentifierType >;
812 
815 
818  float m_Progress;
819 
824 
827 
829  friend class DataObject;
830 
834 
835  friend class DataObjectIterator;
838 
839  friend class TestProcessObject;
840 };
841 } // end namespace itk
842 
843 #endif
DataObjectPointerMap m_Inputs
DataObjectPointerArraySizeType m_NumberOfRequiredInputs
DataObject::DataObjectIdentifierType DataObjectIdentifierType
Light weight base class for most itk classes.
ThreadIdType m_NumberOfWorkUnits
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
DataObject * GetPrimaryOutput()
std::vector< DataObjectPointer > DataObjectPointerArray
virtual const char * GetPrimaryInputName() const
const DataObject * GetPrimaryInput() const
A forward iterator over outputs of a ProcessObject.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags
DataObjectPointerMap m_Outputs
DataObject * GetPrimaryInput()
std::vector< DataObjectIdentifierType > NameArray
MultiThreaderType::Pointer m_MultiThreader
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:40
TimeStamp m_OutputInformationMTime
constexpr std::vcl_size_t ITK_MAX_THREADS
const DataObject * GetInput(DataObjectPointerArraySizeType idx) const
std::map< DataObjectIdentifierType, DataObjectPointer > DataObjectPointerMap
MultiThreaderType * GetMultiThreader() const
A forward iterator over the DataObject of a ProcessObject.
DataObject * GetInput(DataObjectPointerArraySizeType idx)
virtual void EnlargeOutputRequestedRegion(DataObject *)
Generate a unique, increasing time value.
Definition: itkTimeStamp.h:60
A class for performing multithreaded execution.
unsigned int ThreadIdType
Definition: itkIntTypes.h:99
A forward iterator over inputs of a ProcessObject.
A forward iterator over outputs of a ProcessObject.
DataObjectPointerArraySizeType m_NumberOfRequiredOutputs
Control indentation during Print() invocation.
Definition: itkIndent.h:49
std::vector< DataObjectPointerMap::iterator > m_IndexedOutputs
A forward iterator over the DataObject of a ProcessObject.
A forward iterator over inputs of a ProcessObject.
const DataObject * GetPrimaryOutput() const
Base class for most ITK classes.
Definition: itkObject.h:60
SmartPointer< Self > Pointer
std::set< DataObjectIdentifierType > NameSet
std::string DataObjectIdentifierType
Base class for all data objects in ITK.
virtual const char * GetPrimaryOutputName() const
std::vector< DataObjectPointerMap::iterator > m_IndexedInputs