Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Modules/Filtering/FastMarching/include/itkFastMarchingBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ class ITK_TEMPLATE_EXPORT FastMarchingBase : public FastMarchingTraits<TInput, T
using SuperclassType = typename Traits::SuperclassType;

using Self = FastMarchingBase;
using Superclass = SuperclassType;
using Superclass = typename FastMarchingTraits<TInput, TOutput>::SuperclassType;
using Pointer = SmartPointer< Self >;
using ConstPointer = SmartPointer< const Self >;

/** Run-time type information (and related methods). */
itkTypeMacro(FastMarchingBase, FastMarchingTraits);

/** Input Domain related definitions */
using InputDomainType = typename Traits::InputDomainType;
using InputDomainPointer = typename Traits::InputDomainPointer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ITK_TEMPLATE_EXPORT FastMarchingImageFilter:

/** Standard class typdedefs. */
using Self = FastMarchingImageFilter;
using Superclass = ImageSource< TLevelSet >;
using Superclass = ImageToImageFilter< TSpeedImage, TLevelSet >;
using Pointer = SmartPointer< Self >;
using ConstPointer = SmartPointer< const Self >;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int itkFastMarchingExtensionImageFilterTest(int, char* [] )
index[1] -= 1;
TrialPoints->push_back( NodePairType( index, 1. ) );

index.Fill( 300 ); // this node is out of ranage
index.Fill( 300 ); // this node is out of range
TrialPoints->push_back( NodePairType( index, 42. ) );

marcher->SetTrialPoints( TrialPoints );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,100 @@

#include "itkFastMarchingImageFilterBase.h"
#include "itkFastMarchingThresholdStoppingCriterion.h"
#include "itkTestingMacros.h"

/*
* This function ONLY tests basic getters/setters for the base class
* and does not exercise the base class filter. The process of testing
* the running of the filter is delegated to other tests.
* @tparam VDimension
* @return EXIT_SUCCESS if all test passs, EXIT_FAILURE otherwise
*/
template< unsigned int VDimension >
int FastMarchingImageFilterBase( )
{
static int FastMarchingImageFilterBaseTestFunction()
{
using PixelType = float;

using ImageType = itk::Image< PixelType, VDimension >;
typename ImageType::Pointer input = ImageType::New();

using FMMType =
using FastMarchingImageFilterType =
itk::FastMarchingImageFilterBase< ImageType, ImageType >;
typename FMMType::Pointer fmm = FMMType::New();
fmm->SetInput( input );
typename FastMarchingImageFilterType::Pointer fastMarchingFilter =
FastMarchingImageFilterType::New();

bool exception_caught = false;
bool overrideOutputInformation = true;
TEST_SET_GET_BOOLEAN( fastMarchingFilter, OverrideOutputInformation,
overrideOutputInformation );

try
{
fmm->Update();
}
catch( itk::ExceptionObject & excep )
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
exception_caught = true;
}
typename FastMarchingImageFilterType::OutputSizeType outputSize;
outputSize.Fill( 32 );
fastMarchingFilter->SetOutputSize( outputSize );
TEST_SET_GET_VALUE( outputSize, fastMarchingFilter->GetOutputSize() );

if( !exception_caught )
{
std::cout <<"Exception is not caught!" <<std::endl;
return EXIT_FAILURE;
}
typename FastMarchingImageFilterType::OutputRegionType outputRegion;
outputRegion.SetSize( outputSize );
fastMarchingFilter->SetOutputRegion( outputRegion );
TEST_SET_GET_VALUE( outputRegion, fastMarchingFilter->GetOutputRegion() );

typename FastMarchingImageFilterType::OutputSpacingType outputSpacing;
outputSpacing.Fill( 1.0 );
fastMarchingFilter->SetOutputSpacing( outputSpacing );
TEST_SET_GET_VALUE( outputSpacing, fastMarchingFilter->GetOutputSpacing() );

typename FastMarchingImageFilterType::OutputDirectionType outputDirection;
outputDirection.SetIdentity();
fastMarchingFilter->SetOutputDirection( outputDirection );
TEST_SET_GET_VALUE( outputDirection, fastMarchingFilter->GetOutputDirection() );

typename ImageType::Pointer output = fmm->GetOutput();
typename FastMarchingImageFilterType::OutputPointType outputOrigin;
outputOrigin.Fill( 0.0 );
fastMarchingFilter->SetOutputOrigin( outputOrigin );
TEST_SET_GET_VALUE( outputOrigin, fastMarchingFilter->GetOutputOrigin() );

// DO NOT ATTEMPT TO UPDATE the base class filter.
// the base class filter is not sufficiently configured
// with trial point, stopping criteria, normalization factors, or speed constants.
// or given a valid image.
//
// DO NOT ADD TRY_EXPECT_NO_EXCEPTION( fastMarchingFilter->Update() );
// DO NOT ADD typename ImageType::Pointer output = fastMarchingFilter->GetOutput();

return EXIT_SUCCESS;
}
}


// ----------------------------------------------------------------------------
int itkFastMarchingImageFilterBaseTest( int , char * [] )
{
if( FastMarchingImageFilterBase< 2 >() == EXIT_FAILURE )
{
// Exercise basic object methods
// Done outside the helper function in the test because GCC is limited
// when calling overloaded base class functions.
const unsigned int Dimension = 2;
typedef float PixelType;
typedef itk::Image< PixelType, Dimension > ImageType;

typedef itk::FastMarchingImageFilterBase< ImageType, ImageType >
FastMarchingImageFilterType;

FastMarchingImageFilterType::Pointer fastMarchingFilter =
FastMarchingImageFilterType::New();

EXERCISE_BASIC_OBJECT_METHODS( fastMarchingFilter,
FastMarchingImageFilterBase, FastMarchingBase );


if(FastMarchingImageFilterBaseTestFunction<2>() == EXIT_FAILURE )
{
std::cerr << "2D Fails" <<std::endl;
std::cerr << "Test failed!" << std::endl;
return EXIT_FAILURE;
}
if( FastMarchingImageFilterBase< 3 >() == EXIT_FAILURE )
if(FastMarchingImageFilterBaseTestFunction<3>() == EXIT_FAILURE )
{
std::cerr << "3D Fails" <<std::endl;
std::cerr << "Test failed!" << std::endl;
return EXIT_FAILURE;
}


std::cout << "Test finished." <<std::endl;
return EXIT_SUCCESS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "itkFastMarchingImageFilterBase.h"
#include "itkFastMarchingThresholdStoppingCriterion.h"
#include "itkTextOutput.h"
#include "itkTestingMacros.h"
#include "itkCommand.h"


Expand All @@ -29,22 +30,20 @@ namespace{
class ShowProgressObject
{
public:
ShowProgressObject(itk::ProcessObject* o)
{m_Process = o;}
ShowProgressObject( itk::ProcessObject* o )
{ m_Process = o; }
void ShowProgress()
{std::cout << "Progress " << m_Process->GetProgress() << std::endl;}
{ std::cout << "Progress " << m_Process->GetProgress() << std::endl; }
itk::ProcessObject::Pointer m_Process;
};
}

int itkFastMarchingImageFilterRealTest1(int argc, char* argv[] )
int itkFastMarchingImageFilterRealTest1( int itkNotUsed( argc ), char* itkNotUsed( argv )[] )
{
(void) argc;
(void) argv;

itk::OutputWindow::SetInstance(itk::TextOutput::New().GetPointer());
itk::OutputWindow::SetInstance( itk::TextOutput::New().GetPointer() );

// create a fastmarching object
// Create a Fast Marching image filter object
using PixelType = float;
constexpr unsigned Dimension = 2;

Expand All @@ -60,28 +59,32 @@ int itkFastMarchingImageFilterRealTest1(int argc, char* argv[] )
criterion->SetThreshold( 100. );

FastMarchingType::Pointer marcher = FastMarchingType::New();

EXERCISE_BASIC_OBJECT_METHODS( marcher, FastMarchingImageFilterBase,
FastMarchingBase );


marcher->SetStoppingCriterion( criterion );

ShowProgressObject progressWatch(marcher);
itk::SimpleMemberCommand<ShowProgressObject>::Pointer command;
command = itk::SimpleMemberCommand<ShowProgressObject>::New();
command->SetCallbackFunction(&progressWatch,
&ShowProgressObject::ShowProgress);
marcher->AddObserver( itk::ProgressEvent(), command);
ShowProgressObject progressWatch( marcher );
itk::SimpleMemberCommand<ShowProgressObject>::Pointer command =
itk::SimpleMemberCommand< ShowProgressObject >::New();
command->SetCallbackFunction( &progressWatch,
&ShowProgressObject::ShowProgress );
marcher->AddObserver( itk::ProgressEvent(), command );

using NodePairType = FastMarchingType::NodePairType;
// using NodeContainerType = FastMarchingType::NodeContainerType;
using NodePairContainerType = FastMarchingType::NodePairContainerType;

// setup alive points
// Set up alive points
NodePairContainerType::Pointer alive = NodePairContainerType::New();

NodePairType node_pair;

FloatImageType::OffsetType offset0 = {{28,35}};
FloatImageType::OffsetType offset0 = {{28, 35}};

itk::Index<2> index;
index.Fill(0);
itk::Index< Dimension > index;
index.Fill( 0 );

node_pair.SetValue( 0.0 );
node_pair.SetNode( index + offset0 );
Expand All @@ -95,11 +98,11 @@ int itkFastMarchingImageFilterRealTest1(int argc, char* argv[] )

marcher->SetAlivePoints( alive );

// setup trial points
// Set up trial points
NodePairContainerType::Pointer trial = NodePairContainerType::New();
node_pair.SetValue( 1.0 );

index.Fill(0);
index.Fill (0 );
index += offset0;

index[0] += 1;
Expand All @@ -122,17 +125,17 @@ int itkFastMarchingImageFilterRealTest1(int argc, char* argv[] )
trial->push_back( node_pair );

node_pair.SetValue( 42.0 );
index.Fill( 300 ); // this node is out of ranage
index.Fill( 300 ); // this node is out of range
node_pair.SetNode( index );
trial->push_back( node_pair );

marcher->SetTrialPoints( trial );

// specify the size of the output image
FloatImageType::SizeType size = {{64,64}};
// Specify the size of the output image
FloatImageType::SizeType size = {{64, 64}};
marcher->SetOutputSize( size );

// setup a speed image of ones
// Set up a speed image of ones
FloatImageType::Pointer speedImage = FloatImageType::New();
FloatImageType::RegionType region;
region.SetSize( size );
Expand All @@ -148,76 +151,63 @@ int itkFastMarchingImageFilterRealTest1(int argc, char* argv[] )
++speedIter;
}

speedImage->Print( std::cout );
marcher->SetInput( speedImage );

// turn on debugging
// Turn on debugging
marcher->DebugOn();

// update the marcher
marcher->Update();
// Update the Fast Marching filter
TRY_EXPECT_NO_EXCEPTION( marcher->Update() );

// check the results

// Check the results
FloatImageType::Pointer output = marcher->GetOutput();

itk::ImageRegionIterator<FloatImageType>
itk::ImageRegionIterator< FloatImageType >
iterator( output, output->GetBufferedRegion() );

bool passed = true;

double threshold = 1.42;
while ( !iterator.IsAtEnd() )
{
FloatImageType::IndexType tempIndex = iterator.GetIndex();
tempIndex -= offset0;

double distance = 0.0;
for ( int j = 0; j < 2; j++ )
for ( unsigned int j = 0; j < Dimension; j++ )
{
distance += tempIndex[j] * tempIndex[j];
}
distance = std::sqrt( distance );

auto outputValue = static_cast< double >( iterator.Get() );

//std::cout << iterator.GetIndex() <<" ** " <<outputValue <<std::endl;
if (distance > itk::NumericTraits< double >::epsilon() )
if ( distance > itk::NumericTraits< double >::epsilon() )
{
if ( itk::Math::abs( outputValue ) / distance > 1.42 )
if ( itk::Math::abs( outputValue ) / distance > threshold )
{
std::cout << iterator.GetIndex() << " ";
std::cout << itk::Math::abs( outputValue ) / distance << " ";
std::cout << itk::Math::abs( outputValue ) << " " << distance << std::endl;
std::cout << "Error at index [" << iterator.GetIndex() << "]"
<< std::endl;
std::cout << "Expected scaled output value be less than: " << threshold
<<", but got: " << itk::Math::abs( outputValue ) / distance
<< ", where output: " << itk::Math::abs( outputValue )
<< "; scale factor: " << distance << std::endl;
passed = false;
}
}
++iterator;
}

std::cout << "SpeedConstant: " << marcher->GetSpeedConstant() << std::endl;
std::cout << "StoppingValue: " << marcher->GetTargetReachedValue() << std::endl;
std::cout << "SpeedImage: " << marcher->GetInput() << std::endl;

// Exercise other member functions
/*
std::cout << "CollectPoints: " << marcher->GetCollectPoints() << std::endl;

marcher->SetNormalizationFactor( 2.0 );
std::cout << "NormalizationFactor: " << marcher->GetNormalizationFactor();
std::cout << std::endl;


std::cout << std::endl;

marcher->Print( std::cout );*/

if ( passed )
{
std::cout << "Fast Marching test passed" << std::endl;
std::cout << "Test passed!" << std::endl;
return EXIT_SUCCESS;
}
else
{
std::cout << "Fast Marching test failed" << std::endl;
std::cout << "Test failed!" << std::endl;
return EXIT_FAILURE;
}

Expand Down
Loading