00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
#ifndef __itkSize_h
00018
#define __itkSize_h
00019
00020
#include "itkMacro.h"
00021
00022
namespace itk
00023 {
00024
00045
template<
unsigned int VDimension=2>
00046 class Size {
00047
public:
00049 typedef Size Self;
00050
00052 typedef Size<VDimension> SizeType;
00053 typedef unsigned long SizeValueType;
00054
00056 static unsigned int GetSizeDimension(
void) {
return VDimension; }
00057
00059
const Self
00060 operator+(
const Self &vec)
00061 {
00062
Self result;
00063
for (
unsigned int i=0; i < VDimension; i++)
00064 { result[i] = m_Size[i] + vec.
m_Size[i]; }
00065
return result;
00066 }
00067
00069
const Self &
00070
operator+=(
const Self &vec)
00071 {
00072
for (
unsigned int i=0; i < VDimension; i++)
00073 { m_Size[i] += vec.m_Size[i]; }
00074
return *
this;
00075 }
00076
00078
const Self
00079
operator-(
const Self &vec)
00080 {
00081 Self result;
00082
for (
unsigned int i=0; i < VDimension; i++)
00083 { result[i] = m_Size[i] - vec.m_Size[i]; }
00084
return result;
00085 }
00086
00088
const Self &
00089
operator-=(
const Self &vec)
00090 {
00091
for (
unsigned int i=0; i < VDimension; i++)
00092 { m_Size[i] -= vec.m_Size[i]; }
00093
return *
this;
00094 }
00095
00097
const Self
00098
operator*(
const Self &vec)
00099 {
00100 Self result;
00101
for (
unsigned int i=0; i < VDimension; i++)
00102 { result[i] = m_Size[i] * vec.m_Size[i]; }
00103
return result;
00104 }
00105
00107
const Self &
00108
operator*=(
const Self &vec)
00109 {
00110
for (
unsigned int i=0; i < VDimension; i++)
00111 { m_Size[i] *= vec.m_Size[i]; }
00112
return *
this;
00113 }
00114
00116
bool
00117
operator==(
const Self &vec)
const
00118
{
00119
bool same=1;
00120
for (
unsigned int i=0; i < VDimension && same; i++)
00121 { same = (m_Size[i] == vec.m_Size[i]); }
00122
return same;
00123 }
00124
00126
bool
00127
operator!=(
const Self &vec)
const
00128
{
00129
bool same=1;
00130
for (
unsigned int i=0; i < VDimension && same; i++)
00131 { same = (m_Size[i] == vec.m_Size[i]); }
00132
return !same;
00133 }
00134
00137
SizeValueType &
operator[](
unsigned int dim)
00138 {
return m_Size[dim]; }
00139
00143 SizeValueType
operator[](
unsigned int dim)
const
00144
{
return m_Size[dim]; }
00145
00148
const SizeValueType *
GetSize()
const {
return m_Size; };
00149
00153
void SetSize(
const SizeValueType val[VDimension])
00154 { memcpy(m_Size, val,
sizeof(SizeValueType)*VDimension); }
00155
00162
void SetElement(
unsigned long element, SizeValueType val )
00163 { m_Size[ element ] = val; }
00164
00171
SizeValueType GetElement(
unsigned long element )
const
00172
{
return m_Size[ element ]; }
00173
00176
void Fill(SizeValueType value)
00177 {
for(
unsigned int i=0;i < VDimension; ++i)
m_Size[i] = value; }
00178
00189
SizeValueType m_Size[VDimension];
00190
00191 };
00192
00193
00194
template<
unsigned int VDimension>
00195 std::ostream & operator<<(std::ostream &os, const Size<VDimension> &size)
00196 {
00197 os <<
"[";
00198
for (
unsigned int i=0; i+1 < VDimension; ++i)
00199 {
00200 os << size[i] <<
", ";
00201 }
00202
if (VDimension >= 1)
00203 {
00204 os << size[VDimension-1];
00205 }
00206 os <<
"]";
00207
return os;
00208 }
00209
00210 }
00211
00212
#endif