ITK/Examples/SpatialObjects/LineSpatialObject

From KitwarePublic
< ITK‎ | Examples
Revision as of 20:43, 24 January 2011 by Daviddoria (talk | contribs) (Created page with "==LineSpatialObject.cxx== <source lang="cpp"> #include "itkSpatialObjectToImageFilter.h" #include "itkLineSpatialObject.h" #include "itkLineSpatialObjectPoint.h" #include "itkIma...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

LineSpatialObject.cxx

<source lang="cpp">

  1. include "itkSpatialObjectToImageFilter.h"
  2. include "itkLineSpatialObject.h"
  3. include "itkLineSpatialObjectPoint.h"
  4. include "itkImageFileWriter.h"

int main( int argc, char *argv[] ) {

 typedef unsigned char PixelType;
 const unsigned int Dimension = 2;
 typedef itk::Image< PixelType, Dimension >    ImageType;
 typedef itk::LineSpatialObject< Dimension >   LineType;
 typedef itk::SpatialObjectToImageFilter<
   LineType, ImageType >   SpatialObjectToImageFilterType;


 // Create a list of points
 std::vector<LineType::LinePointType> points;
 for(unsigned int i = 0; i < 20; i++)
   {
   LineType::LinePointType point;
   point.SetPosition(10,i);
   LineType::LinePointType::VectorType normal;
   normal[0] = 0;
   normal[1] = 1;
   point.SetNormal(normal,0);
   points.push_back(point);
   }
 // Create a line from the list of points
 LineType::Pointer line = LineType::New();
 line->SetPoints(points);
 SpatialObjectToImageFilterType::Pointer imageFilter =
   SpatialObjectToImageFilterType::New();
 itk::Size<2> size;
 size.Fill(50);
 imageFilter->SetSize(size);
 imageFilter->SetInput(line);
 imageFilter->Update();
 
 typedef itk::ImageFileWriter< ImageType >     WriterType;
 WriterType::Pointer writer = WriterType::New();
 writer->SetFileName("line.png");
 writer->SetInput( imageFilter->GetOutput() );
 writer->Update();
 return EXIT_SUCCESS;

}

</source>

CMakeLists.txt

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

PROJECT(LineSpatialObject)

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

ADD_EXECUTABLE(LineSpatialObject LineSpatialObject.cxx) TARGET_LINK_LIBRARIES(LineSpatialObject ITKIO)

</source>