From 7eef0facc6f10ec62d06ba59bbeceef00c74c716 Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Wed, 14 Aug 2024 11:00:05 -0400 Subject: [PATCH] ENH: Rename DICOMOrientation to AnatomicalOrientation Also rename to ToOrientationEnum to indicate the name of the positive direction of the anatomical orientation. --- ...ientation.h => itkAnatomicalOrientation.h} | 75 ++--- Modules/Core/Common/src/CMakeLists.txt | 2 +- .../Common/src/itkAnatomicalOrientation.cxx | 291 ++++++++++++++++++ .../Core/Common/src/itkDICOMOrientation.cxx | 289 ----------------- Modules/Core/Common/test/CMakeLists.txt | 2 +- .../test/itkAnatomicalOrientationGTest.cxx | 226 ++++++++++++++ .../Common/test/itkDICOMOrientionGTest.cxx | 228 -------------- .../wrapping/itkAnatomicalOrientation.wrap | 1 + .../Common/wrapping/itkDICOMOrientation.wrap | 1 - Modules/IO/GE/src/itkGE4ImageIO.cxx | 24 +- Modules/IO/GE/src/itkGE5ImageIO.cxx | 28 +- Modules/IO/GE/src/itkGEAdwImageIO.cxx | 24 +- Modules/IO/IPL/include/itkGEImageHeader.h | 48 +-- Modules/IO/IPL/src/itkIPLCommonImageIO.cxx | 5 +- .../itkReadWriteImageWithDictionaryTest.cxx | 4 +- Modules/IO/Meta/src/itkMetaImageIO.cxx | 26 +- Modules/IO/NIFTI/src/itkNiftiImageIO.cxx | 50 +-- Modules/IO/NIFTI/test/itkNiftiImageIOTest.h | 9 +- .../IO/NIFTI/test/itkNiftiReadAnalyzeTest.cxx | 116 +++---- .../PhilipsREC/src/itkPhilipsRECImageIO.cxx | 6 +- .../Siemens/src/itkSiemensVisionImageIO.cxx | 36 +-- 21 files changed, 750 insertions(+), 741 deletions(-) rename Modules/Core/Common/include/{itkDICOMOrientation.h => itkAnatomicalOrientation.h} (87%) create mode 100644 Modules/Core/Common/src/itkAnatomicalOrientation.cxx delete mode 100644 Modules/Core/Common/src/itkDICOMOrientation.cxx create mode 100644 Modules/Core/Common/test/itkAnatomicalOrientationGTest.cxx delete mode 100644 Modules/Core/Common/test/itkDICOMOrientionGTest.cxx create mode 100644 Modules/Core/Common/wrapping/itkAnatomicalOrientation.wrap delete mode 100644 Modules/Core/Common/wrapping/itkDICOMOrientation.wrap diff --git a/Modules/Core/Common/include/itkDICOMOrientation.h b/Modules/Core/Common/include/itkAnatomicalOrientation.h similarity index 87% rename from Modules/Core/Common/include/itkDICOMOrientation.h rename to Modules/Core/Common/include/itkAnatomicalOrientation.h index 45895d72ba5b..2a17408ab557 100644 --- a/Modules/Core/Common/include/itkDICOMOrientation.h +++ b/Modules/Core/Common/include/itkAnatomicalOrientation.h @@ -15,8 +15,8 @@ * limitations under the License. * *=========================================================================*/ -#ifndef itkDICOMOrientation_h -#define itkDICOMOrientation_h +#ifndef itkAnatomicalOrientation_h +#define itkAnatomicalOrientation_h #include "ITKCommonExport.h" #include "itkImageBase.h" @@ -29,17 +29,18 @@ namespace itk { -/** \class DICOMOrientation - * \brief A supporting class for DICOMOrientImageFilter. +/** \class AnatomicalOrientation + * \brief A class to represent anatomical orientations and convert between conventions. * - * Defines enums to for patient orientation in a compatible way with DICOM. + * Defines patient specific anatomical names to the XYZ axes of a 3D image. * + * \todo update the details of the enum names in the docs * Instances hold the patient orientation enum and allow conversion to and from enums, string and direction cosine * matrices. Conversions from a direction cosine matrix is approximated with the orientation of the closes axes. * * \ingroup ITKCommon */ -class ITKCommon_EXPORT DICOMOrientation +class ITKCommon_EXPORT AnatomicalOrientation { public: static constexpr unsigned int Dimension = 3; @@ -53,18 +54,20 @@ class ITKCommon_EXPORT DICOMOrientation enum class CoordinateEnum : uint8_t { UNKNOWN = 0, - Left = 2, ///< 0b0010 - RightToLeft = 2, +#ifdef ITK_AMBIBUOUS_TO_COORDINATE_ENUMS + Left = 2, Right = 3, + Anterior = 4, + Posterior = 5, + Superior = 8, + Inferior = 9, +#endif + RightToLeft = 2, ///< 0b0010 LeftToRight = 3, - Anterior = 4, ///< front - 0b0100 - PosteriorToAnterior = 4, - Posterior = 5, ///< back - AnteriorToPosterior = 5, - Superior = 8, ///< above - 0b1000 - InferiorToSuperior = 8, - Inferior = 9, ///< bottom - SuperiorToInferior = 9, + PosteriorToAnterior = 4, ///< front - 0b0100 + AnteriorToPosterior = 5, ///< back + InferiorToSuperior = 8, ///< above - 0b1000 + SuperiorToInferior = 9, ///< bottom }; private: @@ -76,7 +79,7 @@ class ITKCommon_EXPORT DICOMOrientation }; template - static constexpr uint32_t m_ToOrientation = + static constexpr uint32_t m_OrientationValue = (static_cast(VPrimary) << static_cast(CoordinateMajornessTermsEnum::PrimaryMinor)) + (static_cast(VSecondary) << static_cast(CoordinateMajornessTermsEnum::SecondaryMinor)) + (static_cast(VTertiary) << static_cast(CoordinateMajornessTermsEnum::TertiaryMinor)); @@ -85,10 +88,10 @@ class ITKCommon_EXPORT DICOMOrientation GetCoordinateTerm(CoordinateMajornessTermsEnum cmt) const; public: -#define ITK_ORIENTATION_ENUM(P, S, T) m_ToOrientation +#define ITK_ORIENTATION_ENUM(P, S, T) m_OrientationValue - enum class OrientationEnum : uint32_t + enum class ToOrientationEnum : uint32_t { INVALID = 0, @@ -250,9 +253,9 @@ class ITKCommon_EXPORT DICOMOrientation * * If multiple CoordinateEnums are from the same axes then the Orientation value is INVALID. */ - DICOMOrientation(CoordinateEnum primary, CoordinateEnum secondary, CoordinateEnum tertiary); + AnatomicalOrientation(CoordinateEnum primary, CoordinateEnum secondary, CoordinateEnum tertiary); - DICOMOrientation(OrientationEnum orientation) + AnatomicalOrientation(ToOrientationEnum orientation) : m_Value(orientation) {} @@ -262,16 +265,16 @@ class ITKCommon_EXPORT DICOMOrientation * * @param legacyOrientation */ - DICOMOrientation(LegacyOrientationType legacyOrientation); + AnatomicalOrientation(LegacyOrientationType legacyOrientation); #endif - explicit DICOMOrientation(const DirectionType & d) + explicit AnatomicalOrientation(const DirectionType & d) : m_Value(DirectionCosinesToOrientation(d)) {} - explicit DICOMOrientation(std::string str); + explicit AnatomicalOrientation(std::string str); - operator OrientationEnum() const { return m_Value; } + operator ToOrientationEnum() const { return m_Value; } const std::string & GetAsString() const; @@ -282,7 +285,7 @@ class ITKCommon_EXPORT DICOMOrientation return OrientationToDirectionCosines(m_Value); } - OrientationEnum + ToOrientationEnum GetAsOrientation() const { return m_Value; @@ -315,45 +318,45 @@ class ITKCommon_EXPORT DICOMOrientation } /** \brief Return the closest orientation for a direction cosine matrix. */ - static OrientationEnum + static ToOrientationEnum DirectionCosinesToOrientation(const DirectionType & dir); /** \brief Return the direction cosine matrix for a orientation. */ - static DirectionType OrientationToDirectionCosines(OrientationEnum); + static DirectionType OrientationToDirectionCosines(ToOrientationEnum); friend ITKCommon_EXPORT std::ostream & - operator<<(std::ostream & out, OrientationEnum value); + operator<<(std::ostream & out, ToOrientationEnum value); private: // Private methods to create the maps, these will only be called once. - static std::map + static std::map CreateCodeToString(); - static std::map + static std::map CreateStringToCode(); /** \brief Return the global instance of the map from orientation enum to strings. * * The implementation uses a function static local variable so the global is created only if needed, only once. */ - static const std::map & + static const std::map & GetCodeToString(); /** \brief Return the global instance of the map from string to orientation enum. */ - static const std::map & + static const std::map & GetStringToCode(); - OrientationEnum m_Value; + ToOrientationEnum m_Value; }; ITKCommon_EXPORT std::ostream & - operator<<(std::ostream & out, typename DICOMOrientation::OrientationEnum value); + operator<<(std::ostream & out, typename AnatomicalOrientation::ToOrientationEnum value); ITKCommon_EXPORT std::ostream & - operator<<(std::ostream & out, const DICOMOrientation & orientation); + operator<<(std::ostream & out, const AnatomicalOrientation & orientation); } // end namespace itk diff --git a/Modules/Core/Common/src/CMakeLists.txt b/Modules/Core/Common/src/CMakeLists.txt index cbfb85d200ee..8c018b33814e 100644 --- a/Modules/Core/Common/src/CMakeLists.txt +++ b/Modules/Core/Common/src/CMakeLists.txt @@ -146,7 +146,7 @@ set(ITKCommon_SRCS itkObjectStore.cxx itkGaussianDerivativeOperator.cxx itkSpatialOrientation.cxx - itkDICOMOrientation.cxx + itkAnatomicalOrientation.cxx ) if(WIN32) diff --git a/Modules/Core/Common/src/itkAnatomicalOrientation.cxx b/Modules/Core/Common/src/itkAnatomicalOrientation.cxx new file mode 100644 index 000000000000..35a9e9aa2fb4 --- /dev/null +++ b/Modules/Core/Common/src/itkAnatomicalOrientation.cxx @@ -0,0 +1,291 @@ +/*========================================================================= + * + * 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 "itkAnatomicalOrientation.h" +#ifndef ITK_FUTURE_LEGACY_REMOVE +# include "itkSpatialOrientationAdapter.h" +#endif + +namespace itk +{ + + +AnatomicalOrientation::AnatomicalOrientation(CoordinateEnum primary, CoordinateEnum secondary, CoordinateEnum tertiary) +{ + if (SameOrientationAxes(primary, secondary) || SameOrientationAxes(primary, tertiary) || + SameOrientationAxes(secondary, tertiary)) + { + m_Value = ToOrientationEnum::INVALID; + } + else + { + m_Value = static_cast( + (static_cast(primary) << static_cast(CoordinateMajornessTermsEnum::PrimaryMinor)) + + (static_cast(secondary) << static_cast(CoordinateMajornessTermsEnum::SecondaryMinor)) + + (static_cast(tertiary) << static_cast(CoordinateMajornessTermsEnum::TertiaryMinor))); + } +} + +AnatomicalOrientation::AnatomicalOrientation(std::string str) + : m_Value(ToOrientationEnum::INVALID) +{ + std::transform(str.begin(), str.end(), str.begin(), ::toupper); + const std::map & stringToCode = GetStringToCode(); + auto iter = stringToCode.find(str); + if (iter != stringToCode.end()) + { + m_Value = iter->second; + } +} + + +#ifndef ITK_FUTURE_LEGACY_REMOVE +AnatomicalOrientation::AnatomicalOrientation(LegacyOrientationType legacyOrientation) + : AnatomicalOrientation(SpatialOrientationAdapter::ToDirectionCosines(legacyOrientation)) +{ + assert(uint32_t(legacyOrientation) == uint32_t(m_Value)); +} +#endif + + +const std::string & +AnatomicalOrientation::GetAsString() const +{ + const auto & codeToString = GetCodeToString(); + auto iter = codeToString.find(m_Value); + if (iter != codeToString.end()) + { + return iter->second; + } + assert(codeToString.find(ToOrientationEnum::INVALID) != codeToString.end()); + return codeToString.find(ToOrientationEnum::INVALID)->second; +} + + +AnatomicalOrientation::CoordinateEnum +AnatomicalOrientation::GetCoordinateTerm(CoordinateMajornessTermsEnum cmt) const +{ + return static_cast(static_cast(m_Value) >> static_cast(cmt) & 0xff); +} + +std::map +AnatomicalOrientation::CreateStringToCode() +{ + std::map stringToCode; + const std::map & codeToString = GetCodeToString(); + + for (const auto & kv : codeToString) + { + stringToCode[kv.second] = kv.first; + } + return stringToCode; +} + + +const std::map & +AnatomicalOrientation::GetCodeToString() +{ + static const std::map codeToString = CreateCodeToString(); + return codeToString; +} + +const std::map & +AnatomicalOrientation::GetStringToCode() +{ + static const std::map stringToCode = CreateStringToCode(); + return stringToCode; +} + + +std::map +AnatomicalOrientation::CreateCodeToString() +{ + std::map orientToString; + auto helperAddCode = [&orientToString](std::string str, ToOrientationEnum code) { + orientToString[code] = std::move(str); + }; + + // Map between axis string labels and SpatialOrientation + helperAddCode("RIP", ToOrientationEnum::RIP); + helperAddCode("LIP", ToOrientationEnum::LIP); + helperAddCode("RSP", ToOrientationEnum::RSP); + helperAddCode("LSP", ToOrientationEnum::LSP); + helperAddCode("RIA", ToOrientationEnum::RIA); + helperAddCode("LIA", ToOrientationEnum::LIA); + helperAddCode("RSA", ToOrientationEnum::RSA); + helperAddCode("LSA", ToOrientationEnum::LSA); + helperAddCode("IRP", ToOrientationEnum::IRP); + helperAddCode("ILP", ToOrientationEnum::ILP); + helperAddCode("SRP", ToOrientationEnum::SRP); + helperAddCode("SLP", ToOrientationEnum::SLP); + helperAddCode("IRA", ToOrientationEnum::IRA); + helperAddCode("ILA", ToOrientationEnum::ILA); + helperAddCode("SRA", ToOrientationEnum::SRA); + helperAddCode("SLA", ToOrientationEnum::SLA); + helperAddCode("RPI", ToOrientationEnum::RPI); + helperAddCode("LPI", ToOrientationEnum::LPI); + helperAddCode("RAI", ToOrientationEnum::RAI); + helperAddCode("LAI", ToOrientationEnum::LAI); + helperAddCode("RPS", ToOrientationEnum::RPS); + helperAddCode("LPS", ToOrientationEnum::LPS); + helperAddCode("RAS", ToOrientationEnum::RAS); + helperAddCode("LAS", ToOrientationEnum::LAS); + helperAddCode("PRI", ToOrientationEnum::PRI); + helperAddCode("PLI", ToOrientationEnum::PLI); + helperAddCode("ARI", ToOrientationEnum::ARI); + helperAddCode("ALI", ToOrientationEnum::ALI); + helperAddCode("PRS", ToOrientationEnum::PRS); + helperAddCode("PLS", ToOrientationEnum::PLS); + helperAddCode("ARS", ToOrientationEnum::ARS); + helperAddCode("ALS", ToOrientationEnum::ALS); + helperAddCode("IPR", ToOrientationEnum::IPR); + helperAddCode("SPR", ToOrientationEnum::SPR); + helperAddCode("IAR", ToOrientationEnum::IAR); + helperAddCode("SAR", ToOrientationEnum::SAR); + helperAddCode("IPL", ToOrientationEnum::IPL); + helperAddCode("SPL", ToOrientationEnum::SPL); + helperAddCode("IAL", ToOrientationEnum::IAL); + helperAddCode("SAL", ToOrientationEnum::SAL); + helperAddCode("PIR", ToOrientationEnum::PIR); + helperAddCode("PSR", ToOrientationEnum::PSR); + helperAddCode("AIR", ToOrientationEnum::AIR); + helperAddCode("ASR", ToOrientationEnum::ASR); + helperAddCode("PIL", ToOrientationEnum::PIL); + helperAddCode("PSL", ToOrientationEnum::PSL); + helperAddCode("AIL", ToOrientationEnum::AIL); + helperAddCode("ASL", ToOrientationEnum::ASL); + helperAddCode("INVALID", ToOrientationEnum::INVALID); + + return orientToString; +} + + +typename AnatomicalOrientation::ToOrientationEnum +AnatomicalOrientation::DirectionCosinesToOrientation(const DirectionType & dir) +{ + // NOTE: This method was based off of itk::SpatialObjectAdaptor::FromDirectionCosines + // but it is DIFFERENT in the meaning of direction in terms of sign-ness. + CoordinateEnum terms[3] = { CoordinateEnum::UNKNOWN, CoordinateEnum::UNKNOWN, CoordinateEnum::UNKNOWN }; + + std::multimap> value_to_idx; + for (unsigned int c = 0; c < 3; ++c) + { + for (unsigned int r = 0; r < 3; ++r) + { + value_to_idx.emplace(std::abs(dir[c][r]), std::make_pair(c, r)); + } + } + + for (unsigned i = 0; i < 3; ++i) + { + + auto max_idx = value_to_idx.rbegin()->second; + const unsigned int max_c = max_idx.first; + const unsigned int max_r = max_idx.second; + + const int max_sgn = Math::sgn(dir[max_c][max_r]); + + for (auto it = value_to_idx.begin(); it != value_to_idx.end();) + { + if (it->second.first == max_c || it->second.second == max_r) + { + value_to_idx.erase(it++); + } + else + { + ++it; + } + } + + switch (max_c) + { + case 0: + { + // When the dominant axis sign is positive, assign the coordinate for the direction we are increasing towards. + // ITK is in LPS, so that is the positive direction + terms[max_r] = (max_sgn == 1) ? CoordinateEnum::RightToLeft : CoordinateEnum::LeftToRight; + break; + } + case 1: + { + terms[max_r] = (max_sgn == 1) ? CoordinateEnum::AnteriorToPosterior : CoordinateEnum::PosteriorToAnterior; + break; + } + case 2: + { + terms[max_r] = (max_sgn == 1) ? CoordinateEnum::InferiorToSuperior : CoordinateEnum::SuperiorToInferior; + break; + } + default: + itkGenericExceptionMacro("Unexpected Axis"); + } + } + + return AnatomicalOrientation(terms[0], terms[1], terms[2]); +} + + +typename AnatomicalOrientation::DirectionType +AnatomicalOrientation::OrientationToDirectionCosines(ToOrientationEnum orientationEnum) +{ + const AnatomicalOrientation o(orientationEnum); + + CoordinateEnum terms[Dimension] = { o.GetPrimaryTerm(), o.GetSecondaryTerm(), o.GetTertiaryTerm() }; + DirectionType direction; + direction.Fill(0.0); + + for (unsigned int i = 0; i < Dimension; ++i) + { + const int sign = (static_cast(terms[i]) & 0x1) ? 1 : -1; + + switch (terms[i]) + { + case CoordinateEnum::LeftToRight: + case CoordinateEnum::RightToLeft: + direction[0][i] = -1 * sign; + break; + case CoordinateEnum::AnteriorToPosterior: + case CoordinateEnum::PosteriorToAnterior: + direction[1][i] = 1 * sign; + break; + case CoordinateEnum::InferiorToSuperior: + case CoordinateEnum::SuperiorToInferior: + direction[2][i] = -1 * sign; + break; + case CoordinateEnum::UNKNOWN: + break; + } + } + return direction; +} + +std::ostream & +operator<<(std::ostream & out, typename AnatomicalOrientation::ToOrientationEnum value) +{ + auto iter = AnatomicalOrientation::GetCodeToString().find(value); + assert(iter != AnatomicalOrientation::GetCodeToString().end()); + return (out << iter->second); +} + + +std::ostream & +operator<<(std::ostream & out, const AnatomicalOrientation & orientation) +{ + return (out << orientation.GetAsString()); +} + +} // namespace itk diff --git a/Modules/Core/Common/src/itkDICOMOrientation.cxx b/Modules/Core/Common/src/itkDICOMOrientation.cxx deleted file mode 100644 index 5f1cd1f67ee3..000000000000 --- a/Modules/Core/Common/src/itkDICOMOrientation.cxx +++ /dev/null @@ -1,289 +0,0 @@ -/*========================================================================= - * - * 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 "itkDICOMOrientation.h" -#ifndef ITK_FUTURE_LEGACY_REMOVE -# include "itkSpatialOrientationAdapter.h" -#endif - -namespace itk -{ - - -DICOMOrientation::DICOMOrientation(CoordinateEnum primary, CoordinateEnum secondary, CoordinateEnum tertiary) -{ - if (SameOrientationAxes(primary, secondary) || SameOrientationAxes(primary, tertiary) || - SameOrientationAxes(secondary, tertiary)) - { - m_Value = OrientationEnum::INVALID; - } - else - { - m_Value = static_cast( - (static_cast(primary) << static_cast(CoordinateMajornessTermsEnum::PrimaryMinor)) + - (static_cast(secondary) << static_cast(CoordinateMajornessTermsEnum::SecondaryMinor)) + - (static_cast(tertiary) << static_cast(CoordinateMajornessTermsEnum::TertiaryMinor))); - } -} - -DICOMOrientation::DICOMOrientation(std::string str) - : m_Value(OrientationEnum::INVALID) -{ - std::transform(str.begin(), str.end(), str.begin(), ::toupper); - const std::map & stringToCode = GetStringToCode(); - auto iter = stringToCode.find(str); - if (iter != stringToCode.end()) - { - m_Value = iter->second; - } -} - - -#ifndef ITK_FUTURE_LEGACY_REMOVE -DICOMOrientation::DICOMOrientation(LegacyOrientationType legacyOrientation) - : DICOMOrientation(SpatialOrientationAdapter::ToDirectionCosines(legacyOrientation)) -{} -#endif - - -const std::string & -DICOMOrientation::GetAsString() const -{ - const auto & codeToString = GetCodeToString(); - auto iter = codeToString.find(m_Value); - if (iter != codeToString.end()) - { - return iter->second; - } - assert(codeToString.find(OrientationEnum::INVALID) != codeToString.end()); - return codeToString.find(OrientationEnum::INVALID)->second; -} - - -DICOMOrientation::CoordinateEnum -DICOMOrientation::GetCoordinateTerm(CoordinateMajornessTermsEnum cmt) const -{ - return static_cast(static_cast(m_Value) >> static_cast(cmt) & 0xff); -} - -std::map -DICOMOrientation::CreateStringToCode() -{ - std::map stringToCode; - const std::map & codeToString = GetCodeToString(); - - for (const auto & kv : codeToString) - { - stringToCode[kv.second] = kv.first; - } - return stringToCode; -} - - -const std::map & -DICOMOrientation::GetCodeToString() -{ - static const std::map codeToString = CreateCodeToString(); - return codeToString; -} - -const std::map & -DICOMOrientation::GetStringToCode() -{ - static const std::map stringToCode = CreateStringToCode(); - return stringToCode; -} - - -std::map -DICOMOrientation::CreateCodeToString() -{ - std::map orientToString; - auto helperAddCode = [&orientToString](std::string str, OrientationEnum code) { - orientToString[code] = std::move(str); - }; - - // Map between axis string labels and SpatialOrientation - helperAddCode("RIP", OrientationEnum::RIP); - helperAddCode("LIP", OrientationEnum::LIP); - helperAddCode("RSP", OrientationEnum::RSP); - helperAddCode("LSP", OrientationEnum::LSP); - helperAddCode("RIA", OrientationEnum::RIA); - helperAddCode("LIA", OrientationEnum::LIA); - helperAddCode("RSA", OrientationEnum::RSA); - helperAddCode("LSA", OrientationEnum::LSA); - helperAddCode("IRP", OrientationEnum::IRP); - helperAddCode("ILP", OrientationEnum::ILP); - helperAddCode("SRP", OrientationEnum::SRP); - helperAddCode("SLP", OrientationEnum::SLP); - helperAddCode("IRA", OrientationEnum::IRA); - helperAddCode("ILA", OrientationEnum::ILA); - helperAddCode("SRA", OrientationEnum::SRA); - helperAddCode("SLA", OrientationEnum::SLA); - helperAddCode("RPI", OrientationEnum::RPI); - helperAddCode("LPI", OrientationEnum::LPI); - helperAddCode("RAI", OrientationEnum::RAI); - helperAddCode("LAI", OrientationEnum::LAI); - helperAddCode("RPS", OrientationEnum::RPS); - helperAddCode("LPS", OrientationEnum::LPS); - helperAddCode("RAS", OrientationEnum::RAS); - helperAddCode("LAS", OrientationEnum::LAS); - helperAddCode("PRI", OrientationEnum::PRI); - helperAddCode("PLI", OrientationEnum::PLI); - helperAddCode("ARI", OrientationEnum::ARI); - helperAddCode("ALI", OrientationEnum::ALI); - helperAddCode("PRS", OrientationEnum::PRS); - helperAddCode("PLS", OrientationEnum::PLS); - helperAddCode("ARS", OrientationEnum::ARS); - helperAddCode("ALS", OrientationEnum::ALS); - helperAddCode("IPR", OrientationEnum::IPR); - helperAddCode("SPR", OrientationEnum::SPR); - helperAddCode("IAR", OrientationEnum::IAR); - helperAddCode("SAR", OrientationEnum::SAR); - helperAddCode("IPL", OrientationEnum::IPL); - helperAddCode("SPL", OrientationEnum::SPL); - helperAddCode("IAL", OrientationEnum::IAL); - helperAddCode("SAL", OrientationEnum::SAL); - helperAddCode("PIR", OrientationEnum::PIR); - helperAddCode("PSR", OrientationEnum::PSR); - helperAddCode("AIR", OrientationEnum::AIR); - helperAddCode("ASR", OrientationEnum::ASR); - helperAddCode("PIL", OrientationEnum::PIL); - helperAddCode("PSL", OrientationEnum::PSL); - helperAddCode("AIL", OrientationEnum::AIL); - helperAddCode("ASL", OrientationEnum::ASL); - helperAddCode("INVALID", OrientationEnum::INVALID); - - return orientToString; -} - - -typename DICOMOrientation::OrientationEnum -DICOMOrientation::DirectionCosinesToOrientation(const DirectionType & dir) -{ - // NOTE: This method was based off of itk::SpatialObjectAdaptor::FromDirectionCosines - // but it is DIFFERENT in the meaning of direction in terms of sign-ness. - CoordinateEnum terms[3] = { CoordinateEnum::UNKNOWN, CoordinateEnum::UNKNOWN, CoordinateEnum::UNKNOWN }; - - std::multimap> value_to_idx; - for (unsigned int c = 0; c < 3; ++c) - { - for (unsigned int r = 0; r < 3; ++r) - { - value_to_idx.emplace(std::abs(dir[c][r]), std::make_pair(c, r)); - } - } - - for (unsigned i = 0; i < 3; ++i) - { - - auto max_idx = value_to_idx.rbegin()->second; - const unsigned int max_c = max_idx.first; - const unsigned int max_r = max_idx.second; - - const int max_sgn = Math::sgn(dir[max_c][max_r]); - - for (auto it = value_to_idx.begin(); it != value_to_idx.end();) - { - if (it->second.first == max_c || it->second.second == max_r) - { - value_to_idx.erase(it++); - } - else - { - ++it; - } - } - - switch (max_c) - { - case 0: - { - // When the dominant axis sign is positive, assign the coordinate for the direction we are increasing towards. - // ITK is in LPS, so that is the positive direction - terms[max_r] = (max_sgn == 1) ? CoordinateEnum::RightToLeft : CoordinateEnum::LeftToRight; - break; - } - case 1: - { - terms[max_r] = (max_sgn == 1) ? CoordinateEnum::AnteriorToPosterior : CoordinateEnum::PosteriorToAnterior; - break; - } - case 2: - { - terms[max_r] = (max_sgn == 1) ? CoordinateEnum::InferiorToSuperior : CoordinateEnum::SuperiorToInferior; - break; - } - default: - itkGenericExceptionMacro("Unexpected Axis"); - } - } - - return DICOMOrientation(terms[0], terms[1], terms[2]); -} - - -typename DICOMOrientation::DirectionType -DICOMOrientation::OrientationToDirectionCosines(OrientationEnum orientationEnum) -{ - const DICOMOrientation o(orientationEnum); - - CoordinateEnum terms[Dimension] = { o.GetPrimaryTerm(), o.GetSecondaryTerm(), o.GetTertiaryTerm() }; - DirectionType direction; - direction.Fill(0.0); - - for (unsigned int i = 0; i < Dimension; ++i) - { - const int sign = (static_cast(terms[i]) & 0x1) ? 1 : -1; - - switch (terms[i]) - { - case CoordinateEnum::LeftToRight: - case CoordinateEnum::RightToLeft: - direction[0][i] = -1 * sign; - break; - case CoordinateEnum::AnteriorToPosterior: - case CoordinateEnum::PosteriorToAnterior: - direction[1][i] = 1 * sign; - break; - case CoordinateEnum::InferiorToSuperior: - case CoordinateEnum::SuperiorToInferior: - direction[2][i] = -1 * sign; - break; - case CoordinateEnum::UNKNOWN: - break; - } - } - return direction; -} - -std::ostream & -operator<<(std::ostream & out, typename DICOMOrientation::OrientationEnum value) -{ - auto iter = DICOMOrientation::GetCodeToString().find(value); - assert(iter != DICOMOrientation::GetCodeToString().end()); - return (out << iter->second); -} - - -std::ostream & -operator<<(std::ostream & out, const DICOMOrientation & orientation) -{ - return (out << orientation.GetAsString()); -} - -} // namespace itk diff --git a/Modules/Core/Common/test/CMakeLists.txt b/Modules/Core/Common/test/CMakeLists.txt index b974c4eaeab9..4a7592884304 100644 --- a/Modules/Core/Common/test/CMakeLists.txt +++ b/Modules/Core/Common/test/CMakeLists.txt @@ -1759,7 +1759,7 @@ set(ITKCommonGTests itkCommonTypeTraitsGTest.cxx itkMetaDataDictionaryGTest.cxx itkSpatialOrientationAdaptorGTest.cxx - itkDICOMOrientionGTest.cxx + itkAnatomicalOrientationGTest.cxx ) creategoogletestdriver(ITKCommon "${ITKCommon-Test_LIBRARIES}" "${ITKCommonGTests}") # If `-static` was passed to CMAKE_EXE_LINKER_FLAGS, compilation fails. No need to diff --git a/Modules/Core/Common/test/itkAnatomicalOrientationGTest.cxx b/Modules/Core/Common/test/itkAnatomicalOrientationGTest.cxx new file mode 100644 index 000000000000..5c311e1a6b82 --- /dev/null +++ b/Modules/Core/Common/test/itkAnatomicalOrientationGTest.cxx @@ -0,0 +1,226 @@ +/*========================================================================= + * + * 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 + +#include "itkGTest.h" +#include "itkAnatomicalOrientation.h" +#include "itkImage.h" +#include + + +TEST(AnatomicalOrientation, ConstructionAndValues) +{ + using itk::AnatomicalOrientation; + using OE = AnatomicalOrientation::ToOrientationEnum; + using CE = AnatomicalOrientation::CoordinateEnum; + using ImageType = itk::Image; + + ImageType::DirectionType d; + + AnatomicalOrientation do1(OE::LPS); + + EXPECT_EQ("LPS", do1.GetAsString()); + EXPECT_EQ(CE::RightToLeft, do1.GetPrimaryTerm()); + EXPECT_EQ(CE::AnteriorToPosterior, do1.GetSecondaryTerm()); + EXPECT_EQ(CE::InferiorToSuperior, do1.GetTertiaryTerm()); + EXPECT_EQ(OE::LPS, do1.GetAsOrientation()); + + d.SetIdentity(); + EXPECT_EQ(d, do1.GetAsDirection()); + + + do1 = AnatomicalOrientation("RAS"); + + EXPECT_EQ("RAS", do1.GetAsString()); + EXPECT_EQ(CE::LeftToRight, do1.GetPrimaryTerm()); + EXPECT_EQ(CE::PosteriorToAnterior, do1.GetSecondaryTerm()); + EXPECT_EQ(CE::InferiorToSuperior, do1.GetTertiaryTerm()); + EXPECT_EQ(OE::RAS, do1.GetAsOrientation()); + + d.Fill(0.0); + d(0, 0) = -1.0; + d(1, 1) = -1.0; + d(2, 2) = 1.0; + EXPECT_EQ(d, do1.GetAsDirection()); + + + do1 = AnatomicalOrientation("rai"); + + EXPECT_EQ("RAI", do1.GetAsString()); + EXPECT_EQ(CE::LeftToRight, do1.GetPrimaryTerm()); + EXPECT_EQ(CE::PosteriorToAnterior, do1.GetSecondaryTerm()); + EXPECT_EQ(CE::SuperiorToInferior, do1.GetTertiaryTerm()); + EXPECT_EQ(OE::RAI, do1.GetAsOrientation()); + + + do1 = AnatomicalOrientation(OE::PIR); + + EXPECT_EQ("PIR", do1.GetAsString()); + EXPECT_EQ(CE::AnteriorToPosterior, do1.GetPrimaryTerm()); + EXPECT_EQ(CE::SuperiorToInferior, do1.GetSecondaryTerm()); + EXPECT_EQ(CE::LeftToRight, do1.GetTertiaryTerm()); + EXPECT_EQ(OE::PIR, do1.GetAsOrientation()); + + d.Fill(0.0); + d(1, 0) = 1.0; + d(2, 1) = -1.0; + d(0, 2) = -1.0; + EXPECT_EQ(d, do1.GetAsDirection()); + + AnatomicalOrientation do2(d); + + EXPECT_EQ("PIR", do2.GetAsString()); + EXPECT_EQ(CE::AnteriorToPosterior, do2.GetPrimaryTerm()); + EXPECT_EQ(CE::SuperiorToInferior, do2.GetSecondaryTerm()); + EXPECT_EQ(CE::LeftToRight, do2.GetTertiaryTerm()); + EXPECT_EQ(OE::PIR, do2.GetAsOrientation()); + + EXPECT_EQ(d, do2.GetAsDirection()); + + AnatomicalOrientation do3("something invalid"); + EXPECT_EQ("INVALID", do3.GetAsString()); + EXPECT_EQ(CE::UNKNOWN, do3.GetPrimaryTerm()); + EXPECT_EQ(CE::UNKNOWN, do3.GetSecondaryTerm()); + EXPECT_EQ(CE::UNKNOWN, do3.GetTertiaryTerm()); + EXPECT_EQ(OE::INVALID, do3.GetAsOrientation()); +} + + +TEST(AnatomicalOrientation, DirectionCosinesToOrientation) +{ + using itk::AnatomicalOrientation; + using OE = AnatomicalOrientation::ToOrientationEnum; + using ImageType = itk::Image; + ImageType::DirectionType d; + d.SetIdentity(); + + EXPECT_EQ(OE::LPS, AnatomicalOrientation::DirectionCosinesToOrientation(d)); + + d.Fill(0.0); + d(0, 0) = -1.0; + d(1, 1) = -1.0; + d(2, 2) = -1.0; + EXPECT_EQ(OE::RAI, AnatomicalOrientation::DirectionCosinesToOrientation(d)); + + d.Fill(0.0); + d(2, 0) = 1; + d(0, 1) = 1; + d(1, 2) = 1; + EXPECT_EQ(OE::SLP, AnatomicalOrientation::DirectionCosinesToOrientation(d)); + + d.Fill(0.0); + d(1, 0) = 1; + d(2, 1) = 1; + d(0, 2) = 1; + EXPECT_EQ(OE::PSL, AnatomicalOrientation::DirectionCosinesToOrientation(d)); + + d.Fill(0.0); + d(0, 0) = 1; + d(2, 1) = 1; + d(1, 2) = 1; + EXPECT_EQ(OE::LSP, AnatomicalOrientation::DirectionCosinesToOrientation(d)); + + d.Fill(0.0); + d(1, 0) = 1; + d(0, 1) = 1; + d(2, 2) = 1; + EXPECT_EQ(OE::PLS, AnatomicalOrientation::DirectionCosinesToOrientation(d)); + + d.Fill(0.0); + d(2, 0) = 1; + d(1, 1) = 1; + d(0, 2) = 1; + EXPECT_EQ(OE::SPL, AnatomicalOrientation::DirectionCosinesToOrientation(d)); + + const double data[] = { 0.5986634407395047, 0.22716302314740483, -0.768113953548866, + 0.5627936241740271, 0.563067040943212, 0.6051601804419384, + 0.5699696670095713, -0.794576911518317, 0.20924175102261847 }; + ImageType::DirectionType::InternalMatrixType m{ data }; + d.GetVnlMatrix() = m; + EXPECT_EQ(OE::PIR, AnatomicalOrientation::DirectionCosinesToOrientation(d)); +} + +TEST(AnatomicalOrientation, OrientationToDirectionCosines) +{ + using itk::AnatomicalOrientation; + using ImageType = itk::Image; + using OE = AnatomicalOrientation::ToOrientationEnum; + + ImageType::DirectionType d; + d.SetIdentity(); + + EXPECT_EQ(d, AnatomicalOrientation::OrientationToDirectionCosines(OE::LPS)); + + d.Fill(0.0); + d(0, 0) = -1.0; + d(1, 1) = -1.0; + d(2, 2) = -1.0; + EXPECT_EQ(d, AnatomicalOrientation::OrientationToDirectionCosines(OE::RAI)); + + d.Fill(0.0); + d(2, 0) = 1; + d(0, 1) = 1; + d(1, 2) = 1; + EXPECT_EQ(d, AnatomicalOrientation::OrientationToDirectionCosines(OE::SLP)); + + d.Fill(0.0); + d(1, 0) = 1; + d(2, 1) = 1; + d(0, 2) = 1; + EXPECT_EQ(d, AnatomicalOrientation::OrientationToDirectionCosines(OE::PSL)); + + d.Fill(0.0); + d(0, 0) = 1; + d(2, 1) = 1; + d(1, 2) = 1; + EXPECT_EQ(d, AnatomicalOrientation::OrientationToDirectionCosines(OE::LSP)); + + d.Fill(0.0); + d(1, 0) = 1; + d(0, 1) = 1; + d(2, 2) = 1; + EXPECT_EQ(d, AnatomicalOrientation::OrientationToDirectionCosines(OE::PLS)); + + d.Fill(0.0); + d(2, 0) = 1; + d(1, 1) = 1; + d(0, 2) = 1; + EXPECT_EQ(d, AnatomicalOrientation::OrientationToDirectionCosines(OE::SPL)); +} + +#ifndef ITK_FUTURE_LEGACY_REMOVE +# include "itkSpatialOrientation.h" +TEST(AnatomicalOrientation, LegacyInteroperability) +{ + + using OE = itk::AnatomicalOrientation::ToOrientationEnum; + using SOE = itk::SpatialOrientationEnums::ValidCoordinateOrientations; + + // byte for byte compatibility, may assist with migration of bindings when types are not strictly enforced. + static_assert(int(SOE::ITK_COORDINATE_ORIENTATION_RAI) == int(OE::LPS)); + static_assert(int(SOE::ITK_COORDINATE_ORIENTATION_LPS) == int(OE::RAI)); + static_assert(int(SOE::ITK_COORDINATE_ORIENTATION_RSA) == int(OE::LIP)); + static_assert(int(SOE::ITK_COORDINATE_ORIENTATION_ASL) == int(OE::PIR)); + + itk::AnatomicalOrientation itk_rai(SOE::ITK_COORDINATE_ORIENTATION_RAI); + EXPECT_EQ(itk_rai, OE::LPS); + EXPECT_EQ(itk_rai.GetAsOrientation(), OE::LPS); + EXPECT_EQ(itk_rai.GetAsString(), "LPS"); +} +#endif diff --git a/Modules/Core/Common/test/itkDICOMOrientionGTest.cxx b/Modules/Core/Common/test/itkDICOMOrientionGTest.cxx deleted file mode 100644 index 9fcfe2f2102f..000000000000 --- a/Modules/Core/Common/test/itkDICOMOrientionGTest.cxx +++ /dev/null @@ -1,228 +0,0 @@ -/*========================================================================= - * - * 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 - -#include "itkGTest.h" -#include "itkDICOMOrientation.h" -#include "itkImage.h" -#include - - -TEST(DICOMOrientation, ConstructionAndValues) -{ - using itk::DICOMOrientation; - using OE = DICOMOrientation::OrientationEnum; - using CE = DICOMOrientation::CoordinateEnum; - using ImageType = itk::Image; - - ImageType::DirectionType d; - - DICOMOrientation do1(OE::LPS); - - EXPECT_EQ("LPS", do1.GetAsString()); - EXPECT_EQ(CE::Left, do1.GetPrimaryTerm()); - EXPECT_EQ(CE::Posterior, do1.GetSecondaryTerm()); - EXPECT_EQ(CE::Superior, do1.GetTertiaryTerm()); - EXPECT_EQ(OE::LPS, do1.GetAsOrientation()); - - d.SetIdentity(); - EXPECT_EQ(d, do1.GetAsDirection()); - - - do1 = DICOMOrientation("RAS"); - - EXPECT_EQ("RAS", do1.GetAsString()); - EXPECT_EQ(CE::Right, do1.GetPrimaryTerm()); - EXPECT_EQ(CE::Anterior, do1.GetSecondaryTerm()); - EXPECT_EQ(CE::Superior, do1.GetTertiaryTerm()); - EXPECT_EQ(OE::RAS, do1.GetAsOrientation()); - - d.Fill(0.0); - d(0, 0) = -1.0; - d(1, 1) = -1.0; - d(2, 2) = 1.0; - EXPECT_EQ(d, do1.GetAsDirection()); - - - do1 = DICOMOrientation("rai"); - - EXPECT_EQ("RAI", do1.GetAsString()); - EXPECT_EQ(CE::Right, do1.GetPrimaryTerm()); - EXPECT_EQ(CE::Anterior, do1.GetSecondaryTerm()); - EXPECT_EQ(CE::Inferior, do1.GetTertiaryTerm()); - EXPECT_EQ(OE::RAI, do1.GetAsOrientation()); - - - do1 = DICOMOrientation(OE::PIR); - - EXPECT_EQ("PIR", do1.GetAsString()); - EXPECT_EQ(CE::Posterior, do1.GetPrimaryTerm()); - EXPECT_EQ(CE::Inferior, do1.GetSecondaryTerm()); - EXPECT_EQ(CE::Right, do1.GetTertiaryTerm()); - EXPECT_EQ(OE::PIR, do1.GetAsOrientation()); - - d.Fill(0.0); - d(1, 0) = 1.0; - d(2, 1) = -1.0; - d(0, 2) = -1.0; - EXPECT_EQ(d, do1.GetAsDirection()); - - DICOMOrientation do2(d); - - EXPECT_EQ("PIR", do2.GetAsString()); - EXPECT_EQ(CE::Posterior, do2.GetPrimaryTerm()); - EXPECT_EQ(CE::Inferior, do2.GetSecondaryTerm()); - EXPECT_EQ(CE::Right, do2.GetTertiaryTerm()); - EXPECT_EQ(OE::PIR, do2.GetAsOrientation()); - - EXPECT_EQ(d, do2.GetAsDirection()); - - DICOMOrientation do3("something invalid"); - EXPECT_EQ("INVALID", do3.GetAsString()); - EXPECT_EQ(CE::UNKNOWN, do3.GetPrimaryTerm()); - EXPECT_EQ(CE::UNKNOWN, do3.GetSecondaryTerm()); - EXPECT_EQ(CE::UNKNOWN, do3.GetTertiaryTerm()); - EXPECT_EQ(OE::INVALID, do3.GetAsOrientation()); -} - - -TEST(DICOMOrientation, DirectionCosinesToOrientation) -{ - using itk::DICOMOrientation; - using OE = DICOMOrientation::OrientationEnum; - using ImageType = itk::Image; - ImageType::DirectionType d; - d.SetIdentity(); - - EXPECT_EQ(OE::LPS, DICOMOrientation::DirectionCosinesToOrientation(d)); - - d.Fill(0.0); - d(0, 0) = -1.0; - d(1, 1) = -1.0; - d(2, 2) = -1.0; - EXPECT_EQ(OE::RAI, DICOMOrientation::DirectionCosinesToOrientation(d)); - - d.Fill(0.0); - d(2, 0) = 1; - d(0, 1) = 1; - d(1, 2) = 1; - EXPECT_EQ(OE::SLP, DICOMOrientation::DirectionCosinesToOrientation(d)); - - d.Fill(0.0); - d(1, 0) = 1; - d(2, 1) = 1; - d(0, 2) = 1; - EXPECT_EQ(OE::PSL, DICOMOrientation::DirectionCosinesToOrientation(d)); - - d.Fill(0.0); - d(0, 0) = 1; - d(2, 1) = 1; - d(1, 2) = 1; - EXPECT_EQ(OE::LSP, DICOMOrientation::DirectionCosinesToOrientation(d)); - - d.Fill(0.0); - d(1, 0) = 1; - d(0, 1) = 1; - d(2, 2) = 1; - EXPECT_EQ(OE::PLS, DICOMOrientation::DirectionCosinesToOrientation(d)); - - d.Fill(0.0); - d(2, 0) = 1; - d(1, 1) = 1; - d(0, 2) = 1; - EXPECT_EQ(OE::SPL, DICOMOrientation::DirectionCosinesToOrientation(d)); - - const double data[] = {0.5986634407395047, 0.22716302314740483, -0.768113953548866, - 0.5627936241740271, 0.563067040943212, 0.6051601804419384, - 0.5699696670095713, -0.794576911518317, 0.20924175102261847}; - ImageType::DirectionType::InternalMatrixType m{data}; - d.GetVnlMatrix() = m; - EXPECT_EQ(OE::PIR, DICOMOrientation::DirectionCosinesToOrientation(d)); - -} - -TEST(DICOMOrientation, OrientationToDirectionCosines) -{ - using itk::DICOMOrientation; - using ImageType = itk::Image; - using OE = DICOMOrientation::OrientationEnum; - - ImageType::DirectionType d; - d.SetIdentity(); - - EXPECT_EQ(d, DICOMOrientation::OrientationToDirectionCosines(OE::LPS)); - - d.Fill(0.0); - d(0, 0) = -1.0; - d(1, 1) = -1.0; - d(2, 2) = -1.0; - EXPECT_EQ(d, DICOMOrientation::OrientationToDirectionCosines(OE::RAI)); - - d.Fill(0.0); - d(2, 0) = 1; - d(0, 1) = 1; - d(1, 2) = 1; - EXPECT_EQ(d, DICOMOrientation::OrientationToDirectionCosines(OE::SLP)); - - d.Fill(0.0); - d(1, 0) = 1; - d(2, 1) = 1; - d(0, 2) = 1; - EXPECT_EQ(d, DICOMOrientation::OrientationToDirectionCosines(OE::PSL)); - - d.Fill(0.0); - d(0, 0) = 1; - d(2, 1) = 1; - d(1, 2) = 1; - EXPECT_EQ(d, DICOMOrientation::OrientationToDirectionCosines(OE::LSP)); - - d.Fill(0.0); - d(1, 0) = 1; - d(0, 1) = 1; - d(2, 2) = 1; - EXPECT_EQ(d, DICOMOrientation::OrientationToDirectionCosines(OE::PLS)); - - d.Fill(0.0); - d(2, 0) = 1; - d(1, 1) = 1; - d(0, 2) = 1; - EXPECT_EQ(d, DICOMOrientation::OrientationToDirectionCosines(OE::SPL)); -} - -#ifndef ITK_FUTURE_LEGACY_REMOVE -#include "itkSpatialOrientation.h" -TEST(DICOMOrientation, LegacyInteroperability) -{ - - using OE = itk::DICOMOrientation::OrientationEnum; - using SOE = itk::SpatialOrientationEnums::ValidCoordinateOrientations; - - // byte for byte compatibility, may assist with migration of bindings when types are not strictly enforced. - static_assert( int(SOE::ITK_COORDINATE_ORIENTATION_RAI) == int(OE::LPS) ); - static_assert( int(SOE::ITK_COORDINATE_ORIENTATION_LPS) == int(OE::RAI) ); - static_assert( int(SOE::ITK_COORDINATE_ORIENTATION_RSA) == int(OE::LIP) ); - static_assert( int(SOE::ITK_COORDINATE_ORIENTATION_ASL) == int(OE::PIR) ); - - itk::DICOMOrientation itk_rai(SOE::ITK_COORDINATE_ORIENTATION_RAI); - EXPECT_EQ( itk_rai, OE::LPS); - EXPECT_EQ( itk_rai.GetAsOrientation(), OE::LPS); - EXPECT_EQ( itk_rai.GetAsString(), "LPS"); - -} -#endif diff --git a/Modules/Core/Common/wrapping/itkAnatomicalOrientation.wrap b/Modules/Core/Common/wrapping/itkAnatomicalOrientation.wrap new file mode 100644 index 000000000000..9d81865c78e3 --- /dev/null +++ b/Modules/Core/Common/wrapping/itkAnatomicalOrientation.wrap @@ -0,0 +1 @@ +itk_wrap_simple_class("itk::AnatomicalOrientation") diff --git a/Modules/Core/Common/wrapping/itkDICOMOrientation.wrap b/Modules/Core/Common/wrapping/itkDICOMOrientation.wrap deleted file mode 100644 index 88df9faaa6fb..000000000000 --- a/Modules/Core/Common/wrapping/itkDICOMOrientation.wrap +++ /dev/null @@ -1 +0,0 @@ -itk_wrap_simple_class("itk::DICOMOrientation") diff --git a/Modules/IO/GE/src/itkGE4ImageIO.cxx b/Modules/IO/GE/src/itkGE4ImageIO.cxx index dc3ae233a29c..d979055dd8e7 100644 --- a/Modules/IO/GE/src/itkGE4ImageIO.cxx +++ b/Modules/IO/GE/src/itkGE4ImageIO.cxx @@ -144,27 +144,27 @@ GE4ImageIO::ReadHeader(const char * FileNameToRead) if (strstr(tmpStr, "CORONAL") != nullptr) { - hdr->coordinateOrientation = DICOMOrientation(DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::SuperiorToInferior, - DICOMOrientation::CoordinateEnum::PosteriorToAnterior); + hdr->coordinateOrientation = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::SuperiorToInferior, + AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior); } else if (strstr(tmpStr, "SAGITTAL") != nullptr) { - hdr->coordinateOrientation = DICOMOrientation( DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - DICOMOrientation::CoordinateEnum::InferiorToSuperior, - DICOMOrientation::CoordinateEnum::RightToLeft); + hdr->coordinateOrientation = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + AnatomicalOrientation::CoordinateEnum::InferiorToSuperior, + AnatomicalOrientation::CoordinateEnum::RightToLeft); } else if (strstr(tmpStr, "AXIAL") != nullptr) { - hdr->coordinateOrientation = DICOMOrientation( DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - DICOMOrientation::CoordinateEnum::InferiorToSuperior); + hdr->coordinateOrientation = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + AnatomicalOrientation::CoordinateEnum::InferiorToSuperior); } else { - hdr->coordinateOrientation = DICOMOrientation( DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::SuperiorToInferior, - DICOMOrientation::CoordinateEnum::PosteriorToAnterior); + hdr->coordinateOrientation = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::SuperiorToInferior, + AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior); } /* Get the Scan Matrix from the IMAGE Header */ diff --git a/Modules/IO/GE/src/itkGE5ImageIO.cxx b/Modules/IO/GE/src/itkGE5ImageIO.cxx index f721a7b3be5d..9adf26de2ea0 100644 --- a/Modules/IO/GE/src/itkGE5ImageIO.cxx +++ b/Modules/IO/GE/src/itkGE5ImageIO.cxx @@ -362,24 +362,28 @@ GE5ImageIO::ReadHeader(const char * FileNameToRead) switch (GE_Plane) { case GE_CORONAL: - curImage->coordinateOrientation = DICOMOrientation( DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::SuperiorToInferior, - DICOMOrientation::CoordinateEnum::PosteriorToAnterior); + curImage->coordinateOrientation = + AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::SuperiorToInferior, + AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior); break; case GE_SAGITTAL: - curImage->coordinateOrientation = DICOMOrientation( DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - DICOMOrientation::CoordinateEnum::InferiorToSuperior, - DICOMOrientation::CoordinateEnum::RightToLeft); + curImage->coordinateOrientation = + AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + AnatomicalOrientation::CoordinateEnum::InferiorToSuperior, + AnatomicalOrientation::CoordinateEnum::RightToLeft); break; case GE_AXIAL: - curImage->coordinateOrientation = DICOMOrientation( DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - DICOMOrientation::CoordinateEnum::InferiorToSuperior); + curImage->coordinateOrientation = + AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + AnatomicalOrientation::CoordinateEnum::InferiorToSuperior); break; default: - curImage->coordinateOrientation = DICOMOrientation( DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::SuperiorToInferior, - DICOMOrientation::CoordinateEnum::PosteriorToAnterior); + curImage->coordinateOrientation = + AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::SuperiorToInferior, + AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior); break; } diff --git a/Modules/IO/GE/src/itkGEAdwImageIO.cxx b/Modules/IO/GE/src/itkGEAdwImageIO.cxx index 7b10816bf82a..75cf01124b8c 100644 --- a/Modules/IO/GE/src/itkGEAdwImageIO.cxx +++ b/Modules/IO/GE/src/itkGEAdwImageIO.cxx @@ -161,24 +161,24 @@ GEAdwImageIO::ReadHeader(const char * FileNameToRead) switch (tmpShort) { case GE_CORONAL: - hdr->coordinateOrientation = DICOMOrientation(DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::SuperiorToInferior, - DICOMOrientation::CoordinateEnum::PosteriorToAnterior); + hdr->coordinateOrientation = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::SuperiorToInferior, + AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior); break; case GE_SAGITTAL: - hdr->coordinateOrientation = DICOMOrientation(DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - DICOMOrientation::CoordinateEnum::InferiorToSuperior, - DICOMOrientation::CoordinateEnum::RightToLeft); + hdr->coordinateOrientation = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + AnatomicalOrientation::CoordinateEnum::InferiorToSuperior, + AnatomicalOrientation::CoordinateEnum::RightToLeft); break; case GE_AXIAL: - hdr->coordinateOrientation = DICOMOrientation( DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - DICOMOrientation::CoordinateEnum::InferiorToSuperior); + hdr->coordinateOrientation = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + AnatomicalOrientation::CoordinateEnum::InferiorToSuperior); break; default: - hdr->coordinateOrientation = DICOMOrientation( DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::SuperiorToInferior, - DICOMOrientation::CoordinateEnum::PosteriorToAnterior); + hdr->coordinateOrientation = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::SuperiorToInferior, + AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior); break; } this->GetFloatAt(f, GE_ADW_IM_LOC, &(hdr->sliceLocation)); diff --git a/Modules/IO/IPL/include/itkGEImageHeader.h b/Modules/IO/IPL/include/itkGEImageHeader.h index d63d8671faab..dcfbec0d14ce 100644 --- a/Modules/IO/IPL/include/itkGEImageHeader.h +++ b/Modules/IO/IPL/include/itkGEImageHeader.h @@ -30,7 +30,7 @@ #include "ITKIOIPLExport.h" #include "itkIOCommon.h" -#include "itkDICOMOrientation.h" +#include "itkAnatomicalOrientation.h" enum GE_PANE_STRUCT { @@ -73,27 +73,29 @@ struct GEImageHeader float brhcA; float brhcS; - short acqXsize; - short acqYsize; - short frequencyDir; - char scanner[16]; - char pulseSequence[128]; // Needs to be at least 65 for seimens vision - char patientId[32]; - char scanId[32]; - char name[64]; - char date[32]; - short imageXsize; - short imageYsize; - float imageXres; - float imageYres; - itk::DICOMOrientation::OrientationEnum coordinateOrientation; // uint32_t - short numberOfSlices; - short offset; - char filename[itk::IOCommon::ITK_MAXPATHLEN + 1]; - char hospital[35]; - char modality[4]; - short imagesPerSlice; - short turboFactor; // This is only relevant for the geADW image format, but - // is put here for convenience + short acqXsize; + short acqYsize; + short frequencyDir; + char scanner[16]; + char pulseSequence[128]; // Needs to be at least 65 for seimens vision + char patientId[32]; + char scanId[32]; + char name[64]; + char date[32]; + short imageXsize; + short imageYsize; + float imageXres; + float imageYres; + + itk::AnatomicalOrientation::ToOrientationEnum coordinateOrientation; // uint32_t + + short numberOfSlices; + short offset; + char filename[itk::IOCommon::ITK_MAXPATHLEN + 1]; + char hospital[35]; + char modality[4]; + short imagesPerSlice; + short turboFactor; // This is only relevant for the geADW image format, but + // is put here for convenience }; #endif diff --git a/Modules/IO/IPL/src/itkIPLCommonImageIO.cxx b/Modules/IO/IPL/src/itkIPLCommonImageIO.cxx index 7486787acc46..fdecc38f956f 100644 --- a/Modules/IO/IPL/src/itkIPLCommonImageIO.cxx +++ b/Modules/IO/IPL/src/itkIPLCommonImageIO.cxx @@ -19,7 +19,7 @@ #include "itksys/SystemTools.hxx" #include "itkIPLCommonImageIO.h" #include "itkByteSwapper.h" -#include "itkDICOMOrientation.h" +#include "itkAnatomicalOrientation.h" #include "itkDirectory.h" #include "itkMetaDataObject.h" #include @@ -256,7 +256,8 @@ IPLCommonImageIO::ReadImageInformation() // // set direction cosines - DICOMOrientation::DirectionType dir = DICOMOrientation(m_ImageHeader->coordinateOrientation).GetAsDirection(); + AnatomicalOrientation::DirectionType dir = + AnatomicalOrientation(m_ImageHeader->coordinateOrientation).GetAsDirection(); std::vector dirx(3, 0), diry(3, 0), dirz(3, 0); dirx[0] = dir[0][0]; dirx[1] = dir[1][0]; diff --git a/Modules/IO/ImageBase/test/itkReadWriteImageWithDictionaryTest.cxx b/Modules/IO/ImageBase/test/itkReadWriteImageWithDictionaryTest.cxx index 484f3c0afb0a..1fb9369e4093 100644 --- a/Modules/IO/ImageBase/test/itkReadWriteImageWithDictionaryTest.cxx +++ b/Modules/IO/ImageBase/test/itkReadWriteImageWithDictionaryTest.cxx @@ -19,7 +19,7 @@ #include "itkImageFileWriter.h" #include "itkIOCommon.h" #include "itkMetaDataObject.h" -#include "itkDICOMOrientation.h" +#include "itkAnatomicalOrientation.h" #include "itkTestingMacros.h" int @@ -47,7 +47,7 @@ itkReadWriteImageWithDictionaryTest(int argc, char * argv[]) inputImage->Allocate(); inputImage->FillBuffer(0); - inputImage->SetDirection(itk::DICOMOrientation("LSA").GetAsDirection()); + inputImage->SetDirection(itk::AnatomicalOrientation("LSA").GetAsDirection()); // Add some metadata in the dictionary itk::MetaDataDictionary & inputDictionary = inputImage->GetMetaDataDictionary(); diff --git a/Modules/IO/Meta/src/itkMetaImageIO.cxx b/Modules/IO/Meta/src/itkMetaImageIO.cxx index 51e01bf931b6..03caa8dc8be2 100644 --- a/Modules/IO/Meta/src/itkMetaImageIO.cxx +++ b/Modules/IO/Meta/src/itkMetaImageIO.cxx @@ -17,7 +17,7 @@ *=========================================================================*/ #include "itkMetaImageIO.h" -#include "itkDICOMOrientation.h" +#include "itkAnatomicalOrientation.h" #include "itkIOCommon.h" #include "itksys/SystemTools.hxx" #include "itkMath.h" @@ -808,8 +808,8 @@ MetaImageIO::Write(const void * buffer) if (numberOfDimensions == 3) { - std::vector dirx, diry, dirz; - DICOMOrientation::DirectionType dir; + std::vector dirx, diry, dirz; + AnatomicalOrientation::DirectionType dir; dirx = this->GetDirection(0); diry = this->GetDirection(1); dirz = this->GetDirection(2); @@ -819,24 +819,22 @@ MetaImageIO::Write(const void * buffer) dir[ii][1] = diry[ii]; dir[ii][2] = dirz[ii]; } - DICOMOrientation coordOrient(dir); + AnatomicalOrientation coordOrient(dir); // Mapping from DICOM CoordinateEnum defined as the increasing direction to // the MetaIO enum which has from/to orientation defined. - const std::map axisToMetOrientation - { - { DICOMOrientation::CoordinateEnum::RightToLeft, MET_ORIENTATION_RL }, - { DICOMOrientation::CoordinateEnum::LeftToRight, MET_ORIENTATION_LR }, - { DICOMOrientation::CoordinateEnum::AnteriorToPosterior, MET_ORIENTATION_AP }, - { DICOMOrientation::CoordinateEnum::PosteriorToAnterior, MET_ORIENTATION_PA }, - { DICOMOrientation::CoordinateEnum::InferiorToSuperior, MET_ORIENTATION_IS }, - { DICOMOrientation::CoordinateEnum::SuperiorToInferior, MET_ORIENTATION_SI } - }; + const std::map axisToMetOrientation{ + { AnatomicalOrientation::CoordinateEnum::RightToLeft, MET_ORIENTATION_RL }, + { AnatomicalOrientation::CoordinateEnum::LeftToRight, MET_ORIENTATION_LR }, + { AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, MET_ORIENTATION_AP }, + { AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior, MET_ORIENTATION_PA }, + { AnatomicalOrientation::CoordinateEnum::InferiorToSuperior, MET_ORIENTATION_IS }, + { AnatomicalOrientation::CoordinateEnum::SuperiorToInferior, MET_ORIENTATION_SI } + }; m_MetaImage.AnatomicalOrientation(0, axisToMetOrientation.at(coordOrient.GetPrimaryTerm())); m_MetaImage.AnatomicalOrientation(1, axisToMetOrientation.at(coordOrient.GetSecondaryTerm())); m_MetaImage.AnatomicalOrientation(2, axisToMetOrientation.at(coordOrient.GetTertiaryTerm())); - } // Propagate direction cosine information. auto * transformMatrix = static_cast(malloc(numberOfDimensions * numberOfDimensions * sizeof(double))); diff --git a/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx b/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx index ac7283a54a5a..5b50d1d97f23 100644 --- a/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx +++ b/Modules/IO/NIFTI/src/itkNiftiImageIO.cxx @@ -18,7 +18,7 @@ #include "itkNiftiImageIO.h" #include "itkIOCommon.h" #include "itkMetaDataObject.h" -#include "itkDICOMOrientation.h" +#include "itkAnatomicalOrientation.h" #include #include "itkNiftiImageIOConfigurePrivate.h" #include "itkMakeUniqueForOverwrite.h" @@ -1885,47 +1885,47 @@ NiftiImageIO::SetImageIOOrientationFromNIfTI(unsigned short dims, double spacing this->GetLegacyAnalyze75Mode() != NiftiImageIOEnums::Analyze75Flavor::AnalyzeITK4 && this->GetLegacyAnalyze75Mode() != NiftiImageIOEnums::Analyze75Flavor::AnalyzeITK4Warning) { // only do this for Analyze file format - DICOMOrientation orient(DICOMOrientation::OrientationEnum::INVALID); + AnatomicalOrientation orient(AnatomicalOrientation::ToOrientationEnum::INVALID); switch (this->m_NiftiImage->analyze75_orient) { case a75_transverse_unflipped: - orient = DICOMOrientation(DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::PosteriorToAnterior, - DICOMOrientation::CoordinateEnum::InferiorToSuperior); + orient = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior, + AnatomicalOrientation::CoordinateEnum::InferiorToSuperior); break; case a75_sagittal_unflipped: - orient = DICOMOrientation( DICOMOrientation::CoordinateEnum::PosteriorToAnterior, - DICOMOrientation::CoordinateEnum::InferiorToSuperior, - DICOMOrientation::CoordinateEnum::RightToLeft); + orient = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior, + AnatomicalOrientation::CoordinateEnum::InferiorToSuperior, + AnatomicalOrientation::CoordinateEnum::RightToLeft); break; case a75_coronal_unflipped: - orient = DICOMOrientation( DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::InferiorToSuperior, - DICOMOrientation::CoordinateEnum::PosteriorToAnterior); + orient = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::InferiorToSuperior, + AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior); break; case a75_transverse_flipped: - orient = DICOMOrientation( DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - DICOMOrientation::CoordinateEnum::InferiorToSuperior); + orient = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + AnatomicalOrientation::CoordinateEnum::InferiorToSuperior); break; case a75_sagittal_flipped: - orient = DICOMOrientation( DICOMOrientation::CoordinateEnum::PosteriorToAnterior, - DICOMOrientation::CoordinateEnum::InferiorToSuperior, - DICOMOrientation::CoordinateEnum::LeftToRight); + orient = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior, + AnatomicalOrientation::CoordinateEnum::InferiorToSuperior, + AnatomicalOrientation::CoordinateEnum::LeftToRight); break; case a75_coronal_flipped: - orient = DICOMOrientation( DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::SuperiorToInferior, - DICOMOrientation::CoordinateEnum::PosteriorToAnterior); + orient = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::SuperiorToInferior, + AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior); break; case a75_orient_unknown: - orient = DICOMOrientation( DICOMOrientation::CoordinateEnum::RightToLeft, - DICOMOrientation::CoordinateEnum::InferiorToSuperior, - DICOMOrientation::CoordinateEnum::PosteriorToAnterior); + orient = AnatomicalOrientation(AnatomicalOrientation::CoordinateEnum::RightToLeft, + AnatomicalOrientation::CoordinateEnum::InferiorToSuperior, + AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior); break; } - const auto dir = orient.GetAsDirection(); - const int max_defined_orientation_dims = (dims > 3) ? 3 : dims; + const auto dir = orient.GetAsDirection(); + const int max_defined_orientation_dims = (dims > 3) ? 3 : dims; for (int d = 0; d < max_defined_orientation_dims; ++d) { std::vector direction(dims, 0.0); diff --git a/Modules/IO/NIFTI/test/itkNiftiImageIOTest.h b/Modules/IO/NIFTI/test/itkNiftiImageIOTest.h index 25574ea37063..c41dfa715116 100644 --- a/Modules/IO/NIFTI/test/itkNiftiImageIOTest.h +++ b/Modules/IO/NIFTI/test/itkNiftiImageIOTest.h @@ -30,7 +30,7 @@ #include "itkNiftiImageIO.h" #include "itkMetaDataObject.h" #include "itkIOCommon.h" -#include "itkDICOMOrientation.h" +#include "itkAnatomicalOrientation.h" #include "itkDiffusionTensor3D.h" #include "itkAffineTransform.h" #include "itkVector.h" @@ -228,9 +228,10 @@ template typename ImageType::DirectionType CORDirCosines() { - auto CORdir = itk::DICOMOrientation ( itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior, - itk::DICOMOrientation::CoordinateEnum::PosteriorToAnterior).GetAsDirection(); + auto CORdir = itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior, + itk::AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior) + .GetAsDirection(); typename ImageType::DirectionType dir; for (unsigned int i = 0; i < ImageType::ImageDimension; ++i) { diff --git a/Modules/IO/NIFTI/test/itkNiftiReadAnalyzeTest.cxx b/Modules/IO/NIFTI/test/itkNiftiReadAnalyzeTest.cxx index 63833b281d0b..d8f9b69a272d 100644 --- a/Modules/IO/NIFTI/test/itkNiftiReadAnalyzeTest.cxx +++ b/Modules/IO/NIFTI/test/itkNiftiReadAnalyzeTest.cxx @@ -22,7 +22,7 @@ #include "itkImageFileReader.h" #include "itkImageRegionConstIterator.h" #include "itkMath.h" -#include "itkDICOMOrientation.h" +#include "itkAnatomicalOrientation.h" // debug #include @@ -176,11 +176,11 @@ ReadImage(const std::string & fileName, int -itkNiftiAnalyzeContentsAndCoordinatesTest(char * argv[], - unsigned char hist_orient_code, - itk::DICOMOrientation expected_code, - itk::NiftiImageIOEnums::Analyze75Flavor analyze_mode, - bool flip_x = false) +itkNiftiAnalyzeContentsAndCoordinatesTest(char * argv[], + unsigned char hist_orient_code, + itk::AnatomicalOrientation expected_code, + itk::NiftiImageIOEnums::Analyze75Flavor analyze_mode, + bool flip_x = false) { std::string hdrName(argv[1]); hdrName += "/littleEndian_"; @@ -248,7 +248,7 @@ itkNiftiAnalyzeContentsAndCoordinatesTest(char * } } - const itk::DICOMOrientation orientation_code(img->GetDirection()); + const itk::AnatomicalOrientation orientation_code(img->GetDirection()); // verify the correct orientation : if (orientation_code != expected_code) { @@ -289,129 +289,129 @@ itkNiftiReadAnalyzeTest(int argc, char * argv[]) return itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 0, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::PosteriorToAnterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeReject) != EXIT_FAILURE || itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 0, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::PosteriorToAnterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeSPM) == EXIT_FAILURE || itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 1, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior, - itk::DICOMOrientation::CoordinateEnum::PosteriorToAnterior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior, + itk::AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeSPM) == EXIT_FAILURE || itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 2, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::PosteriorToAnterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior, - itk::DICOMOrientation::CoordinateEnum::RightToLeft), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior, + itk::AnatomicalOrientation::CoordinateEnum::RightToLeft), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeSPM) == EXIT_FAILURE || itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 3, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeSPM) == EXIT_FAILURE || itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 4, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::SuperiorToInferior, - itk::DICOMOrientation::CoordinateEnum::PosteriorToAnterior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::SuperiorToInferior, + itk::AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeSPM) == EXIT_FAILURE || itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 5, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::PosteriorToAnterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior, - itk::DICOMOrientation::CoordinateEnum::LeftToRight), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior, + itk::AnatomicalOrientation::CoordinateEnum::LeftToRight), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeSPM) == EXIT_FAILURE || // ITK4 default behaviour: reader should ignore orientation code and always produce RAI , // there should be a warning on console itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 0, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeITK4Warning) == EXIT_FAILURE || // ITK4 reader should ignore orientation code and always produce RAI itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 0, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeITK4) == EXIT_FAILURE || itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 1, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeITK4) == EXIT_FAILURE || itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 2, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeITK4) == EXIT_FAILURE || itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 3, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeITK4) == EXIT_FAILURE || itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 5, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeITK4) == EXIT_FAILURE || itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 5, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeITK4) == EXIT_FAILURE || // flip X axis , SPM reader should respect this itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 0, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::LeftToRight, - itk::DICOMOrientation::CoordinateEnum::PosteriorToAnterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::LeftToRight, + itk::AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeSPM, true) == EXIT_FAILURE || // flip X axis , ITK4 reader should respect this itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 0, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::LeftToRight, - itk::DICOMOrientation::CoordinateEnum::AnteriorToPosterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::LeftToRight, + itk::AnatomicalOrientation::CoordinateEnum::AnteriorToPosterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeITK4, true) == EXIT_FAILURE || // flip X axis , FSL reader should ignore this itkNiftiAnalyzeContentsAndCoordinatesTest( argv, 0, - itk::DICOMOrientation(itk::DICOMOrientation::CoordinateEnum::RightToLeft, - itk::DICOMOrientation::CoordinateEnum::PosteriorToAnterior, - itk::DICOMOrientation::CoordinateEnum::InferiorToSuperior), + itk::AnatomicalOrientation(itk::AnatomicalOrientation::CoordinateEnum::RightToLeft, + itk::AnatomicalOrientation::CoordinateEnum::PosteriorToAnterior, + itk::AnatomicalOrientation::CoordinateEnum::InferiorToSuperior), itk::NiftiImageIOEnums::Analyze75Flavor::AnalyzeFSL, true) == EXIT_FAILURE diff --git a/Modules/IO/PhilipsREC/src/itkPhilipsRECImageIO.cxx b/Modules/IO/PhilipsREC/src/itkPhilipsRECImageIO.cxx index bc6e07a0eab1..9ae07d4ac84c 100644 --- a/Modules/IO/PhilipsREC/src/itkPhilipsRECImageIO.cxx +++ b/Modules/IO/PhilipsREC/src/itkPhilipsRECImageIO.cxx @@ -29,7 +29,7 @@ #include "itkIOCommon.h" #include "itkByteSwapper.h" #include "itkMetaDataObject.h" -#include "itkDICOMOrientation.h" +#include "itkAnatomicalOrientation.h" #include "itksys/SystemTools.hxx" #include "itk_zlib.h" #include @@ -713,7 +713,7 @@ PhilipsRECImageIO::ReadImageInformation() AffineMatrix spacing; spacing.SetIdentity(); - DICOMOrientation coord_orient; + AnatomicalOrientation coord_orient(AnatomicalOrientation::FromEnum::RSA); switch (par.sliceorient) { @@ -747,7 +747,7 @@ PhilipsRECImageIO::ReadImageInformation() spacing[2][2] = par.vox[1]; } - DICOMOrientation::DirectionType dir = coord_orient.GetAsDirection(); + AnatomicalOrientation::DirectionType dir = coord_orient.GetAsDirection(); AffineMatrix direction; direction.SetIdentity(); diff --git a/Modules/IO/Siemens/src/itkSiemensVisionImageIO.cxx b/Modules/IO/Siemens/src/itkSiemensVisionImageIO.cxx index 080b42536752..cd6cfae08266 100644 --- a/Modules/IO/Siemens/src/itkSiemensVisionImageIO.cxx +++ b/Modules/IO/Siemens/src/itkSiemensVisionImageIO.cxx @@ -223,8 +223,8 @@ SiemensVisionImageIO::ReadHeader(const char * FileNameToRead) if (text_angle_len.empty() || itk::Math::abs(std::stod(text_angle_len)) <= 45.0) { // hdr->imagePlane = itk::IOCommon::ITK_ANALYZE_ORIENTATION_IRP_CORONAL; - hdr->coordinateOrientation = - DICOMOrientation(itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RSP); + hdr->coordinateOrientation = AnatomicalOrientation( + itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RSP); } else { @@ -232,15 +232,15 @@ SiemensVisionImageIO::ReadHeader(const char * FileNameToRead) { // hdr->imagePlane = // itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_ANALYZE_ORIENTATION_IRP_SAGITTAL; - hdr->coordinateOrientation = - DICOMOrientation(itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_AIR); + hdr->coordinateOrientation = AnatomicalOrientation( + itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_AIR); } else { // hdr->imagePlane = // itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_ANALYZE_ORIENTATION_IRP_TRANSVERSE; - hdr->coordinateOrientation = - DICOMOrientation(itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RAI); + hdr->coordinateOrientation = AnatomicalOrientation( + itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RAI); } } } @@ -250,8 +250,8 @@ SiemensVisionImageIO::ReadHeader(const char * FileNameToRead) { // hdr->imagePlane = // itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_ANALYZE_ORIENTATION_IRP_SAGITTAL; - hdr->coordinateOrientation = - DICOMOrientation(itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_AIR); + hdr->coordinateOrientation = AnatomicalOrientation( + itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_AIR); } else { @@ -259,15 +259,15 @@ SiemensVisionImageIO::ReadHeader(const char * FileNameToRead) { // hdr->imagePlane = // itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_ANALYZE_ORIENTATION_IRP_CORONAL; - hdr->coordinateOrientation = - DICOMOrientation(itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RSP); + hdr->coordinateOrientation = AnatomicalOrientation( + itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RSP); } else { // hdr->imagePlane = // itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_ANALYZE_ORIENTATION_IRP_TRANSVERSE; - hdr->coordinateOrientation = - DICOMOrientation(itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RAI); + hdr->coordinateOrientation = AnatomicalOrientation( + itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RAI); } } } @@ -277,8 +277,8 @@ SiemensVisionImageIO::ReadHeader(const char * FileNameToRead) { // hdr->imagePlane = // itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_ANALYZE_ORIENTATION_IRP_TRANSVERSE; - hdr->coordinateOrientation = - DICOMOrientation(itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RAI); + hdr->coordinateOrientation = AnatomicalOrientation( + itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RAI); } else { @@ -286,15 +286,15 @@ SiemensVisionImageIO::ReadHeader(const char * FileNameToRead) { // hdr->imagePlane = // itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_ANALYZE_ORIENTATION_IRP_CORONAL; - hdr->coordinateOrientation = - DICOMOrientation(itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RSP); + hdr->coordinateOrientation = AnatomicalOrientation( + itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_RSP); } else { // hdr->imagePlane = // itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_ANALYZE_ORIENTATION_IRP_SAGITTAL; - hdr->coordinateOrientation = - DICOMOrientation(itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_AIR); + hdr->coordinateOrientation = AnatomicalOrientation( + itk::SpatialOrientationEnums::ValidCoordinateOrientations::ITK_COORDINATE_ORIENTATION_AIR); } } }