Bresenham Line#
Synopsis#
Get the points on a Bresenham line between two points.
Results#
Output:
[0, 0]
[1, 1]
[2, 2]
[3, 3]
[0, 0]
[1, 1]
[2, 2]
[3, 3]
[4, 4]
[5, 5]
[6, 6]
Code#
C++#
#include "itkBresenhamLine.h"
#include "itkVector.h"
#include "itkOffset.h"
#include "itkPoint.h"
#include <iostream>
static void
Vector();
static void
Line();
int
main(int itkNotUsed(argc), char * itkNotUsed(argv)[])
{
Vector();
Line();
return EXIT_SUCCESS;
}
void
Vector()
{
itk::BresenhamLine<2> line;
itk::Vector<float, 2> v;
v[0] = 1;
v[1] = 1;
std::vector<itk::Offset<2>> offsets = line.BuildLine(v, 4);
for (auto offset : offsets)
{
std::cout << offset << std::endl;
}
}
void
Line()
{
itk::BresenhamLine<2> line;
itk::Index<2> pixel0;
pixel0[0] = 0;
pixel0[1] = 0;
itk::Index<2> pixel1;
pixel1[0] = 5;
pixel1[1] = 5;
std::vector<itk::Index<2>> pixels = line.BuildLine(pixel0, pixel1);
for (auto pixel : pixels)
{
std::cout << pixel << std::endl;
}
}
Classes demonstrated#
-
template<unsigned int VDimension>
class BresenhamLine