ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkSpecialCoordinatesImage.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 #ifndef __itkSpecialCoordinatesImage_h
00019 #define __itkSpecialCoordinatesImage_h
00020 
00021 #include "itkImageBase.h"
00022 #include "itkImportImageContainer.h"
00023 #include "itkDefaultPixelAccessor.h"
00024 #include "itkDefaultPixelAccessorFunctor.h"
00025 #include "itkContinuousIndex.h"
00026 
00027 namespace itk
00028 {
00094 template< class TPixel, unsigned int VImageDimension = 2 >
00095 class ITK_EXPORT SpecialCoordinatesImage:public ImageBase< VImageDimension >
00096 {
00097 public:
00099   typedef SpecialCoordinatesImage      Self;
00100   typedef ImageBase< VImageDimension > Superclass;
00101   typedef SmartPointer< Self >         Pointer;
00102   typedef SmartPointer< const Self >   ConstPointer;
00103   typedef WeakPointer< const Self >    ConstWeakPointer;
00104 
00106   itkNewMacro(Self);
00107 
00109   itkTypeMacro(SpecialCoordinatesImage, ImageBase);
00110 
00113   typedef TPixel PixelType;
00114 
00116   typedef TPixel ValueType;
00117 
00122   typedef TPixel InternalPixelType;
00123 
00124   typedef PixelType IOPixelType;
00125 
00128   typedef DefaultPixelAccessor< PixelType > AccessorType;
00129 
00133   typedef DefaultPixelAccessorFunctor< Self > AccessorFunctorType;
00134 
00139   itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
00140 
00142   typedef typename Superclass::IndexType IndexType;
00143 
00145   typedef typename Superclass::OffsetType OffsetType;
00146 
00148   typedef typename Superclass::SizeType      SizeType;
00149 
00151   typedef ImportImageContainer< SizeValueType, PixelType > PixelContainer;
00152 
00155   typedef typename Superclass::RegionType RegionType;
00156 
00161   typedef typename Superclass::SpacingType SpacingType;
00162 
00165   typedef typename Superclass::PointType PointType;
00166 
00168   typedef typename PixelContainer::Pointer      PixelContainerPointer;
00169   typedef typename PixelContainer::ConstPointer PixelContainerConstPointer;
00170 
00173   void Allocate();
00174 
00178   void SetRegions(RegionType region)
00179   {
00180     this->SetLargestPossibleRegion(region);
00181     this->SetBufferedRegion(region);
00182     this->SetRequestedRegion(region);
00183   }
00185 
00186   void SetRegions(SizeType size)
00187   {
00188     RegionType region; region.SetSize(size);
00189 
00190     this->SetLargestPossibleRegion(region);
00191     this->SetBufferedRegion(region);
00192     this->SetRequestedRegion(region);
00193   }
00194 
00197   virtual void Initialize();
00198 
00201   void FillBuffer(const TPixel & value);
00202 
00208   void SetPixel(const IndexType & index, const TPixel & value)
00209   {
00210     OffsetValueType offset = this->ComputeOffset(index);
00211     ( *m_Buffer )[offset] = value;
00212   }
00213 
00218   const TPixel & GetPixel(const IndexType & index) const
00219   {
00220     OffsetValueType offset = this->ComputeOffset(index);
00221     return ( ( *m_Buffer )[offset] );
00222   }
00223 
00228   TPixel & GetPixel(const IndexType & index)
00229   {
00230     OffsetValueType offset = this->ComputeOffset(index);
00231     return ( ( *m_Buffer )[offset] );
00232   }
00233 
00238   TPixel & operator[](const IndexType & index) { return this->GetPixel(index); }
00239 
00244   const TPixel & operator[](const IndexType & index) const { return this->GetPixel(index); }
00245 
00248   TPixel * GetBufferPointer() { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00249   const TPixel * GetBufferPointer() const { return m_Buffer ? m_Buffer->GetBufferPointer() : 0; }
00251 
00253   PixelContainer * GetPixelContainer() { return m_Buffer.GetPointer(); }
00254 
00255   const PixelContainer * GetPixelContainer() const { return m_Buffer.GetPointer(); }
00256 
00259   void SetPixelContainer(PixelContainer *container);
00260 
00262   AccessorType GetPixelAccessor(void) { return AccessorType(); }
00263 
00265   const AccessorType GetPixelAccessor(void) const { return AccessorType(); }
00266 
00272   virtual void SetSpacing(const SpacingType &) {}
00273   virtual void SetSpacing(const double[VImageDimension]) {}
00274   virtual void SetSpacing(const float[VImageDimension]) {}
00275   virtual void SetOrigin(const PointType) {}
00276   virtual void SetOrigin(const double[VImageDimension]) {}
00277   virtual void SetOrigin(const float[VImageDimension]) {}
00279 
00280   /* It is ILLEGAL in C++ to make a templated member function virtual! */
00281   /* Therefore, we must just let templates take care of everything.    */
00282   /*
00283   template<class TCoordRep>
00284   virtual bool TransformPhysicalPointToContinuousIndex(
00285               const Point<TCoordRep, VImageDimension>& point,
00286               ContinuousIndex<TCoordRep, VImageDimension>& index   ) const = 0;
00287 
00288   template<class TCoordRep>
00289   virtual bool TransformPhysicalPointToIndex(
00290             const Point<TCoordRep, VImageDimension>&,
00291             IndexType & index                                ) const = 0;
00292 
00293   template<class TCoordRep>
00294   virtual void TransformContinuousIndexToPhysicalPoint(
00295             const ContinuousIndex<TCoordRep, VImageDimension>& index,
00296             Point<TCoordRep, VImageDimension>& point        ) const = 0;
00297 
00298   template<class TCoordRep>
00299   virtual void TransformIndexToPhysicalPoint(
00300                       const IndexType & index,
00301                       Point<TCoordRep, VImageDimension>& point ) const = 0;
00302   */
00303 protected:
00304   SpecialCoordinatesImage();
00305   void PrintSelf(std::ostream & os, Indent indent) const;
00306 
00307   virtual ~SpecialCoordinatesImage() {}
00308 private:
00309   SpecialCoordinatesImage(const Self &); //purposely not implemented
00310   void operator=(const Self &);          //purposely not implemented
00311 
00313   PixelContainerPointer m_Buffer;
00314 };
00315 } // end namespace itk
00316 
00317 // Define instantiation macro for this template.
00318 #define ITK_TEMPLATE_SpecialCoordinatesImage(_, EXPORT, TypeX, TypeY)     \
00319   namespace itk                                                           \
00320   {                                                                       \
00321   _( 2 ( class EXPORT SpecialCoordinatesImage< ITK_TEMPLATE_2 TypeX > ) ) \
00322   namespace Templates                                                     \
00323   {                                                                       \
00324   typedef SpecialCoordinatesImage< ITK_TEMPLATE_2 TypeX >                 \
00325   SpecialCoordinatesImage##TypeY;                                       \
00326   }                                                                       \
00327   }
00328 
00329 #if ITK_TEMPLATE_EXPLICIT
00330 #include "Templates/itkSpecialCoordinatesImage+-.h"
00331 #endif
00332 
00333 #if ITK_TEMPLATE_TXX
00334 #include "itkSpecialCoordinatesImage.hxx"
00335 #endif
00336 
00337 #endif
00338