Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 #include "itkIndex.h"
00025 #include "itkSize.h"
00026
00027 namespace itk
00028 {
00029
00053 class ITK_EXPORT ImageIORegion: public Region
00054 {
00055 public:
00057 typedef ImageIORegion Self;
00058 typedef Region Superclass;
00059
00061 typedef size_t SizeValueType;
00062 typedef ptrdiff_t IndexValueType;
00063 typedef ptrdiff_t OffsetValueType;
00064
00065
00067 typedef std::vector<IndexValueType> IndexType;
00068
00070 typedef std::vector<SizeValueType> SizeType;
00071
00073 typedef Superclass::RegionType RegionType;
00074
00076 itkTypeMacro(ImageIORegion, Region);
00077
00079 unsigned int GetImageDimension() const;
00080
00084 unsigned int GetRegionDimension() const;
00085
00087 virtual RegionType GetRegionType() const;
00088
00091 ImageIORegion(unsigned int dimension);
00092
00095 ImageIORegion();
00096
00099 virtual ~ImageIORegion();
00100
00103 ImageIORegion(const Self& region);
00104
00107 void operator=(const Self& region);
00108
00110 void SetIndex(const IndexType &index);
00111
00113 const IndexType & GetIndex() const;
00114
00117 void SetSize(const SizeType &size);
00118
00120 const SizeType & GetSize() const;
00121
00125 SizeValueType GetSize(unsigned long i) const;
00126 IndexValueType GetIndex(unsigned long i) const;
00127 void SetSize(const unsigned long i, SizeValueType size);
00128 void SetIndex(const unsigned long i, IndexValueType idx);
00130
00132 bool operator==(const Self ®ion) const;
00133
00135 bool operator!=(const Self ®ion) const;
00136
00138 bool IsInside(const IndexType &index) const;
00139
00141 bool IsInside(const Self ®ion) const;
00142
00145 SizeValueType GetNumberOfPixels( void ) const;
00146
00147 protected:
00152 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00153
00154 private:
00155 unsigned int m_ImageDimension;
00156 IndexType m_Index;
00157 SizeType m_Size;
00158 };
00159
00160
00161
00162 extern std::ostream & operator<<(std::ostream &os, const ImageIORegion ®ion);
00163
00168 template< unsigned int VDimension >
00169 class ImageIORegionAdaptor
00170 {
00171 public:
00172 typedef ImageRegion<VDimension> ImageRegionType;
00173 typedef ImageIORegion ImageIORegionType;
00174
00175 typedef typename ImageRegionType::SizeType ImageSizeType;
00176 typedef typename ImageRegionType::IndexType ImageIndexType;
00177
00178 itkLegacyMacro(static void Convert( const ImageRegionType & outImageRegion, ImageIORegionType & inIORegion) );
00179
00180 static void Convert( const ImageRegionType & inImageRegion, ImageIORegionType & outIORegion, const ImageIndexType &largestRegionIndex)
00181 {
00182
00183
00184
00185
00186
00187
00188
00189 const unsigned int ioDimension = outIORegion.GetImageDimension();
00190 const unsigned int imageDimension = VDimension;
00191
00192 unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
00193
00194 ImageSizeType size = inImageRegion.GetSize();
00195 ImageIndexType index = inImageRegion.GetIndex();
00196
00197 for( unsigned int i = 0; i < minDimension; i++ )
00198 {
00199 outIORegion.SetSize( i, size[i] );
00200 outIORegion.SetIndex( i, index[i] - largestRegionIndex[i]);
00201 }
00202
00203
00204
00205
00206 for( unsigned int k = minDimension; k < ioDimension; k++ )
00207 {
00208 outIORegion.SetSize( k, 1 );
00209 outIORegion.SetIndex( k, 0 );
00210 }
00211 }
00212
00213 itkLegacyMacro(static void Convert( const ImageIORegionType & inIORegion, ImageRegionType & outImageRegion) );
00214
00215
00216 static void Convert( const ImageIORegionType & inIORegion, ImageRegionType & outImageRegion, const ImageIndexType &largestRegionIndex )
00217 {
00218 ImageSizeType size;
00219 ImageIndexType index;
00220
00221 size.Fill(1);
00222 index.Fill(0);
00223
00224
00225
00226
00227
00228
00229
00230
00231 const unsigned int ioDimension = inIORegion.GetImageDimension();
00232 const unsigned int imageDimension = VDimension;
00233
00234 unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
00235
00236 for(unsigned int i=0; i<minDimension; i++)
00237 {
00238 size[i] = inIORegion.GetSize(i);
00239 index[i] = inIORegion.GetIndex(i) + largestRegionIndex[i];
00240 }
00241
00242 outImageRegion.SetSize( size );
00243 outImageRegion.SetIndex( index );
00244 }
00245 };
00246
00247 #if !defined(ITK_LEGACY_REMOVE)
00248 template< unsigned int VDimension >
00249 void ImageIORegionAdaptor<VDimension>::Convert( const ImageRegionType & inImageRegion, ImageIORegionType & outIORegion )
00250 {
00251 itkGenericLegacyBodyMacro(ImageIORegionAdaptor::Convert, 4.0);
00252
00253 ImageIndexType index;
00254 index.Fill(0);
00255 ImageIORegionAdaptor<VDimension>::Convert(inImageRegion, outIORegion, index);
00256 }
00257
00258 template< unsigned int VDimension >
00259 void ImageIORegionAdaptor<VDimension>::Convert( const ImageIORegionType & inIORegion, ImageRegionType & outImageRegion )
00260 {
00261 itkGenericLegacyBodyMacro(ImageIORegionAdaptor::Convert, 4.0);
00262
00263 ImageIndexType index;
00264 index.Fill(0);
00265 ImageIORegionAdaptor<VDimension>::Convert(inIORegion, outImageRegion, index);
00266 }
00267 #endif
00268
00269 }
00270
00271 #endif
00272