ITK  5.4.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
*
* https://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
auto contour = ContourType::New();
contour->SetControlPoints(points);
size.Fill(50);
imageFilter->SetInsideValue(255); // white
imageFilter->SetSize(size);
imageFilter->SetInput(contour);
imageFilter->Update();
itk::WriteImage(imageFilter->GetOutput(), "contour.png");
#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:213
itkContourSpatialObjectPoint.h
QuickView.h
QuickView::AddImage
void AddImage(TImage *, bool FlipVertical=true, std::string Description="")
itk::point
*par Constraints *The filter requires an image with at least two dimensions and a vector *length of at least The theory supports extension to scalar but *the implementation of the itk vector classes do not **The template parameter TRealType must be floating point(float or double) or *a user-defined "real" numerical type with arithmetic operations defined *sufficient to compute derivatives. **\par Performance *This filter will automatically multithread if run with *SetUsePrincipleComponents
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:88
New
static Pointer New()
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itk::WriteImage
ITK_TEMPLATE_EXPORT void WriteImage(TImagePointer &&image, const std::string &filename, bool compress=false)
Definition: itkImageFileWriter.h:254