4 #include <initializer_list>
11 template<
typename PixelType,
unsigned int Ndim>
20 for (
unsigned int i = 0; i < Ndim; i++)
22 data_[i] =
static_cast<PixelType
>(0.0);
39 if (list.size() != Ndim)
41 std::stringstream msg;
42 msg <<
"Length of initializer list (" << list.size();
43 msg <<
") does not match number of size dimensions (" << Ndim <<
").";
44 throw IuException(msg.str(), __FILE__, __FUNCTION__, __LINE__);
48 for (
auto elem : list)
79 void fill(
const PixelType& value)
81 for (
unsigned int i = 0; i < Ndim; i++)
88 template<
typename T = std::ostream>
89 friend typename std::enable_if<(Ndim == 1), T&>::type
operator<<(
92 out <<
"[" << v[0] <<
"]";
97 template<
typename T = std::ostream>
98 friend typename std::enable_if<(Ndim > 1), T&>::type
operator<<(
102 for (
int i = 0; i < static_cast<int>(Ndim - 1); i++)
106 out << v[Ndim - 1] <<
"]";
123 template<
typename PixelType,
unsigned int Ndim>
127 for (
unsigned int i = 0; i < Ndim; i++)
136 template<
typename PixelType,
unsigned int Ndim>
140 for (
unsigned int i = 0; i < Ndim; i++)
153 template<
typename PixelType,
unsigned int Ndim>
174 Vector(std::initializer_list<PixelType> list) :
189 for (
unsigned int i = 0; i < Ndim; i++)
191 v[i] = this->
data_[i] + scalar;
200 for (
unsigned int i = 0; i < Ndim; i++)
202 v2[i] = this->
data_[i] + v1[i];
211 for (
unsigned int i = 0; i < Ndim; i++)
213 v[i] = this->
data_[i] - scalar;
222 for (
unsigned int i = 0; i < Ndim; i++)
224 v2[i] = this->
data_[i] - v1[i];
233 for (
unsigned int i = 0; i < Ndim; i++)
235 v[i] = this->
data_[i] * scalar;
244 for (
unsigned int i = 0; i < Ndim; i++)
246 v2[i] = this->
data_[i] * v1[i];
254 for (
unsigned int i = 0; i < Ndim; i++)
256 this->
data_[i] += scalar;
263 for (
unsigned int i = 0; i < Ndim; i++)
265 this->
data_[i] += v2[i];
272 for (
unsigned int i = 0; i < Ndim; i++)
274 this->
data_[i] -= scalar;
281 for (
unsigned int i = 0; i < Ndim; i++)
283 this->
data_[i] -= v2[i];
290 for (
unsigned int i = 0; i < Ndim; i++)
292 this->
data_[i] *= scalar;
299 for (
unsigned int i = 0; i < Ndim; i++)
301 this->
data_[i] *= v2[i];
308 IU_ASSERT(scalar != 0);
309 PixelType invFactor = 1 / scalar;
316 for (
unsigned int i = 0; i < Ndim; i++)
317 this->
data_[i] = from[i];
323 for (
unsigned int i = 0; i < Ndim; i++)
324 this->
data_[i] = from[i];
331 template<
unsigned int Ndim>
353 SizeBase(std::initializer_list<unsigned int> list) :
366 unsigned int num_elements = this->
data_[0];
367 for (
unsigned int i = 1; i < Ndim; i++)
369 if (this->
data_[i] == 0)
371 std::stringstream msg;
372 msg <<
"Zero size elements are not allowed. (" << *
this <<
")";
373 throw IuException(msg.str(), __FILE__, __FUNCTION__, __LINE__);
376 num_elements *= this->
data_[i];
382 template<
typename ScalarType>
386 for (
unsigned int i = 0; i < Ndim; i++)
388 v[i] =
static_cast<unsigned int>(this->
data_[i] * scalar + 0.5f);
394 template<
typename ScalarType>
397 for (
unsigned int i = 0; i < Ndim; i++)
400 static_cast<unsigned int>(this->
data_[i] * scalar + 0.5f);
406 template<
typename ScalarType>
409 IU_ASSERT(scalar != 0);
410 double invFactor = 1.0 /
static_cast<double>(scalar);
415 template<
typename ScalarType>
418 IU_ASSERT(scalar != 0);
419 double invFactor = 1.0 /
static_cast<double>(scalar);
426 for (
unsigned int i = 0; i < Ndim; i++)
427 this->
data_[i] = from[i];
433 for (
unsigned int i = 0; i < Ndim; i++)
434 this->
data_[i] = from[i];
451 const unsigned int*
ptr()
const
453 return reinterpret_cast<const unsigned int*
>(this->
data_);
459 template<
unsigned int Ndim>
480 Size(std::initializer_list<unsigned int> list) :
550 Size(std::initializer_list<unsigned int> list) :
559 Size(
unsigned int width,
unsigned int height) :
618 depth(this->
data_[2])
627 depth(this->
data_[2])
634 Size(std::initializer_list<unsigned int> list) :
636 depth(this->
data_[2])
645 Size(
unsigned int width,
unsigned int height,
unsigned int depth) :
647 depth(this->
data_[2])
662 depth(this->
data_[2])
669 depth(this->
data_[2])
Size & operator=(const SizeBase< 2 > &from)
Definition: vector.h:591
unsigned int numel() const
Definition: vector.h:364
SizeBase(std::initializer_list< unsigned int > list)
Definition: vector.h:353
Size(const Size &from)
Definition: vector.h:660
const unsigned int * ptr() const
Definition: vector.h:451
Size(const SizeBase< Ndim > &from)
Definition: vector.h:497
unsigned int & depth
Definition: vector.h:613
virtual ~VectorBase()
Definition: vector.h:56
VectorBase()
Definition: vector.h:18
Size(std::initializer_list< unsigned int > list)
Definition: vector.h:634
VectorBase(std::initializer_list< PixelType > list)
Definition: vector.h:37
Base class for N-dimensional vectors.
Definition: vector.h:12
Size(unsigned int value)
Definition: vector.h:472
Size(unsigned int width, unsigned int height)
Definition: vector.h:559
void operator+=(const PixelType &scalar)
Definition: vector.h:252
~Vector()
Definition: vector.h:181
friend std::enable_if<(Ndim==1), T & >::type operator<<(std::ostream &out, VectorBase< PixelType, Ndim > const &v)
Definition: vector.h:89
Size(unsigned int width, unsigned int height, unsigned int depth)
Definition: vector.h:645
Vector< PixelType, Ndim > operator+(const PixelType &scalar) const
Definition: vector.h:186
SizeBase operator*(const ScalarType &scalar) const
Definition: vector.h:383
unsigned int & height
Definition: vector.h:531
PixelType data_[Ndim]
Definition: vector.h:112
unsigned int * ptr()
Definition: vector.h:442
Vector(std::initializer_list< PixelType > list)
Definition: vector.h:174
unsigned int & height
Definition: vector.h:611
SizeBase & operator=(const SizeBase &from)
Definition: vector.h:431
void operator-=(const Vector< PixelType, Ndim > &v2)
Definition: vector.h:279
Size & operator=(const Size &from)
Definition: vector.h:503
~Size()
Definition: vector.h:486
bool operator!=(const VectorBase< PixelType, Ndim > &v1, const VectorBase< PixelType, Ndim > &v2)
Definition: vector.h:137
Vector(const Vector &from)
Definition: vector.h:314
Vector< PixelType, Ndim > operator-(const PixelType &scalar) const
Definition: vector.h:208
Exceptions with additional error information.
Definition: coredefs.h:32
VectorBase(const PixelType &value)
Definition: vector.h:29
SizeBase operator/(const ScalarType &scalar) const
Definition: vector.h:407
void operator*=(const ScalarType &scalar)
Definition: vector.h:395
unsigned int & width
Definition: vector.h:529
Main Class for N-dimensional vectors.
Definition: vector.h:154
Size & operator=(const SizeBase< 3 > &from)
Definition: vector.h:681
Vector(const PixelType &value)
Definition: vector.h:166
Size(unsigned int value)
Definition: vector.h:542
static unsigned int ndim()
Definition: vector.h:73
void fill(const PixelType &value)
Definition: vector.h:79
Size(const Size &from)
Definition: vector.h:572
Size(const SizeBase &from)
Definition: vector.h:667
Size(std::initializer_list< unsigned int > list)
Definition: vector.h:550
Vector< PixelType, Ndim > operator-(Vector< PixelType, Ndim > &v1) const
Definition: vector.h:219
void operator-=(const PixelType &scalar)
Definition: vector.h:270
Vector & operator=(const Vector &from)
Definition: vector.h:321
Vector< PixelType, Ndim > operator*(const PixelType &scalar) const
Definition: vector.h:230
bool operator==(const VectorBase< PixelType, Ndim > &v1, const VectorBase< PixelType, Ndim > &v2)
Definition: vector.h:124
Vector operator/(const PixelType scalar) const
Definition: vector.h:306
void operator*=(const PixelType &scalar)
Definition: vector.h:288
Size(unsigned int value)
Definition: vector.h:625
SizeBase(const SizeBase &from)
Definition: vector.h:424
Size & operator=(const Size &from)
Definition: vector.h:584
PixelType operator[](unsigned int i) const
Definition: vector.h:61
Size(std::initializer_list< unsigned int > list)
Definition: vector.h:480
Base class for N-dimensional unsigned int vectors (size vectors).
Definition: vector.h:332
Size()
Definition: vector.h:464
unsigned int & width
Definition: vector.h:609
Size & operator=(const SizeBase< Ndim > &from)
Definition: vector.h:510
SizeBase(unsigned int value)
Definition: vector.h:345
void operator*=(const Vector< PixelType, Ndim > &v2)
Definition: vector.h:297
Size(const SizeBase &from)
Definition: vector.h:578
void operator+=(const Vector< PixelType, Ndim > &v2)
Definition: vector.h:261
~Size()
Definition: vector.h:567
Size()
Definition: vector.h:616
void operator/=(const ScalarType &scalar)
Definition: vector.h:416
Size()
Definition: vector.h:534
Size & operator=(const Size &from)
Definition: vector.h:674
virtual ~SizeBase()
Definition: vector.h:359
~Size()
Definition: vector.h:655
Main class for N-dimensional unsigned int vectors (size vectors).
Definition: vector.h:460
PixelType & operator[](unsigned int i)
Definition: vector.h:67
Size(const Size &from)
Definition: vector.h:491
Vector()
Definition: vector.h:158
Vector< PixelType, Ndim > operator*(Vector< PixelType, Ndim > &v1) const
Definition: vector.h:241
Vector< PixelType, Ndim > operator+(Vector< PixelType, Ndim > &v1) const
Definition: vector.h:197