ITK  4.6.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 {
118 class ITKCommon_EXPORT ProcessObject:public Object
119 {
120 public:
126 
128  itkTypeMacro(ProcessObject, Object);
129 
132 
134  // typedef std::vector< const DataObject * > ConstDataObjectPointerArray;
135 
137  typedef std::vector< DataObjectPointer > DataObjectPointerArray;
138 
140 
142  typedef std::vector< DataObjectIdentifierType > NameArray;
143 
148  NameArray GetInputNames() const;
149 
151  NameArray GetRequiredInputNames() const;
152 
157  DataObjectPointerArray GetInputs();
158  // ConstDataObjectPointerArray GetInputs() const;
160 
162  bool HasInput( const DataObjectIdentifierType & key ) const;
163 
164  typedef DataObjectPointerArray::size_type DataObjectPointerArraySizeType;
165 
172  DataObjectPointerArraySizeType GetNumberOfInputs() const;
173 
174  DataObjectPointerArraySizeType GetNumberOfOutputs() const;
175 
180  NameArray GetOutputNames() const;
181 
186  DataObjectPointerArray GetOutputs();
187  // ConstDataObjectPointerArray GetOutputs() const;
189 
191  bool HasOutput( const DataObjectIdentifierType & key ) const;
192 
196  DataObjectPointerArray GetIndexedInputs();
197  // ConstDataObjectPointerArray GetIndexedInputs() const;
199 
204  DataObjectPointerArraySizeType GetNumberOfIndexedInputs() const;
205 
209  virtual DataObjectPointerArraySizeType GetNumberOfValidRequiredInputs() const;
210 
214  DataObjectPointerArray GetIndexedOutputs();
215  // ConstDataObjectPointerArray GetIndexedOutputs() const;
216  DataObjectPointerArraySizeType GetNumberOfIndexedOutputs() const;
218 
233  virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx);
234 
237  itkSetMacro(AbortGenerateData, bool);
238 
241  itkGetConstReferenceMacro(AbortGenerateData, bool);
242 
244  itkBooleanMacro(AbortGenerateData);
245 
258 #if ! defined ( ITK_FUTURE_LEGACY_REMOVE )
259  void SetProgress(float progress)
260  {
261  // Clamp the value to be between 0 and 1.
262  m_Progress = std::max(progress, 0.0f);
263  m_Progress = std::min(m_Progress, 1.0f);
264  }
265 #endif
266 
267 
271  itkGetConstReferenceMacro(Progress, float);
272 
278  void UpdateProgress(float progress);
279 
298  virtual void Update();
299 
306  virtual void UpdateLargestPossibleRegion();
307 
320  virtual void UpdateOutputInformation();
321 
324  virtual void PropagateRequestedRegion(DataObject *output);
325 
327  virtual void UpdateOutputData(DataObject *output);
328 
336  virtual void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) ){}
337 
341  virtual void ResetPipeline();
342 
357  virtual DataObjectPointer MakeOutput( const DataObjectIdentifierType & );
358 
364  virtual void SetReleaseDataFlag(bool flag);
365  virtual bool GetReleaseDataFlag() const;
366  void ReleaseDataFlagOn() { this->SetReleaseDataFlag(true); }
367  void ReleaseDataFlagOff() { this->SetReleaseDataFlag(false); }
369 
382  itkSetMacro(ReleaseDataBeforeUpdateFlag, bool);
383  itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool);
384  itkBooleanMacro(ReleaseDataBeforeUpdateFlag);
386 
388  itkSetClampMacro(NumberOfThreads, ThreadIdType, 1, ITK_MAX_THREADS);
389  itkGetConstReferenceMacro(NumberOfThreads, ThreadIdType);
391 
393  MultiThreader * GetMultiThreader() const
394  { return m_Threader; }
395 
402  virtual void PrepareOutputs();
403 
404 protected:
405  ProcessObject();
406  ~ProcessObject();
407 
418  template< typename TDomainPartitioner, typename TAssociate >
419  class ProcessObjectDomainThreader: public DomainThreader< TDomainPartitioner, TAssociate >
420  {
421  public:
427 
428  typedef typename Superclass::DomainPartitionerType DomainPartitionerType;
429  typedef typename Superclass::DomainType DomainType;
430 
433 
434  protected:
436  virtual ~ProcessObjectDomainThreader();
437 
440  virtual void DetermineNumberOfThreadsUsed();
441 
442  private:
443  ProcessObjectDomainThreader( const Self & ); // purposely not implemented
444  void operator=( const Self & ); // purposely not implemented
445  };
446 
447  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
448 
449  //
450  // Input Methods
451  //
452 
454  DataObject * GetInput(const DataObjectIdentifierType & key);
455  const DataObject * GetInput(const DataObjectIdentifierType & key) const;
457 
461  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second : ITK_NULLPTR; }
463  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second : ITK_NULLPTR; }
465 
467  virtual void SetInput(const DataObjectIdentifierType & key, DataObject *input);
468 
471  virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input);
472 
474  virtual void AddInput(DataObject *input);
475 
481  virtual void PushBackInput(const DataObject *input);
482  virtual void PopBackInput();
483  virtual void PushFrontInput(const DataObject *input);
484  virtual void PopFrontInput();
486 
493  virtual void RemoveInput(const DataObjectIdentifierType & key);
494  virtual void RemoveInput(DataObjectPointerArraySizeType);
495 
498  { return m_IndexedInputs[0]->second; }
499  const DataObject * GetPrimaryInput() const
500  { return m_IndexedInputs[0]->second; }
502 
504  virtual void SetPrimaryInputName(const DataObjectIdentifierType & key);
505  virtual const char *GetPrimaryInputName( void ) const
506  { return this->m_IndexedInputs[0]->first.c_str(); }
508 
510  virtual void SetPrimaryInput(DataObject *input);
511 
516  void SetNumberOfIndexedInputs(DataObjectPointerArraySizeType num);
517 
524  virtual void SetNumberOfRequiredInputs(DataObjectPointerArraySizeType);
525  itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType);
527 
530  bool AddRequiredInputName( const DataObjectIdentifierType & );
531  bool AddRequiredInputName( const DataObjectIdentifierType &, DataObjectPointerArraySizeType idx );
532  bool RemoveRequiredInputName( const DataObjectIdentifierType & );
533  bool IsRequiredInputName( const DataObjectIdentifierType & ) const;
534  void SetRequiredInputNames( const NameArray & );
536 
537  //
538  // Output Methods
539  //
540 
542  DataObject * GetOutput(const DataObjectIdentifierType & key);
543  const DataObject * GetOutput(const DataObjectIdentifierType & key) const;
545 
547  virtual void SetPrimaryOutputName(const DataObjectIdentifierType & key);
548  virtual const char *GetPrimaryOutputName( void ) const
549  { return this->m_IndexedOutputs[0]->first.c_str(); }
551 
553  DataObject * GetOutput(DataObjectPointerArraySizeType idx);
554  const DataObject * GetOutput(DataObjectPointerArraySizeType idx) const;
556 
558  virtual void SetOutput(const DataObjectIdentifierType & key, DataObject *output);
559 
561  virtual void RemoveOutput(const DataObjectIdentifierType & key);
562 
565  { return m_IndexedOutputs[0]->second; }
566  const DataObject * GetPrimaryOutput() const
567  { return m_IndexedOutputs[0]->second; }
569 
571  virtual void SetPrimaryOutput(DataObject *output);
572 
575  virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output);
576 
577  virtual void AddOutput(DataObject *output);
578 
579  virtual void RemoveOutput(DataObjectPointerArraySizeType idx);
580 
581  itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
582  itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
583 
585  void SetNumberOfIndexedOutputs(DataObjectPointerArraySizeType num);
586 
587 
588  DataObjectIdentifierType MakeNameFromInputIndex( DataObjectPointerArraySizeType idx ) const;
589  DataObjectIdentifierType MakeNameFromOutputIndex( DataObjectPointerArraySizeType idx ) const;
590  DataObjectPointerArraySizeType MakeIndexFromInputName( const DataObjectIdentifierType & name ) const;
591  DataObjectPointerArraySizeType MakeIndexFromOutputName( const DataObjectIdentifierType & name ) const;
592  bool IsIndexedInputName( const DataObjectIdentifierType & ) const;
593  bool IsIndexedOutputName( const DataObjectIdentifierType & ) const;
594 
596  itkLegacyMacro(virtual void RemoveOutput(DataObject *output));
597 
599  itkLegacyMacro(void SetNumberOfOutputs(DataObjectPointerArraySizeType num));
600 
604  itkLegacyMacro(virtual void RemoveInput(DataObject *input));
605 
607  itkLegacyMacro(void SetNumberOfInputs(DataObjectPointerArraySizeType num));
608 
609  //
610  // Pipeline Methods
611  //
612 
624  virtual void VerifyPreconditions();
625 
636  virtual void VerifyInputInformation();
637 
651  virtual void GenerateInputRequestedRegion();
652 
664  virtual void GenerateOutputRequestedRegion(DataObject *output);
665 
676  virtual void GenerateOutputInformation();
677 
679  virtual void GenerateData() {}
680 
685  virtual void PropagateResetPipeline();
686 
698  virtual void ReleaseInputs();
699 
708  virtual void CacheInputReleaseDataFlags();
709 
713  virtual void RestoreInputReleaseDataFlags();
714 
721 
724 
725 private:
726  ProcessObject(const Self &); //purposely not implemented
727  void operator=(const Self &); //purposely not implemented
728 
729  DataObjectIdentifierType MakeNameFromIndex( DataObjectPointerArraySizeType ) const;
730  DataObjectPointerArraySizeType MakeIndexFromName( const DataObjectIdentifierType & ) const;
731 
733  typedef std::map< DataObjectIdentifierType, DataObjectPointer > DataObjectPointerMap;
734 
735 
739 
740  std::vector< DataObjectPointerMap::iterator > m_IndexedInputs;
741  std::vector< DataObjectPointerMap::iterator > m_IndexedOutputs;
742 
744  std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags;
745 
748 
750  typedef std::set< DataObjectIdentifierType > NameSet;
751 
754 
757  float m_Progress;
758 
761  MultiThreader::Pointer m_Threader;
763 
766 
768  friend class DataObject;
769 
773 
774  friend class DataObjectIterator;
777 
778  friend class TestProcessObject;
779 };
780 } // end namespace itk
781 
782 #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
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.
unsigned int ThreadIdType
Definition: itkIntTypes.h:159
std::set< DataObjectIdentifierType > NameSet
std::vector< DataObjectPointerMap::iterator > m_IndexedInputs
void SetProgress(float progress)