ITK  5.4.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
*
* 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.
*
*=========================================================================*/
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>;
auto criterion = CriterionType::New();
criterion->SetThreshold(100.);
auto 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
auto speedImage = FloatImageType::New();
region.SetSize(size);
speedImage->SetLargestPossibleRegion(region);
speedImage->SetBufferedRegion(region);
speedImage->Allocate();
speedImage->FillBuffer(1.0);
// setup a 'alive image'
auto 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'
auto 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);
auto 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());
try
{
itk::WriteImage(marcher->GetOutput(), argv[1]);
}
catch (const 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:274
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::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:88
New
static Pointer New()
itk::ImageRegion::SetSize
void SetSize(const SizeType &size)
Definition: itkImageRegion.h:202
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