ITK/Examples/SpatialObjects/LineSpatialObject: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
No edit summary
(Deprecated content that is moved to sphinx)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
==LineSpatialObject.cxx==
{{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/*  pages likely require ITK version 4.13 or earlier releases.   In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.}}
<source lang="cpp">
#include "itkSpatialObjectToImageFilter.h"
#include "itkLineSpatialObject.h"
#include "itkLineSpatialObjectPoint.h"
#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->SetInsideValue(255); // white
   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>
 
 
{{ITKCMakeLists|LineSpatialObject}}

Latest revision as of 14:14, 7 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.