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: 2002/01/15 18:57:10 $
00007   Version:   $Revision: 1.10 $
00008 
00009   Copyright (c) 2002 Insight 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 
00043 template<unsigned int VOffsetDimension=2>
00044 class Offset {
00045 public:
00047   typedef Offset  Self;
00048   
00050   static unsigned int GetOffsetDimension() { return VOffsetDimension; }
00051 
00053   typedef   Offset<VOffsetDimension>  OffsetType;
00054   typedef   long OffsetValueType;
00055     
00057   const Self
00058   operator+(const Self &offset) const
00059     {
00060     Self result;
00061     for (unsigned int i=0; i < VOffsetDimension; i++)
00062       { result[i] = m_Offset[i] + offset[i]; }
00063     return result;
00064     }
00065 
00067   const Self
00068   operator+(const Size<VOffsetDimension> &size) const
00069     {
00070     Self result;
00071     for (unsigned int i=0; i < VOffsetDimension; i++)
00072       { result[i] = m_Offset[i] + size[i]; }
00073     return result;
00074     }
00075 
00077   const Self &
00078   operator+=(const Size<VOffsetDimension> &size)
00079     {
00080     for (unsigned int i=0; i < VOffsetDimension; i++)
00081       { m_Offset[i] += size[i]; }
00082     return *this;
00083     }
00084 
00086   const Self
00087   operator-(const Self &vec)
00088     {
00089     Self result;
00090     for (unsigned int i=0; i < VOffsetDimension; i++)
00091       { result[i] = m_Offset[i] - vec.m_Offset[i]; }
00092     return result;
00093     }
00094 
00096   const Self &
00097   operator-=(const Self &vec)
00098     {
00099     for (unsigned int i=0; i < VOffsetDimension; i++)
00100       { m_Offset[i] -= vec.m_Offset[i]; }
00101     return *this;
00102     }
00103 
00105   bool
00106   operator==(const Self &vec) const
00107     {
00108     bool same=1;
00109     for (unsigned int i=0; i < VOffsetDimension && same; i++)
00110       { same = (m_Offset[i] == vec.m_Offset[i]); }
00111     return same;
00112     }
00113 
00115   bool
00116   operator!=(const Self &vec) const
00117     {
00118     bool same=1;
00119     for (unsigned int i=0; i < VOffsetDimension && same; i++)
00120       { same = (m_Offset[i] == vec.m_Offset[i]); }
00121     return !same;
00122     }
00123 
00126   OffsetValueType & operator[](unsigned int dim)
00127     { return m_Offset[dim]; }
00128 
00132   OffsetValueType operator[](unsigned int dim) const
00133     { return m_Offset[dim]; }
00134 
00137   const OffsetValueType *GetOffset() const { return m_Offset; };
00138 
00143   void SetOffset(const OffsetValueType val[VOffsetDimension])
00144     { memcpy(m_Offset, val, sizeof(OffsetValueType)*VOffsetDimension); }
00145 
00149   static Self GetBasisOffset(unsigned int dim); 
00150 
00153   void Fill(OffsetValueType value)
00154     { for(unsigned int i=0;i < VOffsetDimension; ++i) m_Offset[i] = value; }
00155   
00161   OffsetValueType m_Offset[VOffsetDimension];
00162 
00163 };
00164 
00165 
00166 template<unsigned int VOffsetDimension>
00167 Offset<VOffsetDimension> 
00168 Offset<VOffsetDimension>
00169 ::GetBasisOffset(unsigned int dim)
00170 {
00171   Self ind;
00172   
00173   memset(ind.m_Offset, 0, sizeof(OffsetValueType)*VOffsetDimension);
00174   ind.m_Offset[dim] = 1;
00175   return ind;
00176 }
00177 
00178 template<unsigned int VOffsetDimension>
00179 std::ostream & operator<<(std::ostream &os, const Offset<VOffsetDimension> &ind)
00180 {
00181   os << "[";
00182   for (unsigned int i=0; i < VOffsetDimension - 1; ++i)
00183     {
00184     os << ind[i] << ", ";
00185     }
00186   if (VOffsetDimension >= 1)
00187     {
00188     os << ind[VOffsetDimension-1];
00189     }
00190   os << "]";
00191   return os;
00192 }
00193 
00194 } // end namespace itk
00195 
00196 #endif 

Generated at Fri May 21 01:15:09 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000