KWStyle - itkImageAdaptor.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkImageAdaptor.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:36 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 #ifndef __itkImageAdaptor_h
18 #define __itkImageAdaptor_h
19
20 #include "itkImage.h"
21 #include "itkDefaultPixelAccessorFunctor.h"
22
23 namespace itk
24 {
25
26 /**
27  * \class ImageAdaptor
28  * \brief Give access to partial aspects of voxels from an Image
29  *
30  * ImageAdaptors are templated over the ImageType and over a functor
31  * that will specify what part of the pixel can be accessed
32  *
33  * The basic aspects of this class are the types it defines.  
34  *
35  * Image adaptors can be used as intermediate classes that allow
36  * the sending of an image to a filter, specifying what part of the
37  * image pixels the filter will act on.
38  *
39  * The TAccessor class should implement the Get and Set methods
40  * These two will specify how data can be put
41  * and get from parts of each pixel. It should define the types
42  * ExternalType and InternalType too.
43  * 
44  * \ingroup ImageAdaptors
45  *
46  */
47 template <class TImage, class TAccessor >
48 LEN class ITK_EXPORT ImageAdaptor : public ImageBase< ::itk::GetImageDimension<TImage>::ImageDimension>
49 {
50 public:
51   /** Dimension of the image.  This constant is used by functions that are
52    * templated over image type (as opposed to being templated over pixel
53    * type and dimension) when they need compile time access to the dimension
54    * of the image. */
55   itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
56
57   /** Standard class typedefs. */
58   typedef ImageAdaptor  Self;
59 TDA   typedef ImageBase<itkGetStaticConstMacro(ImageDimension)> Superclass;
60 TDA   typedef SmartPointer<Self>  Pointer;
61 TDA   typedef SmartPointer<const Self>  ConstPointer;
62 TDA   typedef WeakPointer<const Self>  ConstWeakPointer;
63   
64   /** Run-time type information (and related methods). */
65   itkTypeMacro(ImageAdaptor, ImageBase);
66
67   /** Typedef of unadapted image */
68   typedef TImage InternalImageType;
69   
70   /** Method for creation through the object factory. */
71   itkNewMacro(Self);  
72
73   /** Pixel typedef support. Used to declare pixel type in filters
74    * or other operations. */
75   typedef typename TAccessor::ExternalType PixelType;
76
77   /** Pixel typedef support. Used to declare pixel type in filters
78    * or other operations. */
79   typedef typename TAccessor::InternalType InternalPixelType;
80
81   typedef PixelType  IOPixelType;
82
83   /**  Accessor type that convert data between internal and external
84    *  representations. */
85   typedef   TAccessor   AccessorType;
86
87   /** typedef of the functor that chooses the appropriate accessor 
88    * Image or VectorImage. */
89   typedef DefaultPixelAccessorFunctor< Self > AccessorFunctorType;
90
91   /** Index typedef support. An index is used to access pixel values. */
92   typedef typename Superclass::IndexType  IndexType;
93 TDA   typedef typename IndexType::IndexValueType    IndexValueType;
94   
95   /** Size typedef support. A size is used to define region bounds. */
96   typedef typename Superclass::SizeType  SizeType;
97 TDA   typedef typename SizeType::SizeValueType      SizeValueType;
98     
99   /** Offset typedef support. */
100   typedef typename Superclass::OffsetType OffsetType;
101 TDA   typedef typename OffsetType::OffsetValueType  OffsetValueType;
102     
103   /** Region typedef support. A region is used to specify a subset of
104    *  an image. */
105   typedef typename Superclass::RegionType RegionType;
106
107   /** Spacing typedef support.  Spacing holds the size of a pixel.  The
108    * spacing is the geometric distance between image samples. */
109   typedef typename Superclass::SpacingType SpacingType;
110
111   /** Origin typedef support.  The origin is the geometric coordinates
112    * of the index (0,0). */
113   typedef typename Superclass::PointType PointType;
114
115   /** Set the region object that defines the size and starting index
116    * for the largest possible region this image could represent.  This
117    * is used in determining how much memory would be needed to load an
118    * entire dataset.  It is also used to determine boundary
119    * conditions.
120    * \sa ImageRegion, SetBufferedRegion(), SetRequestedRegion() */
121   virtual void SetLargestPossibleRegion(const RegionType ®ion);
122
123   /** Set the region object that defines the size and starting index
124    * of the region of the image currently load in memory. 
125    * \sa ImageRegion, SetLargestPossibleRegion(), SetRequestedRegion() */
126   virtual void SetBufferedRegion(const RegionType ®ion);
127
128   /** Set the region object that defines the size and starting index
129    * for the region of the image requested.
130    * \sa ImageRegion, SetLargestPossibleRegion(), SetBufferedRegion() */
131   virtual void SetRequestedRegion(const RegionType ®ion);
132
133   /** Set the requested region from this data object to match the requested
134    * region of the data object passed in as a parameter.  This method 
135    * implements the API from DataObject. The data object parameter must be
136    * castable to an ImageBase. */
137   virtual void SetRequestedRegion(DataObject *data);
138
139   /** Get the region object that defines the size and starting index
140    * for the region of the image requested (i.e., the region of the
141    * image to be operated on by a filter).
142    * This method overloads the one in ImageBase in order to delegate
143    * to the adapted image.
144    * \sa ImageRegion, SetLargestPossibleRegion(), SetBufferedRegion() */
145   virtual const RegionType & GetRequestedRegion() const;
146
147   /** Get the region object that defines the size and starting index
148    * for the largest possible region this image could represent.  This
149    * is used in determining how much memory would be needed to load an
150    * entire dataset.  It is also used to determine boundary
151    * conditions.
152    * This method overloads the one in ImageBase in order to delegate
153    * to the adapted image.
154    * \sa ImageRegion, GetBufferedRegion(), GetRequestedRegion() */
155   virtual const RegionType& GetLargestPossibleRegion() const;
156
157   /** Get the region object that defines the size and starting index
158    * of the region of the image currently loaded in memory. 
159    * This method overloads the one in ImageBase in order to delegate
160    * to the adapted image.
161    * \sa ImageRegion, SetLargestPossibleRegion(), SetRequestedRegion() */
162   virtual const RegionType& GetBufferedRegion() const;
163
164   /** Allocate the image memory. Dimension and Size must be set a priori. */
165   inline void Allocate();
166
167
168   /** Restore the data object to its initial state. This means releasing
169    * memory. */
170   virtual void Initialize();
171
172   /** Set a pixel. */
173   void SetPixel(const IndexType &index, const PixelType & value)
174     { m_PixelAccessor.Set( m_Image->GetPixel(index), value ); }
175   
176   /** Get a pixel (read only version)  */
177   PixelType GetPixel(const IndexType &index) const
178     { return m_PixelAccessor.Get( m_Image->GetPixel(index) ); }
179
180   /** Access a pixel. This version can only be an rvalue. */
181   PixelType operator[](const IndexType &index) const
182     { return m_PixelAccessor.Get( m_Image->GetPixel(index) ); }
183
184   /** Get the OffsetTable from the adapted image */
185   const OffsetValueType *GetOffsetTable() const;
186
187   /** Compute  Index given an Offset */
188   IndexType ComputeIndex(OffsetValueType offset) const;
189
190   /** PixelContainer typedef support. Used to construct a container for
191    * the pixel data. */
192   typedef typename TImage::PixelContainer        PixelContainer;
193   typedef typename TImage::PixelContainerPointer PixelContainerPointer;
194 LEN,TDA   typedef typename TImage::PixelContainerConstPointer PixelContainerConstPointer;
195   
196   /** Return a pointer to the container. */
197   PixelContainerPointer GetPixelContainer()
198     { return m_Image->GetPixelContainer(); };
199
200   /** Set the container to use. Note that this does not cause the
201    * DataObject to be modified. */
202   void SetPixelContainer( PixelContainer *container );
203
204   /** Graft the data and information from one image to another. This
205    * is a convenience method to setup a second image with all the meta
206    * information of another image and use the same pixel
207    * container. Note that this method is different than just using two
208    * SmartPointers to the same image since separate DataObjects are
209    * still maintained. This method is similar to
210    * ImageSource::GraftOutput(). The implementation in ImageBase
211    * simply calls CopyInformation() and copies the region ivars.
212    * The implementation here refers to the superclass' implementation
213    * and then copies over the pixel container. */
214   virtual void Graft(const DataObject *data);
215   
216   /** Convenient typedef. */
217   typedef InternalPixelType * InternalPixelPointerType;
218
219   /** Return a pointer to the beginning of the buffer.  This is used by
220    * the image iterator class. */
221   InternalPixelType *GetBufferPointer();
222   const InternalPixelType *GetBufferPointer() const;
223   void GetBufferPointer2( InternalPixelPointerType  & );
224   
225   /** Set the spacing (size of a pixel) of the image. */
226   virtual void SetSpacing( const SpacingType values );
227   virtual void SetSpacing( const double* values /*[ImageDimension]*/ );
228   virtual void SetSpacing( const float* values /*[ImageDimension]*/ );
229   
230   /** Get the spacing (size of a pixel) of the image. The
231    * spacing is the geometric distance between image samples.
232    * \sa SetSpacing() */
233   virtual const SpacingType& GetSpacing() const;
234  
235   /** Get the origin of the image. The origin is the geometric
236    * coordinates of the image origin.  
237    * \sa SetOrigin() */
238   virtual const PointType& GetOrigin() const;
239
240   /** Set the origin of the image. */
241   virtual void SetOrigin( const PointType values);
242   virtual void SetOrigin( const double* values /*[ImageDimension]*/ );
243   virtual void SetOrigin( const float* values /*[ImageDimension]*/ );
244   
245   /** Set Internal Image */
246   virtual void SetImage( TImage * );
247
248   /** Delegate Modified to the Internal Image */
249   virtual void Modified() const;
250
251   /** Delegate GetMTime to the Internal Image */
252   virtual unsigned long GetMTime() const;
253
254   /** Return the Data Accesor object */
255   AccessorType & GetPixelAccessor( void ) 
256     { return m_PixelAccessor; }
257     
258   /** Return the Data Accesor object */
259   const AccessorType & GetPixelAccessor( void ) const
260     { return m_PixelAccessor; }
261
262   /** Sets the Data Accesor object */
263   void SetPixelAccessor( const AccessorType & accessor ) 
264     { m_PixelAccessor = accessor; }
265  
266   /** Return the Data Accesor object */
267   virtual void Update();
268   virtual void CopyInformation(const DataObject *data);
269
270   /** Methods to update the pipeline. Called internally by the
271    * pipeline mechanism. */
272   virtual void UpdateOutputInformation();
273   virtual void SetRequestedRegionToLargestPossibleRegion();
274   virtual void PropagateRequestedRegion() throw (InvalidRequestedRegionError);
275   virtual void UpdateOutputData();
276   virtual bool VerifyRequestedRegion();
277  
278 protected:
279   ImageAdaptor();
280   virtual ~ImageAdaptor();
281   void PrintSelf(std::ostream& os, Indent indent) const;
282   
283 private:
284   ImageAdaptor(const Self&); //purposely not implemented
285   void operator=(const Self&); //purposely not implemented
286   
287   // Adapted image, most of the calls to ImageAdaptor
288   // will be delegated to this image
289   typename TImage::Pointer   m_Image;
290
291   // Data accessor object, 
292   // it converts the presentation of a pixel
293   AccessorType               m_PixelAccessor;
294   
295
296 };
297   
298 // end namespace itk
299
300 #ifndef ITK_MANUAL_INSTANTIATION
301 #include "itkImageAdaptor.txx"
302 #endif
303   
304   
305
306 #endif
307
308 EOF

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:13PM
© Kitware Inc.