ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkDataObject.h
Go to the documentation of this file.
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 __itkDataObject_h
00029 #define __itkDataObject_h
00030 
00031 #include "itkObject.h"
00032 #include "itkSmartPointerForwardReference.h"
00033 #include "itkMacro.h"
00034 #include "itkRealTimeStamp.h"
00035 
00036 namespace itk
00037 {
00038 class ProcessObject;
00039 class DataObject;
00040 
00041 /*--------------------Data Object Exceptions---------------------------*/
00042 
00047 class ITKCommon_EXPORT DataObjectError:public ExceptionObject
00048 {
00049 public:
00052   DataObjectError();
00053 
00055   virtual ~DataObjectError()
00056   throw( ) {}
00057 
00059   DataObjectError(const char *file, unsigned int lineNumber);
00060 
00062   DataObjectError(const std::string & file, unsigned int lineNumber);
00063 
00065   DataObjectError(const DataObjectError & orig);
00066 
00068   DataObjectError & operator=(const DataObjectError & orig);
00069 
00071   itkTypeMacro(DataObjectError, ExceptionObject);
00072 
00074   void SetDataObject(DataObject *dobj);
00075 
00077   DataObject * GetDataObject();
00078 
00079 protected:
00084   virtual void PrintSelf(std::ostream & os, Indent indent) const;
00085 
00086 private:
00087   DataObject *m_DataObject;
00088 };
00089 
00096 class ITKCommon_EXPORT InvalidRequestedRegionError:public DataObjectError
00097 {
00098 public:
00101   InvalidRequestedRegionError();
00102 
00104   virtual ~InvalidRequestedRegionError()
00105   throw( ) {}
00106 
00108   InvalidRequestedRegionError(const char *file, unsigned int lineNumber);
00109 
00111   InvalidRequestedRegionError(const std::string & file, unsigned int lineNumber);
00112 
00114   InvalidRequestedRegionError(const InvalidRequestedRegionError & orig);
00115 
00117   InvalidRequestedRegionError & operator=(const InvalidRequestedRegionError & orig);
00118 
00120   itkTypeMacro(InvalidRequestedRegionError, DataObjectError);
00121 protected:
00122 
00127   virtual void PrintSelf(std::ostream & os, Indent indent) const;
00128 };
00129 
00130 /*----------------------------Data Object--------------------------------*/
00131 
00275 class ITKCommon_EXPORT DataObject:public Object
00276 {
00277 public:
00279   typedef DataObject                 Self;
00280   typedef Object                     Superclass;
00281   typedef SmartPointer< Self >       Pointer;
00282   typedef SmartPointer< const Self > ConstPointer;
00283 
00284   typedef std::string                DataObjectIdentifierType;
00285 
00287   itkTypeMacro(DataObject, Object);
00288 
00294   void DisconnectPipeline();
00295 
00308   SmartPointerForwardReference< ProcessObject > GetSource() const;
00309 
00311   const DataObjectIdentifierType & GetSourceOutputName() const;
00312 
00314   typedef std::vector< Pointer >::size_type DataObjectPointerArraySizeType;
00315   DataObjectPointerArraySizeType GetSourceOutputIndex() const;
00316 
00319   virtual void Initialize();
00320 
00323   void SetReleaseDataFlag(bool flag)
00324   {
00325     m_ReleaseDataFlag = flag;
00326   }
00327 
00328   itkGetConstReferenceMacro(ReleaseDataFlag, bool);
00329   itkBooleanMacro(ReleaseDataFlag);
00330 
00334   static void SetGlobalReleaseDataFlag(bool val);
00335 
00336   static bool GetGlobalReleaseDataFlag();
00337 
00338   static void GlobalReleaseDataFlagOn()
00339   { Self::SetGlobalReleaseDataFlag(true); }
00340   static void GlobalReleaseDataFlagOff()
00341   { Self::SetGlobalReleaseDataFlag(false); }
00342 
00347   void ReleaseData();
00348 
00351   bool ShouldIReleaseData() const;
00352 
00354   bool GetDataReleased() const
00355   { return m_DataReleased; }
00356 
00367   virtual void Update();
00368 
00378   virtual void UpdateOutputInformation();
00379 
00382   virtual void PropagateRequestedRegion();
00383 
00384   virtual void UpdateOutputData();
00385 
00389   virtual void ResetPipeline();
00390 
00393   void SetPipelineMTime(unsigned long time)
00394   { m_PipelineMTime = time; }
00395   itkGetConstReferenceMacro(PipelineMTime, unsigned long);
00397 
00399   virtual unsigned long GetUpdateMTime() const;
00400 
00406   itkSetMacro( RealTimeStamp, RealTimeStamp );
00407   itkGetConstReferenceMacro( RealTimeStamp, RealTimeStamp );
00409 
00418   virtual void PrepareForNewData()
00419   { this->Initialize(); }
00420 
00425   virtual void DataHasBeenGenerated();
00426 
00430   virtual void SetRequestedRegionToLargestPossibleRegion() {}
00431 
00441   virtual bool RequestedRegionIsOutsideOfTheBufferedRegion()
00442   { return false; }
00443 
00456   virtual bool VerifyRequestedRegion() { return true; }
00457 
00467   virtual void CopyInformation(const DataObject *) {}
00468 
00474   virtual void SetRequestedRegion(const DataObject *) {}
00475 
00481   virtual void Graft(const DataObject *) {}
00482 protected:
00483   DataObject();
00484   ~DataObject();
00485   void PrintSelf(std::ostream & os, Indent indent) const;
00487 
00489   virtual void PropagateResetPipeline();
00490 
00491 private:
00492   DataObject(const Self &);     //purposely not implemented
00493   void operator=(const Self &); //purposely not implemented
00494 
00496   WeakPointer< ProcessObject > m_Source;
00497   DataObjectIdentifierType                  m_SourceOutputName;
00498 
00503   TimeStamp m_UpdateMTime;
00504 
00506   RealTimeStamp m_RealTimeStamp;
00507 
00508   bool m_ReleaseDataFlag; //Data will release after use by a filter if on
00509   bool m_DataReleased;    //Keep track of data release during pipeline execution
00510 
00513   unsigned long m_PipelineMTime;
00514 
00516   static bool m_GlobalReleaseDataFlag;
00517 
00522   bool ConnectSource(ProcessObject *s, const DataObjectIdentifierType & name);
00523 
00532   bool DisconnectSource(ProcessObject *s, const DataObjectIdentifierType & name);
00533 
00535   friend class ProcessObject;
00536   friend class DataObjectError;
00537 };
00538 } // end namespace itk
00539 
00540 #endif
00541