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
00024 namespace itk
00025 {
00026
00044 class ITK_EXPORT ImageIORegion: public Region
00045 {
00046 public:
00048 typedef ImageIORegion Self;
00049 typedef Region Superclass;
00050
00052 itkTypeMacro(ImageIORegion, Region);
00053
00055 unsigned int GetImageDimension() const
00056 { return m_ImageDimension; }
00057
00061 unsigned int GetRegionDimension() const
00062 {
00063 unsigned long dim=0;
00064 for (unsigned long i=0; i<m_ImageDimension; i++)
00065 {
00066 if ( m_Size[i] > 1 ) dim++;
00067 }
00068 return dim;
00069 }
00070
00072 typedef std::vector<long> IndexType;
00073
00075 typedef std::vector<long> SizeType;
00076
00078 virtual Superclass::RegionType GetRegionType() const
00079 {return Superclass::ITK_STRUCTURED_REGION;}
00080
00083 ImageIORegion(unsigned int dimension)
00084 {
00085 m_ImageDimension = dimension;
00086 m_Index.resize(m_ImageDimension);
00087 m_Size.resize(m_ImageDimension);
00088 std::fill(m_Index.begin(), m_Index.end(), 0);
00089 std::fill(m_Size.begin(), m_Size.end(), 0);
00090 }
00091
00094 ImageIORegion()
00095 {
00096 m_ImageDimension = 2;
00097 m_Index.resize(2);
00098 m_Size.resize(2);
00099 std::fill(m_Index.begin(), m_Index.end(), 0);
00100 std::fill(m_Size.begin(), m_Size.end(), 0);
00101 }
00102
00105 virtual ~ImageIORegion(){};
00106
00109 ImageIORegion(const Self& region): Region()
00110 {
00111 m_Index =region.m_Index;
00112 m_Size = region.m_Size;
00113 m_ImageDimension = region.m_ImageDimension;
00114 }
00115
00118 void operator=(const Self& region)
00119 {
00120 m_Index = region.m_Index;
00121 m_Size = region.m_Size;
00122 m_ImageDimension = region.m_ImageDimension;
00123 };
00124
00126 void SetIndex(const IndexType &index)
00127 { m_Index = index; };
00128
00130 const IndexType& GetIndex() const
00131 { return m_Index; };
00132
00135 void SetSize(const SizeType &size)
00136 { m_Size = size; };
00137
00139 const SizeType& GetSize() const
00140 { return m_Size;}
00141
00145 long GetSize(unsigned long i) const
00146 { return m_Size[i]; }
00147 long GetIndex(unsigned long i) const
00148 { return m_Index[i]; }
00149 void SetSize(const unsigned long i, long size)
00150 {m_Size[i] = size;}
00151 void SetIndex(const unsigned long i, long idx)
00152 {m_Index[i] = idx;}
00153
00155 bool
00156 operator==(const Self ®ion) const
00157 {
00158 bool same = 1;
00159 same = (m_Index == region.m_Index);
00160 same = same && (m_Size == region.m_Size);
00161 same = same && (m_ImageDimension == region.m_ImageDimension);
00162 return same;
00163 }
00164
00166 bool
00167 operator!=(const Self ®ion) const
00168 {
00169 bool same = 1;
00170 same = (m_Index == region.m_Index);
00171 same = same && (m_Size == region.m_Size);
00172 same = same && (m_ImageDimension == region.m_ImageDimension);
00173 return !same;
00174 }
00175
00177 bool
00178 IsInside(const IndexType &index) const
00179 {
00180 for(unsigned int i=0; i<m_ImageDimension; i++)
00181 {
00182 if( index[i] < m_Index[i] )
00183 {
00184 return false;
00185 }
00186 if( index[i] >= m_Index[i] + m_Size[i] )
00187 {
00188 return false;
00189 }
00190 }
00191 return true;
00192 }
00193
00196 unsigned long GetNumberOfPixels() const;
00197
00198 protected:
00203 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00204
00205 private:
00206 unsigned int m_ImageDimension;
00207 std::vector<long> m_Index;
00208 std::vector<long> m_Size;
00209 };
00210
00211
00212
00213 extern std::ostream & operator<<(std::ostream &os, const ImageIORegion ®ion);
00214
00215 }
00216
00217 #endif
00218