Create a Size#

Synopsis#

Create a itk::Size, which represents the size of a region in an itk::Image.

Results#

Output:

[0, 0]
[1, 2]

Code#

Python#

#!/usr/bin/env python

import itk

Dimension = 2

size = itk.Size[Dimension]()

# Method 1
#
# Set both components (size[0] and size[1]) to the same value
# (in this case, 0).
size.Fill(0)
print(size)

# Method 2
#
# Set each component separately.
size[0] = 1
size[1] = 2
print(size)

C++#

#include <iostream>
#include "itkSize.h"

int
main()
{
  constexpr unsigned int Dimension = 2;
  itk::Size<Dimension>   size;

  // Method 1
  // set both components (size[0] and size[1]) to the same value
  // (in this case, 0).
  size.Fill(0);
  std::cout << size << std::endl;

  // Method 2
  // set each component separately.
  size[0] = 1;
  size[1] = 2;

  std::cout << size << std::endl;

  return EXIT_SUCCESS;
}

Classes demonstrated#

template<unsigned int VDimension = 2>
struct Size

Represent a n-dimensional size (bounds) of a n-dimensional image.

Size is a templated class to represent multi-dimensional array bounds, i.e. (I,J,K,…). Size is templated over teh dimension of the bounds. ITK assumes the first element of a size (bounds) is the fastest moving index.

For efficiency, Size does not define a default constructor, a copy constructor, or an operator=. We rely on the compiler to provide efficient bitwise copies.

Size is an “aggregate” class. Its data is public (m_InternalArray) allowing for fast and convenient instantiations/assignments.

The following syntax for assigning an aggregate type like this is allowed/suggested:

Size<3> var{{ 256, 256, 20 }}; // Also prevent narrowing conversions Size<3> var = {{ 256, 256, 20 }};

The doubled braces {{ and }} are required to prevent gcc -Wall (and perhaps other compilers) from complaining about a partly bracketed initializer.

As an aggregate type that is intended to provide highest performance characteristics, this class is not appropriate to inherit from, so setting this struct as final.

See

Index

ITK Sphinx Examples:

See itk::Size for additional documentation.