Skip to content

Commit

Permalink
STYLE: Prefer using macros for itk::SLICImageFilter basic methods
Browse files Browse the repository at this point in the history
Prefer using macros to exercise `itk::SLICImageFilter` basic methods:
- Exercise basic object methods using the
  `ITK_EXERCISE_BASIC_OBJECT_METHODS`. Remove redundant calls to
  test the filter class and superclass names and to print the filter:
  rely on the basic method exercising macro call.
- Refactor the helper method to return a value as the macro may return a
  value, and rename it to honor its purpose.
- Rename the google test method to honor its contents.
  • Loading branch information
jhlegarreta committed Sep 2, 2023
1 parent 3eb8fd7 commit df51b3f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Expand Up @@ -86,19 +86,15 @@ class SLICFixture : public ::testing::Test
} // namespace


TEST_F(SLICFixture, SetGetPrint)
TEST_F(SLICFixture, SetGet)
{
using namespace itk::GTest::TypedefsAndConstructors::Dimension3;
using Utils = FixtureUtilities<3>;

auto filter = Utils::FilterType::New();
filter->Print(std::cout);

typename Utils::FilterType::ConstPointer constfilter = (const Utils::FilterType *)(filter.GetPointer());

EXPECT_STREQ("SLICImageFilter", filter->GetNameOfClass());
EXPECT_STREQ("ImageToImageFilter", filter->Superclass::GetNameOfClass());

Utils::FilterType::SuperGridSizeType gridSize3(3);
EXPECT_NO_THROW(filter->SetSuperGridSize(gridSize3));
ITK_EXPECT_VECTOR_NEAR(gridSize3, filter->GetSuperGridSize(), 0);
Expand Down
26 changes: 17 additions & 9 deletions Modules/Segmentation/SuperPixel/test/itkSLICImageFilterTest.cxx
Expand Up @@ -44,11 +44,11 @@ iterationEventCallback(itk::Object * object, const itk::EventObject & event, voi


template <typename TInputImageType>
void
itkSLICImageFilter(const std::string & inFileName,
const std::string & outFileName,
const unsigned int gridSize,
bool enforceConnectivity)
int
itkSLICImageFilterTestHelper(const std::string & inFileName,
const std::string & outFileName,
const unsigned int gridSize,
bool enforceConnectivity)
{

const unsigned int Dimension = TInputImageType::ImageDimension;
Expand All @@ -63,6 +63,10 @@ itkSLICImageFilter(const std::string & inFileName,

using FilterType = itk::SLICImageFilter<InputImageType, OutputImageType>;
auto filter = FilterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, SLICImageFilter, ImageToImageFilter);


filter->SetInput(reader->GetOutput());
filter->SetSuperGridSize(gridSize);
filter->SetEnforceConnectivity(enforceConnectivity);
Expand All @@ -80,6 +84,8 @@ itkSLICImageFilter(const std::string & inFileName,
writer->SetFileName(outFileName);
writer->SetInput(filter->GetOutput());
writer->Update();

return EXIT_SUCCESS;
}
} // namespace

Expand Down Expand Up @@ -117,21 +123,23 @@ itkSLICImageFilterTest(int argc, char * argv[])
case 2:
if (numberOfComponents == 1)
{
itkSLICImageFilter<itk::Image<float, 2>>(inFileName, outFileName, gridSize, enforceConnectivity);
itkSLICImageFilterTestHelper<itk::Image<float, 2>>(inFileName, outFileName, gridSize, enforceConnectivity);
}
else
{
itkSLICImageFilter<itk::VectorImage<float, 2>>(inFileName, outFileName, gridSize, enforceConnectivity);
itkSLICImageFilterTestHelper<itk::VectorImage<float, 2>>(
inFileName, outFileName, gridSize, enforceConnectivity);
}
break;
case 3:
if (numberOfComponents == 1)
{
itkSLICImageFilter<itk::Image<float, 3>>(inFileName, outFileName, gridSize, enforceConnectivity);
itkSLICImageFilterTestHelper<itk::Image<float, 3>>(inFileName, outFileName, gridSize, enforceConnectivity);
}
else
{
itkSLICImageFilter<itk::VectorImage<float, 3>>(inFileName, outFileName, gridSize, enforceConnectivity);
itkSLICImageFilterTestHelper<itk::VectorImage<float, 3>>(
inFileName, outFileName, gridSize, enforceConnectivity);
}
break;
default:
Expand Down

0 comments on commit df51b3f

Please sign in to comment.