ITK  5.2.0
Insight Toolkit
SphinxExamples/src/Core/SpatialObjects/ContourSpatialObject/Code.cxx
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifdef ENABLE_QUICKVIEW
# include "QuickView.h"
#endif
int
main(int /*argc*/, char * /*argv*/[])
{
using PixelType = unsigned char;
constexpr unsigned int Dimension = 2;
using SpatialObjectToImageFilterType = itk::SpatialObjectToImageFilter<ContourType, ImageType>;
// Create a list of points
ContourType::ControlPointListType points;
// Add some points
ContourType::ControlPointType point;
point.SetPositionInObjectSpace(0, 0);
points.push_back(point);
point.SetPositionInObjectSpace(0, 30);
points.push_back(point);
point.SetPositionInObjectSpace(30, 30);
points.push_back(point);
point.SetPositionInObjectSpace(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();
size.Fill(50);
imageFilter->SetInsideValue(255); // white
imageFilter->SetSize(size);
imageFilter->SetInput(contour);
imageFilter->Update();
using WriterType = itk::ImageFileWriter<ImageType>;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("contour.png");
writer->SetInput(imageFilter->GetOutput());
writer->Update();
#ifdef ENABLE_QUICKVIEW
QuickView viewer;
viewer.AddImage(imageFilter->GetOutput());
viewer.Visualize();
#endif
return EXIT_SUCCESS;
}
itk::ContourSpatialObject
Representation of a Contour based on the spatial object classes.
Definition: itkContourSpatialObject.h:69
itk::Size< 2 >
itk::SpatialObjectToImageFilter
Base class for filters that take a SpatialObject as input and produce an image as output....
Definition: itkSpatialObjectToImageFilter.h:41
itk::Size::Fill
void Fill(SizeValueType value)
Definition: itkSize.h:211
itkContourSpatialObjectPoint.h
QuickView.h
QuickView::AddImage
void AddImage(TImage *, bool FlipVertical=true, std::string Description="")
itk::ImageFileWriter
Writes image data to a single file.
Definition: itkImageFileWriter.h:88
itkSpatialObjectToImageFilter.h
itkImageFileWriter.h
itkContourSpatialObject.h
QuickView
A convenient class to render itk images with vtk.
Definition: QuickView.h:111
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
QuickView::Visualize
void Visualize(bool interact=true)
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44