Distance Between Indices#

Synopsis#

Compute the distance between two Indices.

Results#

Output:

Distance: 2.82843

Code#

C++#

#include "itkPoint.h"
#include "itkIndex.h"
#include "itkMath.h"

#include <iostream>

int
main()
{
  itk::Index<2> pixel1;
  pixel1.Fill(2);

  itk::Index<2> pixel2;
  pixel2.Fill(4);

  itk::Point<double, 2> p1;
  p1[0] = pixel1[0];
  p1[1] = pixel1[1];

  itk::Point<double, 2> p2;
  p2[0] = pixel2[0];
  p2[1] = pixel2[1];

  double distance = p2.EuclideanDistanceTo(p1);
  std::cout << "Distance: " << distance << std::endl;
}

Classes demonstrated#

template<typename TCoordRep, unsigned int NPointDimension = 3>
class Point : public itk::FixedArray<TCoordRep, NPointDimension>

A templated class holding a geometric point in n-Dimensional space.

Point is a templated class that holds a set of coordinates (components). Point can be used as the data type held at each pixel in an Image or at each vertex of an Mesh. The template parameter T can be any data type that behaves like a primitive (or atomic) data type (int, short, float, complex). The NPointDimension defines the number of components in the point array.

See

Image

See

Mesh

See

Vector

See

CovariantVector

See

Matrix

ITK Sphinx Examples:

See itk::Point for additional documentation.
template<unsigned int VDimension = 2>
struct Index

Represent a n-dimensional index in a n-dimensional image.

Index is a templated class to represent a multi-dimensional index, i.e. (i,j,k,…). Index is templated over the dimension of the index. ITK assumes the first element of an index is the fastest moving index.

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

Index 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:

Index<3> var{{ 256, 256, 20 }}; // Also prevent narrowing conversions Index<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.

ITK Sphinx Examples:

See itk::Index for additional documentation.