Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __cmtkRegion_h_included_
00034 #define __cmtkRegion_h_included_
00035
00036 #include <cmtkconfig.h>
00037
00038 #include <Base/cmtkFixedVector.h>
00039
00040 #include <System/cmtkSmartPtr.h>
00041 #include <System/cmtkSmartConstPtr.h>
00042
00043 #include <fstream>
00044
00045 namespace
00046 cmtk
00047 {
00049 template<size_t NDIM,typename T=int>
00050 class Region
00051 {
00052 public:
00054 typedef Region<NDIM,T> Self;
00055
00057 typedef FixedVector<NDIM,T> IndexType;
00058
00060 typedef SmartPointer<Self> SmartPtr;
00061
00063 typedef SmartConstPointer<Self> SmartConstPtr;
00064
00066 Region() {}
00067
00069 Region( const typename Self::IndexType& fromIndex, const typename Self::IndexType& toIndex )
00070 {
00071 this->m_RegionFrom = fromIndex;
00072 this->m_RegionTo = toIndex;
00073 }
00074
00076 typename Self::IndexType& From()
00077 {
00078 return this->m_RegionFrom;
00079 }
00080
00082 const typename Self::IndexType& From() const
00083 {
00084 return this->m_RegionFrom;
00085 }
00086
00088 typename Self::IndexType& To()
00089 {
00090 return this->m_RegionTo;
00091 }
00092
00094 const typename Self::IndexType& To() const
00095 {
00096 return this->m_RegionTo;
00097 }
00098
00100 T Size() const
00101 {
00102 T size = (this->m_RegionTo[0]-this->m_RegionFrom[0]);
00103 for ( size_t i = 1; i < NDIM; ++i )
00104 size *= (this->m_RegionTo[i]-this->m_RegionFrom[i]);
00105 return size;
00106 }
00107
00109 const typename Self::IndexType begin() const
00110 {
00111 return this->m_RegionFrom;
00112 }
00113
00115 const typename Self::IndexType end() const
00116 {
00117 typename Self::IndexType e = this->m_RegionFrom;
00118 ++e[NDIM-1];
00119 return e;
00120 }
00121
00122 private:
00124 typename Self::IndexType m_RegionFrom;
00125
00127 typename Self::IndexType m_RegionTo;
00128 };
00129
00131 template<size_t NDIM,typename T>
00132 std::ofstream& operator<<( std::ofstream& stream, const Region<NDIM,T>& region )
00133 {
00134 return stream << region.From() << region.To();
00135 }
00136
00138 template<size_t NDIM,typename T>
00139 std::ifstream& operator>>( std::ifstream& stream, Region<NDIM,T>& region )
00140 {
00141 return stream >> region.From() >> region.To();
00142 }
00143
00144 }
00145
00146 #endif // #ifndef __cmtkRegion_h_included_