ITK  4.12.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  ITK_DISALLOW_COPY_AND_ASSIGN(ProcessObjectDomainThreader);
497  };
498 
499  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
500 
501  //
502  // Input Methods
503  //
504 
509  DataObject * GetInput(const DataObjectIdentifierType & key);
510  const DataObject * GetInput(const DataObjectIdentifierType & key) const;
511 
515  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : ITK_NULLPTR; }
517  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second.GetPointer() : ITK_NULLPTR; }
519 
526  virtual void SetInput(const DataObjectIdentifierType & key, DataObject *input);
527  virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input);
528 
530  virtual void AddInput(DataObject *input);
531 
540  virtual void PushBackInput(const DataObject *input);
541  virtual void PopBackInput();
542  virtual void PushFrontInput(const DataObject *input);
543  virtual void PopFrontInput();
544 
551  virtual void RemoveInput(const DataObjectIdentifierType & key);
552  virtual void RemoveInput(DataObjectPointerArraySizeType);
553 
556  { return m_IndexedInputs[0]->second; }
557  const DataObject * GetPrimaryInput() const
558  { return m_IndexedInputs[0]->second; }
560 
562  virtual void SetPrimaryInputName(const DataObjectIdentifierType & key);
563  virtual const char *GetPrimaryInputName( void ) const
564  { return this->m_IndexedInputs[0]->first.c_str(); }
566 
568  virtual void SetPrimaryInput(DataObject *input);
569 
576  void SetNumberOfIndexedInputs(DataObjectPointerArraySizeType num);
577 
587  virtual void SetNumberOfRequiredInputs(DataObjectPointerArraySizeType);
588  itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType);
589 
590 
592  bool AddRequiredInputName( const DataObjectIdentifierType & );
593 
598  bool RemoveRequiredInputName( const DataObjectIdentifierType & );
599 
601  bool IsRequiredInputName( const DataObjectIdentifierType & ) const;
602 
607  void SetRequiredInputNames( const NameArray & );
608 
609 
611  bool AddRequiredInputName( const DataObjectIdentifierType &, DataObjectPointerArraySizeType idx );
612 
613  //
614  // Output Methods
615  //
616 
618  DataObject * GetOutput(const DataObjectIdentifierType & key);
619  const DataObject * GetOutput(const DataObjectIdentifierType & key) const;
621 
623  virtual void SetPrimaryOutputName(const DataObjectIdentifierType & key);
624  virtual const char *GetPrimaryOutputName( void ) const
625  { return this->m_IndexedOutputs[0]->first.c_str(); }
627 
630  const DataObject * GetOutput(DataObjectPointerArraySizeType idx) const;
632 
634  virtual void SetOutput(const DataObjectIdentifierType & key, DataObject *output);
635 
637  virtual void RemoveOutput(const DataObjectIdentifierType & key);
638 
641  { return m_IndexedOutputs[0]->second; }
642  const DataObject * GetPrimaryOutput() const
643  { return m_IndexedOutputs[0]->second; }
645 
647  virtual void SetPrimaryOutput(DataObject *output);
648 
651  virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output);
652 
653  virtual void AddOutput(DataObject *output);
654 
655  virtual void RemoveOutput(DataObjectPointerArraySizeType idx);
656 
657  itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
658  itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
659 
661  void SetNumberOfIndexedOutputs(DataObjectPointerArraySizeType num);
662 
663 
664  DataObjectIdentifierType MakeNameFromInputIndex( DataObjectPointerArraySizeType idx ) const;
665  DataObjectIdentifierType MakeNameFromOutputIndex( DataObjectPointerArraySizeType idx ) const;
666  DataObjectPointerArraySizeType MakeIndexFromInputName( const DataObjectIdentifierType & name ) const;
667  DataObjectPointerArraySizeType MakeIndexFromOutputName( const DataObjectIdentifierType & name ) const;
668  bool IsIndexedInputName( const DataObjectIdentifierType & ) const;
669  bool IsIndexedOutputName( const DataObjectIdentifierType & ) const;
670 
672  itkLegacyMacro(virtual void RemoveOutput(DataObject *output));
673 
675  itkLegacyMacro(void SetNumberOfOutputs(DataObjectPointerArraySizeType num));
676 
680  itkLegacyMacro(virtual void RemoveInput(DataObject *input));
681 
683  itkLegacyMacro(void SetNumberOfInputs(DataObjectPointerArraySizeType num));
684 
685  //
686  // Pipeline Methods
687  //
688 
700  virtual void VerifyPreconditions();
701 
712  virtual void VerifyInputInformation();
713 
727  virtual void GenerateInputRequestedRegion();
728 
740  virtual void GenerateOutputRequestedRegion(DataObject *output);
741 
752  virtual void GenerateOutputInformation();
753 
755  virtual void GenerateData() {}
756 
761  virtual void PropagateResetPipeline();
762 
774  virtual void ReleaseInputs();
775 
784  virtual void CacheInputReleaseDataFlags();
785 
789  virtual void RestoreInputReleaseDataFlags();
790 
797 
800 
801 private:
802  ITK_DISALLOW_COPY_AND_ASSIGN(ProcessObject);
803 
804  DataObjectIdentifierType MakeNameFromIndex( DataObjectPointerArraySizeType ) const;
805  DataObjectPointerArraySizeType MakeIndexFromName( const DataObjectIdentifierType & ) const;
806 
808  typedef std::map< DataObjectIdentifierType, DataObjectPointer > DataObjectPointerMap;
809 
810 
814 
815  std::vector< DataObjectPointerMap::iterator > m_IndexedInputs;
816  std::vector< DataObjectPointerMap::iterator > m_IndexedOutputs;
817 
819  std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags;
820 
823 
825  typedef std::set< DataObjectIdentifierType > NameSet;
826 
829 
832  float m_Progress;
833 
838 
841 
843  friend class DataObject;
844 
848 
849  friend class DataObjectIterator;
852 
853  friend class TestProcessObject;
854 };
855 } // end namespace itk
856 
857 #endif
DataObjectPointerMap m_Inputs
DataObjectPointerArraySizeType m_NumberOfRequiredInputs
DataObject::DataObjectIdentifierType DataObjectIdentifierType
Multi-threaded processing on a domain by processing sub-domains per thread.
virtual void PrintSelf(std::ostream &os, Indent indent) const override
virtual const bool & GetReleaseDataFlag() const
#define ITK_MAX_THREADS
DataObject * GetPrimaryOutput()
Multi-threaded processing on a domain by processing sub-domains per thread.
std::vector< DataObjectIdentifierType > NameArray
virtual void UpdateOutputInformation()
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::vector< Pointer >::size_type DataObjectPointerArraySizeType
std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags
DataObject::Pointer DataObjectPointer
DataObjectPointerMap m_Outputs
std::string DataObjectIdentifierType
DataObject * GetPrimaryInput()
MultiThreader::Pointer m_Threader
TimeStamp m_OutputInformationMTime
SmartPointer< Self > Pointer
const DataObject * GetInput(DataObjectPointerArraySizeType idx) const
SmartPointer< Self > Pointer
virtual void ResetPipeline()
A forward iterator over the DataObject of a ProcessObject.
virtual void PropagateResetPipeline()
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
DataObject * GetInput(DataObjectPointerArraySizeType idx)
SmartPointer< const Self > ConstPointer
virtual void EnlargeOutputRequestedRegion(DataObject *)
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:39
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
Base class for all data objects in ITK.
virtual void PropagateRequestedRegion()
A forward iterator over outputs of a ProcessObject.
DataObjectPointerArraySizeType m_NumberOfRequiredOutputs
std::vector< DataObjectPointer > DataObjectPointerArray
virtual void GenerateData()
virtual void Update()
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
void SetReleaseDataFlag(bool flag)
const DataObject * GetPrimaryOutput() const
Base class for most ITK classes.
Definition: itkObject.h:59
std::set< DataObjectIdentifierType > NameSet
std::vector< DataObjectPointerMap::iterator > m_IndexedInputs
virtual void UpdateOutputData()
void SetProgress(float progress)