ITK  5.2.0
Insight Toolkit
SphinxExamples/src/Filtering/FastMarching/CreateDistanceMapFromSeeds/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.
*
*=========================================================================*/
int
main(int argc, char * argv[])
{
if (argc != 2)
{
std::cerr << "Usage:" << std::endl;
std::cerr << argv[0] << " <OutputFileName>" << std::endl;
return EXIT_FAILURE;
}
// create a fastmarching object
using PixelType = float;
constexpr unsigned int Dimension = 2;
using FloatImageType = itk::Image<PixelType, Dimension>;
CriterionType::Pointer criterion = CriterionType::New();
criterion->SetThreshold(100.);
FastMarchingType::Pointer marcher = FastMarchingType::New();
marcher->SetStoppingCriterion(criterion);
// specify the size of the output image
FloatImageType::SizeType size = { { 64, 64 } };
marcher->SetOutputSize(size);
// setup a speed image of ones
FloatImageType::Pointer speedImage = FloatImageType::New();
region.SetSize(size);
speedImage->SetLargestPossibleRegion(region);
speedImage->SetBufferedRegion(region);
speedImage->Allocate();
speedImage->FillBuffer(1.0);
// setup a 'alive image'
FloatImageType::Pointer AliveImage = FloatImageType::New();
AliveImage->SetLargestPossibleRegion(region);
AliveImage->SetBufferedRegion(region);
AliveImage->Allocate();
AliveImage->FillBuffer(0.0);
FloatImageType::OffsetType offset0 = { { 28, 35 } };
index.Fill(0);
index += offset0;
AliveImage->SetPixel(index, 1.0);
// setup a 'trial image'
FloatImageType::Pointer TrialImage = FloatImageType::New();
TrialImage->SetLargestPossibleRegion(region);
TrialImage->SetBufferedRegion(region);
TrialImage->Allocate();
TrialImage->FillBuffer(0.0);
index[0] += 1;
TrialImage->SetPixel(index, 1.0);
index[0] -= 1;
index[1] += 1;
TrialImage->SetPixel(index, 1.0);
index[0] -= 1;
index[1] -= 1;
TrialImage->SetPixel(index, 1.0);
index[0] += 1;
index[1] -= 1;
TrialImage->SetPixel(index, 1.0);
marcher->SetInput(speedImage);
AdaptorType::Pointer adaptor = AdaptorType::New();
adaptor->SetAliveImage(AliveImage.GetPointer());
adaptor->SetAliveValue(0.0);
adaptor->SetTrialImage(TrialImage.GetPointer());
adaptor->SetTrialValue(1.0);
adaptor->Update();
marcher->SetAlivePoints(adaptor->GetAlivePoints());
marcher->SetTrialPoints(adaptor->GetTrialPoints());
WriterType::Pointer writer = WriterType::New();
writer->SetInput(marcher->GetOutput());
writer->SetFileName(argv[1]);
try
{
writer->Update();
}
catch (itk::ExceptionObject & error)
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
itk::FastMarchingImageToNodePairContainerAdaptor
Convenient adaptor class which converts Image into FastMarching::NodePairContainerType used for initi...
Definition: itkFastMarchingImageToNodePairContainerAdaptor.h:50
itkFastMarchingThresholdStoppingCriterion.h
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::Index::Fill
void Fill(IndexValueType value)
Definition: itkIndex.h:270
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::FastMarchingImageFilterBase
Apply the Fast Marching method to solve an Eikonal equation on an image.
Definition: itkFastMarchingImageFilterBase.h:75
itk::ImageFileWriter
Writes image data to a single file.
Definition: itkImageFileWriter.h:87
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::FastMarchingThresholdStoppingCriterion
Stopping Criterion is verified when Current Value is equal to or greater than the provided threshold.
Definition: itkFastMarchingThresholdStoppingCriterion.h:35
itkFastMarchingImageToNodePairContainerAdaptor.h
itkImageFileWriter.h
itkFastMarchingImageFilterBase.h
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
itk::ImageRegion::SetSize
void SetSize(const SizeType &size)
Definition: itkImageRegion.h:174
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44