ITK  4.4.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 
40 namespace itk
41 {
117 class ITKCommon_EXPORT ProcessObject:public Object
118 {
119 public:
125 
127  itkTypeMacro(ProcessObject, Object);
128 
131 
133  // typedef std::vector< const DataObject * > ConstDataObjectPointerArray;
134 
136  typedef std::vector< DataObjectPointer > DataObjectPointerArray;
137 
139 
141  typedef std::vector< DataObjectIdentifierType > NameArray;
142 
147  NameArray GetInputNames() const;
148 
150  NameArray GetRequiredInputNames() const;
151 
156  DataObjectPointerArray GetInputs();
157  // ConstDataObjectPointerArray GetInputs() const;
159 
161  bool HasInput( const DataObjectIdentifierType & key ) const;
162 
163  typedef DataObjectPointerArray::size_type DataObjectPointerArraySizeType;
164 
171  DataObjectPointerArraySizeType GetNumberOfInputs() const;
172 
173  DataObjectPointerArraySizeType GetNumberOfOutputs() const;
174 
179  NameArray GetOutputNames() const;
180 
185  DataObjectPointerArray GetOutputs();
186  // ConstDataObjectPointerArray GetOutputs() const;
188 
190  bool HasOutput( const DataObjectIdentifierType & key ) const;
191 
195  DataObjectPointerArray GetIndexedInputs();
196  // ConstDataObjectPointerArray GetIndexedInputs() const;
198 
203  DataObjectPointerArraySizeType GetNumberOfIndexedInputs() const;
204 
208  virtual DataObjectPointerArraySizeType GetNumberOfValidRequiredInputs() const;
209 
213  DataObjectPointerArray GetIndexedOutputs();
214  // ConstDataObjectPointerArray GetIndexedOutputs() const;
215  DataObjectPointerArraySizeType GetNumberOfIndexedOutputs() const;
217 
232  virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx);
233 
236  itkSetMacro(AbortGenerateData, bool);
237 
240  itkGetConstReferenceMacro(AbortGenerateData, bool);
241 
243  itkBooleanMacro(AbortGenerateData);
244 
249  itkSetClampMacro(Progress, float, 0.0f, 1.0f);
250 
254  itkGetConstReferenceMacro(Progress, float);
255 
261  void UpdateProgress(float amount);
262 
281  virtual void Update();
282 
289  virtual void UpdateLargestPossibleRegion();
290 
303  virtual void UpdateOutputInformation();
304 
307  virtual void PropagateRequestedRegion(DataObject *output);
308 
310  virtual void UpdateOutputData(DataObject *output);
311 
319  virtual void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) ){}
320 
324  virtual void ResetPipeline();
325 
340  virtual DataObjectPointer MakeOutput( const DataObjectIdentifierType & );
341 
347  virtual void SetReleaseDataFlag(bool flag);
348  virtual bool GetReleaseDataFlag() const;
349  void ReleaseDataFlagOn() { this->SetReleaseDataFlag(true); }
350  void ReleaseDataFlagOff() { this->SetReleaseDataFlag(false); }
352 
365  itkSetMacro(ReleaseDataBeforeUpdateFlag, bool);
366  itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool);
367  itkBooleanMacro(ReleaseDataBeforeUpdateFlag);
369 
371  itkSetClampMacro(NumberOfThreads, ThreadIdType, 1, ITK_MAX_THREADS);
372  itkGetConstReferenceMacro(NumberOfThreads, ThreadIdType);
374 
376  MultiThreader * GetMultiThreader() const
377  { return m_Threader; }
378 
385  virtual void PrepareOutputs();
386 
387 protected:
388  ProcessObject();
389  ~ProcessObject();
390 
401  template< class TDomainPartitioner, class TAssociate >
402  class ProcessObjectDomainThreader: public DomainThreader< TDomainPartitioner, TAssociate >
403  {
404  public:
410 
411  typedef typename Superclass::DomainPartitionerType DomainPartitionerType;
412  typedef typename Superclass::DomainType DomainType;
413 
416 
417  protected:
419  virtual ~ProcessObjectDomainThreader();
420 
423  virtual void DetermineNumberOfThreadsUsed();
424 
425  private:
426  ProcessObjectDomainThreader( const Self & ); // purposely not implemented
427  void operator=( const Self & ); // purposely not implemented
428  };
429 
430  void PrintSelf(std::ostream & os, Indent indent) const;
431 
432  //
433  // Input Methods
434  //
435 
437  DataObject * GetInput(const DataObjectIdentifierType & key);
438  const DataObject * GetInput(const DataObjectIdentifierType & key) const;
440 
444  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second : NULL; }
445  const DataObject * GetInput(DataObjectPointerArraySizeType idx) const
446  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second : NULL; }
448 
450  virtual void SetInput(const DataObjectIdentifierType & key, DataObject *input);
451 
454  virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input);
455 
457  virtual void AddInput(DataObject *input);
458 
464  virtual void PushBackInput(const DataObject *input);
465  virtual void PopBackInput();
466  virtual void PushFrontInput(const DataObject *input);
467  virtual void PopFrontInput();
469 
476  virtual void RemoveInput(const DataObjectIdentifierType & key);
477  virtual void RemoveInput(DataObjectPointerArraySizeType);
478 
480  DataObject * GetPrimaryInput()
481  { return m_IndexedInputs[0]->second; }
482  const DataObject * GetPrimaryInput() const
483  { return m_IndexedInputs[0]->second; }
485 
487  virtual void SetPrimaryInputName(const DataObjectIdentifierType & key);
488  virtual const char *GetPrimaryInputName( void ) const
489  { return this->m_IndexedInputs[0]->first.c_str(); }
491 
493  virtual void SetPrimaryInput(DataObject *input);
494 
499  void SetNumberOfIndexedInputs(DataObjectPointerArraySizeType num);
500 
507  virtual void SetNumberOfRequiredInputs(DataObjectPointerArraySizeType);
508  itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType);
510 
513  bool AddRequiredInputName( const DataObjectIdentifierType & );
514  bool AddRequiredInputName( const DataObjectIdentifierType &, DataObjectPointerArraySizeType idx );
515  bool RemoveRequiredInputName( const DataObjectIdentifierType & );
516  bool IsRequiredInputName( const DataObjectIdentifierType & ) const;
517  void SetRequiredInputNames( const NameArray & );
519 
520  //
521  // Output Methods
522  //
523 
525  DataObject * GetOutput(const DataObjectIdentifierType & key);
526  const DataObject * GetOutput(const DataObjectIdentifierType & key) const;
528 
530  virtual void SetPrimaryOutputName(const DataObjectIdentifierType & key);
531  virtual const char *GetPrimaryOutputName( void ) const
532  { return this->m_IndexedOutputs[0]->first.c_str(); }
534 
536  DataObject * GetOutput(DataObjectPointerArraySizeType idx);
537  const DataObject * GetOutput(DataObjectPointerArraySizeType idx) const;
539 
541  virtual void SetOutput(const DataObjectIdentifierType & key, DataObject *output);
542 
544  virtual void RemoveOutput(const DataObjectIdentifierType & key);
545 
547  DataObject * GetPrimaryOutput()
548  { return m_IndexedOutputs[0]->second; }
549  const DataObject * GetPrimaryOutput() const
550  { return m_IndexedOutputs[0]->second; }
552 
554  virtual void SetPrimaryOutput(DataObject *output);
555 
558  virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output);
559 
560  virtual void AddOutput(DataObject *output);
561 
562  virtual void RemoveOutput(DataObjectPointerArraySizeType idx);
563 
564  itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
565  itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
566 
568  void SetNumberOfIndexedOutputs(DataObjectPointerArraySizeType num);
569 
570 
571  DataObjectIdentifierType MakeNameFromInputIndex( DataObjectPointerArraySizeType idx ) const;
572  DataObjectIdentifierType MakeNameFromOutputIndex( DataObjectPointerArraySizeType idx ) const;
573  DataObjectPointerArraySizeType MakeIndexFromInputName( const DataObjectIdentifierType & name ) const;
574  DataObjectPointerArraySizeType MakeIndexFromOutputName( const DataObjectIdentifierType & name ) const;
575  bool IsIndexedInputName( const DataObjectIdentifierType & ) const;
576  bool IsIndexedOutputName( const DataObjectIdentifierType & ) const;
577 
579  itkLegacyMacro(virtual void RemoveOutput(DataObject *output));
580 
582  itkLegacyMacro(void SetNumberOfOutputs(DataObjectPointerArraySizeType num));
583 
587  itkLegacyMacro(virtual void RemoveInput(DataObject *input));
588 
590  itkLegacyMacro(void SetNumberOfInputs(DataObjectPointerArraySizeType num));
591 
592  //
593  // Pipeline Methods
594  //
595 
607  virtual void VerifyPreconditions();
608 
619  virtual void VerifyInputInformation();
620 
634  virtual void GenerateInputRequestedRegion();
635 
647  virtual void GenerateOutputRequestedRegion(DataObject *output);
648 
659  virtual void GenerateOutputInformation();
660 
662  virtual void GenerateData() {}
663 
668  virtual void PropagateResetPipeline();
669 
681  virtual void ReleaseInputs();
682 
691  virtual void CacheInputReleaseDataFlags();
692 
696  virtual void RestoreInputReleaseDataFlags();
697 
704 
707 
708 private:
709  ProcessObject(const Self &); //purposely not implemented
710  void operator=(const Self &); //purposely not implemented
711 
712  DataObjectIdentifierType MakeNameFromIndex( DataObjectPointerArraySizeType ) const;
713  DataObjectPointerArraySizeType MakeIndexFromName( const DataObjectIdentifierType & ) const;
714  bool IsIndexedName( const DataObjectIdentifierType & ) const;
715 
717  typedef std::map< DataObjectIdentifierType, DataObjectPointer > DataObjectPointerMap;
718 
719 
723 
724  std::vector< DataObjectPointerMap::iterator > m_IndexedInputs;
725  std::vector< DataObjectPointerMap::iterator > m_IndexedOutputs;
726 
728  std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags;
729 
732 
734  typedef std::set< DataObjectIdentifierType > NameSet;
735 
738 
741  float m_Progress;
742 
745  MultiThreader::Pointer m_Threader;
747 
750 
752  friend class DataObject;
753 
757 
758  friend class DataObjectIterator;
761 
762  friend class TestProcessObject;
763 };
764 } // end namespace itk
765 
766 #endif
767