ITK  4.3.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 <vector>
36 #include <map>
37 #include <set>
38 
39 namespace itk
40 {
112 class ITKCommon_EXPORT ProcessObject:public Object
113 {
114 public:
120 
122  itkTypeMacro(ProcessObject, Object);
123 
126 
128  // typedef std::vector< const DataObject * > ConstDataObjectPointerArray;
129 
131  typedef std::vector< DataObjectPointer > DataObjectPointerArray;
132 
134 
136  typedef std::vector< DataObjectIdentifierType > NameArray;
137 
142  NameArray GetInputNames() const;
143 
145  NameArray GetRequiredInputNames() const;
146 
151  DataObjectPointerArray GetInputs();
152  // ConstDataObjectPointerArray GetInputs() const;
154 
156  bool HasInput( const DataObjectIdentifierType & key ) const;
157 
158  typedef DataObjectPointerArray::size_type DataObjectPointerArraySizeType;
159 
164  DataObjectPointerArraySizeType GetNumberOfInputs() const
165  { return m_Inputs.size(); }
166 
167  DataObjectPointerArraySizeType GetNumberOfOutputs() const
168  { return m_Outputs.size(); }
169 
174  NameArray GetOutputNames() const;
175 
180  DataObjectPointerArray GetOutputs();
181  // ConstDataObjectPointerArray GetOutputs() const;
183 
185  bool HasOutput( const DataObjectIdentifierType & key ) const;
186 
190  DataObjectPointerArray GetIndexedInputs();
191  // ConstDataObjectPointerArray GetIndexedInputs() const;
193 
198  DataObjectPointerArraySizeType GetNumberOfIndexedInputs() const;
199 
203  virtual DataObjectPointerArraySizeType GetNumberOfValidRequiredInputs() const;
204 
208  DataObjectPointerArray GetIndexedOutputs();
209  // ConstDataObjectPointerArray GetIndexedOutputs() const;
210  DataObjectPointerArraySizeType GetNumberOfIndexedOutputs() const;
212 
227  virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx);
228 
231  itkSetMacro(AbortGenerateData, bool);
232 
235  itkGetConstReferenceMacro(AbortGenerateData, bool);
236 
238  itkBooleanMacro(AbortGenerateData);
239 
244  itkSetClampMacro(Progress, float, 0.0f, 1.0f);
245 
249  itkGetConstReferenceMacro(Progress, float);
250 
256  void UpdateProgress(float amount);
257 
276  virtual void Update();
277 
284  virtual void UpdateLargestPossibleRegion();
285 
298  virtual void UpdateOutputInformation();
299 
302  virtual void PropagateRequestedRegion(DataObject *output);
303 
305  virtual void UpdateOutputData(DataObject *output);
306 
314  virtual void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) ){}
315 
319  virtual void ResetPipeline();
320 
335  virtual DataObjectPointer MakeOutput( const DataObjectIdentifierType & );
336 
342  virtual void SetReleaseDataFlag(bool flag);
343  virtual bool GetReleaseDataFlag() const;
344  void ReleaseDataFlagOn() { this->SetReleaseDataFlag(true); }
345  void ReleaseDataFlagOff() { this->SetReleaseDataFlag(false); }
347 
360  itkSetMacro(ReleaseDataBeforeUpdateFlag, bool);
361  itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool);
362  itkBooleanMacro(ReleaseDataBeforeUpdateFlag);
364 
366  itkSetClampMacro(NumberOfThreads, ThreadIdType, 1, ITK_MAX_THREADS);
367  itkGetConstReferenceMacro(NumberOfThreads, ThreadIdType);
369 
371  MultiThreader * GetMultiThreader() const
372  { return m_Threader; }
373 
380  virtual void PrepareOutputs();
381 
382 protected:
383  ProcessObject();
384  ~ProcessObject();
385 
396  template< class TDomainPartitioner, class TAssociate >
397  class ProcessObjectDomainThreader: public DomainThreader< TDomainPartitioner, TAssociate >
398  {
399  public:
405 
406  typedef typename Superclass::DomainPartitionerType DomainPartitionerType;
407  typedef typename Superclass::DomainType DomainType;
408 
411 
412  protected:
414  virtual ~ProcessObjectDomainThreader();
415 
418  virtual void DetermineNumberOfThreadsUsed();
419 
420  private:
421  ProcessObjectDomainThreader( const Self & ); // purposely not implemented
422  void operator=( const Self & ); // purposely not implemented
423  };
424 
425  void PrintSelf(std::ostream & os, Indent indent) const;
426 
428  DataObject * GetInput(const DataObjectIdentifierType & key);
429  const DataObject * GetInput(const DataObjectIdentifierType & key) const;
431 
434  const DataObject * GetInput(DataObjectPointerArraySizeType idx) const;
436 
438  virtual void SetInput(const DataObjectIdentifierType & key, DataObject *input);
439 
442  virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input);
443 
445  virtual void RemoveInput(const DataObjectIdentifierType & key);
446 
448  virtual void RemoveInput(DataObjectPointerArraySizeType);
449 
453  itkLegacyMacro(virtual void RemoveInput(DataObject *input));
454 
456  DataObject * GetPrimaryInput();
457  const DataObject * GetPrimaryInput() const;
459 
461  virtual void SetPrimaryInputName(const DataObjectIdentifierType & key);
462  itkGetStringMacro(PrimaryInputName);
464 
466  virtual void SetPrimaryInput(DataObject *input);
467 
469  DataObject * GetOutput(const DataObjectIdentifierType & key);
470  const DataObject * GetOutput(const DataObjectIdentifierType & key) const;
472 
474  virtual void SetPrimaryOutputName(const DataObjectIdentifierType & key);
475  itkGetStringMacro(PrimaryOutputName);
477 
480  const DataObject * GetOutput(DataObjectPointerArraySizeType idx) const;
482 
484  virtual void SetOutput(const DataObjectIdentifierType & key, DataObject *output);
485 
487  virtual void RemoveOutput(const DataObjectIdentifierType & key);
488 
490  itkLegacyMacro(virtual void RemoveOutput(DataObject *output));
491 
493  DataObject * GetPrimaryOutput();
494  const DataObject * GetPrimaryOutput() const;
496 
498  virtual void SetPrimaryOutput(DataObject *output);
499 
500  DataObjectIdentifierType MakeNameFromInputIndex( DataObjectPointerArraySizeType idx ) const;
501  DataObjectIdentifierType MakeNameFromOutputIndex( DataObjectPointerArraySizeType idx ) const;
502  DataObjectPointerArraySizeType MakeIndexFromInputName( const DataObjectIdentifierType & name ) const;
503  DataObjectPointerArraySizeType MakeIndexFromOutputName( const DataObjectIdentifierType & name ) const;
504  bool IsIndexedInputName( const DataObjectIdentifierType & ) const;
505  bool IsIndexedOutputName( const DataObjectIdentifierType & ) const;
506 
518  virtual void VerifyPreconditions();
519 
530  virtual void VerifyInputInformation();
531 
532  virtual void AddInput(DataObject *input);
533 
538  virtual void SetNumberOfRequiredInputs(DataObjectPointerArraySizeType);
539  itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType);
541 
547  virtual void PushBackInput(const DataObject *input);
548  virtual void PopBackInput();
549  virtual void PushFrontInput(const DataObject *input);
550  virtual void PopFrontInput();
552 
556  void SetNumberOfIndexedInputs(DataObjectPointerArraySizeType num);
557 
559  itkLegacyMacro(void SetNumberOfInputs(DataObjectPointerArraySizeType num));
560 
563  virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output);
564 
565  virtual void AddOutput(DataObject *output);
566 
567  virtual void RemoveOutput(DataObjectPointerArraySizeType idx);
568 
569  itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
570  itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
571 
572  bool AddRequiredInputName( const DataObjectIdentifierType & );
573  bool RemoveRequiredInputName( const DataObjectIdentifierType & );
574  bool IsRequiredInputName( const DataObjectIdentifierType & ) const;
575  void SetRequiredInputNames( const NameArray & );
576 
578  void SetNumberOfIndexedOutputs(DataObjectPointerArraySizeType num);
579 
581  itkLegacyMacro(void SetNumberOfOutputs(DataObjectPointerArraySizeType num));
582 
596  virtual void GenerateInputRequestedRegion();
597 
609  virtual void GenerateOutputRequestedRegion(DataObject *output);
610 
621  virtual void GenerateOutputInformation();
622 
624  virtual void GenerateData() {}
625 
630  virtual void PropagateResetPipeline();
631 
643  virtual void ReleaseInputs();
644 
653  virtual void CacheInputReleaseDataFlags();
654 
658  virtual void RestoreInputReleaseDataFlags();
659 
666 
669 
670 private:
671  ProcessObject(const Self &); //purposely not implemented
672  void operator=(const Self &); //purposely not implemented
673 
675  {
676  bool operator()( const DataObjectIdentifierType & a, const DataObjectIdentifierType & b ) const
677  {
678  if( b == "Primary" )
679  {
680  return false;
681  }
682  if( a == "Primary" )
683  {
684  return true;
685  }
686  return a < b;
687  }
688  };
689 
690  DataObjectIdentifierType MakeNameFromIndex( DataObjectPointerArraySizeType ) const;
691  DataObjectPointerArraySizeType MakeIndexFromName( const DataObjectIdentifierType & ) const;
692  bool IsIndexedName( const DataObjectIdentifierType & ) const;
693 
695  typedef std::map< DataObjectIdentifierType, DataObjectPointer, NameComparator > DataObjectPointerMap;
696 
700 
702  std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags;
703 
706 
709 
711  typedef std::set< DataObjectIdentifierType, NameComparator > NameSet;
712 
715 
719 
722  float m_Progress;
723 
726  MultiThreader::Pointer m_Threader;
728 
731 
733  friend class DataObject;
734 
738 
739  friend class DataObjectIterator;
742 
743  friend class TestProcessObject;
744 };
745 } // end namespace itk
746 
747 #endif
748