From 944f3b09b1aeb4e21965aaddccef5491a418a24a Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Wed, 11 Feb 2026 21:32:07 -0600 Subject: [PATCH] ENH: Replace 'char' with int8_t when numeric is intended The 'char' type can be signed or unsigned on different platforms and is generally used for ASCII character storage. To conistently represent 8-bit signed values on differnt platforms the int8_t type is recommended. --- Modules/Bridge/VtkGlue/src/QuickView.cxx | 2 +- .../itkConstNeighborhoodIteratorWithOnlyIndex.h | 4 ++-- .../test/itkImageComputeOffsetAndIndexTest.cxx | 8 ++++---- .../Common/test/itkImageIteratorWithIndexTest.cxx | 6 +++--- ...rchingImageFilterRealWithNumberOfElementsTest.cxx | 2 +- .../ImageFilterBase/test/itkCastImageFilterTest.cxx | 4 ++-- ...encyFFTLayoutImageRegionIteratorWithIndexTest.cxx | 2 +- .../ImageIntensity/test/itkClampImageFilterTest.cxx | 8 ++++---- .../test/itkHistogramMatchingImageFilterTest.cxx | 2 +- Modules/IO/MINC/test/itkMINCImageIOTest.cxx | 2 +- Modules/IO/NIFTI/test/itkNiftiImageIOTest.cxx | 2 +- Modules/IO/NRRD/test/itkNrrdImageIOTest.cxx | 8 ++++---- Modules/IO/VTK/test/itkVTKImageIO2Test.cxx | 12 ++++++------ Modules/IO/VTK/test/itkVTKImageIOStreamTest.cxx | 2 +- Modules/IO/VTK/test/itkVTKImageIOTest.cxx | 2 +- .../test/itkImageRegistrationMethodTest_16.cxx | 2 +- 16 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Modules/Bridge/VtkGlue/src/QuickView.cxx b/Modules/Bridge/VtkGlue/src/QuickView.cxx index ee7527236f9..a95380588ea 100644 --- a/Modules/Bridge/VtkGlue/src/QuickView.cxx +++ b/Modules/Bridge/VtkGlue/src/QuickView.cxx @@ -47,7 +47,7 @@ using UnsignedCharRGBImageType = itk::Image, 2>; using FloatRGBImageType = itk::Image, 2>; using UnsignedCharImageType = itk::Image; -using CharImageType = itk::Image; +using CharImageType = itk::Image; using UnsignedShortImageType = itk::Image; using ShortImageType = itk::Image; using UnsignedIntImageType = itk::Image; diff --git a/Modules/Core/Common/include/itkConstNeighborhoodIteratorWithOnlyIndex.h b/Modules/Core/Common/include/itkConstNeighborhoodIteratorWithOnlyIndex.h index c4eea2df5bd..fafd9ed00c2 100644 --- a/Modules/Core/Common/include/itkConstNeighborhoodIteratorWithOnlyIndex.h +++ b/Modules/Core/Common/include/itkConstNeighborhoodIteratorWithOnlyIndex.h @@ -57,7 +57,7 @@ namespace itk * */ template -class ITK_TEMPLATE_EXPORT ConstNeighborhoodIteratorWithOnlyIndex : public Neighborhood +class ITK_TEMPLATE_EXPORT ConstNeighborhoodIteratorWithOnlyIndex : public Neighborhood { public: ITK_DEFAULT_COPY_AND_MOVE(ConstNeighborhoodIteratorWithOnlyIndex); @@ -68,7 +68,7 @@ class ITK_TEMPLATE_EXPORT ConstNeighborhoodIteratorWithOnlyIndex : public Neighb /** Save the image dimension. */ static constexpr DimensionValueType Dimension = TImage::ImageDimension; - using DummyNeighborhoodPixelType = char; + using DummyNeighborhoodPixelType = int8_t; /** Standard class type aliases. */ using Self = ConstNeighborhoodIteratorWithOnlyIndex; diff --git a/Modules/Core/Common/test/itkImageComputeOffsetAndIndexTest.cxx b/Modules/Core/Common/test/itkImageComputeOffsetAndIndexTest.cxx index 18d98758e94..e89361289a2 100644 --- a/Modules/Core/Common/test/itkImageComputeOffsetAndIndexTest.cxx +++ b/Modules/Core/Common/test/itkImageComputeOffsetAndIndexTest.cxx @@ -112,7 +112,7 @@ itkImageComputeOffsetAndIndexTest(int, char *[]) #define TRY_FAST_INDEX(dim) \ { \ - using PixelType = char; \ + using PixelType = int8_t; \ using ImageType = itk::Image; \ auto myImage = ImageType::New(); \ const auto size = ImageType::SizeType::Filled(50); \ @@ -137,7 +137,7 @@ itkImageComputeOffsetAndIndexTest(int, char *[]) #define TRY_INDEX(dim) \ { \ - using PixelType = char; \ + using PixelType = int8_t; \ using ImageType = itk::Image; \ auto myImage = ImageType::New(); \ const auto size = ImageType::SizeType::Filled(50); \ @@ -162,7 +162,7 @@ itkImageComputeOffsetAndIndexTest(int, char *[]) #define TRY_FAST_OFFSET(dim) \ { \ - using PixelType = char; \ + using PixelType = int8_t; \ using ImageType = itk::Image; \ auto myImage = ImageType::New(); \ const auto size = ImageType::SizeType::Filled(50); \ @@ -182,7 +182,7 @@ itkImageComputeOffsetAndIndexTest(int, char *[]) ITK_MACROEND_NOOP_STATEMENT #define TRY_OFFSET(dim) \ { \ - using PixelType = char; \ + using PixelType = int8_t; \ using ImageType = itk::Image; \ auto myImage = ImageType::New(); \ const auto size = ImageType::SizeType::Filled(50); \ diff --git a/Modules/Core/Common/test/itkImageIteratorWithIndexTest.cxx b/Modules/Core/Common/test/itkImageIteratorWithIndexTest.cxx index a7bd2073da2..b81996949ed 100644 --- a/Modules/Core/Common/test/itkImageIteratorWithIndexTest.cxx +++ b/Modules/Core/Common/test/itkImageIteratorWithIndexTest.cxx @@ -140,7 +140,7 @@ itkImageIteratorWithIndexTest(int, char *[]) // test the iterators on them std::cout << "Testing with Image< char, 3 > " << std::endl; - itkImageIteratorWithIndexTestIteratorTester TesterC(10); + itkImageIteratorWithIndexTestIteratorTester TesterC(10); if (TesterC.TestIterator() == false) { testPassed = false; @@ -259,8 +259,8 @@ itkImageIteratorWithIndexTest(int, char *[]) testPassed = false; } - std::cout << "Testing with Image< itk::Vector, 3 > " << std::endl; - using VC = itk::Vector; + std::cout << "Testing with Image< itk::Vector, 3 > " << std::endl; + using VC = itk::Vector; auto vc = itk::MakeFilled(127); itkImageIteratorWithIndexTestIteratorTester TesterVC(vc); if (TesterVC.TestIterator() == false) diff --git a/Modules/Filtering/FastMarching/test/itkFastMarchingImageFilterRealWithNumberOfElementsTest.cxx b/Modules/Filtering/FastMarching/test/itkFastMarchingImageFilterRealWithNumberOfElementsTest.cxx index eec73a340bb..cbb0b753aaf 100644 --- a/Modules/Filtering/FastMarching/test/itkFastMarchingImageFilterRealWithNumberOfElementsTest.cxx +++ b/Modules/Filtering/FastMarching/test/itkFastMarchingImageFilterRealWithNumberOfElementsTest.cxx @@ -120,7 +120,7 @@ itkFastMarchingImageFilterRealWithNumberOfElementsTest(int, char *[]) ITK_TRY_EXPECT_NO_EXCEPTION(marcher->Update()); - using OutputPixelType = char; + using OutputPixelType = int8_t; using OutputImageType = itk::Image; diff --git a/Modules/Filtering/ImageFilterBase/test/itkCastImageFilterTest.cxx b/Modules/Filtering/ImageFilterBase/test/itkCastImageFilterTest.cxx index fb6ec61a3f0..11b0d276c74 100644 --- a/Modules/Filtering/ImageFilterBase/test/itkCastImageFilterTest.cxx +++ b/Modules/Filtering/ImageFilterBase/test/itkCastImageFilterTest.cxx @@ -253,7 +253,7 @@ bool TestCastFrom() { bool success = true; - success &= TestCastFromTo(); + success &= TestCastFromTo(); success &= TestCastFromTo(); success &= TestCastFromTo(); success &= TestCastFromTo(); @@ -460,7 +460,7 @@ itkCastImageFilterTest(int, char *[]) } bool success = true; - success &= TestCastFrom(); + success &= TestCastFrom(); success &= TestCastFrom(); success &= TestCastFrom(); success &= TestCastFrom(); diff --git a/Modules/Filtering/ImageFrequency/test/itkFrequencyFFTLayoutImageRegionIteratorWithIndexTest.cxx b/Modules/Filtering/ImageFrequency/test/itkFrequencyFFTLayoutImageRegionIteratorWithIndexTest.cxx index c11b3b9e71d..2cd14ec20ae 100644 --- a/Modules/Filtering/ImageFrequency/test/itkFrequencyFFTLayoutImageRegionIteratorWithIndexTest.cxx +++ b/Modules/Filtering/ImageFrequency/test/itkFrequencyFFTLayoutImageRegionIteratorWithIndexTest.cxx @@ -254,7 +254,7 @@ itkFrequencyFFTLayoutImageRegionIteratorWithIndexTest(int, char *[]) constexpr unsigned int Dimension{ 3 }; - using CharPixelType = char; + using CharPixelType = int8_t; using FloatPixelType = float; // Even input image size test diff --git a/Modules/Filtering/ImageIntensity/test/itkClampImageFilterTest.cxx b/Modules/Filtering/ImageIntensity/test/itkClampImageFilterTest.cxx index a5b9c454bf1..bff33124ac9 100644 --- a/Modules/Filtering/ImageIntensity/test/itkClampImageFilterTest.cxx +++ b/Modules/Filtering/ImageIntensity/test/itkClampImageFilterTest.cxx @@ -150,7 +150,7 @@ bool TestClampFrom() { const bool success = - TestClampFromTo() && TestClampFromTo() && + TestClampFromTo() && TestClampFromTo() && TestClampFromTo() && TestClampFromTo() && TestClampFromTo() && TestClampFromTo() && TestClampFromTo() && TestClampFromTo() && @@ -263,7 +263,7 @@ template bool TestClampFromWithCustomBounds() { - const bool success = TestClampFromToWithCustomBounds() && + const bool success = TestClampFromToWithCustomBounds() && TestClampFromToWithCustomBounds() && TestClampFromToWithCustomBounds() && TestClampFromToWithCustomBounds() && @@ -290,12 +290,12 @@ itkClampImageFilterTest(int, char *[]) auto filter = FilterType::New(); ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, ClampImageFilter, UnaryFunctorImageFilter); - const bool success = TestClampFrom() && TestClampFrom() && TestClampFrom() && + const bool success = TestClampFrom() && TestClampFrom() && TestClampFrom() && TestClampFrom() && TestClampFrom() && TestClampFrom() && TestClampFrom() && TestClampFrom() && TestClampFrom() && TestClampFrom() && TestClampFrom() && TestClampFrom() && - TestClampFromWithCustomBounds() && TestClampFromWithCustomBounds() && + TestClampFromWithCustomBounds() && TestClampFromWithCustomBounds() && TestClampFromWithCustomBounds() && TestClampFromWithCustomBounds() && TestClampFromWithCustomBounds() && TestClampFromWithCustomBounds() && TestClampFromWithCustomBounds() && TestClampFromWithCustomBounds() && diff --git a/Modules/Filtering/ImageIntensity/test/itkHistogramMatchingImageFilterTest.cxx b/Modules/Filtering/ImageIntensity/test/itkHistogramMatchingImageFilterTest.cxx index 392fe4073cb..e9768c869c0 100644 --- a/Modules/Filtering/ImageIntensity/test/itkHistogramMatchingImageFilterTest.cxx +++ b/Modules/Filtering/ImageIntensity/test/itkHistogramMatchingImageFilterTest.cxx @@ -434,7 +434,7 @@ itkHistogramMatchingImageFilterTest(int, char *[]) { return EXIT_FAILURE; } - if (itkHistogramMatchingImageFilterTest() != EXIT_SUCCESS) + if (itkHistogramMatchingImageFilterTest() != EXIT_SUCCESS) { return EXIT_FAILURE; } diff --git a/Modules/IO/MINC/test/itkMINCImageIOTest.cxx b/Modules/IO/MINC/test/itkMINCImageIOTest.cxx index c81d4c72ae4..286390fbbba 100644 --- a/Modules/IO/MINC/test/itkMINCImageIOTest.cxx +++ b/Modules/IO/MINC/test/itkMINCImageIOTest.cxx @@ -789,7 +789,7 @@ itkMINCImageIOTest(int argc, char * argv[]) int result(0); // straightforward test result += MINCReadWriteTest("3DUCharImage.mnc", typeid(unsigned char).name()); - result += MINCReadWriteTest("3DCharImage.mnc", typeid(unsigned char).name()); + result += MINCReadWriteTest("3DCharImage.mnc", typeid(unsigned char).name()); result += MINCReadWriteTest("3DUShortImage.mnc", typeid(short).name()); result += MINCReadWriteTest("3DShortImage.mnc", typeid(unsigned short).name()); result += MINCReadWriteTest("3DUIntImage.mnc", typeid(int).name()); diff --git a/Modules/IO/NIFTI/test/itkNiftiImageIOTest.cxx b/Modules/IO/NIFTI/test/itkNiftiImageIOTest.cxx index 6d5bda5a35b..d8467cbcef7 100644 --- a/Modules/IO/NIFTI/test/itkNiftiImageIOTest.cxx +++ b/Modules/IO/NIFTI/test/itkNiftiImageIOTest.cxx @@ -411,7 +411,7 @@ itkNiftiImageIOTest(int argc, char * argv[]) } else // This is the mechanism for doing internal testing of all data types. { - int cur_return = MakeNiftiImage(testFileName); + int cur_return = MakeNiftiImage(testFileName); if (cur_return != 0) { std::cerr << "Error writing Nifti file type char" << std::endl; diff --git a/Modules/IO/NRRD/test/itkNrrdImageIOTest.cxx b/Modules/IO/NRRD/test/itkNrrdImageIOTest.cxx index 1727107e994..edb1016115d 100644 --- a/Modules/IO/NRRD/test/itkNrrdImageIOTest.cxx +++ b/Modules/IO/NRRD/test/itkNrrdImageIOTest.cxx @@ -47,7 +47,7 @@ itkNrrdImageIOTest(int argc, char * argv[]) int ret = EXIT_SUCCESS; ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); - ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); + ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); @@ -59,7 +59,7 @@ itkNrrdImageIOTest(int argc, char * argv[]) ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); - ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); + ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); @@ -72,7 +72,7 @@ itkNrrdImageIOTest(int argc, char * argv[]) ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); - ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); + ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); @@ -86,7 +86,7 @@ itkNrrdImageIOTest(int argc, char * argv[]) ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile); // Test with compression on - ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile, true); + ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile, true); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile, true); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile, true); ret += itkNrrdImageIOTestReadWriteTest(std::string(argv[1]), sz, inputFile, true); diff --git a/Modules/IO/VTK/test/itkVTKImageIO2Test.cxx b/Modules/IO/VTK/test/itkVTKImageIO2Test.cxx index 344818ef21b..efd9e68e88b 100644 --- a/Modules/IO/VTK/test/itkVTKImageIO2Test.cxx +++ b/Modules/IO/VTK/test/itkVTKImageIO2Test.cxx @@ -130,7 +130,7 @@ class VTKImageIOTester writer->SetInput(image); - const std::string outputFileName = VTKImageIOTester::SetupFileName(filePrefix, "vtk", outputPath); + const std::string outputFileName = VTKImageIOTester::SetupFileName(filePrefix, "vtk", outputPath); writer->SetFileName(outputFileName); writer->Update(); @@ -371,7 +371,7 @@ itkVTKImageIO2Test(int argc, char * argv[]) int status = 0; status += Test1Type(filePrefix, outputPath, "unsigned char"); - status += Test1Type(filePrefix, outputPath, "char"); + status += Test1Type(filePrefix, outputPath, "char"); status += Test1Type(filePrefix, outputPath, "unsigned short"); status += Test1Type(filePrefix, outputPath, "short"); status += Test1Type(filePrefix, outputPath, "unsigned int"); @@ -399,7 +399,7 @@ itkVTKImageIO2Test(int argc, char * argv[]) // // read bad file extension - if (VTKImageIOTester::CanReadFileTest(filePrefix, "bad", outputPath)) + if (VTKImageIOTester::CanReadFileTest(filePrefix, "bad", outputPath)) { std::cout << "[FAILED] didn't properly reject bad file extension for reading" << std::endl; status++; @@ -407,7 +407,7 @@ itkVTKImageIO2Test(int argc, char * argv[]) std::cout << "[PASSED] rejected bad file extension for reading" << std::endl; // read bad file name - if (VTKImageIOTester::CanReadFileTest("BadFile", "vtk", outputPath)) + if (VTKImageIOTester::CanReadFileTest("BadFile", "vtk", outputPath)) { std::cout << "[FAILED] didn't properly reject bad file name for reading" << std::endl; status++; @@ -415,7 +415,7 @@ itkVTKImageIO2Test(int argc, char * argv[]) std::cout << "[PASSED] rejected bad file name for reading" << std::endl; // write bad file extension - if (VTKImageIOTester::CanWriteFileTest(filePrefix, "bad", outputPath)) + if (VTKImageIOTester::CanWriteFileTest(filePrefix, "bad", outputPath)) { std::cout << "[FAILED] didn't properly reject bad file extension for writing" << std::endl; status++; @@ -423,7 +423,7 @@ itkVTKImageIO2Test(int argc, char * argv[]) std::cout << "[PASSED] rejected bad file extension for writing" << std::endl; // write bad file extension when the string ".vtk" is part of the prefix - if (VTKImageIOTester::CanWriteFileTest(filePrefix + ".vtk", "bad", outputPath)) + if (VTKImageIOTester::CanWriteFileTest(filePrefix + ".vtk", "bad", outputPath)) { std::cout << "[FAILED] didn't properly reject bad file extension for writing" << std::endl; status++; diff --git a/Modules/IO/VTK/test/itkVTKImageIOStreamTest.cxx b/Modules/IO/VTK/test/itkVTKImageIOStreamTest.cxx index 8bb0f6825c0..4bb1643eb44 100644 --- a/Modules/IO/VTK/test/itkVTKImageIOStreamTest.cxx +++ b/Modules/IO/VTK/test/itkVTKImageIOStreamTest.cxx @@ -308,7 +308,7 @@ itkVTKImageIOStreamTest(int argc, char * argv[]) ReadWriteTestMACRO(float); ReadWriteTestMACRO(double); ReadWriteTestMACRO(unsigned char); - ReadWriteTestMACRO(char); + ReadWriteTestMACRO(int8_t); ReadWriteTestMACRO(unsigned short); ReadWriteTestMACRO(short); ReadWriteTestMACRO(unsigned int); diff --git a/Modules/IO/VTK/test/itkVTKImageIOTest.cxx b/Modules/IO/VTK/test/itkVTKImageIOTest.cxx index a207c281c37..90861a824ca 100644 --- a/Modules/IO/VTK/test/itkVTKImageIOTest.cxx +++ b/Modules/IO/VTK/test/itkVTKImageIOTest.cxx @@ -141,7 +141,7 @@ itkVTKImageIOTest(int argc, char * argv[]) status += Test1Type(file1, file2); status += Test1Type(file1, file2); status += Test1Type(file1, file2); - status += Test1Type(file1, file2); + status += Test1Type(file1, file2); status += Test1Type(file1, file2); status += Test1Type(file1, file2); status += Test1Type(file1, file2); diff --git a/Modules/Registration/Common/test/itkImageRegistrationMethodTest_16.cxx b/Modules/Registration/Common/test/itkImageRegistrationMethodTest_16.cxx index dda5bf8ab58..211f24b11c7 100644 --- a/Modules/Registration/Common/test/itkImageRegistrationMethodTest_16.cxx +++ b/Modules/Registration/Common/test/itkImageRegistrationMethodTest_16.cxx @@ -174,7 +174,7 @@ int itkImageRegistrationMethodTest_16(int itkNotUsed(argc), char *[] itkNotUsed(argv)) { const bool result_uc = DoRegistration(); - const bool result_c = DoRegistration(); + const bool result_c = DoRegistration(); const bool result_us = DoRegistration(); const bool result_s = DoRegistration(); const bool result_ui = DoRegistration();