ITK/Examples/WishList/SpatialObjects/ContourSpatialObject

From KitwarePublic
< ITK‎ | Examples
Revision as of 14:38, 25 January 2011 by Daviddoria (talk | contribs) (Created page with "Output image is empty? ==ContourSpatialObject.cxx== <source lang="cpp"> #include "itkSpatialObjectToImageFilter.h" #include "itkContourSpatialObject.h" #include "itkContourSpati...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Output image is empty?

ContourSpatialObject.cxx

<source lang="cpp">

  1. include "itkSpatialObjectToImageFilter.h"
  2. include "itkContourSpatialObject.h"
  3. include "itkContourSpatialObjectPoint.h"
  4. include "itkImageFileWriter.h"
  1. 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>