From 9d5e84db9a1815b89624620da9bbab407866ff9c Mon Sep 17 00:00:00 2001 From: Dominique Belhachemi Date: Fri, 20 Nov 2026 23:07:45 +0000 Subject: [PATCH] BUG: Fix MeshIOBase component types of signed char and plain char MapComponentType returned UNKNOWNCOMPONENTTYPE for `signed char`, and CHAR for plain `char` even where it is unsigned (e.g. arm64). A new itkMeshIOBaseGTest checks the mapping of each type at compile time. --- .../IO/MeshBase/include/itkMeshFileReader.hxx | 4 +- Modules/IO/MeshBase/include/itkMeshIOBase.h | 5 +- Modules/IO/MeshBase/test/CMakeLists.txt | 6 ++- .../IO/MeshBase/test/itkMeshIOBaseGTest.cxx | 48 +++++++++++++++++++ 4 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 Modules/IO/MeshBase/test/itkMeshIOBaseGTest.cxx diff --git a/Modules/IO/MeshBase/include/itkMeshFileReader.hxx b/Modules/IO/MeshBase/include/itkMeshFileReader.hxx index d1123369959..1b780bb0315 100644 --- a/Modules/IO/MeshBase/include/itkMeshFileReader.hxx +++ b/Modules/IO/MeshBase/include/itkMeshFileReader.hxx @@ -724,7 +724,7 @@ MeshFileReader::Co << "to one of: " << std::endl << " " << MeshIOBase::GetComponentTypeAsString(MeshIOBase::MapComponentType::CType) << std::endl - << " " << MeshIOBase::GetComponentTypeAsString(MeshIOBase::MapComponentType::CType) << std::endl + << " " << MeshIOBase::GetComponentTypeAsString(MeshIOBase::MapComponentType::CType) << std::endl << " " << MeshIOBase::GetComponentTypeAsString(MeshIOBase::MapComponentType::CType) << std::endl << " " << MeshIOBase::GetComponentTypeAsString(MeshIOBase::MapComponentType::CType) << std::endl @@ -799,7 +799,7 @@ MeshFileReader::Co << "to one of: " << std::endl << " " << MeshIOBase::GetComponentTypeAsString(MeshIOBase::MapComponentType::CType) << std::endl - << " " << MeshIOBase::GetComponentTypeAsString(MeshIOBase::MapComponentType::CType) << std::endl + << " " << MeshIOBase::GetComponentTypeAsString(MeshIOBase::MapComponentType::CType) << std::endl << " " << MeshIOBase::GetComponentTypeAsString(MeshIOBase::MapComponentType::CType) << std::endl << " " << MeshIOBase::GetComponentTypeAsString(MeshIOBase::MapComponentType::CType) << std::endl diff --git a/Modules/IO/MeshBase/include/itkMeshIOBase.h b/Modules/IO/MeshBase/include/itkMeshIOBase.h index 1a6035c95eb..8e98e355d33 100644 --- a/Modules/IO/MeshBase/include/itkMeshIOBase.h +++ b/Modules/IO/MeshBase/include/itkMeshIOBase.h @@ -208,8 +208,9 @@ class ITKIOMeshBase_EXPORT MeshIOBase : public LightProcessObject struct MapComponentType { static constexpr IOComponentEnum CType = - std::is_same_v ? IOComponentEnum::UCHAR - : std::is_same_v ? IOComponentEnum::CHAR + std::is_same_v ? (std::is_signed_v ? IOComponentEnum::CHAR : IOComponentEnum::UCHAR) + : std::is_same_v ? IOComponentEnum::CHAR + : std::is_same_v ? IOComponentEnum::UCHAR : std::is_same_v ? IOComponentEnum::SHORT : std::is_same_v ? IOComponentEnum::USHORT : std::is_same_v ? IOComponentEnum::INT diff --git a/Modules/IO/MeshBase/test/CMakeLists.txt b/Modules/IO/MeshBase/test/CMakeLists.txt index 789b415276b..8237b2bfb49 100644 --- a/Modules/IO/MeshBase/test/CMakeLists.txt +++ b/Modules/IO/MeshBase/test/CMakeLists.txt @@ -16,5 +16,9 @@ itk_add_test( ${ITK_TEST_OUTPUT_DIR}/itkMeshFileReaderWriterTest.vtk ) -set(ITKIOMeshBaseGTests itkMeshIOExceptionsGTest.cxx) +set( + ITKIOMeshBaseGTests + itkMeshIOBaseGTest.cxx + itkMeshIOExceptionsGTest.cxx +) creategoogletestdriver(ITKIOMeshBase "${ITKIOMeshBase-Test_LIBRARIES}" "${ITKIOMeshBaseGTests}") diff --git a/Modules/IO/MeshBase/test/itkMeshIOBaseGTest.cxx b/Modules/IO/MeshBase/test/itkMeshIOBaseGTest.cxx new file mode 100644 index 00000000000..d0c57f610f6 --- /dev/null +++ b/Modules/IO/MeshBase/test/itkMeshIOBaseGTest.cxx @@ -0,0 +1,48 @@ +/*========================================================================= + * + * 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 "itkMeshIOBase.h" +#include + +namespace +{ +// Tests `MeshIOBase::MapComponentType::CType`. +using itk::IOComponentEnum; +using itk::MeshIOBase; + +struct UnknownComponentType +{}; +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::UNKNOWNCOMPONENTTYPE); + +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::UCHAR); +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::CHAR); +static_assert(MeshIOBase::MapComponentType::CType == + (std::is_signed_v ? IOComponentEnum::CHAR : IOComponentEnum::UCHAR)); +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::USHORT); +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::SHORT); +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::UINT); +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::INT); +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::ULONG); +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::LONG); +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::ULONGLONG); +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::LONGLONG); +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::FLOAT); +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::DOUBLE); +static_assert(MeshIOBase::MapComponentType::CType == IOComponentEnum::LDOUBLE); +} // namespace