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     }
00069 
00071   const Self
00072   operator+(const Size<VOffsetDimension> &size) const
00073     {
00074     Self result;
00075     for (unsigned int i=0; i < VOffsetDimension; i++)
00076       { result[i] = m_Offset[i] + size[i]; }
00077     return result;
00078     }
00079 
00081   const Self &
00082   operator+=(const Size<VOffsetDimension> &size)
00083     {
00084     for (unsigned int i=0; i < VOffsetDimension; i++)
00085       { m_Offset[i] += size[i]; }
00086     return *this;
00087     }
00088 
00090   const Self &
00091   operator-=(const Size<VOffsetDimension> &size)
00092     {
00093     for (unsigned int i=0; i < VOffsetDimension; i++)
00094       { m_Offset[i] -= size[i]; }
00095     return *this;
00096     }
00097 
00099   const Self
00100   operator-(const Self &vec)
00101     {
00102     Self result;
00103     for (unsigned int i=0; i < VOffsetDimension; i++)
00104       { result[i] = m_Offset[i] - vec.m_Offset[i]; }
00105     return result;
00106     }
00107 
00109   const Self &
00110   operator+=(const Self &vec)
00111     {
00112     for (unsigned int i=0; i < VOffsetDimension; i++)
00113       { m_Offset[i] += vec.m_Offset[i]; }
00114     return *this;
00115     }
00116 
00118   const Self &
00119   operator-=(const Self &vec)
00120     {
00121     for (unsigned int i=0; i < VOffsetDimension; i++)
00122       { m_Offset[i] -= vec.m_Offset[i]; }
00123     return *this;
00124     }
00125 
00127   bool
00128   operator==(const Self &vec) const
00129     {
00130     bool same=1;
00131     for (unsigned int i=0; i < VOffsetDimension && same; i++)
00132       { same = (m_Offset[i] == vec.m_Offset[i]); }
00133     return same;
00134     }
00135 
00137   bool
00138   operator!=(const Self &vec) const
00139     {
00140     bool same=1;
00141     for (unsigned int i=0; i < VOffsetDimension && same; i++)
00142       { same = (m_Offset[i] == vec.m_Offset[i]); }
00143     return !same;
00144     }
00145 
00148   OffsetValueType & operator[](unsigned int dim)
00149     { return m_Offset[dim]; }
00150 
00154   OffsetValueType operator[](unsigned int dim) const
00155     { return m_Offset[dim]; }
00156 
00159   const OffsetValueType *GetOffset() const { return m_Offset; };
00160 
00165   void SetOffset(const OffsetValueType val[VOffsetDimension])
00166     { memcpy(m_Offset, val, sizeof(OffsetValueType)*VOffsetDimension); }
00167 
00171   static Self GetBasisOffset(unsigned int dim); 
00172 
00175   void Fill(OffsetValueType value)
00176     { for(unsigned int i=0;i < VOffsetDimension; ++i) m_Offset[i] = value; }
00177   
00183   OffsetValueType m_Offset[VOffsetDimension];
00184 
00185 };
00186 
00187 
00188 template<unsigned int VOffsetDimension>
00189 Offset<VOffsetDimension> 
00190 Offset<VOffsetDimension>
00191 ::GetBasisOffset(unsigned int dim)
00192 {
00193   Self ind;
00194   
00195   memset(ind.m_Offset, 0, sizeof(OffsetValueType)*VOffsetDimension);
00196   ind.m_Offset[dim] = 1;
00197   return ind;
00198 }
00199 
00200 template<unsigned int VOffsetDimension>
00201 std::ostream & operator<<(std::ostream &os, const Offset<VOffsetDimension> &ind)
00202 {
00203   os << "[";
00204   unsigned int dimlim = VOffsetDimension - 1;
00205   for (unsigned int i=0; i < dimlim; ++i)
00206     {
00207     os << ind[i] << ", ";
00208     }
00209   if (VOffsetDimension >= 1)
00210     {
00211     os << ind[VOffsetDimension-1];
00212     }
00213   os << "]";
00214   return os;
00215 }
00216 
00217 } // end namespace itk
00218 
00219 #endif 

Generated at Wed May 24 23:47:55 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000