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: 2008-05-08 15:41:46 $
00007   Version:   $Revision: 1.17 $
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 #if defined(_MSC_VER)
00028 
00029 // local variable may be used without having been initialized
00030 #pragma warning ( disable : 4701 )
00031 #endif
00032 namespace itk
00033 {
00034 
00052 template<unsigned int VOffsetDimension=2>
00053 class Offset {
00054 public:
00056   typedef Offset  Self;
00057 
00059   static unsigned int GetOffsetDimension() { return VOffsetDimension; }
00060 
00062   typedef   Offset<VOffsetDimension>  OffsetType;
00063   typedef   long OffsetValueType;
00064 
00066   const Self
00067   operator+(const Self &offset) const
00068     {
00069     Self result;
00070     for (unsigned int i=0; i < VOffsetDimension; i++)
00071       { result[i] = m_Offset[i] + offset[i]; }
00072     return result;
00073     }
00075 
00077   const Self
00078   operator+(const Size<VOffsetDimension> &size) const
00079     {
00080     Self result;
00081     for (unsigned int i=0; i < VOffsetDimension; i++)
00082       { result[i] = m_Offset[i] + size[i]; }
00083     return result;
00084     }
00086 
00088   const Self &
00089   operator+=(const Size<VOffsetDimension> &size)
00090     {
00091     for (unsigned int i=0; i < VOffsetDimension; i++)
00092       { m_Offset[i] += size[i]; }
00093     return *this;
00094     }
00096 
00098   const Self &
00099   operator-=(const Size<VOffsetDimension> &size)
00100     {
00101     for (unsigned int i=0; i < VOffsetDimension; i++)
00102       { m_Offset[i] -= size[i]; }
00103     return *this;
00104     }
00106 
00108   const Self
00109   operator-(const Self &vec)
00110     {
00111     Self result;
00112     for (unsigned int i=0; i < VOffsetDimension; i++)
00113       { result[i] = m_Offset[i] - vec.m_Offset[i]; }
00114     return result;
00115     }
00117 
00119   const Self &
00120   operator+=(const Self &vec)
00121     {
00122     for (unsigned int i=0; i < VOffsetDimension; i++)
00123       { m_Offset[i] += vec.m_Offset[i]; }
00124     return *this;
00125     }
00127 
00129   const Self &
00130   operator-=(const Self &vec)
00131     {
00132     for (unsigned int i=0; i < VOffsetDimension; i++)
00133       { m_Offset[i] -= vec.m_Offset[i]; }
00134     return *this;
00135     }
00137 
00139   bool
00140   operator==(const Self &vec) const
00141     {
00142     bool same=1;
00143     for (unsigned int i=0; i < VOffsetDimension && same; i++)
00144       { same = (m_Offset[i] == vec.m_Offset[i]); }
00145     return same;
00146     }
00148 
00150   bool
00151   operator!=(const Self &vec) const
00152     {
00153     bool same=1;
00154     for (unsigned int i=0; i < VOffsetDimension && same; i++)
00155       { same = (m_Offset[i] == vec.m_Offset[i]); }
00156     return !same;
00157     }
00159 
00162   OffsetValueType & operator[](unsigned int dim)
00163     { return m_Offset[dim]; }
00164 
00168   OffsetValueType operator[](unsigned int dim) const
00169     { return m_Offset[dim]; }
00170 
00173   const OffsetValueType *GetOffset() const { return m_Offset; };
00174 
00179   void SetOffset(const OffsetValueType val[VOffsetDimension])
00180     { memcpy(m_Offset, val, sizeof(OffsetValueType)*VOffsetDimension); }
00181 
00185   static Self GetBasisOffset(unsigned int dim); 
00186 
00189   void Fill(OffsetValueType value)
00190     { for(unsigned int i=0;i < VOffsetDimension; ++i) m_Offset[i] = value; }
00191 
00197   OffsetValueType m_Offset[VOffsetDimension];
00198 
00199 
00200 // force gccxml to find the constructors found before the internal upgrade to gcc 4.2
00201 #if defined(CABLE_CONFIGURATION)
00202   Offset(); //purposely not implemented
00203   Offset(const Self&); //purposely not implemented
00204   void operator=(const Self&); //purposely not implemented
00205 #endif
00206 
00207 };
00208 
00209 
00210 template<unsigned int VOffsetDimension>
00211 Offset<VOffsetDimension> 
00212 Offset<VOffsetDimension>
00213 ::GetBasisOffset(unsigned int dim)
00214 {
00215   Self ind;
00216   
00217   memset(ind.m_Offset, 0, sizeof(OffsetValueType)*VOffsetDimension);
00218   ind.m_Offset[dim] = 1;
00219   return ind;
00220 }
00221 
00222 template<unsigned int VOffsetDimension>
00223 std::ostream & operator<<(std::ostream &os, const Offset<VOffsetDimension> &ind)
00224 {
00225   os << "[";
00226   unsigned int dimlim = VOffsetDimension - 1;
00227   for (unsigned int i=0; i < dimlim; ++i)
00228     {
00229     os << ind[i] << ", ";
00230     }
00231   if (VOffsetDimension >= 1)
00232     {
00233     os << ind[VOffsetDimension-1];
00234     }
00235   os << "]";
00236   return os;
00237 }
00238 
00239 } // end namespace itk
00240 
00241 #endif 
00242 

Generated at Tue Jul 29 21:34:24 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000