From c58b9c081d5f0487cc0da7ede2ea89d1987325c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Sun, 6 Oct 2024 13:42:13 -0400 Subject: [PATCH] ENH: Add `itk::RelabelComponenetsImageFilter` signedness test Add a test to check that the `itk::RelabelComponenetsImageFilter` class does not trigger compiler warnings with signed pixel types. Ensures regressions are not introduced after the fix in commit 108a2cf. --- .../ConnectedComponents/test/CMakeLists.txt | 7 +++ ...abelComponentImageFilterSignednessTest.cxx | 52 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 Modules/Segmentation/ConnectedComponents/test/itkRelabelComponentImageFilterSignednessTest.cxx diff --git a/Modules/Segmentation/ConnectedComponents/test/CMakeLists.txt b/Modules/Segmentation/ConnectedComponents/test/CMakeLists.txt index 276063f169b..6a06023eaf5 100644 --- a/Modules/Segmentation/ConnectedComponents/test/CMakeLists.txt +++ b/Modules/Segmentation/ConnectedComponents/test/CMakeLists.txt @@ -1,6 +1,7 @@ itk_module_test() set(ITKConnectedComponentsTests itkRelabelComponentImageFilterTest.cxx + itkRelabelComponentImageFilterSignednessTest.cxx itkHardConnectedComponentImageFilterTest.cxx itkConnectedComponentImageFilterTestRGB.cxx itkConnectedComponentImageFilterTest.cxx @@ -26,6 +27,12 @@ itk_add_test( ${ITK_TEST_OUTPUT_DIR}/RelabelComponentImageFilterTest.png 130 145) +itk_add_test( + NAME + itkRelabelComponentImageFilterSignednessTest + COMMAND + ITKConnectedComponentsTestDriver + itkRelabelComponentImageFilterSignednessTest) itk_add_test( NAME itkHardConnectedComponentImageFilterTest diff --git a/Modules/Segmentation/ConnectedComponents/test/itkRelabelComponentImageFilterSignednessTest.cxx b/Modules/Segmentation/ConnectedComponents/test/itkRelabelComponentImageFilterSignednessTest.cxx new file mode 100644 index 00000000000..9a670d85407 --- /dev/null +++ b/Modules/Segmentation/ConnectedComponents/test/itkRelabelComponentImageFilterSignednessTest.cxx @@ -0,0 +1,52 @@ +/*========================================================================= + * + * 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. + * + *=========================================================================*/ + +#include "itkImage.h" +#include "itkRelabelComponentImageFilter.h" +#include "itkTestingMacros.h" + + +int +itkRelabelComponentImageFilterSignednessTest(int, char *[]) +{ + + constexpr unsigned int Dimension = 3; + // Use a signed type + using PixelType = signed short; + + using ImageType = itk::Image; + using FilterType = itk::RelabelComponentImageFilter; + using LabelType = FilterType::LabelType; + + auto relabeler = FilterType::New(); + + // Call itk::RelabelComponentImageFilter methods to ensure that using a signed image does not raise any + // signedness compilation warning in them + LabelType label{}; + itk::SizeValueType obj{}; + + ITK_TEST_EXPECT_EQUAL(0, relabeler->GetSizeOfObjectInPixels(label)); + ITK_TEST_EXPECT_EQUAL(0, relabeler->GetSizeOfObjectInPixels(obj)); + + ITK_TEST_EXPECT_EQUAL(0, relabeler->GetSizeOfObjectInPhysicalUnits(label)); + ITK_TEST_EXPECT_EQUAL(0, relabeler->GetSizeOfObjectInPhysicalUnits(obj)); + + + std::cout << "Test finished." << std::endl; + return EXIT_SUCCESS; +}