ITK  4.13.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 "itkMultiThreader.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:
143 
145  itkTypeMacro(ProcessObject, Object);
146 
149 
151  // typedef std::vector< const DataObject * > ConstDataObjectPointerArray;
152 
154  typedef std::vector< DataObjectPointer > DataObjectPointerArray;
155 
157 
159  typedef std::vector< DataObjectIdentifierType > NameArray;
160 
162  typedef MultiThreader MultiThreaderType;
163 
169  NameArray GetInputNames() const;
170 
172  NameArray GetRequiredInputNames() const;
173 
179  DataObjectPointerArray GetInputs();
180 
182  bool HasInput( const DataObjectIdentifierType & key ) const;
183 
184  typedef DataObjectPointerArray::size_type DataObjectPointerArraySizeType;
185 
196  DataObjectPointerArraySizeType GetNumberOfInputs() const;
197 
199  DataObjectPointerArraySizeType GetNumberOfOutputs() const;
200 
206  NameArray GetOutputNames() const;
207 
213  DataObjectPointerArray GetOutputs();
214 
216  bool HasOutput( const DataObjectIdentifierType & key ) const;
217 
219  DataObjectPointerArray GetIndexedInputs();
220 
234  DataObjectPointerArraySizeType GetNumberOfIndexedInputs() const;
235 
245  virtual DataObjectPointerArraySizeType GetNumberOfValidRequiredInputs() const;
246 
248  DataObjectPointerArray GetIndexedOutputs();
249 
251  DataObjectPointerArraySizeType GetNumberOfIndexedOutputs() const;
252 
268  virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx);
269 
275  itkSetMacro(AbortGenerateData, bool);
276 
278  itkGetConstReferenceMacro(AbortGenerateData, bool);
279 
281  itkBooleanMacro(AbortGenerateData);
282 
295 #if ! defined ( ITK_FUTURE_LEGACY_REMOVE )
296  void SetProgress(float progress)
297  {
298  // Clamp the value to be between 0 and 1.
299  m_Progress = std::max(progress, 0.0f);
300  m_Progress = std::min(m_Progress, 1.0f);
301  }
302 #endif
303 
304 
310  itkGetConstReferenceMacro(Progress, float);
311 
318  void UpdateProgress(float progress);
319 
341  virtual void Update();
342 
352  virtual void UpdateLargestPossibleRegion();
353 
369  virtual void UpdateOutputInformation();
370 
373  virtual void PropagateRequestedRegion(DataObject *output);
374 
376  virtual void UpdateOutputData(DataObject *output);
377 
387  virtual void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) ){}
388 
395  virtual void ResetPipeline();
396 
413  virtual DataObjectPointer MakeOutput( const DataObjectIdentifierType & );
414 
420  virtual void SetReleaseDataFlag(bool flag);
421  virtual bool GetReleaseDataFlag() const;
422  void ReleaseDataFlagOn() { this->SetReleaseDataFlag(true); }
423  void ReleaseDataFlagOff() { this->SetReleaseDataFlag(false); }
425 
438  itkSetMacro(ReleaseDataBeforeUpdateFlag, bool);
439  itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool);
440  itkBooleanMacro(ReleaseDataBeforeUpdateFlag);
442 
444  itkSetClampMacro(NumberOfThreads, ThreadIdType, 1, ITK_MAX_THREADS);
445  itkGetConstReferenceMacro(NumberOfThreads, ThreadIdType);
447 
450  { return m_Threader; }
451 
458  virtual void PrepareOutputs();
459 
460 protected:
461  ProcessObject();
462  ~ProcessObject() ITK_OVERRIDE;
463 
474  template< typename TDomainPartitioner, typename TAssociate >
475  class ProcessObjectDomainThreader: public DomainThreader< TDomainPartitioner, TAssociate >
476  {
477  public:
483 
484  typedef typename Superclass::DomainPartitionerType DomainPartitionerType;
485  typedef typename Superclass::DomainType DomainType;
486 
489 
490  protected:
492  virtual ~ProcessObjectDomainThreader();
493 
496  virtual void DetermineNumberOfThreadsUsed();
497 
498  private:
499  ITK_DISALLOW_COPY_AND_ASSIGN(ProcessObjectDomainThreader);
500  };
501 
502  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
503 
504  //
505  // Input Methods
506  //
507 
512  DataObject * GetInput(const DataObjectIdentifierType & key);
513  const DataObject * GetInput(const DataObjectIdentifierType & key) const;
514 
518  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : ITK_NULLPTR; }
520  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : ITK_NULLPTR; }
522 
529  virtual void SetInput(const DataObjectIdentifierType & key, DataObject *input);
530  virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input);
531 
533  virtual void AddInput(DataObject *input);
534 
543  virtual void PushBackInput(const DataObject *input);
544  virtual void PopBackInput();
545  virtual void PushFrontInput(const DataObject *input);
546  virtual void PopFrontInput();
547 
554  virtual void RemoveInput(const DataObjectIdentifierType & key);
555  virtual void RemoveInput(DataObjectPointerArraySizeType);
556 
559  { return m_IndexedInputs[0]->second; }
560  const DataObject * GetPrimaryInput() const
561  { return m_IndexedInputs[0]->second; }
563 
565  virtual void SetPrimaryInputName(const DataObjectIdentifierType & key);
566  virtual const char *GetPrimaryInputName( void ) const
567  { return this->m_IndexedInputs[0]->first.c_str(); }
569 
571  virtual void SetPrimaryInput(DataObject *input);
572 
579  void SetNumberOfIndexedInputs(DataObjectPointerArraySizeType num);
580 
590  virtual void SetNumberOfRequiredInputs(DataObjectPointerArraySizeType);
591  itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType);
592 
593 
598  bool RemoveRequiredInputName( const DataObjectIdentifierType & );
599 
601  bool IsRequiredInputName( const DataObjectIdentifierType & ) const;
602 
607  void SetRequiredInputNames( const NameArray & );
608 
619  bool AddRequiredInputName( const DataObjectIdentifierType & );
620  bool AddRequiredInputName( const DataObjectIdentifierType &, DataObjectPointerArraySizeType idx );
621 
632  void AddOptionalInputName( const DataObjectIdentifierType & );
633  void AddOptionalInputName( const DataObjectIdentifierType &, DataObjectPointerArraySizeType idx );
634 
635 
636  //
637  // Output Methods
638  //
639 
641  DataObject * GetOutput(const DataObjectIdentifierType & key);
642  const DataObject * GetOutput(const DataObjectIdentifierType & key) const;
644 
646  virtual void SetPrimaryOutputName(const DataObjectIdentifierType & key);
647  virtual const char *GetPrimaryOutputName( void ) const
648  { return this->m_IndexedOutputs[0]->first.c_str(); }
650 
652  DataObject * GetOutput(DataObjectPointerArraySizeType idx);
653  const DataObject * GetOutput(DataObjectPointerArraySizeType idx) const;
655 
657  virtual void SetOutput(const DataObjectIdentifierType & key, DataObject *output);
658 
660  virtual void RemoveOutput(const DataObjectIdentifierType & key);
661 
664  { return m_IndexedOutputs[0]->second; }
665  const DataObject * GetPrimaryOutput() const
666  { return m_IndexedOutputs[0]->second; }
668 
670  virtual void SetPrimaryOutput(DataObject *output);
671 
674  virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output);
675 
676  virtual void AddOutput(DataObject *output);
677 
678  virtual void RemoveOutput(DataObjectPointerArraySizeType idx);
679 
680  itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
681  itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
682 
684  void SetNumberOfIndexedOutputs(DataObjectPointerArraySizeType num);
685 
686 
687  DataObjectIdentifierType MakeNameFromInputIndex( DataObjectPointerArraySizeType idx ) const;
688  DataObjectIdentifierType MakeNameFromOutputIndex( DataObjectPointerArraySizeType idx ) const;
689  DataObjectPointerArraySizeType MakeIndexFromInputName( const DataObjectIdentifierType & name ) const;
690  DataObjectPointerArraySizeType MakeIndexFromOutputName( const DataObjectIdentifierType & name ) const;
691  bool IsIndexedInputName( const DataObjectIdentifierType & ) const;
692  bool IsIndexedOutputName( const DataObjectIdentifierType & ) const;
693 
695  itkLegacyMacro(virtual void RemoveOutput(DataObject *output));
696 
698  itkLegacyMacro(void SetNumberOfOutputs(DataObjectPointerArraySizeType num));
699 
703  itkLegacyMacro(virtual void RemoveInput(DataObject *input));
704 
706  itkLegacyMacro(void SetNumberOfInputs(DataObjectPointerArraySizeType num));
707 
708  //
709  // Pipeline Methods
710  //
711 
723  virtual void VerifyPreconditions();
724 
735  virtual void VerifyInputInformation();
736 
750  virtual void GenerateInputRequestedRegion();
751 
763  virtual void GenerateOutputRequestedRegion(DataObject *output);
764 
775  virtual void GenerateOutputInformation();
776 
778  virtual void GenerateData() {}
779 
784  virtual void PropagateResetPipeline();
785 
797  virtual void ReleaseInputs();
798 
807  virtual void CacheInputReleaseDataFlags();
808 
812  virtual void RestoreInputReleaseDataFlags();
813 
820 
823 
824 private:
825  ITK_DISALLOW_COPY_AND_ASSIGN(ProcessObject);
826 
827  DataObjectIdentifierType MakeNameFromIndex( DataObjectPointerArraySizeType ) const;
828  DataObjectPointerArraySizeType MakeIndexFromName( const DataObjectIdentifierType & ) const;
829 
831  typedef std::map< DataObjectIdentifierType, DataObjectPointer > DataObjectPointerMap;
832 
833 
837 
838  std::vector< DataObjectPointerMap::iterator > m_IndexedInputs;
839  std::vector< DataObjectPointerMap::iterator > m_IndexedOutputs;
840 
842  std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags;
843 
846 
848  typedef std::set< DataObjectIdentifierType > NameSet;
849 
852 
855  float m_Progress;
856 
859  MultiThreaderType::Pointer m_Threader;
861 
864 
866  friend class DataObject;
867 
871 
872  friend class DataObjectIterator;
875 
876  friend class TestProcessObject;
877 };
878 } // end namespace itk
879 
880 #endif
DataObjectPointerMap m_Inputs
DataObjectPointerArraySizeType m_NumberOfRequiredInputs
DataObject::DataObjectIdentifierType DataObjectIdentifierType
Multi-threaded processing on a domain by processing sub-domains per thread.
std::string DataObjectIdentifierType
#define ITK_MAX_THREADS
DataObject * GetPrimaryOutput()
Multi-threaded processing on a domain by processing sub-domains per thread.
std::vector< DataObjectIdentifierType > NameArray
virtual const char * GetPrimaryInputName(void) const
const DataObject * GetPrimaryInput() const
A forward iterator over outputs of a ProcessObject.
DomainThreader< TDomainPartitioner, ProcessObject::Self > Superclass
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags
DataObject::Pointer DataObjectPointer
DataObjectPointerMap m_Outputs
DataObject * GetPrimaryInput()
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:39
TimeStamp m_OutputInformationMTime
const DataObject * GetInput(DataObjectPointerArraySizeType idx) const
SmartPointer< Self > Pointer
MultiThreaderType * GetMultiThreader() const
A forward iterator over the DataObject of a ProcessObject.
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
DataObject * GetInput(DataObjectPointerArraySizeType idx)
MultiThreaderType::Pointer m_Threader
SmartPointer< const Self > ConstPointer
virtual void EnlargeOutputRequestedRegion(DataObject *)
Generate a unique, increasing time value.
Definition: itkTimeStamp.h:59
std::map< DataObjectIdentifierType, DataObjectPointer > DataObjectPointerMap
virtual const char * GetPrimaryOutputName(void) const
unsigned int ThreadIdType
Definition: itkIntTypes.h:159
A forward iterator over inputs of a ProcessObject.
ThreadIdType m_NumberOfThreads
A forward iterator over outputs of a ProcessObject.
DataObjectPointerArraySizeType m_NumberOfRequiredOutputs
std::vector< DataObjectPointer > DataObjectPointerArray
virtual void GenerateData()
Control indentation during Print() invocation.
Definition: itkIndent.h:49
MultiThreader MultiThreaderType
std::vector< DataObjectPointerMap::iterator > m_IndexedOutputs
A forward iterator over the DataObject of a ProcessObject.
A forward iterator over inputs of a ProcessObject.
Superclass::DomainPartitionerType DomainPartitionerType
const DataObject * GetPrimaryOutput() const
Base class for most ITK classes.
Definition: itkObject.h:59
Base class for all data objects in ITK.
std::set< DataObjectIdentifierType > NameSet
std::vector< DataObjectPointerMap::iterator > m_IndexedInputs
void SetProgress(float progress)