ITK  4.2.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 {
110 class ITKCommon_EXPORT ProcessObject:public Object
111 {
112 public:
118 
120  itkTypeMacro(ProcessObject, Object);
121 
124 
126  // typedef std::vector< const DataObject * > ConstDataObjectPointerArray;
127 
129  typedef std::vector< DataObjectPointer > DataObjectPointerArray;
130 
132 
134  typedef std::vector< DataObjectIdentifierType > NameArray;
135 
140  NameArray GetInputNames() const;
141 
143  NameArray GetRequiredInputNames() const;
144 
149  DataObjectPointerArray GetInputs();
150  // ConstDataObjectPointerArray GetInputs() const;
152 
154  bool HasInput( const DataObjectIdentifierType & key ) const;
155 
156  typedef DataObjectPointerArray::size_type DataObjectPointerArraySizeType;
157 
162  DataObjectPointerArraySizeType GetNumberOfInputs() const
163  { return m_Inputs.size(); }
164 
165  DataObjectPointerArraySizeType GetNumberOfOutputs() const
166  { return m_Outputs.size(); }
167 
172  NameArray GetOutputNames() const;
173 
178  DataObjectPointerArray GetOutputs();
179  // ConstDataObjectPointerArray GetOutputs() const;
181 
183  bool HasOutput( const DataObjectIdentifierType & key ) const;
184 
188  DataObjectPointerArray GetIndexedInputs();
189  // ConstDataObjectPointerArray GetIndexedInputs() const;
191 
196  DataObjectPointerArraySizeType GetNumberOfIndexedInputs() const;
197 
205  virtual DataObjectPointerArraySizeType GetNumberOfValidRequiredInputs() const;
206 
210  DataObjectPointerArray GetIndexedOutputs();
211  // ConstDataObjectPointerArray GetIndexedOutputs() const;
212  DataObjectPointerArraySizeType GetNumberOfIndexedOutputs() const;
214 
229  virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx);
230 
233  itkSetMacro(AbortGenerateData, bool);
234 
237  itkGetConstReferenceMacro(AbortGenerateData, bool);
238 
240  itkBooleanMacro(AbortGenerateData);
241 
246  itkSetClampMacro(Progress, float, 0.0f, 1.0f);
247 
251  itkGetConstReferenceMacro(Progress, float);
252 
258  void UpdateProgress(float amount);
259 
278  virtual void Update();
279 
286  virtual void UpdateLargestPossibleRegion();
287 
300  virtual void UpdateOutputInformation();
301 
304  virtual void PropagateRequestedRegion(DataObject *output);
305 
307  virtual void UpdateOutputData(DataObject *output);
308 
316  virtual void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) ){}
317 
321  virtual void ResetPipeline();
322 
337  virtual DataObjectPointer MakeOutput( const DataObjectIdentifierType & );
338 
344  virtual void SetReleaseDataFlag(bool flag);
345  virtual bool GetReleaseDataFlag() const;
346  void ReleaseDataFlagOn() { this->SetReleaseDataFlag(true); }
347  void ReleaseDataFlagOff() { this->SetReleaseDataFlag(false); }
349 
362  itkSetMacro(ReleaseDataBeforeUpdateFlag, bool);
363  itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool);
364  itkBooleanMacro(ReleaseDataBeforeUpdateFlag);
366 
368  itkSetClampMacro(NumberOfThreads, ThreadIdType, 1, ITK_MAX_THREADS);
369  itkGetConstReferenceMacro(NumberOfThreads, ThreadIdType);
371 
373  MultiThreader * GetMultiThreader() const
374  { return m_Threader; }
375 
382  virtual void PrepareOutputs();
383 
384 protected:
385  ProcessObject();
386  ~ProcessObject();
387 
398  template< class TDomainPartitioner, class TAssociate >
399  class ProcessObjectDomainThreader: public DomainThreader< TDomainPartitioner, TAssociate >
400  {
401  public:
407 
408  typedef typename Superclass::DomainPartitionerType DomainPartitionerType;
409  typedef typename Superclass::DomainType DomainType;
410 
413 
414  protected:
416  virtual ~ProcessObjectDomainThreader();
417 
420  virtual void DetermineNumberOfThreadsUsed();
421 
422  private:
423  ProcessObjectDomainThreader( const Self & ); // purposely not implemented
424  void operator=( const Self & ); // purposely not implemented
425  };
426 
427  void PrintSelf(std::ostream & os, Indent indent) const;
428 
430  DataObject * GetInput(const DataObjectIdentifierType & key);
431  const DataObject * GetInput(const DataObjectIdentifierType & key) const;
433 
436  const DataObject * GetInput(DataObjectPointerArraySizeType idx) const;
438 
440  virtual void SetInput(const DataObjectIdentifierType & key, DataObject *input);
441 
444  virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input);
445 
447  virtual void RemoveInput(const DataObjectIdentifierType & key);
448 
450  virtual void RemoveInput(DataObjectPointerArraySizeType);
451 
455  itkLegacyMacro(virtual void RemoveInput(DataObject *input));
456 
458  DataObject * GetPrimaryInput();
459  const DataObject * GetPrimaryInput() const;
461 
463  virtual void SetPrimaryInput(DataObject *input);
464 
466  DataObject * GetOutput(const DataObjectIdentifierType & key);
467  const DataObject * GetOutput(const DataObjectIdentifierType & key) const;
469 
472  const DataObject * GetOutput(DataObjectPointerArraySizeType idx) const;
474 
476  virtual void SetOutput(const DataObjectIdentifierType & key, DataObject *output);
477 
479  virtual void RemoveOutput(const DataObjectIdentifierType & key);
480 
482  itkLegacyMacro(virtual void RemoveOutput(DataObject *output));
483 
485  DataObject * GetPrimaryOutput();
486  const DataObject * GetPrimaryOutput() const;
488 
490  virtual void SetPrimaryOutput(DataObject *output);
491 
492  DataObjectIdentifierType MakeNameFromIndex( DataObjectPointerArraySizeType ) const;
493  DataObjectPointerArraySizeType MakeIndexFromName( const DataObjectIdentifierType & ) const;
494  bool IsIndexedName( const DataObjectIdentifierType & ) const;
495 
507  virtual void VerifyPreconditions();
508 
519  virtual void VerifyInputInformation();
520 
521  virtual void AddInput(DataObject *input);
522 
523  virtual void SetNumberOfRequiredInputs(DataObjectPointerArraySizeType);
524  itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType);
525 
531  virtual void PushBackInput(const DataObject *input);
532  virtual void PopBackInput();
533  virtual void PushFrontInput(const DataObject *input);
534  virtual void PopFrontInput();
536 
540  void SetNumberOfIndexedInputs(DataObjectPointerArraySizeType num);
541 
543  itkLegacyMacro(void SetNumberOfInputs(DataObjectPointerArraySizeType num));
544 
547  virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output);
548 
549  virtual void AddOutput(DataObject *output);
550 
551  virtual void RemoveOutput(DataObjectPointerArraySizeType idx);
552 
553  itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
554  itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
555 
556  bool AddRequiredInputName( const DataObjectIdentifierType & );
557  bool RemoveRequiredInputName( const DataObjectIdentifierType & );
558  bool IsRequiredInputName( const DataObjectIdentifierType & ) const;
559  void SetRequiredInputNames( const NameArray & );
560 
562  void SetNumberOfIndexedOutputs(DataObjectPointerArraySizeType num);
563 
565  itkLegacyMacro(void SetNumberOfOutputs(DataObjectPointerArraySizeType num));
566 
580  virtual void GenerateInputRequestedRegion();
581 
593  virtual void GenerateOutputRequestedRegion(DataObject *output);
594 
605  virtual void GenerateOutputInformation();
606 
608  virtual void GenerateData() {}
609 
614  virtual void PropagateResetPipeline();
615 
627  virtual void ReleaseInputs();
628 
637  virtual void CacheInputReleaseDataFlags();
638 
642  virtual void RestoreInputReleaseDataFlags();
643 
650 
653 private:
654  ProcessObject(const Self &); //purposely not implemented
655  void operator=(const Self &); //purposely not implemented
657 
659  {
660  bool operator()( const DataObjectIdentifierType & a, const DataObjectIdentifierType & b ) const
661  {
662  if( b == "Primary" )
663  {
664  return false;
665  }
666  if( a == "Primary" )
667  {
668  return true;
669  }
670  return a < b;
671  }
672  };
673 
675  typedef std::map< DataObjectIdentifierType, DataObjectPointer, NameComparator > DataObjectPointerMap;
676 
680 
682  std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags;
683 
686 
689 
691  typedef std::set< DataObjectIdentifierType, NameComparator > NameSet;
692 
695 
698  float m_Progress;
699 
702  MultiThreader::Pointer m_Threader;
704 
707 
709  friend class DataObject;
710 
714 
715  friend class DataObjectIterator;
718 
719  friend class TestProcessObject;
720 };
721 } // end namespace itk
722 
723 #endif
724