ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 /*========================================================================= 00019 * 00020 * Portions of this file are subject to the VTK Toolkit Version 3 copyright. 00021 * 00022 * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00023 * 00024 * For complete copyright, license and disclaimer of warranty information 00025 * please refer to the NOTICE file at the top of the ITK source tree. 00026 * 00027 *=========================================================================*/ 00028 #ifndef __itkProcessObject_h 00029 #define __itkProcessObject_h 00030 00031 #include "itkDataObject.h" 00032 #include "itkDomainThreader.h" 00033 #include "itkMultiThreader.h" 00034 #include "itkObjectFactory.h" 00035 #include <vector> 00036 #include <map> 00037 #include <set> 00038 00039 namespace itk 00040 { 00110 class ITKCommon_EXPORT ProcessObject:public Object 00111 { 00112 public: 00114 typedef ProcessObject Self; 00115 typedef Object Superclass; 00116 typedef SmartPointer< Self > Pointer; 00117 typedef SmartPointer< const Self > ConstPointer; 00118 00120 itkTypeMacro(ProcessObject, Object); 00121 00123 typedef DataObject::Pointer DataObjectPointer; 00124 00126 // typedef std::vector< const DataObject * > ConstDataObjectPointerArray; 00127 00129 typedef std::vector< DataObjectPointer > DataObjectPointerArray; 00130 00131 typedef DataObject::DataObjectIdentifierType DataObjectIdentifierType; 00132 00134 typedef std::vector< DataObjectIdentifierType > NameArray; 00135 00140 NameArray GetInputNames() const; 00141 00143 NameArray GetRequiredInputNames() const; 00144 00149 DataObjectPointerArray GetInputs(); 00150 // ConstDataObjectPointerArray GetInputs() const; 00152 00154 bool HasInput( const DataObjectIdentifierType & key ) const; 00155 00156 typedef DataObjectPointerArray::size_type DataObjectPointerArraySizeType; 00157 00162 DataObjectPointerArraySizeType GetNumberOfInputs() const 00163 { return m_Inputs.size(); } 00164 00165 DataObjectPointerArraySizeType GetNumberOfOutputs() const 00166 { return m_Outputs.size(); } 00167 00172 NameArray GetOutputNames() const; 00173 00178 DataObjectPointerArray GetOutputs(); 00179 // ConstDataObjectPointerArray GetOutputs() const; 00181 00183 bool HasOutput( const DataObjectIdentifierType & key ) const; 00184 00188 DataObjectPointerArray GetIndexedInputs(); 00189 // ConstDataObjectPointerArray GetIndexedInputs() const; 00191 00196 DataObjectPointerArraySizeType GetNumberOfIndexedInputs() const; 00197 00205 virtual DataObjectPointerArraySizeType GetNumberOfValidRequiredInputs() const; 00206 00210 DataObjectPointerArray GetIndexedOutputs(); 00211 // ConstDataObjectPointerArray GetIndexedOutputs() const; 00212 DataObjectPointerArraySizeType GetNumberOfIndexedOutputs() const; 00214 00229 virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx); 00230 00233 itkSetMacro(AbortGenerateData, bool); 00234 00237 itkGetConstReferenceMacro(AbortGenerateData, bool); 00238 00240 itkBooleanMacro(AbortGenerateData); 00241 00246 itkSetClampMacro(Progress, float, 0.0f, 1.0f); 00247 00251 itkGetConstReferenceMacro(Progress, float); 00252 00258 void UpdateProgress(float amount); 00259 00278 virtual void Update(); 00279 00286 virtual void UpdateLargestPossibleRegion(); 00287 00300 virtual void UpdateOutputInformation(); 00301 00304 virtual void PropagateRequestedRegion(DataObject *output); 00305 00307 virtual void UpdateOutputData(DataObject *output); 00308 00316 virtual void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) ){} 00317 00321 virtual void ResetPipeline(); 00322 00337 virtual DataObjectPointer MakeOutput( const DataObjectIdentifierType & ); 00338 00344 virtual void SetReleaseDataFlag(bool flag); 00345 virtual bool GetReleaseDataFlag() const; 00346 void ReleaseDataFlagOn() { this->SetReleaseDataFlag(true); } 00347 void ReleaseDataFlagOff() { this->SetReleaseDataFlag(false); } 00349 00362 itkSetMacro(ReleaseDataBeforeUpdateFlag, bool); 00363 itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool); 00364 itkBooleanMacro(ReleaseDataBeforeUpdateFlag); 00366 00368 itkSetClampMacro(NumberOfThreads, ThreadIdType, 1, ITK_MAX_THREADS); 00369 itkGetConstReferenceMacro(NumberOfThreads, ThreadIdType); 00371 00373 MultiThreader * GetMultiThreader() const 00374 { return m_Threader; } 00375 00382 virtual void PrepareOutputs(); 00383 00384 protected: 00385 ProcessObject(); 00386 ~ProcessObject(); 00387 00398 template< class TDomainPartitioner, class TAssociate > 00399 class ProcessObjectDomainThreader: public DomainThreader< TDomainPartitioner, TAssociate > 00400 { 00401 public: 00403 typedef ProcessObjectDomainThreader Self; 00404 typedef DomainThreader< TDomainPartitioner, ProcessObject::Self > Superclass; 00405 typedef SmartPointer< Self > Pointer; 00406 typedef SmartPointer< const Self > ConstPointer; 00407 00408 typedef typename Superclass::DomainPartitionerType DomainPartitionerType; 00409 typedef typename Superclass::DomainType DomainType; 00410 00412 itkTypeMacro( ProcessObject::ProcessObjectDomainThreader, DomainThreader ); 00413 00414 protected: 00415 ProcessObjectDomainThreader(); 00416 virtual ~ProcessObjectDomainThreader(); 00417 00420 virtual void DetermineNumberOfThreadsUsed(); 00421 00422 private: 00423 ProcessObjectDomainThreader( const Self & ); // purposely not implemented 00424 void operator=( const Self & ); // purposely not implemented 00425 }; 00426 00427 void PrintSelf(std::ostream & os, Indent indent) const; 00428 00430 DataObject * GetInput(const DataObjectIdentifierType & key); 00431 const DataObject * GetInput(const DataObjectIdentifierType & key) const; 00433 00435 DataObject * GetInput(DataObjectPointerArraySizeType); 00436 const DataObject * GetInput(DataObjectPointerArraySizeType idx) const; 00438 00440 virtual void SetInput(const DataObjectIdentifierType & key, DataObject *input); 00441 00444 virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input); 00445 00447 virtual void RemoveInput(const DataObjectIdentifierType & key); 00448 00450 virtual void RemoveInput(DataObjectPointerArraySizeType); 00451 00455 virtual void RemoveInput(DataObject *input); 00456 00458 DataObject * GetPrimaryInput(); 00459 const DataObject * GetPrimaryInput() const; 00461 00463 virtual void SetPrimaryInput(DataObject *input); 00464 00466 DataObject * GetOutput(const DataObjectIdentifierType & key); 00467 const DataObject * GetOutput(const DataObjectIdentifierType & key) const; 00469 00471 DataObject * GetOutput(DataObjectPointerArraySizeType idx); 00472 const DataObject * GetOutput(DataObjectPointerArraySizeType idx) const; 00474 00476 virtual void SetOutput(const DataObjectIdentifierType & key, DataObject *output); 00477 00479 virtual void RemoveOutput(const DataObjectIdentifierType & key); 00480 00482 virtual void RemoveOutput(DataObject *output); 00483 00485 DataObject * GetPrimaryOutput(); 00486 const DataObject * GetPrimaryOutput() const; 00488 00490 virtual void SetPrimaryOutput(DataObject *output); 00491 00492 DataObjectIdentifierType MakeNameFromIndex( DataObjectPointerArraySizeType ) const; 00493 DataObjectPointerArraySizeType MakeIndexFromName( const DataObjectIdentifierType & ) const; 00494 bool IsIndexedName( const DataObjectIdentifierType & ) const; 00495 00507 virtual void VerifyPreconditions(); 00508 00519 virtual void VerifyInputInformation(); 00520 00521 virtual void AddInput(DataObject *input); 00522 00523 virtual void SetNumberOfRequiredInputs(DataObjectPointerArraySizeType); 00524 itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType); 00525 00531 virtual void PushBackInput(const DataObject *input); 00532 virtual void PopBackInput(); 00533 virtual void PushFrontInput(const DataObject *input); 00534 virtual void PopFrontInput(); 00536 00540 void SetNumberOfIndexedInputs(DataObjectPointerArraySizeType num); 00541 00543 void SetNumberOfInputs(DataObjectPointerArraySizeType num); 00544 00547 virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output); 00548 00549 virtual void AddOutput(DataObject *output); 00550 00551 virtual void RemoveOutput(DataObjectPointerArraySizeType idx); 00552 00553 itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType); 00554 itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType); 00555 00556 bool AddRequiredInputName( const DataObjectIdentifierType & ); 00557 bool RemoveRequiredInputName( const DataObjectIdentifierType & ); 00558 bool IsRequiredInputName( const DataObjectIdentifierType & ) const; 00559 void SetRequiredInputNames( const NameArray & ); 00560 00562 void SetNumberOfIndexedOutputs(DataObjectPointerArraySizeType num); 00563 00565 void SetNumberOfOutputs(DataObjectPointerArraySizeType num); 00566 00580 virtual void GenerateInputRequestedRegion(); 00581 00593 virtual void GenerateOutputRequestedRegion(DataObject *output); 00594 00605 virtual void GenerateOutputInformation(); 00606 00608 virtual void GenerateData() {} 00609 00614 virtual void PropagateResetPipeline(); 00615 00627 virtual void ReleaseInputs(); 00628 00637 virtual void CacheInputReleaseDataFlags(); 00638 00642 virtual void RestoreInputReleaseDataFlags(); 00643 00649 bool m_Updating; 00650 00652 TimeStamp m_OutputInformationMTime; 00653 private: 00654 ProcessObject(const Self &); //purposely not implemented 00655 void operator=(const Self &); //purposely not implemented 00657 00658 struct NameComparator 00659 { 00660 bool operator()( const DataObjectIdentifierType & a, const DataObjectIdentifierType & b ) const 00661 { 00662 if( b == "Primary" ) 00663 { 00664 return false; 00665 } 00666 if( a == "Primary" ) 00667 { 00668 return true; 00669 } 00670 return a < b; 00671 } 00672 }; 00673 00675 typedef std::map< DataObjectIdentifierType, DataObjectPointer, NameComparator > DataObjectPointerMap; 00676 00678 DataObjectPointerMap m_Inputs; 00679 DataObjectPointerMap m_Outputs; 00680 00682 std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags; 00683 00684 DataObjectPointerArraySizeType m_NumberOfIndexedInputs; 00685 DataObjectPointerArraySizeType m_NumberOfIndexedOutputs; 00686 00687 DataObjectPointerArraySizeType m_NumberOfRequiredInputs; 00688 DataObjectPointerArraySizeType m_NumberOfRequiredOutputs; 00689 00691 typedef std::set< DataObjectIdentifierType, NameComparator > NameSet; 00692 00694 NameSet m_RequiredInputNames; 00695 00697 bool m_AbortGenerateData; 00698 float m_Progress; 00699 00702 MultiThreader::Pointer m_Threader; 00703 ThreadIdType m_NumberOfThreads; 00704 00706 bool m_ReleaseDataBeforeUpdateFlag; 00707 00709 friend class DataObject; 00710 00711 friend class DataObjectConstIterator; 00712 friend class InputDataObjectConstIterator; 00713 friend class OutputDataObjectConstIterator; 00714 00715 friend class DataObjectIterator; 00716 friend class InputDataObjectIterator; 00717 friend class OutputDataObjectIterator; 00718 00719 friend class TestProcessObject; 00720 }; 00721 } // end namespace itk 00722 00723 #endif 00724