Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STYLE: Improve style in miscellaneous tests #4203

8 changes: 1 addition & 7 deletions Modules/Core/Common/test/itkBSplineKernelFunctionTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
#include "itkTestingMacros.h"


/*
* This test exercises the BSpline kernel function
* of various orders.
*/
int
itkBSplineKernelFunctionTest(int, char *[])
{
Expand Down Expand Up @@ -190,7 +186,6 @@ itkBSplineKernelFunctionTest(int, char *[])

// Testing case of unimplemented spline order
{

using FunctionType = itk::BSplineKernelFunction<7>;
auto function = FunctionType::New();

Expand All @@ -199,14 +194,13 @@ itkBSplineKernelFunctionTest(int, char *[])

// Testing case of unimplemented spline order
{

using FunctionType = itk::BSplineDerivativeKernelFunction<5>;
auto function = FunctionType::New();

ITK_TRY_EXPECT_EXCEPTION(function->Evaluate(0.0));
}


std::cout << "Test passed. " << std::endl;
std::cout << "Test finished. " << std::endl;
return EXIT_SUCCESS;
}
5 changes: 4 additions & 1 deletion Modules/Core/Common/test/itkGaussianSpatialFunctionTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ itkGaussianSpatialFunctionTest(int argc, char * argv[])
{
if (argc < 3)
{
std::cout << "Usage: " << itkNameOfTestExecutableMacro(argv) << " scale normalized" << std::endl;
std::cerr << "Missing parameters." << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " scale normalized" << std::endl;
return EXIT_FAILURE;
}

Expand Down Expand Up @@ -110,5 +111,7 @@ itkGaussianSpatialFunctionTest(int argc, char * argv[])
return EXIT_FAILURE;
}


std::cerr << "Test finished." << std::endl;
return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,6 @@ itkImageSpatialObjectTest(int, char *[])
}


std::cout << "Test finished" << std::endl;
std::cout << "Test finished." << std::endl;
return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ itkDisplacementFieldTransformTest(int argc, char * argv[])
{
if (argc < 3)
{
std::cerr << "Missing parameters." << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv);
std::cerr << " coordinateTolerance directionTolerance";
std::cerr << std::endl;
Expand Down
27 changes: 6 additions & 21 deletions Modules/Filtering/ImageGrid/test/itkExpandImageFilterTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,13 @@ class ShowProgressObject
int
itkExpandImageFilterTest(int, char *[])
{
constexpr unsigned int ImageDimension = 2;

using PixelType = float;
enum
{
ImageDimension = 2
};
using ImageType = itk::Image<PixelType, ImageDimension>;

int testPassed = EXIT_SUCCESS;


//=============================================================

std::cout << "Create the input image pattern." << std::endl;
ImageType::RegionType region;
ImageType::SizeType size = { { 64, 64 } };
Expand All @@ -96,10 +91,9 @@ itkExpandImageFilterTest(int, char *[])
input->SetBufferedRegion(region);
input->Allocate();

int j;
ImagePattern<ImageDimension> pattern;
pattern.m_Offset = 64;
for (j = 0; j < ImageDimension; ++j)
for (unsigned int j = 0; j < ImageDimension; ++j)
{
pattern.m_Coeff[j] = 1.0;
}
Expand All @@ -113,10 +107,7 @@ itkExpandImageFilterTest(int, char *[])
++inIter;
}

//=============================================================

std::cout << "Run ExpandImageFilter in standalone mode with progress.";
std::cout << std::endl;
std::cout << "Run ExpandImageFilter in standalone mode with progress." << std::endl;
using ExpanderType = itk::ExpandImageFilter<ImageType, ImageType>;
auto expander = ExpanderType::New();

Expand Down Expand Up @@ -144,8 +135,6 @@ itkExpandImageFilterTest(int, char *[])
expander->Print(std::cout);
expander->Update();

//=============================================================

std::cout << "Checking the output against expected." << std::endl;
Iterator outIter(expander->GetOutput(), expander->GetOutput()->GetBufferedRegion());

Expand Down Expand Up @@ -191,10 +180,7 @@ itkExpandImageFilterTest(int, char *[])
++outIter;
}

//=============================================================

std::cout << "Run ExpandImageFilter with streamer";
std::cout << std::endl;
std::cout << "Run ExpandImageFilter with streamer" << std::endl;

using CasterType = itk::CastImageFilter<ImageType, ImageType>;
auto caster = CasterType::New();
Expand All @@ -215,7 +201,6 @@ itkExpandImageFilterTest(int, char *[])
streamer->SetNumberOfStreamDivisions(3);
streamer->Update();

//=============================================================
std::cout << "Compare standalone and streamed outputs" << std::endl;

Iterator streamIter(streamer->GetOutput(), streamer->GetOutput()->GetBufferedRegion());
Expand Down Expand Up @@ -254,6 +239,6 @@ itkExpandImageFilterTest(int, char *[])
expander->SetInterpolator(interpolator);


std::cout << "Test passed." << std::endl;
std::cout << "Test finished." << std::endl;
return testPassed;
}
20 changes: 11 additions & 9 deletions Modules/Filtering/ImageGrid/test/itkExpandImageFilterTest2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,10 @@ DoubleToStringArray(double * a, unsigned int size)
int
itkExpandImageFilterTest2(int, char *[])
{
// return EXIT_FAILURE;
int statusValue = EXIT_SUCCESS;

/// Test 1D: A 5 pixel long 1D image with 2 channels. Using a NearestNeighborInterpolator for simplicity. Expanding
/// by 2.
// Test 1D: A 5 pixel long 1D image with 2 channels. Using a NearestNeighborInterpolator for simplicity. Expanding
// by 2.
VectorImage1D::SizeType size1D = { { 5 } };

VectorImage1D::Pointer input1D = GetVectorTestImage<VectorImage1D>(size1D, 2);
Expand All @@ -213,8 +212,8 @@ itkExpandImageFilterTest2(int, char *[])
expander1D->Update();
VectorImage1D::Pointer output1D = expander1D->GetOutput();

std::cout << "Output 1D: \n";
std::cout << PrintTestImage1D<VectorImage1D>(output1D) << '\n';
std::cout << "Output 1D: " << std::endl;
std::cout << PrintTestImage1D<VectorImage1D>(output1D) << std::endl;

auto s1 = output1D->GetLargestPossibleRegion().GetSize()[0];

Expand All @@ -237,8 +236,8 @@ itkExpandImageFilterTest2(int, char *[])
statusValue = EXIT_FAILURE;
}

/// Test 3D: a 3 x 3 4-channel image. Like above, incremental pixel values along each channel, dim 0, dim 1, dim 2.
/// Channel 1 values are 1-27, Channel 2 is 28-54, etc. Expanding by 2 along dim 1.
// Test 3D: a 3 x 3 4-channel image. Like above, incremental pixel values along each channel, dim 0, dim 1, dim 2.
// Channel 1 values are 1-27, Channel 2 is 28-54, etc. Expanding by 2 along dim 1.
VectorImage3D::SizeType size3D = { { 3, 3, 3 } };
VectorImage3D::Pointer input3D = GetVectorTestImage<VectorImage3D>(size3D, 4);

Expand All @@ -259,8 +258,8 @@ itkExpandImageFilterTest2(int, char *[])

VectorImage3D::Pointer output3D = expander3D->GetOutput();

std::cout << "Output 3D: \n";
std::cout << PrintTestImage3D<VectorImage3D>(output3D) << '\n';
std::cout << "Output 3D: " << std::endl;
std::cout << PrintTestImage3D<VectorImage3D>(output3D) << std::endl;

VectorImage3D::SizeType s2 = output3D->GetLargestPossibleRegion().GetSize();
double d3[3] = { 3, 6, 3 };
Expand Down Expand Up @@ -297,5 +296,8 @@ itkExpandImageFilterTest2(int, char *[])
<< "\nActual: " << DoubleToStringArray(slice3Out, 6) << '\n';
statusValue = EXIT_FAILURE;
}


std::cout << "Test finished." << std::endl;
return statusValue;
}
40 changes: 11 additions & 29 deletions Modules/Filtering/ImageGrid/test/itkWarpImageFilterTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,16 @@ class ShowProgressObject
int
itkWarpImageFilterTest(int, char *[])
{
constexpr unsigned int ImageDimension = 2;

using PixelType = float;
enum
{
ImageDimension = 2
};
using ImageType = itk::Image<PixelType, ImageDimension>;
using VectorImageType = itk::VectorImage<PixelType, ImageDimension>;
using VectorType = itk::Vector<float, ImageDimension>;
using FieldType = itk::Image<VectorType, ImageDimension>;

int testPassed = EXIT_SUCCESS;


//=============================================================

std::cout << "Create the input image pattern." << std::endl;
ImageType::RegionType region;
ImageType::SizeType size = { { 64, 64 } };
Expand All @@ -121,11 +116,10 @@ itkWarpImageFilterTest(int, char *[])

ImageType::PixelType padValue = 4.0;

int j;
ImagePattern<ImageDimension> pattern;

pattern.m_Offset = 64;
for (j = 0; j < ImageDimension; ++j)
for (unsigned int j = 0; j < ImageDimension; ++j)
{
pattern.m_Coeff[j] = 1.0;
}
Expand All @@ -137,16 +131,14 @@ itkWarpImageFilterTest(int, char *[])
inIter.Set(pattern.Evaluate(inIter.GetIndex(), size, size, padValue));
}

//=============================================================

std::cout << "Create the input displacement field." << std::endl;

// Tested with { 2, 4 } and { 2, 5 } as well...
unsigned int factors[ImageDimension] = { 2, 3 };

ImageType::RegionType fieldRegion;
ImageType::SizeType fieldSize;
for (j = 0; j < ImageDimension; ++j)
for (unsigned int j = 0; j < ImageDimension; ++j)
{
fieldSize[j] = size[j] * factors[j] + 5;
}
Expand All @@ -163,23 +155,19 @@ itkWarpImageFilterTest(int, char *[])
{
ImageType::IndexType index = fieldIter.GetIndex();
VectorType displacement;
for (j = 0; j < ImageDimension; ++j)
for (unsigned int j = 0; j < ImageDimension; ++j)
{
displacement[j] = static_cast<float>(index[j]) * ((1.0 / factors[j]) - 1.0);
}
fieldIter.Set(displacement);
}

//=============================================================
std::cout << "Instantiate WarpImageFilter with VectorImage.";
std::cout << std::endl;
std::cout << "Instantiate WarpImageFilter with VectorImage." << std::endl;

using WarpVectorImageFilterType = itk::WarpImageFilter<VectorImageType, VectorImageType, VectorImageType>;
auto warpVectorImageFilter = WarpVectorImageFilterType::New();

//=============================================================
std::cout << "Run WarpImageFilter in standalone mode with progress.";
std::cout << std::endl;
std::cout << "Run WarpImageFilter in standalone mode with progress." << std::endl;
using WarperType = itk::WarpImageFilter<ImageType, ImageType, FieldType>;
auto warper = WarperType::New();

Expand Down Expand Up @@ -242,8 +230,6 @@ itkWarpImageFilterTest(int, char *[])
// Update the filter
warper->Update();

//=============================================================

std::cout << "Checking the output against expected." << std::endl;

// compute non-padded output region
Expand All @@ -256,7 +242,7 @@ itkWarpImageFilterTest(int, char *[])
ImageType::SizeType decrementForScaling;
ImageType::SizeType clampSizeDecrement;
ImageType::SizeType clampSize;
for (j = 0; j < ImageDimension; ++j)
for (unsigned int j = 0; j < ImageDimension; ++j)
{
validSize[j] = size[j] * factors[j];

Expand Down Expand Up @@ -290,7 +276,7 @@ itkWarpImageFilterTest(int, char *[])
validRegion.SetSize(validSize);

// adjust the pattern coefficients to match
for (j = 0; j < ImageDimension; ++j)
for (unsigned int j = 0; j < ImageDimension; ++j)
{
pattern.m_Coeff[j] /= static_cast<double>(factors[j]);
}
Expand Down Expand Up @@ -329,10 +315,7 @@ itkWarpImageFilterTest(int, char *[])
++outIter;
}

//=============================================================

std::cout << "Run ExpandImageFilter with streamer";
std::cout << std::endl;
std::cout << "Run ExpandImageFilter with streamer" << std::endl;

using VectorCasterType = itk::CastImageFilter<FieldType, FieldType>;
auto vcaster = VectorCasterType::New();
Expand All @@ -351,7 +334,6 @@ itkWarpImageFilterTest(int, char *[])
streamer->SetNumberOfStreamDivisions(3);
streamer->Update();

//=============================================================
std::cout << "Compare standalone and streamed outputs" << std::endl;

Iterator streamIter(streamer->GetOutput(), streamer->GetOutput()->GetBufferedRegion());
Expand Down Expand Up @@ -387,6 +369,6 @@ itkWarpImageFilterTest(int, char *[])
warper->SetInterpolator(interp);


std::cout << "Test passed." << std::endl;
std::cout << "Test finished." << std::endl;
return testPassed;
}
Loading