ITK/Examples/SimpleOperations/BresenhamLine: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Created page with "==BresenhamLine.cxx== <source lang="cpp"> #include "itkBresenhamLine.h" #include "itkVector.h" #include "itkOffset.h" #include "itkPoint.h" #include <iostream> int main(int arg...")
 
No edit summary
Line 7: Line 7:


#include <iostream>
#include <iostream>
void Vector();
void Line();


int main(int argc, char *argv[])
int main(int argc, char *argv[])
{
{
   // Get the points on a Bresenham line between (2,2) and (5,5)
   Vector();
  itk::Point<float,2> p0;
   Line();
  p0[0] = 2;
  p0[1] = 2;
    
  itk::Point<float,2> p1;
  p1[0] = 5;
  p1[1] = 5;
 
  float dist = p0.EuclideanDistanceTo(p1);
    
    
  return EXIT_SUCCESS;
}
void Vector()
{
   itk::BresenhamLine<2> line;
   itk::BresenhamLine<2> line;


Line 26: Line 27:
   v[0] = 1;
   v[0] = 1;
   v[1] = 1;
   v[1] = 1;
   std::vector< itk::Offset<2> > offsets = line.BuildLine(v, dist);
   std::vector< itk::Offset<2> > offsets = line.BuildLine(v, 4);


   itk::Index<2> p0index;
  for(unsigned int i = 0; i < offsets.size(); i++)
   p0index[0] = p0[0];
    {
   p0index[1] = p0[1];
    std::cout << offsets[i] << std::endl;
    }
 
}
 
void Line()
{
 
  itk::BresenhamLine<2> line;
   itk::Index<2> pixel0;
   pixel0[0] = 0;
   pixel0[1] = 0;
    
    
   for(unsigned int i = 0; i < offsets.size(); i++)
  itk::Index<2> pixel1;
  pixel1[0] = 5;
  pixel1[1] = 5;
 
  std::vector< itk::Index<2> > pixels = line.BuildLine(pixel0, pixel1);
 
   for(unsigned int i = 0; i < pixels.size(); i++)
     {
     {
     std::cout << p0index + offsets[i] << std::endl;
     std::cout << pixels[i] << std::endl;
     }
     }


  return EXIT_SUCCESS;
}
}
</source>
</source>

Revision as of 18:00, 6 February 2011

BresenhamLine.cxx

<source lang="cpp">

  1. include "itkBresenhamLine.h"
  2. include "itkVector.h"
  3. include "itkOffset.h"
  4. include "itkPoint.h"
  1. include <iostream>

void Vector(); void Line();

int main(int argc, char *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(unsigned int i = 0; i < offsets.size(); i++)
   {
   std::cout << offsets[i] << 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(unsigned int i = 0; i < pixels.size(); i++)
   {
   std::cout << pixels[i] << std::endl;
   }

} </source>

CMakeLists.txt

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

PROJECT(BresenhamLine)

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

ADD_EXECUTABLE(BresenhamLine BresenhamLine.cxx) TARGET_LINK_LIBRARIES(BresenhamLine ITKIO)

</source>