ITK/Examples/SimpleOperations/DistanceBetweenIndices

From KitwarePublic
< ITK‎ | Examples
Revision as of 05:06, 17 February 2011 by 184.153.14.165 (talk) (Compilation error)
Jump to navigationJump to search

Compute the distance between two indices.

DistanceBetweenIndices.cxx

<source lang="cpp">

  1. include "itkPoint.h"
  2. include "itkIndex.h"
  1. include <iostream>
  2. include <string>

int main(int, char *[]) {

 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;
 return EXIT_SUCCESS;

}


</source>

CMakeLists.txt

<source lang="cmake"> cmake_minimum_required(VERSION 2.6)

PROJECT(DistanceBetweenIndices)

FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})

ADD_EXECUTABLE(DistanceBetweenIndices DistanceBetweenIndices.cxx) TARGET_LINK_LIBRARIES(DistanceBetweenIndices ITKNumerics)

</source>