|
|
(4 intermediate revisions by 2 users 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->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>
| |