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 unsigned long SizeValueType;
00062 typedef long IndexValueType;
00063
00064
00066 typedef std::vector<IndexValueType> IndexType;
00067
00069 typedef std::vector<SizeValueType> SizeType;
00070
00072 typedef Superclass::RegionType RegionType;
00073
00075 itkTypeMacro(ImageIORegion, Region);
00076
00078 unsigned int GetImageDimension() const;
00079
00083 unsigned int GetRegionDimension() const;
00084
00086 virtual RegionType GetRegionType() const;
00087
00090 ImageIORegion(unsigned int dimension);
00091
00094 ImageIORegion();
00095
00098 virtual ~ImageIORegion();
00099
00102 ImageIORegion(const Self& region);
00103
00106 void operator=(const Self& region);
00107
00109 void SetIndex(const IndexType &index);
00110
00112 const IndexType & GetIndex() const;
00113
00116 void SetSize(const SizeType &size);
00117
00119 const SizeType & GetSize() const;
00120
00124 SizeValueType GetSize(unsigned long i) const;
00125 IndexValueType GetIndex(unsigned long i) const;
00126 void SetSize(const unsigned long i, SizeValueType size);
00127 void SetIndex(const unsigned long i, IndexValueType idx);
00129
00131 bool operator==(const Self ®ion) const;
00132
00134 bool operator!=(const Self ®ion) const;
00135
00137 bool IsInside(const IndexType &index) const;
00138
00140 bool IsInside(const Self ®ion) const;
00141
00142
00143 protected:
00148 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00149
00150 private:
00151 unsigned int m_ImageDimension;
00152 IndexType m_Index;
00153 SizeType m_Size;
00154 };
00155
00156
00157
00158 extern std::ostream & operator<<(std::ostream &os, const ImageIORegion ®ion);
00159
00164 template< unsigned int VDimension >
00165 class ImageIORegionAdaptor
00166 {
00167 public:
00168 typedef ImageRegion<VDimension> ImageRegionType;
00169 typedef ImageIORegion ImageIORegionType;
00170
00171 typedef typename ImageRegionType::SizeType ImageSizeType;
00172 typedef typename ImageRegionType::IndexType ImageIndexType;
00173
00174 itkLegacyMacro(static void Convert( const ImageRegionType & outImageRegion, ImageIORegionType & inIORegion) );
00175
00176 static void Convert( const ImageRegionType & inImageRegion, ImageIORegionType & outIORegion, const ImageIndexType &largestRegionIndex)
00177 {
00178
00179
00180
00181
00182
00183
00184
00185 const unsigned int ioDimension = outIORegion.GetImageDimension();
00186 const unsigned int imageDimension = VDimension;
00187
00188 unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
00189
00190 ImageSizeType size = inImageRegion.GetSize();
00191 ImageIndexType index = inImageRegion.GetIndex();
00192
00193 for( unsigned int i = 0; i < minDimension; i++ )
00194 {
00195 outIORegion.SetSize( i, size[i] );
00196 outIORegion.SetIndex( i, index[i] - largestRegionIndex[i]);
00197 }
00198
00199
00200
00201
00202 for( unsigned int k = minDimension; k < ioDimension; k++ )
00203 {
00204 outIORegion.SetSize( k, 1 );
00205 outIORegion.SetIndex( k, 0 );
00206 }
00207 }
00208
00209 itkLegacyMacro(static void Convert( const ImageIORegionType & inIORegion, ImageRegionType & outImageRegion) );
00210
00211
00212 static void Convert( const ImageIORegionType & inIORegion, ImageRegionType & outImageRegion, const ImageIndexType &largestRegionIndex )
00213 {
00214 ImageSizeType size;
00215 ImageIndexType index;
00216
00217 size.Fill(1);
00218 index.Fill(0);
00219
00220
00221
00222
00223
00224
00225
00226
00227 const unsigned int ioDimension = inIORegion.GetImageDimension();
00228 const unsigned int imageDimension = VDimension;
00229
00230 unsigned int minDimension = ( ioDimension > imageDimension ) ? imageDimension : ioDimension;
00231
00232 for(unsigned int i=0; i<minDimension; i++)
00233 {
00234 size[i] = inIORegion.GetSize(i);
00235 index[i] = inIORegion.GetIndex(i) + largestRegionIndex[i];
00236 }
00237
00238 outImageRegion.SetSize( size );
00239 outImageRegion.SetIndex( index );
00240 }
00241 };
00242
00243 #if !defined(ITK_LEGACY_REMOVE)
00244 template< unsigned int VDimension >
00245 void ImageIORegionAdaptor<VDimension>::Convert( const ImageRegionType & inImageRegion, ImageIORegionType & outIORegion )
00246 {
00247 itkGenericLegacyBodyMacro(ImageIORegionAdaptor::Convert, 4.0);
00248
00249 ImageIndexType index;
00250 index.Fill(0);
00251 ImageIORegionAdaptor<VDimension>::Convert(inImageRegion, outIORegion, index);
00252 }
00253
00254 template< unsigned int VDimension >
00255 void ImageIORegionAdaptor<VDimension>::Convert( const ImageIORegionType & inIORegion, ImageRegionType & outImageRegion )
00256 {
00257 itkGenericLegacyBodyMacro(ImageIORegionAdaptor::Convert, 4.0);
00258
00259 ImageIndexType index;
00260 index.Fill(0);
00261 ImageIORegionAdaptor<VDimension>::Convert(inIORegion, outImageRegion, index);
00262 }
00263 #endif
00264
00265 }
00266
00267 #endif
00268