Create a Line Spatial Object

Synopsis

Specify a piecewise-linear object by specifying points along the line.

Results

line.png

line.png

Code

C++

#include "itkSpatialObjectToImageFilter.h"
#include "itkLineSpatialObject.h"
#include "itkLineSpatialObjectPoint.h"
#include "itkImageFileWriter.h"

int
main(int itkNotUsed(argc), char * itkNotUsed(argv)[])
{
  using PixelType = unsigned char;
  constexpr unsigned int Dimension = 2;

  using ImageType = itk::Image<PixelType, Dimension>;

  using LineType = itk::LineSpatialObject<Dimension>;

  using SpatialObjectToImageFilterType = itk::SpatialObjectToImageFilter<LineType, ImageType>;


  // Create a list of points
  std::vector<LineType::LinePointType> points;
  for (unsigned int i = 0; i < 20; i++)
  {
    LineType::LinePointType point;
    point.SetPositionInObjectSpace(10, i);

    LineType::LinePointType::CovariantVectorType normal;
    normal[0] = 0;
    normal[1] = 1;
    point.SetNormalInObjectSpace(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();

  using WriterType = itk::ImageFileWriter<ImageType>;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("line.png");
  writer->SetInput(imageFilter->GetOutput());
  writer->Update();

  return EXIT_SUCCESS;
}

Classes demonstrated

template<unsigned int TDimension = 3>
class LineSpatialObject : public itk::PointBasedSpatialObject<TDimension, LineSpatialObjectPoint<TDimension>>

Representation of a Line based on the spatial object classes.

The Line is basically defined by a set of points.

See

LineSpatialObjectPoint

ITK Sphinx Examples:

See itk::LineSpatialObject for additional documentation.
template<unsigned int TPointDimension = 3>
class LineSpatialObjectPoint : public itk::SpatialObjectPoint<TPointDimension>

Point used for a line definition.

This class contains all the functions necessary to define a point that can be used to build lines. This Class derives from SpatialObjectPoint. A LineSpatialObjectPoint has NDimension-1 normals.

ITK Sphinx Examples:

See itk::LineSpatialObjectPoint for additional documentation.