ITK
4.0.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 00038 namespace itk 00039 { 00109 class ITKCommon_EXPORT ProcessObject:public Object 00110 { 00111 public: 00113 typedef ProcessObject Self; 00114 typedef Object Superclass; 00115 typedef SmartPointer< Self > Pointer; 00116 typedef SmartPointer< const Self > ConstPointer; 00117 00119 itkTypeMacro(ProcessObject, Object); 00120 00122 typedef DataObject::Pointer DataObjectPointer; 00123 00125 // typedef std::vector< const DataObject * > ConstDataObjectPointerArray; 00126 00128 typedef std::vector< DataObjectPointer > DataObjectPointerArray; 00129 00130 typedef DataObject::DataObjectIdentifierType DataObjectIdentifierType; 00131 00133 typedef std::vector< DataObjectIdentifierType > NameArray; 00134 00139 NameArray GetInputNames() const; 00140 00145 DataObjectPointerArray GetInputs(); 00146 // ConstDataObjectPointerArray GetInputs() const; 00148 00150 bool HasInput( const DataObjectIdentifierType & key ) const; 00151 00152 typedef DataObjectPointerArray::size_type DataObjectPointerArraySizeType; 00153 00158 DataObjectPointerArraySizeType GetNumberOfInputs() const 00159 { return m_Inputs.size(); } 00160 00161 DataObjectPointerArraySizeType GetNumberOfOutputs() const 00162 { return m_Outputs.size(); } 00163 00168 NameArray GetOutputNames() const; 00169 00174 DataObjectPointerArray GetOutputs(); 00175 // ConstDataObjectPointerArray GetOutputs() const; 00177 00179 bool HasOutput( const DataObjectIdentifierType & key ) const; 00180 00184 DataObjectPointerArray GetIndexedInputs(); 00185 // ConstDataObjectPointerArray GetIndexedInputs() const; 00187 00192 DataObjectPointerArraySizeType GetNumberOfIndexedInputs() const; 00193 00201 virtual DataObjectPointerArraySizeType GetNumberOfValidRequiredInputs() const; 00202 00206 DataObjectPointerArray GetIndexedOutputs(); 00207 // ConstDataObjectPointerArray GetIndexedOutputs() const; 00208 DataObjectPointerArraySizeType GetNumberOfIndexedOutputs() const; 00210 00225 virtual DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx); 00226 00229 itkSetMacro(AbortGenerateData, bool); 00230 00233 itkGetConstReferenceMacro(AbortGenerateData, bool); 00234 00236 itkBooleanMacro(AbortGenerateData); 00237 00242 itkSetClampMacro(Progress, float, 0.0f, 1.0f); 00243 00247 itkGetConstReferenceMacro(Progress, float); 00248 00254 void UpdateProgress(float amount); 00255 00274 virtual void Update(); 00275 00282 virtual void UpdateLargestPossibleRegion(); 00283 00296 virtual void UpdateOutputInformation(); 00297 00300 virtual void PropagateRequestedRegion(DataObject *output); 00301 00303 virtual void UpdateOutputData(DataObject *output); 00304 00312 virtual void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) ){} 00313 00317 virtual void ResetPipeline(); 00318 00333 virtual DataObjectPointer MakeOutput( const DataObjectIdentifierType & ); 00334 00340 virtual void SetReleaseDataFlag(bool flag); 00341 virtual bool GetReleaseDataFlag() const; 00342 void ReleaseDataFlagOn() { this->SetReleaseDataFlag(true); } 00343 void ReleaseDataFlagOff() { this->SetReleaseDataFlag(false); } 00345 00358 itkSetMacro(ReleaseDataBeforeUpdateFlag, bool); 00359 itkGetConstReferenceMacro(ReleaseDataBeforeUpdateFlag, bool); 00360 itkBooleanMacro(ReleaseDataBeforeUpdateFlag); 00362 00364 itkSetClampMacro(NumberOfThreads, ThreadIdType, 1, ITK_MAX_THREADS); 00365 itkGetConstReferenceMacro(NumberOfThreads, ThreadIdType); 00367 00369 MultiThreader * GetMultiThreader() const 00370 { return m_Threader; } 00371 00378 virtual void PrepareOutputs(); 00379 00380 protected: 00381 ProcessObject(); 00382 ~ProcessObject(); 00383 00394 template< class TDomainPartitioner, class TAssociate > 00395 class ProcessObjectDomainThreader: public DomainThreader< TDomainPartitioner, TAssociate > 00396 { 00397 public: 00399 typedef ProcessObjectDomainThreader Self; 00400 typedef DomainThreader< TDomainPartitioner, ProcessObject::Self > Superclass; 00401 typedef SmartPointer< Self > Pointer; 00402 typedef SmartPointer< const Self > ConstPointer; 00403 00404 typedef typename Superclass::DomainPartitionerType DomainPartitionerType; 00405 typedef typename Superclass::DomainType DomainType; 00406 00408 itkTypeMacro( ProcessObject::ProcessObjectDomainThreader, DomainThreader ); 00409 00410 protected: 00411 ProcessObjectDomainThreader(); 00412 virtual ~ProcessObjectDomainThreader(); 00413 00416 virtual void DetermineNumberOfThreadsUsed(); 00417 00418 private: 00419 ProcessObjectDomainThreader( const Self & ); // purposely not implemented 00420 void operator=( const Self & ); // purposely not implemented 00421 }; 00422 00423 void PrintSelf(std::ostream & os, Indent indent) const; 00424 00426 DataObject * GetInput(const DataObjectIdentifierType & key); 00427 const DataObject * GetInput(const DataObjectIdentifierType & key) const; 00429 00431 DataObject * GetInput(DataObjectPointerArraySizeType); 00432 const DataObject * GetInput(DataObjectPointerArraySizeType idx) const; 00434 00436 virtual void SetInput(const DataObjectIdentifierType & key, DataObject *input); 00437 00440 virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input); 00441 00443 virtual void RemoveInput(const DataObjectIdentifierType & key); 00444 00446 virtual void RemoveInput(DataObjectPointerArraySizeType); 00447 00451 virtual void RemoveInput(DataObject *input); 00452 00454 DataObject * GetPrimaryInput(); 00455 const DataObject * GetPrimaryInput() const; 00457 00459 virtual void SetPrimaryInput(DataObject *input); 00460 00462 DataObject * GetOutput(const DataObjectIdentifierType & key); 00463 const DataObject * GetOutput(const DataObjectIdentifierType & key) const; 00465 00467 DataObject * GetOutput(DataObjectPointerArraySizeType idx); 00468 const DataObject * GetOutput(DataObjectPointerArraySizeType idx) const; 00470 00472 virtual void SetOutput(const DataObjectIdentifierType & key, DataObject *output); 00473 00475 virtual void RemoveOutput(const DataObjectIdentifierType & key); 00476 00478 virtual void RemoveOutput(DataObject *output); 00479 00481 DataObject * GetPrimaryOutput(); 00482 const DataObject * GetPrimaryOutput() const; 00484 00486 virtual void SetPrimaryOutput(DataObject *output); 00487 00488 DataObjectIdentifierType MakeNameFromIndex( DataObjectPointerArraySizeType ) const; 00489 DataObjectPointerArraySizeType MakeIndexFromName( const DataObjectIdentifierType & ) const; 00490 bool IsIndexedName( const DataObjectIdentifierType & ) const; 00491 00503 virtual void VerifyPreconditions(); 00504 00515 virtual void VerifyInputInformation(); 00516 00517 virtual void AddInput(DataObject *input); 00518 00519 itkSetMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType); 00520 itkGetConstReferenceMacro(NumberOfRequiredInputs, DataObjectPointerArraySizeType); 00521 00527 virtual void PushBackInput(const DataObject *input); 00528 virtual void PopBackInput(); 00529 virtual void PushFrontInput(const DataObject *input); 00530 virtual void PopFrontInput(); 00532 00536 void SetNumberOfIndexedInputs(DataObjectPointerArraySizeType num); 00537 00539 void SetNumberOfInputs(DataObjectPointerArraySizeType num); 00540 00543 virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output); 00544 00545 virtual void AddOutput(DataObject *output); 00546 00547 virtual void RemoveOutput(DataObjectPointerArraySizeType idx); 00548 00549 itkSetMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType); 00550 itkGetConstReferenceMacro(NumberOfRequiredOutputs, DataObjectPointerArraySizeType); 00551 00553 void SetNumberOfIndexedOutputs(DataObjectPointerArraySizeType num); 00554 00556 void SetNumberOfOutputs(DataObjectPointerArraySizeType num); 00557 00571 virtual void GenerateInputRequestedRegion(); 00572 00584 virtual void GenerateOutputRequestedRegion(DataObject *output); 00585 00596 virtual void GenerateOutputInformation(); 00597 00599 virtual void GenerateData() {} 00600 00605 virtual void PropagateResetPipeline(); 00606 00618 virtual void ReleaseInputs(); 00619 00628 virtual void CacheInputReleaseDataFlags(); 00629 00633 virtual void RestoreInputReleaseDataFlags(); 00634 00640 bool m_Updating; 00641 00643 TimeStamp m_OutputInformationMTime; 00644 private: 00645 ProcessObject(const Self &); //purposely not implemented 00646 void operator=(const Self &); //purposely not implemented 00648 00649 struct NameComparator 00650 { 00651 bool operator()( const DataObjectIdentifierType & a, const DataObjectIdentifierType & b ) const 00652 { 00653 if( b == "Primary" ) 00654 { 00655 return false; 00656 } 00657 if( a == "Primary" ) 00658 { 00659 return true; 00660 } 00661 return a < b; 00662 } 00663 }; 00664 00666 typedef std::map< DataObjectIdentifierType, DataObjectPointer, NameComparator > DataObjectPointerMap; 00667 00669 DataObjectPointerMap m_Inputs; 00670 DataObjectPointerMap m_Outputs; 00671 00673 std::map< DataObjectIdentifierType, bool > m_CachedInputReleaseDataFlags; 00674 00675 DataObjectPointerArraySizeType m_NumberOfIndexedInputs; 00676 DataObjectPointerArraySizeType m_NumberOfIndexedOutputs; 00677 00678 DataObjectPointerArraySizeType m_NumberOfRequiredInputs; 00679 DataObjectPointerArraySizeType m_NumberOfRequiredOutputs; 00680 00682 bool m_AbortGenerateData; 00683 float m_Progress; 00684 00687 MultiThreader::Pointer m_Threader; 00688 ThreadIdType m_NumberOfThreads; 00689 00691 bool m_ReleaseDataBeforeUpdateFlag; 00692 00694 friend class DataObject; 00695 00696 friend class DataObjectConstIterator; 00697 friend class InputDataObjectConstIterator; 00698 friend class OutputDataObjectConstIterator; 00699 00700 friend class DataObjectIterator; 00701 friend class InputDataObjectIterator; 00702 friend class OutputDataObjectIterator; 00703 00704 friend class TestProcessObject; 00705 }; 00706 } // end namespace itk 00707 00708 #endif 00709