Orfeo Toolbox  4.0
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;
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;
187 
189  bool HasOutput( const DataObjectIdentifierType & key ) const;
190 
194  DataObjectPointerArray GetIndexedInputs();
195  // ConstDataObjectPointerArray GetIndexedInputs() const;
196 
201  DataObjectPointerArraySizeType GetNumberOfIndexedInputs() const;
202 
206  virtual DataObjectPointerArraySizeType GetNumberOfValidRequiredInputs() const;
207 
211  DataObjectPointerArray GetIndexedOutputs();
212  // ConstDataObjectPointerArray GetIndexedOutputs() const;
213  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 
254 #if ! defined ( ITK_FUTURE_LEGACY_REMOVE )
255  void SetProgress(float progress)
256  {
257  // Clamp the value to be between 0 and 1.
258  m_Progress = std::max(progress, 0.0f);
259  m_Progress = std::min(m_Progress, 1.0f);
260  }
261 #endif
262 
266  itkGetConstReferenceMacro(Progress, float);
267 
273  void UpdateProgress(float progress);
274 
293  virtual void Update();
294 
301  virtual void UpdateLargestPossibleRegion();
302 
315  virtual void UpdateOutputInformation();
316 
319  virtual void PropagateRequestedRegion(DataObject *output);
320 
322  virtual void UpdateOutputData(DataObject *output);
323 
331  virtual void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) ){}
332 
336  virtual void ResetPipeline();
337 
352  virtual DataObjectPointer MakeOutput( const DataObjectIdentifierType & );
353 
359  virtual void SetReleaseDataFlag(bool flag);
360  virtual bool GetReleaseDataFlag() const;
361  void ReleaseDataFlagOn() { this->SetReleaseDataFlag(true); }
362  void ReleaseDataFlagOff() { this->SetReleaseDataFlag(false); }
363 
376  itkSetMacro(ReleaseDataBeforeUpdateFlag, bool);
377  itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool);
378  itkBooleanMacro(ReleaseDataBeforeUpdateFlag);
379 
381  itkSetClampMacro(NumberOfThreads, ThreadIdType, 1, ITK_MAX_THREADS);
382  itkGetConstReferenceMacro(NumberOfThreads, ThreadIdType);
383 
385  MultiThreader * GetMultiThreader() const
386  { return m_Threader; }
387 
394  virtual void PrepareOutputs();
395 
396 protected:
397  ProcessObject();
398  ~ProcessObject();
399 
410  template< typename TDomainPartitioner, typename TAssociate >
411  class ProcessObjectDomainThreader: public DomainThreader< TDomainPartitioner, TAssociate >
412  {
413  public:
419 
420  typedef typename Superclass::DomainPartitionerType DomainPartitionerType;
421  typedef typename Superclass::DomainType DomainType;
422 
425 
426  protected:
428  virtual ~ProcessObjectDomainThreader();
429 
432  virtual void DetermineNumberOfThreadsUsed();
433 
434  private:
435  ProcessObjectDomainThreader( const Self & ); // purposely not implemented
436  void operator=( const Self & ); // purposely not implemented
437  };
438 
439  void PrintSelf(std::ostream & os, Indent indent) const;
440 
441  //
442  // Input Methods
443  //
444 
446  DataObject * GetInput(const DataObjectIdentifierType & key);
447  const DataObject * GetInput(const DataObjectIdentifierType & key) const;
448 
452  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second : NULL; }
453  const DataObject * GetInput(DataObjectPointerArraySizeType idx) const
454  { return idx < m_IndexedInputs.size() ? m_IndexedInputs[idx]->second : NULL; }
455 
457  virtual void SetInput(const DataObjectIdentifierType & key, DataObject *input);
458 
461  virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input);
462 
464  virtual void AddInput(DataObject *input);
465 
471  virtual void PushBackInput(const DataObject *input);
472  virtual void PopBackInput();
473  virtual void PushFrontInput(const DataObject *input);
474  virtual void PopFrontInput();
475 
482  virtual void RemoveInput(const DataObjectIdentifierType & key);
483  virtual void RemoveInput(DataObjectPointerArraySizeType);
484 
486  DataObject * GetPrimaryInput()
487  { return m_IndexedInputs[0]->second; }
488  const DataObject * GetPrimaryInput() const
489  { return m_IndexedInputs[0]->second; }
490 
492  virtual void SetPrimaryInputName(const DataObjectIdentifierType & key);
493  virtual const char *GetPrimaryInputName( void ) const
494  { return this->m_IndexedInputs[0]->first.c_str(); }
495 
497  virtual void SetPrimaryInput(DataObject *input);
498 
503  void SetNumberOfIndexedInputs(DataObjectPointerArraySizeType num);
504 
511  virtual void SetNumberOfRequiredInputs(DataObjectPointerArraySizeType);
512  itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType);
513 
516  bool AddRequiredInputName( const DataObjectIdentifierType & );
517  bool AddRequiredInputName( const DataObjectIdentifierType &, DataObjectPointerArraySizeType idx );
518  bool RemoveRequiredInputName( const DataObjectIdentifierType & );
519  bool IsRequiredInputName( const DataObjectIdentifierType & ) const;
520  void SetRequiredInputNames( const NameArray & );
521 
522  //
523  // Output Methods
524  //
525 
527  DataObject * GetOutput(const DataObjectIdentifierType & key);
528  const DataObject * GetOutput(const DataObjectIdentifierType & key) const;
529 
531  virtual void SetPrimaryOutputName(const DataObjectIdentifierType & key);
532  virtual const char *GetPrimaryOutputName( void ) const
533  { return this->m_IndexedOutputs[0]->first.c_str(); }
534 
536  DataObject * GetOutput(DataObjectPointerArraySizeType idx);
537  const DataObject * GetOutput(DataObjectPointerArraySizeType idx) const;
538 
540  virtual void SetOutput(const DataObjectIdentifierType & key, DataObject *output);
541 
543  virtual void RemoveOutput(const DataObjectIdentifierType & key);
544 
546  DataObject * GetPrimaryOutput()
547  { return m_IndexedOutputs[0]->second; }
548  const DataObject * GetPrimaryOutput() const
549  { return m_IndexedOutputs[0]->second; }
550 
552  virtual void SetPrimaryOutput(DataObject *output);
553 
556  virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output);
557 
558  virtual void AddOutput(DataObject *output);
559 
560  virtual void RemoveOutput(DataObjectPointerArraySizeType idx);
561 
562  itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
563  itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType);
564 
566  void SetNumberOfIndexedOutputs(DataObjectPointerArraySizeType num);
567 
568 
569  DataObjectIdentifierType MakeNameFromInputIndex( DataObjectPointerArraySizeType idx ) const;
570  DataObjectIdentifierType MakeNameFromOutputIndex( DataObjectPointerArraySizeType idx ) const;
571  DataObjectPointerArraySizeType MakeIndexFromInputName( const DataObjectIdentifierType & name ) const;
572  DataObjectPointerArraySizeType MakeIndexFromOutputName( const DataObjectIdentifierType & name ) const;
573  bool IsIndexedInputName( const DataObjectIdentifierType & ) const;
574  bool IsIndexedOutputName( const DataObjectIdentifierType & ) const;
575 
577  itkLegacyMacro(virtual void RemoveOutput(DataObject *output));
578 
580  itkLegacyMacro(void SetNumberOfOutputs(DataObjectPointerArraySizeType num));
581 
585  itkLegacyMacro(virtual void RemoveInput(DataObject *input));
586 
588  itkLegacyMacro(void SetNumberOfInputs(DataObjectPointerArraySizeType num));
589 
590  //
591  // Pipeline Methods
592  //
593 
605  virtual void VerifyPreconditions();
606 
617  virtual void VerifyInputInformation();
618 
632  virtual void GenerateInputRequestedRegion();
633 
645  virtual void GenerateOutputRequestedRegion(DataObject *output);
646 
657  virtual void GenerateOutputInformation();
658 
660  virtual void GenerateData() {}
661 
665  virtual void PropagateResetPipeline();
666 
678  virtual void ReleaseInputs();
679 
688  virtual void CacheInputReleaseDataFlags();
689 
693  virtual void RestoreInputReleaseDataFlags();
694 
701 
704 
705 private:
706  ProcessObject(const Self &); //purposely not implemented
707  void operator=(const Self &); //purposely not implemented
708 
709  DataObjectIdentifierType MakeNameFromIndex( DataObjectPointerArraySizeType ) const;
710  DataObjectPointerArraySizeType MakeIndexFromName( const DataObjectIdentifierType & ) const;
711 
713  typedef std::map< DataObjectIdentifierType, DataObjectPointer > DataObjectPointerMap;
714 
715 
719 
720  std::vector< DataObjectPointerMap::iterator > m_IndexedInputs;
721  std::vector< DataObjectPointerMap::iterator > m_IndexedOutputs;
722 
724  std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags;
725 
728 
730  typedef std::set< DataObjectIdentifierType > NameSet;
731 
734 
737  float m_Progress;
738 
743 
746 
748  friend class DataObject;
749 
753 
754  friend class DataObjectIterator;
757 
758  friend class TestProcessObject;
759 };
760 } // end namespace itk
761 
762 #endif

Generated at Sat Mar 8 2014 15:23:52 for Orfeo Toolbox with doxygen 1.8.3.1