From 64a30cc0e9b8407f38cf36cd716f0a8c2bcfb58c Mon Sep 17 00:00:00 2001 From: Martin Falk Date: Fri, 11 Oct 2024 15:02:31 +0200 Subject: [PATCH 1/4] MedVis: DICOM sanity check fix --- .../dicom/datastructures/dicomdirtypes.h | 7 ++-- .../src/datastructures/dicomdirtypes.cpp | 37 ++++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/medvis/dicom/include/inviwo/dicom/datastructures/dicomdirtypes.h b/medvis/dicom/include/inviwo/dicom/datastructures/dicomdirtypes.h index a6e10dbf..b26c1100 100644 --- a/medvis/dicom/include/inviwo/dicom/datastructures/dicomdirtypes.h +++ b/medvis/dicom/include/inviwo/dicom/datastructures/dicomdirtypes.h @@ -102,9 +102,9 @@ struct IVW_MODULE_DICOM_API Series { * * pixel format * * color space (i.e. Photometric Interpretation) containing no. of samples per pixel * * intercept and slope - * * TODO: pixel spacing - * * TODO: image orientation (patient) with summed squared difference < 1e-4 - * * TODO: image position (patient) with summed squared difference < 1e-4 + * * pixel spacing + * * image orientation (patient) with summed squared difference < 1e-4 + * * image position (patient) with summed squared difference < 1e-4 * * @param series series containing images with valid paths * @param dicompath used only in case of an error and should refer to the main DICOM dataset @@ -119,7 +119,6 @@ struct IVW_MODULE_DICOM_API Series { * TODO: proper volume sorting with more heuristics according to * https://nipy.org/nibabel/dicom/spm_dicom.html#spm-volume-sorting */ - void sortImages(); bool empty() const; diff --git a/medvis/dicom/src/datastructures/dicomdirtypes.cpp b/medvis/dicom/src/datastructures/dicomdirtypes.cpp index ed9a2948..7007c557 100644 --- a/medvis/dicom/src/datastructures/dicomdirtypes.cpp +++ b/medvis/dicom/src/datastructures/dicomdirtypes.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -50,6 +51,7 @@ #include #include +#include namespace inviwo { @@ -147,14 +149,14 @@ struct ImageMetaData { slope = interceptSlopeVec[1]; } - size2_t dims; - gdcm::PixelFormat pixelformat; - gdcm::PhotometricInterpretation photometric; - double intercept; - double slope; - dvec3 pixelSpacing; - dvec3 orientation[2]; - dvec3 origin; + size2_t dims{0}; + gdcm::PixelFormat pixelformat = gdcm::PixelFormat::UNKNOWN; + gdcm::PhotometricInterpretation photometric = gdcm::PhotometricInterpretation::UNKNOWN; + double intercept{0.0}; + double slope{1.0}; + dvec3 pixelSpacing{0.0}; + std::array orientation = {dvec3{0.0}, dvec3{0.0}}; + dvec3 origin{0.0}; }; } // namespace @@ -167,16 +169,19 @@ void Series::updateImageInformation(const std::filesystem::path& dicompath) { // series: // * dimensions // * pixel format - // * color space (i.e. Photometric Interpretation) containing no. of samples per - // pixel + // * color space (i.e. Photometric Interpretation) containing no. of samples per + // pixel // * intercept and slope // * pixel spacing // * image orientation (patient) with summed squared difference < 1e-4 - // * image position (patient) with summed squared difference < 1e-4 + // * image position (patient) with summed squared difference < 1e-4 execpt along axis + // orthogonal to image orientation + bool warnSlopeIntercept = false; bool warnPixelSpacing = false; bool warnOrientation = false; bool warnOrigin = false; + auto ssd = [](auto vec) { return glm::dot(vec, vec); }; auto sanityCheck = [&](const ImageMetaData& ref, const ImageMetaData& img) { if (ref.dims != img.dims) { throw DataReaderException( @@ -197,14 +202,10 @@ void Series::updateImageInformation(const std::filesystem::path& dicompath) { } const double dicomDelta = 1.0e-4; if (std::abs(ref.slope - img.slope) > dicomDelta || - std::abs(ref.intercept - img.intercept) < dicomDelta) { + std::abs(ref.intercept - img.intercept) > dicomDelta) { warnSlopeIntercept = true; } - auto ssd = [](auto vec) { // compute squared sums - return glm::dot(vec, vec); - }; - if (ssd(ref.pixelSpacing - img.pixelSpacing) > dicomDelta) { warnPixelSpacing = true; } @@ -212,7 +213,9 @@ void Series::updateImageInformation(const std::filesystem::path& dicompath) { (ssd(ref.orientation[1] - img.orientation[1]) > dicomDelta)) { warnOrientation = true; } - if (ssd(ref.origin - img.origin) > dicomDelta) { + const dmat3 refT{ref.orientation[0], ref.orientation[1], dvec3{0.0}}; + const dmat3 imgT{img.orientation[0], img.orientation[1], dvec3{0.0}}; + if (ssd(refT * ref.origin - imgT * img.origin) > dicomDelta) { warnOrigin = true; } }; From cc299d19789ee636223d4f774d47880f7f94822c Mon Sep 17 00:00:00 2001 From: Martin Falk Date: Tue, 15 Oct 2024 09:39:20 +0200 Subject: [PATCH 2/4] MedVis: requested change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Jönsson --- medvis/dicom/src/datastructures/dicomdirtypes.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/medvis/dicom/src/datastructures/dicomdirtypes.cpp b/medvis/dicom/src/datastructures/dicomdirtypes.cpp index 7007c557..f2577e2d 100644 --- a/medvis/dicom/src/datastructures/dicomdirtypes.cpp +++ b/medvis/dicom/src/datastructures/dicomdirtypes.cpp @@ -181,7 +181,7 @@ void Series::updateImageInformation(const std::filesystem::path& dicompath) { bool warnPixelSpacing = false; bool warnOrientation = false; bool warnOrigin = false; - auto ssd = [](auto vec) { return glm::dot(vec, vec); }; + auto squaredSum = [](auto vec) { return glm::dot(vec, vec); }; auto sanityCheck = [&](const ImageMetaData& ref, const ImageMetaData& img) { if (ref.dims != img.dims) { throw DataReaderException( @@ -206,16 +206,16 @@ void Series::updateImageInformation(const std::filesystem::path& dicompath) { warnSlopeIntercept = true; } - if (ssd(ref.pixelSpacing - img.pixelSpacing) > dicomDelta) { + if (squaredSum(ref.pixelSpacing - img.pixelSpacing) > dicomDelta) { warnPixelSpacing = true; } - if ((ssd(ref.orientation[0] - img.orientation[0]) > dicomDelta) || - (ssd(ref.orientation[1] - img.orientation[1]) > dicomDelta)) { + if ((squaredSum(ref.orientation[0] - img.orientation[0]) > dicomDelta) || + (squaredSum(ref.orientation[1] - img.orientation[1]) > dicomDelta)) { warnOrientation = true; } const dmat3 refT{ref.orientation[0], ref.orientation[1], dvec3{0.0}}; const dmat3 imgT{img.orientation[0], img.orientation[1], dvec3{0.0}}; - if (ssd(refT * ref.origin - imgT * img.origin) > dicomDelta) { + if (squaredSum(refT * ref.origin - imgT * img.origin) > dicomDelta) { warnOrigin = true; } }; From 9fc2db9d4f617aea51616fca4a6daad1e1e40a6e Mon Sep 17 00:00:00 2001 From: Martin Falk Date: Wed, 27 Nov 2024 15:37:13 +0100 Subject: [PATCH 3/4] MedVis,TensorVis: warn fixes --- medvis/dicom/src/io/gdcmvolumereader.cpp | 2 +- .../tensorvisbase/src/datastructures/tensorfield3d.cpp | 3 --- .../tensorvisio/src/processors/tensorfield2dimport.cpp | 10 +++++----- tensorvis/tensorvisio/src/tensorvisiomodule.cpp | 1 - 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/medvis/dicom/src/io/gdcmvolumereader.cpp b/medvis/dicom/src/io/gdcmvolumereader.cpp index 82e41529..8ccc4ec1 100644 --- a/medvis/dicom/src/io/gdcmvolumereader.cpp +++ b/medvis/dicom/src/io/gdcmvolumereader.cpp @@ -664,7 +664,7 @@ std::shared_ptr GdcmVolumeReader::generateVolume(const gdcm::Image& imag LogInfo("spacing: " << spacestr); LogInfo("volume size: " << size); LogInfo("voxel size: " << voxelsz << "(components: " << (format->getComponents()) - << ", component size: " << (format->getSize()) << ")"); + << ", component size: " << (format->getSizeInBytes()) << ")"); LogInfo("sample value range is [" << pixelformat.GetMin() << ", " << pixelformat.GetMax() << "]."); pixelformat.Print(gdcm::Trace::GetDebugStream()); diff --git a/tensorvis/tensorvisbase/src/datastructures/tensorfield3d.cpp b/tensorvis/tensorvisbase/src/datastructures/tensorfield3d.cpp index 4616d7d8..361a05ff 100644 --- a/tensorvis/tensorvisbase/src/datastructures/tensorfield3d.cpp +++ b/tensorvis/tensorvisbase/src/datastructures/tensorfield3d.cpp @@ -677,9 +677,6 @@ void TensorField3D::computeEigenValuesAndEigenVectors() { if (tensor == dmat3(0.0)) { return {{std::make_pair(0, dvec3{0}), std::make_pair(0, dvec3{0}), std::make_pair(0, dvec3{0})}}; - return std::array, 3>{std::pair{0, dvec3(0)}, - std::pair{0, dvec3(0)}, - std::pair{0, dvec3(0)}}; } Eigen::EigenSolver solver(util::glm2eigen(tensor)); diff --git a/tensorvis/tensorvisio/src/processors/tensorfield2dimport.cpp b/tensorvis/tensorvisio/src/processors/tensorfield2dimport.cpp index 56bd1357..c03bdd1a 100644 --- a/tensorvis/tensorvisio/src/processors/tensorfield2dimport.cpp +++ b/tensorvis/tensorvisio/src/processors/tensorfield2dimport.cpp @@ -71,12 +71,12 @@ void TensorField2DImport::process() { return; } - size_t version; - size2_t dimensions; + size_t version{0}; + size2_t dimensions{1}; auto extents = dvec2(1.0); - size_t rank; - size_t dimensionality; - bool hasEigenInfo; + size_t rank{0}; + size_t dimensionality{0}; + bool hasEigenInfo = false; std::string versionStr; size_t size; diff --git a/tensorvis/tensorvisio/src/tensorvisiomodule.cpp b/tensorvis/tensorvisio/src/tensorvisiomodule.cpp index 540adeac..cf763bbd 100644 --- a/tensorvis/tensorvisio/src/tensorvisiomodule.cpp +++ b/tensorvis/tensorvisio/src/tensorvisiomodule.cpp @@ -80,7 +80,6 @@ bool TensorVisIOModule::Converter::convert(TxElement* root) { default: return false; // No changes } - return true; } } // namespace inviwo From b2dfc13d0e862945487369a74ecc8c8cb21824d9 Mon Sep 17 00:00:00 2001 From: Martin Falk Date: Thu, 28 Nov 2024 14:26:23 +0100 Subject: [PATCH 4/4] TensorVis: warn fix --- .../tensorvisbase/src/processors/tensorfield2danisotropy.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tensorvis/tensorvisbase/src/processors/tensorfield2danisotropy.cpp b/tensorvis/tensorvisbase/src/processors/tensorfield2danisotropy.cpp index c966052a..7290c55a 100644 --- a/tensorvis/tensorvisbase/src/processors/tensorfield2danisotropy.cpp +++ b/tensorvis/tensorvisbase/src/processors/tensorfield2danisotropy.cpp @@ -104,13 +104,12 @@ void TensorField2DAnisotropy::process() { default: throw Exception(IVW_CONTEXT, "Unsupported tensorutil::Anisotropy"); } - return nullptr; }(); auto [min, max] = util::layerMinMax(layerRam.get(), IgnoreSpecialValues::No); dvec2 range{glm::compMin(min), glm::compMax(max)}; - std::shared_ptr layer = std::make_shared(layerRam); + auto layer = std::make_shared(layerRam); layer->dataMap.dataRange = range; layer->dataMap.valueRange = range;