ITK/Examples/WishList/SpatialObjects/ContourSpatialObject: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Created page with "Output image is empty? ==ContourSpatialObject.cxx== <source lang="cpp"> #include "itkSpatialObjectToImageFilter.h" #include "itkContourSpatialObject.h" #include "itkContourSpati...")
 
(Deprcated)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
Output image is empty?
{{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.}}
 
==ContourSpatialObject.cxx==
<source lang="cpp">
#include "itkSpatialObjectToImageFilter.h"
#include "itkContourSpatialObject.h"
#include "itkContourSpatialObjectPoint.h"
#include "itkImageFileWriter.h"
 
#include "QuickView.h"
 
int main( int argc, char *argv[] )
{
  typedef unsigned char PixelType;
  const unsigned int Dimension = 2;
 
  typedef itk::Image< PixelType, Dimension >    ImageType;
 
  typedef itk::ContourSpatialObject< Dimension >  ContourType;
 
  typedef itk::SpatialObjectToImageFilter<
    ContourType, ImageType >  SpatialObjectToImageFilterType;
 
 
  // Create a list of points
  ContourType::ControlPointListType points;
 
  // Add some points
  ContourType::ControlPointType point;
  point.SetPosition(0,0);
  points.push_back(point);
  point.SetPosition(0,30);
  points.push_back(point);
  point.SetPosition(30,30);
  points.push_back(point);
  point.SetPosition(0,0);
  points.push_back(point);
 
  // Create a contour from the list of points
  ContourType::Pointer contour = ContourType::New();
  contour->SetControlPoints(points);
 
  SpatialObjectToImageFilterType::Pointer imageFilter =
    SpatialObjectToImageFilterType::New();
  itk::Size<2> size;
  size.Fill(50);
  imageFilter->SetInsideValue(255); // white
  imageFilter->SetSize(size);
  imageFilter->SetInput(contour);
  imageFilter->Update();
 
  QuickView viewer;
  viewer.AddImage(imageFilter->GetOutput());
  viewer.Visualize();
  /*
  typedef itk::ImageFileWriter< ImageType >    WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("contour.png");
  writer->SetInput( imageFilter->GetOutput() );
  writer->Update();
  */
  return EXIT_SUCCESS;
}
 
</source>
 
==CMakeLists.txt==
<source lang="cmake">
cmake_minimum_required(VERSION 2.6)
 
include_directories(/home/doriad/ITKWikiExamples/ItkVtkGlue)
 
PROJECT(ContourSpatialObject)
 
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})
 
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
 
ADD_EXECUTABLE(ContourSpatialObject ContourSpatialObject.cxx
/home/doriad/ITKWikiExamples/ItkVtkGlue/QuickView.cxx)
TARGET_LINK_LIBRARIES(ContourSpatialObject
ITKIO ITKBasicFilters ITKCommon
vtkHybrid)
 
</source>

Latest revision as of 23: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.