Skip to content

Commit

Permalink
ENH: improvements suggested by @jhlegarreta:
Browse files Browse the repository at this point in the history
  • Loading branch information
romangrothausmann committed Jan 23, 2019
1 parent 1b922ae commit 9b63a48
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 93 deletions.
84 changes: 12 additions & 72 deletions Modules/Filtering/ImageGrid/test/itkResampleImageTest2s.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,15 @@ int itkResampleImageTest2s(int argc, char * argv [] )
// Run the resampling filter with the normal, linear, affine transform.
// This will use ResampleImageFilter::LinearThreadedGenerateData().
std::cout << "Test with normal AffineTransform." << std::endl;
try
{
writer1->SetNumberOfStreamDivisions(8); //split into 8 pieces for streaming.
writer1->Update();
}
catch( itk::ExceptionObject & excp )
{
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
writer1->SetNumberOfStreamDivisions(8); //split into 8 pieces for streaming.
TRY_EXPECT_NO_EXCEPTION( writer1->Update() );

// this verifies that the pipeline was executed as expected along
// with correct region propagation and output information
if (!monitor->VerifyAllInputCanStream(8))
{
std::cout << "Streaming failed to execute as expected!" << std::endl;
std::cout << monitor;
std::cerr << "Streaming failed to execute as expected!" << std::endl;
std::cerr << monitor;
return EXIT_FAILURE;
}

Expand All @@ -189,79 +181,27 @@ int itkResampleImageTest2s(int argc, char * argv [] )
nonlinearAffineTransform->Scale(2.0);
resample->SetTransform( nonlinearAffineTransform );
writer2->SetInput( resample->GetOutput() );
try
{
writer2->SetNumberOfStreamDivisions(8); //demand splitting into 8 pieces for streaming, but faked non-linearity will disable streaming
writer2->Update();
}
catch( itk::ExceptionObject & excp )
{
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
writer2->SetNumberOfStreamDivisions(8); //demand splitting into 8 pieces for streaming, but faked non-linearity will disable streaming
TRY_EXPECT_NO_EXCEPTION( writer2->Update() );

// Instead of using the default pixel when sampling outside the input image,
// we use a nearest neighbor extrapolator.
resample->SetTransform( affineTransform );
resample->SetExtrapolator( extrapolator );
writer3->SetInput( resample->GetOutput() );
std::cout << "Test with nearest neighbor extrapolator, affine transform." << std::endl;
try
{
writer3->SetNumberOfStreamDivisions(8); //split into 8 pieces for streaming.
writer3->Update();
}
catch( itk::ExceptionObject & excp )
{
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
writer3->SetNumberOfStreamDivisions(8); //split into 8 pieces for streaming.
TRY_EXPECT_NO_EXCEPTION( writer3->Update() );

// Instead of using the default pixel when sampling outside the input image,
// we use a nearest neighbor extrapolator.
resample->SetTransform( nonlinearAffineTransform );
writer4->SetInput( resample->GetOutput() );
std::cout << "Test with nearest neighbor extrapolator, nonlinear transform." << std::endl;
try
{
writer4->SetNumberOfStreamDivisions(8); //demand splitting into 8 pieces for streaming, but faked non-linearity will disable streaming
writer4->Update();
}
catch( itk::ExceptionObject & excp )
{
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}

// Check UseReferenceImage methods
resample->UseReferenceImageOff();
if( resample->GetUseReferenceImage() )
{
std::cerr << "GetUseReferenceImage() or UseReferenceImageOff() failed ! ";
std::cerr << std::endl;
return EXIT_FAILURE;
}

// Check UseReferenceImage methods
resample->UseReferenceImageOn();
if( !resample->GetUseReferenceImage() )
{
std::cerr << "GetUseReferenceImage() or UseReferenceImageOn() failed ! ";
std::cerr << std::endl;
return EXIT_FAILURE;
}

// Check UseReferenceImage methods
resample->SetUseReferenceImage( false );
if( resample->GetUseReferenceImage() )
{
std::cerr << "GetUseReferenceImage() or SetUseReferenceImage() failed ! ";
std::cerr << std::endl;
return EXIT_FAILURE;
}

writer4->SetNumberOfStreamDivisions(8); //demand splitting into 8 pieces for streaming, but faked non-linearity will disable streaming
TRY_EXPECT_NO_EXCEPTION( writer4->Update() );

std::cout << "Test passed." << std::endl;
return EXIT_SUCCESS;
std::cout << "Test passed." << std::endl;
return EXIT_SUCCESS;

}
32 changes: 11 additions & 21 deletions Modules/Filtering/ImageGrid/test/itkResampleImageTest7.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,8 @@ int itkResampleImageTest7(int argc, char * argv [] )

// Run the resampling filter without streaming, i.e. 1 StreamDivisions
numStreamDiv= 1; // do not split, i.e. do not stream
try
{
streamer->SetNumberOfStreamDivisions(numStreamDiv);
streamer->Update();
}
catch( itk::ExceptionObject & excp )
{
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
streamer->SetNumberOfStreamDivisions(numStreamDiv);
TRY_EXPECT_NO_EXCEPTION( streamer->Update() );

if (!monitor->VerifyAllInputCanStream(numStreamDiv))
{
Expand All @@ -148,16 +140,8 @@ int itkResampleImageTest7(int argc, char * argv [] )
// Run the resampling filter with streaming
numStreamDiv= 8; // split into numStream pieces for streaming.
resample->Modified(); // enforce re-execution even though nothing of filter changed
try
{
streamer->SetNumberOfStreamDivisions(numStreamDiv);
streamer->Update();
}
catch( itk::ExceptionObject & excp )
{
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
streamer->SetNumberOfStreamDivisions(numStreamDiv);
TRY_EXPECT_NO_EXCEPTION( streamer->Update() );

if (!monitor->VerifyAllInputCanStream(numStreamDiv))
{
Expand All @@ -181,12 +165,18 @@ int itkResampleImageTest7(int argc, char * argv [] )
std::cout << "Pixels differ "
<< itNoSDI.Value() << " "
<< itSDI.Value() << std::endl;
std::cerr << "Test failed!" << std::endl;
std::cerr << "Error in pixel value at index [" << itNoSDI.GetIndex() << "]" << std::endl;
std::cerr << "Expected difference " << itNoSDI.Get() - itSDI.Get() << std::endl;
std::cerr << " differs from 0 ";
return EXIT_FAILURE;
}
}
if(itNoSDI.IsAtEnd() != itSDI.IsAtEnd())
{
std::cout << "Iterators don't agree on end of image" << std::endl;
std::cerr << "Test failed!" << std::endl;
std::cerr << "Iterators don't agree on end of image" << std::endl;
std::cerr << "at index [" << itNoSDI.GetIndex() << "]" << std::endl;
return EXIT_FAILURE;
}

Expand Down

0 comments on commit 9b63a48

Please sign in to comment.