ITK  4.8.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 
166  NameArray GetInputNames() const;
167 
169  NameArray GetRequiredInputNames() const;
170 
176  DataObjectPointerArray GetInputs();
177 
179  bool HasInput( const DataObjectIdentifierType & key ) const;
180 
181  typedef DataObjectPointerArray::size_type DataObjectPointerArraySizeType;
182 
193  DataObjectPointerArraySizeType GetNumberOfInputs() const;
194 
196  DataObjectPointerArraySizeType GetNumberOfOutputs() const;
197 
203  NameArray GetOutputNames() const;
204 
210  DataObjectPointerArray GetOutputs();
211 
213  bool HasOutput( const DataObjectIdentifierType & key ) const;
214 
216  DataObjectPointerArray GetIndexedInputs();
217 
231  DataObjectPointerArraySizeType GetNumberOfIndexedInputs() const;
232 
242  virtual DataObjectPointerArraySizeType GetNumberOfValidRequiredInputs() const;
243 
245  DataObjectPointerArray GetIndexedOutputs();
246 
248  DataObjectPointerArraySizeType GetNumberOfIndexedOutputs() const;
249 
265  virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx);
266 
272  itkSetMacro(AbortGenerateData, bool);
273 
275  itkGetConstReferenceMacro(AbortGenerateData, bool);
276 
278  itkBooleanMacro(AbortGenerateData);
279 
292 #if ! defined ( ITK_FUTURE_LEGACY_REMOVE )
293  void SetProgress(float progress)
294  {
295  // Clamp the value to be between 0 and 1.
296  m_Progress = std::max(progress, 0.0f);
297  m_Progress = std::min(m_Progress, 1.0f);
298  }
299 #endif
300 
301 
307  itkGetConstReferenceMacro(Progress, float);
308 
315  void UpdateProgress(float progress);
316 
338  virtual void Update();
339 
349  virtual void UpdateLargestPossibleRegion();
350 
366  virtual void UpdateOutputInformation();
367 
370  virtual void PropagateRequestedRegion(DataObject *output);
371 
373  virtual void UpdateOutputData(DataObject *output);
374 
384  virtual void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) ){}
385 
392  virtual void ResetPipeline();
393 
410  virtual DataObjectPointer MakeOutput( const DataObjectIdentifierType & );
411 
417  virtual void SetReleaseDataFlag(bool flag);
418  virtual bool GetReleaseDataFlag() const;
419  void ReleaseDataFlagOn() { this->SetReleaseDataFlag(true); }
420  void ReleaseDataFlagOff() { this->SetReleaseDataFlag(false); }
422 
435  itkSetMacro(ReleaseDataBeforeUpdateFlag, bool);
436  itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool);
437  itkBooleanMacro(ReleaseDataBeforeUpdateFlag);
439 
441  itkSetClampMacro(NumberOfThreads, ThreadIdType, 1, ITK_MAX_THREADS);
442  itkGetConstReferenceMacro(NumberOfThreads, ThreadIdType);
444 
446  MultiThreader * GetMultiThreader() const
447  { return m_Threader; }
448 
455  virtual void PrepareOutputs();
456 
457 protected:
458  ProcessObject();
459  ~ProcessObject();
460 
471  template< typename TDomainPartitioner, typename TAssociate >
472  class ProcessObjectDomainThreader: public DomainThreader< TDomainPartitioner, TAssociate >
473  {
474  public:
480 
481  typedef typename Superclass::DomainPartitionerType DomainPartitionerType;
482  typedef typename Superclass::DomainType DomainType;
483 
486 
487  protected:
489  virtual ~ProcessObjectDomainThreader();
490 
493  virtual void DetermineNumberOfThreadsUsed();
494 
495  private:
496  ProcessObjectDomainThreader( const Self & ); // purposely not implemented
497  void operator=( const Self & ); // purposely not implemented
498  };
499 
500  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
501 
502  //
503  // Input Methods
504  //
505 
510  DataObject * GetInput(const DataObjectIdentifierType & key);
511  const DataObject * GetInput(const DataObjectIdentifierType & key) const;
512 
516  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second : ITK_NULLPTR; }
518  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second : ITK_NULLPTR; }
520 
527  virtual void SetInput(const DataObjectIdentifierType & key, DataObject *input);
528  virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input);
529 
531  virtual void AddInput(DataObject *input);
532 
541  virtual void PushBackInput(const DataObject *input);
542  virtual void PopBackInput();
543  virtual void PushFrontInput(const DataObject *input);
544  virtual void PopFrontInput();
545 
552  virtual void RemoveInput(const DataObjectIdentifierType & key);
553  virtual void RemoveInput(DataObjectPointerArraySizeType);
554 
557  { return m_IndexedInputs[0]->second; }
558  const DataObject * GetPrimaryInput() const
559  { return m_IndexedInputs[0]->second; }
561 
563  virtual void SetPrimaryInputName(const DataObjectIdentifierType & key);
564  virtual const char *GetPrimaryInputName( void ) const
565  { return this->m_IndexedInputs[0]->first.c_str(); }
567 
569  virtual void SetPrimaryInput(DataObject *input);
570 
577  void SetNumberOfIndexedInputs(DataObjectPointerArraySizeType num);
578 
588  virtual void SetNumberOfRequiredInputs(DataObjectPointerArraySizeType);
589  itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType);
590 
591 
593  bool AddRequiredInputName( const DataObjectIdentifierType & );
594 
599  bool RemoveRequiredInputName( const DataObjectIdentifierType & );
600 
602  bool IsRequiredInputName( const DataObjectIdentifierType & ) const;
603 
608  void SetRequiredInputNames( const NameArray & );
609 
610 
612  bool AddRequiredInputName( const DataObjectIdentifierType &, DataObjectPointerArraySizeType idx );
613 
614  //
615  // Output Methods
616  //
617 
619  DataObject * GetOutput(const DataObjectIdentifierType & key);
620  const DataObject * GetOutput(const DataObjectIdentifierType & key) const;
622 
624  virtual void SetPrimaryOutputName(const DataObjectIdentifierType & key);
625  virtual const char *GetPrimaryOutputName( void ) const
626  { return this->m_IndexedOutputs[0]->first.c_str(); }
628 
630  DataObject * GetOutput(DataObjectPointerArraySizeType idx);
631  const DataObject * GetOutput(DataObjectPointerArraySizeType idx) const;
633 
635  virtual void SetOutput(const DataObjectIdentifierType & key, DataObject *output);
636 
638  virtual void RemoveOutput(const DataObjectIdentifierType & key);
639 
642  { return m_IndexedOutputs[0]->second; }
643  const DataObject * GetPrimaryOutput() const
644  { return m_IndexedOutputs[0]->second; }
646 
648  virtual void SetPrimaryOutput(DataObject *output);
649 
652  virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output);
653 
654  virtual void AddOutput(DataObject *output);
655 
656  virtual void RemoveOutput(DataObjectPointerArraySizeType idx);
657 
658  itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
659  itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
660 
662  void SetNumberOfIndexedOutputs(DataObjectPointerArraySizeType num);
663 
664 
665  DataObjectIdentifierType MakeNameFromInputIndex( DataObjectPointerArraySizeType idx ) const;
666  DataObjectIdentifierType MakeNameFromOutputIndex( DataObjectPointerArraySizeType idx ) const;
667  DataObjectPointerArraySizeType MakeIndexFromInputName( const DataObjectIdentifierType & name ) const;
668  DataObjectPointerArraySizeType MakeIndexFromOutputName( const DataObjectIdentifierType & name ) const;
669  bool IsIndexedInputName( const DataObjectIdentifierType & ) const;
670  bool IsIndexedOutputName( const DataObjectIdentifierType & ) const;
671 
673  itkLegacyMacro(virtual void RemoveOutput(DataObject *output));
674 
676  itkLegacyMacro(void SetNumberOfOutputs(DataObjectPointerArraySizeType num));
677 
681  itkLegacyMacro(virtual void RemoveInput(DataObject *input));
682 
684  itkLegacyMacro(void SetNumberOfInputs(DataObjectPointerArraySizeType num));
685 
686  //
687  // Pipeline Methods
688  //
689 
701  virtual void VerifyPreconditions();
702 
713  virtual void VerifyInputInformation();
714 
728  virtual void GenerateInputRequestedRegion();
729 
741  virtual void GenerateOutputRequestedRegion(DataObject *output);
742 
753  virtual void GenerateOutputInformation();
754 
756  virtual void GenerateData() {}
757 
762  virtual void PropagateResetPipeline();
763 
775  virtual void ReleaseInputs();
776 
785  virtual void CacheInputReleaseDataFlags();
786 
790  virtual void RestoreInputReleaseDataFlags();
791 
798 
801 
802 private:
803  ProcessObject(const Self &); //purposely not implemented
804  void operator=(const Self &); //purposely not implemented
805 
806  DataObjectIdentifierType MakeNameFromIndex( DataObjectPointerArraySizeType ) const;
807  DataObjectPointerArraySizeType MakeIndexFromName( const DataObjectIdentifierType & ) const;
808 
810  typedef std::map< DataObjectIdentifierType, DataObjectPointer > DataObjectPointerMap;
811 
812 
816 
817  std::vector< DataObjectPointerMap::iterator > m_IndexedInputs;
818  std::vector< DataObjectPointerMap::iterator > m_IndexedOutputs;
819 
821  std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags;
822 
825 
827  typedef std::set< DataObjectIdentifierType > NameSet;
828 
831 
834  float m_Progress;
835 
838  MultiThreader::Pointer m_Threader;
840 
843 
845  friend class DataObject;
846 
850 
851  friend class DataObjectIterator;
854 
855  friend class TestProcessObject;
856 };
857 } // end namespace itk
858 
859 #endif
DataObjectPointerMap m_Inputs
DataObjectPointerArraySizeType m_NumberOfRequiredInputs
DataObject::DataObjectIdentifierType DataObjectIdentifierType
Multi-threaded processing on a domain by processing sub-domains per thread.
Light weight base class for most itk classes.
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
MultiThreader * GetMultiThreader() const
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()
MultiThreader::Pointer m_Threader
TimeStamp m_OutputInformationMTime
const DataObject * GetInput(DataObjectPointerArraySizeType idx) const
SmartPointer< Self > Pointer
A forward iterator over the DataObject of a ProcessObject.
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
DataObject * GetInput(DataObjectPointerArraySizeType idx)
SmartPointer< const Self > ConstPointer
virtual void EnlargeOutputRequestedRegion(DataObject *)
Generate a unique, increasing time value.
Definition: itkTimeStamp.h:58
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
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:57
Base class for all data objects in ITK.
std::set< DataObjectIdentifierType > NameSet
std::vector< DataObjectPointerMap::iterator > m_IndexedInputs
void SetProgress(float progress)