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

itkOffset.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkOffset.h,v $
00005   Language:  C++
00006   Date:      $Date: 2004/06/20 12:34:13 $
00007   Version:   $Revision: 1.14 $
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 __itkOffset_h
00018 #define __itkOffset_h
00019 
00020 #include "itkMacro.h"
00021 #include "itkSize.h"
00022 
00023 #include <memory>
00024 
00025 #include "itkExceptionObject.h"
00026 
00027 namespace itk
00028 {
00029 
00047 template<unsigned int VOffsetDimension=2>
00048 class Offset {
00049 public:
00051   typedef Offset  Self;
00052 
00054   static unsigned int GetOffsetDimension() { return VOffsetDimension; }
00055 
00057   typedef   Offset<VOffsetDimension>  OffsetType;
00058   typedef   long OffsetValueType;
00059 
00061   const Self
00062   operator+(const Self &offset) const
00063     {
00064     Self result;
00065     for (unsigned int i=0; i < VOffsetDimension; i++)
00066       { result[i] = m_Offset[i] + offset[i]; }
00067     return result;
00068     }
00070 
00072   const Self
00073   operator+(const Size<VOffsetDimension> &size) const
00074     {
00075     Self result;
00076     for (unsigned int i=0; i < VOffsetDimension; i++)
00077       { result[i] = m_Offset[i] + size[i]; }
00078     return result;
00079     }
00081 
00083   const Self &
00084   operator+=(const Size<VOffsetDimension> &size)
00085     {
00086     for (unsigned int i=0; i < VOffsetDimension; i++)
00087       { m_Offset[i] += size[i]; }
00088     return *this;
00089     }
00091 
00093   const Self &
00094   operator-=(const Size<VOffsetDimension> &size)
00095     {
00096     for (unsigned int i=0; i < VOffsetDimension; i++)
00097       { m_Offset[i] -= size[i]; }
00098     return *this;
00099     }
00101 
00103   const Self
00104   operator-(const Self &vec)
00105     {
00106     Self result;
00107     for (unsigned int i=0; i < VOffsetDimension; i++)
00108       { result[i] = m_Offset[i] - vec.m_Offset[i]; }
00109     return result;
00110     }
00112 
00114   const Self &
00115   operator+=(const Self &vec)
00116     {
00117     for (unsigned int i=0; i < VOffsetDimension; i++)
00118       { m_Offset[i] += vec.m_Offset[i]; }
00119     return *this;
00120     }
00122 
00124   const Self &
00125   operator-=(const Self &vec)
00126     {
00127     for (unsigned int i=0; i < VOffsetDimension; i++)
00128       { m_Offset[i] -= vec.m_Offset[i]; }
00129     return *this;
00130     }
00132 
00134   bool
00135   operator==(const Self &vec) const
00136     {
00137     bool same=1;
00138     for (unsigned int i=0; i < VOffsetDimension && same; i++)
00139       { same = (m_Offset[i] == vec.m_Offset[i]); }
00140     return same;
00141     }
00143 
00145   bool
00146   operator!=(const Self &vec) const
00147     {
00148     bool same=1;
00149     for (unsigned int i=0; i < VOffsetDimension && same; i++)
00150       { same = (m_Offset[i] == vec.m_Offset[i]); }
00151     return !same;
00152     }
00154 
00157   OffsetValueType & operator[](unsigned int dim)
00158     { return m_Offset[dim]; }
00159 
00163   OffsetValueType operator[](unsigned int dim) const
00164     { return m_Offset[dim]; }
00165 
00168   const OffsetValueType *GetOffset() const { return m_Offset; };
00169 
00174   void SetOffset(const OffsetValueType val[VOffsetDimension])
00175     { memcpy(m_Offset, val, sizeof(OffsetValueType)*VOffsetDimension); }
00176 
00180   static Self GetBasisOffset(unsigned int dim); 
00181 
00184   void Fill(OffsetValueType value)
00185     { for(unsigned int i=0;i < VOffsetDimension; ++i) m_Offset[i] = value; }
00186 
00192   OffsetValueType m_Offset[VOffsetDimension];
00193 
00194 };
00195 
00196 
00197 template<unsigned int VOffsetDimension>
00198 Offset<VOffsetDimension> 
00199 Offset<VOffsetDimension>
00200 ::GetBasisOffset(unsigned int dim)
00201 {
00202   Self ind;
00203   
00204   memset(ind.m_Offset, 0, sizeof(OffsetValueType)*VOffsetDimension);
00205   ind.m_Offset[dim] = 1;
00206   return ind;
00207 }
00208 
00209 template<unsigned int VOffsetDimension>
00210 std::ostream & operator<<(std::ostream &os, const Offset<VOffsetDimension> &ind)
00211 {
00212   os << "[";
00213   unsigned int dimlim = VOffsetDimension - 1;
00214   for (unsigned int i=0; i < dimlim; ++i)
00215     {
00216     os << ind[i] << ", ";
00217     }
00218   if (VOffsetDimension >= 1)
00219     {
00220     os << ind[VOffsetDimension-1];
00221     }
00222   os << "]";
00223   return os;
00224 }
00225 
00226 } // end namespace itk
00227 
00228 #endif 
00229 

Generated at Mon Mar 12 01:58:58 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000