Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkImageIORegion.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkImageIORegion.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007/08/22 17:47:20 $
00007   Version:   $Revision: 1.19 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkImageIORegion_h
00018 #define __itkImageIORegion_h
00019 
00020 #include <algorithm>
00021 #include "itkRegion.h"
00022 #include "itkObjectFactory.h"
00023 #include "itkImageRegion.h"
00024 
00025 namespace itk
00026 {
00027 
00045 class ITK_EXPORT ImageIORegion: public Region
00046 {
00047 public:
00049   typedef ImageIORegion Self;
00050   typedef Region        Superclass;
00051 
00053   itkTypeMacro(ImageIORegion, Region);
00054 
00056   unsigned int GetImageDimension() const
00057     {
00058     return m_ImageDimension;
00059     }
00060 
00064   unsigned int GetRegionDimension() const
00065     {  
00066     unsigned int dim=0;
00067     for (unsigned int i=0; i<m_ImageDimension; i++)
00068       {
00069       if ( m_Size[i] > 1 ) dim++;
00070       }
00071     return dim;
00072     }
00074 
00076   typedef std::vector<long>  IndexType;
00077 
00079   typedef std::vector<long>  SizeType;
00080 
00082   virtual Superclass::RegionType GetRegionType() const
00083   {return Superclass::ITK_STRUCTURED_REGION;}
00084 
00087   ImageIORegion(unsigned int dimension)
00088     {
00089     m_ImageDimension = dimension;
00090     m_Index.resize(m_ImageDimension);
00091     m_Size.resize(m_ImageDimension);
00092     std::fill(m_Index.begin(), m_Index.end(), 0);
00093     std::fill(m_Size.begin(), m_Size.end(), 0);
00094     }
00096 
00099   ImageIORegion()
00100     {
00101     m_ImageDimension = 2;
00102     m_Index.resize(2);
00103     m_Size.resize(2);
00104     std::fill(m_Index.begin(), m_Index.end(), 0);
00105     std::fill(m_Size.begin(), m_Size.end(), 0);
00106     }
00108 
00111   virtual ~ImageIORegion(){};
00112 
00115   ImageIORegion(const Self& region): Region()
00116     { 
00117     m_Index =region.m_Index; 
00118     m_Size = region.m_Size; 
00119     m_ImageDimension = region.m_ImageDimension;
00120     }
00121 
00124   void operator=(const Self& region) 
00125     {
00126     m_Index = region.m_Index;  
00127     m_Size = region.m_Size;
00128     m_ImageDimension = region.m_ImageDimension;
00129     }
00130 
00132   void SetIndex(const IndexType &index) 
00133     {
00134     m_Index = index;\
00135     }
00136 
00138   const IndexType& GetIndex() const
00139     {
00140     return m_Index;
00141     }
00142 
00145   void SetSize(const SizeType &size)
00146     {
00147     m_Size = size;
00148     }
00149 
00151   const SizeType& GetSize() const
00152     {
00153     return m_Size;
00154     }
00155 
00159   long GetSize(unsigned long i) const
00160     {
00161     return m_Size[i];
00162     }
00163   long GetIndex(unsigned long i) const
00164     {
00165     return m_Index[i];
00166     }
00167   void SetSize(const unsigned long i, long size)
00168     {
00169     m_Size[i] = size;
00170     }
00171   void SetIndex(const unsigned long i, long idx)
00172     {
00173     m_Index[i] = idx;
00174     }
00176 
00178   bool
00179   operator==(const Self &region) const
00180     {
00181     bool same = 1;
00182     same = (m_Index == region.m_Index);
00183     same = same && (m_Size == region.m_Size);
00184     same = same && (m_ImageDimension == region.m_ImageDimension);
00185     return same;
00186     }
00188 
00190   bool
00191   operator!=(const Self &region) const
00192     {
00193     bool same = 1;
00194     same = (m_Index == region.m_Index);
00195     same = same && (m_Size == region.m_Size);
00196     same = same && (m_ImageDimension == region.m_ImageDimension);
00197     return !same;
00198     }
00200 
00202   bool
00203   IsInside(const IndexType &index) const
00204     {
00205     for(unsigned int i=0; i<m_ImageDimension; i++)
00206       {
00207       if( index[i] < m_Index[i] ) 
00208         {
00209         return false;
00210         }
00211       if( index[i] >= m_Index[i] + m_Size[i] ) 
00212         {
00213         return false;
00214         }
00215       }
00216     return true;
00217     }
00219 
00222 //  unsigned long GetNumberOfPixels() const;
00223 
00224 protected:
00229   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00230 
00231 private:
00232   unsigned int      m_ImageDimension;
00233   std::vector<long> m_Index;
00234   std::vector<long> m_Size;
00235 };
00236 
00237 
00238 // Declare operator<<
00239 extern std::ostream & operator<<(std::ostream &os, const ImageIORegion &region); 
00240 
00245 template< unsigned int VDimension >
00246 class ImageIORegionAdaptor
00247 {
00248 public:
00249   typedef ImageRegion<VDimension>  ImageRegionType;
00250   typedef ImageIORegion            ImageIORegionType;
00251 
00252   typedef typename ImageRegionType::SizeType  ImageSizeType;
00253   typedef typename ImageRegionType::IndexType ImageIndexType;
00254 
00255   static void Convert( const ImageRegionType & inImageRegion, ImageIORegionType & outIORegion )
00256     {
00257     //
00258     // The ImageRegion and ImageIORegion objects may have different dimensions.
00259     // Here we only copy the common dimensions between the two. If the ImageRegion
00260     // has more dimensions than the ImageIORegion, then the defaults of the ImageRegion
00261     // will take care of the remaining codimension. If the ImageRegion has less dimensions
00262     // than the ImageIORegion, then the remaining IO dimensions are simply ignored.
00263     //
00264     const unsigned int ioDimension = outIORegion.GetImageDimension();
00265     const unsigned int imageDimension = VDimension;
00266 
00267     unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
00268 
00269     ImageSizeType  size  = inImageRegion.GetSize();
00270     ImageIndexType index = inImageRegion.GetIndex();
00271     
00272     for( unsigned int i = 0; i < minDimension; i++ )
00273       {
00274       outIORegion.SetSize(  i, size[i] );
00275       outIORegion.SetIndex( i, index[i] );
00276       }
00277 
00278     //
00279     // Fill in the remaining codimension (if any) with default values
00280     //
00281     for( unsigned int k = minDimension; k < ioDimension; k++ )
00282       {
00283       outIORegion.SetSize(  k, 1 ); // Note that default size in IO is 1 not 0
00284       outIORegion.SetIndex( k, 0 );
00285       }
00286     }
00287 
00288   static void Convert( const ImageIORegionType & inIORegion, ImageRegionType & outImageRegion )
00289     {
00290     ImageSizeType  size;
00291     ImageIndexType index;
00292 
00293     size.Fill(1);  // initialize with default values
00294     index.Fill(0);
00295 
00296     //
00297     // The ImageRegion and ImageIORegion objects may have different dimensions.
00298     // Here we only copy the common dimensions between the two. If the ImageRegion
00299     // has more dimensions than the ImageIORegion, then the defaults of the ImageRegion
00300     // will take care of the remaining codimension. If the ImageRegion has less dimensions
00301     // than the ImageIORegion, then the remaining IO dimensions are simply ignored.
00302     //
00303     const unsigned int ioDimension = inIORegion.GetImageDimension();
00304     const unsigned int imageDimension = VDimension;
00305 
00306     unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
00307 
00308     for(unsigned int i=0; i<minDimension; i++)
00309       {
00310       size[i]  = inIORegion.GetSize(i);
00311       index[i] = inIORegion.GetIndex(i);
00312       }
00313 
00314     outImageRegion.SetSize( size );
00315     outImageRegion.SetIndex( index );
00316     }
00317 };
00318 
00319 } // end namespace itk
00320 
00321 #endif
00322 

Generated at Tue Jul 29 20:30:08 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000