From c4775b4f33b381b4435a545459ee561c8be43ce0 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Tue, 3 Nov 2026 18:08:34 -0500 Subject: [PATCH 01/33] BUG: AlignSectionsFeatureCentroid - Shift the top section with a nonzero reference slice With Use Reference Slice on and a reference slice other than 0, the shift loops started at traversal index 1. Index 0 is the highest-Z section, so that section never got a shift and stayed misaligned. DREAM.3D 6.5.171 has the same defect (errata KI-010); the output now differs from 6.5.171 on purpose. The centroid loops now start at index 0 in that case, and the shared AlignSections transfer applies a nonzero row-0 shift. The diagnostic slice-index row 0 names the physical reference slice. Align Sections (List) now also applies row 0 of a shift file, in Relative and Cumulative mode, so a Feature Centroid result can be replayed through it. Earlier versions ignored row 0. The example pipeline Align_Sections_User_Input.d3dpipeline reads a relative file whose row 0 is "1 1", so its sections now move 1, 2 and 3 cells instead of 0, 1 and 2, matching example_cumulative_shifts.txt. Add tests with hand-calculated centroid shifts on a 3x3x4 image for Feature Centroid (Direct and Scanline, with and without diagnostic arrays) and for List with a nonzero top row. Fixes #1908 item L04 Signed-off-by: Michael Jackson --- .../AlignSectionsFeatureCentroidFilter.md | 2 + .../docs/AlignSectionsListFilter.md | 6 +- .../AlignSectionsFeatureCentroid.cpp | 12 ++-- .../Filters/Algorithms/AlignSectionsList.cpp | 8 +-- .../test/AlignSectionsFeatureCentroidTest.cpp | 70 +++++++++++++++++++ .../test/AlignSectionsListTest.cpp | 50 +++++++++++++ src/simplnx/Utilities/AlignSections.cpp | 9 +-- 7 files changed, 141 insertions(+), 16 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/AlignSectionsFeatureCentroidFilter.md b/src/Plugins/SimplnxCore/docs/AlignSectionsFeatureCentroidFilter.md index 6a3ea5284f..2ac6fd15eb 100644 --- a/src/Plugins/SimplnxCore/docs/AlignSectionsFeatureCentroidFilter.md +++ b/src/Plugins/SimplnxCore/docs/AlignSectionsFeatureCentroidFilter.md @@ -24,6 +24,8 @@ Unlike the misorientation-based and mutual-information-based alignment methods, If *Use Reference Slice* is enabled, each section is shifted to align with a single fixed reference slice rather than its immediate neighbor. This prevents small errors from accumulating across many sections. +The highest-Z section is also shifted when the reference slice is not 0. This corrects DREAM3D 6.5.171 behavior, which left that section unchanged. + ## Algorithm The algorithm proceeds in two phases: diff --git a/src/Plugins/SimplnxCore/docs/AlignSectionsListFilter.md b/src/Plugins/SimplnxCore/docs/AlignSectionsListFilter.md index 61abab9ac6..90c5c0f5d4 100644 --- a/src/Plugins/SimplnxCore/docs/AlignSectionsListFilter.md +++ b/src/Plugins/SimplnxCore/docs/AlignSectionsListFilter.md @@ -20,16 +20,18 @@ All shift values are in **cell (voxel) units**, not physical units. A shift of 3 The input shifts can be provided in either format: -- **Relative [0]**: Each shift describes the offset of section N relative to section N-1. The filter internally converts these to cumulative shifts before applying them. +- **Relative [0]**: Each shift describes the offset of section N relative to section N-1. Row 0 supplies the initial offset of the highest-Z section. The filter adds each later relative shift to the previous cumulative shift. - **Cumulative [1]**: Each shift describes the absolute offset of section N from a fixed reference point. +A nonzero row 0 now shifts the highest-Z section. Earlier versions ignored this row. + ### Preparing Shift Data from a File If your shifts are stored in an external file, you need to import them into a DataArray before using this filter: **Requirements:** - The number of shift entries must equal the number of slices (Z dimension of the geometry) -- Slices must be ordered from bottom to top +- Slices must be ordered from highest Z to lowest Z. Row 0 applies to the highest-Z section, including a nonzero shift **Recommended file format** (space-delimited, two values per line): diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsFeatureCentroid.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsFeatureCentroid.cpp index ad5f327065..18dab31ca9 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsFeatureCentroid.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsFeatureCentroid.cpp @@ -127,7 +127,7 @@ Result<> AlignSectionsFeatureCentroid::findShifts(std::vector& xShifts, s auto& centroidsStore = m_DataStructure.getDataAs(m_InputValues->CentroidsArrayPath)->getDataStoreRef(); // Convert physical centroid differences to integer voxel offsets. - for(usize iter = 1; iter < dims[2]; iter++) + for(usize iter = (m_InputValues->UseReferenceSlice && m_InputValues->ReferenceSlice != 0) ? 0 : 1; iter < dims[2]; iter++) { slice = (dims[2] - 1) - iter; if(m_InputValues->UseReferenceSlice) @@ -179,7 +179,7 @@ Result<> AlignSectionsFeatureCentroid::findShifts(std::vector& xShifts, s usize xIndex = iter * 2; usize yIndex = (iter * 2) + 1; slicesStore[xIndex] = slice; - slicesStore[yIndex] = slice + 1; + slicesStore[yIndex] = iter == 0 ? dims[2] - 1 - static_cast(m_InputValues->ReferenceSlice) : slice + 1; relativeShiftsStore[xIndex] = relativexshift; relativeShiftsStore[yIndex] = relativeyshift; cumulativeShiftsStore[xIndex] = xShifts[iter]; @@ -191,7 +191,7 @@ Result<> AlignSectionsFeatureCentroid::findShifts(std::vector& xShifts, s else { // Compute shifts without writing diagnostic arrays. - for(usize iter = 1; iter < dims[2]; iter++) + for(usize iter = (m_InputValues->UseReferenceSlice && m_InputValues->ReferenceSlice != 0) ? 0 : 1; iter < dims[2]; iter++) { if(m_InputValues->UseReferenceSlice) { @@ -332,7 +332,7 @@ Result<> AlignSectionsFeatureCentroid::findShiftsOoc(std::vector& xShifts // Convert physical centroid differences to integer voxel offsets. bool xWarning = false; bool yWarning = false; - for(usize iter = 1; iter < dims[2]; iter++) + for(usize iter = (m_InputValues->UseReferenceSlice && m_InputValues->ReferenceSlice != 0) ? 0 : 1; iter < dims[2]; iter++) { if(m_InputValues->UseReferenceSlice) { @@ -379,7 +379,7 @@ Result<> AlignSectionsFeatureCentroid::findShiftsOoc(std::vector& xShifts auto& cumulativeShiftsStore = m_DataStructure.getDataAs(m_InputValues->CumulativeShiftsArrayPath)->getDataStoreRef(); auto& centroidsStore = m_DataStructure.getDataAs(m_InputValues->CentroidsArrayPath)->getDataStoreRef(); - for(usize iter = 1; iter < dims[2]; iter++) + for(usize iter = (m_InputValues->UseReferenceSlice && m_InputValues->ReferenceSlice != 0) ? 0 : 1; iter < dims[2]; iter++) { usize slice = (dims[2] - 1) - iter; int64 relativexshift = 0; @@ -398,7 +398,7 @@ Result<> AlignSectionsFeatureCentroid::findShiftsOoc(std::vector& xShifts usize xIndex = iter * 2; usize yIndex = (iter * 2) + 1; slicesStore[xIndex] = slice; - slicesStore[yIndex] = slice + 1; + slicesStore[yIndex] = iter == 0 ? dims[2] - 1 - static_cast(m_InputValues->ReferenceSlice) : slice + 1; relativeShiftsStore[xIndex] = relativexshift; relativeShiftsStore[yIndex] = relativeyshift; cumulativeShiftsStore[xIndex] = xShifts[iter]; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsList.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsList.cpp index f696cd9320..8255269e34 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsList.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsList.cpp @@ -46,10 +46,10 @@ Result<> AlignSectionsList::findShifts(std::vector& xShifts, std::vector< // Size validated in preflight const auto& relativeShiftsStore = m_DataStructure.getDataAs(m_InputValues->ShiftsArrayPath)->getDataStoreRef(); const usize numTup = relativeShiftsStore.getNumberOfTuples(); - for(usize i = 1; i < numTup; i++) + for(usize i = 0; i < numTup; i++) { - xShifts[i] = xShifts[i - 1] + relativeShiftsStore[i * 2]; - yShifts[i] = yShifts[i - 1] + relativeShiftsStore[(i * 2) + 1]; + xShifts[i] = (i == 0 ? 0 : xShifts[i - 1]) + relativeShiftsStore[i * 2]; + yShifts[i] = (i == 0 ? 0 : yShifts[i - 1]) + relativeShiftsStore[(i * 2) + 1]; } } else if(alignSectionsType == static_cast(to_underlying(AlignSectionsInputType::CumulativeShifts))) @@ -57,7 +57,7 @@ Result<> AlignSectionsList::findShifts(std::vector& xShifts, std::vector< // Size validated in preflight const auto& cumulativeShiftsStore = m_DataStructure.getDataAs(m_InputValues->ShiftsArrayPath)->getDataStoreRef(); const usize numTup = cumulativeShiftsStore.getNumberOfTuples(); - for(usize i = 1; i < numTup; i++) + for(usize i = 0; i < numTup; i++) { xShifts[i] = cumulativeShiftsStore[i * 2]; yShifts[i] = cumulativeShiftsStore[(i * 2) + 1]; diff --git a/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp b/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp index 29c1e534a0..a7e5b3013d 100644 --- a/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp +++ b/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp @@ -12,6 +12,7 @@ #include +#include #include #include @@ -182,3 +183,72 @@ TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Geometry cell tuple REQUIRE(errorRef.message.find("'Image' has 12 cells") != std::string::npos); } } + +TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Nonzero reference top slice", "[Reconstruction][AlignSectionsFeatureCentroidFilter]") +{ + UnitTest::LoadPlugins(); + const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); + const bool storeShifts = GENERATE(false, true); + CAPTURE(scenario, storeShifts); + UnitTest::AlgorithmTestScope scope(scenario); + using FilterType = AlignSectionsFeatureCentroidFilter; + DataStructure dataStructure; + auto* geom = ImageGeom::Create(dataStructure, "Image"); + REQUIRE(geom != nullptr); + geom->setDimensions({3, 3, 4}); + geom->setSpacing({1.0F, 1.0F, 1.0F}); + auto* cells = AttributeMatrix::Create(dataStructure, "Cells", ShapeType{4, 3, 3}, geom->getId()); + REQUIRE(cells != nullptr); + geom->setCellData(*cells); + auto* mask = UInt8Array::Create(dataStructure, "Mask", std::make_shared>(ShapeType{4, 3, 3}, ShapeType{1}, 0), cells->getId()); + REQUIRE(mask != nullptr); + mask->fill(0); + // One marked cell per slice: (1,1), (0,0), (1,1), (2,2) in ascending Z. + // Reference index 1 counts from the top, so it is physical slice 2. + // Centroid differences in descending Z are (+1,+1), (0,0), (-1,-1), (0,0). + // Reading source at destination + shift must place all marks at (1,1). + (*mask)[4] = 1; + (*mask)[9] = 1; + (*mask)[22] = 1; + (*mask)[35] = 1; + + FilterType filter; + Arguments args; + args.insertOrAssign(FilterType::k_SelectedImageGeometryPath_Key, std::make_any(DataPath({"Image"}))); + args.insertOrAssign(FilterType::k_MaskArrayPath_Key, std::make_any(DataPath({"Image", "Cells", "Mask"}))); + args.insertOrAssign(FilterType::k_UseReferenceSlice_Key, std::make_any(true)); + args.insertOrAssign(FilterType::k_ReferenceSlice_Key, std::make_any(1)); + args.insertOrAssign(FilterType::k_StoreAlignmentShifts_Key, std::make_any(storeShifts)); + args.insertOrAssign(FilterType::k_AlignmentAMName_Key, std::make_any("Shifts")); + args.insertOrAssign(FilterType::k_CumulativeShiftsArrayName_Key, std::make_any("Cumulative")); + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + auto result = scope.executeFilter(filter, dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + for(usize z = 0; z < 4; z++) + { + for(usize xy = 0; xy < 9; xy++) + { + CAPTURE(z, xy); + CHECK((*mask)[(z * 9) + xy] == (xy == 4 ? 1 : 0)); + } + } + if(storeShifts) + { + const auto& slices = dataStructure.getDataRefAs(DataPath({"Image", "Shifts", "Slice Indices"})); + // Row 0 pairs the top slice (physical 3) with the reference (physical 2). + CHECK(slices[0] == 3); + CHECK(slices[1] == 2); + const DataPath shiftsPath({"Image", "Shifts", "Cumulative"}); + REQUIRE_NOTHROW(dataStructure.getDataRefAs(shiftsPath)); + const auto& shifts = dataStructure.getDataRefAs(shiftsPath); + const std::array expectedShifts = {1, 0, -1, 0}; + for(usize iter = 0; iter < 4; iter++) + { + CAPTURE(iter); + CHECK(shifts[iter * 2] == expectedShifts[iter]); + CHECK(shifts[(iter * 2) + 1] == expectedShifts[iter]); + } + } + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} diff --git a/src/Plugins/SimplnxCore/test/AlignSectionsListTest.cpp b/src/Plugins/SimplnxCore/test/AlignSectionsListTest.cpp index 13effc8eb6..781e90bada 100644 --- a/src/Plugins/SimplnxCore/test/AlignSectionsListTest.cpp +++ b/src/Plugins/SimplnxCore/test/AlignSectionsListTest.cpp @@ -11,6 +11,7 @@ #include +#include #include #include @@ -185,3 +186,52 @@ TEST_CASE("SimplnxCore::AlignSectionsListFilter: Cumulative Shifts execution", " UnitTest::CheckArraysInheritTupleDims(dataStructure, SmallIn100::k_TupleCheckIgnoredPaths); } + +TEST_CASE("SimplnxCore::AlignSectionsListFilter: Nonzero top row", "[SimplnxCore][AlignSectionsListFilter]") +{ + UnitTest::LoadPlugins(); + const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); + const auto inputType = GENERATE(0ULL, 1ULL); + const int64 sign = GENERATE(-1, 1); + CAPTURE(scenario, inputType, sign); + UnitTest::AlgorithmTestScope scope(scenario); + DataStructure dataStructure; + auto* geom = ImageGeom::Create(dataStructure, "Image"); + REQUIRE(geom != nullptr); + geom->setDimensions({3, 3, 4}); + auto* cells = AttributeMatrix::Create(dataStructure, "Cells", ShapeType{4, 3, 3}, geom->getId()); + REQUIRE(cells != nullptr); + geom->setCellData(*cells); + auto* mask = UInt8Array::Create(dataStructure, "Mask", std::make_shared>(ShapeType{4, 3, 3}, ShapeType{1}, 0), cells->getId()); + REQUIRE(mask != nullptr); + auto* shifts = Int64Array::Create(dataStructure, "Shifts", std::make_shared>(ShapeType{4}, ShapeType{2}, 0)); + REQUIRE(shifts != nullptr); + // Descending cumulative offsets are sign * {1,0,-1,0} on both axes. + // Relative offsets are their differences, with row 0 as the initial offset. + // Each source mark is at (1 + offset, 1 + offset), so all outputs must be (1,1). + const std::array cumulative = {1, 0, -1, 0}; + const std::array relative = {1, -1, -1, 1}; + for(usize row = 0; row < 4; row++) + { + const usize coordinate = static_cast(1 + (sign * cumulative[row])); + (*mask)[((3 - row) * 9) + (coordinate * 3) + coordinate] = 1; + (*shifts)[row * 2] = sign * (inputType == 0 ? relative[row] : cumulative[row]); + (*shifts)[(row * 2) + 1] = (*shifts)[row * 2]; + } + AlignSectionsListFilter filter; + Arguments args; + args.insertOrAssign(AlignSectionsListFilter::k_InputArrayType_Key, std::make_any(inputType)); + args.insertOrAssign(AlignSectionsListFilter::k_SelectedImageGeometryPath_Key, std::make_any(DataPath({"Image"}))); + args.insertOrAssign(AlignSectionsListFilter::k_ShiftsArrayPath_Key, std::make_any(DataPath({"Shifts"}))); + auto result = scope.executeFilter(filter, dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + for(usize z = 0; z < 4; z++) + { + for(usize xy = 0; xy < 9; xy++) + { + CAPTURE(z, xy); + CHECK((*mask)[(z * 9) + xy] == (xy == 4 ? 1 : 0)); + } + } + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} diff --git a/src/simplnx/Utilities/AlignSections.cpp b/src/simplnx/Utilities/AlignSections.cpp index a7f50987cb..112b86c617 100644 --- a/src/simplnx/Utilities/AlignSections.cpp +++ b/src/simplnx/Utilities/AlignSections.cpp @@ -55,7 +55,7 @@ class AlignSectionsTransferDataImpl { T var = static_cast(0); - for(size_t i = 1; i < m_Dims[2]; i++) + for(size_t i = (!m_Xshifts.empty() && (m_Xshifts[0] != 0 || m_Yshifts[0] != 0)) ? 0 : 1; i < m_Dims[2]; i++) { m_Filter->sendThreadSafeProgressMessage(1); if(m_Filter->getCancel()) @@ -159,7 +159,7 @@ class AlignSectionsTransferDataOocImpl auto sliceBuffer = std::make_unique(sliceElements); auto outBuffer = std::make_unique(sliceElements); - for(usize i = 1; i < m_Dims[2]; i++) + for(usize i = (!m_Xshifts.empty() && (m_Xshifts[0] != 0 || m_Yshifts[0] != 0)) ? 0 : 1; i < m_Dims[2]; i++) { m_Filter->sendThreadSafeProgressMessage(1); if(m_Filter->getCancel()) @@ -311,7 +311,7 @@ Result<> AlignSections::execute(const SizeVec3& udims, const DataPath& imageGeom } // Every transfer reports through one shared throttle, so the denominator is aggregate: each array - // contributes the slices its loop visits, which is every slice after the first. Arrays that are not + // contributes the slices its loop visits, including the first when its shift is nonzero. Arrays that are not // IDataArray objects are skipped below, so count only the ones that will actually run. usize transferArrayCount = 0; for(const auto& cellArrayPath : selectedCellArrays) @@ -321,7 +321,8 @@ Result<> AlignSections::execute(const SizeVec3& udims, const DataPath& imageGeom transferArrayCount++; } } - const usize slicesPerArray = (udims[2] > 1) ? (udims[2] - 1) : 0; + const usize firstSlice = (!xShifts.empty() && (xShifts[0] != 0 || yShifts[0] != 0)) ? 0 : 1; + const usize slicesPerArray = udims[2] > firstSlice ? udims[2] - firstSlice : 0; m_Throttle.reset(transferArrayCount * slicesPerArray, "Updating cell data"); ParallelTaskAlgorithm taskRunner; From 2ac9a359afe853f793f246b04a8af45fae1bff96 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Tue, 3 Nov 2026 18:24:29 -0500 Subject: [PATCH 02/33] BUG: ComputeFeatureClustering - Use every random reference pair in the RDF normalization The random reference distribution generates 1000 points and divides by 1000 * 999 ordered pairs, but the pair loop started at index 1. The 1998 ordered pairs of point 0 were never counted, so the reference was about 0.2% short and the RDF values were too high. DREAM.3D 6.5.171 has the same defect (errata KI-017); the output now differs from 6.5.171 on purpose. The pair loop now starts at 0. Add a closed-form test where every reference distance falls into one bin, so the RDF must be exactly 1 (it was 1.002). The exemplar test no longer checks RDF equality with the 6.5.171 result, which has the defect; it now checks that no bin grows and that at least one bin shrinks, which follows from the added reference pairs. Fixes #1820 Fixes #1908 item L11 Signed-off-by: Michael Jackson --- .../docs/ComputeFeatureClusteringFilter.md | 2 + .../Algorithms/ComputeFeatureClustering.cpp | 2 +- .../test/ComputeFeatureClusteringTest.cpp | 69 ++++++++++++++++++- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/ComputeFeatureClusteringFilter.md b/src/Plugins/SimplnxCore/docs/ComputeFeatureClusteringFilter.md index e458a27f95..29302600b4 100644 --- a/src/Plugins/SimplnxCore/docs/ComputeFeatureClusteringFilter.md +++ b/src/Plugins/SimplnxCore/docs/ComputeFeatureClusteringFilter.md @@ -22,6 +22,8 @@ The **Filter** also outputs the clustering list (every inter-**Feature** distanc *Note:* Because the algorithm iterates over all **Features**, each distance is double-counted. For example, the distance from **Feature** 1 to **Feature** 2 is counted along with the identical distance from **Feature** 2 to **Feature** 1. +The random reference includes all pairs of distinct sample indices among its 1,000 sample points. DREAM3D 6.5.171 omitted pairs involving the first sample point. It omitted 1,998 of the 999,000 ordered reference pairs (0.2%). The correction can lower RDF values. The change in each bin depends on how many reference pairs were missing from that bin. + ### Bin Count **Number of Bins for RDF** is a dimensionless count and must be at least 1. Preflight rejects zero and negative counts. diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeFeatureClustering.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeFeatureClustering.cpp index ee369df7a5..67dca53ef2 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeFeatureClustering.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeFeatureClustering.cpp @@ -71,7 +71,7 @@ std::vector GenerateRandomDistribution(float32 minDistance, float32 max distanceList.resize(largeNumber); - for(usize i = 1; i < largeNumber; i++) + for(usize i = 0; i < largeNumber; i++) { const float32 x = randomCentroids[3 * i]; const float32 y = randomCentroids[3 * i + 1]; diff --git a/src/Plugins/SimplnxCore/test/ComputeFeatureClusteringTest.cpp b/src/Plugins/SimplnxCore/test/ComputeFeatureClusteringTest.cpp index 70f7c727a6..eee1a23524 100644 --- a/src/Plugins/SimplnxCore/test/ComputeFeatureClusteringTest.cpp +++ b/src/Plugins/SimplnxCore/test/ComputeFeatureClusteringTest.cpp @@ -113,7 +113,27 @@ TEST_CASE("SimplnxCore::ComputeFeatureClusteringFilter: Valid Filter Execution", SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result) CompareNeighborLists(dataStructure, k_CellFeatureDataPath.createChildPath(k_ExemplarClusteringList), k_CellFeatureDataPath.createChildPath(k_GeneratedClusteringList)); - CompareArrays(dataStructure, k_CellEnsembleAttributeMatrixPath.createChildPath(k_ExemplarRDF), k_CellEnsembleAttributeMatrixPath.createChildPath(k_GeneratedRDF)); + // The legacy RDF exemplar omits reference pairs involving sample zero (L11 / #1820). + // Correct RDF normalization is checked by the independent closed-form test below. + // The same seed gives the same samples, and the fix only adds reference pairs. So no bin can grow. + // In this data set some of the 999 distances from sample zero fall inside the RDF distance range, + // so at least one bin must shrink. + { + const auto& legacyRdf = dataStructure.getDataRefAs(k_CellEnsembleAttributeMatrixPath.createChildPath(k_ExemplarRDF)); + const auto& generatedRdf = dataStructure.getDataRefAs(k_CellEnsembleAttributeMatrixPath.createChildPath(k_GeneratedRDF)); + REQUIRE(generatedRdf.getSize() == legacyRdf.getSize()); + usize lowerBins = 0; + for(usize i = 0; i < generatedRdf.getSize(); i++) + { + INFO(fmt::format("RDF index {}: generated {} legacy {}", i, generatedRdf[i], legacyRdf[i])); + REQUIRE(generatedRdf[i] <= legacyRdf[i]); + if(generatedRdf[i] < legacyRdf[i]) + { + lowerBins++; + } + } + REQUIRE(lowerBins > 0); + } CompareArrays(dataStructure, k_CellEnsembleAttributeMatrixPath.createChildPath(k_ExemplarMinMaxDistances), k_CellEnsembleAttributeMatrixPath.createChildPath(k_GeneratedMinMaxDistances)); UnitTest::CheckArraysInheritTupleDims(dataStructure); @@ -317,3 +337,50 @@ TEST_CASE("SimplnxCore::ComputeFeatureClustering: positive bin count domain", "[ SIMPLNX_RESULT_REQUIRE_VALID(preflight.outputActions); UnitTest::CheckArraysInheritTupleDims(dataStructure); } + +TEST_CASE("SimplnxCore::ComputeFeatureClusteringFilter: Complete reference pair normalization", "[SimplnxCore][ComputeFeatureClusteringFilter]") +{ + UnitTest::LoadPlugins(); + DataStructure dataStructure; + auto* geometry = ImageGeom::Create(dataStructure, "Image"); + REQUIRE(geometry != nullptr); + geometry->setDimensions({1, 1, 1}); + geometry->setSpacing({1.0f, 1.0f, 1.0f}); + auto* features = AttributeMatrix::Create(dataStructure, "Features", {4}, geometry->getId()); + REQUIRE(features != nullptr); + auto* ensembles = AttributeMatrix::Create(dataStructure, "Ensembles", {2}, geometry->getId()); + REQUIRE(ensembles != nullptr); + auto* phases = Int32Array::CreateWithStore(dataStructure, "Phases", {4}, {1}, features->getId()); + auto* centroids = Float32Array::CreateWithStore(dataStructure, "Centroids", {4}, {3}, features->getId()); + REQUIRE(phases != nullptr); + REQUIRE(centroids != nullptr); + phases->fill(1); + (*phases)[0] = 0; + centroids->fill(0.0f); + (*centroids)[9] = 0.5f; + + ComputeFeatureClusteringFilter filter; + Arguments args = filter.getDefaultArguments(); + args.insertOrAssign(ComputeFeatureClusteringFilter::k_SelectedImageGeometryPath_Key, std::make_any(DataPath({"Image"}))); + args.insertOrAssign(ComputeFeatureClusteringFilter::k_NumberOfBins_Key, std::make_any(1)); + args.insertOrAssign(ComputeFeatureClusteringFilter::k_PhaseNumber_Key, std::make_any(1)); + args.insertOrAssign(ComputeFeatureClusteringFilter::k_RemoveBiasedFeatures_Key, std::make_any(false)); + args.insertOrAssign(ComputeFeatureClusteringFilter::k_SetRandomSeed_Key, std::make_any(true)); + args.insertOrAssign(ComputeFeatureClusteringFilter::k_SeedValue_Key, std::make_any(5489)); + args.insertOrAssign(ComputeFeatureClusteringFilter::k_FeaturePhasesArrayPath_Key, std::make_any(DataPath({"Image", "Features", "Phases"}))); + args.insertOrAssign(ComputeFeatureClusteringFilter::k_CentroidsArrayPath_Key, std::make_any(DataPath({"Image", "Features", "Centroids"}))); + args.insertOrAssign(ComputeFeatureClusteringFilter::k_CellEnsembleAttributeMatrixPath_Key, std::make_any(DataPath({"Image", "Ensembles"}))); + args.insertOrAssign(ComputeFeatureClusteringFilter::k_RDFArrayName_Key, std::make_any("RDF")); + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions) + auto executeResult = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result) + + // Closed form: a one-voxel reference puts all 1000 * 999 ordered pairs at distance zero. + // The three feature distances are 0, 0.5, 0.5. One bin contains all six ordered pairs. + // Its reference probability is 1, so RDF = 6 / (1 * 3 * 2) = 1, independent of seed. + REQUIRE_NOTHROW(dataStructure.getDataRefAs(DataPath({"Image", "Ensembles", "RDF"}))); + const auto& rdf = dataStructure.getDataRefAs(DataPath({"Image", "Ensembles", "RDF"})); + REQUIRE(rdf[1] == Approx(1.0f).margin(1.0e-6f)); + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} From baf638a81eb5562b7ac99773134a2f260ee70a67 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Tue, 3 Nov 2026 18:31:06 -0500 Subject: [PATCH 03/33] BUG: ComputeVectorColors - Color a trend of exactly 360 degrees red A vector with a very small negative Y component has a trend of about -5.7e-7 degrees. After the wrap (trend += 360), float32 rounds it to exactly 360.0, and the last hue branch tested trend < 360, so no branch set a color. A horizontal vector came out black, and other vectors got a gray. DREAM.3D 6.5.171 has the same defect (errata KI-014). The last hue branch now includes 360, which is the same red as 0. Add a test with the vector (1, -1e-8, 0): the trend rounds to 360 and the plunge is 90, so the expected color is pure red (255, 0, 0). Fixes #1908 item L12 Signed-off-by: Michael Jackson --- .../docs/ComputeVectorColorsFilter.md | 2 ++ .../Algorithms/ComputeVectorColors.cpp | 2 +- .../test/ComputeVectorColorsTest.cpp | 35 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Plugins/SimplnxCore/docs/ComputeVectorColorsFilter.md b/src/Plugins/SimplnxCore/docs/ComputeVectorColorsFilter.md index a20d3b26c9..e9af209df6 100644 --- a/src/Plugins/SimplnxCore/docs/ComputeVectorColorsFilter.md +++ b/src/Plugins/SimplnxCore/docs/ComputeVectorColorsFilter.md @@ -12,6 +12,8 @@ This filter generates an RGB color for each **Cell** based on the vector assigne When *Apply to Good Voxels Only* is enabled, the supplied boolean or uint8 **Mask** array marks which **Cells** are valid; **Cells** flagged as bad are left black (RGB 0,0,0) instead of being colored. +A trend that rounds to 360 degrees selects the red hue, the same as 0 degrees. The plunge then blends this hue toward white. For horizontal vectors, this corrects the black output in DREAM3D 6.5.171 to red. + ### Required Input Sources - **Vector Attribute Array** -- a 3-component float32 per-**Cell** vector array. This may come from any filter that produces a per-**Cell** vector field (for example, a dipole, gradient, or orientation-derived vector array). diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeVectorColors.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeVectorColors.cpp index c98e4f54c4..664488f4ac 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeVectorColors.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeVectorColors.cpp @@ -118,7 +118,7 @@ Result<> ComputeVectorColorsInChunks(const AbstractDataStore& vectors, g = 255.0f * ((120.0f - trend) / 120.0f); b = 255.0f * (trend / 120.0f); } - if(trend > 240.0f && trend < 360.0f) + if(trend > 240.0f && trend <= 360.0f) { trend -= 240.0f; r = 255.0f * (trend / 120.0f); diff --git a/src/Plugins/SimplnxCore/test/ComputeVectorColorsTest.cpp b/src/Plugins/SimplnxCore/test/ComputeVectorColorsTest.cpp index e76bc309b2..24369f6289 100644 --- a/src/Plugins/SimplnxCore/test/ComputeVectorColorsTest.cpp +++ b/src/Plugins/SimplnxCore/test/ComputeVectorColorsTest.cpp @@ -27,6 +27,41 @@ DataPath eulerAnglesPath = ebsdPath.createChildPath(Constants::k_EulerAngles); const std::string k_VecColorsNX = "Vector Colors"; } // namespace +TEST_CASE("SimplnxCore::ComputeVectorColorsFilter: Rounded full-turn trend stays red", "[SimplnxCore][ComputeVectorColorsFilter]") +{ + UnitTest::LoadPlugins(); + + DataStructure dataStructure; + const DataPath vectorsPath({"Vectors"}); + auto vectorsStore = DataStoreUtilities::CreateDataStore(dataStructure, vectorsPath, {1}, {3}); + REQUIRE(Float32Array::Create(dataStructure, vectorsPath.getTargetName(), vectorsStore) != nullptr); + const std::array vectors = {1.0f, -1.0e-8f, 0.0f}; + const auto writeResult = vectorsStore->copyFromBuffer(0, nonstd::span(vectors.data(), vectors.size())); + SIMPLNX_RESULT_REQUIRE_VALID(writeResult); + + ComputeVectorColorsFilter filter; + Arguments args; + args.insertOrAssign(ComputeVectorColorsFilter::k_UseMask_Key, std::make_any(false)); + args.insertOrAssign(ComputeVectorColorsFilter::k_VectorsArrayPath_Key, std::make_any(vectorsPath)); + args.insertOrAssign(ComputeVectorColorsFilter::k_CellVectorColorsArrayName_Key, std::make_any(k_VecColorsNX)); + const auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + const auto executeResult = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); + + // Hand calculation: atan2(-1e-8, 1) is about -5.73e-7 degrees. + // Adding 360 rounds to exactly 360 in float32, equivalent to trend 0. + // With Z=0, plunge is 90 degrees: the red endpoint is RGB (255, 0, 0). + const std::array expectedColors = {255, 0, 0}; + const auto* colors = dataStructure.getDataAs(DataPath({k_VecColorsNX})); + REQUIRE(colors != nullptr); + std::array actualColors = {}; + const auto readResult = colors->getDataStoreRef().copyIntoBuffer(0, nonstd::span(actualColors.data(), actualColors.size())); + SIMPLNX_RESULT_REQUIRE_VALID(readResult); + CHECK(actualColors == expectedColors); + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} + TEST_CASE("SimplnxCore::ComputeVectorColorsFilter: Repeated unmasked execution creates only colors", "[SimplnxCore][ComputeVectorColorsFilter]") { UnitTest::LoadPlugins(); From 4eb2444a6e8712295ba444058bf82102e08eead5 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Tue, 3 Nov 2026 18:52:26 -0500 Subject: [PATCH 04/33] BUG: QuickSurfaceMesh - Transfer cell and feature data in Face Labels order For an internal face, Face Labels are swapped so that the smaller Feature Id comes first. The cell and feature data transfer still used the old cell order, so for faces where the cell had the smaller Feature Id the two halves of each transferred array belonged to the wrong sides. Both the Direct and the Scanline algorithm had the error. DREAM.3D 6.5.171 has the same defect (errata KI-007); the output now differs from 6.5.171 on purpose on those faces. Both algorithms now pass the two source cells in the same order as Face Labels: the first N components come from the side of Face Labels[0] and the last N from the side of Face Labels[1]. Add a test with two adjacent cells along X, Y and Z, with ascending and descending Feature Ids, that checks every transferred cell and feature value against the face labels in both algorithms. The existing exemplar archives hold the reversed 6.5.171 values, so the exemplar tests swap the two halves of a face only where the archive's own transferred Feature Ids are exactly reversed; any other mismatch still fails. Fixes #1908 item L23 Signed-off-by: Michael Jackson --- .../docs/QuickSurfaceMeshFilter.md | 5 + .../Algorithms/QuickSurfaceMeshDirect.cpp | 18 ++- .../Algorithms/QuickSurfaceMeshScanline.cpp | 12 +- .../test/QuickSurfaceMeshFilterTest.cpp | 140 ++++++++++++++++++ 4 files changed, 163 insertions(+), 12 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/QuickSurfaceMeshFilter.md b/src/Plugins/SimplnxCore/docs/QuickSurfaceMeshFilter.md index f735d65805..9a3c949d43 100644 --- a/src/Plugins/SimplnxCore/docs/QuickSurfaceMeshFilter.md +++ b/src/Plugins/SimplnxCore/docs/QuickSurfaceMeshFilter.md @@ -28,6 +28,11 @@ The resulting mesh is "blocky" because each triangle aligns with a voxel face. T The user may select any number of **Cell Attribute Arrays** to transfer onto the new **Triangle Geometry**. Each output **Face** inherits the values of the **Cell** it came from. Only scalar and vector arrays can be transferred; multi-dimensional component shapes (e.g., N×M matrices) are not supported. +Selected feature arrays are transferred in the same way. Each **Face** has two sides, so a transferred array +with N components per tuple has 2N components per **Face**. The first N components come from the side of +Face Labels[0]. The last N components come from the side of Face Labels[1]. In DREAM3D 6.5.171, the two +halves were reversed on some internal faces. This filter corrects that, so its output is different there. + ### Face Labels Convention Each triangle gets a 2-component *Face Labels* attribute storing the two Feature IDs on either side of the boundary. The filter guarantees the smaller Feature ID is in component 0, so downstream filters can rely on a consistent ordering. diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/QuickSurfaceMeshDirect.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/QuickSurfaceMeshDirect.cpp index 0ccf70cb84..f6bc812b46 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/QuickSurfaceMeshDirect.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/QuickSurfaceMeshDirect.cpp @@ -1179,9 +1179,11 @@ Result<> QuickSurfaceMeshDirect::createNodesAndTriangles(std::vectorquickSurfaceTransfer(triangleIndex, neigh1, point, faceLabelsStore); + tupleTransferFunction->quickSurfaceTransfer(triangleIndex, firstCell, secondCell, faceLabelsStore); } triangleIndex++; @@ -1201,7 +1203,7 @@ Result<> QuickSurfaceMeshDirect::createNodesAndTriangles(std::vectorquickSurfaceTransfer(triangleIndex, neigh1, point, faceLabelsStore); + tupleTransferFunction->quickSurfaceTransfer(triangleIndex, firstCell, secondCell, faceLabelsStore); } triangleIndex++; @@ -1291,9 +1293,11 @@ Result<> QuickSurfaceMeshDirect::createNodesAndTriangles(std::vectorquickSurfaceTransfer(triangleIndex, neigh2, point, faceLabelsStore); + tupleTransferFunction->quickSurfaceTransfer(triangleIndex, firstCell, secondCell, faceLabelsStore); } triangleIndex++; @@ -1313,7 +1317,7 @@ Result<> QuickSurfaceMeshDirect::createNodesAndTriangles(std::vectorquickSurfaceTransfer(triangleIndex, neigh2, point, faceLabelsStore); + tupleTransferFunction->quickSurfaceTransfer(triangleIndex, firstCell, secondCell, faceLabelsStore); } triangleIndex++; @@ -1403,9 +1407,11 @@ Result<> QuickSurfaceMeshDirect::createNodesAndTriangles(std::vectorquickSurfaceTransfer(triangleIndex, neigh3, point, faceLabelsStore); + tupleTransferFunction->quickSurfaceTransfer(triangleIndex, firstCell, secondCell, faceLabelsStore); } triangleIndex++; @@ -1425,7 +1431,7 @@ Result<> QuickSurfaceMeshDirect::createNodesAndTriangles(std::vectorquickSurfaceTransfer(triangleIndex, neigh3, point, faceLabelsStore); + tupleTransferFunction->quickSurfaceTransfer(triangleIndex, firstCell, secondCell, faceLabelsStore); } triangleIndex++; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/QuickSurfaceMeshScanline.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/QuickSurfaceMeshScanline.cpp index 4df057b92f..0958a98720 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/QuickSurfaceMeshScanline.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/QuickSurfaceMeshScanline.cpp @@ -1453,7 +1453,7 @@ Result<> QuickSurfaceMeshScanline::createNodesAndTriangles(MeshIndexType nodeCou triBuffer.push_back(nid2); faceLabelBuf.push_back(curFeature); faceLabelBuf.push_back(neigh1Feature); - ttArgsBuf.push_back({triangleIndex, neigh1, point, curFeature, neigh1Feature}); + ttArgsBuf.push_back({triangleIndex, point, neigh1, curFeature, neigh1Feature}); } else { @@ -1472,7 +1472,7 @@ Result<> QuickSurfaceMeshScanline::createNodesAndTriangles(MeshIndexType nodeCou triBuffer.push_back(nid4); faceLabelBuf.push_back(curFeature); faceLabelBuf.push_back(neigh1Feature); - ttArgsBuf.push_back({triangleIndex, neigh1, point, curFeature, neigh1Feature}); + ttArgsBuf.push_back({triangleIndex, point, neigh1, curFeature, neigh1Feature}); } else { @@ -1560,7 +1560,7 @@ Result<> QuickSurfaceMeshScanline::createNodesAndTriangles(MeshIndexType nodeCou triBuffer.push_back(nid3); faceLabelBuf.push_back(curFeature); faceLabelBuf.push_back(neigh2Feature); - ttArgsBuf.push_back({triangleIndex, neigh2, point, curFeature, neigh2Feature}); + ttArgsBuf.push_back({triangleIndex, point, neigh2, curFeature, neigh2Feature}); } else { @@ -1579,7 +1579,7 @@ Result<> QuickSurfaceMeshScanline::createNodesAndTriangles(MeshIndexType nodeCou triBuffer.push_back(nid3); faceLabelBuf.push_back(curFeature); faceLabelBuf.push_back(neigh2Feature); - ttArgsBuf.push_back({triangleIndex, neigh2, point, curFeature, neigh2Feature}); + ttArgsBuf.push_back({triangleIndex, point, neigh2, curFeature, neigh2Feature}); } else { @@ -1667,7 +1667,7 @@ Result<> QuickSurfaceMeshScanline::createNodesAndTriangles(MeshIndexType nodeCou triBuffer.push_back(nid2); faceLabelBuf.push_back(curFeature); faceLabelBuf.push_back(neigh3Feature); - ttArgsBuf.push_back({triangleIndex, neigh3, point, curFeature, neigh3Feature}); + ttArgsBuf.push_back({triangleIndex, point, neigh3, curFeature, neigh3Feature}); } else { @@ -1686,7 +1686,7 @@ Result<> QuickSurfaceMeshScanline::createNodesAndTriangles(MeshIndexType nodeCou triBuffer.push_back(nid4); faceLabelBuf.push_back(curFeature); faceLabelBuf.push_back(neigh3Feature); - ttArgsBuf.push_back({triangleIndex, neigh3, point, curFeature, neigh3Feature}); + ttArgsBuf.push_back({triangleIndex, point, neigh3, curFeature, neigh3Feature}); } else { diff --git a/src/Plugins/SimplnxCore/test/QuickSurfaceMeshFilterTest.cpp b/src/Plugins/SimplnxCore/test/QuickSurfaceMeshFilterTest.cpp index 899ff7c195..ea9577fce1 100644 --- a/src/Plugins/SimplnxCore/test/QuickSurfaceMeshFilterTest.cpp +++ b/src/Plugins/SimplnxCore/test/QuickSurfaceMeshFilterTest.cpp @@ -114,6 +114,52 @@ void RequirePreflightWithoutCellAttributeMatrix(UnitTest::AlgorithmTestScope* al } UnitTest::CheckArraysInheritTupleDims(dataStructure); } + +struct SwapExemplarSides +{ + template + void operator()(IDataArray& array, usize face) const + { + auto& typed = dynamic_cast&>(array); + const usize components = typed.getNumberOfComponents() / 2; + for(usize component = 0; component < components; component++) + { + const usize first = face * components * 2 + component; + const usize second = first + components; + const T value = typed[first]; + typed[first] = typed[second]; + typed[second] = value; + } + } +}; + +void CorrectLegacyExemplarTransferOrder(DataStructure& dataStructure, const DataPath& facePath) +{ + // The legacy exemplar transferred FeatureIds record the source side of every transferred tuple. + // Use those IDs, independently of the computed mesh, to align all exemplar tuples with Face Labels. + REQUIRE_NOTHROW(dataStructure.getDataRefAs(facePath.createChildPath(k_FeatureIds))); + REQUIRE_NOTHROW(dataStructure.getDataRefAs(facePath.createChildPath(k_Face_Labels))); + const auto& ids = dataStructure.getDataRefAs(facePath.createChildPath(k_FeatureIds)); + const auto& labels = dataStructure.getDataRefAs(facePath.createChildPath(k_Face_Labels)); + auto& faces = dataStructure.getDataRefAs(facePath); + for(usize face = 0; face < labels.getNumberOfTuples(); face++) + { + if(labels[2 * face] >= 0 && labels[2 * face + 1] >= 0 && ids[2 * face] != labels[2 * face]) + { + REQUIRE(ids[2 * face] == labels[2 * face + 1]); + REQUIRE(ids[2 * face + 1] == labels[2 * face]); + for(const auto& [id, object] : faces) + { + if(object->getName() != k_Face_Labels) + { + auto* array = dynamic_cast(object.get()); + REQUIRE(array != nullptr); + ExecuteDataFunction(SwapExemplarSides{}, array->getDataType(), *array, face); + } + } + } + } +} } // namespace TEST_CASE("SimplnxCore::QuickSurfaceMeshFilter: Image Geometry without a Cell Attribute Matrix", "[SimplnxCore][QuickSurfaceMeshFilter]") @@ -129,6 +175,96 @@ TEST_CASE("SimplnxCore::QuickSurfaceMeshFilter: Rectilinear Grid without a Cell RequirePreflightWithoutCellAttributeMatrix(); } +TEST_CASE("SimplnxCore::QuickSurfaceMeshFilter: Transferred sides match face labels", "[SimplnxCore][QuickSurfaceMeshFilter]") +{ + UnitTest::LoadPlugins(); + const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); + const usize axis = GENERATE(0, 1, 2); + const bool ascending = GENERATE(false, true); + CAPTURE(scenario, axis, ascending); + UnitTest::AlgorithmTestScope scope(scenario); + + DataStructure dataStructure; + auto* image = ImageGeom::Create(dataStructure, "Image"); + REQUIRE(image != nullptr); + SizeVec3 dims = {1, 1, 1}; + dims[axis] = 2; + image->setDimensions(dims); + image->setOrigin({0, 0, 0}); + image->setSpacing({1, 1, 1}); + const ShapeType shape = {dims[2], dims[1], dims[0]}; + auto* cells = AttributeMatrix::Create(dataStructure, "Cells", shape, image->getId()); + REQUIRE(cells != nullptr); + image->setCellData(cells->getId()); + auto* ids = Int32Array::CreateWithStore>(dataStructure, "Ids", shape, {1}, cells->getId()); + auto* values = Int32Array::CreateWithStore>(dataStructure, "Cell Values", shape, {2}, cells->getId()); + auto* features = AttributeMatrix::Create(dataStructure, "Features", {3}, image->getId()); + REQUIRE(features != nullptr); + auto* featureValues = Int32Array::CreateWithStore>(dataStructure, "Feature Values", {3}, {2}, features->getId()); + REQUIRE(ids != nullptr); + REQUIRE(values != nullptr); + REQUIRE(featureValues != nullptr); + // Independent oracle: feature f owns cell tuple (10*f, 10*f+1) and feature tuple (100*f, 100*f+1). + // Two adjacent unit cubes have exactly two internal triangles, each with labels (1, 2). + for(usize cell = 0; cell < 2; cell++) + { + const int32 id = ascending ? static_cast(cell + 1) : static_cast(2 - cell); + (*ids)[cell] = id; + for(usize component = 0; component < 2; component++) + { + (*values)[2 * cell + component] = 10 * id + static_cast(component); + } + } + for(usize f = 0; f < 3; f++) + { + (*featureValues)[2 * f] = static_cast(100 * f); + (*featureValues)[2 * f + 1] = static_cast(100 * f + 1); + } + QuickSurfaceMeshFilter filter; + Arguments args; + args.insertOrAssign(QuickSurfaceMeshFilter::k_GridGeometryDataPath_Key, std::make_any(DataPath({"Image"}))); + args.insertOrAssign(QuickSurfaceMeshFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(DataPath({"Image", "Cells", "Ids"}))); + args.insertOrAssign(QuickSurfaceMeshFilter::k_SelectedDataArrayPaths_Key, + std::make_any(MultiArraySelectionParameter::ValueType{DataPath({"Image", "Cells", "Cell Values"})})); + args.insertOrAssign(QuickSurfaceMeshFilter::k_SelectedFeatureDataArrayPaths_Key, + std::make_any(MultiArraySelectionParameter::ValueType{DataPath({"Image", "Features", "Feature Values"})})); + args.insertOrAssign(QuickSurfaceMeshFilter::k_FixProblemVoxels_Key, std::make_any(false)); + args.insertOrAssign(QuickSurfaceMeshFilter::k_RepairTriangleWinding_Key, std::make_any(false)); + args.insertOrAssign(QuickSurfaceMeshFilter::k_CreatedTriangleGeometryPath_Key, std::make_any(DataPath({"Mesh"}))); + args.insertOrAssign(QuickSurfaceMeshFilter::k_FaceDataGroupName_Key, std::make_any("Faces")); + auto result = scope.executeFilter(filter, dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + const DataPath facePath({"Mesh", "Faces"}); + REQUIRE_NOTHROW(dataStructure.getDataRefAs(facePath.createChildPath("FaceLabels"))); + REQUIRE_NOTHROW(dataStructure.getDataRefAs(facePath.createChildPath("Cell Values"))); + REQUIRE_NOTHROW(dataStructure.getDataRefAs(facePath.createChildPath("Feature Values"))); + const auto& labels = dataStructure.getDataRefAs(facePath.createChildPath("FaceLabels")); + const auto& transferredCells = dataStructure.getDataRefAs(facePath.createChildPath("Cell Values")); + const auto& transferredFeatures = dataStructure.getDataRefAs(facePath.createChildPath("Feature Values")); + usize internalFaces = 0; + for(usize face = 0; face < labels.getNumberOfTuples(); face++) + { + if(labels[2 * face] >= 0 && labels[2 * face + 1] >= 0) + { + internalFaces++; + CHECK(labels[2 * face] == 1); + CHECK(labels[2 * face + 1] == 2); + } + for(usize side = 0; side < 2; side++) + { + const int32 label = labels[2 * face + side]; + for(usize component = 0; component < 2; component++) + { + const usize index = 4 * face + 2 * side + component; + CHECK(transferredCells[index] == (label == -1 ? 0 : 10 * label + static_cast(component))); + CHECK(transferredFeatures[index] == (label == -1 ? 0 : 100 * label + static_cast(component))); + } + } + } + CHECK(internalFaces == 2); + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} + TEST_CASE("SimplnxCore::QuickSurfaceMeshFilter: Preserve winding and pruning warnings", "[SimplnxCore][QuickSurfaceMeshFilter]") { UnitTest::LoadPlugins(); @@ -303,6 +439,7 @@ TEST_CASE("SimplnxCore::QuickSurfaceMeshFilter", "[SimplnxCore][QuickSurfaceMesh CompareArrays(dataStructure, exemplarSharedVertexPath, computedTriangleGeomPath.createChildPath(TriangleGeom::k_SharedVertexListName)); DataPath exemplarFaceAttrMatPath = exemplarTriangleGeomPath.createChildPath(k_FaceDataGroupName); + CorrectLegacyExemplarTransferOrder(dataStructure, exemplarFaceAttrMatPath); CompareExemplarToGenerateAttributeMatrix(dataStructure, exemplarFaceAttrMatPath, dataStructure, faceGroupDataPath, true); DataPath exemplarVertexAttrMatPath = exemplarTriangleGeomPath.createChildPath(k_VertexDataGroupName); @@ -400,6 +537,7 @@ TEST_CASE("SimplnxCore::QuickSurfaceMeshFilter: Winding", "[SimplnxCore][QuickSu CompareArrays(dataStructure, computedTriangleGeomPath.createChildPath(TriangleGeom::k_SharedVertexListName), exemplarSharedVertexPath); DataPath exemplarFaceAttrMatPath = exemplarTriangleGeomPath.createChildPath(k_FaceDataGroupName); + CorrectLegacyExemplarTransferOrder(dataStructure, exemplarFaceAttrMatPath); CompareExemplarToGenerateAttributeMatrix(dataStructure, exemplarFaceAttrMatPath, dataStructure, faceGroupDataPath, true); DataPath exemplarVertexAttrMatPath = exemplarTriangleGeomPath.createChildPath(k_VertexDataGroupName); @@ -497,6 +635,7 @@ TEST_CASE("SimplnxCore::QuickSurfaceMeshFilter: Problem Voxels", "[SimplnxCore][ CompareArrays(dataStructure, computedTriangleGeomPath.createChildPath(TriangleGeom::k_SharedVertexListName), exemplarSharedVertexPath); DataPath exemplarFaceAttrMatPath = exemplarTriangleGeomPath.createChildPath(k_FaceDataGroupName); + CorrectLegacyExemplarTransferOrder(dataStructure, exemplarFaceAttrMatPath); CompareExemplarToGenerateAttributeMatrix(dataStructure, exemplarFaceAttrMatPath, dataStructure, faceGroupDataPath, true); DataPath exemplarVertexAttrMatPath = exemplarTriangleGeomPath.createChildPath(k_VertexDataGroupName); @@ -594,6 +733,7 @@ TEST_CASE("SimplnxCore::QuickSurfaceMeshFilter: Winding and Problem Voxels", "[S CompareArrays(dataStructure, computedTriangleGeomPath.createChildPath(TriangleGeom::k_SharedVertexListName), exemplarSharedVertexPath); DataPath exemplarFaceAttrMatPath = exemplarTriangleGeomPath.createChildPath(k_FaceDataGroupName); + CorrectLegacyExemplarTransferOrder(dataStructure, exemplarFaceAttrMatPath); CompareExemplarToGenerateAttributeMatrix(dataStructure, exemplarFaceAttrMatPath, dataStructure, faceGroupDataPath, true); DataPath exemplarVertexAttrMatPath = exemplarTriangleGeomPath.createChildPath(k_VertexDataGroupName); From 19acd18fc426bdb7f4a7342b9550c1ee9ff7f378 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Tue, 3 Nov 2026 19:14:23 -0500 Subject: [PATCH 05/33] BUG: ImageRotationUtilities - Take grid-rotation output spacing from the source axis of each output axis CreateRotationArgs chose the spacing of each output axis from a column of the rotation matrix. A column shows where an input axis lands, but the spacing of an output axis comes from the input axis that maps to it, which is a row of the matrix. For two-axis swaps both give the same answer, but for three-axis cycles (for example 120 degrees about <111>) on anisotropic data, Rotate Sample Reference Frame produced the wrong spacing and dimensions. DREAM.3D 6.5.171 has the same defect (errata KI-008); the output now differs from 6.5.171 on purpose (V&V deviation D2). For grid rotations (signed permutation matrices, with or without a scale per axis) the output spacing now comes from the matrix rows, and each input spacing is first multiplied by the norm of its matrix column, so a scale stays with its source axis. The grid test accepts every matrix that Rotate Sample Reference Frame accepts (tolerance 1e-4 on the raw entries, t/(1-t) after normalizing each column). All other transformations (off-axis rotations, possibly with non-uniform scaling) keep the earlier column-based spacing rule unchanged. Write OnScale Table File no longer fails with -12041 for these rotations; the check stays as a guard with a corrected message. Add a RotateSampleRefFrame test with a 120 degree rotation of a 2x3x4 grid with spacing (2,3,5) that checks dimensions, spacing and every value against the closed form; helper tests for a scaled, reflected three-cycle, for near-grid three-cycles at the tolerance limit, and for an off-axis 45 degree rotation with scale (2,1,1) that keeps the column-based result. The OnScale test now expects a successful export. Fixes #1908 item L28 Signed-off-by: Michael Jackson --- .../docs/RotateSampleRefFrameFilter.md | 2 + .../docs/WriteOnScaleTableFileFilter.md | 2 +- .../Algorithms/WriteOnScaleTableFile.cpp | 12 +- .../test/RotateSampleRefFrameTest.cpp | 38 ++++++ .../test/WriteOnScaleTableFileTest.cpp | 19 +-- .../vv/RotateSampleRefFrameFilter.md | 15 ++- .../deviations/RotateSampleRefFrameFilter.md | 11 +- .../provenance/RotateSampleRefFrameFilter.md | 6 + .../Utilities/ImageRotationUtilities.cpp | 56 ++++++++- test/ImageRotationUtilitiesTest.cpp | 119 ++++++++++++++++++ 10 files changed, 256 insertions(+), 24 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/RotateSampleRefFrameFilter.md b/src/Plugins/SimplnxCore/docs/RotateSampleRefFrameFilter.md index 52134fcaf6..6a31a158bc 100644 --- a/src/Plugins/SimplnxCore/docs/RotateSampleRefFrameFilter.md +++ b/src/Plugins/SimplnxCore/docs/RotateSampleRefFrameFilter.md @@ -42,6 +42,8 @@ The *Perform Slice By Slice Transform* option applies the rotation independently ## Notes +Spacing follows the source axis for each output axis. For example, a 120 degree rotation about (111) maps (x,y,z) to (z,x,y). Input spacing (2,3,5) becomes (5,2,3). This corrects DREAM3D 6.5.171 errata KI-008. The output intentionally differs from 6.5.171 for affected anisotropic rotations. + The rotation will most likely produce an origin that differs from the input geometry's origin (the transformed bounding box is repositioned). The *Keep Input Geometry's Origin* option preserves the original origin instead; by default it is OFF and the transform-derived origin is used. To reset the origin and spacing afterward, use the [Set Origin & Spacing](SetImageGeomOriginScalingFilter.md) filter. ## Example diff --git a/src/Plugins/SimplnxCore/docs/WriteOnScaleTableFileFilter.md b/src/Plugins/SimplnxCore/docs/WriteOnScaleTableFileFilter.md index 3ee712a04e..e563727ddc 100644 --- a/src/Plugins/SimplnxCore/docs/WriteOnScaleTableFileFilter.md +++ b/src/Plugins/SimplnxCore/docs/WriteOnScaleTableFileFilter.md @@ -46,7 +46,7 @@ The `name` data line in the generated file ends with one ASCII space after `Phas The legacy DREAM.3D exporter required dimensions in non-increasing order (X >= Y >= Z), and this filter keeps that rule. If an **Image Geometry** does not have this order, the filter determines the required 90-degree axis rotations and runs the Rotate Sample Reference Frame **Filter** internally. The exported dimensions, spacing, origin, and feature IDs come from the reordered copy. The input **Data Structure** does not change. -The filter validates two-axis reorders after rotation and reports an error if the rotated dimensions are not the sorted input dimensions. This problem occurs with anisotropic spacing because of a limitation in the current Rotate Sample Reference Frame implementation; resample to isotropic spacing or reorder the axes before this filter. +Two-axis reorders preserve anisotropic spacing and all cells. This corrects DREAM3D 6.5.171 errata KI-008. The filter still checks that the rotated dimensions match the sorted input dimensions before export. A **Rectilinear Grid Geometry** with dimensions that require reordering is not supported. The filter rejects this geometry during preflight because a 90-degree image rotation cannot preserve its non-uniform bounds arrays. diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteOnScaleTableFile.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteOnScaleTableFile.cpp index 5a65b1b4ad..92f837ae72 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteOnScaleTableFile.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteOnScaleTableFile.cpp @@ -370,15 +370,13 @@ Result<> WriteOnScaleTableFile::operator()() const SizeVec3 reorderedDimensions = exportGeometry->getDimensions(); SizeVec3 expectedDimensions = inputDimensions; std::sort(expectedDimensions.begin(), expectedDimensions.end(), std::greater()); - // ImageRotationUtilities::CreateRotationArgs selects output spacing from matrix columns, which show where each old axis lands. - // New-axis spacing requires matrix rows, or equivalently the columns of the transposed matrix. + // Check that the rotation preserved the intended axis permutation before exporting. if(reorderedDimensions != expectedDimensions) { - return MakeErrorResult( - k_UnexpectedReorderedDimensionsError, - fmt::format("Rotate Sample Reference Frame produced dimensions ({}) for geometry '{}' but the OnScale reorder expected ({}). This happens for two-axis reorders of geometries with " - "anisotropic spacing because the rotation utility assigns output spacing from the wrong matrix axis. Resample to isotropic spacing or reorder the axes before this filter.", - StringUtilities::formatDimensions3D(reorderedDimensions), m_InputValues->InputGeometryPath.toString(), StringUtilities::formatDimensions3D(expectedDimensions))); + return MakeErrorResult(k_UnexpectedReorderedDimensionsError, fmt::format("Rotate Sample Reference Frame produced dimensions ({}) for geometry '{}' but the OnScale reorder expected ({}). " + "The rotated geometry cannot be exported with the required axis order.", + StringUtilities::formatDimensions3D(reorderedDimensions), m_InputValues->InputGeometryPath.toString(), + StringUtilities::formatDimensions3D(expectedDimensions))); } exportFeatureIds = &rotatedDataStructure.getDataRefAs(k_ScratchCellDataPath.createChildPath(inputFeatureIds.getName())); m_MessageHandler.sendInfoMessage( diff --git a/src/Plugins/SimplnxCore/test/RotateSampleRefFrameTest.cpp b/src/Plugins/SimplnxCore/test/RotateSampleRefFrameTest.cpp index 575beaf8e4..3ed2c9fed6 100644 --- a/src/Plugins/SimplnxCore/test/RotateSampleRefFrameTest.cpp +++ b/src/Plugins/SimplnxCore/test/RotateSampleRefFrameTest.cpp @@ -810,3 +810,41 @@ TEST_CASE("SimplnxCore::RotateSampleRefFrame: Child names containing the geometr } UnitTest::CheckArraysInheritTupleDims(dataStructure); } + +TEST_CASE("SimplnxCore::RotateSampleRefFrame: anisotropic three-cycle preserves the voxel grid", "[SimplnxCore][RotateSampleRefFrameFilter]") +{ + const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); + CAPTURE(scenario); + UnitTest::AlgorithmTestScope algorithmTestScope(scenario); + DataStructure dataStructure; + CreateSequentialImageGeom(dataStructure, "Input", {2, 3, 4}, {2.0F, 3.0F, 5.0F}); + RotateSampleRefFrameFilter filter; + Arguments args = MakeAxisAngleArgs(k_InputPath, k_OutputPath, {1.0F, 1.0F, 1.0F, 120.0F}); + // Closed-form oracle: R(x,y,z)=(z,x,y). Thus dimensions (2,3,4) and + // spacing (2,3,5) become (4,2,3) and (5,2,3). Output (i,j,k) samples + // input (j,k,i), whose sequential value is 1 + j + 2*k + 6*i. + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + auto executeResult = algorithmTestScope.executeFilter(filter, dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); + const ImageGeom* output = nullptr; + REQUIRE_NOTHROW(output = &dataStructure.getDataRefAs(k_OutputPath)); + CHECK(output->getDimensions() == SizeVec3{4, 2, 3}); + for(usize axis = 0; axis < 3; axis++) + { + CHECK(output->getSpacing()[axis] == Approx(FloatVec3{5.0F, 2.0F, 3.0F}[axis])); + } + const auto values = ReadOutputValues(dataStructure, k_OutputPath); + REQUIRE(values.size() == 24); + for(usize k = 0; k < 3; k++) + { + for(usize j = 0; j < 2; j++) + { + for(usize i = 0; i < 4; i++) + { + CHECK(values[i + 4 * j + 8 * k] == static_cast(1 + j + 2 * k + 6 * i)); + } + } + } + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} diff --git a/src/Plugins/SimplnxCore/test/WriteOnScaleTableFileTest.cpp b/src/Plugins/SimplnxCore/test/WriteOnScaleTableFileTest.cpp index f599aaed93..f1f62a4938 100644 --- a/src/Plugins/SimplnxCore/test/WriteOnScaleTableFileTest.cpp +++ b/src/Plugins/SimplnxCore/test/WriteOnScaleTableFileTest.cpp @@ -562,9 +562,12 @@ TEST_CASE("SimplnxCore::WriteOnScaleTableFileFilter: Reorders Z Then X", "[Simpl RequireReorderedExportMatchesRotation({2, 4, 3}, compositeRotation, outputPath, "OnScale_Reordered_ZX"); } -TEST_CASE("SimplnxCore::WriteOnScaleTableFileFilter: Anisotropic Two Axis Reorder Fails Loudly", "[SimplnxCore][WriteOnScaleTableFileFilter]") +TEST_CASE("SimplnxCore::WriteOnScaleTableFileFilter: Anisotropic Two Axis Reorder Preserves Cells", "[SimplnxCore][WriteOnScaleTableFileFilter]") { UnitTest::LoadPlugins(); + const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); + CAPTURE(scenario); + UnitTest::AlgorithmTestScope algorithmTestScope(scenario); std::vector featureIds(24); std::iota(featureIds.begin(), featureIds.end(), 1); @@ -574,12 +577,14 @@ TEST_CASE("SimplnxCore::WriteOnScaleTableFileFilter: Anisotropic Two Axis Reorde fs::create_directories(outputPath); const WriteOnScaleTableFileFilter filter; - auto executeResult = filter.execute(dataStructure, CreateArguments(outputPath, "OnScale_Anisotropic_Two_Axis")); - REQUIRE(executeResult.result.invalid()); - REQUIRE(executeResult.result.errors().front().code == -12041); - REQUIRE(executeResult.result.errors().front().message.find("produced dimensions (Z=1, Y=9, X=3)") != std::string::npos); - REQUIRE(executeResult.result.errors().front().message.find("expected (Z=2, Y=3, X=4)") != std::string::npos); - REQUIRE_FALSE(fs::exists(outputPath / "OnScale_Anisotropic_Two_Axis.flxtbl")); + auto executeResult = algorithmTestScope.executeFilter(filter, dataStructure, CreateArguments(outputPath, "OnScale_Anisotropic_Two_Axis")); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); + const std::string contents = ReadFile(outputPath / "OnScale_Anisotropic_Two_Axis.flxtbl"); + // Rx * Rz maps (x,y,z) to (-y,-z,x). Dimensions become (4,3,2). + // Output (i,j,k) samples input (k,3-i,2-j), giving 1+k+2*(3-i)+8*(2-j). + REQUIRE(contents.find("divisions\n4 3 2\n") != std::string::npos); + REQUIRE(ExtractMatrBlock(contents) == "23 21 19 17 15 13 11 9 7 5 3 1 24 22 20 18 16 14 12 10 8 6 4 2"); + RequireFeatureIdMultiset(ExtractMatrBlock(contents), featureIds); UnitTest::CheckArraysInheritTupleDims(dataStructure); } diff --git a/src/Plugins/SimplnxCore/vv/RotateSampleRefFrameFilter.md b/src/Plugins/SimplnxCore/vv/RotateSampleRefFrameFilter.md index 4cbc017cdb..4f591f3b19 100644 --- a/src/Plugins/SimplnxCore/vv/RotateSampleRefFrameFilter.md +++ b/src/Plugins/SimplnxCore/vv/RotateSampleRefFrameFilter.md @@ -19,8 +19,8 @@ | Code paths enumerated | 11 (filter preflight guard + geometry setup, and the NN-resample execute). 10 of 12 exercised. | | Tests today | 12 registered cases plus one hidden HDF5 boundary test. Paired CTest selections pass 12/12. | | Exemplar archive | **`Rotate_Sample_Ref_Frame_Test_v2/v3.tar.gz` retired** — golden-file (regression) oracle replaced by an inlined Class 1 analytical oracle. No archive is downloaded. See `vv/provenance/RotateSampleRefFrameFilter.md`. | -| Legacy comparison | **Run** (SIMPLNX vs 6.5.171) on four principal-90 fixtures (90@Z, 180@Z, 90@X, 180@Y): **bit-identical** — same dims and same voxel values. 1 deviation, on the *unsupported* arbitrary-rotation domain only. | -| Bug flags | None. The single deviation (D1) is an intentional guard, not a bug. | +| Legacy comparison | **Run** (SIMPLNX vs 6.5.171) on four isotropic principal-90 fixtures (90@Z, 180@Z, 90@X, 180@Y): **bit-identical** dims and voxel values. Two documented deviations: D1 rejects unsupported rotations; D2 corrects anisotropic three-cycle spacing (analytical evidence, no new legacy binary comparison). | +| Bug flags | KI-008 / L28 corrected (D2). D1 is an intentional guard. | | V&V phase | Historical status and sign-off retained. Section 4.3 adds real-HDF5 boundary verification and paired CTest evidence. | ## Summary @@ -100,6 +100,15 @@ OOC recertification (2026-09-21): serial CTest passed 12/12 target entries in ea ## Deviations from DREAM3D 6.5.171 -Comparison run on four principal-90 fixtures (90@Z, 180@Z, 90@X, 180@Y) — see `vv/comparisons/RotateSampleRefFrameFilter/results.md`. On the supported domain, **no deviations** (bit-identical dims and voxel values). One deviation on the unsupported domain: +Comparison run on four principal-90 fixtures (90@Z, 180@Z, 90@X, 180@Y) — see `vv/comparisons/RotateSampleRefFrameFilter/results.md`. These four isotropic fixtures have bit-identical dims and voxel values. They do not cover anisotropic three-cycle rotations. The documented deviations are: - `RotateSampleRefFrameFilter-D1` — legacy silently runs arbitrary (non-principal-90) rotations as a lossy resample; SIMPLNX rejects them in preflight (`-6850`). Root cause: algorithmic choice (intentional; not a bug). See `vv/deviations/RotateSampleRefFrameFilter.md`. +- `RotateSampleRefFrameFilter-D2` — corrected spacing and dimensions for anisotropic three-cycle rotations (KI-008 / L28). Independent analytical tests cover both algorithms on in-memory stores. No new legacy binary comparison was run. See `vv/deviations/RotateSampleRefFrameFilter.md`. + +## Bugs found and fixed: errata KI-008 (L28) + +`SimplnxCore::RotateSampleRefFrame: anisotropic three-cycle preserves the voxel grid` uses an inline analytical oracle. The map R(x,y,z)=(z,x,y) sends dimensions (2,3,4) to (4,2,3) and spacing (2,3,5) to (5,2,3). Output (i,j,k) has value 1+j+2*k+6*i. The test checks every cell in Direct and Scanline paths on in-memory stores. No exemplar is used. + +Test sensitivity verification: before the fix, both paths returned dimensions (7,1,5), spacing (3,5,2), and 35 cells instead of 24. For grid rotations (signed axis permutations), the shared helper now selects spacing from matrix rows and applies the selected source axis scale. Other transformations keep the earlier spacing rule. This intentionally corrects DREAM3D 6.5.171 behavior; see `RotateSampleRefFrameFilter-D2`. No new legacy binary comparison or disk-backed OOC validation is claimed. + +To repeat the L28 check, run the `SimplnxCore::RotateSampleRefFrame` CTest entries serially. The historical A/B results above are unchanged and apply only to their four fixtures. diff --git a/src/Plugins/SimplnxCore/vv/deviations/RotateSampleRefFrameFilter.md b/src/Plugins/SimplnxCore/vv/deviations/RotateSampleRefFrameFilter.md index 2e79c0da0f..51c4af47b6 100644 --- a/src/Plugins/SimplnxCore/vv/deviations/RotateSampleRefFrameFilter.md +++ b/src/Plugins/SimplnxCore/vv/deviations/RotateSampleRefFrameFilter.md @@ -4,7 +4,7 @@ This file lists every documented behavioral difference between this SIMPLNX filt Entries are referenced by stable ID (`RotateSampleRefFrameFilter-D`) from the V&V report and from public migration guidance. The ID is stable across renames; the Filter UUID field is the permanent cross-reference anchor. -Legacy equivalent: `RotateSampleRefFrame` (SIMPL UUID `{e25d9b4c-2b37-578c-b1de-cf7032b5ef19}`) in the Sampling plugin. On the **supported domain** (a 90/180/270-degree rotation about the X, Y, or Z axis) SIMPLNX and 6.5.171 are **bit-identical** — same output dimensions and same voxel values on all four A/B fixtures (see `../comparisons/RotateSampleRefFrameFilter/results.md`). The single deviation below is about rotations *outside* that domain. +Legacy equivalent: `RotateSampleRefFrame` (SIMPL UUID `{e25d9b4c-2b37-578c-b1de-cf7032b5ef19}`) in the Sampling plugin. On the **supported domain** (a 90/180/270-degree rotation about the X, Y, or Z axis) SIMPLNX and 6.5.171 are **bit-identical** — same output dimensions and same voxel values on all four A/B fixtures (see `../comparisons/RotateSampleRefFrameFilter/results.md`). Those four isotropic fixtures do not cover anisotropic three-cycle rotations. The deviations below include that correction. --- @@ -25,3 +25,12 @@ Legacy equivalent: `RotateSampleRefFrame` (SIMPL UUID `{e25d9b4c-2b37-578c-b1de- **Blast radius — internal callers.** `ReadH5Ebsd` (`ReadH5Ebsd.cpp`) forwards the sample-reference-frame transform stored in the `.h5ebsd` file directly into this filter with slice-by-slice enabled, and propagates preflight errors. If a file's *recommended* sample transform is not a lossless, Z-preserving rotation (for example a stored 90° about X, which trips `-6851`, or any non-group angle, which trips `-6850`), the entire H5EBSD import now fails preflight with an error naming a filter the user never placed. The prior behavior was a silently corrupted (slice-pinned) import, so failing loudly is arguably correct, but the message can be confusing in that context. The practical workaround is to uncheck *Use Recommended Transformations* in `ReadH5Ebsd` (or apply the transform separately). This is called out here so the failure mode is documented rather than surprising. **Recommendation:** Trust SIMPLNX. For an arbitrary rotation with interpolation, use the `Apply Transformation To Geometry` filter, which is designed for lossy resampling rotations (nearest-neighbor or trilinear). The legacy result for a lossy rotation was a silent lossy resample, not a faithful reference-frame rotation. For H5EBSD imports whose recommended transform is lossy, uncheck *Use Recommended Transformations* in `ReadH5Ebsd`. + +## RotateSampleRefFrameFilter-D2 + +- **Filter UUID:** `d2451dc1-a5a1-4ac2-a64d-7991669dcffc` +- **Status:** active +- **Symptom:** DREAM3D 6.5.171 errata KI-008 assigns spacing from the wrong source axis for three-cycle rotations. Anisotropic output spacing and dimensions are wrong. +- **Correction:** Select the source axis from each output matrix row. For R(x,y,z)=(z,x,y), spacing (2,3,5) becomes (5,2,3). +- **Evidence:** The inline analytical regression checks dimensions and every voxel in both Direct and Scanline paths. Both paths failed before the fix. No new legacy binary comparison was run. +- **Recommendation:** Use the corrected output. Affected anisotropic rotations intentionally differ from DREAM3D 6.5.171. diff --git a/src/Plugins/SimplnxCore/vv/provenance/RotateSampleRefFrameFilter.md b/src/Plugins/SimplnxCore/vv/provenance/RotateSampleRefFrameFilter.md index 841a78a682..11f48889e6 100644 --- a/src/Plugins/SimplnxCore/vv/provenance/RotateSampleRefFrameFilter.md +++ b/src/Plugins/SimplnxCore/vv/provenance/RotateSampleRefFrameFilter.md @@ -42,3 +42,9 @@ These A/B artifacts are working files, not a test-consumed archive; they are kep ## Regenerated to fix a circular-oracle situation? Yes — this replaces the retired `Rotate_Sample_Ref_Frame_Test_v2/v3.tar.gz` golden-file archives with an independently-derived Class 1 analytical oracle. The new oracle is *not* derived from SIMPLNX (or legacy) output; it is hand-derived from the definition of a principal-90 reference-frame rotation. + +## Errata KI-008 regression (L28) + +`SimplnxCore::RotateSampleRefFrame: anisotropic three-cycle preserves the voxel grid` uses an inline analytical oracle. The map R(x,y,z)=(z,x,y) sends dimensions (2,3,4) to (4,2,3) and spacing (2,3,5) to (5,2,3). Output (i,j,k) has value 1+j+2*k+6*i. The test checks every cell in Direct and Scanline paths on in-memory stores. No exemplar is used. + +Test sensitivity verification: before the fix, both paths returned dimensions (7,1,5), spacing (3,5,2), and 35 cells instead of 24. For grid rotations (signed axis permutations), the shared helper now selects spacing from matrix rows and applies the selected source axis scale. Other transformations keep the earlier spacing rule. This intentionally corrects DREAM3D 6.5.171 behavior; see `RotateSampleRefFrameFilter-D2`. No new legacy binary comparison or disk-backed OOC validation is claimed. diff --git a/src/simplnx/Utilities/ImageRotationUtilities.cpp b/src/simplnx/Utilities/ImageRotationUtilities.cpp index 5fa1fee579..1ee1fdcf82 100644 --- a/src/simplnx/Utilities/ImageRotationUtilities.cpp +++ b/src/simplnx/Utilities/ImageRotationUtilities.cpp @@ -74,13 +74,59 @@ RotateArgs CreateRotationArgs(const ImageGeom& imageGeom, const Matrix4fR& trans FloatVec6 minMaxCoords = DetermineMinMaxCoords(imageGeom, transformationMatrix); - const Eigen::Vector3f xAxisNew = rotationMatrix * k_XAxis; - const Eigen::Vector3f yAxisNew = rotationMatrix * k_YAxis; - const Eigen::Vector3f zAxisNew = rotationMatrix * k_ZAxis; + // Normalize each source column to distinguish grid rotations from general transforms. + // A signed permutation has exactly one unit entry in each column and each row. + // The filter checks raw entries with tolerance t. Accepted column norms are at least 1-t, + // so normalized off-axis entries can be as large as t/(1-t). + constexpr float32 k_RawGridTolerance = 1.0e-4F; + constexpr float32 k_GridTolerance = k_RawGridTolerance / (1.0F - k_RawGridTolerance); + bool isGridRotation = true; + std::array usedRows = {false, false, false}; + for(int32 col = 0; col < 3; ++col) + { + const float32 scale = rotationMatrix.col(col).norm(); + if(!std::isfinite(scale) || scale <= 0.0F) + { + isGridRotation = false; + break; + } + const Eigen::Vector3f normalized = rotationMatrix.col(col) / scale; + Eigen::Index sourceRow = 0; + normalized.cwiseAbs().maxCoeff(&sourceRow); + if(usedRows[sourceRow] || std::abs(std::abs(normalized[sourceRow]) - 1.0F) > k_GridTolerance) + { + isGridRotation = false; + break; + } + usedRows[sourceRow] = true; + for(int32 row = 0; row < 3; ++row) + { + if(row != sourceRow && std::abs(normalized[row]) > k_GridTolerance) + { + isGridRotation = false; + } + } + } + + FloatVec3 outputSpacing; + if(isGridRotation) + { + // Each row identifies the source axis for an output axis. Scale belongs to that source column. + const FloatVec3 scaledSpacing = {spacing[0] * rotationMatrix.col(0).norm(), spacing[1] * rotationMatrix.col(1).norm(), spacing[2] * rotationMatrix.col(2).norm()}; + outputSpacing = {DetermineSpacing(scaledSpacing, rotationMatrix.row(0).transpose()), DetermineSpacing(scaledSpacing, rotationMatrix.row(1).transpose()), + DetermineSpacing(scaledSpacing, rotationMatrix.row(2).transpose())}; + } + else + { + // Keep the column-based spacing rule for off-axis rotations and general transforms. + const Eigen::Vector3f xAxisNew = rotationMatrix * k_XAxis; + const Eigen::Vector3f yAxisNew = rotationMatrix * k_YAxis; + const Eigen::Vector3f zAxisNew = rotationMatrix * k_ZAxis; - FloatVec3 transformScale = {(rotationMatrix * k_XAxis).norm(), (rotationMatrix * k_YAxis).norm(), (rotationMatrix * k_ZAxis).norm()}; + FloatVec3 transformScale = {(rotationMatrix * k_XAxis).norm(), (rotationMatrix * k_YAxis).norm(), (rotationMatrix * k_ZAxis).norm()}; - FloatVec3 outputSpacing = {DetermineSpacing(spacing, xAxisNew) * transformScale[0], DetermineSpacing(spacing, yAxisNew) * transformScale[1], DetermineSpacing(spacing, zAxisNew) * transformScale[2]}; + outputSpacing = {DetermineSpacing(spacing, xAxisNew) * transformScale[0], DetermineSpacing(spacing, yAxisNew) * transformScale[1], DetermineSpacing(spacing, zAxisNew) * transformScale[2]}; + } USizeVec3 outputDims = {static_cast(std::nearbyint((minMaxCoords[1] - minMaxCoords[0]) / outputSpacing[0])), static_cast(std::nearbyint((minMaxCoords[3] - minMaxCoords[2]) / outputSpacing[1])), diff --git a/test/ImageRotationUtilitiesTest.cpp b/test/ImageRotationUtilitiesTest.cpp index b44a99559a..c566ccc424 100644 --- a/test/ImageRotationUtilitiesTest.cpp +++ b/test/ImageRotationUtilitiesTest.cpp @@ -1,4 +1,7 @@ #include "simplnx/Utilities/ImageRotationUtilities.hpp" +#include "simplnx/DataStructure/DataStructure.hpp" +#include "simplnx/DataStructure/Geometry/ImageGeom.hpp" +#include "simplnx/UnitTest/UnitTestCommon.hpp" #include @@ -58,3 +61,119 @@ TEST_CASE("ImageRotationUtilities: Octant offsets match the trilinear corner ord } } } + +TEST_CASE("ImageRotationUtilities: Scaled three-cycle takes spacing from the scaled source axis", "[ImageRotationUtilities][CreateRotationArgs]") +{ + DataStructure dataStructure; + ImageGeom* image = ImageGeom::Create(dataStructure, "Input"); + REQUIRE(image != nullptr); + image->setDimensions({2, 3, 4}); + image->setSpacing({2.0F, 3.0F, 5.0F}); + image->setOrigin({1.0F, 2.0F, 3.0F}); + + // The matrix maps (x,y,z) to (-4z, 2x, 3y). It is a three-cycle with a reflection and a different scale on each source axis. + ImageRotationUtilities::Matrix4fR transform = ImageRotationUtilities::Matrix4fR::Identity(); + transform.block<3, 3>(0, 0) << 0.0F, 0.0F, -4.0F, 2.0F, 0.0F, 0.0F, 0.0F, 3.0F, 0.0F; + + // Hand calculation: + // Output X comes from source Z: spacing 4 * 5 = 20, extent 4 * (4 * 5) = 80, so 4 cells. + // Output Y comes from source X: spacing 2 * 2 = 4, extent 2 * (2 * 2) = 8, so 2 cells. + // Output Z comes from source Y: spacing 3 * 3 = 9, extent 3 * (3 * 3) = 27, so 3 cells. + // Minimum corner: X = -4 * (3 + 20) = -92, Y = 2 * 1 = 2, Z = 3 * 2 = 6. + const ImageRotationUtilities::RotateArgs args = ImageRotationUtilities::CreateRotationArgs(*image, transform); + const std::array expectedDims = {4, 2, 3}; + const std::array expectedSpacing = {20.0F, 4.0F, 9.0F}; + const std::array expectedOrigin = {-92.0F, 2.0F, 6.0F}; + for(usize axis = 0; axis < 3; ++axis) + { + INFO("axis " + std::to_string(axis)); + CHECK(args.outputDims[axis] == expectedDims[axis]); + CHECK(args.outputSpacing[axis] == Approx(expectedSpacing[axis])); + CHECK(args.TransformedSpacing[axis] == Approx(expectedSpacing[axis])); + CHECK(args.TransformedOrigin[axis] == Approx(expectedOrigin[axis])); + } +} + +TEST_CASE("ImageRotationUtilities: Off-axis scaling keeps the column-based spacing", "[ImageRotationUtilities][CreateRotationArgs]") +{ + DataStructure dataStructure; + ImageGeom* image = ImageGeom::Create(dataStructure, "Input"); + REQUIRE(image != nullptr); + image->setDimensions({2, 3, 4}); + image->setSpacing({2.0F, 3.0F, 5.0F}); + image->setOrigin({0.0F, 0.0F, 0.0F}); + + const float32 c = std::sqrt(0.5F); + ImageRotationUtilities::Matrix4fR transform = ImageRotationUtilities::Matrix4fR::Identity(); + transform.block<3, 3>(0, 0) << 2 * c, -c, 0, 2 * c, c, 0, 0, 0, 1; + + // The column-based rule selects spacing by each column's largest absolute direction cosine, + // breaking the 45-degree tie toward X, then multiplies by that column's norm. + // Column norms (2,1,1) therefore give spacing (2*2,2*1,5*1) = (4,2,5). + // Source extents are (4,9,20). Rotated XY extents are (2*4+9)/sqrt(2). + // nearbyint gives dimensions (round(17/(4*sqrt(2))),round(17/(2*sqrt(2))),4) = (3,6,4). + const auto args = ImageRotationUtilities::CreateRotationArgs(*image, transform); + const std::array expectedSpacing = {4.0F, 2.0F, 5.0F}; + const std::array expectedDims = {3, 6, 4}; + for(usize axis = 0; axis < 3; ++axis) + { + CHECK(args.outputSpacing[axis] == Approx(expectedSpacing[axis])); + CHECK(args.outputDims[axis] == expectedDims[axis]); + } +} + +TEST_CASE("ImageRotationUtilities: Near-grid three-cycle accepted by Rotate Sample Reference Frame uses source-axis spacing", "[ImageRotationUtilities][CreateRotationArgs]") +{ + DataStructure dataStructure; + ImageGeom* image = ImageGeom::Create(dataStructure, "Input"); + REQUIRE(image != nullptr); + image->setDimensions({2, 3, 4}); + image->setSpacing({2.0F, 3.0F, 5.0F}); + image->setOrigin({0.0F, 0.0F, 0.0F}); + + // 119.995 degrees about (111) differs from the exact three-cycle by about 5e-5 per entry. + // Rotate Sample Reference Frame accepts it as a grid rotation (tolerance 1e-4). + // The exact map is R(x,y,z) = (z,x,y): output X comes from source Z, output Y from source X + // and output Z from source Y. Spacing (2,3,5) becomes (5,2,3) and dimensions (2,3,4) become (4,2,3). + const ImageRotationUtilities::Matrix4fR transform = ImageRotationUtilities::GenerateRotationTransformationMatrix({1.0F, 1.0F, 1.0F, 119.995F}); + const auto args = ImageRotationUtilities::CreateRotationArgs(*image, transform); + const std::array expectedSpacing = {5.0F, 2.0F, 3.0F}; + const std::array expectedDims = {4, 2, 3}; + for(usize axis = 0; axis < 3; ++axis) + { + CHECK(args.outputSpacing[axis] == Approx(expectedSpacing[axis])); + CHECK(args.outputDims[axis] == expectedDims[axis]); + } +} + +TEST_CASE("ImageRotationUtilities: Raw grid tolerance accounts for column normalization", "[ImageRotationUtilities][CreateRotationArgs]") +{ + UnitTest::LoadPlugins(); + DataStructure dataStructure; + ImageGeom* imageGeomPtr = ImageGeom::Create(dataStructure, "Input"); + REQUIRE(imageGeomPtr != nullptr); + imageGeomPtr->setDimensions({2, 3, 4}); + imageGeomPtr->setSpacing({2.0F, 3.0F, 5.0F}); + imageGeomPtr->setOrigin({0.0F, 0.0F, 0.0F}); + + ImageRotationUtilities::Matrix4fR transform = ImageRotationUtilities::Matrix4fR::Identity(); + transform.block<3, 3>(0, 0) << 0.000099998F, 0.0F, 1.0F, 0.99995F, 0.0F, 0.0F, 0.0F, 1.00005F, 0.0F; + + // Raw entries and determinant pass the filter's grid guard. Normalizing column 0 raises its small entry above 1e-4. + REQUIRE(std::abs(transform(0, 0)) < 1.0e-4F); + REQUIRE(std::abs(transform(1, 0) - 1.0F) < 1.0e-4F); + REQUIRE(std::abs(transform(2, 1) - 1.0F) < 1.0e-4F); + REQUIRE(std::abs(transform.block<3, 3>(0, 0).determinant() - 1.0F) < 1.0e-4F); + REQUIRE(transform(0, 0) / transform.block<3, 1>(0, 0).norm() > 1.0e-4F); + + // Source axes Z, X, Y supply output spacing. Their scales are 1, sqrt(0.99995^2+0.000099998^2), 1.00005. + // Output extents are 20+4*0.000099998, 4*0.99995, 9*1.00005. Rounding extent/spacing gives (4,2,3). + const std::array expectedSpacing = {5.0, 2.0 * std::sqrt(0.99995 * 0.99995 + 0.000099998 * 0.000099998), 3.0 * 1.00005}; + const std::array expectedDims = {4, 2, 3}; + const auto args = ImageRotationUtilities::CreateRotationArgs(*imageGeomPtr, transform); + for(usize axis = 0; axis < 3; ++axis) + { + CHECK(args.outputSpacing[axis] == Approx(expectedSpacing[axis])); + CHECK(args.outputDims[axis] == expectedDims[axis]); + } +} From 0f2974f1109b9c229e0f23c2b5cedb4960681f1d Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 4 Nov 2026 11:49:20 -0500 Subject: [PATCH 06/33] BUG: WriteVtkRectilinearGrid - Write ASCII coordinates with full precision In ASCII mode, the X, Y and Z coordinates were written with "%f", which keeps 6 decimals. With a spacing of 1e-7, every coordinate was written as 0 or -0. DREAM.3D 6.5.171 has the same defect (errata KI-016). Coordinates are now written with "%.*g" and max_digits10 significant digits, so they read back as the same float values. Binary output is unchanged. Add a test with spacing 1e-7 that checks every written coordinate against origin + (i - 1/2) * spacing. The exact-text bulk Boolean test now expects 9 significant digits. Fixes #1908 item L29 Signed-off-by: Michael Jackson --- .../docs/WriteVtkRectilinearGridFilter.md | 2 + .../Algorithms/WriteVtkRectilinearGrid.cpp | 4 +- .../test/WriteVtkRectilinearGridTest.cpp | 70 ++++++++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/WriteVtkRectilinearGridFilter.md b/src/Plugins/SimplnxCore/docs/WriteVtkRectilinearGridFilter.md index 39612f039c..f61d0d3864 100644 --- a/src/Plugins/SimplnxCore/docs/WriteVtkRectilinearGridFilter.md +++ b/src/Plugins/SimplnxCore/docs/WriteVtkRectilinearGridFilter.md @@ -16,6 +16,8 @@ The user selects which **Cell** **Data Array**s from the **Image Geometry** are The *Write Binary File* parameter controls the on-disk encoding. When *false* (the default), the data is written as plain ASCII text, which is portable and easy to inspect but larger and slower to read. When *true*, the data is written in VTK's binary form, producing smaller files that load faster. +ASCII coordinates retain the precision of the computed float values, including small spacing such as `1e-7`. This corrects the six-decimal rounding in DREAM3D 6.5.171, so ASCII coordinate output can differ from that version. + ### Required Input Sources - **Image Geometry** -- the geometry whose dimensions and spacing define the grid. diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkRectilinearGrid.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkRectilinearGrid.cpp index 306b741db7..bcf436c542 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkRectilinearGrid.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkRectilinearGrid.cpp @@ -7,6 +7,8 @@ #include "SimplnxCore/utils/VtkUtilities.hpp" +#include + using namespace nx::core; WriteVtkRectilinearGrid::WriteVtkRectilinearGrid(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, @@ -130,7 +132,7 @@ Result<> WriteVtkRectilinearGrid::writeCoords(FILE* outputFile, const std::strin for(int idx = 0; idx < nPoints; ++idx) { d = idx * step + min; - fprintf(outputFile, "%f ", d); + fprintf(outputFile, "%.*g ", std::numeric_limits::max_digits10, static_cast(d)); if(idx % 20 == 0 && idx != 0) { fprintf(outputFile, "\n"); diff --git a/src/Plugins/SimplnxCore/test/WriteVtkRectilinearGridTest.cpp b/src/Plugins/SimplnxCore/test/WriteVtkRectilinearGridTest.cpp index 1a6eb8ed6c..18f2fc38fa 100644 --- a/src/Plugins/SimplnxCore/test/WriteVtkRectilinearGridTest.cpp +++ b/src/Plugins/SimplnxCore/test/WriteVtkRectilinearGridTest.cpp @@ -182,7 +182,7 @@ void AppendCoordinatesAscii(std::string& expected, const std::string& axis, usiz expected += fmt::format("{} {} float\n", axis, count); for(usize idx = 0; idx < count; idx++) { - expected += fmt::format("{:.6f} ", static_cast(idx) - 0.5F); + expected += fmt::format("{:.9g} ", static_cast(idx) - 0.5F); if(idx % 20 == 0 && idx != 0) { expected += "\n"; @@ -298,6 +298,74 @@ TEST_CASE("SimplnxCore::WriteVtkRectilinearGridFilter: ASCII comparison preserve "SCALARS Values float 1\nversion\n3.583333\nSCALARS Ids int 1\nLOOKUP_TABLE default\n1.000000\n")); } +TEST_CASE("SimplnxCore::WriteVtkRectilinearGridFilter: ASCII small coordinates", "[SimplnxCore][WriteVtkRectilinearGridFilter][VtkAsciiCoordinates]") +{ + UnitTest::LoadPlugins(); + + DataStructure dataStructure; + const DataPath imagePath({"SmallImage"}); + const DataPath cellPath = imagePath.createChildPath("CellData"); + const DataPath valuesPath = cellPath.createChildPath("Values"); + auto* image = ImageGeom::Create(dataStructure, imagePath.getTargetName()); + REQUIRE(image != nullptr); + image->setDimensions({3, 3, 3}); + image->setSpacing({1.0e-7F, 1.0e-7F, 1.0e-7F}); + image->setOrigin({0.0F, 0.0F, 0.0F}); + auto* cellData = AttributeMatrix::Create(dataStructure, cellPath.getTargetName(), ShapeType{3, 3, 3}, image->getId()); + REQUIRE(cellData != nullptr); + image->setCellData(*cellData); + auto store = DataStoreUtilities::CreateDataStore(dataStructure, valuesPath, {3, 3, 3}, {1}); + auto* values = Float32Array::Create(dataStructure, valuesPath.getTargetName(), store, cellData->getId()); + REQUIRE(values != nullptr); + values->fill(0.0F); + + const fs::path outputPath = fs::path(unit_test::k_BinaryTestOutputDir.view()) / "VtkAsciiSmallCoordinates.vtk"; + const WriteVtkRectilinearGridFilter filter; + Arguments args = filter.getDefaultArguments(); + args.insertOrAssign(WriteVtkRectilinearGridFilter::k_OutputFile_Key, std::make_any(outputPath)); + args.insertOrAssign(WriteVtkRectilinearGridFilter::k_WriteBinaryFile_Key, std::make_any(false)); + args.insertOrAssign(WriteVtkRectilinearGridFilter::k_ImageGeometryPath_Key, std::make_any(imagePath)); + args.insertOrAssign(WriteVtkRectilinearGridFilter::k_SelectedDataArrayPaths_Key, std::make_any(MultiArraySelectionParameter::ValueType{valuesPath})); + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + auto executeResult = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); + + std::ifstream output(outputPath); + REQUIRE(output.is_open()); + std::string line; + while(std::getline(output, line) && line != "X_COORDINATES 4 float") + { + } + REQUIRE(line == "X_COORDINATES 4 float"); + // The writer uses origin + (i - 1/2) * spacing for its coordinates. + // The half-cell shift is tracked separately in #1878 (WriteVtkRectilinearGridFilter#1). + // For origin zero and spacing 1e-7, hand calculation gives these four values. + // The tolerance allows float arithmetic rounding, but not six-place truncation. + constexpr std::array k_Expected = {-5.0e-8, 5.0e-8, 1.5e-7, 2.5e-7}; + for(const std::string axis : {"X", "Y", "Z"}) + { + if(axis != "X") + { + std::string header; + usize count = 0; + std::string type; + REQUIRE(output >> header >> count >> type); + REQUIRE(header == axis + "_COORDINATES"); + REQUIRE(count == 4); + REQUIRE(type == "float"); + } + for(usize index = 0; index < k_Expected.size(); index++) + { + CAPTURE(axis, index); + double actual = 0.0; + REQUIRE(output >> actual); + CHECK(actual == Approx(k_Expected[index]).margin(2.0e-14)); + } + } + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} + TEMPLATE_TEST_CASE("SimplnxCore::WriteVtkRectilinearGridFilter: ASCII floating point round trip", "[SimplnxCore][WriteVtkRectilinearGridFilter][VtkAsciiFloats]", float32, float64) { UnitTest::LoadPlugins(); From 118f5cc92e811336a17645ee101bade620784bdf Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 4 Nov 2026 12:05:54 -0500 Subject: [PATCH 07/33] BUG: WriteVtk(RectilinearGrid|StructuredPoints) - Reject arrays with more than 4 components Both legacy VTK writers wrote arrays with any number of components as SCALARS. The legacy VTK format allows only 1 to 4 components for SCALARS, so 6- or 9-component arrays produced files outside the format. DREAM.3D 6.5.171 has the same defect (errata KI-082). Preflight now rejects a selected array with 0 or more than 4 components, with error -12073 (rectilinear grid) or -12074 (structured points). The check reads only metadata. Add a test for each writer that checks 1 to 4 components pass and 5, 6 and 9 components fail, in ASCII and binary mode. Fixes #1908 item L51 Fixes #1908 item L52 Signed-off-by: Michael Jackson --- .../docs/WriteVtkRectilinearGridFilter.md | 4 +- .../docs/WriteVtkStructuredPointsFilter.md | 4 +- .../Filters/WriteVtkRectilinearGridFilter.cpp | 10 +++++ .../WriteVtkStructuredPointsFilter.cpp | 10 +++++ .../test/WriteVtkRectilinearGridTest.cpp | 44 +++++++++++++++++++ .../test/WriteVtkStructuredPointsTest.cpp | 44 +++++++++++++++++++ 6 files changed, 114 insertions(+), 2 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/WriteVtkRectilinearGridFilter.md b/src/Plugins/SimplnxCore/docs/WriteVtkRectilinearGridFilter.md index f61d0d3864..fcbc6320e1 100644 --- a/src/Plugins/SimplnxCore/docs/WriteVtkRectilinearGridFilter.md +++ b/src/Plugins/SimplnxCore/docs/WriteVtkRectilinearGridFilter.md @@ -18,10 +18,12 @@ The *Write Binary File* parameter controls the on-disk encoding. When *false* (t ASCII coordinates retain the precision of the computed float values, including small spacing such as `1e-7`. This corrects the six-decimal rounding in DREAM3D 6.5.171, so ASCII coordinate output can differ from that version. +Arrays are written as legacy VTK `SCALARS`, which supports 1 to 4 components. Preflight rejects arrays with more than 4 components, including 6- and 9-component arrays. This corrects DREAM3D 6.5.171 behavior, which wrote these arrays with invalid `SCALARS` headers. + ### Required Input Sources - **Image Geometry** -- the geometry whose dimensions and spacing define the grid. -- **Cell Data Array(s) to write** -- any per-cell arrays on the **Image Geometry**. A common choice is a *FeatureIds* array produced by [Segment Features (Scalar)](ScalarSegmentFeaturesFilter.md). +- **Cell Data Array(s) to write** -- any per-cell arrays with 1 to 4 components on the **Image Geometry**. A common choice is a *FeatureIds* array produced by [Segment Features (Scalar)](ScalarSegmentFeaturesFilter.md). % Auto generated parameter table will be inserted here diff --git a/src/Plugins/SimplnxCore/docs/WriteVtkStructuredPointsFilter.md b/src/Plugins/SimplnxCore/docs/WriteVtkStructuredPointsFilter.md index 3ad3e1e31c..a150414e9f 100644 --- a/src/Plugins/SimplnxCore/docs/WriteVtkStructuredPointsFilter.md +++ b/src/Plugins/SimplnxCore/docs/WriteVtkStructuredPointsFilter.md @@ -20,10 +20,12 @@ Use **Write Vtk Structured Points** when the **Image Geometry** has uniform spac The *Write Binary File* parameter controls the on-disk encoding. When *false* (the default), the data is written as plain ASCII text, which is portable and easy to inspect but larger and slower to read. When *true*, the data is written in VTK's binary form, producing smaller files that load faster. +Arrays are written as legacy VTK `SCALARS`, which supports 1 to 4 components. Preflight rejects arrays with more than 4 components, including 6- and 9-component arrays. This corrects DREAM3D 6.5.171 behavior, which wrote these arrays with invalid `SCALARS` headers. + ### Required Input Sources - **Image Geometry** -- the geometry whose origin, spacing, and dimensions define the grid. -- **Cell Data Array(s) to write** -- any per-cell arrays on the **Image Geometry**. A common choice is a *FeatureIds* array produced by [Segment Features (Scalar)](ScalarSegmentFeaturesFilter.md). +- **Cell Data Array(s) to write** -- any per-cell arrays with 1 to 4 components on the **Image Geometry**. A common choice is a *FeatureIds* array produced by [Segment Features (Scalar)](ScalarSegmentFeaturesFilter.md). % Auto generated parameter table will be inserted here diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/WriteVtkRectilinearGridFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/WriteVtkRectilinearGridFilter.cpp index 2c270592d7..7aaf6c2b67 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/WriteVtkRectilinearGridFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/WriteVtkRectilinearGridFilter.cpp @@ -91,6 +91,16 @@ IFilter::PreflightResult WriteVtkRectilinearGridFilter::preflightImpl(const Data return MakePreflightErrorResult(-2070, "No cell data arrays are selected. You must select at least one array."); } + for(const auto& arrayPath : pSelectedDataArrayPathsValue) + { + const usize components = dataStructure.getDataRefAs(arrayPath).getNumberOfComponents(); + if(components < 1 || components > 4) + { + return MakePreflightErrorResult( + -12073, fmt::format("Array '{}' has {} components. Legacy VTK SCALARS requires 1 to 4 components. Select an array with 1 to 4 components.", arrayPath.toString(), components)); + } + } + auto tupleValidityCheck = dataStructure.validateNumberOfTuples(pSelectedDataArrayPathsValue); if(!tupleValidityCheck) { diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/WriteVtkStructuredPointsFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/WriteVtkStructuredPointsFilter.cpp index 09d759fffb..e4654602df 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/WriteVtkStructuredPointsFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/WriteVtkStructuredPointsFilter.cpp @@ -90,6 +90,16 @@ IFilter::PreflightResult WriteVtkStructuredPointsFilter::preflightImpl(const Dat return MakePreflightErrorResult(-2070, "No cell data arrays are selected. You must select at least one array."); } + for(const auto& arrayPath : pSelectedDataArrayPathsValue) + { + const usize components = dataStructure.getDataRefAs(arrayPath).getNumberOfComponents(); + if(components < 1 || components > 4) + { + return MakePreflightErrorResult( + -12074, fmt::format("Array '{}' has {} components. Legacy VTK SCALARS requires 1 to 4 components. Select an array with 1 to 4 components.", arrayPath.toString(), components)); + } + } + auto tupleValidityCheck = dataStructure.validateNumberOfTuples(pSelectedDataArrayPathsValue); if(!tupleValidityCheck) { diff --git a/src/Plugins/SimplnxCore/test/WriteVtkRectilinearGridTest.cpp b/src/Plugins/SimplnxCore/test/WriteVtkRectilinearGridTest.cpp index 18f2fc38fa..cc118ac4a6 100644 --- a/src/Plugins/SimplnxCore/test/WriteVtkRectilinearGridTest.cpp +++ b/src/Plugins/SimplnxCore/test/WriteVtkRectilinearGridTest.cpp @@ -621,3 +621,47 @@ TEST_CASE("SimplnxCore::WriteVtkRectilinearGridFilter: SIMPL Backwards Compatibi } } } + +TEST_CASE("SimplnxCore::WriteVtkRectilinearGridFilter: Legacy scalar component limits", "[SimplnxCore][WriteVtkRectilinearGridFilter]") +{ + UnitTest::LoadPlugins(); + + const usize components = GENERATE(1, 2, 3, 4, 5, 6, 9); + const bool binary = GENERATE(false, true); + CAPTURE(components, binary); + DataStructure dataStructure; + auto* image = ImageGeom::Create(dataStructure, "Image"); + REQUIRE(image != nullptr); + image->setDimensions({1, 1, 1}); + auto* cells = AttributeMatrix::Create(dataStructure, "Cells", ShapeType{1, 1, 1}, image->getId()); + REQUIRE(cells != nullptr); + image->setCellData(*cells); + const DataPath arrayPath({"Image", "Cells", "Values"}); + auto store = DataStoreUtilities::CreateDataStore(dataStructure, arrayPath, ShapeType{1, 1, 1}, ShapeType{components}); + auto* values = Float32Array::Create(dataStructure, "Values", store, cells->getId()); + REQUIRE(values != nullptr); + + WriteVtkRectilinearGridFilter filter; + auto args = filter.getDefaultArguments(); + args.insertOrAssign(WriteVtkRectilinearGridFilter::k_OutputFile_Key, + std::make_any(fs::path(unit_test::k_BinaryTestOutputDir.view()) / "component_limits_RectilinearGrid.vtk")); + args.insertOrAssign(WriteVtkRectilinearGridFilter::k_WriteBinaryFile_Key, std::make_any(binary)); + args.insertOrAssign(WriteVtkRectilinearGridFilter::k_ImageGeometryPath_Key, std::make_any(DataPath({"Image"}))); + args.insertOrAssign(WriteVtkRectilinearGridFilter::k_SelectedDataArrayPaths_Key, std::make_any(MultiArraySelectionParameter::ValueType{arrayPath})); + + // Independent format oracle: legacy VTK SCALARS permits 1 through 4 components. + // Counts 5, 6 and 9 must be rejected before a file can be written, for either encoding. + IFilter::PreflightResult result; + REQUIRE_NOTHROW(result = filter.preflight(dataStructure, args)); + if(components <= 4) + { + SIMPLNX_RESULT_REQUIRE_VALID(result.outputActions); + } + else + { + SIMPLNX_RESULT_REQUIRE_INVALID(result.outputActions); + REQUIRE(result.outputActions.errors().size() == 1); + REQUIRE(result.outputActions.errors()[0].code == -12073); + } + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} diff --git a/src/Plugins/SimplnxCore/test/WriteVtkStructuredPointsTest.cpp b/src/Plugins/SimplnxCore/test/WriteVtkStructuredPointsTest.cpp index f78261fe86..ff39b72a75 100644 --- a/src/Plugins/SimplnxCore/test/WriteVtkStructuredPointsTest.cpp +++ b/src/Plugins/SimplnxCore/test/WriteVtkStructuredPointsTest.cpp @@ -209,3 +209,47 @@ TEST_CASE("SimplnxCore::WriteVtkStructuredPointsFilter: ASCII correctness", "[Si UnitTest::AlgorithmTestScope scope(scenario); WriteVtkStructuredPointsTest::CheckAsciiOutput(scope, ""); } + +TEST_CASE("SimplnxCore::WriteVtkStructuredPointsFilter: Legacy scalar component limits", "[SimplnxCore][WriteVtkStructuredPointsFilter]") +{ + UnitTest::LoadPlugins(); + + const usize components = GENERATE(1, 2, 3, 4, 5, 6, 9); + const bool binary = GENERATE(false, true); + CAPTURE(components, binary); + DataStructure dataStructure; + auto* image = ImageGeom::Create(dataStructure, "Image"); + REQUIRE(image != nullptr); + image->setDimensions({1, 1, 1}); + auto* cells = AttributeMatrix::Create(dataStructure, "Cells", ShapeType{1, 1, 1}, image->getId()); + REQUIRE(cells != nullptr); + image->setCellData(*cells); + const DataPath arrayPath({"Image", "Cells", "Values"}); + auto store = DataStoreUtilities::CreateDataStore(dataStructure, arrayPath, ShapeType{1, 1, 1}, ShapeType{components}); + auto* values = Float32Array::Create(dataStructure, "Values", store, cells->getId()); + REQUIRE(values != nullptr); + + WriteVtkStructuredPointsFilter filter; + auto args = filter.getDefaultArguments(); + args.insertOrAssign(WriteVtkStructuredPointsFilter::k_OutputFile_Key, + std::make_any(fs::path(unit_test::k_BinaryTestOutputDir.view()) / "component_limits_StructuredPoints.vtk")); + args.insertOrAssign(WriteVtkStructuredPointsFilter::k_WriteBinaryFile_Key, std::make_any(binary)); + args.insertOrAssign(WriteVtkStructuredPointsFilter::k_ImageGeometryPath_Key, std::make_any(DataPath({"Image"}))); + args.insertOrAssign(WriteVtkStructuredPointsFilter::k_SelectedDataArrayPaths_Key, std::make_any(MultiArraySelectionParameter::ValueType{arrayPath})); + + // Independent format oracle: legacy VTK SCALARS permits 1 through 4 components. + // Counts 5, 6 and 9 must be rejected before a file can be written, for either encoding. + IFilter::PreflightResult result; + REQUIRE_NOTHROW(result = filter.preflight(dataStructure, args)); + if(components <= 4) + { + SIMPLNX_RESULT_REQUIRE_VALID(result.outputActions); + } + else + { + SIMPLNX_RESULT_REQUIRE_INVALID(result.outputActions); + REQUIRE(result.outputActions.errors().size() == 1); + REQUIRE(result.outputActions.errors()[0].code == -12074); + } + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} From 57e9a75f9f8bde3b8b7d83abe477d39bbcfa75f9 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 4 Nov 2026 12:11:26 -0500 Subject: [PATCH 08/33] BUG: AddBadData - Reject StringArray and NeighborList cell arrays in preflight The algorithm sets values to 0 in every array of the geometry's Cell Data Attribute Matrix and reads each one as a numeric DataArray. A StringArray or NeighborList in that Attribute Matrix made the cast throw, and the filter failed with the generic error -2. DREAM.3D 6.5.171 crashed in the same case (errata KI-052). Preflight now checks every array in the Cell Data Attribute Matrix and returns -76239, with the array path, when one is not a numeric DataArray. Add a test with a StringArray and with a NeighborList in the cell Attribute Matrix that expects -76239 from preflight and execute in both algorithm scenarios. Fixes #1908 item L30 Signed-off-by: Michael Jackson --- .../SimplnxCore/docs/AddBadDataFilter.md | 2 + .../SimplnxCore/Filters/AddBadDataFilter.cpp | 15 ++++++ .../SimplnxCore/test/AddBadDataTest.cpp | 52 +++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/src/Plugins/SimplnxCore/docs/AddBadDataFilter.md b/src/Plugins/SimplnxCore/docs/AddBadDataFilter.md index e3be25073c..5d37c9795d 100644 --- a/src/Plugins/SimplnxCore/docs/AddBadDataFilter.md +++ b/src/Plugins/SimplnxCore/docs/AddBadDataFilter.md @@ -32,6 +32,8 @@ This means a volume fraction of 0.2 in boundary-only mode introduces far fewer b To flag a cell as bad, the filter sets the corresponding tuple in every **Attribute Array** in the same **Attribute Matrix** as the *Boundary Euclidean Distances* input to **0**. This includes Feature Ids, Phases, Quaternions, and any other cell-level data sharing that matrix. Be aware that "0" may be a legitimate value for some arrays (e.g., a phase index) and that the convention here is shared with experimental cleanup filters that interpret Feature Id 0 as bad. +The filter rejects StringArray and NeighborList objects in the geometry's Cell Data Attribute Matrix during preflight. The error identifies the array to move. DREAM3D 6.5.171 did not check these types before execution. + ### Prerequisite Steps This filter needs to know which cells are near a feature boundary. That information comes from a Manhattan-distance map, which must be computed and converted before this filter runs: diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AddBadDataFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AddBadDataFilter.cpp index d982fa74fa..aa5f2e92e4 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AddBadDataFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AddBadDataFilter.cpp @@ -15,6 +15,7 @@ #include "simplnx/Parameters/NumberParameter.hpp" #include "simplnx/Utilities/DataArrayUtilities.hpp" +#include "simplnx/Utilities/DataGroupUtilities.hpp" #include "simplnx/Utilities/FilterUtilities.hpp" #include "simplnx/Utilities/SIMPLConversion.hpp" @@ -175,6 +176,20 @@ IFilter::PreflightResult AddBadDataFilter::preflightImpl(const DataStructure& da return {MakeErrorResult(-76237, fmt::format("Image geometry must have a valid cell Attribute Matrix"))}; } + const auto childArrayPaths = GetAllChildArrayDataPaths(dataStructure, imgGeomPtr->getCellDataPath()); + if(childArrayPaths.has_value()) + { + for(const auto& arrayPath : childArrayPaths.value()) + { + if(dataStructure.getDataAs(arrayPath) == nullptr) + { + return {MakeErrorResult( + -76239, fmt::format("Cell array '{}' is not a numeric DataArray. Move StringArray and NeighborList objects out of the geometry's cell Attribute Matrix before adding bad data.", + arrayPath.toString()))}; + } + } + } + { auto createAction = std::make_unique(DataType::uint64, std::vector{1}, std::vector{1}, DataPath({pSeedArrayNameValue})); resultOutputActions.value().appendAction(std::move(createAction)); diff --git a/src/Plugins/SimplnxCore/test/AddBadDataTest.cpp b/src/Plugins/SimplnxCore/test/AddBadDataTest.cpp index 7b3d138a77..548d7102b8 100644 --- a/src/Plugins/SimplnxCore/test/AddBadDataTest.cpp +++ b/src/Plugins/SimplnxCore/test/AddBadDataTest.cpp @@ -6,6 +6,7 @@ #include "simplnx/DataStructure/DataArray.hpp" #include "simplnx/DataStructure/DataStore.hpp" #include "simplnx/DataStructure/Geometry/ImageGeom.hpp" +#include "simplnx/DataStructure/NeighborList.hpp" #include "simplnx/DataStructure/StringArray.hpp" #include "simplnx/Filter/IParameter.hpp" #include "simplnx/Utilities/AlgorithmDispatch.hpp" @@ -229,3 +230,54 @@ TEST_CASE("SimplnxCore::AddBadData: rejects nonnumeric input arrays", "[SimplnxC REQUIRE(preflight.outputActions.errors().front().message.find("Input") != std::string::npos); UnitTest::CheckArraysInheritTupleDims(dataStructure); } + +TEST_CASE("SimplnxCore::AddBadDataFilter: Reject nonnumeric cell arrays", "[SimplnxCore][AddBadDataFilter]") +{ + UnitTest::LoadPlugins(); + const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); + CAPTURE(scenario); + UnitTest::AlgorithmTestScope scope(scenario); + const bool useStrings = GENERATE(true, false); + CAPTURE(useStrings); + + DataStructure dataStructure; + auto* imageGeom = ImageGeom::Create(dataStructure, "Image"); + REQUIRE(imageGeom != nullptr); + imageGeom->setDimensions({1, 1, 1}); + auto* cellAM = AttributeMatrix::Create(dataStructure, "Cell Data", ShapeType{1, 1, 1}, imageGeom->getId()); + REQUIRE(cellAM != nullptr); + imageGeom->setCellData(*cellAM); + REQUIRE(Int32Array::Create(dataStructure, "Distances", std::make_shared>(ShapeType{1, 1, 1}, ShapeType{1}, 0), cellAM->getId()) != nullptr); + if(useStrings) + { + REQUIRE(StringArray::CreateWithValues(dataStructure, "Unsupported", cellAM->getShape(), {"label"}, cellAM->getId()) != nullptr); + } + else + { + REQUIRE(NeighborList::Create(dataStructure, "Unsupported", cellAM->getShape(), cellAM->getId()) != nullptr); + } + + AddBadDataFilter filter; + Arguments args; + args.insertOrAssign(AddBadDataFilter::k_ImageGeometryPath_Key, std::make_any(DataPath({"Image"}))); + args.insertOrAssign(AddBadDataFilter::k_GBEuclideanDistancesArrayPath_Key, std::make_any(DataPath({"Image", "Cell Data", "Distances"}))); + args.insertOrAssign(AddBadDataFilter::k_PoissonNoise_Key, std::make_any(true)); + args.insertOrAssign(AddBadDataFilter::k_PoissonVolFraction_Key, std::make_any(1.0F)); + args.insertOrAssign(AddBadDataFilter::k_UseSeed_Key, std::make_any(true)); + + // Type-contract oracle: zeroing numeric components is undefined for strings and variable-length lists. + // Reject either type in preflight, before execution can cast it to IDataArray. + const auto preflight = filter.preflight(dataStructure, args); + CHECK(preflight.outputActions.invalid()); + const auto execute = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_INVALID(execute.result); + REQUIRE(execute.result.errors().size() == 1); + CHECK(execute.result.errors()[0].code == -76239); + CHECK(execute.result.errors()[0].message.find("Image/Cell Data/Unsupported") != std::string::npos); + if(preflight.outputActions.invalid()) + { + REQUIRE(preflight.outputActions.errors().size() == 1); + CHECK(preflight.outputActions.errors()[0].code == -76239); + } + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} From 05844c4ddb1c74db3b84f4f6157882c784bb6722 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 4 Nov 2026 12:17:15 -0500 Subject: [PATCH 09/33] BUG: ExecuteProcess - Do not keep separator spaces in parsed arguments After a quoted argument, or at a second space between arguments, the argument parser started the next token on the separator space. For "/a b/prog" --help the second argument became " --help", and double spaces produced arguments that were a single space. DREAM.3D 6.5.171 has the same parser (errata KI-080). The parser now skips separator spaces before it starts the next token. Spaces inside quotes are kept. Add a test with a quoted executable, double spaces, a quoted middle argument, trailing spaces and a plain command line, with hand-written expected argument lists. Fixes #1908 item L38 Signed-off-by: Michael Jackson --- .../SimplnxCore/docs/ExecuteProcessFilter.md | 2 ++ .../Filters/Algorithms/ExecuteProcess.cpp | 4 ++++ .../SimplnxCore/test/ExecuteProcessTest.cpp | 21 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/Plugins/SimplnxCore/docs/ExecuteProcessFilter.md b/src/Plugins/SimplnxCore/docs/ExecuteProcessFilter.md index 497deff2a7..3987ba39e9 100644 --- a/src/Plugins/SimplnxCore/docs/ExecuteProcessFilter.md +++ b/src/Plugins/SimplnxCore/docs/ExecuteProcessFilter.md @@ -18,6 +18,8 @@ Simple command with arguments (for Windows users) > C:/Applications/DREAM3D-NX/nxrunner.exe --execute C:/Applications/DREAM3D-NX/Data/MyPipeline.d3dpipeline +Spaces between arguments are ignored. Spaces inside double quotes are preserved. This corrects DREAM3D 6.5.171 behavior, which could add a leading space to an argument after a quoted argument or repeated spaces. + For a command with spaces in the path > "C:/Program Files/DREAM3D-NX/nxrunner.exe" --execute "C:/Program Files/DREAM3D-NX/pipelines/OrientationAnalysis/Small_IN100_Processing/(01) Small IN100 Archive.d3dpipeline" diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ExecuteProcess.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ExecuteProcess.cpp index f3dbdafa27..c711ce82e2 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ExecuteProcess.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ExecuteProcess.cpp @@ -155,6 +155,10 @@ std::vector ExecuteProcess::splitArgumentsString(const std::string& std::vector argumentList; for(int i = 0; i < arguments.size(); i++) { + if(arguments[i] == ' ') + { + continue; + } if(arguments[i] == '\"') { i++; diff --git a/src/Plugins/SimplnxCore/test/ExecuteProcessTest.cpp b/src/Plugins/SimplnxCore/test/ExecuteProcessTest.cpp index 5c2e5639d4..7c1d5ab259 100644 --- a/src/Plugins/SimplnxCore/test/ExecuteProcessTest.cpp +++ b/src/Plugins/SimplnxCore/test/ExecuteProcessTest.cpp @@ -12,6 +12,7 @@ #include "simplnx/UnitTest/UnitTestCommon.hpp" #include "simplnx/Utilities/StringUtilities.hpp" +#include "SimplnxCore/Filters/Algorithms/ExecuteProcess.hpp" #include "SimplnxCore/Filters/ExecuteProcessFilter.hpp" #include @@ -146,3 +147,23 @@ TEST_CASE("SimplnxCore::ExecuteProcessFilter: SIMPL Backwards Compatibility", "[ } } } + +TEST_CASE("SimplnxCore::ExecuteProcessFilter: Argument separator regression", "[SimplnxCore][ExecuteProcessFilter]") +{ + UnitTest::LoadPlugins(); + + // Oracle: spaces outside quotes separate tokens; spaces inside quotes are literal. + // Each command below therefore has exactly the explicitly listed arguments. + const std::vector>> cases = { + {R"("/a b/prog" --help)", {"/a b/prog", "--help"}}, {"prog --help", {"prog", "--help"}}, {R"(prog "a b" --help)", {"prog", "a b", "--help"}}, + {R"( "a b" " c d " )", {"a b", " c d "}}, {"prog --help", {"prog", "--help"}}, + }; + for(const auto& [command, expected] : cases) + { + DYNAMIC_SECTION(command) + { + const auto actual = ExecuteProcess::splitArgumentsString(command); + REQUIRE(actual == expected); + } + } +} From 0fdae74e463fc9e1144fec019f95616a01a30d2f Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 4 Nov 2026 12:22:48 -0500 Subject: [PATCH 10/33] BUG: FeatureFaceCurvature - Write NaN for a one-triangle Feature face instead of failing A Feature face made of a single triangle has no neighbors, so its N-ring patch holds one triangle. The algorithm threw "NRingNeighbor failed to find more than one triangles." and the whole filter failed with -2. DREAM.3D 6.5.171 wrote invalid values for such faces (errata KI-013). The triangle now gets NaN in every requested output, the same rule already used for patches with fewer than two valid triangles, and the other triangles are still processed. Add a test with a single-triangle Feature face that expects NaN outputs, with and without normal fitting. Fixes #1908 item L39 Signed-off-by: Michael Jackson --- .../docs/FeatureFaceCurvatureFilter.md | 2 +- .../CalculateTriangleGroupCurvatures.cpp | 3 +- .../test/FeatureFaceCurvatureTest.cpp | 83 +++++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/FeatureFaceCurvatureFilter.md b/src/Plugins/SimplnxCore/docs/FeatureFaceCurvatureFilter.md index a8d7f03b19..bbc73366a3 100644 --- a/src/Plugins/SimplnxCore/docs/FeatureFaceCurvatureFilter.md +++ b/src/Plugins/SimplnxCore/docs/FeatureFaceCurvatureFilter.md @@ -16,7 +16,7 @@ The principal directions can have their signs flipped: they come from eigenvecto *Note*: Computing the Weingarten matrix values is an experimental feature, and there is no guarantee at this time that the values are correct. -The fitting neighborhood contains the triangle itself and its neighbors within the **Neighborhood Ring Count**. Only neighbors with the same pair of **Face Labels** are included. If this neighborhood initially contains fewer than two triangles, the filter returns an error. Otherwise, triangles with a NaN component in their face normal or face centroid are excluded from the fit. If the evaluated triangle is excluded, all of its requested outputs are NaN. The outputs are also NaN if this exclusion leaves fewer than two triangles. The evaluated triangle counts toward this minimum. +The fitting neighborhood contains the triangle itself and its neighbors within the **Neighborhood Ring Count**. Only neighbors with the same pair of **Face Labels** are included. If this neighborhood contains fewer than two triangles, all requested outputs for that triangle are NaN and the filter continues. This includes a Feature face with only one triangle. This differs from DREAM3D 6.5.171, which wrote invalid values for one-triangle faces. Triangles with a NaN component in their face normal or face centroid are excluded from the fit. If the evaluated triangle is excluded, all of its requested outputs are NaN. The outputs are also NaN if this exclusion leaves fewer than two triangles. The evaluated triangle counts toward this minimum. ### Units diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CalculateTriangleGroupCurvatures.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CalculateTriangleGroupCurvatures.cpp index 02a346d3c0..42e3392097 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CalculateTriangleGroupCurvatures.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/CalculateTriangleGroupCurvatures.cpp @@ -223,7 +223,8 @@ void CalculateTriangleGroupCurvatures::operator()() const FindNRingNeighbors::UniqueFaceIds_t triPatch = nRingNeighborAlg.getNRingTriangles(); if(triPatch.size() <= 1) { - throw std::runtime_error("NRingNeighbor failed to find more than one triangles."); + markOutputsInvalid(triId); + continue; } size_t beforeSize = triPatch.size(); diff --git a/src/Plugins/SimplnxCore/test/FeatureFaceCurvatureTest.cpp b/src/Plugins/SimplnxCore/test/FeatureFaceCurvatureTest.cpp index 5c0cfbf636..24fc7530ad 100644 --- a/src/Plugins/SimplnxCore/test/FeatureFaceCurvatureTest.cpp +++ b/src/Plugins/SimplnxCore/test/FeatureFaceCurvatureTest.cpp @@ -267,3 +267,86 @@ TEST_CASE("SimplnxCore::FeatureFaceCurvatureFilter: NaN patch data", "[FeatureFa } UnitTest::CheckArraysInheritTupleDims(dataStructure); } + +TEST_CASE("SimplnxCore::FeatureFaceCurvatureFilter: Single triangle face", "[FeatureFaceCurvatureFilter][SingleTriangle]") +{ + UnitTest::LoadPlugins(); + const bool useNormals = GENERATE(false, true); + const bool optionalOutputs = GENERATE(false, true); + CAPTURE(useNormals, optionalOutputs); + + DataStructure dataStructure; + auto* geom = TriangleGeom::Create(dataStructure, "Triangles"); + REQUIRE(geom != nullptr); + auto* faceData = AttributeMatrix::Create(dataStructure, "FaceData", {1}, geom->getId()); + REQUIRE(faceData != nullptr); + geom->setFaceAttributeMatrix(*faceData); + auto* vertices = Float32Array::Create(dataStructure, "Vertices", std::make_unique>(ShapeType{3}, ShapeType{3}, 0.0F), geom->getId()); + auto* faces = DataArray::Create(dataStructure, "Faces", std::make_unique>(ShapeType{1}, ShapeType{3}, 0), geom->getId()); + REQUIRE(vertices != nullptr); + REQUIRE(faces != nullptr); + geom->setVertices(*vertices); + geom->setFaceList(*faces); + auto* labels = Int32Array::Create(dataStructure, "Labels", std::make_unique>(ShapeType{1}, ShapeType{2}, 1), faceData->getId()); + auto* ids = Int32Array::Create(dataStructure, "Ids", std::make_unique>(ShapeType{1}, ShapeType{1}, 1), faceData->getId()); + auto* normals = Float64Array::Create(dataStructure, "Normals", std::make_unique>(ShapeType{1}, ShapeType{3}, 0.0), faceData->getId()); + auto* centroids = Float64Array::Create(dataStructure, "Centroids", std::make_unique>(ShapeType{1}, ShapeType{3}, 0.0), faceData->getId()); + REQUIRE(labels != nullptr); + REQUIRE(ids != nullptr); + REQUIRE(normals != nullptr); + REQUIRE(centroids != nullptr); + + // Triangle (0,0,0), (1,0,0), (0,1,0): centroid (1/3,1/3,0), normal +Z. + vertices->setComponent(1, 0, 1.0F); + vertices->setComponent(2, 1, 1.0F); + faces->setComponent(0, 1, 1); + faces->setComponent(0, 2, 2); + labels->setComponent(0, 1, 2); + normals->setComponent(0, 2, 1.0); + centroids->setComponent(0, 0, 1.0 / 3.0); + centroids->setComponent(0, 1, 1.0 / 3.0); + + const DataPath geomPath({"Triangles"}); + const DataPath facePath = geomPath.createChildPath("FaceData"); + Arguments args; + args.insertOrAssign(FeatureFaceCurvatureFilter::k_TriangleGeomPath_Key, std::make_any(geomPath)); + args.insertOrAssign(FeatureFaceCurvatureFilter::k_FaceAttribMatrixPath_Key, std::make_any(facePath)); + args.insertOrAssign(FeatureFaceCurvatureFilter::k_NeighborhoodRing_Key, std::make_any(1)); + args.insertOrAssign(FeatureFaceCurvatureFilter::k_UseFaceNormals_Key, std::make_any(useNormals)); + args.insertOrAssign(FeatureFaceCurvatureFilter::k_ComputePrincipalDirection_Key, std::make_any(optionalOutputs)); + args.insertOrAssign(FeatureFaceCurvatureFilter::k_ComputeGaussianCurvature_Key, std::make_any(optionalOutputs)); + args.insertOrAssign(FeatureFaceCurvatureFilter::k_ComputeMeanCurvaturePath_Key, std::make_any(optionalOutputs)); + args.insertOrAssign(FeatureFaceCurvatureFilter::k_ComputeWeingartenMatrix_Key, std::make_any(optionalOutputs)); + args.insertOrAssign(FeatureFaceCurvatureFilter::k_FaceLabelsPath_Key, std::make_any(facePath.createChildPath("Labels"))); + args.insertOrAssign(FeatureFaceCurvatureFilter::k_FeatureFaceIdsPath_Key, std::make_any(facePath.createChildPath("Ids"))); + args.insertOrAssign(FeatureFaceCurvatureFilter::k_FaceNormalsPath_Key, std::make_any(facePath.createChildPath("Normals"))); + args.insertOrAssign(FeatureFaceCurvatureFilter::k_FaceCentroidsPath_Key, std::make_any(facePath.createChildPath("Centroids"))); + const std::array outputKeys = {FeatureFaceCurvatureFilter::k_PrincipalCurvature1Path_Key, FeatureFaceCurvatureFilter::k_PrincipalCurvature2Path_Key, + FeatureFaceCurvatureFilter::k_GaussianCurvaturePath_Key, FeatureFaceCurvatureFilter::k_MeanCurvaturePath_Key, + FeatureFaceCurvatureFilter::k_WeingartenMatrixPath_Key, FeatureFaceCurvatureFilter::k_PrincipalDirection1Path_Key, + FeatureFaceCurvatureFilter::k_PrincipalDirection2Path_Key}; + for(usize i = 0; i < outputKeys.size(); ++i) + { + args.insertOrAssign(outputKeys[i], std::make_any(facePath.createChildPath("Output" + std::to_string(i)))); + } + FeatureFaceCurvatureFilter filter; + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + auto executeResult = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); + + // Independent oracle: one centroid and normal cannot determine surface curvature. + // The insufficient-patch convention requires NaN in every requested component. + for(usize i = 0; i < (optionalOutputs ? outputKeys.size() : 2); ++i) + { + const auto* output = dataStructure.getDataAs(facePath.createChildPath("Output" + std::to_string(i))); + REQUIRE(output != nullptr); + REQUIRE(output->getNumberOfTuples() == 1); + for(usize c = 0; c < output->getNumberOfComponents(); ++c) + { + CAPTURE(i, c); + CHECK(std::isnan(output->getDataStoreRef().getComponentValue(0, c))); + } + } + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} From c6c9223b222e36d908a7aefc12c4d77355235b2c Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Tue, 3 Nov 2026 17:53:21 -0500 Subject: [PATCH 11/33] BUG: ReadDREAM3D - Warn when an Include List path is not in the file An Include List path that did not exist in the input file was dropped without a warning. Only its existing ancestors were imported, as empty groups, so the pipeline continued with missing data and no message. Preflight now checks every requested Include List path against the file metadata and reports warning -12 for each path that is not in the file. Ancestor import is unchanged. DREAM.3D 6.5.171 (errata KI-081) also gave no warning. Add a test that writes its own file (Group and Group/Values = 42) and checks the warnings and the imported data for a missing leaf, a mix of valid and missing paths, and valid paths only. Fixes #1908 item L43 Signed-off-by: Mike Jackson --- .../SimplnxCore/docs/ReadDREAM3DFilter.md | 2 + .../SimplnxCore/Filters/ReadDREAM3DFilter.cpp | 7 ++ .../SimplnxCore/test/DREAM3DFileTest.cpp | 73 +++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/src/Plugins/SimplnxCore/docs/ReadDREAM3DFilter.md b/src/Plugins/SimplnxCore/docs/ReadDREAM3DFilter.md index 4ad0f9161f..857188f87b 100644 --- a/src/Plugins/SimplnxCore/docs/ReadDREAM3DFilter.md +++ b/src/Plugins/SimplnxCore/docs/ReadDREAM3DFilter.md @@ -12,6 +12,8 @@ This filter reads data from a `.dream3d` file into the pipeline. A `.dream3d` fi The filter does not have to read the entire file. Through the *Import File Path* parameter, the user can browse the structure of the selected `.dream3d` file and choose exactly which data objects to import. Selecting only the objects that are needed avoids loading large arrays that the rest of the pipeline does not use, which saves memory and time. To import everything, simply select all objects. +If an **Include List** path does not exist in the file, preflight reports a warning that names the missing path. Existing ancestors of that path are still imported. They may be empty groups. DREAM3D 6.5.171 did not report this warning. + ### How Imported Objects Are Added The selected objects are added into the pipeline's current **DataStructure** at the same paths they had in the file. If an object being imported has the same path as an object already present in the current **DataStructure**, the existing object is replaced (overwritten) by the imported one, so take care when reading into a non-empty **DataStructure**. Any pipeline metadata stored in the file may also be read when the file is opened. diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ReadDREAM3DFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ReadDREAM3DFilter.cpp index 8f8de32e7d..3012a28bd9 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ReadDREAM3DFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ReadDREAM3DFilter.cpp @@ -98,6 +98,13 @@ IFilter::PreflightResult ReadDREAM3DFilter::preflightImpl(const DataStructure& d if(importData.ImportPolicy == Dream3dImportParameter::PathImportPolicy::IncludeList) { + for(const auto& dataPath : importData.DataPaths) + { + if(!importedDataStructure.containsData(dataPath)) + { + result.warnings().push_back(Warning{-12, fmt::format("The Include List path '{}' does not exist in the input file '{}'.", dataPath.toString(), importData.FilePath.string())}); + } + } auto allDataPaths = importedDataStructure.getAllDataPaths(); std::vector selectedDataPaths = DREAM3D::ExpandSelectedPathsToDescendants(importData.DataPaths, allDataPaths); selectedDataPaths = DREAM3D::ExpandSelectedPathsToAncestors(selectedDataPaths); diff --git a/src/Plugins/SimplnxCore/test/DREAM3DFileTest.cpp b/src/Plugins/SimplnxCore/test/DREAM3DFileTest.cpp index effa28cc57..e2223cb418 100644 --- a/src/Plugins/SimplnxCore/test/DREAM3DFileTest.cpp +++ b/src/Plugins/SimplnxCore/test/DREAM3DFileTest.cpp @@ -1699,6 +1699,79 @@ TEST_CASE("DREAM3DFileTest: Path Import Policy Tests", "[ReadDREAM3DFilter]") UnitTest::CheckArraysInheritTupleDims(dataStructure, SmallIn100::k_TupleCheckIgnoredPaths); } +TEST_CASE("SimplnxCore::ReadDREAM3DFilter: Include List warns for missing paths", "[SimplnxCore][ReadDREAM3DFilter]") +{ + Application::GetOrCreateInstance()->loadPlugins(unit_test::k_BuildDir.view(), true); + + DataStructure writtenData; + auto* group = DataGroup::Create(writtenData, "Group"); + REQUIRE(group != nullptr); + auto store = std::make_shared>(ShapeType{1}, ShapeType{1}, 42); + REQUIRE(Int32Array::Create(writtenData, "Values", store, group->getId()) != nullptr); + const fs::path filePath = GetTestFilePath("read_dream3d_missing_include_paths.dream3d"); + fs::remove(filePath); + auto writeResult = DREAM3D::WriteFile(filePath, writtenData, Pipeline{}, false); + SIMPLNX_RESULT_REQUIRE_VALID(writeResult); + + const DataPath validPath({"Group", "Values"}); + std::vector selectedPaths; + std::vector missingPaths; + SECTION("Missing leaf with existing ancestor") + { + missingPaths = {DataPath({"Group", "Missing"})}; + selectedPaths = missingPaths; + } + SECTION("Mixed valid and missing paths") + { + missingPaths = {DataPath({"Group", "Missing"}), DataPath({"Absent"})}; + selectedPaths = {validPath, missingPaths[0], missingPaths[1]}; + } + SECTION("Existing path") + { + selectedPaths = {validPath}; + } + + // Oracle: the file contains exactly Group and Group/Values (one scalar, 42). + // Group/Missing and Absent do not exist: each must produce a warning naming that path. + // Selecting Group/Values alone must produce no warning and must import the scalar unchanged. + DataStructure dataStructure; + ReadDREAM3DFilter filter; + Arguments args; + Dream3dImportParameter::ImportData importData(filePath, Dream3dImportParameter::PathImportPolicy::IncludeList, selectedPaths); + args.insert(ReadDREAM3DFilter::k_ImportFileData, importData); + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + CHECK(preflightResult.outputActions.warnings().size() == missingPaths.size()); + for(const auto& missingPath : missingPaths) + { + bool foundWarning = false; + for(const auto& warning : preflightResult.outputActions.warnings()) + { + foundWarning = foundWarning || warning.message.find(missingPath.toString()) != std::string::npos; + } + CHECK(foundWarning); + } + + auto executeResult = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); + REQUIRE(dataStructure.containsData(DataPath({"Group"}))); + for(const auto& missingPath : missingPaths) + { + REQUIRE_FALSE(dataStructure.containsData(missingPath)); + } + if(selectedPaths.front() == validPath) + { + const auto* values = dataStructure.getDataAs(validPath); + REQUIRE(values != nullptr); + REQUIRE((*values)[0] == 42); + } + else + { + REQUIRE(dataStructure.getAllDataPaths().size() == 1); + } + fs::remove(filePath); +} + TEST_CASE("SimplnxCore::ReadDREAM3DFilter: SIMPL Backwards Compatibility", "[SimplnxCore][ReadDREAM3DFilter][BackwardsCompatibility]") { auto app = Application::GetOrCreateInstance(); From b14dbe1af36d0051fe66cf887893b5e262812782 Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Tue, 3 Nov 2026 18:06:13 -0500 Subject: [PATCH 12/33] BUG: ReadStlFile - Reject a triangle count that the file is too short to hold A binary STL file with a corrupt triangle count (for example 0x7FFFFFFF) passed preflight. The output arrays were then sized from that count, so a 134-byte file asked for tens of GB or failed with bad_alloc. StlUtilities::SanityCheckFile now rejects a file that is shorter than 84 + 50 * triangle count bytes with the existing error -1108, and preflight calls it before it creates the output actions. Files that are truncated after a real attribute payload still fail in the read loop with -1106 or -1107. DREAM.3D 6.5.171 (errata KI-050) has no file-size check at all. Add a test that declares 0x7FFFFFFF triangles in a 134-byte file and expects -1108 from preflight and execute, and a test that keeps the read-loop errors -1106 and -1107 covered. Fixes #1908 item L44 Signed-off-by: Mike Jackson --- .../SimplnxCore/docs/ReadStlFileFilter.md | 2 + .../SimplnxCore/Filters/ReadStlFileFilter.cpp | 8 ++ .../src/SimplnxCore/utils/StlUtilities.cpp | 18 ++-- .../SimplnxCore/test/ReadStlFileTest.cpp | 101 +++++++++++++++--- 4 files changed, 109 insertions(+), 20 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/ReadStlFileFilter.md b/src/Plugins/SimplnxCore/docs/ReadStlFileFilter.md index a6a0c961d4..6d397a6ba6 100644 --- a/src/Plugins/SimplnxCore/docs/ReadStlFileFilter.md +++ b/src/Plugins/SimplnxCore/docs/ReadStlFileFilter.md @@ -29,6 +29,8 @@ The filter inspects the header to try to determine the vendor of the STL file, b ## IMPORTANT NOTES +After validating the binary header and triangle count, preflight checks the minimum file size: 80 header bytes, 4 count bytes, and 50 bytes for each declared triangle. If this size check fails, preflight returns a file-length error before mesh arrays are allocated. This differs from DREAM3D 6.5.171, where a corrupt triangle count can cause a very large allocation or an allocation failure. + The reader follows the STL specification strictly and obeys the "Attribute byte count" value written after each triangle. If you are writing an STL file, set the "Attribute byte count" to *zero* (0) unless you are deliberately encoding extra data after each triangle, in which case the count must exactly match the number of extra bytes. An incorrect "Attribute byte count" is the most common cause of read failures, because the reader will skip the number of bytes the file claims are present. ## Known Vendors Who Write Out-of-Spec STL Files diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ReadStlFileFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ReadStlFileFilter.cpp index 42d16fae17..877452b536 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ReadStlFileFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ReadStlFileFilter.cpp @@ -137,6 +137,14 @@ IFilter::PreflightResult ReadStlFileFilter::preflightImpl(const DataStructure& d return MakePreflightErrorResult(numTriangles, fmt::format("Error extracting the number of triangles from the STL file '{}'. Returned error code {}.", pStlFilePathValue.string(), numTriangles)); } + // Reject impossible triangle counts before creating actions that allocate the output arrays. + const StlConstants::StlFileCheck stlFileCheck = StlUtilities::SanityCheckFile(pStlFilePathValue); + if(stlFileCheck.error != 0) + { + return MakePreflightErrorResult(stlFileCheck.error, stlFileCheck.errorMessage); + } + numTriangles = stlFileCheck.numTriangles; + // This can happen in a LOT of STL files. Just means the writer didn't go back and update the header. if(numTriangles == 0) { diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/utils/StlUtilities.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/utils/StlUtilities.cpp index f2daa02d64..02f7384b51 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/utils/StlUtilities.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/utils/StlUtilities.cpp @@ -168,20 +168,26 @@ StlConstants::StlFileCheck StlUtilities::SanityCheckFile(const fs::path& path) return stlFileCheck; } - stlFileCheck.header = header; - stlFileCheck.numTriangles = triCount; - stlFileCheck.fileSize = fileSize; - // The size this file would be if none of its triangles carry any attribute payload. The // arithmetic is done in uintmax_t because triCount * k_StlTriangleBytes overflows int32 // for meshes beyond roughly 42.9 million triangles. const uintmax_t sizeWithoutPayload = StlConstants::k_StlFixedHeaderBytes + (static_cast(triCount) * StlConstants::k_StlTriangleBytes); + if(fileSize < sizeWithoutPayload) + { + stlFileCheck.error = StlConstants::k_StlFileLengthError; + stlFileCheck.errorMessage = + fmt::format("STL file '{}' declares {} triangles and requires at least {} bytes, but the file is only {} bytes long.", path.string(), triCount, sizeWithoutPayload, fileSize); + return stlFileCheck; + } + + stlFileCheck.header = header; + stlFileCheck.numTriangles = triCount; + stlFileCheck.fileSize = fileSize; // Only a file with bytes left over beyond the fixed size records has anywhere to put // attribute payload. If the size matches exactly, then every attribute byte count in the file // is something other than a length and must be ignored, no matter what any individual - // triangle happens to contain. A file that is *smaller* than this is truncated; report no - // payload so the reader does not seek, and let the read loop report the truncation precisely. + // triangle happens to contain. Smaller files were rejected above before any mesh allocation. // Vendors known to misuse the field are excluded even when there are spare bytes, since those // bytes may just be trailing junk. stlFileCheck.attributePayloadPresent = (fileSize > sizeWithoutPayload) && !IsMagicsFile(header) && !IsVxElementsFile(header); diff --git a/src/Plugins/SimplnxCore/test/ReadStlFileTest.cpp b/src/Plugins/SimplnxCore/test/ReadStlFileTest.cpp index 5db3c9f179..ddb9277970 100644 --- a/src/Plugins/SimplnxCore/test/ReadStlFileTest.cpp +++ b/src/Plugins/SimplnxCore/test/ReadStlFileTest.cpp @@ -165,6 +165,35 @@ TEST_CASE("SimplnxCore::ReadStlFileFilter:Valid_File", "[SimplnxCore][ReadStlFil UnitTest::CheckArraysInheritTupleDims(dataStructure); } +TEST_CASE("SimplnxCore::ReadStlFileFilter:CorruptTriangleCount", "[SimplnxCore][ReadStlFileFilter]") +{ + UnitTest::LoadPlugins(); + + const fs::path inputFile = fs::path(unit_test::k_BinaryTestOutputDir.view()) / "ReadStlFileTest" / "corrupt_triangle_count.stl"; + WriteBinaryStlFile(inputFile, "Corrupt triangle count", 0x7FFFFFFF, std::vector(1)); + + // Binary STL needs 80 + 4 + 50 * N bytes: 107374182434 for N = 0x7FFFFFFF. + // This file has only 134 bytes (one triangle). Reject it before creating output actions + // so execution cannot allocate arrays for the corrupt count. + REQUIRE(fs::file_size(inputFile) == 134); + + DataStructure dataStructure; + Arguments args; + ReadStlFileFilter filter; + args.insertOrAssign(ReadStlFileFilter::k_StlFilePath_Key, std::make_any(inputFile)); + args.insertOrAssign(ReadStlFileFilter::k_CreatedTriangleGeometryPath_Key, std::make_any(DataPath({"[Triangle Geometry]"}))); + + IFilter::PreflightResult preflightResult; + REQUIRE_NOTHROW(preflightResult = filter.preflight(dataStructure, args)); + SIMPLNX_RESULT_REQUIRE_INVALID(preflightResult.outputActions); + REQUIRE(preflightResult.outputActions.errors().front().code == StlConstants::k_StlFileLengthError); + + IFilter::ExecuteResult executeResult; + REQUIRE_NOTHROW(executeResult = filter.execute(dataStructure, args)); + SIMPLNX_RESULT_REQUIRE_INVALID(executeResult.result); + REQUIRE(executeResult.result.errors().front().code == StlConstants::k_StlFileLengthError); +} + TEST_CASE("SimplnxCore::ReadStlFileFilter:STLParseError", "[SimplnxCore][ReadStlFileFilter]") { UnitTest::LoadPlugins(); @@ -184,15 +213,16 @@ TEST_CASE("SimplnxCore::ReadStlFileFilter:STLParseError", "[SimplnxCore][ReadStl args.insertOrAssign(ReadStlFileFilter::k_StlFilePath_Key, std::make_any(fs::path(inputFile))); args.insertOrAssign(ReadStlFileFilter::k_CreatedTriangleGeometryPath_Key, std::make_any(triangleGeomDataPath)); - // Preflight the filter and check result + // Reject the truncated file before allocating output arrays auto preflightResult = filter.preflight(dataStructure, args); - SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + SIMPLNX_RESULT_REQUIRE_INVALID(preflightResult.outputActions); + REQUIRE(preflightResult.outputActions.errors().front().code == StlConstants::k_StlFileLengthError); // Execute the filter and check the result auto executeResult = filter.execute(dataStructure, args); SIMPLNX_RESULT_REQUIRE_INVALID(executeResult.result); - REQUIRE(executeResult.result.errors().front().code == -1108); + REQUIRE(executeResult.result.errors().front().code == StlConstants::k_StlFileLengthError); UnitTest::CheckArraysInheritTupleDims(dataStructure); } @@ -216,15 +246,16 @@ TEST_CASE("SimplnxCore::ReadStlFileFilter:TriangleParseError", "[SimplnxCore][Re args.insertOrAssign(ReadStlFileFilter::k_StlFilePath_Key, std::make_any(fs::path(inputFile))); args.insertOrAssign(ReadStlFileFilter::k_CreatedTriangleGeometryPath_Key, std::make_any(triangleGeomDataPath)); - // Preflight the filter and check result + // Reject the truncated file before allocating output arrays auto preflightResult = filter.preflight(dataStructure, args); - SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + SIMPLNX_RESULT_REQUIRE_INVALID(preflightResult.outputActions); + REQUIRE(preflightResult.outputActions.errors().front().code == StlConstants::k_StlFileLengthError); // Execute the filter and check the result auto executeResult = filter.execute(dataStructure, args); SIMPLNX_RESULT_REQUIRE_INVALID(executeResult.result); - REQUIRE(executeResult.result.errors().front().code == -1106); + REQUIRE(executeResult.result.errors().front().code == StlConstants::k_StlFileLengthError); UnitTest::CheckArraysInheritTupleDims(dataStructure); } @@ -248,15 +279,16 @@ TEST_CASE("SimplnxCore::ReadStlFileFilter:AttributeParseError", "[SimplnxCore][R args.insertOrAssign(ReadStlFileFilter::k_StlFilePath_Key, std::make_any(fs::path(inputFile))); args.insertOrAssign(ReadStlFileFilter::k_CreatedTriangleGeometryPath_Key, std::make_any(triangleGeomDataPath)); - // Preflight the filter and check result + // Reject the truncated file before allocating output arrays auto preflightResult = filter.preflight(dataStructure, args); - SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + SIMPLNX_RESULT_REQUIRE_INVALID(preflightResult.outputActions); + REQUIRE(preflightResult.outputActions.errors().front().code == StlConstants::k_StlFileLengthError); // Execute the filter and check the result auto executeResult = filter.execute(dataStructure, args); SIMPLNX_RESULT_REQUIRE_INVALID(executeResult.result); - REQUIRE(executeResult.result.errors().front().code == -1107); + REQUIRE(executeResult.result.errors().front().code == StlConstants::k_StlFileLengthError); UnitTest::CheckArraysInheritTupleDims(dataStructure); } @@ -388,6 +420,48 @@ TEST_CASE("SimplnxCore::ReadStlFileFilter:ShortFileWithAttributePayload", "[Simp REQUIRE(executeResult.result.errors().front().message.find(std::to_string(expectedFileSize)) != std::string::npos); } +TEST_CASE("SimplnxCore::ReadStlFileFilter:TruncatedRecordAfterPayload", "[SimplnxCore][ReadStlFileFilter]") +{ + UnitTest::LoadPlugins(); + + const DataPath triangleGeomDataPath({"[Triangle Geometry]"}); + + // Triangle 0 carries 10 real payload bytes, so the file is larger than 84 + 50 * 2 = 184 bytes and + // passes the minimum size check with the attribute counts honored. Triangle 1 starts at byte + // 84 + 50 + 10 = 144 and is cut short, so the read loop itself must report where it stopped. + // - 44 trailing bytes (file size 188): only 11 of the 12 floats can be read. + // - 48 trailing bytes (file size 192): the 12 floats are read, the 2 byte attribute count is not. + const uint16_t k_PayloadBytes = 10; + std::vector triangleSpecs(1); + triangleSpecs[0].attributeByteCount = k_PayloadBytes; + triangleSpecs[0].payloadBytes = k_PayloadBytes; + + auto [trailingBytes, expectedError] = GENERATE(table({{44, StlConstants::k_TriangleParseError}, {48, StlConstants::k_AttributeParseError}})); + + DYNAMIC_SECTION("Trailing bytes: " << trailingBytes) + { + const fs::path inputFile = fs::path(unit_test::k_BinaryTestOutputDir.view()) / "ReadStlFileTest" / "truncated_record_after_payload.stl"; + WriteBinaryStlFile(inputFile, "Payload then a truncated record", 2, triangleSpecs); + { + std::ofstream outputFile(inputFile, std::ios::binary | std::ios::app); + REQUIRE(outputFile.is_open()); + const std::vector partialRecord(trailingBytes, 0x00); + outputFile.write(partialRecord.data(), static_cast(partialRecord.size())); + } + REQUIRE(fs::file_size(inputFile) == 144 + trailingBytes); + + const StlConstants::StlFileCheck stlFileCheck = StlUtilities::SanityCheckFile(inputFile); + REQUIRE(stlFileCheck.error == 0); + REQUIRE(stlFileCheck.numTriangles == 2); + REQUIRE(stlFileCheck.attributePayloadPresent == true); + + DataStructure dataStructure; + auto executeResult = RunReadStlFileFilter(dataStructure, inputFile, triangleGeomDataPath); + SIMPLNX_RESULT_REQUIRE_INVALID(executeResult.result); + REQUIRE(executeResult.result.errors().front().code == expectedError); + } +} + TEST_CASE("SimplnxCore::StlUtilities:SanityCheckFile", "[SimplnxCore][ReadStlFileFilter]") { const fs::path testDir = fs::path(unit_test::k_BinaryTestOutputDir.view()) / "ReadStlFileTest"; @@ -442,16 +516,15 @@ TEST_CASE("SimplnxCore::StlUtilities:SanityCheckFile", "[SimplnxCore][ReadStlFil REQUIRE(stlFileCheck.numTriangles == 0); } - SECTION("Truncated triangle data reports no payload so the reader does not seek") + SECTION("Truncated triangle data is rejected before allocating mesh arrays") { - // The header claims more triangles than the file can hold. The read loop is responsible for - // reporting exactly where it ran out, so SanityCheckFile must not seek past anything. + // 100 triangles require at least 84 + 50 * 100 = 5084 bytes; four records provide only 284. const fs::path inputFile = testDir / "truncated_triangle_data.stl"; WriteBinaryStlFile(inputFile, "Header count is too large", 100, std::vector(4)); const StlConstants::StlFileCheck stlFileCheck = StlUtilities::SanityCheckFile(inputFile); - REQUIRE(stlFileCheck.error == 0); - REQUIRE(stlFileCheck.numTriangles == 100); + REQUIRE(stlFileCheck.error == StlConstants::k_StlFileLengthError); + REQUIRE(stlFileCheck.numTriangles == 0); REQUIRE(stlFileCheck.attributePayloadPresent == false); } } From 47a13476c0512f415de2308b70098b6df52679f1 Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Tue, 3 Nov 2026 18:23:50 -0500 Subject: [PATCH 13/33] BUG: ReadVtkStructuredPoints - Read 2D and 1D files and reject a zero dimension The cell dimensions were computed as point dimensions minus 1 on every axis. A valid 2D file (DIMENSIONS 10 10 1) got 0 cells in Z and failed with -260, and DIMENSIONS 0 underflowed the unsigned value and passed preflight. DREAM.3D 6.5.171 has the same defect (errata KI-083). A singleton axis now keeps one cell, as VTK does, so 2D planes, 1D lines and single points load. A DIMENSIONS value of 0 is rejected in preflight and execute with error -10354, which names the X, Y or Z axis. Add a test that writes ASCII and binary files for all plane and line orientations, a single point and a 3D control, with hand-calculated cell and point counts, and that checks the zero-dimension error. Fixes #1908 item L45 Signed-off-by: Mike Jackson --- .../docs/ReadVtkStructuredPointsFilter.md | 4 +- .../Algorithms/ReadVtkStructuredPoints.cpp | 17 ++- .../Algorithms/ReadVtkStructuredPoints.hpp | 3 +- .../test/ReadVtkStructuredPointsTest.cpp | 103 ++++++++++++++++++ 4 files changed, 121 insertions(+), 6 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/ReadVtkStructuredPointsFilter.md b/src/Plugins/SimplnxCore/docs/ReadVtkStructuredPointsFilter.md index 1ef98e6366..83df79f1a0 100644 --- a/src/Plugins/SimplnxCore/docs/ReadVtkStructuredPointsFilter.md +++ b/src/Plugins/SimplnxCore/docs/ReadVtkStructuredPointsFilter.md @@ -6,7 +6,7 @@ IO (Input) ## Description -This filter reads a *STRUCTURED_POINTS* 3D array from a legacy `.vtk` file and stores it in an **Image Geometry** (a regular grid of equally-sized voxels). A *STRUCTURED_POINTS* file is a general form of an **Image Geometry** in which data values can be attached either to each voxel or to the corner points of each voxel. The file can be either binary or ASCII. The currently supported VTK attribute types are *SCALARS* and *VECTORS*; other attribute types are not read correctly and may cause the filter to fail. +This filter reads a *STRUCTURED_POINTS* grid from a legacy `.vtk` file and stores it in an **Image Geometry** (a regular grid of equally-sized voxels). A *STRUCTURED_POINTS* file is a general form of an **Image Geometry** in which data values can be attached either to each voxel or to the corner points of each voxel. The file can be either binary or ASCII. The currently supported VTK attribute types are *SCALARS* and *VECTORS*; other attribute types are not read correctly and may cause the filter to fail. ### Point Data vs. Cell Data @@ -23,6 +23,8 @@ When both are read, two independent outputs are created: the **Cell Data** is pl The grid dimensions, spacing, and origin are read directly from the `.vtk` file's `DIMENSIONS`, `SPACING`, and `ORIGIN` records. The spacing and origin are plain numbers with no embedded unit, so their length unit is whatever the file's author intended (dimensionless to the reader). +Each cell dimension is one less than its point dimension, with a minimum of one. This supports 2D planes, 1D lines, and a single point. For example, `DIMENSIONS 10 10 1` has 81 cells in a `9 9 1` grid. Zero point dimensions return an error during preflight. These behaviors intentionally differ from DREAM3D 6.5.171, which rejects valid cell data on singleton axes and can underflow on zero dimensions. + ### Example Input # vtk DataFile Version 2.0 diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReadVtkStructuredPoints.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReadVtkStructuredPoints.cpp index 3169d9244c..c1249f92e3 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReadVtkStructuredPoints.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReadVtkStructuredPoints.cpp @@ -9,10 +9,12 @@ #include #include +#include #include #include #include #include +#include #include using namespace nx::core; @@ -702,7 +704,7 @@ Result<> ReadVtkStructuredPoints::readFile() { return result; } - // Cell dimensions subtract one from each point dimension. + // Read point dimensions before deriving cell dimensions. line = std::string(buf.data()); auto tokens = StringUtilities::split(line, ' '); if(tokens.size() != 4) @@ -737,9 +739,16 @@ Result<> ReadVtkStructuredPoints::readFile() pointDims[2] = convertResultSizeT.value(); CreateImageGeometryAction::DimensionType cellDims(3, 0); - cellDims[0] = pointDims[0] - 1; - cellDims[1] = pointDims[1] - 1; - cellDims[2] = pointDims[2] - 1; + constexpr std::array k_AxisNames = {"X", "Y", "Z"}; + for(usize axis = 0; axis < 3; axis++) + { + if(pointDims[axis] == 0) + { + return MakeErrorResult(to_underlying(ErrorCodes::DimsValueErr), + fmt::format("The {} value for the {} axis is 0. Each {} value must be at least 1.", k_DimensionsKeyword, k_AxisNames[axis], k_DimensionsKeyword)); + } + cellDims[axis] = pointDims[axis] > 1 ? pointDims[axis] - 1 : 1; + } std::fill(buf.begin(), buf.end(), '\0'); result = ReadLine(in, buf.data(), kBufferSize); diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReadVtkStructuredPoints.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReadVtkStructuredPoints.hpp index 0d87b866c7..ae7812485c 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReadVtkStructuredPoints.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReadVtkStructuredPoints.hpp @@ -94,7 +94,8 @@ class SIMPLNXCORE_EXPORT ReadVtkStructuredPoints AsciiDataReadErr = -268, ///< Reports truncated or failed ASCII data. AsciiTokenTooLongErr = -269, ///< Reports a token longer than 1,024 characters. AsciiStreamPositionErr = -270, ///< Reports failure to restore the next header position. - NumberConvertErr = -10351 ///< Reports numeric text conversion failure. + NumberConvertErr = -10351, ///< Reports numeric text conversion failure. + DimsValueErr = -10354 ///< Reports a zero point dimension. }; /** diff --git a/src/Plugins/SimplnxCore/test/ReadVtkStructuredPointsTest.cpp b/src/Plugins/SimplnxCore/test/ReadVtkStructuredPointsTest.cpp index 9ed33e3ef8..c730972cbd 100644 --- a/src/Plugins/SimplnxCore/test/ReadVtkStructuredPointsTest.cpp +++ b/src/Plugins/SimplnxCore/test/ReadVtkStructuredPointsTest.cpp @@ -96,6 +96,109 @@ void WriteSectionValues(std::ostream& output, nonstd::span values, bool } } // namespace +TEST_CASE("SimplnxCore::ReadVtkStructuredPointsFilter: Singleton and Zero Dimensions", "[SimplnxCore][ReadVtkStructuredPointsFilter]") +{ + UnitTest::LoadPlugins(); + + const fs::path filePath = fs::path(unit_test::k_BinaryDir.view()) / "ReadVtkDimensions.vtk"; + auto fileGuard = MakeScopeGuard([&filePath]() noexcept { + std::error_code errorCode; + fs::remove(filePath, errorCode); + }); + ReadVtkStructuredPointsFilter filter; + DataStructure ds; + Arguments args = createArgs(filePath); + + SECTION("Singleton axes retain one cell dimension") + { + const bool binary = GENERATE(false, true); + const usize grid = GENERATE(0, 1, 2, 3, 4, 5, 6, 7); + CAPTURE(binary, grid); + // Hand calculation: adjacent points define n-1 cells along an active axis. + // A singleton axis contributes a factor of one, including a single vertex cell. + // Thus 10x10x1 points have 9x9x1 = 81 cells, and 4x1x1 points have 3 cells. + const std::array pointDimensions = {SizeVec3{10, 10, 1}, SizeVec3{3, 1, 4}, SizeVec3{1, 3, 4}, SizeVec3{4, 1, 1}, + SizeVec3{1, 4, 1}, SizeVec3{1, 1, 4}, SizeVec3{1, 1, 1}, SizeVec3{3, 3, 3}}; + const std::array cellDimensions = {SizeVec3{9, 9, 1}, SizeVec3{2, 1, 3}, SizeVec3{1, 2, 3}, SizeVec3{3, 1, 1}, + SizeVec3{1, 3, 1}, SizeVec3{1, 1, 3}, SizeVec3{1, 1, 1}, SizeVec3{2, 2, 2}}; + const auto& pointDims = pointDimensions[grid]; + const auto& cellDims = cellDimensions[grid]; + std::vector pointValues(pointDims[0] * pointDims[1] * pointDims[2]); + std::vector cellValues(cellDims[0] * cellDims[1] * cellDims[2]); + for(usize index = 0; index < pointValues.size(); index++) + { + pointValues[index] = static_cast(index) + 1; + } + for(usize index = 0; index < cellValues.size(); index++) + { + cellValues[index] = static_cast(index) + 100; + } + { + std::ofstream output(filePath, std::ios::binary | std::ios::trunc); + REQUIRE(output.is_open()); + output << "# vtk DataFile Version 3.0\nDimension regression\n" << (binary ? "BINARY\n" : "ASCII\n"); + output << "DATASET STRUCTURED_POINTS\nDIMENSIONS " << pointDims[0] << ' ' << pointDims[1] << ' ' << pointDims[2] << "\nSPACING 1 1 1\nORIGIN 0 0 0\n"; + output << "POINT_DATA " << pointValues.size() << "\nSCALARS Values int 1\nLOOKUP_TABLE default\n"; + WriteSectionValues(output, pointValues, binary); + output << "CELL_DATA " << cellValues.size() << "\nSCALARS Values int 1\nLOOKUP_TABLE default\n"; + WriteSectionValues(output, cellValues, binary); + output.close(); + REQUIRE(output.good()); + } + + const auto preflightResult = filter.preflight(ds, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + const auto executeResult = filter.execute(ds, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); + for(const bool points : {false, true}) + { + const DataPath geomPath({points ? "VTK Point Data" : "VTK Cell Data"}); + const auto& geom = ds.getDataRefAs(geomPath); + REQUIRE(geom.getDimensions() == (points ? pointDims : cellDims)); + const auto& values = ds.getDataRefAs(geomPath.createChildPath(points ? "Vertex Data" : "Cell Data").createChildPath("Values")); + REQUIRE(values.getNumberOfTuples() == (points ? pointValues.size() : cellValues.size())); + REQUIRE(values.getNumberOfComponents() == 1); + for(usize index = 0; index < values.getNumberOfTuples(); index++) + { + REQUIRE(values[index] == static_cast(index) + (points ? 1 : 100)); + } + } + UnitTest::CheckArraysInheritTupleDims(ds); + } + + SECTION("Zero dimensions are rejected before creating geometry") + { + const usize axis = GENERATE(0, 1, 2); + CAPTURE(axis); + SizeVec3 pointDims{1, 1, 1}; + pointDims[axis] = 0; + // A structured-points dimension must be at least one. A zero axis is invalid, + // even when CELL_DATA declares zero tuples; unsigned subtraction must not wrap. + { + std::ofstream output(filePath, std::ios::trunc); + REQUIRE(output.is_open()); + output << "# vtk DataFile Version 3.0\nZero dimension\nASCII\nDATASET STRUCTURED_POINTS\nDIMENSIONS "; + output << pointDims[0] << ' ' << pointDims[1] << ' ' << pointDims[2] << "\nSPACING 1 1 1\nORIGIN 0 0 0\nCELL_DATA 0\n"; + output.close(); + REQUIRE(output.good()); + } + args.insertOrAssign(ReadVtkStructuredPointsFilter::k_ReadPointData_Key, std::make_any(false)); + IFilter::PreflightResult preflightResult; + REQUIRE_NOTHROW(preflightResult = filter.preflight(ds, args)); + SIMPLNX_RESULT_REQUIRE_INVALID(preflightResult.outputActions); + REQUIRE(preflightResult.outputActions.errors()[0].code == -10354); + // The message names the axis as X, Y or Z, not as a zero-based index. + const std::array axisNames = {"X axis", "Y axis", "Z axis"}; + REQUIRE(preflightResult.outputActions.errors()[0].message.find(axisNames[axis]) != std::string::npos); + IFilter::ExecuteResult executeResult; + REQUIRE_NOTHROW(executeResult = filter.execute(ds, args)); + SIMPLNX_RESULT_REQUIRE_INVALID(executeResult.result); + REQUIRE(executeResult.result.errors().size() == 1); + REQUIRE(executeResult.result.errors()[0].code == -10354); + REQUIRE(ds.getData(DataPath({"VTK Cell Data"})) == nullptr); + } +} + TEST_CASE("SimplnxCore::ReadVtkStructuredPointsFilter: Section Selection", "[SimplnxCore][ReadVtkStructuredPointsFilter]") { UnitTest::LoadPlugins(); From 39414a2f19529f1fdba2c9556a8c007fbefa865a Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Tue, 3 Nov 2026 18:39:40 -0500 Subject: [PATCH 14/33] BUG: ReadH5OimData - Stack the selected scans in the chosen Z order The OIM and Esprit readers read the selected scans in selection order and always wrote scan i to Z slice i. The Stacking Order setting was never used, so High to Low gave the same volume as Low to High. DREAM.3D 6.5.171 has the same defect (errata KI-011). The shared IEbsdOemReader loop still reads the scans in selection order, but now copies scan i to slice N-1-i when the order is High to Low. The H5OINA reader has its own loop and already honored the setting. Add a test that writes a distinct IQ value into each of three OIM scans, selects them as [2, 1, 3], and checks every IQ value for both orders against the hand-derived slice order. Fixes #1908 item L54 Signed-off-by: Mike Jackson --- .../docs/ReadH5EspritDataFilter.md | 2 + .../docs/ReadH5OimDataFilter.md | 4 +- .../Filters/Algorithms/ReadH5EspritData.hpp | 2 +- .../Filters/Algorithms/ReadH5OimData.hpp | 2 +- .../utilities/IEbsdOemReader.hpp | 7 +- .../test/ReadH5OimDataTest.cpp | 83 +++++++++++++++++++ 6 files changed, 94 insertions(+), 6 deletions(-) diff --git a/src/Plugins/OrientationAnalysis/docs/ReadH5EspritDataFilter.md b/src/Plugins/OrientationAnalysis/docs/ReadH5EspritDataFilter.md index b84da017a3..cb4e393259 100644 --- a/src/Plugins/OrientationAnalysis/docs/ReadH5EspritDataFilter.md +++ b/src/Plugins/OrientationAnalysis/docs/ReadH5EspritDataFilter.md @@ -12,6 +12,8 @@ Each measurement is placed at the grid cell named by its own `X BEAM` and `Y BEA The scan stores an **orientation** at every pixel as three **Euler angles** (three angles, in the Bunge Z-X-Z convention, describing how the measured crystal at that pixel is rotated relative to the sample). +The **Scan Names** stacking order controls placement along the **Image Geometry** Z direction. **Low to High** places the first selected scan at the lowest Z slice. **High to Low** places it at the highest Z slice and places the last selected scan at the lowest Z slice. A single scan has the same placement in either order. High to Low output intentionally differs from DREAM3D 6.5.171, which ignored this setting (errata KI-011). + | User interface before entering a proper "Z Spacing" value and selecting which scans to include. | |-------| |![](Images/ReadEspritH5_1.png)| diff --git a/src/Plugins/OrientationAnalysis/docs/ReadH5OimDataFilter.md b/src/Plugins/OrientationAnalysis/docs/ReadH5OimDataFilter.md index 10f8082243..2c58275789 100644 --- a/src/Plugins/OrientationAnalysis/docs/ReadH5OimDataFilter.md +++ b/src/Plugins/OrientationAnalysis/docs/ReadH5OimDataFilter.md @@ -33,7 +33,9 @@ the user should **CHECK** the option **ON** for "Perform Slice By Slice Transfor ## Algorithm -Each selected scan is appended in selection order along the **Image Geometry** Z direction. Phase values are clamped and Euler components are interleaved into their output array; scalar measurements, including X and Y positions, are copied at that scan's tuple offset. Pattern data uses the same tuple offset multiplied by its pattern component count. Output arrays are written in bounded bulk transfers, which supports out-of-core output storage. +The **Scan Names** stacking order controls placement along the **Image Geometry** Z direction. **Low to High** places the first selected scan at the lowest Z slice. **High to Low** places it at the highest Z slice and places the last selected scan at the lowest Z slice. A single scan has the same placement in either order. High to Low output intentionally differs from DREAM3D 6.5.171, which ignored this setting (errata KI-011). + +Phase values are clamped and Euler components are interleaved into their output array; scalar measurements, including X and Y positions, are copied at that scan's tuple offset. Pattern data uses the same tuple offset multiplied by its pattern component count. Output arrays are written in bounded bulk transfers, which supports out-of-core output storage. ### X Position and Y Position diff --git a/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/ReadH5EspritData.hpp b/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/ReadH5EspritData.hpp index 58912514de..e3f7480223 100644 --- a/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/ReadH5EspritData.hpp +++ b/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/ReadH5EspritData.hpp @@ -59,7 +59,7 @@ class ORIENTATIONANALYSIS_EXPORT ReadH5EspritData : public IEbsdOemReader copyRawEbsdData(int sliceIndex) override; diff --git a/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/utilities/IEbsdOemReader.hpp b/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/utilities/IEbsdOemReader.hpp index 8f4da4686d..df3d7fde2b 100644 --- a/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/utilities/IEbsdOemReader.hpp +++ b/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/utilities/IEbsdOemReader.hpp @@ -73,7 +73,7 @@ class ORIENTATIONANALYSIS_EXPORT IEbsdOemReader IEbsdOemReader& operator=(IEbsdOemReader&&) noexcept = delete; /** - * @brief Loads and copies each selected scan in selection order. + * @brief Loads scans in selection order and copies them to the requested Z stacking order. * @return Reader, phase-metadata, or derived copy errors. * * The method sets the destination geometry unit to micrometers before import. @@ -100,7 +100,8 @@ class ORIENTATIONANALYSIS_EXPORT IEbsdOemReader return readResults; } - Result<> copyDataResults = copyRawEbsdData(index); + const int sliceIndex = m_InputValues->SelectedScanNames.stackingOrder == RefFrameZDir::k_HightoLow ? static_cast(scanNames.size()) - 1 - index : index; + Result<> copyDataResults = copyRawEbsdData(sliceIndex); if(copyDataResults.invalid()) { return copyDataResults; @@ -177,7 +178,7 @@ class ORIENTATIONANALYSIS_EXPORT IEbsdOemReader /** * @brief Copies the currently loaded scan into its destination volume range. - * @param index Zero-based scan index. + * @param index Zero-based destination Z slice. execute() computes it from the selection index and the stacking order. * @return Source conversion or destination transfer errors. */ virtual Result<> copyRawEbsdData(int index) = 0; diff --git a/src/Plugins/OrientationAnalysis/test/ReadH5OimDataTest.cpp b/src/Plugins/OrientationAnalysis/test/ReadH5OimDataTest.cpp index 90e250b1a3..48b6348d79 100644 --- a/src/Plugins/OrientationAnalysis/test/ReadH5OimDataTest.cpp +++ b/src/Plugins/OrientationAnalysis/test/ReadH5OimDataTest.cpp @@ -17,6 +17,8 @@ #include #include +#include + #include #include #include @@ -83,6 +85,87 @@ void RequireAcquisitionCoordinates(const DataStructure& dataStructure, usize sca } } // namespace +TEST_CASE("OrientationAnalysis::ReadH5OimDataFilter: Scan Stacking Order", "[OrientationAnalysis][ReadH5OimDataFilter]") +{ + UnitTest::LoadPlugins(); + const UnitTest::TestFileSentinel testDataSentinel(unit_test::k_TestFilesDir, "7_read_oem_ebsd_h5_files_v3.tar.gz", "7_read_oem_ebsd_h5_files_v3"); + const auto sourceFile = fs::path(fmt::format("{}/7_read_oem_ebsd_h5_files_v3/EdaxOIMData.h5", unit_test::k_TestFilesDir)); + const auto inputFile = fs::path(unit_test::k_BinaryTestOutputDir.view()) / "ReadH5OimData_StackingOrder.h5"; + fs::copy_file(sourceFile, inputFile, fs::copy_options::overwrite_existing); + + constexpr usize k_TuplesPerScan = 186 * 151; + { + const hid_t fileId = H5Fopen(inputFile.string().c_str(), H5F_ACC_RDWR, H5P_DEFAULT); + REQUIRE(fileId >= 0); + H5Support::H5ScopedFileSentinel sentinel(fileId, true); + // The downloaded scans have identical IQ values. Give scan s the exact + // integer-valued signal IQ(s, p) = 100000*s + p, where p is the pixel index. + for(int32 scan = 1; scan <= 3; scan++) + { + std::vector values(k_TuplesPerScan); + for(usize pixel = 0; pixel < k_TuplesPerScan; pixel++) + { + values[pixel] = static_cast(100000 * scan + pixel); + } + const std::string datasetPath = fmt::format("/Scan {}/EBSD/Data/IQ", scan); + const hid_t datasetId = H5Dopen2(fileId, datasetPath.c_str(), H5P_DEFAULT); + REQUIRE(datasetId >= 0); + const herr_t writeResult = H5Dwrite(datasetId, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, values.data()); + REQUIRE(H5Dclose(datasetId) >= 0); + REQUIRE(writeResult >= 0); + } + } + + OEMEbsdScanSelectionParameter::ValueType scanSelections = {inputFile, RefFrameZDir::k_LowtoHigh, {k_ScanName_2, k_ScanName_1, k_ScanName_3}}; + std::vector expectedScans; + // For N selected scans, selection index i occupies Z slice i (Low to High) + // or N-1-i (High to Low). Thus [2,1,3] becomes [2,1,3] or [3,1,2] in Z. + SECTION("Low to High") + { + expectedScans = {2, 1, 3}; + } + SECTION("High to Low") + { + scanSelections.stackingOrder = RefFrameZDir::k_HightoLow; + expectedScans = {3, 1, 2}; + } + SECTION("High to Low single scan") + { + scanSelections.stackingOrder = RefFrameZDir::k_HightoLow; + scanSelections.scanNames = {k_ScanName_2}; + expectedScans = {2}; + } + + DataStructure dataStructure; + ReadH5OimDataFilter filter; + Arguments args; + args.insertOrAssign(ReadH5OimDataFilter::k_SelectedScanNames_Key, std::make_any(scanSelections)); + args.insertOrAssign(ReadH5OimDataFilter::k_ZSpacing_Key, std::make_any(1.0f)); + args.insertOrAssign(ReadH5OimDataFilter::k_Origin_Key, std::make_any(std::vector(3, 0.0f))); + args.insertOrAssign(ReadH5OimDataFilter::k_ReadPatternData_Key, std::make_any(false)); + const DataPath geometryPath({ImageGeom::k_TypeName}); + args.insertOrAssign(ReadH5OimDataFilter::k_CreatedImageGeometryPath_Key, std::make_any(geometryPath)); + args.insertOrAssign(ReadH5OimDataFilter::k_CellAttributeMatrixName_Key, std::make_any(k_Cell_Data)); + args.insertOrAssign(ReadH5OimDataFilter::k_CellEnsembleAttributeMatrixName_Key, std::make_any(k_Cell_Ensemble_Data)); + + const auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions) + const auto executeResult = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result) + REQUIRE(dataStructure.getDataRefAs(geometryPath).getDimensions() == SizeVec3{186, 151, expectedScans.size()}); + const auto& imageQuality = dataStructure.getDataRefAs(geometryPath.createChildPath(k_Cell_Data).createChildPath(ebsdlib::Ang::ImageQuality)); + REQUIRE(imageQuality.getNumberOfTuples() == k_TuplesPerScan * expectedScans.size()); + for(usize slice = 0; slice < expectedScans.size(); slice++) + { + for(usize pixel = 0; pixel < k_TuplesPerScan; pixel++) + { + CAPTURE(slice, pixel); + REQUIRE(imageQuality[slice * k_TuplesPerScan + pixel] == static_cast(100000 * expectedScans[slice] + pixel)); + } + } + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} + TEST_CASE("OrientationAnalysis::ReadH5OimDataFilter: Acquisition Coordinates", "[OrientationAnalysis][ReadH5OimDataFilter]") { UnitTest::LoadPlugins(); From efbaae5a3c994f01e4ba47e8a118cee8dde4e4d7 Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Tue, 3 Nov 2026 18:47:32 -0500 Subject: [PATCH 15/33] BUG: WriteINLFile - Write the TSL symmetry code of every Laue class in the data rows The data rows mapped only Cubic_High (43) and Hexagonal_High (62). Every other Laue class was written as UnknownSymmetry (999), while the header mapped all classes. The default branch of the mapping also returned UnknownCrystalStructure instead of UnknownSymmetry. DREAM.3D 6.5.171 has the same defect (errata KI-012). The data rows now use the same mapping as the header, and an unknown structure maps to UnknownSymmetry (999). Phase 0 is still written as 999. Add a test with one cell for phase 0, each of the 11 Laue classes, an unknown structure and an unsupported value. It checks every header line and data row against the TSL code table, on both algorithm paths. Fixes #1908 item L55 Signed-off-by: Mike Jackson --- .../docs/WriteINLFileFilter.md | 4 +- .../Filters/Algorithms/WriteINLFile.cpp | 25 +--- .../test/WriteINLFileTest.cpp | 113 ++++++++++++++++++ 3 files changed, 119 insertions(+), 23 deletions(-) diff --git a/src/Plugins/OrientationAnalysis/docs/WriteINLFileFilter.md b/src/Plugins/OrientationAnalysis/docs/WriteINLFileFilter.md index 99a1f86077..4c36826de5 100644 --- a/src/Plugins/OrientationAnalysis/docs/WriteINLFileFilter.md +++ b/src/Plugins/OrientationAnalysis/docs/WriteINLFileFilter.md @@ -18,7 +18,9 @@ This **Filter** writes out **Cell** data from an **Image Geometry** to a file fo - Phase Id -- the ensemble (phase) each cell belongs to - Symmetry -- the crystal-symmetry code for the cell's phase -The **Symmetry** column holds the integer crystal-symmetry code corresponding to the cell's crystal structure (for example, *43* denotes cubic m-3m and *62* denotes hexagonal 6/mmm). The codes follow the EBSDLib `CrystalStructure` enumeration and are taken from the **Crystal Structures** ensemble array. +The **Symmetry** column holds the TSL phase-symmetry code for the cell's crystal structure. For example, *43* denotes cubic m-3m and *62* denotes hexagonal 6/mmm. The filter converts the **Crystal Structures** values to these codes. The phase headers and data rows use the same mapping for all 11 Laue classes. Unknown or unsupported structures use *999*. Cells with phase zero also use *999*. + +This intentionally differs from DREAM.3D 6.5.171. That version wrote *999* in data rows for every Laue class except cubic-high and hexagonal-high. Some information about the phase is included in the header section of the file in addition to values for the origin, step size, and dimensions. The origin, **step sizes** (`X_STEP`, `Y_STEP`, `Z_STEP`), and min/max positions in the header are all in **microns**. The header also reports the number of **Features** in the file. diff --git a/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/WriteINLFile.cpp b/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/WriteINLFile.cpp index 85ecf7eb16..4360999eb0 100644 --- a/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/WriteINLFile.cpp +++ b/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/WriteINLFile.cpp @@ -30,7 +30,7 @@ constexpr usize k_EulerComponents = 3; /** * @brief Maps a simplnx crystal structure to the INL TSL symmetry code. * @param symmetry Simplnx crystal-structure value. - * @return Matching TSL phase symmetry, or UnknownCrystalStructure when unsupported. + * @return Matching TSL phase symmetry, or UnknownSymmetry when unsupported. */ uint32 mapCrystalSymmetryToTslSymmetry(uint32 symmetry) { @@ -59,7 +59,7 @@ uint32 mapCrystalSymmetryToTslSymmetry(uint32 symmetry) case ebsdlib::CrystalStructure::Trigonal_Low: return ebsdlib::Ang::PhaseSymmetry::Trigonal; default: - return ebsdlib::CrystalStructure::UnknownCrystalStructure; + return ebsdlib::Ang::PhaseSymmetry::UnknownSymmetry; } } } // namespace @@ -303,26 +303,7 @@ Result<> WriteINLFile::operator()() const float64 yPos = origin[1] + (static_cast(y) * res[1]); const float64 zPos = origin[2] + (static_cast(z) * res[2]); const int32 phaseId = cellPhasesChunk[chunkIndex]; - uint32 symmetry = crystalStructuresCache[phaseId]; - if(phaseId > 0) - { - if(symmetry == ebsdlib::CrystalStructure::Cubic_High) - { - symmetry = ebsdlib::Ang::PhaseSymmetry::Cubic; - } - else if(symmetry == ebsdlib::CrystalStructure::Hexagonal_High) - { - symmetry = ebsdlib::Ang::PhaseSymmetry::DiHexagonal; - } - else - { - symmetry = ebsdlib::Ang::PhaseSymmetry::UnknownSymmetry; - } - } - else - { - symmetry = ebsdlib::Ang::PhaseSymmetry::UnknownSymmetry; - } + const uint32 symmetry = phaseId > 0 ? mapCrystalSymmetryToTslSymmetry(crystalStructuresCache[phaseId]) : ebsdlib::Ang::PhaseSymmetry::UnknownSymmetry; textStream << phi1 << " " << phi << " " << phi2 << " " << xPos << " " << yPos << " " << zPos << " " << featureIdsChunk[chunkIndex] << " " << phaseId << " " << symmetry << "\n"; diff --git a/src/Plugins/OrientationAnalysis/test/WriteINLFileTest.cpp b/src/Plugins/OrientationAnalysis/test/WriteINLFileTest.cpp index a999007341..72813f8b7b 100644 --- a/src/Plugins/OrientationAnalysis/test/WriteINLFileTest.cpp +++ b/src/Plugins/OrientationAnalysis/test/WriteINLFileTest.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include #include @@ -258,6 +260,117 @@ TEST_CASE("OrientationAnalysis::WriteINLFileFilter: Valid Filter Execution", "[O UnitTest::CheckArraysInheritTupleDims(dataStructure); } +TEST_CASE("OrientationAnalysis::WriteINLFileFilter: All Laue symmetry codes", "[OrientationAnalysis][WriteINLFileFilter]") +{ + UnitTest::LoadPlugins(); + const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); + CAPTURE(scenario); + UnitTest::AlgorithmTestScope scope(scenario); + + // Independent oracle: the TSL Laue codes (AngConstants.h) are m-3m=43, m-3=23, + // 4/mmm=42, 4/m=4, mmm=22, 2/m (c axis)=2, -1=1, 6/mmm=62, 6/m=6, -3m=32, + // and -3=3. Unknown/unsupported structures and phase zero must use TSL unknown=999. + // Give phase zero a known structure to verify that it remains an unknown phase. + const std::array structures = {ebsdlib::CrystalStructure::Cubic_High, + ebsdlib::CrystalStructure::Cubic_High, + ebsdlib::CrystalStructure::Cubic_Low, + ebsdlib::CrystalStructure::Tetragonal_High, + ebsdlib::CrystalStructure::Tetragonal_Low, + ebsdlib::CrystalStructure::OrthoRhombic, + ebsdlib::CrystalStructure::Monoclinic, + ebsdlib::CrystalStructure::Triclinic, + ebsdlib::CrystalStructure::Hexagonal_High, + ebsdlib::CrystalStructure::Hexagonal_Low, + ebsdlib::CrystalStructure::Trigonal_High, + ebsdlib::CrystalStructure::Trigonal_Low, + ebsdlib::CrystalStructure::UnknownCrystalStructure, + 12345}; + const std::array expectedCodes = {999, 43, 23, 42, 4, 22, 2, 1, 62, 6, 32, 3, 999, 999}; + const usize numCells = structures.size(); + + DataStructure dataStructure; + auto* imageGeom = ImageGeom::Create(dataStructure, "ImageGeometry"); + REQUIRE(imageGeom != nullptr); + imageGeom->setDimensions({numCells, 1, 1}); + imageGeom->setSpacing({1.0F, 1.0F, 1.0F}); + imageGeom->setOrigin({0.0F, 0.0F, 0.0F}); + auto* cellData = AttributeMatrix::Create(dataStructure, "Cell Data", {1, 1, numCells}, imageGeom->getId()); + REQUIRE(cellData != nullptr); + imageGeom->setCellData(*cellData); + auto* featureIds = Int32Array::CreateWithStore(dataStructure, "FeatureIds", {1, 1, numCells}, {1}, cellData->getId()); + auto* phases = Int32Array::CreateWithStore(dataStructure, "Phases", {1, 1, numCells}, {1}, cellData->getId()); + auto* eulers = Float32Array::CreateWithStore(dataStructure, "EulerAngles", {1, 1, numCells}, {3}, cellData->getId()); + REQUIRE(featureIds != nullptr); + REQUIRE(phases != nullptr); + REQUIRE(eulers != nullptr); + eulers->fill(0.0F); + auto* crystalStructures = UInt32Array::CreateWithStore(dataStructure, "CrystalStructures", {numCells}, {1}); + auto* numFeatures = Int32Array::CreateWithStore(dataStructure, "NumFeatures", {numCells}, {1}); + REQUIRE(crystalStructures != nullptr); + REQUIRE(numFeatures != nullptr); + numFeatures->fill(1); + REQUIRE(StringArray::CreateWithValues(dataStructure, "Materials", {numCells}, std::vector(numCells, "Phase")) != nullptr); + for(usize i = 0; i < numCells; ++i) + { + (*featureIds)[i] = static_cast(i); + (*phases)[i] = static_cast(i); + (*crystalStructures)[i] = structures[i]; + } + + const fs::path outputPath = fs::temp_directory_path() / "nx_all_laue_inl_writer.inl"; + auto outputFileGuard = MakeScopeGuard([&outputPath]() noexcept { + std::error_code errorCode; + fs::remove(outputPath, errorCode); + }); + WriteINLFileFilter filter; + Arguments args = filter.getDefaultArguments(); + args.insertOrAssign(WriteINLFileFilter::k_OutputFile_Key, std::make_any(outputPath)); + args.insertOrAssign(WriteINLFileFilter::k_ImageGeomPath_Key, std::make_any(DataPath({"ImageGeometry"}))); + args.insertOrAssign(WriteINLFileFilter::k_FeatureIdsArrayPath_Key, std::make_any(DataPath({"ImageGeometry", "Cell Data", "FeatureIds"}))); + args.insertOrAssign(WriteINLFileFilter::k_CellPhasesArrayPath_Key, std::make_any(DataPath({"ImageGeometry", "Cell Data", "Phases"}))); + args.insertOrAssign(WriteINLFileFilter::k_CellEulerAnglesArrayPath_Key, std::make_any(DataPath({"ImageGeometry", "Cell Data", "EulerAngles"}))); + args.insertOrAssign(WriteINLFileFilter::k_CrystalStructuresArrayPath_Key, std::make_any(DataPath({"CrystalStructures"}))); + args.insertOrAssign(WriteINLFileFilter::k_NumFeaturesArrayPath_Key, std::make_any(DataPath({"NumFeatures"}))); + args.insertOrAssign(WriteINLFileFilter::k_MaterialNameArrayPath_Key, std::make_any(DataPath({"Materials"}))); + const auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + const auto executeResult = scope.executeFilter(filter, dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); + + std::ifstream inputStream(outputPath); + REQUIRE(inputStream.is_open()); + usize rowCount = 0; + usize headerCount = 0; + std::string line; + while(std::getline(inputStream, line)) + { + if(line.rfind("# Symmetry_", 0) == 0) + { + ++headerCount; + REQUIRE(headerCount < numCells); + CAPTURE(headerCount); + CHECK(line == fmt::format("# Symmetry_{}: {}", headerCount, expectedCodes[headerCount])); + } + if(line.empty() || line[0] == '#') + { + continue; + } + REQUIRE(rowCount < numCells); + CAPTURE(rowCount); + std::istringstream row(line); + float64 phi1 = 0, phi = 0, phi2 = 0, x = 0, y = 0, z = 0; + int32 featureId = -1, phaseId = -1; + uint32 symmetry = 0; + REQUIRE(static_cast(row >> phi1 >> phi >> phi2 >> x >> y >> z >> featureId >> phaseId >> symmetry)); + CHECK(phaseId == static_cast(rowCount)); + CHECK(symmetry == expectedCodes[rowCount]); + ++rowCount; + } + CHECK(headerCount == numCells - 1); + CHECK(rowCount == numCells); + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} + TEST_CASE("OrientationAnalysis::WriteINLFileFilter: cancellation leaves the existing output untouched", "[OrientationAnalysis][WriteINLFileFilter]") { UnitTest::LoadPlugins(); From 3fb7e606adad4c25e529a11046d5839e962927f9 Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Tue, 3 Nov 2026 18:53:45 -0500 Subject: [PATCH 16/33] BUG: WriteStatsGenOdfAngleFile - Write a colon when the Colon delimiter is chosen Delimiter choice 3 is labeled Colon in the parameter and in the file header, but the rows were written with a double quote (") between the values. DREAM.3D 6.5.171 has the same defect (errata KI-015). The delimiter table now uses : for that choice. No reader takes the delimiter from the header line, and the StatsGenerator header line "Angle Count:N" is read before the data rows, so the change breaks no reader. Add a test with two masked tuples in two phases that checks the exact colon-separated rows (hand-converted to degrees) in the Direct and Scanline algorithms. Fixes #1908 item L56 Signed-off-by: Mike Jackson --- .../docs/WriteStatsGenOdfAngleFileFilter.md | 2 + .../Algorithms/WriteStatsGenOdfAngleFile.cpp | 4 +- .../test/WriteStatsGenOdfAngleFileTest.cpp | 46 +++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/Plugins/OrientationAnalysis/docs/WriteStatsGenOdfAngleFileFilter.md b/src/Plugins/OrientationAnalysis/docs/WriteStatsGenOdfAngleFileFilter.md index 9fe88d1efd..863710a565 100644 --- a/src/Plugins/OrientationAnalysis/docs/WriteStatsGenOdfAngleFileFilter.md +++ b/src/Plugins/OrientationAnalysis/docs/WriteStatsGenOdfAngleFileFilter.md @@ -62,6 +62,8 @@ The *Delimiter* parameter provides the following choices: - **: (colon) [3]**: Uses a colon as the column separator. - **\t (tab) [4]**: Uses a tab character as the column separator. +The Colon option now writes `:` between values. This intentionally differs from DREAM3D 6.5.171, which wrote double quotes for this option (errata KI-015). + ## Required Input Sources - **Euler Angles** -- typically read from EBSD data via [Read H5EBSD File](ReadH5EbsdFilter.md), [Read EDAX EBSD Data (.ang)](ReadAngDataFilter.md), or [Read Oxford Instr. EBSD Data (.ctf)](ReadCtfDataFilter.md). Supplied in radians (Bunge Z-X-Z convention); use the *Convert to Degrees* option only if **StatsGenerator** will import them as degrees. diff --git a/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/WriteStatsGenOdfAngleFile.cpp b/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/WriteStatsGenOdfAngleFile.cpp index 04fb2e6bf4..7ba831caed 100644 --- a/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/WriteStatsGenOdfAngleFile.cpp +++ b/src/Plugins/OrientationAnalysis/src/OrientationAnalysis/Filters/Algorithms/WriteStatsGenOdfAngleFile.cpp @@ -26,9 +26,7 @@ namespace { constexpr usize k_ChunkTuples = 65536; constexpr usize k_EulerComponents = 3; -// Choice three is labeled Colon but currently writes a double quote. Preserve -// this mismatch until output-format behavior is changed explicitly. -constexpr std::array k_Delimiters = {',', ';', ' ', '"', '\t'}; +constexpr std::array k_Delimiters = {',', ';', ' ', ':', '\t'}; const std::array k_DelimiterStr = {"Comma", "Semicolon", "Space", "Colon", "Tab"}; void WriteHeader(std::ofstream& out, const WriteStatsGenOdfAngleFileInputValues& inputValues, int32 lineCount) diff --git a/src/Plugins/OrientationAnalysis/test/WriteStatsGenOdfAngleFileTest.cpp b/src/Plugins/OrientationAnalysis/test/WriteStatsGenOdfAngleFileTest.cpp index e4b201b137..42211eae94 100644 --- a/src/Plugins/OrientationAnalysis/test/WriteStatsGenOdfAngleFileTest.cpp +++ b/src/Plugins/OrientationAnalysis/test/WriteStatsGenOdfAngleFileTest.cpp @@ -206,6 +206,52 @@ TEST_CASE("OrientationAnalysis::WriteStatsGenOdfAngleFileFilter: analytical Bool UnitTest::CheckArraysInheritTupleDims(dataStructure); } +TEST_CASE("OrientationAnalysis::WriteStatsGenOdfAngleFileFilter: Colon delimiter writes colon separated rows", "[OrientationAnalysis][WriteStatsGenOdfAngleFileFilter]") +{ + UnitTest::LoadPlugins(); + const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); + CAPTURE(scenario); + UnitTest::AlgorithmTestScope scope(scenario); + + DataStructure dataStructure = CreateAnalyticalDataStructure(); + scope.requireExpectedStore(dataStructure.getDataRefAs(k_AnalyticalEulersPath)); + + const fs::path outputFile = fs::path(fmt::format("{}/StatsGenODF_Colon.txt", unit_test::k_BinaryTestOutputDir)); + WriteStatsGenOdfAngleFileFilter filter; + Arguments args = filter.getDefaultArguments(); + args.insertOrAssign(WriteStatsGenOdfAngleFileFilter::k_OutputFile_Key, std::make_any(outputFile)); + args.insertOrAssign(WriteStatsGenOdfAngleFileFilter::k_Weight_Key, std::make_any(2.5F)); + args.insertOrAssign(WriteStatsGenOdfAngleFileFilter::k_Sigma_Key, std::make_any(3)); + args.insertOrAssign(WriteStatsGenOdfAngleFileFilter::k_Delimiter_Key, std::make_any(WriteStatsGenOdfAngleFileFilter::k_ColonDelimiter)); + args.insertOrAssign(WriteStatsGenOdfAngleFileFilter::k_ConvertToDegrees_Key, std::make_any(true)); + args.insertOrAssign(WriteStatsGenOdfAngleFileFilter::k_UseMask_Key, std::make_any(true)); + args.insertOrAssign(WriteStatsGenOdfAngleFileFilter::k_CellEulerAnglesArrayPath_Key, std::make_any(k_AnalyticalEulersPath)); + args.insertOrAssign(WriteStatsGenOdfAngleFileFilter::k_CellPhasesArrayPath_Key, std::make_any(k_AnalyticalPhasesPath)); + args.insertOrAssign(WriteStatsGenOdfAngleFileFilter::k_MaskArrayPath_Key, std::make_any(k_AnalyticalBoolMaskPath)); + + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions) + auto executeResult = scope.executeFilter(filter, dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result) + + // The mask keeps (0, pi/2, pi) in phase 1 and (pi/2, 0, pi/2) in phase 2. + // Multiplying by 180/pi gives (0, 90, 180) and (90, 0, 90) degrees. + // Append the supplied weight 2.5 and sigma 3, separating all five values with ':'. + const std::array expectedRows = {"0.00000000:90.00000000:180.00000000:2.50000000:3", "90.00000000:0.00000000:90.00000000:2.50000000:3"}; + for(usize phaseIndex = 0; phaseIndex < expectedRows.size(); phaseIndex++) + { + CAPTURE(phaseIndex); + const auto lines = ReadLines(outputFile.parent_path() / fmt::format("StatsGenODF_Colon_Phase_{}.txt", phaseIndex + 1)); + REQUIRE(lines.size() == 8); + CHECK(lines[3] == "# Angle Data is Colon delimited."); + CHECK(lines[4] == "# Euler angles are expressed in degrees"); + CHECK(lines[6] == "Angle Count:1"); + CHECK(lines[7] == expectedRows[phaseIndex]); + } + + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} + TEST_CASE("OrientationAnalysis::WriteStatsGenOdfAngleFileFilter: InValid Filter Execution", "[OrientationAnalysis][WriteStatsGenOdfAngleFileFilter]") { UnitTest::LoadPlugins(); From 3f41bc70636aee92f8db5dfe417aa208b9067b95 Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Tue, 3 Nov 2026 19:11:09 -0500 Subject: [PATCH 17/33] BUG: ReadImage - Reject a TIFF page with a different pixel layout before copying it In a multi-page TIFF, the reader detected that a later page had a different number of components than page 0 (for example an RGB page 0 and a grayscale page 1), but it still copied the page with the pixel size of page 0. The copy read past the end of the narrower page buffer and wrote wrong values into that Z slice, and the -2007 error came only after the copy. DREAM.3D 6.5.171 (errata KI-053) had the same problem in its ITK reader. The reader now returns -2007 as soon as it reads such a page, before any crop, conversion or write to the data store. The late -2007 check now reports only dimension mismatches. Add a test that writes a real two-page TIFF (RGB 255, then grayscale 127) with libtiff and checks, with and without conversion to uint16, that page 0 is read, error -2007 is returned and slice 1 is untouched. Fixes #1908 item L57 Signed-off-by: Mike Jackson --- .../NXImageProcessing/docs/ReadImageFilter.md | 2 + .../Filters/Algorithms/ReadImage.cpp | 10 ++- .../NXImageProcessing/test/ReadImageTest.cpp | 75 +++++++++++++++++++ 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/src/Plugins/NXImageProcessing/docs/ReadImageFilter.md b/src/Plugins/NXImageProcessing/docs/ReadImageFilter.md index 7291b5517e..cd95375624 100644 --- a/src/Plugins/NXImageProcessing/docs/ReadImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/ReadImageFilter.md @@ -16,6 +16,8 @@ The following image types are supported: - TIFF / TIF, including multi-page TIFF read as a 3D Z-stack (via libtiff) - NRRD (`.nrrd` attached, `.nhdr` detached) (ITK-free, zlib only) +If the first page of a multi-page TIFF is RGB and a later page is grayscale, the filter fails with error `-2007` when it reads that later page. It fails before it copies any pixels of that page. This intentionally differs from DREAM3D 6.5.171, which could crash on mixed-page TIFF files (KI-053). + ### NRRD Volumes For a [NRRD](https://teem.sourceforge.net/nrrd/format.html) input (attached single-file `.nrrd`, or detached `.nhdr` + external data file), the geometry is built directly from the NRRD header. Supported header features: diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/Algorithms/ReadImage.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/Algorithms/ReadImage.cpp index 03fa4e8e90..2ae05cc571 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/Algorithms/ReadImage.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/Algorithms/ReadImage.cpp @@ -336,7 +336,6 @@ Result<> ReadRasterBackend(DataStructure& dataStructure, const ReadImageInputVal // extent of its own decoded segments and reject any mismatch rather than mis-sizing the slice. usize observedRows = 0; usize observedColumns = 0; - bool pixelStrideMismatch = false; readResult = imageIO->readPixelDataRows( inputFilePath, @@ -362,7 +361,10 @@ Result<> ReadRasterBackend(DataStructure& dataStructure, const ReadImageInputVal observedColumns = std::max(observedColumns, sourceColumn + pixelCount); if(pixels.size() != pixelCount * bytesPerPixel) { - pixelStrideMismatch = true; + // Reject an incompatible segment before forming a span with page 0's pixel stride. + return MakeErrorResult(-2007, fmt::format("Page {} of '{}' has a differing pixel byte count from page 0. Every page of a multi-page volume must share identical dimensions, " + "component count, and scalar type.", + sourcePage, inputFilePath.string())); } // Y crop: skip rows outside the destination window. @@ -408,9 +410,9 @@ Result<> ReadRasterBackend(DataStructure& dataStructure, const ReadImageInputVal return readResult; } - if(observedRows != stream.srcHeight || observedColumns != stream.srcWidth || pixelStrideMismatch) + if(observedRows != stream.srcHeight || observedColumns != stream.srcWidth) { - return MakeErrorResult(-2007, fmt::format("Page {} of '{}' has dimensions {}x{} (or a differing component count / scalar type) that do not match page 0 ({}x{}). Every page of a " + return MakeErrorResult(-2007, fmt::format("Page {} of '{}' has dimensions {}x{} that do not match page 0 ({}x{}). Every page of a " "multi-page volume must share identical dimensions, component count, and scalar type.", sourcePage, inputFilePath.string(), observedColumns, observedRows, stream.srcWidth, stream.srcHeight)); } diff --git a/src/Plugins/NXImageProcessing/test/ReadImageTest.cpp b/src/Plugins/NXImageProcessing/test/ReadImageTest.cpp index 5563e3a539..46b9d15f99 100644 --- a/src/Plugins/NXImageProcessing/test/ReadImageTest.cpp +++ b/src/Plugins/NXImageProcessing/test/ReadImageTest.cpp @@ -736,6 +736,81 @@ TEST_CASE("NXImageProcessing::ReadImageFilter: MultiPage_TIFF_ZStack", "[NXImage } } +TEST_CASE("NXImageProcessing::ReadImageFilter: MultiPage_TIFF_RGB_Then_Grayscale_Rejected_Before_Copy", "[NXImageProcessing][ReadImageFilter]") +{ + UnitTest::LoadPlugins(); + const bool convertData = GENERATE(false, true); + CAPTURE(convertData); + const fs::path tiffPath = ReadImageOutputDir() / "rgb_then_grayscale.tif"; + constexpr uint32_t width = 3; + constexpr uint32_t height = 2; + { + std::unique_ptr tiff(TIFFOpen(tiffPath.string().c_str(), "w"), TIFFClose); + REQUIRE(tiff != nullptr); + for(const uint16_t components : {uint16_t{3}, uint16_t{1}}) + { + REQUIRE(TIFFSetField(tiff.get(), TIFFTAG_IMAGEWIDTH, width) == 1); + REQUIRE(TIFFSetField(tiff.get(), TIFFTAG_IMAGELENGTH, height) == 1); + REQUIRE(TIFFSetField(tiff.get(), TIFFTAG_BITSPERSAMPLE, 8) == 1); + REQUIRE(TIFFSetField(tiff.get(), TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT) == 1); + REQUIRE(TIFFSetField(tiff.get(), TIFFTAG_SAMPLESPERPIXEL, components) == 1); + REQUIRE(TIFFSetField(tiff.get(), TIFFTAG_PHOTOMETRIC, components == 3 ? PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK) == 1); + REQUIRE(TIFFSetField(tiff.get(), TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT) == 1); + REQUIRE(TIFFSetField(tiff.get(), TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG) == 1); + REQUIRE(TIFFSetField(tiff.get(), TIFFTAG_COMPRESSION, COMPRESSION_NONE) == 1); + REQUIRE(TIFFSetField(tiff.get(), TIFFTAG_ROWSPERSTRIP, height) == 1); + std::vector row(width * components, components == 3 ? uint8_t{255} : uint8_t{127}); + for(uint32_t y = 0; y < height; ++y) + { + REQUIRE(TIFFWriteScanline(tiff.get(), row.data(), y, 0) == 1); + } + REQUIRE(TIFFWriteDirectory(tiff.get()) == 1); + } + } + + const DataPath geomPath({"Mixed Pages"}); + const DataPath arrayPath = geomPath.createChildPath("Cell Data").createChildPath("Pixels"); + Arguments args; + args.insertOrAssign(ReadImageFilter::k_FileName_Key, tiffPath); + args.insertOrAssign(ReadImageFilter::k_ImageGeometryPath_Key, geomPath); + args.insertOrAssign(ReadImageFilter::k_CellDataName_Key, std::string("Cell Data")); + args.insertOrAssign(ReadImageFilter::k_ImageDataArrayPath_Key, std::string("Pixels")); + args.insertOrAssign(ReadImageFilter::k_ChangeOrigin_Key, false); + args.insertOrAssign(ReadImageFilter::k_ChangeSpacing_Key, false); + args.insertOrAssign(ReadImageFilter::k_ChangeDataType_Key, convertData); + args.insertOrAssign(ReadImageFilter::k_ImageDataType_Key, ChoicesParameter::ValueType{1}); + ReadImageFilter filter; + DataStructure dataStructure; + auto preflight = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflight.outputActions); + IFilter::ExecuteResult execute; + REQUIRE_NOTHROW(execute = filter.execute(dataStructure, args)); + SIMPLNX_RESULT_REQUIRE_INVALID(execute.result); + REQUIRE(execute.result.errors()[0].code == -2007); // The page-layout check must reject page 1, not another error path. + REQUIRE(dataStructure.getDataRefAs(geomPath).getDimensions() == SizeVec3{width, height, 2}); + + // Oracle: page 0 has 3*2*3 = 18 white components (255, or 65535 after conversion). + // Page 1 supplies only 3 bytes per row, but the RGB destination needs 3*3 = 9. + // Reject that segment before copying any bytes; its 18 destination components must + // retain their initial zero values. This detects a late error even without a sanitizer. + const auto checkPixels = [](const auto& pixels, auto white) { + REQUIRE(pixels.getSize() == 36); + for(usize i = 0; i < 18; ++i) + { + REQUIRE(pixels[i] == white); + REQUIRE(pixels[18 + i] == 0); + } + }; + if(convertData) + { + checkPixels(dataStructure.getDataRefAs(arrayPath), uint16_t{65535}); + } + else + { + checkPixels(dataStructure.getDataRefAs(arrayPath), uint8_t{255}); + } +} + TEST_CASE("NXImageProcessing::ReadImageFilter: Nrrd_Scalar3D", "[NXImageProcessing][ReadImageFilter]") { UnitTest::LoadPlugins(); From f400b34b6b4306773f0c3e963aed1f5cb7f203f9 Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Wed, 4 Nov 2026 12:19:17 -0500 Subject: [PATCH 18/33] BUG: ProjectionImageFilters - Add Copy Non-Cell Attribute Matrices and name dropped objects With Perform In-Place on, the shared projection helper replaces the whole input geometry. Every other Attribute Matrix on it (for example Cell Feature Data and Cell Ensemble Data) was deleted, and warning -8343 named only the dropped Cell Data arrays. DREAM.3D 6.5.171 deleted the other arrays too (errata KI-009). All seven projection filters (Maximum, Minimum, Mean, Median, Sum, Standard Deviation and Binary) get a new parameter, Copy Non-Cell Attribute Matrices (copy_non_cell_attribute_matrices), default false, parameter version 2: - false: unchanged behavior. In-place warning -8343 now lists every discarded Cell Data array and every other discarded geometry child. - true, in-place: the non-cell Attribute Matrices are moved to the projected geometry. No arrays are copied. - true, new geometry: the non-cell Attribute Matrices are deep-copied into the created geometry. String arrays in them currently share their values with the input (StringArray::deepCopy shares its store; separate issue). Older pipelines without the key load with false. Add tests for Maximum and Standard Deviation that cover both modes, the omitted, false and true option values, and an extra Cell Data array, with hand-written fixture values, and tests that version-1 JSON loads with false. Fixes #1908 item L58 Fixes #1908 item L63 Signed-off-by: Mike Jackson --- .../docs/BinaryProjectionImageFilter.md | 8 +- .../docs/MaximumProjectionImageFilter.md | 8 +- .../docs/MeanProjectionImageFilter.md | 8 +- .../docs/MedianProjectionImageFilter.md | 8 +- .../docs/MinimumProjectionImageFilter.md | 8 +- .../StandardDeviationProjectionImageFilter.md | 8 +- .../docs/SumProjectionImageFilter.md | 8 +- ...ection-Based_Quality_Summaries.d3dpipeline | 42 ++++- .../Filters/BinaryProjectionImageFilter.cpp | 7 +- .../Filters/BinaryProjectionImageFilter.hpp | 1 + .../Filters/MaximumProjectionImageFilter.cpp | 9 +- .../Filters/MaximumProjectionImageFilter.hpp | 1 + .../Filters/MeanProjectionImageFilter.cpp | 7 +- .../Filters/MeanProjectionImageFilter.hpp | 1 + .../Filters/MedianProjectionImageFilter.cpp | 9 +- .../Filters/MedianProjectionImageFilter.hpp | 1 + .../Filters/MinimumProjectionImageFilter.cpp | 9 +- .../Filters/MinimumProjectionImageFilter.hpp | 1 + ...StandardDeviationProjectionImageFilter.cpp | 7 +- ...StandardDeviationProjectionImageFilter.hpp | 1 + .../Filters/SumProjectionImageFilter.cpp | 7 +- .../Filters/SumProjectionImageFilter.hpp | 1 + .../test/MaximumProjectionImageFilterTest.cpp | 148 ++++++++++++++++++ ...dardDeviationProjectionImageFilterTest.cpp | 148 ++++++++++++++++++ .../ImageProcessingFilterUtilities.hpp | 68 ++++++-- .../14_Projection-Based_Quality_Summaries.py | 7 + 26 files changed, 491 insertions(+), 40 deletions(-) diff --git a/src/Plugins/NXImageProcessing/docs/BinaryProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/BinaryProjectionImageFilter.md index 0eafc129e4..74f8524516 100644 --- a/src/Plugins/NXImageProcessing/docs/BinaryProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/BinaryProjectionImageFilter.md @@ -14,7 +14,13 @@ The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. The **Foreground Value** and **Background Value** are supplied as floating-point numbers and cast to the input element type; the foreground equality test is performed in the input element type. This matches the legacy ITK Binary Projection accumulator, which initializes each column to background and switches it to foreground the first time a voxel equal to the foreground value is encountered. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection); the filter emits a preflight warning listing them. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. + +**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. + +Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. + +Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. The input array must be single-component (scalar) and one of the scalar numeric types (`int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`, `float32`, or `float64`). This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Binary Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/MaximumProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/MaximumProjectionImageFilter.md index 1d951fd8d8..24817744f4 100644 --- a/src/Plugins/NXImageProcessing/docs/MaximumProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/MaximumProjectionImageFilter.md @@ -12,7 +12,13 @@ Collapses the selected **Projection Dimension** of a scalar Image Geometry to a The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection); the filter emits a preflight warning listing them. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. + +**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. + +Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. + +Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. The input array must be single-component (scalar) and one of the supported types: `uint8`, `int16`, `uint16`, or `float32`. This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Maximum Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/MeanProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/MeanProjectionImageFilter.md index 12c05dcdf2..514c7f9a55 100644 --- a/src/Plugins/NXImageProcessing/docs/MeanProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/MeanProjectionImageFilter.md @@ -14,7 +14,13 @@ The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. The output element type is always **Float64** (double), regardless of the input element type, matching the legacy ITK Mean Projection Image Filter (the mean of an integer column is generally not an integer). The mean is accumulated with a Kahan-compensated running sum so that long columns do not lose precision. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection); the filter emits a preflight warning listing them. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. + +**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. + +Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. + +Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. The input array must be single-component (scalar) and one of the scalar numeric types (`int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`, `float32`, or `float64`). This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Mean Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/MedianProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/MedianProjectionImageFilter.md index 419e89bdff..588b868a4c 100644 --- a/src/Plugins/NXImageProcessing/docs/MedianProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/MedianProjectionImageFilter.md @@ -12,7 +12,13 @@ Collapses the selected **Projection Dimension** of a scalar Image Geometry to a The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection); the filter emits a preflight warning listing them. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. + +**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. + +Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. + +Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. The input array must be single-component (scalar) and one of the supported types: `uint8`, `int16`, `uint16`, or `float32`. This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Median Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/MinimumProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/MinimumProjectionImageFilter.md index e6af8d6e1e..cb63212f06 100644 --- a/src/Plugins/NXImageProcessing/docs/MinimumProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/MinimumProjectionImageFilter.md @@ -12,7 +12,13 @@ Collapses the selected **Projection Dimension** of a scalar Image Geometry to a The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection); the filter emits a preflight warning listing them. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. + +**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. + +Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. + +Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. The input array must be single-component (scalar) and one of the supported types: `uint8`, `int16`, `uint16`, or `float32`. This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Minimum Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/StandardDeviationProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/StandardDeviationProjectionImageFilter.md index a0be927d65..ee84e63348 100644 --- a/src/Plugins/NXImageProcessing/docs/StandardDeviationProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/StandardDeviationProjectionImageFilter.md @@ -14,7 +14,13 @@ The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. The standard deviation is the *sample* standard deviation: the column mean is formed with the population divisor *N*, but the sum of squared deviations is divided by *N − 1* before taking the square root, matching the legacy ITK Standard Deviation Projection Image Filter. A column of length 1 (or a degenerate projected axis) yields 0. The output element type is always **Float64** (double), regardless of the input element type. The statistic uses Welford's online update to avoid cancellation when large values have small differences. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection); the filter emits a preflight warning listing them. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. + +**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. + +Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. + +Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. The input array must be single-component (scalar) and one of the scalar numeric types (`int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`, `float32`, or `float64`). This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Standard Deviation Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/SumProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/SumProjectionImageFilter.md index 0e000400ab..bb905a60d6 100644 --- a/src/Plugins/NXImageProcessing/docs/SumProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/SumProjectionImageFilter.md @@ -14,7 +14,13 @@ The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. The output element type is always **Float64** (double), regardless of the input element type, matching the legacy ITK Sum Projection Image Filter (the sum of an integer column readily overflows a narrow integer type). The sum is accumulated with a Kahan-compensated running sum so that long columns do not lose precision. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection); the filter emits a preflight warning listing them. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. + +**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. + +Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. + +Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. The input array must be single-component (scalar) and one of the scalar numeric types (`int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`, `float32`, or `float64`). This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Sum Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/pipelines/14_Projection-Based_Quality_Summaries/14_Projection-Based_Quality_Summaries.d3dpipeline b/src/Plugins/NXImageProcessing/pipelines/14_Projection-Based_Quality_Summaries/14_Projection-Based_Quality_Summaries.d3dpipeline index 0e38d321b3..a15cd9a6b2 100644 --- a/src/Plugins/NXImageProcessing/pipelines/14_Projection-Based_Quality_Summaries/14_Projection-Based_Quality_Summaries.d3dpipeline +++ b/src/Plugins/NXImageProcessing/pipelines/14_Projection-Based_Quality_Summaries/14_Projection-Based_Quality_Summaries.d3dpipeline @@ -128,6 +128,10 @@ "value": 0.0, "version": 1 }, + "copy_non_cell_attribute_matrices": { + "value": false, + "version": 1 + }, "foreground_value": { "value": 1.0, "version": 1 @@ -148,7 +152,7 @@ "value": "Binary Pore Projection", "version": 1 }, - "parameters_version": 1, + "parameters_version": 2, "projection_dimension": { "value": 2, "version": 1 @@ -167,6 +171,10 @@ }, { "args": { + "copy_non_cell_attribute_matrices": { + "value": false, + "version": 1 + }, "input_image_data_path": { "value": "Projection Volume/Cell Data/XCT Intensity", "version": 1 @@ -183,7 +191,7 @@ "value": "Maximum XCT Projection", "version": 1 }, - "parameters_version": 1, + "parameters_version": 2, "projection_dimension": { "value": 2, "version": 1 @@ -202,6 +210,10 @@ }, { "args": { + "copy_non_cell_attribute_matrices": { + "value": false, + "version": 1 + }, "input_image_data_path": { "value": "Projection Volume/Cell Data/XCT Intensity", "version": 1 @@ -218,7 +230,7 @@ "value": "Mean XCT Projection", "version": 1 }, - "parameters_version": 1, + "parameters_version": 2, "projection_dimension": { "value": 2, "version": 1 @@ -237,6 +249,10 @@ }, { "args": { + "copy_non_cell_attribute_matrices": { + "value": false, + "version": 1 + }, "input_image_data_path": { "value": "Projection Volume/Cell Data/XCT Intensity", "version": 1 @@ -253,7 +269,7 @@ "value": "Median XCT Projection", "version": 1 }, - "parameters_version": 1, + "parameters_version": 2, "projection_dimension": { "value": 2, "version": 1 @@ -272,6 +288,10 @@ }, { "args": { + "copy_non_cell_attribute_matrices": { + "value": false, + "version": 1 + }, "input_image_data_path": { "value": "Projection Volume/Cell Data/XCT Intensity", "version": 1 @@ -288,7 +308,7 @@ "value": "Minimum XCT Projection", "version": 1 }, - "parameters_version": 1, + "parameters_version": 2, "projection_dimension": { "value": 2, "version": 1 @@ -307,6 +327,10 @@ }, { "args": { + "copy_non_cell_attribute_matrices": { + "value": false, + "version": 1 + }, "input_image_data_path": { "value": "Projection Volume/Cell Data/XCT Intensity", "version": 1 @@ -323,7 +347,7 @@ "value": "Deviation XCT Projection", "version": 1 }, - "parameters_version": 1, + "parameters_version": 2, "projection_dimension": { "value": 2, "version": 1 @@ -342,6 +366,10 @@ }, { "args": { + "copy_non_cell_attribute_matrices": { + "value": false, + "version": 1 + }, "input_image_data_path": { "value": "Projection Volume/Cell Data/XCT Intensity", "version": 1 @@ -358,7 +386,7 @@ "value": "Sum XCT Projection", "version": 1 }, - "parameters_version": 1, + "parameters_version": 2, "projection_dimension": { "value": 2, "version": 1 diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.cpp index 68fd5a17d9..e23c30fd0e 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.cpp @@ -115,6 +115,8 @@ Parameters BinaryProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); + params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", + "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insert(std::make_unique( k_ForegroundValue_Key, "Foreground Value", "The value a projected column is set to when ANY voxel along the projection axis equals this value. For an integer input image the value must be finite and within the image type's range.", @@ -143,7 +145,7 @@ Parameters BinaryProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType BinaryProjectionImageFilter::parametersVersion() const { - return 1; + return 2; } //------------------------------------------------------------------------------ @@ -161,6 +163,7 @@ IFilter::PreflightResult BinaryProjectionImageFilter::preflightImpl(const DataSt auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); + auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); auto foregroundValue = filterArgs.value(k_ForegroundValue_Key); auto backgroundValue = filterArgs.value(k_BackgroundValue_Key); @@ -170,7 +173,7 @@ IFilter::PreflightResult BinaryProjectionImageFilter::preflightImpl(const DataSt // default SameAsInput OutTypeMap keeps the allocated and written output types in lock-step). The scalar // (single-component) and tuple-consistency checks are performed inside PreflightAxisProjection. Result resultOutputActions = ImageProcessing::PreflightAxisProjection( - dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); + dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName, copyNonCellAttributeMatrices); if(resultOutputActions.invalid()) { return {std::move(resultOutputActions)}; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.hpp index eb73031cdc..7fdcf2f006 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.hpp @@ -28,6 +28,7 @@ class NXIMAGEPROCESSING_EXPORT BinaryProjectionImageFilter : public IFilter // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; + static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.cpp index e29f766f71..e7d272e4a5 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.cpp @@ -55,6 +55,8 @@ Parameters MaximumProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); + params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", + "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insertSeparator(Parameters::Separator{"Input Cell Data"}); params.insert(std::make_unique(k_InputImageGeomPath_Key, "Image Geometry", "Select the Image Geometry Group from the DataStructure.", DataPath({"Image Geometry"}), @@ -75,7 +77,7 @@ Parameters MaximumProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType MaximumProjectionImageFilter::parametersVersion() const { - return 1; + return 2; } //------------------------------------------------------------------------------ @@ -93,12 +95,13 @@ IFilter::PreflightResult MaximumProjectionImageFilter::preflightImpl(const DataS auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); + auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); // Maximum projection preserves the element type, so both preflight and execute use the default // SameAsInput OutTypeMap (kept in lock-step so the allocated and written output types agree). - Result resultOutputActions = - ImageProcessing::PreflightAxisProjection(dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); + Result resultOutputActions = ImageProcessing::PreflightAxisProjection(dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, + outputGeomName, outputArrayName, copyNonCellAttributeMatrices); return {std::move(resultOutputActions)}; } diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.hpp index f61e8b3163..f15ca29bb5 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.hpp @@ -27,6 +27,7 @@ class NXIMAGEPROCESSING_EXPORT MaximumProjectionImageFilter : public IFilter // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; + static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.cpp index 6df9606e2e..18573ad2aa 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.cpp @@ -53,6 +53,8 @@ Parameters MeanProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); + params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", + "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insertSeparator(Parameters::Separator{"Input Cell Data"}); params.insert(std::make_unique(k_InputImageGeomPath_Key, "Image Geometry", "Select the Image Geometry Group from the DataStructure.", DataPath({"Image Geometry"}), @@ -73,7 +75,7 @@ Parameters MeanProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType MeanProjectionImageFilter::parametersVersion() const { - return 1; + return 2; } //------------------------------------------------------------------------------ @@ -91,6 +93,7 @@ IFilter::PreflightResult MeanProjectionImageFilter::preflightImpl(const DataStru auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); + auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); // The mean of an integer column is generally not an integer, so the legacy ITK filter emits a double @@ -99,7 +102,7 @@ IFilter::PreflightResult MeanProjectionImageFilter::preflightImpl(const DataStru // execute façade below MUST use the same pair, or the allocated and written output types disagree. The // scalar (single-component) and tuple-consistency checks are performed inside PreflightAxisProjection. Result resultOutputActions = ImageProcessing::PreflightAxisProjection( - dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); + dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName, copyNonCellAttributeMatrices); return {std::move(resultOutputActions)}; } diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.hpp index 0566fb1324..a6a5cd830d 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.hpp @@ -28,6 +28,7 @@ class NXIMAGEPROCESSING_EXPORT MeanProjectionImageFilter : public IFilter // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; + static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.cpp index 48b442e3e2..540d950594 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.cpp @@ -55,6 +55,8 @@ Parameters MedianProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); + params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", + "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insertSeparator(Parameters::Separator{"Input Cell Data"}); params.insert(std::make_unique(k_InputImageGeomPath_Key, "Image Geometry", "Select the Image Geometry Group from the DataStructure.", DataPath({"Image Geometry"}), @@ -75,7 +77,7 @@ Parameters MedianProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType MedianProjectionImageFilter::parametersVersion() const { - return 1; + return 2; } //------------------------------------------------------------------------------ @@ -93,12 +95,13 @@ IFilter::PreflightResult MedianProjectionImageFilter::preflightImpl(const DataSt auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); + auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); // Median projection preserves the element type, so both preflight and execute use the default // SameAsInput OutTypeMap (kept in lock-step so the allocated and written output types agree). - Result resultOutputActions = - ImageProcessing::PreflightAxisProjection(dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); + Result resultOutputActions = ImageProcessing::PreflightAxisProjection(dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, + outputGeomName, outputArrayName, copyNonCellAttributeMatrices); return {std::move(resultOutputActions)}; } diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.hpp index f38a115a76..dbe36d0195 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.hpp @@ -27,6 +27,7 @@ class NXIMAGEPROCESSING_EXPORT MedianProjectionImageFilter : public IFilter // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; + static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.cpp index ff28b7f9a1..d88699686f 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.cpp @@ -55,6 +55,8 @@ Parameters MinimumProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); + params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", + "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insertSeparator(Parameters::Separator{"Input Cell Data"}); params.insert(std::make_unique(k_InputImageGeomPath_Key, "Image Geometry", "Select the Image Geometry Group from the DataStructure.", DataPath({"Image Geometry"}), @@ -75,7 +77,7 @@ Parameters MinimumProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType MinimumProjectionImageFilter::parametersVersion() const { - return 1; + return 2; } //------------------------------------------------------------------------------ @@ -93,12 +95,13 @@ IFilter::PreflightResult MinimumProjectionImageFilter::preflightImpl(const DataS auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); + auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); // Minimum projection preserves the element type, so both preflight and execute use the default // SameAsInput OutTypeMap (kept in lock-step so the allocated and written output types agree). - Result resultOutputActions = - ImageProcessing::PreflightAxisProjection(dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); + Result resultOutputActions = ImageProcessing::PreflightAxisProjection(dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, + outputGeomName, outputArrayName, copyNonCellAttributeMatrices); return {std::move(resultOutputActions)}; } diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.hpp index 8826fd0efb..68c77c893e 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.hpp @@ -27,6 +27,7 @@ class NXIMAGEPROCESSING_EXPORT MinimumProjectionImageFilter : public IFilter // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; + static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.cpp index b4dd04668a..c580f8e006 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.cpp @@ -53,6 +53,8 @@ Parameters StandardDeviationProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); + params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", + "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insertSeparator(Parameters::Separator{"Input Cell Data"}); params.insert(std::make_unique(k_InputImageGeomPath_Key, "Image Geometry", "Select the Image Geometry Group from the DataStructure.", DataPath({"Image Geometry"}), @@ -73,7 +75,7 @@ Parameters StandardDeviationProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType StandardDeviationProjectionImageFilter::parametersVersion() const { - return 1; + return 2; } //------------------------------------------------------------------------------ @@ -91,6 +93,7 @@ IFilter::PreflightResult StandardDeviationProjectionImageFilter::preflightImpl(c auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); + auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); // The standard deviation is a real-valued statistic, so the legacy ITK filter emits a double (Float64) @@ -99,7 +102,7 @@ IFilter::PreflightResult StandardDeviationProjectionImageFilter::preflightImpl(c // MUST use the same pair, or the allocated and written output types disagree. The scalar // (single-component) and tuple-consistency checks are performed inside PreflightAxisProjection. Result resultOutputActions = ImageProcessing::PreflightAxisProjection( - dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); + dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName, copyNonCellAttributeMatrices); return {std::move(resultOutputActions)}; } diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.hpp index bf6d548f63..e2d46d4129 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.hpp @@ -28,6 +28,7 @@ class NXIMAGEPROCESSING_EXPORT StandardDeviationProjectionImageFilter : public I // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; + static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.cpp index 7570a574dd..2477f2ad85 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.cpp @@ -53,6 +53,8 @@ Parameters SumProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); + params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", + "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insertSeparator(Parameters::Separator{"Input Cell Data"}); params.insert(std::make_unique(k_InputImageGeomPath_Key, "Image Geometry", "Select the Image Geometry Group from the DataStructure.", DataPath({"Image Geometry"}), @@ -73,7 +75,7 @@ Parameters SumProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType SumProjectionImageFilter::parametersVersion() const { - return 1; + return 2; } //------------------------------------------------------------------------------ @@ -91,6 +93,7 @@ IFilter::PreflightResult SumProjectionImageFilter::preflightImpl(const DataStruc auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); + auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); // The sum of an integer column overflows narrow integer types, so the legacy ITK filter emits a double @@ -99,7 +102,7 @@ IFilter::PreflightResult SumProjectionImageFilter::preflightImpl(const DataStruc // execute façade below MUST use the same pair, or the allocated and written output types disagree. The // scalar (single-component) and tuple-consistency checks are performed inside PreflightAxisProjection. Result resultOutputActions = ImageProcessing::PreflightAxisProjection( - dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); + dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName, copyNonCellAttributeMatrices); return {std::move(resultOutputActions)}; } diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.hpp index b6da6b215d..18328bc15d 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.hpp @@ -28,6 +28,7 @@ class NXIMAGEPROCESSING_EXPORT SumProjectionImageFilter : public IFilter // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; + static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp b/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp index f230c12200..9a7fe01ecc 100644 --- a/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp +++ b/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp @@ -124,3 +124,151 @@ TEST_CASE("NXImageProcessing::MaximumProjectionImageFilter: ITK real-image golde { projection_test::RunProjectionMd5ItkGolden("Ramp-Up-Short.nrrd", /*projDim=*/1, /*removeOriginalGeometry=*/true, "5390344262c91e83bc9208b0991a2fc9"); } + +TEST_CASE("ImageProcessing::MaximumProjectionImageFilter: Copy non-cell Attribute Matrices", "[ImageProcessing][MaximumProjectionImageFilter]") +{ + UnitTest::LoadPlugins(); + const UnitTest::PreferencesSentinel prefsSentinel(DataStorageMode::ForceInCore, 0); + const bool inPlace = GENERATE(true, false); + const bool extraCellArray = GENERATE(false, true); + // Omitted exercises callers written before this option existed. + const int copyOption = GENERATE(-1, 0, 1); + const bool copyNonCell = copyOption == 1; + CAPTURE(inPlace, extraCellArray, copyOption); + + DataStructure ds; + const DataPath inputPath = ip_test::BuildRampImage(ds, 3, 0.0, 1.0); + const DataPath geomPath({"Image Geometry"}); + auto& imageGeom = ds.getDataRefAs(geomPath); + const DataPath featurePath = geomPath.createChildPath("Cell Feature Data"); + auto* featureAM = AttributeMatrix::Create(ds, "Cell Feature Data", {2}, imageGeom.getId()); + REQUIRE(featureAM != nullptr); + const DataPath featureArrayPath = featurePath.createChildPath("Feature Values"); + auto featureStore = DataStoreUtilities::CreateDataStore(ds, featureArrayPath, {2}, {1}); + REQUIRE(Int32Array::Create(ds, "Feature Values", featureStore, featureAM->getId()) != nullptr); + featureStore->setValue(0, 17); + featureStore->setValue(1, 29); + const DataPath ensemblePath = geomPath.createChildPath("Cell Ensemble Data"); + REQUIRE(AttributeMatrix::Create(ds, "Cell Ensemble Data", {1}, imageGeom.getId()) != nullptr); + const auto featureId = featureAM->getId(); + const auto featureArrayId = ds.getDataRefAs(featureArrayPath).getId(); + const auto ensembleId = ds.getDataRefAs(ensemblePath).getId(); + if(extraCellArray) + { + const DataPath cellPath = inputPath.getParent(); + auto& cellAM = ds.getDataRefAs(cellPath); + auto extraStore = DataStoreUtilities::CreateDataStore(ds, cellPath.createChildPath("Extra"), cellAM.getShape(), {1}); + REQUIRE(Int16Array::Create(ds, "Extra", extraStore, cellAM.getId()) != nullptr); + } + + MaximumProjectionImageFilter filter; + Arguments args; + args.insertOrAssign(MaximumProjectionImageFilter::k_InputImageGeomPath_Key, std::make_any(geomPath)); + args.insertOrAssign(MaximumProjectionImageFilter::k_InputImageDataPath_Key, std::make_any(inputPath)); + args.insertOrAssign(MaximumProjectionImageFilter::k_ProjectionDimension_Key, std::make_any(0)); + args.insertOrAssign(MaximumProjectionImageFilter::k_RemoveOriginalGeometry_Key, std::make_any(inPlace)); + args.insertOrAssign(MaximumProjectionImageFilter::k_OutputImageGeomName_Key, std::make_any("Projected Image")); + args.insertOrAssign(MaximumProjectionImageFilter::k_OutputImageArrayName_Key, std::make_any("Output")); + if(copyOption >= 0) + { + args.insertOrAssign("copy_non_cell_attribute_matrices", std::make_any(copyNonCell)); + } + const auto preflightResult = filter.preflight(ds, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + std::string discardedWarning; + for(const auto& warning : preflightResult.outputActions.warnings()) + { + if(warning.code == -8343) + { + discardedWarning += warning.message; + } + } + // Only discarded objects belong in the warning. Preserved matrices must not be listed. + if(inPlace) + { + CHECK((discardedWarning.find("Cell Feature Data") != std::string::npos) == !copyNonCell); + CHECK((discardedWarning.find("Cell Ensemble Data") != std::string::npos) == !copyNonCell); + CHECK(discardedWarning.empty() == (copyNonCell && !extraCellArray)); + if(extraCellArray) + { + CHECK(discardedWarning.find("Extra") != std::string::npos); + } + } + else + { + CHECK(discardedWarning.empty()); + } + + // Axis projection dispatches by store type; it has no Direct/Scanline AlgorithmTestScope override. + const auto executeResult = filter.execute(ds, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); + const DataPath outputGeomPath = inPlace ? geomPath : DataPath({"Projected Image"}); + REQUIRE(ds.getDataRefAs(outputGeomPath).getDimensions() == SizeVec3{1, 3, 3}); + const auto& output = ds.getDataRefAs(outputGeomPath.createChildPath("CellData").createChildPath("Output")); + REQUIRE(output.getNumberOfTuples() == 9); + for(usize slot = 0; slot < 9; ++slot) + { + // Along X, the 3x3x3 ramp has columns {3*s, 3*s+1, 3*s+2}, so max = 3*s+2. + REQUIRE(output[slot] == static_cast(3 * slot + 2)); + } + if(copyNonCell) + { + const DataPath outputFeaturePath = outputGeomPath.createChildPath("Cell Feature Data"); + const auto* outputFeatureAM = ds.getDataAs(outputFeaturePath); + REQUIRE(outputFeatureAM != nullptr); + CHECK(outputFeatureAM->getShape() == ShapeType{2}); + auto& features = ds.getDataRefAs(outputFeaturePath.createChildPath("Feature Values")); + CHECK(features[0] == 17); + CHECK(features[1] == 29); + const auto* ensemble = ds.getDataAs(outputGeomPath.createChildPath("Cell Ensemble Data")); + REQUIRE(ensemble != nullptr); + CHECK(ensemble->getShape() == ShapeType{1}); + CHECK(ensemble->getSize() == 0); + if(inPlace) + { + CHECK(outputFeatureAM->getId() == featureId); + CHECK(features.getId() == featureArrayId); + CHECK(features.getDataStore() == featureStore.get()); + CHECK(ensemble->getId() == ensembleId); + } + else + { + CHECK(outputFeatureAM->getId() != featureId); + CHECK(features.getId() != featureArrayId); + CHECK(features.getDataStore() != featureStore.get()); + CHECK(ensemble->getId() != ensembleId); + features[0] = 101; + CHECK(ds.getDataRefAs(featureArrayPath)[0] == 17); + featureStore->setValue(1, 103); + CHECK(features[1] == 29); + featureStore->setValue(1, 29); + } + } + else + { + CHECK(ds.getData(outputGeomPath.createChildPath("Cell Feature Data")) == nullptr); + CHECK(ds.getData(outputGeomPath.createChildPath("Cell Ensemble Data")) == nullptr); + } + if(!inPlace) + { + const auto& features = ds.getDataRefAs(featureArrayPath); + CHECK(features[0] == 17); + CHECK(features[1] == 29); + CHECK(ds.getDataRefAs(featurePath).getId() == featureId); + CHECK(ds.getDataRefAs(ensemblePath).getId() == ensembleId); + CHECK(ds.getDataRefAs(geomPath).getDimensions() == SizeVec3{3, 3, 3}); + } + UnitTest::CheckArraysInheritTupleDims(ds); +} + +TEST_CASE("ImageProcessing::MaximumProjectionImageFilter: Older pipelines default to discarding non-cell matrices", "[ImageProcessing][MaximumProjectionImageFilter]") +{ + MaximumProjectionImageFilter filter; + auto json = filter.toJson(filter.getDefaultArguments()); + json.erase("copy_non_cell_attribute_matrices"); + json["parameters_version"] = 1; + const auto converted = filter.fromJson(json); + SIMPLNX_RESULT_REQUIRE_VALID(converted); + REQUIRE(converted.value().contains("copy_non_cell_attribute_matrices")); + CHECK_FALSE(converted.value().value("copy_non_cell_attribute_matrices")); +} diff --git a/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp b/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp index 4a28a79810..ef669a5575 100644 --- a/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp +++ b/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp @@ -264,3 +264,151 @@ TEST_CASE("NXImageProcessing::StandardDeviationProjectionImageFilter: ITK real-i projection_test::RunProjectionBaselineItkGolden("RA-Float.nrrd", "BasicFilters_StandardDeviationProjectionImageFilter_z_projection.nrrd", /*projDim=*/2, /*tolerance=*/0.0001); } + +TEST_CASE("ImageProcessing::StandardDeviationProjectionImageFilter: Copy non-cell Attribute Matrices", "[ImageProcessing][StandardDeviationProjectionImageFilter]") +{ + UnitTest::LoadPlugins(); + const UnitTest::PreferencesSentinel prefsSentinel(DataStorageMode::ForceInCore, 0); + const bool inPlace = GENERATE(true, false); + const bool extraCellArray = GENERATE(false, true); + // Omitted exercises callers written before this option existed. + const int copyOption = GENERATE(-1, 0, 1); + const bool copyNonCell = copyOption == 1; + CAPTURE(inPlace, extraCellArray, copyOption); + + DataStructure ds; + const DataPath inputPath = ip_test::BuildRampImage(ds, 3, 0.0, 1.0); + const DataPath geomPath({"Image Geometry"}); + auto& imageGeom = ds.getDataRefAs(geomPath); + const DataPath featurePath = geomPath.createChildPath("Cell Feature Data"); + auto* featureAM = AttributeMatrix::Create(ds, "Cell Feature Data", {2}, imageGeom.getId()); + REQUIRE(featureAM != nullptr); + const DataPath featureArrayPath = featurePath.createChildPath("Feature Values"); + auto featureStore = DataStoreUtilities::CreateDataStore(ds, featureArrayPath, {2}, {1}); + REQUIRE(Int32Array::Create(ds, "Feature Values", featureStore, featureAM->getId()) != nullptr); + featureStore->setValue(0, 17); + featureStore->setValue(1, 29); + const DataPath ensemblePath = geomPath.createChildPath("Cell Ensemble Data"); + REQUIRE(AttributeMatrix::Create(ds, "Cell Ensemble Data", {1}, imageGeom.getId()) != nullptr); + const auto featureId = featureAM->getId(); + const auto featureArrayId = ds.getDataRefAs(featureArrayPath).getId(); + const auto ensembleId = ds.getDataRefAs(ensemblePath).getId(); + if(extraCellArray) + { + const DataPath cellPath = inputPath.getParent(); + auto& cellAM = ds.getDataRefAs(cellPath); + auto extraStore = DataStoreUtilities::CreateDataStore(ds, cellPath.createChildPath("Extra"), cellAM.getShape(), {1}); + REQUIRE(Int16Array::Create(ds, "Extra", extraStore, cellAM.getId()) != nullptr); + } + + StandardDeviationProjectionImageFilter filter; + Arguments args; + args.insertOrAssign(StandardDeviationProjectionImageFilter::k_InputImageGeomPath_Key, std::make_any(geomPath)); + args.insertOrAssign(StandardDeviationProjectionImageFilter::k_InputImageDataPath_Key, std::make_any(inputPath)); + args.insertOrAssign(StandardDeviationProjectionImageFilter::k_ProjectionDimension_Key, std::make_any(0)); + args.insertOrAssign(StandardDeviationProjectionImageFilter::k_RemoveOriginalGeometry_Key, std::make_any(inPlace)); + args.insertOrAssign(StandardDeviationProjectionImageFilter::k_OutputImageGeomName_Key, std::make_any("Projected Image")); + args.insertOrAssign(StandardDeviationProjectionImageFilter::k_OutputImageArrayName_Key, std::make_any("Output")); + if(copyOption >= 0) + { + args.insertOrAssign("copy_non_cell_attribute_matrices", std::make_any(copyNonCell)); + } + const auto preflightResult = filter.preflight(ds, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + std::string discardedWarning; + for(const auto& warning : preflightResult.outputActions.warnings()) + { + if(warning.code == -8343) + { + discardedWarning += warning.message; + } + } + // Only discarded objects belong in the warning. Preserved matrices must not be listed. + if(inPlace) + { + CHECK((discardedWarning.find("Cell Feature Data") != std::string::npos) == !copyNonCell); + CHECK((discardedWarning.find("Cell Ensemble Data") != std::string::npos) == !copyNonCell); + CHECK(discardedWarning.empty() == (copyNonCell && !extraCellArray)); + if(extraCellArray) + { + CHECK(discardedWarning.find("Extra") != std::string::npos); + } + } + else + { + CHECK(discardedWarning.empty()); + } + + // Axis projection dispatches by store type; it has no Direct/Scanline AlgorithmTestScope override. + const auto executeResult = filter.execute(ds, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); + const DataPath outputGeomPath = inPlace ? geomPath : DataPath({"Projected Image"}); + REQUIRE(ds.getDataRefAs(outputGeomPath).getDimensions() == SizeVec3{1, 3, 3}); + const auto& output = ds.getDataRefAs(outputGeomPath.createChildPath("CellData").createChildPath("Output")); + REQUIRE(output.getNumberOfTuples() == 9); + for(usize slot = 0; slot < 9; ++slot) + { + // Along X, each ramp column is {a, a+1, a+2}. Sample variance = (1+0+1)/(3-1) = 1. + REQUIRE(output[slot] == Approx(1.0).margin(1.0e-12)); + } + if(copyNonCell) + { + const DataPath outputFeaturePath = outputGeomPath.createChildPath("Cell Feature Data"); + const auto* outputFeatureAM = ds.getDataAs(outputFeaturePath); + REQUIRE(outputFeatureAM != nullptr); + CHECK(outputFeatureAM->getShape() == ShapeType{2}); + auto& features = ds.getDataRefAs(outputFeaturePath.createChildPath("Feature Values")); + CHECK(features[0] == 17); + CHECK(features[1] == 29); + const auto* ensemble = ds.getDataAs(outputGeomPath.createChildPath("Cell Ensemble Data")); + REQUIRE(ensemble != nullptr); + CHECK(ensemble->getShape() == ShapeType{1}); + CHECK(ensemble->getSize() == 0); + if(inPlace) + { + CHECK(outputFeatureAM->getId() == featureId); + CHECK(features.getId() == featureArrayId); + CHECK(features.getDataStore() == featureStore.get()); + CHECK(ensemble->getId() == ensembleId); + } + else + { + CHECK(outputFeatureAM->getId() != featureId); + CHECK(features.getId() != featureArrayId); + CHECK(features.getDataStore() != featureStore.get()); + CHECK(ensemble->getId() != ensembleId); + features[0] = 101; + CHECK(ds.getDataRefAs(featureArrayPath)[0] == 17); + featureStore->setValue(1, 103); + CHECK(features[1] == 29); + featureStore->setValue(1, 29); + } + } + else + { + CHECK(ds.getData(outputGeomPath.createChildPath("Cell Feature Data")) == nullptr); + CHECK(ds.getData(outputGeomPath.createChildPath("Cell Ensemble Data")) == nullptr); + } + if(!inPlace) + { + const auto& features = ds.getDataRefAs(featureArrayPath); + CHECK(features[0] == 17); + CHECK(features[1] == 29); + CHECK(ds.getDataRefAs(featurePath).getId() == featureId); + CHECK(ds.getDataRefAs(ensemblePath).getId() == ensembleId); + CHECK(ds.getDataRefAs(geomPath).getDimensions() == SizeVec3{3, 3, 3}); + } + UnitTest::CheckArraysInheritTupleDims(ds); +} + +TEST_CASE("ImageProcessing::StandardDeviationProjectionImageFilter: Older pipelines default to discarding non-cell matrices", "[ImageProcessing][StandardDeviationProjectionImageFilter]") +{ + StandardDeviationProjectionImageFilter filter; + auto json = filter.toJson(filter.getDefaultArguments()); + json.erase("copy_non_cell_attribute_matrices"); + json["parameters_version"] = 1; + const auto converted = filter.fromJson(json); + SIMPLNX_RESULT_REQUIRE_VALID(converted); + REQUIRE(converted.value().contains("copy_non_cell_attribute_matrices")); + CHECK_FALSE(converted.value().value("copy_non_cell_attribute_matrices")); +} diff --git a/src/simplnx/Utilities/ImageProcessing/ImageProcessingFilterUtilities.hpp b/src/simplnx/Utilities/ImageProcessing/ImageProcessingFilterUtilities.hpp index 52e35db44c..802a870caa 100644 --- a/src/simplnx/Utilities/ImageProcessing/ImageProcessingFilterUtilities.hpp +++ b/src/simplnx/Utilities/ImageProcessing/ImageProcessingFilterUtilities.hpp @@ -7,11 +7,14 @@ #include "simplnx/DataStructure/DataStructure.hpp" #include "simplnx/DataStructure/Geometry/ImageGeom.hpp" #include "simplnx/DataStructure/IDataArray.hpp" +#include "simplnx/Filter/Actions/CopyDataObjectAction.hpp" #include "simplnx/Filter/Actions/CreateArrayAction.hpp" #include "simplnx/Filter/Actions/CreateImageGeometryAction.hpp" #include "simplnx/Filter/Actions/DeleteDataAction.hpp" +#include "simplnx/Filter/Actions/MoveDataAction.hpp" #include "simplnx/Filter/Actions/RenameDataAction.hpp" #include "simplnx/Filter/Output.hpp" +#include "simplnx/Utilities/DataGroupUtilities.hpp" #include "simplnx/Utilities/ImageProcessing/ImageProcessingConstants.hpp" #include "simplnx/Utilities/MemoryUtilities.hpp" @@ -665,7 +668,10 @@ Result PreflightFullOverwriteImageFilter(const DataStructure& dat * is impossible because the collapsed output array cannot be inserted into the still-full cell * AttributeMatrix (tuple-count mismatch), and resizing the AttributeMatrix before executeImpl * would destroy the input the engine still has to read. Because that swap replaces the whole - * original geometry, any OTHER arrays in its cell data are discarded; a warning enumerates them. + * original geometry, any OTHER arrays in its cell data and unpreserved geometry children are + * discarded; a warning enumerates them. + * - copyNonCellAttributeMatrices == true: non-cell Attribute Matrices are moved before the deferred + * in-place swap (no array copies), or deep-copied into the new geometry in non-in-place mode. * * The output element type is the input type mapped through @p OutTypeMap (SameAsInput for type-preserving * reducers like Max; a fixed float map for Mean/StdDev/Sum). The execute façade MUST be instantiated with @@ -676,7 +682,7 @@ Result PreflightFullOverwriteImageFilter(const DataStructure& dat */ template class OutTypeMap = SameAsInput> Result PreflightAxisProjection(const DataStructure& dataStructure, const DataPath& imageGeomPath, const DataPath& inputArrayPath, usize projDim, bool performInPlace, - const std::string& outputGeomName, const std::string& outputArrayName) + const std::string& outputGeomName, const std::string& outputArrayName, bool copyNonCellAttributeMatrices = false) { if(projDim > 2) { @@ -745,6 +751,38 @@ Result PreflightAxisProjection(const DataStructure& dataStructure result.value().appendAction(std::make_unique(outputDataType, tupleShape, std::vector{1}, outputArrayPath, inputArray.getDataFormat(), "", std::nullopt, DataStoreInitializationMode::DeferredZeroFill)); + if(copyNonCellAttributeMatrices) + { + for(const auto& [childId, childObject] : imageGeom) + { + if(childId == cellData->getId() || dynamic_cast(childObject.get()) == nullptr) + { + continue; + } + const DataPath sourcePath = imageGeomPath.createChildPath(childObject->getName()); + if(performInPlace) + { + // Preserve the original objects and stores after projection, before deleting their old geometry. + result.value().appendDeferredAction(std::make_unique(sourcePath, targetGeomPath)); + } + else + { + const DataPath destinationPath = targetGeomPath.createChildPath(childObject->getName()); + std::vector allCreatedPaths = {destinationPath}; + const auto childPaths = GetAllChildDataPathsRecursive(dataStructure, sourcePath); + if(childPaths.has_value()) + { + for(const auto& childPath : childPaths.value()) + { + allCreatedPaths.push_back(childPath.rebase(sourcePath, destinationPath).value()); + } + } + // Data-store deep copies use bounded transfers and respect the destination storage policy. + result.value().appendAction(std::make_unique(sourcePath, destinationPath, allCreatedPaths)); + } + } + } + if(performInPlace) { // Deferred (post-executeImpl) swap: rename the original geometry away, delete it, then rename the @@ -757,9 +795,9 @@ Result PreflightAxisProjection(const DataStructure& dataStructure result.value().appendDeferredAction(std::make_unique(renamedOriginalPath)); result.value().appendDeferredAction(std::make_unique(targetGeomPath, originalName)); - // In-place discards the whole original geometry, so any OTHER cell-data arrays are lost. They cannot - // survive the collapse (they have the original, non-collapsed tuple count), but say so rather than - // dropping them silently. The selected input (consumed by the projection) is not listed. + // In-place discards the original geometry. List unpreserved children as well as other cell-data + // arrays. Non-cell Attribute Matrices can be moved above. The selected input is consumed by the + // projection and the output name is replaced, so neither is listed. const std::string inputArrayName = inputArrayPath.getTargetName(); std::string discarded; for(const auto& [childId, childObject] : *cellData) @@ -773,13 +811,25 @@ Result PreflightAxisProjection(const DataStructure& dataStructure { discarded += ", "; } - discarded += childName; + discarded += imageGeom.getCellDataPath().createChildPath(childName).toString(); + } + for(const auto& [childId, childObject] : imageGeom) + { + if(childId == cellData->getId() || (copyNonCellAttributeMatrices && dynamic_cast(childObject.get()) != nullptr)) + { + continue; + } + if(!discarded.empty()) + { + discarded += ", "; + } + discarded += imageGeomPath.createChildPath(childObject->getName()).toString(); } if(!discarded.empty()) { - result.warnings().push_back(Warning{-8343, fmt::format("Perform In-Place replaces Image Geometry '{}' with the collapsed projection, so the following other array(s) in cell data '{}' will be " - "discarded (they cannot be projected and do not fit the collapsed shape): {}. Disable 'Perform In-Place' to keep the original geometry.", - imageGeomPath.toString(), cellDataName, discarded)}); + result.warnings().push_back(Warning{-8343, fmt::format("Perform In-Place replaces Image Geometry '{}' with the collapsed projection. The following other data object(s), including their " + "contents, will be discarded: {}. Disable 'Perform In-Place' to keep the original geometry.", + imageGeomPath.toString(), discarded)}); } } diff --git a/wrapping/python/examples/pipelines/NXImageProcessing/14_Projection-Based_Quality_Summaries.py b/wrapping/python/examples/pipelines/NXImageProcessing/14_Projection-Based_Quality_Summaries.py index d447dad9d4..06e0601981 100644 --- a/wrapping/python/examples/pipelines/NXImageProcessing/14_Projection-Based_Quality_Summaries.py +++ b/wrapping/python/examples/pipelines/NXImageProcessing/14_Projection-Based_Quality_Summaries.py @@ -59,6 +59,7 @@ output_array_name='Pore Occupancy', output_image_geometry_name='Binary Pore Projection', projection_dimension=2, + copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.BinaryProjectionImageFilter, result) @@ -71,6 +72,7 @@ output_array_name='Maximum Intensity', output_image_geometry_name='Maximum XCT Projection', projection_dimension=2, + copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.MaximumProjectionImageFilter, result) @@ -83,6 +85,7 @@ output_array_name='Mean Intensity', output_image_geometry_name='Mean XCT Projection', projection_dimension=2, + copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.MeanProjectionImageFilter, result) @@ -95,6 +98,7 @@ output_array_name='Median Intensity', output_image_geometry_name='Median XCT Projection', projection_dimension=2, + copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.MedianProjectionImageFilter, result) @@ -107,6 +111,7 @@ output_array_name='Minimum Intensity', output_image_geometry_name='Minimum XCT Projection', projection_dimension=2, + copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.MinimumProjectionImageFilter, result) @@ -119,6 +124,7 @@ output_array_name='Intensity Deviation', output_image_geometry_name='Deviation XCT Projection', projection_dimension=2, + copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.StandardDeviationProjectionImageFilter, result) @@ -131,6 +137,7 @@ output_array_name='Integrated Intensity', output_image_geometry_name='Sum XCT Projection', projection_dimension=2, + copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.SumProjectionImageFilter, result) From f7516fb5d1878cb4924da80aac282f55b67afcf6 Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Wed, 4 Nov 2026 13:46:25 -0500 Subject: [PATCH 19/33] BUG: ReadImageStack - Report a slice with a different data type instead of throwing The stack array takes its data type from file 0. A later slice with a different type (for example uint16 in a uint8 stack) made the typed array lookup throw std::bad_cast after earlier slices were already copied, and the user got the generic error -2. DREAM.3D 6.5.171 could crash or produce zero slices in its ITK reader (errata KI-051). At the start of execute, before any slice is decoded or written, the filter now reads the header of every kept slice and returns -23534, naming the slice, its type and the stack type, when a type differs. Preflight still opens only file 0, so editing a pipeline with a large stack stays fast. With an explicit output data type, a mixed stack is converted and imported as before. Add a test with generated uint8 and uint16 TIFF slices in both orders: without conversion, preflight passes and execute returns -23534 with the stack left at zero; with uint16 conversion, both slices import (10 -> 2570, 1000); a Z crop that keeps only slice 0 succeeds. Fixes #1908 item L62 Signed-off-by: Mike Jackson --- .../docs/ReadImageStackFilter.md | 2 + .../Filters/ReadImageStackFilter.cpp | 49 +++++++ .../test/ReadImageStackTest.cpp | 135 ++++++++++++++++++ 3 files changed, 186 insertions(+) diff --git a/src/Plugins/NXImageProcessing/docs/ReadImageStackFilter.md b/src/Plugins/NXImageProcessing/docs/ReadImageStackFilter.md index 026d2056da..b8007f7c9e 100644 --- a/src/Plugins/NXImageProcessing/docs/ReadImageStackFilter.md +++ b/src/Plugins/NXImageProcessing/docs/ReadImageStackFilter.md @@ -78,6 +78,8 @@ The *Output Data Type* parameter provides the following choices: - **uint16 [1]**: Convert image data to 16-bit unsigned integer. - **uint32 [2]**: Convert image data to 32-bit unsigned integer. +Preflight reads only the first file's image header. At the start of execution, the filter checks the data type of each slice kept by the Z crop. When *Set Image Data Type* is off, the first file in the list sets the stack's output type, also when the Z crop removes that file. If a slice cannot match the stack's output type, error `-23534` names the file and the expected and actual types. No slice pixels are written on this error. Mixed uint8 and uint16 slices can be read together when *Set Image Data Type* converts them to the same output type. This intentionally differs from the failure described in DREAM3D 6.5.171 errata KI-051. + ### Cropping Caveats The user can crop the incoming image geometry using the Cropping Options section. The cropping type options are: diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/ReadImageStackFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/ReadImageStackFilter.cpp index 95737f57b3..ddcd5ecb6a 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/ReadImageStackFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/ReadImageStackFilter.cpp @@ -27,6 +27,7 @@ #include "simplnx/Utilities/ImageProcessing/ImageGeometryResample.hpp" #include "simplnx/Utilities/SIMPLConversion.hpp" +#include #include namespace fs = std::filesystem; @@ -441,6 +442,54 @@ Result<> ReadImageStackFilter::executeImpl(DataStructure& dataStructure, const A inputValues.imageDataType = ChoiceToImageDataType(filterArgs.value(k_ImageDataType_Key)); inputValues.croppingOptions = filterArgs.value(k_CroppingOptions_Key); + // Output actions have already created the stack. Check headers before decoding or copying any + // slice pixels; interactive preflight reads only file 0. These checks do not apply slice actions. + auto zRangeResult = ComputeCroppedZRange(inputValues.croppingOptions, inputValues.fileList.size(), inputValues.origin, inputValues.spacing, inputValues.changeOrigin, inputValues.changeSpacing, + inputValues.originSpacingProcessing); + if(zRangeResult.invalid()) + { + return ConvertResult(std::move(zRangeResult)); + } + const auto& zRange = zRangeResult.value(); + const DataPath imageDataPath = inputValues.imageGeometryPath.createChildPath(inputValues.cellDataName).createChildPath(inputValues.imageDataArrayName); + const DataType stackType = dataStructure.getDataRefAs(imageDataPath).getDataType(); + + ReadImageSubFilterConfig subConfig{}; + subConfig.imageGeometryPath = inputValues.imageGeometryPath; + subConfig.cellDataName = inputValues.cellDataName; + subConfig.imageDataArrayName = inputValues.imageDataArrayName; + subConfig.changeOrigin = inputValues.changeOrigin; + subConfig.changeSpacing = inputValues.changeSpacing; + subConfig.origin = inputValues.origin; + subConfig.spacing = inputValues.spacing; + subConfig.originSpacingProcessing = inputValues.originSpacingProcessing; + subConfig.changeDataType = inputValues.changeDataType; + subConfig.imageDataType = inputValues.imageDataType; + subConfig.croppingOptions = inputValues.croppingOptions; + + DataStructure tmpDs; + ReadImageFilter imageReader; + imageReader.setReadSinglePageOnly(true); + for(usize i = std::max(1, zRange.zMin); i <= zRange.zMax; ++i) + { + subConfig.filePath = inputValues.fileList[i]; + PreflightResult sliceResult = imageReader.preflight(tmpDs, BuildReadImageFilterArgs(subConfig), messageHandler, shouldCancel); + if(sliceResult.outputActions.invalid()) + { + return ConvertResult(std::move(sliceResult.outputActions)); + } + const auto* sliceArrayAction = FindFirstActionOfType(sliceResult.outputActions.value().actions); + if(sliceArrayAction == nullptr) + { + return MakeErrorResult(-23531, "Internal error: ReadImageFilter preflight did not produce a CreateArrayAction."); + } + if(sliceArrayAction->type() != stackType) + { + return MakeErrorResult( + -23534, fmt::format("Slice {} ('{}') has data type {}, but the stack requires {}.", i, inputValues.fileList[i], DataTypeToString(sliceArrayAction->type()), DataTypeToString(stackType))); + } + } + return ReadImageStack(dataStructure, messageHandler, shouldCancel, inputValues)(); } diff --git a/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp b/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp index 68712a55c2..0ab37fca32 100644 --- a/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp +++ b/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -1489,6 +1490,140 @@ TEST_CASE("NXImageProcessing::ReadImageStackFilter::MultiPage_FirstPagePerFile", REQUIRE(hasMultiPageWarning); } +TEST_CASE("ImageProcessing::ReadImageStackFilter::MixedSliceDataTypes", "[ImageProcessing][ReadImageStackFilter]") +{ + UnitTest::LoadPlugins(); + const bool firstSliceIsUint16 = GENERATE(false, true); + CAPTURE(firstSliceIsUint16); + const fs::path inputDir = fs::path(std::string(unit_test::k_BinaryTestOutputDir.view())) / "ReadImageStackMixedSliceDataTypes"; + fs::create_directories(inputDir); + for(usize slice = 0; slice < 2; ++slice) + { + const fs::path path = inputDir / fmt::format("slice_{}.tif", slice); + if((slice == 0) == firstSliceIsUint16) + { + TIFF* tif = TIFFOpen(path.string().c_str(), "w"); + REQUIRE(tif != nullptr); + REQUIRE(TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, 2) != 0); + REQUIRE(TIFFSetField(tif, TIFFTAG_IMAGELENGTH, 2) != 0); + REQUIRE(TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1) != 0); + REQUIRE(TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16) != 0); + REQUIRE(TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT) != 0); + REQUIRE(TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT) != 0); + REQUIRE(TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG) != 0); + REQUIRE(TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK) != 0); + std::vector pixels = {1000, 1000, 1000, 1000}; + REQUIRE(TIFFWriteScanline(tif, pixels.data(), 0, 0) >= 0); + REQUIRE(TIFFWriteScanline(tif, pixels.data() + 2, 1, 0) >= 0); + TIFFClose(tif); + } + else + { + WriteMultiPageTiff(path, 2, 2, {{10, 10, 10, 10}}); + } + } + + GeneratedFileListParameter::ValueType fileList; + fileList.inputPath = inputDir.string(); + fileList.filePrefix = "slice_"; + fileList.fileSuffix = ""; + fileList.fileExtension = ".tif"; + fileList.startIndex = 0; + fileList.endIndex = 1; + fileList.incrementIndex = 1; + fileList.paddingDigits = 1; + fileList.ordering = GeneratedFileListParameter::Ordering::LowToHigh; + + ReadImageStackFilter filter; + DataStructure ds; + Arguments args; + args.insertOrAssign(ReadImageStackFilter::k_InputFileListInfo_Key, std::make_any(fileList)); + args.insertOrAssign(ReadImageStackFilter::k_ImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); + + SECTION("Reject before writing any slices") + { + // With conversion disabled, uint8 and uint16 cannot share a typed stack array. + // Preflight reads only file 0. Execute must reject the mismatch before copying any pixels. + DataStructure preflightDs; + IFilter::PreflightResult preflightResult; + REQUIRE_NOTHROW(preflightResult = filter.preflight(preflightDs, args)); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + IFilter::ExecuteResult executeResult; + REQUIRE_NOTHROW(executeResult = filter.execute(ds, args)); + SIMPLNX_RESULT_REQUIRE_INVALID(executeResult.result); + const auto& sliceError = executeResult.result.errors().front(); + CAPTURE(sliceError.code, sliceError.message); + CHECK(sliceError.code == -23534); + CHECK(sliceError.message.find("slice_1.tif") != std::string::npos); + CHECK(sliceError.message.find("uint8") != std::string::npos); + CHECK(sliceError.message.find("uint16") != std::string::npos); + // IFilter applies output actions before executeImpl. The initial zeros must remain unchanged, + // including slice 0, whose nonzero fixture values would expose a late validation check. + if(firstSliceIsUint16) + { + const auto& store = ds.getDataRefAs(k_ImageDataPath).getDataStoreRef(); + REQUIRE(store.getSize() == 8); + for(usize pixel = 0; pixel < store.getSize(); ++pixel) + { + CHECK(store[pixel] == 0); + } + } + else + { + const auto& store = ds.getDataRefAs(k_ImageDataPath).getDataStoreRef(); + REQUIRE(store.getSize() == 8); + for(usize pixel = 0; pixel < store.getSize(); ++pixel) + { + CHECK(store[pixel] == 0); + } + } + } + + SECTION("Preflight does not read later slice headers") + { + // An existing file with an invalid TIFF header distinguishes header I/O from file-list checks. + { + std::ofstream invalidSlice(inputDir / "slice_1.tif", std::ios::binary | std::ios::trunc); + REQUIRE(invalidSlice.is_open()); + invalidSlice << "not a TIFF"; + REQUIRE(invalidSlice.good()); + } + auto preflightResult = filter.preflight(ds, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + } + + SECTION("Explicit conversion permits mixed types") + { + args.insertOrAssign(ReadImageStackFilter::k_ChangeDataType_Key, true); + args.insertOrAssign(ReadImageStackFilter::k_ImageDataType_Key, std::make_any(1)); + auto executeResult = filter.execute(ds, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); + const auto& store = ds.getDataRefAs(k_ImageDataPath).getDataStoreRef(); + REQUIRE(store.getNumberOfTuples() == 8); + // Read Image's normalized conversion gives 10 * (65535 / 255) = 2570; + // uint16(1000) remains 1000 when the source and destination types match. + for(usize slice = 0; slice < 2; ++slice) + { + const uint16_t expected = ((slice == 0) == firstSliceIsUint16) ? 1000 : 2570; + for(usize pixel = 0; pixel < 4; ++pixel) + { + REQUIRE(store[slice * 4 + pixel] == expected); + } + } + } + + SECTION("Z crop excludes the mismatched slice") + { + auto crop = CreateCropOptions(CropGeometryParameter::CropValues::TypeEnum::VoxelSubvolume, false, false, true); + crop.zBoundVoxels = {0, 0}; + args.insertOrAssign(ReadImageStackFilter::k_CroppingOptions_Key, std::make_any(crop)); + auto executeResult = filter.execute(ds, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); + VerifyGeometryDimensions(ds, k_ImageGeomPath, 2, 2, 1); + } +} + namespace { /** From a95cf0cfb0fa1e2868e2a51283a6637e80734fd7 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 4 Nov 2026 17:46:11 -0500 Subject: [PATCH 20/33] REV: ProjectionImageFilters - Keep only the in-place warning fix Review of #1915: the Copy Non-Cell Attribute Matrices option went beyond the filed defect. It exposed the StringArray deep-copy defect (#1916) and copy failures that are not reported, and it made preflight copy full feature matrices. The option moves to a separate pull request. Remove the parameter from the seven projection filters, the move and copy actions in the shared helper, the parameter version bump, and the pipeline and Python example changes. The projection filter sources and the shipped pipeline are identical to develop again. Keep the fix of the filed defect: with Perform In-Place on, warning -8343 names every discarded Cell Data array (including one with the output name) and every other child of the geometry, such as Cell Feature Data, by full path. The consumed input is not listed, also when it is not in Cell Data. Tests for Maximum and Standard Deviation check the warning text. Fixes #1908 item L58 Fixes #1908 item L63 Signed-off-by: Michael Jackson --- .../docs/BinaryProjectionImageFilter.md | 8 +- .../docs/MaximumProjectionImageFilter.md | 8 +- .../docs/MeanProjectionImageFilter.md | 8 +- .../docs/MedianProjectionImageFilter.md | 8 +- .../docs/MinimumProjectionImageFilter.md | 8 +- .../StandardDeviationProjectionImageFilter.md | 8 +- .../docs/SumProjectionImageFilter.md | 8 +- ...ection-Based_Quality_Summaries.d3dpipeline | 42 +---- .../Filters/BinaryProjectionImageFilter.cpp | 7 +- .../Filters/BinaryProjectionImageFilter.hpp | 1 - .../Filters/MaximumProjectionImageFilter.cpp | 9 +- .../Filters/MaximumProjectionImageFilter.hpp | 1 - .../Filters/MeanProjectionImageFilter.cpp | 7 +- .../Filters/MeanProjectionImageFilter.hpp | 1 - .../Filters/MedianProjectionImageFilter.cpp | 9 +- .../Filters/MedianProjectionImageFilter.hpp | 1 - .../Filters/MinimumProjectionImageFilter.cpp | 9 +- .../Filters/MinimumProjectionImageFilter.hpp | 1 - ...StandardDeviationProjectionImageFilter.cpp | 7 +- ...StandardDeviationProjectionImageFilter.hpp | 1 - .../Filters/SumProjectionImageFilter.cpp | 7 +- .../Filters/SumProjectionImageFilter.hpp | 1 - .../test/MaximumProjectionImageFilterTest.cpp | 163 ++++++------------ ...dardDeviationProjectionImageFilterTest.cpp | 138 +++------------ .../ImageProcessingFilterUtilities.hpp | 51 +----- .../14_Projection-Based_Quality_Summaries.py | 7 - 26 files changed, 119 insertions(+), 400 deletions(-) diff --git a/src/Plugins/NXImageProcessing/docs/BinaryProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/BinaryProjectionImageFilter.md index 74f8524516..10dd512f47 100644 --- a/src/Plugins/NXImageProcessing/docs/BinaryProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/BinaryProjectionImageFilter.md @@ -14,13 +14,7 @@ The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. The **Foreground Value** and **Background Value** are supplied as floating-point numbers and cast to the input element type; the foreground equality test is performed in the input element type. This matches the legacy ITK Binary Projection accumulator, which initializes each column to background and switches it to foreground the first time a voxel equal to the foreground value is encountered. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. - -**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. - -Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. - -Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the scalar numeric types (`int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`, `float32`, or `float64`). This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Binary Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/MaximumProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/MaximumProjectionImageFilter.md index 24817744f4..da6c772431 100644 --- a/src/Plugins/NXImageProcessing/docs/MaximumProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/MaximumProjectionImageFilter.md @@ -12,13 +12,7 @@ Collapses the selected **Projection Dimension** of a scalar Image Geometry to a The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. - -**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. - -Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. - -Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the supported types: `uint8`, `int16`, `uint16`, or `float32`. This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Maximum Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/MeanProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/MeanProjectionImageFilter.md index 514c7f9a55..ac4e0513f1 100644 --- a/src/Plugins/NXImageProcessing/docs/MeanProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/MeanProjectionImageFilter.md @@ -14,13 +14,7 @@ The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. The output element type is always **Float64** (double), regardless of the input element type, matching the legacy ITK Mean Projection Image Filter (the mean of an integer column is generally not an integer). The mean is accumulated with a Kahan-compensated running sum so that long columns do not lose precision. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. - -**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. - -Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. - -Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the scalar numeric types (`int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`, `float32`, or `float64`). This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Mean Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/MedianProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/MedianProjectionImageFilter.md index 588b868a4c..f33d0e3029 100644 --- a/src/Plugins/NXImageProcessing/docs/MedianProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/MedianProjectionImageFilter.md @@ -12,13 +12,7 @@ Collapses the selected **Projection Dimension** of a scalar Image Geometry to a The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. - -**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. - -Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. - -Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the supported types: `uint8`, `int16`, `uint16`, or `float32`. This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Median Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/MinimumProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/MinimumProjectionImageFilter.md index cb63212f06..4a5e0f2bea 100644 --- a/src/Plugins/NXImageProcessing/docs/MinimumProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/MinimumProjectionImageFilter.md @@ -12,13 +12,7 @@ Collapses the selected **Projection Dimension** of a scalar Image Geometry to a The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. - -**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. - -Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. - -Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the supported types: `uint8`, `int16`, `uint16`, or `float32`. This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Minimum Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/StandardDeviationProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/StandardDeviationProjectionImageFilter.md index ee84e63348..b24f7f3168 100644 --- a/src/Plugins/NXImageProcessing/docs/StandardDeviationProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/StandardDeviationProjectionImageFilter.md @@ -14,13 +14,7 @@ The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. The standard deviation is the *sample* standard deviation: the column mean is formed with the population divisor *N*, but the sum of squared deviations is divided by *N − 1* before taking the square root, matching the legacy ITK Standard Deviation Projection Image Filter. A column of length 1 (or a degenerate projected axis) yields 0. The output element type is always **Float64** (double), regardless of the input element type. The statistic uses Welford's online update to avoid cancellation when large values have small differences. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. - -**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. - -Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. - -Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the scalar numeric types (`int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`, `float32`, or `float64`). This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Standard Deviation Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/SumProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/SumProjectionImageFilter.md index bb905a60d6..121e704dae 100644 --- a/src/Plugins/NXImageProcessing/docs/SumProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/SumProjectionImageFilter.md @@ -14,13 +14,7 @@ The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. The output element type is always **Float64** (double), regardless of the input element type, matching the legacy ITK Sum Projection Image Filter (the sum of an integer column readily overflows a narrow integer type). The sum is accumulated with a Kahan-compensated running sum so that long columns do not lose precision. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the collapsed geometry containing the output array. Other Cell Data arrays are discarded. Preflight warning `-8343` lists the paths of the discarded objects. The contents of each listed object are also discarded. - -**Copy Non-Cell Attribute Matrices** is disabled by default. With this option disabled, the projected geometry contains only the projected Cell Data. In-place projection discards other geometry children, including Cell Feature Data and Cell Ensemble Data. Warning `-8343` names these objects even when there are no other Cell Data arrays. - -Enable **Copy Non-Cell Attribute Matrices** to keep every non-cell Attribute Matrix and its contents in the projected geometry. In-place projection moves these matrices without copying their arrays. They are then omitted from warning `-8343`. This optional preservation differs from DREAM3D 6.5.171, which discards these matrices during in-place projection. The preserved data is unchanged; feature measurements are not recalculated for the projection. - -Disable **Perform In-Place** to keep the original geometry and all its data. The result is written to a new geometry named by **Created Image Geometry**. Its cell-data Attribute Matrix uses the same name as the input. When **Copy Non-Cell Attribute Matrices** is enabled, the new geometry also receives independent copies of the non-cell Attribute Matrices and their contents. String arrays in the copied Attribute Matrices currently share their values with the input; they are not independent copies. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the scalar numeric types (`int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`, `float32`, or `float64`). This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Sum Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/pipelines/14_Projection-Based_Quality_Summaries/14_Projection-Based_Quality_Summaries.d3dpipeline b/src/Plugins/NXImageProcessing/pipelines/14_Projection-Based_Quality_Summaries/14_Projection-Based_Quality_Summaries.d3dpipeline index a15cd9a6b2..0e38d321b3 100644 --- a/src/Plugins/NXImageProcessing/pipelines/14_Projection-Based_Quality_Summaries/14_Projection-Based_Quality_Summaries.d3dpipeline +++ b/src/Plugins/NXImageProcessing/pipelines/14_Projection-Based_Quality_Summaries/14_Projection-Based_Quality_Summaries.d3dpipeline @@ -128,10 +128,6 @@ "value": 0.0, "version": 1 }, - "copy_non_cell_attribute_matrices": { - "value": false, - "version": 1 - }, "foreground_value": { "value": 1.0, "version": 1 @@ -152,7 +148,7 @@ "value": "Binary Pore Projection", "version": 1 }, - "parameters_version": 2, + "parameters_version": 1, "projection_dimension": { "value": 2, "version": 1 @@ -171,10 +167,6 @@ }, { "args": { - "copy_non_cell_attribute_matrices": { - "value": false, - "version": 1 - }, "input_image_data_path": { "value": "Projection Volume/Cell Data/XCT Intensity", "version": 1 @@ -191,7 +183,7 @@ "value": "Maximum XCT Projection", "version": 1 }, - "parameters_version": 2, + "parameters_version": 1, "projection_dimension": { "value": 2, "version": 1 @@ -210,10 +202,6 @@ }, { "args": { - "copy_non_cell_attribute_matrices": { - "value": false, - "version": 1 - }, "input_image_data_path": { "value": "Projection Volume/Cell Data/XCT Intensity", "version": 1 @@ -230,7 +218,7 @@ "value": "Mean XCT Projection", "version": 1 }, - "parameters_version": 2, + "parameters_version": 1, "projection_dimension": { "value": 2, "version": 1 @@ -249,10 +237,6 @@ }, { "args": { - "copy_non_cell_attribute_matrices": { - "value": false, - "version": 1 - }, "input_image_data_path": { "value": "Projection Volume/Cell Data/XCT Intensity", "version": 1 @@ -269,7 +253,7 @@ "value": "Median XCT Projection", "version": 1 }, - "parameters_version": 2, + "parameters_version": 1, "projection_dimension": { "value": 2, "version": 1 @@ -288,10 +272,6 @@ }, { "args": { - "copy_non_cell_attribute_matrices": { - "value": false, - "version": 1 - }, "input_image_data_path": { "value": "Projection Volume/Cell Data/XCT Intensity", "version": 1 @@ -308,7 +288,7 @@ "value": "Minimum XCT Projection", "version": 1 }, - "parameters_version": 2, + "parameters_version": 1, "projection_dimension": { "value": 2, "version": 1 @@ -327,10 +307,6 @@ }, { "args": { - "copy_non_cell_attribute_matrices": { - "value": false, - "version": 1 - }, "input_image_data_path": { "value": "Projection Volume/Cell Data/XCT Intensity", "version": 1 @@ -347,7 +323,7 @@ "value": "Deviation XCT Projection", "version": 1 }, - "parameters_version": 2, + "parameters_version": 1, "projection_dimension": { "value": 2, "version": 1 @@ -366,10 +342,6 @@ }, { "args": { - "copy_non_cell_attribute_matrices": { - "value": false, - "version": 1 - }, "input_image_data_path": { "value": "Projection Volume/Cell Data/XCT Intensity", "version": 1 @@ -386,7 +358,7 @@ "value": "Sum XCT Projection", "version": 1 }, - "parameters_version": 2, + "parameters_version": 1, "projection_dimension": { "value": 2, "version": 1 diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.cpp index e23c30fd0e..68fd5a17d9 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.cpp @@ -115,8 +115,6 @@ Parameters BinaryProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); - params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", - "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insert(std::make_unique( k_ForegroundValue_Key, "Foreground Value", "The value a projected column is set to when ANY voxel along the projection axis equals this value. For an integer input image the value must be finite and within the image type's range.", @@ -145,7 +143,7 @@ Parameters BinaryProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType BinaryProjectionImageFilter::parametersVersion() const { - return 2; + return 1; } //------------------------------------------------------------------------------ @@ -163,7 +161,6 @@ IFilter::PreflightResult BinaryProjectionImageFilter::preflightImpl(const DataSt auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); - auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); auto foregroundValue = filterArgs.value(k_ForegroundValue_Key); auto backgroundValue = filterArgs.value(k_BackgroundValue_Key); @@ -173,7 +170,7 @@ IFilter::PreflightResult BinaryProjectionImageFilter::preflightImpl(const DataSt // default SameAsInput OutTypeMap keeps the allocated and written output types in lock-step). The scalar // (single-component) and tuple-consistency checks are performed inside PreflightAxisProjection. Result resultOutputActions = ImageProcessing::PreflightAxisProjection( - dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName, copyNonCellAttributeMatrices); + dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); if(resultOutputActions.invalid()) { return {std::move(resultOutputActions)}; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.hpp index 7fdcf2f006..eb73031cdc 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/BinaryProjectionImageFilter.hpp @@ -28,7 +28,6 @@ class NXIMAGEPROCESSING_EXPORT BinaryProjectionImageFilter : public IFilter // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; - static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.cpp index e7d272e4a5..e29f766f71 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.cpp @@ -55,8 +55,6 @@ Parameters MaximumProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); - params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", - "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insertSeparator(Parameters::Separator{"Input Cell Data"}); params.insert(std::make_unique(k_InputImageGeomPath_Key, "Image Geometry", "Select the Image Geometry Group from the DataStructure.", DataPath({"Image Geometry"}), @@ -77,7 +75,7 @@ Parameters MaximumProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType MaximumProjectionImageFilter::parametersVersion() const { - return 2; + return 1; } //------------------------------------------------------------------------------ @@ -95,13 +93,12 @@ IFilter::PreflightResult MaximumProjectionImageFilter::preflightImpl(const DataS auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); - auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); // Maximum projection preserves the element type, so both preflight and execute use the default // SameAsInput OutTypeMap (kept in lock-step so the allocated and written output types agree). - Result resultOutputActions = ImageProcessing::PreflightAxisProjection(dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, - outputGeomName, outputArrayName, copyNonCellAttributeMatrices); + Result resultOutputActions = + ImageProcessing::PreflightAxisProjection(dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); return {std::move(resultOutputActions)}; } diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.hpp index f15ca29bb5..f61e8b3163 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MaximumProjectionImageFilter.hpp @@ -27,7 +27,6 @@ class NXIMAGEPROCESSING_EXPORT MaximumProjectionImageFilter : public IFilter // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; - static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.cpp index 18573ad2aa..6df9606e2e 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.cpp @@ -53,8 +53,6 @@ Parameters MeanProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); - params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", - "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insertSeparator(Parameters::Separator{"Input Cell Data"}); params.insert(std::make_unique(k_InputImageGeomPath_Key, "Image Geometry", "Select the Image Geometry Group from the DataStructure.", DataPath({"Image Geometry"}), @@ -75,7 +73,7 @@ Parameters MeanProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType MeanProjectionImageFilter::parametersVersion() const { - return 2; + return 1; } //------------------------------------------------------------------------------ @@ -93,7 +91,6 @@ IFilter::PreflightResult MeanProjectionImageFilter::preflightImpl(const DataStru auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); - auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); // The mean of an integer column is generally not an integer, so the legacy ITK filter emits a double @@ -102,7 +99,7 @@ IFilter::PreflightResult MeanProjectionImageFilter::preflightImpl(const DataStru // execute façade below MUST use the same pair, or the allocated and written output types disagree. The // scalar (single-component) and tuple-consistency checks are performed inside PreflightAxisProjection. Result resultOutputActions = ImageProcessing::PreflightAxisProjection( - dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName, copyNonCellAttributeMatrices); + dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); return {std::move(resultOutputActions)}; } diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.hpp index a6a5cd830d..0566fb1324 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MeanProjectionImageFilter.hpp @@ -28,7 +28,6 @@ class NXIMAGEPROCESSING_EXPORT MeanProjectionImageFilter : public IFilter // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; - static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.cpp index 540d950594..48b442e3e2 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.cpp @@ -55,8 +55,6 @@ Parameters MedianProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); - params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", - "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insertSeparator(Parameters::Separator{"Input Cell Data"}); params.insert(std::make_unique(k_InputImageGeomPath_Key, "Image Geometry", "Select the Image Geometry Group from the DataStructure.", DataPath({"Image Geometry"}), @@ -77,7 +75,7 @@ Parameters MedianProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType MedianProjectionImageFilter::parametersVersion() const { - return 2; + return 1; } //------------------------------------------------------------------------------ @@ -95,13 +93,12 @@ IFilter::PreflightResult MedianProjectionImageFilter::preflightImpl(const DataSt auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); - auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); // Median projection preserves the element type, so both preflight and execute use the default // SameAsInput OutTypeMap (kept in lock-step so the allocated and written output types agree). - Result resultOutputActions = ImageProcessing::PreflightAxisProjection(dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, - outputGeomName, outputArrayName, copyNonCellAttributeMatrices); + Result resultOutputActions = + ImageProcessing::PreflightAxisProjection(dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); return {std::move(resultOutputActions)}; } diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.hpp index dbe36d0195..f38a115a76 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MedianProjectionImageFilter.hpp @@ -27,7 +27,6 @@ class NXIMAGEPROCESSING_EXPORT MedianProjectionImageFilter : public IFilter // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; - static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.cpp index d88699686f..ff28b7f9a1 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.cpp @@ -55,8 +55,6 @@ Parameters MinimumProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); - params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", - "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insertSeparator(Parameters::Separator{"Input Cell Data"}); params.insert(std::make_unique(k_InputImageGeomPath_Key, "Image Geometry", "Select the Image Geometry Group from the DataStructure.", DataPath({"Image Geometry"}), @@ -77,7 +75,7 @@ Parameters MinimumProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType MinimumProjectionImageFilter::parametersVersion() const { - return 2; + return 1; } //------------------------------------------------------------------------------ @@ -95,13 +93,12 @@ IFilter::PreflightResult MinimumProjectionImageFilter::preflightImpl(const DataS auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); - auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); // Minimum projection preserves the element type, so both preflight and execute use the default // SameAsInput OutTypeMap (kept in lock-step so the allocated and written output types agree). - Result resultOutputActions = ImageProcessing::PreflightAxisProjection(dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, - outputGeomName, outputArrayName, copyNonCellAttributeMatrices); + Result resultOutputActions = + ImageProcessing::PreflightAxisProjection(dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); return {std::move(resultOutputActions)}; } diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.hpp index 68c77c893e..8826fd0efb 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/MinimumProjectionImageFilter.hpp @@ -27,7 +27,6 @@ class NXIMAGEPROCESSING_EXPORT MinimumProjectionImageFilter : public IFilter // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; - static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.cpp index c580f8e006..b4dd04668a 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.cpp @@ -53,8 +53,6 @@ Parameters StandardDeviationProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); - params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", - "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insertSeparator(Parameters::Separator{"Input Cell Data"}); params.insert(std::make_unique(k_InputImageGeomPath_Key, "Image Geometry", "Select the Image Geometry Group from the DataStructure.", DataPath({"Image Geometry"}), @@ -75,7 +73,7 @@ Parameters StandardDeviationProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType StandardDeviationProjectionImageFilter::parametersVersion() const { - return 2; + return 1; } //------------------------------------------------------------------------------ @@ -93,7 +91,6 @@ IFilter::PreflightResult StandardDeviationProjectionImageFilter::preflightImpl(c auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); - auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); // The standard deviation is a real-valued statistic, so the legacy ITK filter emits a double (Float64) @@ -102,7 +99,7 @@ IFilter::PreflightResult StandardDeviationProjectionImageFilter::preflightImpl(c // MUST use the same pair, or the allocated and written output types disagree. The scalar // (single-component) and tuple-consistency checks are performed inside PreflightAxisProjection. Result resultOutputActions = ImageProcessing::PreflightAxisProjection( - dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName, copyNonCellAttributeMatrices); + dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); return {std::move(resultOutputActions)}; } diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.hpp index e2d46d4129..bf6d548f63 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.hpp @@ -28,7 +28,6 @@ class NXIMAGEPROCESSING_EXPORT StandardDeviationProjectionImageFilter : public I // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; - static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.cpp index 2477f2ad85..7570a574dd 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.cpp @@ -53,8 +53,6 @@ Parameters SumProjectionImageFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_ProjectionDimension_Key, "Projection Dimension", "The axis to project along: 0=X, 1=Y, 2=Z.", 0u)); params.insertLinkableParameter(std::make_unique(k_RemoveOriginalGeometry_Key, "Perform In-Place", "Performs the projection in-place for the given Image Geometry", true)); - params.insert(std::make_unique(k_CopyNonCellAttributeMatrices_Key, "Copy Non-Cell Attribute Matrices", - "Move non-cell Attribute Matrices to the projected geometry in-place, or copy them when creating a new geometry.", false)); params.insertSeparator(Parameters::Separator{"Input Cell Data"}); params.insert(std::make_unique(k_InputImageGeomPath_Key, "Image Geometry", "Select the Image Geometry Group from the DataStructure.", DataPath({"Image Geometry"}), @@ -75,7 +73,7 @@ Parameters SumProjectionImageFilter::parameters() const //------------------------------------------------------------------------------ IFilter::VersionType SumProjectionImageFilter::parametersVersion() const { - return 2; + return 1; } //------------------------------------------------------------------------------ @@ -93,7 +91,6 @@ IFilter::PreflightResult SumProjectionImageFilter::preflightImpl(const DataStruc auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); - auto copyNonCellAttributeMatrices = filterArgs.value(k_CopyNonCellAttributeMatrices_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); // The sum of an integer column overflows narrow integer types, so the legacy ITK filter emits a double @@ -102,7 +99,7 @@ IFilter::PreflightResult SumProjectionImageFilter::preflightImpl(const DataStruc // execute façade below MUST use the same pair, or the allocated and written output types disagree. The // scalar (single-component) and tuple-consistency checks are performed inside PreflightAxisProjection. Result resultOutputActions = ImageProcessing::PreflightAxisProjection( - dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName, copyNonCellAttributeMatrices); + dataStructure, imageGeomPath, selectedInputArray, static_cast(projectionDimension), performInPlace, outputGeomName, outputArrayName); return {std::move(resultOutputActions)}; } diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.hpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.hpp index 18328bc15d..b6da6b215d 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.hpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/SumProjectionImageFilter.hpp @@ -28,7 +28,6 @@ class NXIMAGEPROCESSING_EXPORT SumProjectionImageFilter : public IFilter // Parameter Keys static constexpr StringLiteral k_ProjectionDimension_Key = "projection_dimension"; static constexpr StringLiteral k_RemoveOriginalGeometry_Key = "remove_original_geometry"; - static constexpr StringLiteral k_CopyNonCellAttributeMatrices_Key = "copy_non_cell_attribute_matrices"; static constexpr StringLiteral k_InputImageGeomPath_Key = "input_image_geometry_path"; static constexpr StringLiteral k_InputImageDataPath_Key = "input_image_data_path"; static constexpr StringLiteral k_OutputImageGeomName_Key = "output_image_geometry_name"; diff --git a/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp b/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp index 9a7fe01ecc..2b209eca6c 100644 --- a/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp +++ b/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp @@ -125,54 +125,31 @@ TEST_CASE("NXImageProcessing::MaximumProjectionImageFilter: ITK real-image golde projection_test::RunProjectionMd5ItkGolden("Ramp-Up-Short.nrrd", /*projDim=*/1, /*removeOriginalGeometry=*/true, "5390344262c91e83bc9208b0991a2fc9"); } -TEST_CASE("ImageProcessing::MaximumProjectionImageFilter: Copy non-cell Attribute Matrices", "[ImageProcessing][MaximumProjectionImageFilter]") +TEST_CASE("ImageProcessing::MaximumProjectionImageFilter: Warning names discarded objects", "[ImageProcessing][MaximumProjectionImageFilter]") { UnitTest::LoadPlugins(); const UnitTest::PreferencesSentinel prefsSentinel(DataStorageMode::ForceInCore, 0); - const bool inPlace = GENERATE(true, false); - const bool extraCellArray = GENERATE(false, true); - // Omitted exercises callers written before this option existed. - const int copyOption = GENERATE(-1, 0, 1); - const bool copyNonCell = copyOption == 1; - CAPTURE(inPlace, extraCellArray, copyOption); - + // No extra cell array, an extra one, and an old array with the output name (also discarded in place). + const std::string extraName = GENERATE(std::string(""), std::string("Extra"), std::string("Output")); DataStructure ds; const DataPath inputPath = ip_test::BuildRampImage(ds, 3, 0.0, 1.0); const DataPath geomPath({"Image Geometry"}); auto& imageGeom = ds.getDataRefAs(geomPath); const DataPath featurePath = geomPath.createChildPath("Cell Feature Data"); - auto* featureAM = AttributeMatrix::Create(ds, "Cell Feature Data", {2}, imageGeom.getId()); - REQUIRE(featureAM != nullptr); - const DataPath featureArrayPath = featurePath.createChildPath("Feature Values"); - auto featureStore = DataStoreUtilities::CreateDataStore(ds, featureArrayPath, {2}, {1}); - REQUIRE(Int32Array::Create(ds, "Feature Values", featureStore, featureAM->getId()) != nullptr); - featureStore->setValue(0, 17); - featureStore->setValue(1, 29); - const DataPath ensemblePath = geomPath.createChildPath("Cell Ensemble Data"); - REQUIRE(AttributeMatrix::Create(ds, "Cell Ensemble Data", {1}, imageGeom.getId()) != nullptr); - const auto featureId = featureAM->getId(); - const auto featureArrayId = ds.getDataRefAs(featureArrayPath).getId(); - const auto ensembleId = ds.getDataRefAs(ensemblePath).getId(); - if(extraCellArray) + REQUIRE(AttributeMatrix::Create(ds, "Cell Feature Data", {2}, imageGeom.getId()) != nullptr); + const DataPath extraPath = inputPath.getParent().createChildPath(extraName.empty() ? "Extra" : extraName); + if(!extraName.empty()) { - const DataPath cellPath = inputPath.getParent(); - auto& cellAM = ds.getDataRefAs(cellPath); - auto extraStore = DataStoreUtilities::CreateDataStore(ds, cellPath.createChildPath("Extra"), cellAM.getShape(), {1}); - REQUIRE(Int16Array::Create(ds, "Extra", extraStore, cellAM.getId()) != nullptr); + auto& cellAM = ds.getDataRefAs(inputPath.getParent()); + auto store = DataStoreUtilities::CreateDataStore(ds, extraPath, cellAM.getShape(), {1}); + REQUIRE(Int16Array::Create(ds, extraName, store, cellAM.getId()) != nullptr); } - MaximumProjectionImageFilter filter; Arguments args; args.insertOrAssign(MaximumProjectionImageFilter::k_InputImageGeomPath_Key, std::make_any(geomPath)); args.insertOrAssign(MaximumProjectionImageFilter::k_InputImageDataPath_Key, std::make_any(inputPath)); - args.insertOrAssign(MaximumProjectionImageFilter::k_ProjectionDimension_Key, std::make_any(0)); - args.insertOrAssign(MaximumProjectionImageFilter::k_RemoveOriginalGeometry_Key, std::make_any(inPlace)); - args.insertOrAssign(MaximumProjectionImageFilter::k_OutputImageGeomName_Key, std::make_any("Projected Image")); + args.insertOrAssign(MaximumProjectionImageFilter::k_RemoveOriginalGeometry_Key, std::make_any(true)); args.insertOrAssign(MaximumProjectionImageFilter::k_OutputImageArrayName_Key, std::make_any("Output")); - if(copyOption >= 0) - { - args.insertOrAssign("copy_non_cell_attribute_matrices", std::make_any(copyNonCell)); - } const auto preflightResult = filter.preflight(ds, args); SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); std::string discardedWarning; @@ -183,92 +160,62 @@ TEST_CASE("ImageProcessing::MaximumProjectionImageFilter: Copy non-cell Attribut discardedWarning += warning.message; } } - // Only discarded objects belong in the warning. Preserved matrices must not be listed. - if(inPlace) + // The geometry swap deletes the original children. The warning excludes the consumed input, + // but must name the feature matrix even when it is the only other discarded object, using full paths. + CHECK(discardedWarning.find(featurePath.toString()) != std::string::npos); + CHECK(discardedWarning.find(inputPath.toString()) == std::string::npos); + if(!extraName.empty()) { - CHECK((discardedWarning.find("Cell Feature Data") != std::string::npos) == !copyNonCell); - CHECK((discardedWarning.find("Cell Ensemble Data") != std::string::npos) == !copyNonCell); - CHECK(discardedWarning.empty() == (copyNonCell && !extraCellArray)); - if(extraCellArray) - { - CHECK(discardedWarning.find("Extra") != std::string::npos); - } - } - else - { - CHECK(discardedWarning.empty()); + CHECK(discardedWarning.find(extraPath.toString()) != std::string::npos); } - - // Axis projection dispatches by store type; it has no Direct/Scanline AlgorithmTestScope override. + // Axis projection dispatches by store type; it has no Direct/Scanline override. const auto executeResult = filter.execute(ds, args); SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); - const DataPath outputGeomPath = inPlace ? geomPath : DataPath({"Projected Image"}); - REQUIRE(ds.getDataRefAs(outputGeomPath).getDimensions() == SizeVec3{1, 3, 3}); - const auto& output = ds.getDataRefAs(outputGeomPath.createChildPath("CellData").createChildPath("Output")); - REQUIRE(output.getNumberOfTuples() == 9); - for(usize slot = 0; slot < 9; ++slot) - { - // Along X, the 3x3x3 ramp has columns {3*s, 3*s+1, 3*s+2}, so max = 3*s+2. - REQUIRE(output[slot] == static_cast(3 * slot + 2)); - } - if(copyNonCell) - { - const DataPath outputFeaturePath = outputGeomPath.createChildPath("Cell Feature Data"); - const auto* outputFeatureAM = ds.getDataAs(outputFeaturePath); - REQUIRE(outputFeatureAM != nullptr); - CHECK(outputFeatureAM->getShape() == ShapeType{2}); - auto& features = ds.getDataRefAs(outputFeaturePath.createChildPath("Feature Values")); - CHECK(features[0] == 17); - CHECK(features[1] == 29); - const auto* ensemble = ds.getDataAs(outputGeomPath.createChildPath("Cell Ensemble Data")); - REQUIRE(ensemble != nullptr); - CHECK(ensemble->getShape() == ShapeType{1}); - CHECK(ensemble->getSize() == 0); - if(inPlace) - { - CHECK(outputFeatureAM->getId() == featureId); - CHECK(features.getId() == featureArrayId); - CHECK(features.getDataStore() == featureStore.get()); - CHECK(ensemble->getId() == ensembleId); - } - else - { - CHECK(outputFeatureAM->getId() != featureId); - CHECK(features.getId() != featureArrayId); - CHECK(features.getDataStore() != featureStore.get()); - CHECK(ensemble->getId() != ensembleId); - features[0] = 101; - CHECK(ds.getDataRefAs(featureArrayPath)[0] == 17); - featureStore->setValue(1, 103); - CHECK(features[1] == 29); - featureStore->setValue(1, 29); - } - } - else + CHECK(ds.getData(featurePath) == nullptr); + if(extraName != "Output") { - CHECK(ds.getData(outputGeomPath.createChildPath("Cell Feature Data")) == nullptr); - CHECK(ds.getData(outputGeomPath.createChildPath("Cell Ensemble Data")) == nullptr); + CHECK(ds.getData(extraPath) == nullptr); } - if(!inPlace) + REQUIRE(ds.getDataRefAs(geomPath).getDimensions() == SizeVec3{1, 3, 3}); + const auto& output = ds.getDataRefAs(inputPath.getParent().createChildPath("Output")); + REQUIRE(output.getNumberOfTuples() == 9); + for(usize slot = 0; slot < 9; ++slot) { - const auto& features = ds.getDataRefAs(featureArrayPath); - CHECK(features[0] == 17); - CHECK(features[1] == 29); - CHECK(ds.getDataRefAs(featurePath).getId() == featureId); - CHECK(ds.getDataRefAs(ensemblePath).getId() == ensembleId); - CHECK(ds.getDataRefAs(geomPath).getDimensions() == SizeVec3{3, 3, 3}); + // X columns are {3*s, 3*s+1, 3*s+2}: max = 3*s+2. + CHECK(output[slot] == static_cast(3 * slot + 2)); } UnitTest::CheckArraysInheritTupleDims(ds); } -TEST_CASE("ImageProcessing::MaximumProjectionImageFilter: Older pipelines default to discarding non-cell matrices", "[ImageProcessing][MaximumProjectionImageFilter]") +TEST_CASE("ImageProcessing::MaximumProjectionImageFilter: Warning excludes an input outside cell data", "[ImageProcessing][MaximumProjectionImageFilter]") { + UnitTest::LoadPlugins(); + const UnitTest::PreferencesSentinel prefsSentinel(DataStorageMode::ForceInCore, 0); + DataStructure ds; + const DataPath cellInputPath = ip_test::BuildRampImage(ds, 3, 0.0, 1.0); + const DataPath geomPath({"Image Geometry"}); + auto& imageGeom = ds.getDataRefAs(geomPath); + // The selected input is a direct child of the geometry. It has the cell tuple count, so it is accepted. + const DataPath inputPath = geomPath.createChildPath("Geometry Input"); + auto store = DataStoreUtilities::CreateDataStore(ds, inputPath, ShapeType{3, 3, 3}, {1}); + REQUIRE(Float32Array::Create(ds, "Geometry Input", store, imageGeom.getId()) != nullptr); MaximumProjectionImageFilter filter; - auto json = filter.toJson(filter.getDefaultArguments()); - json.erase("copy_non_cell_attribute_matrices"); - json["parameters_version"] = 1; - const auto converted = filter.fromJson(json); - SIMPLNX_RESULT_REQUIRE_VALID(converted); - REQUIRE(converted.value().contains("copy_non_cell_attribute_matrices")); - CHECK_FALSE(converted.value().value("copy_non_cell_attribute_matrices")); + Arguments args; + args.insertOrAssign(MaximumProjectionImageFilter::k_InputImageGeomPath_Key, std::make_any(geomPath)); + args.insertOrAssign(MaximumProjectionImageFilter::k_InputImageDataPath_Key, std::make_any(inputPath)); + args.insertOrAssign(MaximumProjectionImageFilter::k_RemoveOriginalGeometry_Key, std::make_any(true)); + args.insertOrAssign(MaximumProjectionImageFilter::k_OutputImageArrayName_Key, std::make_any("Output")); + const auto preflightResult = filter.preflight(ds, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + std::string discardedWarning; + for(const auto& warning : preflightResult.outputActions.warnings()) + { + if(warning.code == -8343) + { + discardedWarning += warning.message; + } + } + // The cell array is not the input, so it is named. The consumed input is not named. + CHECK(discardedWarning.find(cellInputPath.toString()) != std::string::npos); + CHECK(discardedWarning.find(inputPath.toString()) == std::string::npos); } diff --git a/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp b/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp index ef669a5575..c24c14e680 100644 --- a/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp +++ b/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp @@ -265,54 +265,31 @@ TEST_CASE("NXImageProcessing::StandardDeviationProjectionImageFilter: ITK real-i /*tolerance=*/0.0001); } -TEST_CASE("ImageProcessing::StandardDeviationProjectionImageFilter: Copy non-cell Attribute Matrices", "[ImageProcessing][StandardDeviationProjectionImageFilter]") +TEST_CASE("ImageProcessing::StandardDeviationProjectionImageFilter: Warning names discarded objects", "[ImageProcessing][StandardDeviationProjectionImageFilter]") { UnitTest::LoadPlugins(); const UnitTest::PreferencesSentinel prefsSentinel(DataStorageMode::ForceInCore, 0); - const bool inPlace = GENERATE(true, false); - const bool extraCellArray = GENERATE(false, true); - // Omitted exercises callers written before this option existed. - const int copyOption = GENERATE(-1, 0, 1); - const bool copyNonCell = copyOption == 1; - CAPTURE(inPlace, extraCellArray, copyOption); - + // No extra cell array, an extra one, and an old array with the output name (also discarded in place). + const std::string extraName = GENERATE(std::string(""), std::string("Extra"), std::string("Output")); DataStructure ds; const DataPath inputPath = ip_test::BuildRampImage(ds, 3, 0.0, 1.0); const DataPath geomPath({"Image Geometry"}); auto& imageGeom = ds.getDataRefAs(geomPath); const DataPath featurePath = geomPath.createChildPath("Cell Feature Data"); - auto* featureAM = AttributeMatrix::Create(ds, "Cell Feature Data", {2}, imageGeom.getId()); - REQUIRE(featureAM != nullptr); - const DataPath featureArrayPath = featurePath.createChildPath("Feature Values"); - auto featureStore = DataStoreUtilities::CreateDataStore(ds, featureArrayPath, {2}, {1}); - REQUIRE(Int32Array::Create(ds, "Feature Values", featureStore, featureAM->getId()) != nullptr); - featureStore->setValue(0, 17); - featureStore->setValue(1, 29); - const DataPath ensemblePath = geomPath.createChildPath("Cell Ensemble Data"); - REQUIRE(AttributeMatrix::Create(ds, "Cell Ensemble Data", {1}, imageGeom.getId()) != nullptr); - const auto featureId = featureAM->getId(); - const auto featureArrayId = ds.getDataRefAs(featureArrayPath).getId(); - const auto ensembleId = ds.getDataRefAs(ensemblePath).getId(); - if(extraCellArray) + REQUIRE(AttributeMatrix::Create(ds, "Cell Feature Data", {2}, imageGeom.getId()) != nullptr); + const DataPath extraPath = inputPath.getParent().createChildPath(extraName.empty() ? "Extra" : extraName); + if(!extraName.empty()) { - const DataPath cellPath = inputPath.getParent(); - auto& cellAM = ds.getDataRefAs(cellPath); - auto extraStore = DataStoreUtilities::CreateDataStore(ds, cellPath.createChildPath("Extra"), cellAM.getShape(), {1}); - REQUIRE(Int16Array::Create(ds, "Extra", extraStore, cellAM.getId()) != nullptr); + auto& cellAM = ds.getDataRefAs(inputPath.getParent()); + auto store = DataStoreUtilities::CreateDataStore(ds, extraPath, cellAM.getShape(), {1}); + REQUIRE(Int16Array::Create(ds, extraName, store, cellAM.getId()) != nullptr); } - StandardDeviationProjectionImageFilter filter; Arguments args; args.insertOrAssign(StandardDeviationProjectionImageFilter::k_InputImageGeomPath_Key, std::make_any(geomPath)); args.insertOrAssign(StandardDeviationProjectionImageFilter::k_InputImageDataPath_Key, std::make_any(inputPath)); - args.insertOrAssign(StandardDeviationProjectionImageFilter::k_ProjectionDimension_Key, std::make_any(0)); - args.insertOrAssign(StandardDeviationProjectionImageFilter::k_RemoveOriginalGeometry_Key, std::make_any(inPlace)); - args.insertOrAssign(StandardDeviationProjectionImageFilter::k_OutputImageGeomName_Key, std::make_any("Projected Image")); + args.insertOrAssign(StandardDeviationProjectionImageFilter::k_RemoveOriginalGeometry_Key, std::make_any(true)); args.insertOrAssign(StandardDeviationProjectionImageFilter::k_OutputImageArrayName_Key, std::make_any("Output")); - if(copyOption >= 0) - { - args.insertOrAssign("copy_non_cell_attribute_matrices", std::make_any(copyNonCell)); - } const auto preflightResult = filter.preflight(ds, args); SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); std::string discardedWarning; @@ -323,92 +300,29 @@ TEST_CASE("ImageProcessing::StandardDeviationProjectionImageFilter: Copy non-cel discardedWarning += warning.message; } } - // Only discarded objects belong in the warning. Preserved matrices must not be listed. - if(inPlace) + // The geometry swap deletes the original children. The warning excludes the consumed input, + // but must name the feature matrix even when it is the only other discarded object, using full paths. + CHECK(discardedWarning.find(featurePath.toString()) != std::string::npos); + CHECK(discardedWarning.find(inputPath.toString()) == std::string::npos); + if(!extraName.empty()) { - CHECK((discardedWarning.find("Cell Feature Data") != std::string::npos) == !copyNonCell); - CHECK((discardedWarning.find("Cell Ensemble Data") != std::string::npos) == !copyNonCell); - CHECK(discardedWarning.empty() == (copyNonCell && !extraCellArray)); - if(extraCellArray) - { - CHECK(discardedWarning.find("Extra") != std::string::npos); - } + CHECK(discardedWarning.find(extraPath.toString()) != std::string::npos); } - else - { - CHECK(discardedWarning.empty()); - } - - // Axis projection dispatches by store type; it has no Direct/Scanline AlgorithmTestScope override. + // Axis projection dispatches by store type; it has no Direct/Scanline override. const auto executeResult = filter.execute(ds, args); SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); - const DataPath outputGeomPath = inPlace ? geomPath : DataPath({"Projected Image"}); - REQUIRE(ds.getDataRefAs(outputGeomPath).getDimensions() == SizeVec3{1, 3, 3}); - const auto& output = ds.getDataRefAs(outputGeomPath.createChildPath("CellData").createChildPath("Output")); - REQUIRE(output.getNumberOfTuples() == 9); - for(usize slot = 0; slot < 9; ++slot) - { - // Along X, each ramp column is {a, a+1, a+2}. Sample variance = (1+0+1)/(3-1) = 1. - REQUIRE(output[slot] == Approx(1.0).margin(1.0e-12)); - } - if(copyNonCell) - { - const DataPath outputFeaturePath = outputGeomPath.createChildPath("Cell Feature Data"); - const auto* outputFeatureAM = ds.getDataAs(outputFeaturePath); - REQUIRE(outputFeatureAM != nullptr); - CHECK(outputFeatureAM->getShape() == ShapeType{2}); - auto& features = ds.getDataRefAs(outputFeaturePath.createChildPath("Feature Values")); - CHECK(features[0] == 17); - CHECK(features[1] == 29); - const auto* ensemble = ds.getDataAs(outputGeomPath.createChildPath("Cell Ensemble Data")); - REQUIRE(ensemble != nullptr); - CHECK(ensemble->getShape() == ShapeType{1}); - CHECK(ensemble->getSize() == 0); - if(inPlace) - { - CHECK(outputFeatureAM->getId() == featureId); - CHECK(features.getId() == featureArrayId); - CHECK(features.getDataStore() == featureStore.get()); - CHECK(ensemble->getId() == ensembleId); - } - else - { - CHECK(outputFeatureAM->getId() != featureId); - CHECK(features.getId() != featureArrayId); - CHECK(features.getDataStore() != featureStore.get()); - CHECK(ensemble->getId() != ensembleId); - features[0] = 101; - CHECK(ds.getDataRefAs(featureArrayPath)[0] == 17); - featureStore->setValue(1, 103); - CHECK(features[1] == 29); - featureStore->setValue(1, 29); - } - } - else + CHECK(ds.getData(featurePath) == nullptr); + if(extraName != "Output") { - CHECK(ds.getData(outputGeomPath.createChildPath("Cell Feature Data")) == nullptr); - CHECK(ds.getData(outputGeomPath.createChildPath("Cell Ensemble Data")) == nullptr); + CHECK(ds.getData(extraPath) == nullptr); } - if(!inPlace) + REQUIRE(ds.getDataRefAs(geomPath).getDimensions() == SizeVec3{1, 3, 3}); + const auto& output = ds.getDataRefAs(inputPath.getParent().createChildPath("Output")); + REQUIRE(output.getNumberOfTuples() == 9); + for(usize slot = 0; slot < 9; ++slot) { - const auto& features = ds.getDataRefAs(featureArrayPath); - CHECK(features[0] == 17); - CHECK(features[1] == 29); - CHECK(ds.getDataRefAs(featurePath).getId() == featureId); - CHECK(ds.getDataRefAs(ensemblePath).getId() == ensembleId); - CHECK(ds.getDataRefAs(geomPath).getDimensions() == SizeVec3{3, 3, 3}); + // X columns are {3*s, 3*s+1, 3*s+2}: sample variance = (1+0+1)/(3-1) = 1. + CHECK(output[slot] == Approx(1.0).margin(1.0e-12)); } UnitTest::CheckArraysInheritTupleDims(ds); } - -TEST_CASE("ImageProcessing::StandardDeviationProjectionImageFilter: Older pipelines default to discarding non-cell matrices", "[ImageProcessing][StandardDeviationProjectionImageFilter]") -{ - StandardDeviationProjectionImageFilter filter; - auto json = filter.toJson(filter.getDefaultArguments()); - json.erase("copy_non_cell_attribute_matrices"); - json["parameters_version"] = 1; - const auto converted = filter.fromJson(json); - SIMPLNX_RESULT_REQUIRE_VALID(converted); - REQUIRE(converted.value().contains("copy_non_cell_attribute_matrices")); - CHECK_FALSE(converted.value().value("copy_non_cell_attribute_matrices")); -} diff --git a/src/simplnx/Utilities/ImageProcessing/ImageProcessingFilterUtilities.hpp b/src/simplnx/Utilities/ImageProcessing/ImageProcessingFilterUtilities.hpp index 802a870caa..ba7bf4ea64 100644 --- a/src/simplnx/Utilities/ImageProcessing/ImageProcessingFilterUtilities.hpp +++ b/src/simplnx/Utilities/ImageProcessing/ImageProcessingFilterUtilities.hpp @@ -7,14 +7,11 @@ #include "simplnx/DataStructure/DataStructure.hpp" #include "simplnx/DataStructure/Geometry/ImageGeom.hpp" #include "simplnx/DataStructure/IDataArray.hpp" -#include "simplnx/Filter/Actions/CopyDataObjectAction.hpp" #include "simplnx/Filter/Actions/CreateArrayAction.hpp" #include "simplnx/Filter/Actions/CreateImageGeometryAction.hpp" #include "simplnx/Filter/Actions/DeleteDataAction.hpp" -#include "simplnx/Filter/Actions/MoveDataAction.hpp" #include "simplnx/Filter/Actions/RenameDataAction.hpp" #include "simplnx/Filter/Output.hpp" -#include "simplnx/Utilities/DataGroupUtilities.hpp" #include "simplnx/Utilities/ImageProcessing/ImageProcessingConstants.hpp" #include "simplnx/Utilities/MemoryUtilities.hpp" @@ -668,10 +665,8 @@ Result PreflightFullOverwriteImageFilter(const DataStructure& dat * is impossible because the collapsed output array cannot be inserted into the still-full cell * AttributeMatrix (tuple-count mismatch), and resizing the AttributeMatrix before executeImpl * would destroy the input the engine still has to read. Because that swap replaces the whole - * original geometry, any OTHER arrays in its cell data and unpreserved geometry children are + * original geometry, any OTHER arrays in its cell data and other geometry children are * discarded; a warning enumerates them. - * - copyNonCellAttributeMatrices == true: non-cell Attribute Matrices are moved before the deferred - * in-place swap (no array copies), or deep-copied into the new geometry in non-in-place mode. * * The output element type is the input type mapped through @p OutTypeMap (SameAsInput for type-preserving * reducers like Max; a fixed float map for Mean/StdDev/Sum). The execute façade MUST be instantiated with @@ -682,7 +677,7 @@ Result PreflightFullOverwriteImageFilter(const DataStructure& dat */ template class OutTypeMap = SameAsInput> Result PreflightAxisProjection(const DataStructure& dataStructure, const DataPath& imageGeomPath, const DataPath& inputArrayPath, usize projDim, bool performInPlace, - const std::string& outputGeomName, const std::string& outputArrayName, bool copyNonCellAttributeMatrices = false) + const std::string& outputGeomName, const std::string& outputArrayName) { if(projDim > 2) { @@ -751,38 +746,6 @@ Result PreflightAxisProjection(const DataStructure& dataStructure result.value().appendAction(std::make_unique(outputDataType, tupleShape, std::vector{1}, outputArrayPath, inputArray.getDataFormat(), "", std::nullopt, DataStoreInitializationMode::DeferredZeroFill)); - if(copyNonCellAttributeMatrices) - { - for(const auto& [childId, childObject] : imageGeom) - { - if(childId == cellData->getId() || dynamic_cast(childObject.get()) == nullptr) - { - continue; - } - const DataPath sourcePath = imageGeomPath.createChildPath(childObject->getName()); - if(performInPlace) - { - // Preserve the original objects and stores after projection, before deleting their old geometry. - result.value().appendDeferredAction(std::make_unique(sourcePath, targetGeomPath)); - } - else - { - const DataPath destinationPath = targetGeomPath.createChildPath(childObject->getName()); - std::vector allCreatedPaths = {destinationPath}; - const auto childPaths = GetAllChildDataPathsRecursive(dataStructure, sourcePath); - if(childPaths.has_value()) - { - for(const auto& childPath : childPaths.value()) - { - allCreatedPaths.push_back(childPath.rebase(sourcePath, destinationPath).value()); - } - } - // Data-store deep copies use bounded transfers and respect the destination storage policy. - result.value().appendAction(std::make_unique(sourcePath, destinationPath, allCreatedPaths)); - } - } - } - if(performInPlace) { // Deferred (post-executeImpl) swap: rename the original geometry away, delete it, then rename the @@ -795,15 +758,15 @@ Result PreflightAxisProjection(const DataStructure& dataStructure result.value().appendDeferredAction(std::make_unique(renamedOriginalPath)); result.value().appendDeferredAction(std::make_unique(targetGeomPath, originalName)); - // In-place discards the original geometry. List unpreserved children as well as other cell-data - // arrays. Non-cell Attribute Matrices can be moved above. The selected input is consumed by the - // projection and the output name is replaced, so neither is listed. + // In-place discards the original geometry. List its other children and cell-data arrays. The selected + // input is consumed by the projection, so it is not listed. The output array is created in the new + // geometry, so an old cell-data array with the output name is discarded and listed. const std::string inputArrayName = inputArrayPath.getTargetName(); std::string discarded; for(const auto& [childId, childObject] : *cellData) { const std::string childName = childObject->getName(); - if(childName == inputArrayName || childName == outputArrayName) + if(childName == inputArrayName) { continue; } @@ -815,7 +778,7 @@ Result PreflightAxisProjection(const DataStructure& dataStructure } for(const auto& [childId, childObject] : imageGeom) { - if(childId == cellData->getId() || (copyNonCellAttributeMatrices && dynamic_cast(childObject.get()) != nullptr)) + if(childId == cellData->getId() || childId == inputArray.getId()) { continue; } diff --git a/wrapping/python/examples/pipelines/NXImageProcessing/14_Projection-Based_Quality_Summaries.py b/wrapping/python/examples/pipelines/NXImageProcessing/14_Projection-Based_Quality_Summaries.py index 06e0601981..d447dad9d4 100644 --- a/wrapping/python/examples/pipelines/NXImageProcessing/14_Projection-Based_Quality_Summaries.py +++ b/wrapping/python/examples/pipelines/NXImageProcessing/14_Projection-Based_Quality_Summaries.py @@ -59,7 +59,6 @@ output_array_name='Pore Occupancy', output_image_geometry_name='Binary Pore Projection', projection_dimension=2, - copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.BinaryProjectionImageFilter, result) @@ -72,7 +71,6 @@ output_array_name='Maximum Intensity', output_image_geometry_name='Maximum XCT Projection', projection_dimension=2, - copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.MaximumProjectionImageFilter, result) @@ -85,7 +83,6 @@ output_array_name='Mean Intensity', output_image_geometry_name='Mean XCT Projection', projection_dimension=2, - copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.MeanProjectionImageFilter, result) @@ -98,7 +95,6 @@ output_array_name='Median Intensity', output_image_geometry_name='Median XCT Projection', projection_dimension=2, - copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.MedianProjectionImageFilter, result) @@ -111,7 +107,6 @@ output_array_name='Minimum Intensity', output_image_geometry_name='Minimum XCT Projection', projection_dimension=2, - copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.MinimumProjectionImageFilter, result) @@ -124,7 +119,6 @@ output_array_name='Intensity Deviation', output_image_geometry_name='Deviation XCT Projection', projection_dimension=2, - copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.StandardDeviationProjectionImageFilter, result) @@ -137,7 +131,6 @@ output_array_name='Integrated Intensity', output_image_geometry_name='Sum XCT Projection', projection_dimension=2, - copy_non_cell_attribute_matrices=False, remove_original_geometry=False, ) simplnx_utilities.check_filter_result(nximgproc.SumProjectionImageFilter, result) From 5ebb9517537c50be6305ffaf74d76f372724ecf2 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 4 Nov 2026 17:54:03 -0500 Subject: [PATCH 21/33] REV: AlignSectionsList - Ignore row 0 of the shift file again Review of #1915: commit 035079b35 also made Align Sections (List) apply row 0, so a Feature Centroid result could be replayed. That went beyond the L04 defect, changed the output of saved pipelines with a nonzero first row, and exposed a separate defect: with a fixed reference slice, Feature Centroid writes reference offsets into the Relative Shifts array (#1908 item L77). Withdraw that part. The Align Sections (List) source, docs and tests are identical to develop again, and Align_Sections_User_Input gives its develop output. List leaves row 0 at 0, so the shared transfer still skips it. The Feature Centroid fix for the top slice stays. Fixes #1908 item L04 Signed-off-by: Michael Jackson --- .../docs/AlignSectionsListFilter.md | 6 +-- .../Filters/Algorithms/AlignSectionsList.cpp | 8 +-- .../test/AlignSectionsListTest.cpp | 50 ------------------- 3 files changed, 6 insertions(+), 58 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/AlignSectionsListFilter.md b/src/Plugins/SimplnxCore/docs/AlignSectionsListFilter.md index 90c5c0f5d4..61abab9ac6 100644 --- a/src/Plugins/SimplnxCore/docs/AlignSectionsListFilter.md +++ b/src/Plugins/SimplnxCore/docs/AlignSectionsListFilter.md @@ -20,18 +20,16 @@ All shift values are in **cell (voxel) units**, not physical units. A shift of 3 The input shifts can be provided in either format: -- **Relative [0]**: Each shift describes the offset of section N relative to section N-1. Row 0 supplies the initial offset of the highest-Z section. The filter adds each later relative shift to the previous cumulative shift. +- **Relative [0]**: Each shift describes the offset of section N relative to section N-1. The filter internally converts these to cumulative shifts before applying them. - **Cumulative [1]**: Each shift describes the absolute offset of section N from a fixed reference point. -A nonzero row 0 now shifts the highest-Z section. Earlier versions ignored this row. - ### Preparing Shift Data from a File If your shifts are stored in an external file, you need to import them into a DataArray before using this filter: **Requirements:** - The number of shift entries must equal the number of slices (Z dimension of the geometry) -- Slices must be ordered from highest Z to lowest Z. Row 0 applies to the highest-Z section, including a nonzero shift +- Slices must be ordered from bottom to top **Recommended file format** (space-delimited, two values per line): diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsList.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsList.cpp index 8255269e34..f696cd9320 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsList.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsList.cpp @@ -46,10 +46,10 @@ Result<> AlignSectionsList::findShifts(std::vector& xShifts, std::vector< // Size validated in preflight const auto& relativeShiftsStore = m_DataStructure.getDataAs(m_InputValues->ShiftsArrayPath)->getDataStoreRef(); const usize numTup = relativeShiftsStore.getNumberOfTuples(); - for(usize i = 0; i < numTup; i++) + for(usize i = 1; i < numTup; i++) { - xShifts[i] = (i == 0 ? 0 : xShifts[i - 1]) + relativeShiftsStore[i * 2]; - yShifts[i] = (i == 0 ? 0 : yShifts[i - 1]) + relativeShiftsStore[(i * 2) + 1]; + xShifts[i] = xShifts[i - 1] + relativeShiftsStore[i * 2]; + yShifts[i] = yShifts[i - 1] + relativeShiftsStore[(i * 2) + 1]; } } else if(alignSectionsType == static_cast(to_underlying(AlignSectionsInputType::CumulativeShifts))) @@ -57,7 +57,7 @@ Result<> AlignSectionsList::findShifts(std::vector& xShifts, std::vector< // Size validated in preflight const auto& cumulativeShiftsStore = m_DataStructure.getDataAs(m_InputValues->ShiftsArrayPath)->getDataStoreRef(); const usize numTup = cumulativeShiftsStore.getNumberOfTuples(); - for(usize i = 0; i < numTup; i++) + for(usize i = 1; i < numTup; i++) { xShifts[i] = cumulativeShiftsStore[i * 2]; yShifts[i] = cumulativeShiftsStore[(i * 2) + 1]; diff --git a/src/Plugins/SimplnxCore/test/AlignSectionsListTest.cpp b/src/Plugins/SimplnxCore/test/AlignSectionsListTest.cpp index 781e90bada..13effc8eb6 100644 --- a/src/Plugins/SimplnxCore/test/AlignSectionsListTest.cpp +++ b/src/Plugins/SimplnxCore/test/AlignSectionsListTest.cpp @@ -11,7 +11,6 @@ #include -#include #include #include @@ -186,52 +185,3 @@ TEST_CASE("SimplnxCore::AlignSectionsListFilter: Cumulative Shifts execution", " UnitTest::CheckArraysInheritTupleDims(dataStructure, SmallIn100::k_TupleCheckIgnoredPaths); } - -TEST_CASE("SimplnxCore::AlignSectionsListFilter: Nonzero top row", "[SimplnxCore][AlignSectionsListFilter]") -{ - UnitTest::LoadPlugins(); - const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); - const auto inputType = GENERATE(0ULL, 1ULL); - const int64 sign = GENERATE(-1, 1); - CAPTURE(scenario, inputType, sign); - UnitTest::AlgorithmTestScope scope(scenario); - DataStructure dataStructure; - auto* geom = ImageGeom::Create(dataStructure, "Image"); - REQUIRE(geom != nullptr); - geom->setDimensions({3, 3, 4}); - auto* cells = AttributeMatrix::Create(dataStructure, "Cells", ShapeType{4, 3, 3}, geom->getId()); - REQUIRE(cells != nullptr); - geom->setCellData(*cells); - auto* mask = UInt8Array::Create(dataStructure, "Mask", std::make_shared>(ShapeType{4, 3, 3}, ShapeType{1}, 0), cells->getId()); - REQUIRE(mask != nullptr); - auto* shifts = Int64Array::Create(dataStructure, "Shifts", std::make_shared>(ShapeType{4}, ShapeType{2}, 0)); - REQUIRE(shifts != nullptr); - // Descending cumulative offsets are sign * {1,0,-1,0} on both axes. - // Relative offsets are their differences, with row 0 as the initial offset. - // Each source mark is at (1 + offset, 1 + offset), so all outputs must be (1,1). - const std::array cumulative = {1, 0, -1, 0}; - const std::array relative = {1, -1, -1, 1}; - for(usize row = 0; row < 4; row++) - { - const usize coordinate = static_cast(1 + (sign * cumulative[row])); - (*mask)[((3 - row) * 9) + (coordinate * 3) + coordinate] = 1; - (*shifts)[row * 2] = sign * (inputType == 0 ? relative[row] : cumulative[row]); - (*shifts)[(row * 2) + 1] = (*shifts)[row * 2]; - } - AlignSectionsListFilter filter; - Arguments args; - args.insertOrAssign(AlignSectionsListFilter::k_InputArrayType_Key, std::make_any(inputType)); - args.insertOrAssign(AlignSectionsListFilter::k_SelectedImageGeometryPath_Key, std::make_any(DataPath({"Image"}))); - args.insertOrAssign(AlignSectionsListFilter::k_ShiftsArrayPath_Key, std::make_any(DataPath({"Shifts"}))); - auto result = scope.executeFilter(filter, dataStructure, args); - SIMPLNX_RESULT_REQUIRE_VALID(result.result); - for(usize z = 0; z < 4; z++) - { - for(usize xy = 0; xy < 9; xy++) - { - CAPTURE(z, xy); - CHECK((*mask)[(z * 9) + xy] == (xy == 4 ? 1 : 0)); - } - } - UnitTest::CheckArraysInheritTupleDims(dataStructure); -} From 17c76ac9164b1cfb731528e9fcb1fa2e5f1c4d83 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 4 Nov 2026 18:01:56 -0500 Subject: [PATCH 22/33] REV: AlignSectionsFeatureCentroid - Give an empty slice a zero shift Review of #1915: a slice with no mask voxels has a NaN centroid, and converting a NaN shift to int64 is undefined behavior. Commit 035079b35 made the top slice reach this conversion when Use Reference Slice is on with a reference slice other than 0; other slices already did on develop. A shift is now computed only when both centroids it uses are finite. Otherwise the relative shift is 0, so in consecutive mode the slice keeps the cumulative shift of the previous slice. This applies to all in-core and out-of-core loops, with and without the diagnostic arrays. The NaN info messages now include the slice number. Add tests with an empty top slice (reference slice 1) and an empty middle slice (consecutive mode), with hand-calculated shifts, for the in-core and out-of-core paths with Store Alignment Shifts on and off. UBSan reports the undefined conversion before the fix. Fixes #1908 item L04 Signed-off-by: Michael Jackson --- .../AlignSectionsFeatureCentroidFilter.md | 2 + .../AlignSectionsFeatureCentroid.cpp | 54 ++++++----- .../test/AlignSectionsFeatureCentroidTest.cpp | 90 +++++++++++++++++++ 3 files changed, 126 insertions(+), 20 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/AlignSectionsFeatureCentroidFilter.md b/src/Plugins/SimplnxCore/docs/AlignSectionsFeatureCentroidFilter.md index 2ac6fd15eb..faed33999a 100644 --- a/src/Plugins/SimplnxCore/docs/AlignSectionsFeatureCentroidFilter.md +++ b/src/Plugins/SimplnxCore/docs/AlignSectionsFeatureCentroidFilter.md @@ -26,6 +26,8 @@ If *Use Reference Slice* is enabled, each section is shifted to align with a sin The highest-Z section is also shifted when the reference slice is not 0. This corrects DREAM3D 6.5.171 behavior, which left that section unchanged. +An empty mask section has no finite centroid. If either centroid used for a shift is not finite, the relative shift is zero. In consecutive mode, the cumulative shift stays equal to the previous section's shift. In reference mode, the section stays unchanged. This defines behavior that was undefined in DREAM3D 6.5.171. + ## Algorithm The algorithm proceeds in two phases: diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsFeatureCentroid.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsFeatureCentroid.cpp index 18dab31ca9..d016d5ac7a 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsFeatureCentroid.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/AlignSectionsFeatureCentroid.cpp @@ -1,4 +1,5 @@ #include +#include #include "AlignSectionsFeatureCentroid.hpp" @@ -11,6 +12,19 @@ using namespace nx::core; +namespace +{ +int64 ComputeCentroidShift(float32 centroid, float32 referenceCentroid, float32 spacing) +{ + // Empty mask slices have NaN centroids and contribute no relative shift. + if(!std::isfinite(centroid) || !std::isfinite(referenceCentroid)) + { + return 0; + } + return static_cast((centroid - referenceCentroid) / spacing); +} +} // namespace + AlignSectionsFeatureCentroid::AlignSectionsFeatureCentroid(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, AlignSectionsFeatureCentroidInputValues* inputValues) : AlignSections(dataStructure, shouldCancel, mesgHandler) @@ -133,16 +147,16 @@ Result<> AlignSectionsFeatureCentroid::findShifts(std::vector& xShifts, s if(m_InputValues->UseReferenceSlice) { // Reference-relative and cumulative shifts are identical in this mode. - relativexshift = static_cast((xCentroid[iter] - xCentroid[static_cast(m_InputValues->ReferenceSlice)]) / spacing[0]); - relativeyshift = static_cast((yCentroid[iter] - yCentroid[static_cast(m_InputValues->ReferenceSlice)]) / spacing[1]); + relativexshift = ComputeCentroidShift(xCentroid[iter], xCentroid[static_cast(m_InputValues->ReferenceSlice)], spacing[0]); + relativeyshift = ComputeCentroidShift(yCentroid[iter], yCentroid[static_cast(m_InputValues->ReferenceSlice)], spacing[1]); xShifts[iter] = relativexshift; yShifts[iter] = relativeyshift; } else { // Accumulate consecutive-slice offsets. - relativexshift = static_cast((xCentroid[iter] - xCentroid[iter - 1]) / spacing[0]); - relativeyshift = static_cast((yCentroid[iter] - yCentroid[iter - 1]) / spacing[1]); + relativexshift = ComputeCentroidShift(xCentroid[iter], xCentroid[iter - 1], spacing[0]); + relativeyshift = ComputeCentroidShift(yCentroid[iter], yCentroid[iter - 1], spacing[1]); xShifts[iter] = xShifts[iter - 1] + relativexshift; yShifts[iter] = yShifts[iter - 1] + relativeyshift; } @@ -165,13 +179,13 @@ Result<> AlignSectionsFeatureCentroid::findShifts(std::vector& xShifts, s } if(std::isnan(xCentroid[iter]) && !xWarning) { - std::string message = fmt::format("The X Centroid was NaN. All subsequent slices are probably wrong. Slice=", iter); + std::string message = fmt::format("The X Centroid was NaN. All subsequent slices are probably wrong. Slice={}", iter); m_MessageHandler.sendInfoMessage(message); xWarning = true; } if(std::isnan(yCentroid[iter]) && !yWarning) { - std::string message = fmt::format("The Y Centroid was NaN. All subsequent slices are probably wrong. Slice=", iter); + std::string message = fmt::format("The Y Centroid was NaN. All subsequent slices are probably wrong. Slice={}", iter); m_MessageHandler.sendInfoMessage(message); yWarning = true; } @@ -195,13 +209,13 @@ Result<> AlignSectionsFeatureCentroid::findShifts(std::vector& xShifts, s { if(m_InputValues->UseReferenceSlice) { - xShifts[iter] = static_cast((xCentroid[iter] - xCentroid[static_cast(m_InputValues->ReferenceSlice)]) / spacing[0]); - yShifts[iter] = static_cast((yCentroid[iter] - yCentroid[static_cast(m_InputValues->ReferenceSlice)]) / spacing[1]); + xShifts[iter] = ComputeCentroidShift(xCentroid[iter], xCentroid[static_cast(m_InputValues->ReferenceSlice)], spacing[0]); + yShifts[iter] = ComputeCentroidShift(yCentroid[iter], yCentroid[static_cast(m_InputValues->ReferenceSlice)], spacing[1]); } else { - xShifts[iter] = xShifts[iter - 1] + static_cast((xCentroid[iter] - xCentroid[iter - 1]) / spacing[0]); - yShifts[iter] = yShifts[iter - 1] + static_cast((yCentroid[iter] - yCentroid[iter - 1]) / spacing[1]); + xShifts[iter] = xShifts[iter - 1] + ComputeCentroidShift(xCentroid[iter], xCentroid[iter - 1], spacing[0]); + yShifts[iter] = yShifts[iter - 1] + ComputeCentroidShift(yCentroid[iter], yCentroid[iter - 1], spacing[1]); } if((xShifts[iter] < -sdims[0] || xShifts[iter] > sdims[0]) && !xWarning) @@ -222,13 +236,13 @@ Result<> AlignSectionsFeatureCentroid::findShifts(std::vector& xShifts, s } if(std::isnan(xCentroid[iter]) && !xWarning) { - std::string message = fmt::format("The X Centroid was NaN. All subsequent slices are probably wrong. Slice=", iter); + std::string message = fmt::format("The X Centroid was NaN. All subsequent slices are probably wrong. Slice={}", iter); m_MessageHandler.sendInfoMessage(message); xWarning = true; } if(std::isnan(yCentroid[iter]) && !yWarning) { - std::string message = fmt::format("The Y Centroid was NaN. All subsequent slices are probably wrong. Slice=", iter); + std::string message = fmt::format("The Y Centroid was NaN. All subsequent slices are probably wrong. Slice={}", iter); m_MessageHandler.sendInfoMessage(message); yWarning = true; } @@ -336,13 +350,13 @@ Result<> AlignSectionsFeatureCentroid::findShiftsOoc(std::vector& xShifts { if(m_InputValues->UseReferenceSlice) { - xShifts[iter] = static_cast((xCentroid[iter] - xCentroid[static_cast(m_InputValues->ReferenceSlice)]) / spacing[0]); - yShifts[iter] = static_cast((yCentroid[iter] - yCentroid[static_cast(m_InputValues->ReferenceSlice)]) / spacing[1]); + xShifts[iter] = ComputeCentroidShift(xCentroid[iter], xCentroid[static_cast(m_InputValues->ReferenceSlice)], spacing[0]); + yShifts[iter] = ComputeCentroidShift(yCentroid[iter], yCentroid[static_cast(m_InputValues->ReferenceSlice)], spacing[1]); } else { - xShifts[iter] = xShifts[iter - 1] + static_cast((xCentroid[iter] - xCentroid[iter - 1]) / spacing[0]); - yShifts[iter] = yShifts[iter - 1] + static_cast((yCentroid[iter] - yCentroid[iter - 1]) / spacing[1]); + xShifts[iter] = xShifts[iter - 1] + ComputeCentroidShift(xCentroid[iter], xCentroid[iter - 1], spacing[0]); + yShifts[iter] = yShifts[iter - 1] + ComputeCentroidShift(yCentroid[iter], yCentroid[iter - 1], spacing[1]); } if((xShifts[iter] < -sdims[0] || xShifts[iter] > sdims[0]) && !xWarning) @@ -361,12 +375,12 @@ Result<> AlignSectionsFeatureCentroid::findShiftsOoc(std::vector& xShifts } if(std::isnan(xCentroid[iter]) && !xWarning) { - m_MessageHandler.sendMessage(nx::core::IFilter::Message::Type::Info, fmt::format("The X Centroid was NaN. All subsequent slices are probably wrong. Slice=", iter)); + m_MessageHandler.sendMessage(nx::core::IFilter::Message::Type::Info, fmt::format("The X Centroid was NaN. All subsequent slices are probably wrong. Slice={}", iter)); xWarning = true; } if(std::isnan(yCentroid[iter]) && !yWarning) { - m_MessageHandler.sendMessage(nx::core::IFilter::Message::Type::Info, fmt::format("The Y Centroid was NaN. All subsequent slices are probably wrong. Slice=", iter)); + m_MessageHandler.sendMessage(nx::core::IFilter::Message::Type::Info, fmt::format("The Y Centroid was NaN. All subsequent slices are probably wrong. Slice={}", iter)); yWarning = true; } } @@ -391,8 +405,8 @@ Result<> AlignSectionsFeatureCentroid::findShiftsOoc(std::vector& xShifts } else { - relativexshift = static_cast((xCentroid[iter] - xCentroid[iter - 1]) / spacing[0]); - relativeyshift = static_cast((yCentroid[iter] - yCentroid[iter - 1]) / spacing[1]); + relativexshift = ComputeCentroidShift(xCentroid[iter], xCentroid[iter - 1], spacing[0]); + relativeyshift = ComputeCentroidShift(yCentroid[iter], yCentroid[iter - 1], spacing[1]); } usize xIndex = iter * 2; diff --git a/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp b/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp index a7e5b3013d..cc17a76f37 100644 --- a/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp +++ b/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp @@ -252,3 +252,93 @@ TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Nonzero reference to } UnitTest::CheckArraysInheritTupleDims(dataStructure); } + +TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Empty slices", "[Reconstruction][AlignSectionsFeatureCentroidFilter]") +{ + UnitTest::LoadPlugins(); + const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); + const bool storeShifts = GENERATE(false, true); + const int emptyCase = GENERATE(0, 1, 2); // Empty top, middle, or fixed reference. + const bool useReference = emptyCase != 1; + CAPTURE(scenario, storeShifts, emptyCase); + UnitTest::AlgorithmTestScope scope(scenario); + using FilterType = AlignSectionsFeatureCentroidFilter; + DataStructure dataStructure; + auto* geom = ImageGeom::Create(dataStructure, "Image"); + REQUIRE(geom != nullptr); + geom->setDimensions({3, 3, 4}); + geom->setSpacing({1.0F, 1.0F, 1.0F}); + auto* cells = AttributeMatrix::Create(dataStructure, "Cells", ShapeType{4, 3, 3}, geom->getId()); + REQUIRE(cells != nullptr); + geom->setCellData(*cells); + auto* mask = UInt8Array::Create(dataStructure, "Mask", std::make_shared>(ShapeType{4, 3, 3}, ShapeType{1}, 0), cells->getId()); + REQUIRE(mask != nullptr); + mask->fill(0); + // Descending-Z centroids are (2,2), (1,1), (0,0), (1,1) before removing a mark. + // Empty top with reference 1: offsets [0,0,-1,0]. Empty reference: all offsets 0. + // Empty middle (index 2), consecutive: relative [0,-1,0,0], cumulative [0,-1,-1,-1]. + // Both axes have the same values. A zero relative shift preserves the previous cumulative shift. + std::array expectedShifts = emptyCase == 0 ? std::array{0, 0, -1, 0} : emptyCase == 1 ? std::array{0, -1, -1, -1} : std::array{0, 0, 0, 0}; + std::array expectedRelative = emptyCase == 1 ? std::array{0, -1, 0, 0} : expectedShifts; + const usize emptyZ = emptyCase == 0 ? 3 : emptyCase == 1 ? 1 : 2; + const std::array markXY = {4, 0, 4, 8}; + for(usize z = 0; z < 4; z++) + { + if(z != emptyZ) + { + (*mask)[z * 9 + markXY[z]] = 1; + } + } + // A separate marker makes the empty slice's applied shift observable without diagnostics. + auto* values = Int32Array::Create(dataStructure, "Values", std::make_shared>(ShapeType{4, 3, 3}, ShapeType{1}, 0), cells->getId()); + REQUIRE(values != nullptr); + values->fill(0); + for(usize z = 0; z < 4; z++) + { + (*values)[z * 9 + 4] = 7; + } + + FilterType filter; + Arguments args; + args.insertOrAssign(FilterType::k_SelectedImageGeometryPath_Key, std::make_any(DataPath({"Image"}))); + args.insertOrAssign(FilterType::k_MaskArrayPath_Key, std::make_any(DataPath({"Image", "Cells", "Mask"}))); + args.insertOrAssign(FilterType::k_UseReferenceSlice_Key, std::make_any(useReference)); + args.insertOrAssign(FilterType::k_ReferenceSlice_Key, std::make_any(1)); + args.insertOrAssign(FilterType::k_StoreAlignmentShifts_Key, std::make_any(storeShifts)); + args.insertOrAssign(FilterType::k_AlignmentAMName_Key, std::make_any("Shifts")); + args.insertOrAssign(FilterType::k_CumulativeShiftsArrayName_Key, std::make_any("Cumulative")); + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + auto result = scope.executeFilter(filter, dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + for(usize z = 0; z < 4; z++) + { + const int64 shift = expectedShifts[3 - z]; + for(usize xy = 0; xy < 9; xy++) + { + CAPTURE(z, xy); + const int64 sourceX = static_cast(xy % 3) + shift; + const int64 sourceY = static_cast(xy / 3) + shift; + CHECK((*values)[z * 9 + xy] == (sourceX == 1 && sourceY == 1 ? 7 : 0)); + } + } + if(storeShifts) + { + const DataPath shiftsPath({"Image", "Shifts", "Cumulative"}); + const DataPath relativePath({"Image", "Shifts", "Relative Shifts"}); + REQUIRE_NOTHROW(dataStructure.getDataRefAs(shiftsPath)); + REQUIRE_NOTHROW(dataStructure.getDataRefAs(relativePath)); + const auto& shifts = dataStructure.getDataRefAs(shiftsPath); + const auto& relative = dataStructure.getDataRefAs(relativePath); + for(usize iter = 0; iter < 4; iter++) + { + CAPTURE(iter); + for(usize axis = 0; axis < 2; axis++) + { + CHECK(shifts[iter * 2 + axis] == expectedShifts[iter]); + CHECK(relative[iter * 2 + axis] == expectedRelative[iter]); + } + } + } + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} From a9cae87770f2249f428723e6f22f02a408be9a9d Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Wed, 4 Nov 2026 17:33:49 -0500 Subject: [PATCH 23/33] REV: ReadImageStack - Check the slice data type where the slice is read Review of #1915: the earlier fix ran Read Image preflight for every slice at the start of execute and trusted the type of its first CreateArrayAction. That added header reads and did not protect the typed access if a file changed between the check and the read. Remove the pre-scan. The algorithm now compares the decoded slice's data type with the stack type right after Read Image returns, before resampling, grayscale conversion, flips, the typed access and the copy, and returns -23534 with the slice number, file name and both types. Preflight still opens only file 0. Slices before the bad one may already be written; the documentation says so, and the test no longer requires an untouched output after the error. Fixes #1908 item L62 Signed-off-by: Michael Jackson --- .../docs/ReadImageStackFilter.md | 2 +- .../Filters/Algorithms/ReadImageStack.cpp | 9 +++- .../Filters/ReadImageStackFilter.cpp | 49 ------------------- .../test/ReadImageStackTest.cpp | 24 +-------- 4 files changed, 10 insertions(+), 74 deletions(-) diff --git a/src/Plugins/NXImageProcessing/docs/ReadImageStackFilter.md b/src/Plugins/NXImageProcessing/docs/ReadImageStackFilter.md index b8007f7c9e..96018b79d6 100644 --- a/src/Plugins/NXImageProcessing/docs/ReadImageStackFilter.md +++ b/src/Plugins/NXImageProcessing/docs/ReadImageStackFilter.md @@ -78,7 +78,7 @@ The *Output Data Type* parameter provides the following choices: - **uint16 [1]**: Convert image data to 16-bit unsigned integer. - **uint32 [2]**: Convert image data to 32-bit unsigned integer. -Preflight reads only the first file's image header. At the start of execution, the filter checks the data type of each slice kept by the Z crop. When *Set Image Data Type* is off, the first file in the list sets the stack's output type, also when the Z crop removes that file. If a slice cannot match the stack's output type, error `-23534` names the file and the expected and actual types. No slice pixels are written on this error. Mixed uint8 and uint16 slices can be read together when *Set Image Data Type* converts them to the same output type. This intentionally differs from the failure described in DREAM3D 6.5.171 errata KI-051. +Preflight reads only the first file's image header. During execution, the filter checks each decoded slice kept by the Z crop before further processing or copying it into the stack. When *Set Image Data Type* is off, the first file in the list sets the stack's output type, also when the Z crop removes that file. If a slice cannot match the stack's output type, error `-23534` names the file and the expected and actual types. Earlier slices may already have been written when this error occurs. Mixed uint8 and uint16 slices can be read together when *Set Image Data Type* converts them to the same output type. This intentionally differs from the failure described in DREAM3D 6.5.171 errata KI-051. ### Cropping Caveats diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/Algorithms/ReadImageStack.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/Algorithms/ReadImageStack.cpp index a463278154..c2a1affa2c 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/Algorithms/ReadImageStack.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/Algorithms/ReadImageStack.cpp @@ -298,6 +298,13 @@ Result<> ReadImageStackImpl(DataStructure& dataStructure, const ReadImageStackIn } } + DataPath srcImageDataPath = imageGeomPath.createChildPath(cellDataName).createChildPath(imageArrayName); + const DataType sliceType = importedDataStructure.getDataRefAs(srcImageDataPath).getDataType(); + if(sliceType != GetDataType()) + { + return MakeErrorResult(-23534, fmt::format("Slice {} ('{}') has data type {}, but the stack requires {}.", i, filePath, DataTypeToString(sliceType), DataTypeToString(GetDataType()))); + } + if(resample != k_NoResampleModeIndex) { if(resample == k_ScalingModeIndex) @@ -338,8 +345,6 @@ Result<> ReadImageStackImpl(DataStructure& dataStructure, const ReadImageStackIn destImageGeomPath = ResampledTemporaryGeometryPath(imageGeomPath); } - DataPath srcImageDataPath = imageGeomPath.createChildPath(cellDataName).createChildPath(imageArrayName); - bool validInputForGrayScaleConversion = importedDataStructure.getDataRefAs(srcImageDataPath).getDataType() == DataType::uint8; if(convertToGrayscale && validInputForGrayScaleConversion) { diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/ReadImageStackFilter.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/ReadImageStackFilter.cpp index ddcd5ecb6a..95737f57b3 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/ReadImageStackFilter.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/ReadImageStackFilter.cpp @@ -27,7 +27,6 @@ #include "simplnx/Utilities/ImageProcessing/ImageGeometryResample.hpp" #include "simplnx/Utilities/SIMPLConversion.hpp" -#include #include namespace fs = std::filesystem; @@ -442,54 +441,6 @@ Result<> ReadImageStackFilter::executeImpl(DataStructure& dataStructure, const A inputValues.imageDataType = ChoiceToImageDataType(filterArgs.value(k_ImageDataType_Key)); inputValues.croppingOptions = filterArgs.value(k_CroppingOptions_Key); - // Output actions have already created the stack. Check headers before decoding or copying any - // slice pixels; interactive preflight reads only file 0. These checks do not apply slice actions. - auto zRangeResult = ComputeCroppedZRange(inputValues.croppingOptions, inputValues.fileList.size(), inputValues.origin, inputValues.spacing, inputValues.changeOrigin, inputValues.changeSpacing, - inputValues.originSpacingProcessing); - if(zRangeResult.invalid()) - { - return ConvertResult(std::move(zRangeResult)); - } - const auto& zRange = zRangeResult.value(); - const DataPath imageDataPath = inputValues.imageGeometryPath.createChildPath(inputValues.cellDataName).createChildPath(inputValues.imageDataArrayName); - const DataType stackType = dataStructure.getDataRefAs(imageDataPath).getDataType(); - - ReadImageSubFilterConfig subConfig{}; - subConfig.imageGeometryPath = inputValues.imageGeometryPath; - subConfig.cellDataName = inputValues.cellDataName; - subConfig.imageDataArrayName = inputValues.imageDataArrayName; - subConfig.changeOrigin = inputValues.changeOrigin; - subConfig.changeSpacing = inputValues.changeSpacing; - subConfig.origin = inputValues.origin; - subConfig.spacing = inputValues.spacing; - subConfig.originSpacingProcessing = inputValues.originSpacingProcessing; - subConfig.changeDataType = inputValues.changeDataType; - subConfig.imageDataType = inputValues.imageDataType; - subConfig.croppingOptions = inputValues.croppingOptions; - - DataStructure tmpDs; - ReadImageFilter imageReader; - imageReader.setReadSinglePageOnly(true); - for(usize i = std::max(1, zRange.zMin); i <= zRange.zMax; ++i) - { - subConfig.filePath = inputValues.fileList[i]; - PreflightResult sliceResult = imageReader.preflight(tmpDs, BuildReadImageFilterArgs(subConfig), messageHandler, shouldCancel); - if(sliceResult.outputActions.invalid()) - { - return ConvertResult(std::move(sliceResult.outputActions)); - } - const auto* sliceArrayAction = FindFirstActionOfType(sliceResult.outputActions.value().actions); - if(sliceArrayAction == nullptr) - { - return MakeErrorResult(-23531, "Internal error: ReadImageFilter preflight did not produce a CreateArrayAction."); - } - if(sliceArrayAction->type() != stackType) - { - return MakeErrorResult( - -23534, fmt::format("Slice {} ('{}') has data type {}, but the stack requires {}.", i, inputValues.fileList[i], DataTypeToString(sliceArrayAction->type()), DataTypeToString(stackType))); - } - } - return ReadImageStack(dataStructure, messageHandler, shouldCancel, inputValues)(); } diff --git a/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp b/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp index 0ab37fca32..c3585bbff9 100644 --- a/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp +++ b/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp @@ -1540,10 +1540,10 @@ TEST_CASE("ImageProcessing::ReadImageStackFilter::MixedSliceDataTypes", "[ImageP args.insertOrAssign(ReadImageStackFilter::k_InputFileListInfo_Key, std::make_any(fileList)); args.insertOrAssign(ReadImageStackFilter::k_ImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); - SECTION("Reject before writing any slices") + SECTION("Reject mismatched slice data types") { // With conversion disabled, uint8 and uint16 cannot share a typed stack array. - // Preflight reads only file 0. Execute must reject the mismatch before copying any pixels. + // Preflight reads only file 0. Execute must report the mismatched slice without throwing. DataStructure preflightDs; IFilter::PreflightResult preflightResult; REQUIRE_NOTHROW(preflightResult = filter.preflight(preflightDs, args)); @@ -1558,26 +1558,6 @@ TEST_CASE("ImageProcessing::ReadImageStackFilter::MixedSliceDataTypes", "[ImageP CHECK(sliceError.message.find("slice_1.tif") != std::string::npos); CHECK(sliceError.message.find("uint8") != std::string::npos); CHECK(sliceError.message.find("uint16") != std::string::npos); - // IFilter applies output actions before executeImpl. The initial zeros must remain unchanged, - // including slice 0, whose nonzero fixture values would expose a late validation check. - if(firstSliceIsUint16) - { - const auto& store = ds.getDataRefAs(k_ImageDataPath).getDataStoreRef(); - REQUIRE(store.getSize() == 8); - for(usize pixel = 0; pixel < store.getSize(); ++pixel) - { - CHECK(store[pixel] == 0); - } - } - else - { - const auto& store = ds.getDataRefAs(k_ImageDataPath).getDataStoreRef(); - REQUIRE(store.getSize() == 8); - for(usize pixel = 0; pixel < store.getSize(); ++pixel) - { - CHECK(store[pixel] == 0); - } - } } SECTION("Preflight does not read later slice headers") From cfa0e7ef011d4d4fe8bfcc913834bb65cb7f0949 Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Wed, 4 Nov 2026 17:42:51 -0500 Subject: [PATCH 24/33] REV: ImageRotationUtilities - Use the classified source axis for grid-rotation spacing Review of #1915: CreateRotationArgs classified a grid rotation from the normalized columns, but then chose each output spacing from the largest entry of the raw matrix row. Under uneven scaling with a small shear the two disagree. For x' = x + 5y, y' = 100000y and spacing (2,3,5), the classifier maps X to X, but the output got X spacing 300000 and one X cell. The classifier now records, for each column, its output row and its scale, and the output spacing comes directly from that mapping. The non-grid path does not change. Add closed-form tests of this matrix through the helper and through Apply Transformation to Geometry (Direct and Scanline): spacing (2, 300000, 5) and dimensions (17, 2, 2). Use the reviewer's wording for the V&V deviation: only the four isotropic principal-axis fixtures are claimed identical to 6.5.171. Fixes #1908 item L28 Signed-off-by: Michael Jackson --- .../ApplyTransformationToGeometryFilter.md | 2 + .../ApplyTransformationToGeometryTest.cpp | 54 +++++++++++++++++++ .../vv/RotateSampleRefFrameFilter.md | 6 ++- .../deviations/RotateSampleRefFrameFilter.md | 6 +-- .../provenance/RotateSampleRefFrameFilter.md | 4 +- .../Utilities/ImageRotationUtilities.cpp | 8 +-- test/ImageRotationUtilitiesTest.cpp | 31 +++++++++++ 7 files changed, 101 insertions(+), 10 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/ApplyTransformationToGeometryFilter.md b/src/Plugins/SimplnxCore/docs/ApplyTransformationToGeometryFilter.md index 605f6ea49e..a6a15ded40 100644 --- a/src/Plugins/SimplnxCore/docs/ApplyTransformationToGeometryFilter.md +++ b/src/Plugins/SimplnxCore/docs/ApplyTransformationToGeometryFilter.md @@ -21,6 +21,8 @@ For Image Geometries, transformation requires re-gridding because cell positions - **Interpolation Method** -- how cell data values are sampled from the old grid (see below). - **Cell Attribute Matrix** -- which attribute matrix holds the cell data to transform. +For transforms classified as grid rotations, each output axis uses its matched source axis spacing and scale. This also applies when uneven scaling includes a small shear within the grid tolerance. For example, the transform (x,y,z) to (x+5y,100000y,z) changes spacing (2,3,5) to (2,300000,5). + ### Image Geometry Caveat: Successive Transformations Applying multiple transformations one-at-a-time to an Image Geometry produces visible re-gridding artifacts because each intermediate step re-samples the data. The following example shows a 90-degree rotation done as a single step versus as two 45-degree steps: diff --git a/src/Plugins/SimplnxCore/test/ApplyTransformationToGeometryTest.cpp b/src/Plugins/SimplnxCore/test/ApplyTransformationToGeometryTest.cpp index cfc3b6479f..892563cc7d 100644 --- a/src/Plugins/SimplnxCore/test/ApplyTransformationToGeometryTest.cpp +++ b/src/Plugins/SimplnxCore/test/ApplyTransformationToGeometryTest.cpp @@ -1024,6 +1024,60 @@ TEST_CASE("SimplnxCore::ApplyTransformationToGeometryFilter:Manual_Image", "[Sim } } +TEST_CASE("SimplnxCore::ApplyTransformationToGeometryFilter: Uneven scaling keeps the classified source axis", "[SimplnxCore][ApplyTransformationToGeometryFilter]") +{ + UnitTest::LoadPlugins(); + const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); + CAPTURE(scenario); + + DataStructure dataStructure; + const DataPath inputGeometryPath({"Input"}); + const DataPath inputCellAMPath = inputGeometryPath.createChildPath(k_Cell_Data); + auto* image = ImageGeom::Create(dataStructure, "Input"); + REQUIRE(image != nullptr); + image->setDimensions({2, 2, 2}); + image->setSpacing({2.0F, 3.0F, 5.0F}); + image->setOrigin({0.0F, 0.0F, 0.0F}); + auto* cellAM = AttributeMatrix::Create(dataStructure, k_Cell_Data, {2, 2, 2}, image->getId()); + REQUIRE(cellAM != nullptr); + image->setCellData(*cellAM); + auto* values = Int32Array::CreateWithStore(dataStructure, "Data", {2, 2, 2}, {1}, cellAM->getId()); + REQUIRE(values != nullptr); + values->fill(1); + + const ApplyTransformationToGeometryFilter filter; + Arguments args; + args.insertOrAssign(ApplyTransformationToGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any(inputGeometryPath)); + args.insertOrAssign(ApplyTransformationToGeometryFilter::k_CellAttributeMatrixPath_Key, std::make_any(inputCellAMPath)); + args.insertOrAssign(ApplyTransformationToGeometryFilter::k_TransformationType_Key, std::make_any(apply_transformation_to_geometry::k_ManualTransformationMatrixIdx)); + args.insertOrAssign(ApplyTransformationToGeometryFilter::k_InterpolationType_Key, std::make_any(apply_transformation_to_geometry::k_NearestNeighborInterpolationIdx)); + const DynamicTableParameter::ValueType matrix{{1.0, 5.0, 0.0, 0.0}, {0.0, 100000.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0}, {0.0, 0.0, 0.0, 1.0}}; + args.insertOrAssign(ApplyTransformationToGeometryFilter::k_ManualTransformationMatrix_Key, std::make_any(matrix)); + args.insertOrAssign(ApplyTransformationToGeometryFilter::k_TranslateGeometryToGlobalOrigin_Key, std::make_any(false)); + + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions) + UnitTest::AlgorithmTestScope algorithmTestScope(scenario); + auto executeResult = algorithmTestScope.executeFilter(filter, dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result) + + // Hand calculation: (x,y,z) -> (x+5y,100000y,z). The normalized Y column's + // off-axis entry is about 5e-5, so the classified source axes remain X, Y, Z. + // Spacing is (2, 3*sqrt(100000^2+5^2), 5), or (2,300000,5) in float32. + // Bounds have extents (4+5*6,100000*6,10) = (34,600000,10). + // Extents divided by spacing give dimensions (17,2,2). + const auto& output = dataStructure.getDataRefAs(inputGeometryPath); + const FloatVec3 expectedSpacing = {2.0F, 300000.0F, 5.0F}; + const SizeVec3 expectedDims = {17, 2, 2}; + for(usize axis = 0; axis < 3; ++axis) + { + CAPTURE(axis); + CHECK(output.getSpacing()[axis] == Approx(expectedSpacing[axis])); + CHECK(output.getDimensions()[axis] == expectedDims[axis]); + } + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} + TEST_CASE("SimplnxCore::ApplyTransformationToGeometryFilter:Precomputed_Image", "[SimplnxCore][ApplyTransformationToGeometryFilter]") { UnitTest::LoadPlugins(); diff --git a/src/Plugins/SimplnxCore/vv/RotateSampleRefFrameFilter.md b/src/Plugins/SimplnxCore/vv/RotateSampleRefFrameFilter.md index 4f591f3b19..54bf58a6da 100644 --- a/src/Plugins/SimplnxCore/vv/RotateSampleRefFrameFilter.md +++ b/src/Plugins/SimplnxCore/vv/RotateSampleRefFrameFilter.md @@ -25,7 +25,7 @@ ## Summary -`RotateSampleRefFrame` rotates the reference frame of an **Image Geometry** by nearest-neighbor resampling. V&V established that the operation is a *lossless voxel permutation* — the only correct meaning of a reference-frame rotation — **if and only if** the rotation maps the cubic voxel grid onto itself, i.e. it is a member of the octahedral rotation group (the 90/180/270-degree rotations about X/Y/Z, plus 180 about a face-diagonal and 120/240 about a body-diagonal); for any other rotation it silently produces a lossy, background-padded resample (empirically demonstrated: 45@Z turns 24 voxels into 50 with 24 introduced zeros). A preflight **guard** was added to enforce the supported domain (error `-6850`, plus `-6851` for a slice-reordering slice-by-slice combination), the golden-file exemplar was retired in favor of an inlined **Class 1 analytical-permutation** oracle (+ Class 4 invariants), and a legacy A/B on four principal-90 fixtures showed SIMPLNX is **bit-identical** to DREAM3D 6.5.171 on the standard EBSD sample transforms. +`RotateSampleRefFrame` rotates the reference frame of an **Image Geometry** by nearest-neighbor resampling. V&V established that the operation is a *lossless voxel permutation* — the only correct meaning of a reference-frame rotation — **if and only if** the rotation maps the cubic voxel grid onto itself, i.e. it is a member of the octahedral rotation group (the 90/180/270-degree rotations about X/Y/Z, plus 180 about a face-diagonal and 120/240 about a body-diagonal); for any other rotation it silently produces a lossy, background-padded resample (empirically demonstrated: 45@Z turns 24 voxels into 50 with 24 introduced zeros). A preflight **guard** was added to enforce the supported domain (error `-6850`, plus `-6851` for a slice-reordering slice-by-slice combination), the golden-file exemplar was retired in favor of an inlined **Class 1 analytical-permutation** oracle (+ Class 4 invariants), and a legacy A/B showed identical dimensions and voxel values in simplnx and DREAM3D 6.5.171 on the four tested isotropic principal-axis fixtures. ## Algorithm Relationship @@ -109,6 +109,8 @@ Comparison run on four principal-90 fixtures (90@Z, 180@Z, 90@X, 180@Y) — see `SimplnxCore::RotateSampleRefFrame: anisotropic three-cycle preserves the voxel grid` uses an inline analytical oracle. The map R(x,y,z)=(z,x,y) sends dimensions (2,3,4) to (4,2,3) and spacing (2,3,5) to (5,2,3). Output (i,j,k) has value 1+j+2*k+6*i. The test checks every cell in Direct and Scanline paths on in-memory stores. No exemplar is used. -Test sensitivity verification: before the fix, both paths returned dimensions (7,1,5), spacing (3,5,2), and 35 cells instead of 24. For grid rotations (signed axis permutations), the shared helper now selects spacing from matrix rows and applies the selected source axis scale. Other transformations keep the earlier spacing rule. This intentionally corrects DREAM3D 6.5.171 behavior; see `RotateSampleRefFrameFilter-D2`. No new legacy binary comparison or disk-backed OOC validation is claimed. +Test sensitivity verification: before the fix, both paths returned dimensions (7,1,5), spacing (3,5,2), and 35 cells instead of 24. For transforms classified as grid rotations, the shared helper uses the classified source axis and its column scale for each output axis. Other transformations keep the earlier spacing rule. This intentionally corrects DREAM3D 6.5.171 behavior; see `RotateSampleRefFrameFilter-D2`. No new legacy binary comparison or disk-backed OOC validation is claimed. To repeat the L28 check, run the `SimplnxCore::RotateSampleRefFrame` CTest entries serially. The historical A/B results above are unchanged and apply only to their four fixtures. + +The R5 helper regression and Apply Transformation to Geometry regression check uneven scaling with a small shear. For (x,y,z) to (x+5y,100000y,z), a 2×2×2 image with spacing (2,3,5) has transformed extents (34,600000,10). The analytical spacing is (2,3*sqrt(100000^2+5^2),5), or (2,300000,5) in float32. The expected dimensions are (17,2,2). Both regressions failed before R5 and pass after it; the filter test covers Direct and Scanline on in-memory stores. This is shared-helper evidence, not a new DREAM3D 6.5.171 comparison. diff --git a/src/Plugins/SimplnxCore/vv/deviations/RotateSampleRefFrameFilter.md b/src/Plugins/SimplnxCore/vv/deviations/RotateSampleRefFrameFilter.md index 51c4af47b6..1c814360ef 100644 --- a/src/Plugins/SimplnxCore/vv/deviations/RotateSampleRefFrameFilter.md +++ b/src/Plugins/SimplnxCore/vv/deviations/RotateSampleRefFrameFilter.md @@ -4,7 +4,7 @@ This file lists every documented behavioral difference between this SIMPLNX filt Entries are referenced by stable ID (`RotateSampleRefFrameFilter-D`) from the V&V report and from public migration guidance. The ID is stable across renames; the Filter UUID field is the permanent cross-reference anchor. -Legacy equivalent: `RotateSampleRefFrame` (SIMPL UUID `{e25d9b4c-2b37-578c-b1de-cf7032b5ef19}`) in the Sampling plugin. On the **supported domain** (a 90/180/270-degree rotation about the X, Y, or Z axis) SIMPLNX and 6.5.171 are **bit-identical** — same output dimensions and same voxel values on all four A/B fixtures (see `../comparisons/RotateSampleRefFrameFilter/results.md`). Those four isotropic fixtures do not cover anisotropic three-cycle rotations. The deviations below include that correction. +Legacy equivalent: `RotateSampleRefFrame` (SIMPL UUID `{e25d9b4c-2b37-578c-b1de-cf7032b5ef19}`) in the Sampling plugin. The four isotropic principal-axis fixtures produced identical dimensions and voxel values in simplnx and 6.5.171. D2 verifies the anisotropic three-cycle against an analytical result. See `../comparisons/RotateSampleRefFrameFilter/results.md` for the four A/B fixtures. --- @@ -20,7 +20,7 @@ Legacy equivalent: `RotateSampleRefFrame` (SIMPL UUID `{e25d9b4c-2b37-578c-b1de- **Root cause:** Algorithmic choice. A reference-frame rotation is only a lossless re-labeling of the voxels when the rotation maps the grid onto itself (a signed axis-permutation / octahedral-group rotation). For any other rotation the nearest-neighbor resample is lossy: it enlarges the bounding box, drops and duplicates voxels, and pads the result with background (0) values — 45° about Z of a 4×3×2 test volume, for example, turns 24 voxels into 50 with 24 introduced zeros. Legacy 6.5.171 performed this lossy resample silently (its documentation only *hedged* that the filter was "verified" for 90/180 about a principal axis). SIMPLNX makes the supported domain an enforced contract via a preflight guard (`RotateSampleRefFrameFilter.cpp`, `IsLosslessGridRotation`), so the arbitrary-rotation path can no longer be reached — arguably a latent-bug fix for a filter whose purpose is a reference-frame rotation. -**Affected users:** Anyone who previously fed a lossy rotation to the legacy filter (an undocumented/unsupported use). Pipelines that used the standard EBSD sample transforms (n×90 about a principal axis, e.g. 180° about Y) are unaffected — those remain bit-identical. +**Affected users:** Anyone who previously fed a lossy rotation to the legacy filter (an undocumented/unsupported use). The four tested isotropic principal-axis fixtures are unaffected. **Blast radius — internal callers.** `ReadH5Ebsd` (`ReadH5Ebsd.cpp`) forwards the sample-reference-frame transform stored in the `.h5ebsd` file directly into this filter with slice-by-slice enabled, and propagates preflight errors. If a file's *recommended* sample transform is not a lossless, Z-preserving rotation (for example a stored 90° about X, which trips `-6851`, or any non-group angle, which trips `-6850`), the entire H5EBSD import now fails preflight with an error naming a filter the user never placed. The prior behavior was a silently corrupted (slice-pinned) import, so failing loudly is arguably correct, but the message can be confusing in that context. The practical workaround is to uncheck *Use Recommended Transformations* in `ReadH5Ebsd` (or apply the transform separately). This is called out here so the failure mode is documented rather than surprising. @@ -31,6 +31,6 @@ Legacy equivalent: `RotateSampleRefFrame` (SIMPL UUID `{e25d9b4c-2b37-578c-b1de- - **Filter UUID:** `d2451dc1-a5a1-4ac2-a64d-7991669dcffc` - **Status:** active - **Symptom:** DREAM3D 6.5.171 errata KI-008 assigns spacing from the wrong source axis for three-cycle rotations. Anisotropic output spacing and dimensions are wrong. -- **Correction:** Select the source axis from each output matrix row. For R(x,y,z)=(z,x,y), spacing (2,3,5) becomes (5,2,3). +- **Correction:** Use the source axis and column scale found when classifying the grid rotation. For R(x,y,z)=(z,x,y), spacing (2,3,5) becomes (5,2,3). - **Evidence:** The inline analytical regression checks dimensions and every voxel in both Direct and Scanline paths. Both paths failed before the fix. No new legacy binary comparison was run. - **Recommendation:** Use the corrected output. Affected anisotropic rotations intentionally differ from DREAM3D 6.5.171. diff --git a/src/Plugins/SimplnxCore/vv/provenance/RotateSampleRefFrameFilter.md b/src/Plugins/SimplnxCore/vv/provenance/RotateSampleRefFrameFilter.md index 11f48889e6..096eea9398 100644 --- a/src/Plugins/SimplnxCore/vv/provenance/RotateSampleRefFrameFilter.md +++ b/src/Plugins/SimplnxCore/vv/provenance/RotateSampleRefFrameFilter.md @@ -47,4 +47,6 @@ Yes — this replaces the retired `Rotate_Sample_Ref_Frame_Test_v2/v3.tar.gz` go `SimplnxCore::RotateSampleRefFrame: anisotropic three-cycle preserves the voxel grid` uses an inline analytical oracle. The map R(x,y,z)=(z,x,y) sends dimensions (2,3,4) to (4,2,3) and spacing (2,3,5) to (5,2,3). Output (i,j,k) has value 1+j+2*k+6*i. The test checks every cell in Direct and Scanline paths on in-memory stores. No exemplar is used. -Test sensitivity verification: before the fix, both paths returned dimensions (7,1,5), spacing (3,5,2), and 35 cells instead of 24. For grid rotations (signed axis permutations), the shared helper now selects spacing from matrix rows and applies the selected source axis scale. Other transformations keep the earlier spacing rule. This intentionally corrects DREAM3D 6.5.171 behavior; see `RotateSampleRefFrameFilter-D2`. No new legacy binary comparison or disk-backed OOC validation is claimed. +Test sensitivity verification: before the fix, both paths returned dimensions (7,1,5), spacing (3,5,2), and 35 cells instead of 24. For transforms classified as grid rotations, the shared helper uses the classified source axis and its column scale for each output axis. Other transformations keep the earlier spacing rule. This intentionally corrects DREAM3D 6.5.171 behavior; see `RotateSampleRefFrameFilter-D2`. No new legacy binary comparison or disk-backed OOC validation is claimed. + +The R5 helper regression and Apply Transformation to Geometry regression check uneven scaling with a small shear. For (x,y,z) to (x+5y,100000y,z), a 2×2×2 image with spacing (2,3,5) has transformed extents (34,600000,10). The analytical spacing is (2,3*sqrt(100000^2+5^2),5), or (2,300000,5) in float32. The expected dimensions are (17,2,2). Both regressions failed before R5 and pass after it; the filter test covers Direct and Scanline on in-memory stores. This is shared-helper evidence, not a new DREAM3D 6.5.171 comparison. diff --git a/src/simplnx/Utilities/ImageRotationUtilities.cpp b/src/simplnx/Utilities/ImageRotationUtilities.cpp index 1ee1fdcf82..d4d8099263 100644 --- a/src/simplnx/Utilities/ImageRotationUtilities.cpp +++ b/src/simplnx/Utilities/ImageRotationUtilities.cpp @@ -82,6 +82,7 @@ RotateArgs CreateRotationArgs(const ImageGeom& imageGeom, const Matrix4fR& trans constexpr float32 k_GridTolerance = k_RawGridTolerance / (1.0F - k_RawGridTolerance); bool isGridRotation = true; std::array usedRows = {false, false, false}; + FloatVec3 gridSpacing; for(int32 col = 0; col < 3; ++col) { const float32 scale = rotationMatrix.col(col).norm(); @@ -99,6 +100,8 @@ RotateArgs CreateRotationArgs(const ImageGeom& imageGeom, const Matrix4fR& trans break; } usedRows[sourceRow] = true; + // Preserve the classified source axis and its scale for this output row. + gridSpacing[sourceRow] = spacing[col] * scale; for(int32 row = 0; row < 3; ++row) { if(row != sourceRow && std::abs(normalized[row]) > k_GridTolerance) @@ -111,10 +114,7 @@ RotateArgs CreateRotationArgs(const ImageGeom& imageGeom, const Matrix4fR& trans FloatVec3 outputSpacing; if(isGridRotation) { - // Each row identifies the source axis for an output axis. Scale belongs to that source column. - const FloatVec3 scaledSpacing = {spacing[0] * rotationMatrix.col(0).norm(), spacing[1] * rotationMatrix.col(1).norm(), spacing[2] * rotationMatrix.col(2).norm()}; - outputSpacing = {DetermineSpacing(scaledSpacing, rotationMatrix.row(0).transpose()), DetermineSpacing(scaledSpacing, rotationMatrix.row(1).transpose()), - DetermineSpacing(scaledSpacing, rotationMatrix.row(2).transpose())}; + outputSpacing = gridSpacing; } else { diff --git a/test/ImageRotationUtilitiesTest.cpp b/test/ImageRotationUtilitiesTest.cpp index c566ccc424..093d19d146 100644 --- a/test/ImageRotationUtilitiesTest.cpp +++ b/test/ImageRotationUtilitiesTest.cpp @@ -94,6 +94,37 @@ TEST_CASE("ImageRotationUtilities: Scaled three-cycle takes spacing from the sca } } +TEST_CASE("ImageRotationUtilities: Uneven scaling keeps the classified source axis", "[ImageRotationUtilities][CreateRotationArgs]") +{ + DataStructure dataStructure; + ImageGeom* image = ImageGeom::Create(dataStructure, "Input"); + REQUIRE(image != nullptr); + image->setDimensions({2, 2, 2}); + image->setSpacing({2.0F, 3.0F, 5.0F}); + image->setOrigin({0.0F, 0.0F, 0.0F}); + + ImageRotationUtilities::Matrix4fR transform = ImageRotationUtilities::Matrix4fR::Identity(); + transform(0, 1) = 5.0F; + transform(1, 1) = 100000.0F; + + // Hand calculation: (x,y,z) -> (x+5y,100000y,z). The normalized Y column's + // off-axis entry is about 5e-5, so the classified source axes remain X, Y, Z. + // Spacing is (2, 3*sqrt(100000^2+5^2), 5), which rounds to (2,300000,5) in float32. + // Input extents (4,6,10) become (4+5*6,100000*6,10) = (34,600000,10). + // Dividing by spacing and rounding gives dimensions (17,2,2). + const auto args = ImageRotationUtilities::CreateRotationArgs(*image, transform); + const std::array expectedSpacing = {2.0F, 300000.0F, 5.0F}; + const std::array expectedDims = {17, 2, 2}; + for(usize axis = 0; axis < 3; ++axis) + { + CAPTURE(axis); + CHECK(args.outputSpacing[axis] == Approx(expectedSpacing[axis])); + CHECK(args.TransformedSpacing[axis] == Approx(expectedSpacing[axis])); + CHECK(args.outputDims[axis] == expectedDims[axis]); + CHECK(args.TransformedDims[axis] == expectedDims[axis]); + } +} + TEST_CASE("ImageRotationUtilities: Off-axis scaling keeps the column-based spacing", "[ImageRotationUtilities][CreateRotationArgs]") { DataStructure dataStructure; From 4ca210f8fd5dd21107113cf5ca1bfc0d355ef70d Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Wed, 4 Nov 2026 17:49:31 -0500 Subject: [PATCH 25/33] REV: ReadVtkStructuredPoints - Center a plane or line on its VTK position Review of #1915: a DIMENSIONS value of 1 gives that axis one cell, but the origin stayed on the VTK point, so the voxel center moved by half the spacing. A plane at Z = 10 with Z spacing 4 was imported with its voxel center at Z = 12. On every axis with one point, the origin of the cell and point Image Geometries is now the VTK origin minus half the spacing, so the voxel is centered on the plane or line. Axes with more than one point do not change. Add tests for a plane and for X, Y and Z lines that check dimensions, values, origin and voxel centers of both geometries, in preflight and execute. Fixes #1908 item L45 Signed-off-by: Michael Jackson --- .../docs/ReadVtkStructuredPointsFilter.md | 2 + .../Algorithms/ReadVtkStructuredPoints.cpp | 9 ++ .../test/ReadVtkStructuredPointsTest.cpp | 95 +++++++++++++++++++ 3 files changed, 106 insertions(+) diff --git a/src/Plugins/SimplnxCore/docs/ReadVtkStructuredPointsFilter.md b/src/Plugins/SimplnxCore/docs/ReadVtkStructuredPointsFilter.md index 83df79f1a0..dff6524521 100644 --- a/src/Plugins/SimplnxCore/docs/ReadVtkStructuredPointsFilter.md +++ b/src/Plugins/SimplnxCore/docs/ReadVtkStructuredPointsFilter.md @@ -25,6 +25,8 @@ The grid dimensions, spacing, and origin are read directly from the `.vtk` file' Each cell dimension is one less than its point dimension, with a minimum of one. This supports 2D planes, 1D lines, and a single point. For example, `DIMENSIONS 10 10 1` has 81 cells in a `9 9 1` grid. Zero point dimensions return an error during preflight. These behaviors intentionally differ from DREAM3D 6.5.171, which rejects valid cell data on singleton axes and can underflow on zero dimensions. +On each axis with one point, both output geometries use the file origin minus half the spacing to keep the voxel center at the point's physical position. + ### Example Input # vtk DataFile Version 2.0 diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReadVtkStructuredPoints.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReadVtkStructuredPoints.cpp index c1249f92e3..c0558347d9 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReadVtkStructuredPoints.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ReadVtkStructuredPoints.cpp @@ -829,6 +829,15 @@ Result<> ReadVtkStructuredPoints::readFile() } origin[2] = convertResultF32.value(); + // Center the one-voxel slab on the VTK point along each singleton axis. + for(usize axis = 0; axis < 3; axis++) + { + if(pointDims[axis] == 1) + { + origin[axis] -= 0.5f * spacing[axis]; + } + } + if(m_InputValues->ReadPointData && m_Preflight) { auto createImageGeometryAction = std::make_unique(m_InputValues->PointGeomPath, pointDims, origin, spacing, m_InputValues->PointAttributeMatrixName); diff --git a/src/Plugins/SimplnxCore/test/ReadVtkStructuredPointsTest.cpp b/src/Plugins/SimplnxCore/test/ReadVtkStructuredPointsTest.cpp index c730972cbd..dab092a1ab 100644 --- a/src/Plugins/SimplnxCore/test/ReadVtkStructuredPointsTest.cpp +++ b/src/Plugins/SimplnxCore/test/ReadVtkStructuredPointsTest.cpp @@ -199,6 +199,101 @@ TEST_CASE("SimplnxCore::ReadVtkStructuredPointsFilter: Singleton and Zero Dimens } } +TEST_CASE("SimplnxCore::ReadVtkStructuredPointsFilter: Singleton Axis Physical Position", "[SimplnxCore][ReadVtkStructuredPointsFilter]") +{ + UnitTest::LoadPlugins(); + + const bool binary = GENERATE(false, true); + const usize grid = GENERATE(0, 1, 2, 3, 4); + CAPTURE(binary, grid); + // Hand calculation: for origin (2, 6, 10) and spacing (2, 6, 4), a singleton + // axis needs origin - spacing/2 so its voxel center stays at the VTK point. + // The Z plane therefore has origin Z = 8 and center Z = 10. The next three + // cases are X, Y and Z lines; the last is a 3D control with unchanged origin. + // Active axes have n-1 cells and retain their original origin and spacing. + const std::array pointDimensions = {SizeVec3{3, 3, 1}, SizeVec3{3, 1, 1}, SizeVec3{1, 3, 1}, SizeVec3{1, 1, 3}, SizeVec3{3, 3, 3}}; + const std::array cellDimensions = {SizeVec3{2, 2, 1}, SizeVec3{2, 1, 1}, SizeVec3{1, 2, 1}, SizeVec3{1, 1, 2}, SizeVec3{2, 2, 2}}; + const std::array expectedOrigins = {FloatVec3{2, 6, 8}, FloatVec3{2, 3, 8}, FloatVec3{1, 6, 8}, FloatVec3{1, 3, 10}, FloatVec3{2, 6, 10}}; + const std::array expectedCenters = {FloatVec3{3, 9, 10}, FloatVec3{3, 6, 10}, FloatVec3{2, 9, 10}, FloatVec3{2, 6, 12}, FloatVec3{3, 9, 12}}; + const auto& pointDims = pointDimensions[grid]; + const auto& cellDims = cellDimensions[grid]; + std::vector pointValues(pointDims[0] * pointDims[1] * pointDims[2]); + std::vector cellValues(cellDims[0] * cellDims[1] * cellDims[2]); + for(usize index = 0; index < pointValues.size(); index++) + { + pointValues[index] = static_cast(index) + 1; + } + for(usize index = 0; index < cellValues.size(); index++) + { + cellValues[index] = static_cast(index) + 100; + } + + const fs::path filePath = fs::path(unit_test::k_BinaryDir.view()) / "ReadVtkPhysicalPosition.vtk"; + auto fileGuard = MakeScopeGuard([&filePath]() noexcept { + std::error_code errorCode; + fs::remove(filePath, errorCode); + }); + { + std::ofstream output(filePath, std::ios::binary | std::ios::trunc); + REQUIRE(output.is_open()); + output << "# vtk DataFile Version 3.0\nPhysical position regression\n" << (binary ? "BINARY\n" : "ASCII\n"); + output << "DATASET STRUCTURED_POINTS\nDIMENSIONS " << pointDims[0] << ' ' << pointDims[1] << ' ' << pointDims[2] << "\nSPACING 2 6 4\nORIGIN 2 6 10\n"; + output << "POINT_DATA " << pointValues.size() << "\nSCALARS Values int 1\nLOOKUP_TABLE default\n"; + WriteSectionValues(output, pointValues, binary); + output << "CELL_DATA " << cellValues.size() << "\nSCALARS Values int 1\nLOOKUP_TABLE default\n"; + WriteSectionValues(output, cellValues, binary); + output.close(); + REQUIRE(output.good()); + } + + ReadVtkStructuredPointsFilter filter; + Arguments args = createArgs(filePath); + for(const bool preflight : {true, false}) + { + CAPTURE(preflight); + DataStructure ds; + if(preflight) + { + auto preflightResult = filter.preflight(ds, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + const auto applyResult = preflightResult.outputActions.value().applyRegular(ds, IDataAction::Mode::Preflight); + SIMPLNX_RESULT_REQUIRE_VALID(applyResult); + } + else + { + const auto executeResult = filter.execute(ds, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result); + } + for(const bool points : {false, true}) + { + CAPTURE(points); + const DataPath geomPath({points ? "VTK Point Data" : "VTK Cell Data"}); + const auto& geom = ds.getDataRefAs(geomPath); + REQUIRE(geom.getDimensions() == (points ? pointDims : cellDims)); + REQUIRE(geom.getSpacing() == FloatVec3{2, 6, 4}); + const auto center = geom.getCoordsf(0, 0, 0); + for(usize axis = 0; axis < 3; axis++) + { + CAPTURE(axis); + CHECK(geom.getOrigin()[axis] == expectedOrigins[grid][axis]); + CHECK(center[axis] == expectedCenters[grid][axis]); + } + const auto& values = ds.getDataRefAs(geomPath.createChildPath(points ? "Vertex Data" : "Cell Data").createChildPath("Values")); + REQUIRE(values.getNumberOfTuples() == (points ? pointValues.size() : cellValues.size())); + REQUIRE(values.getNumberOfComponents() == 1); + if(!preflight) + { + // Values must match the literal sequence written above, regardless of origin. + for(usize index = 0; index < values.getNumberOfTuples(); index++) + { + REQUIRE(values[index] == static_cast(index) + (points ? 1 : 100)); + } + } + } + UnitTest::CheckArraysInheritTupleDims(ds); + } +} + TEST_CASE("SimplnxCore::ReadVtkStructuredPointsFilter: Section Selection", "[SimplnxCore][ReadVtkStructuredPointsFilter]") { UnitTest::LoadPlugins(); From 123c01eb4b99ec3547fffdb33f8fa00dbbd03130 Mon Sep 17 00:00:00 2001 From: Mike Jackson Date: Wed, 4 Nov 2026 18:00:53 -0500 Subject: [PATCH 26/33] REV: ReadImage - State only what the multi-page TIFF checks compare Review of #1915: the -2007 messages and the loop comment written for L57 said that every page must share dimensions, component count and scalar type, which read as if all three were checked. The code compares only the number of bytes per pixel and the dimensions of each page with page 0, because IImageIO gives metadata only for page 0. Each -2007 message now says what was found (a different number of bytes per pixel, or different dimensions) and what is required. The comment and the filter documentation say that a page with a different layout but the same number of bytes per pixel is not detected. That case is tracked as #1908 item L79. Fixes #1908 item L57 Signed-off-by: Michael Jackson --- .../NXImageProcessing/docs/ReadImageFilter.md | 4 +++- .../Filters/Algorithms/ReadImage.cpp | 15 +++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Plugins/NXImageProcessing/docs/ReadImageFilter.md b/src/Plugins/NXImageProcessing/docs/ReadImageFilter.md index cd95375624..7ec4d8d756 100644 --- a/src/Plugins/NXImageProcessing/docs/ReadImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/ReadImageFilter.md @@ -16,7 +16,9 @@ The following image types are supported: - TIFF / TIF, including multi-page TIFF read as a 3D Z-stack (via libtiff) - NRRD (`.nrrd` attached, `.nhdr` detached) (ITK-free, zlib only) -If the first page of a multi-page TIFF is RGB and a later page is grayscale, the filter fails with error `-2007` when it reads that later page. It fails before it copies any pixels of that page. This intentionally differs from DREAM3D 6.5.171, which could crash on mixed-page TIFF files (KI-053). +All pages of a multi-page TIFF must have the same dimensions, component count, and scalar type. The filter compares the number of bytes per pixel and the dimensions of each page it reads with page 0. It does not compare component counts or scalar types. A change in component count or scalar type can go undetected when the number of bytes per pixel stays the same. This can cause incorrect pixel values. + +If the first page is 8-bit RGB and a later page is 8-bit grayscale, the filter fails with error `-2007` when it reads that later page. The number of bytes per pixel differs (3 and 1), so it fails before it copies any pixels of that page. This intentionally differs from DREAM3D 6.5.171, which could crash on mixed-page TIFF files (KI-053). ### NRRD Volumes diff --git a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/Algorithms/ReadImage.cpp b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/Algorithms/ReadImage.cpp index 2ae05cc571..28232b156f 100644 --- a/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/Algorithms/ReadImage.cpp +++ b/src/Plugins/NXImageProcessing/src/NXImageProcessing/Filters/Algorithms/ReadImage.cpp @@ -330,10 +330,9 @@ Result<> ReadRasterBackend(DataStructure& dataStructure, const ReadImageInputVal const usize sourcePage = stream.singlePageOnly ? 0 : (stream.zStart + dz); const usize destSliceBase = dz * sliceElements; - // Per-page geometry check: the destination offsets are computed from page-0-derived dimensions, so a - // page whose dimensions / component count / scalar type differ would silently mis-map. Because the - // IImageIO interface exposes metadata only for page 0, we validate each page against the observed - // extent of its own decoded segments and reject any mismatch rather than mis-sizing the slice. + // Destination offsets use page 0's dimensions and pixel stride. Check each page's decoded segment + // byte counts and observed dimensions against page 0. IImageIO exposes metadata only for page 0, + // so these checks cannot detect different component counts or scalar types with the same byte width. usize observedRows = 0; usize observedColumns = 0; @@ -362,8 +361,8 @@ Result<> ReadRasterBackend(DataStructure& dataStructure, const ReadImageInputVal if(pixels.size() != pixelCount * bytesPerPixel) { // Reject an incompatible segment before forming a span with page 0's pixel stride. - return MakeErrorResult(-2007, fmt::format("Page {} of '{}' has a differing pixel byte count from page 0. Every page of a multi-page volume must share identical dimensions, " - "component count, and scalar type.", + return MakeErrorResult(-2007, fmt::format("Page {} of '{}' has a pixel byte count that differs from page 0. All pages must have the same dimensions, component count, and " + "scalar type.", sourcePage, inputFilePath.string())); } @@ -412,8 +411,8 @@ Result<> ReadRasterBackend(DataStructure& dataStructure, const ReadImageInputVal if(observedRows != stream.srcHeight || observedColumns != stream.srcWidth) { - return MakeErrorResult(-2007, fmt::format("Page {} of '{}' has dimensions {}x{} that do not match page 0 ({}x{}). Every page of a " - "multi-page volume must share identical dimensions, component count, and scalar type.", + return MakeErrorResult(-2007, fmt::format("Page {} of '{}' has dimensions {}x{} that do not match page 0 ({}x{}). All pages must have the same dimensions, component count, and " + "scalar type.", sourcePage, inputFilePath.string(), observedColumns, observedRows, stream.srcWidth, stream.srcHeight)); } if(singlePage) From ae1cab142bac13031b6998d87a2e6903f3475889 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Thu, 5 Nov 2026 11:01:59 -0500 Subject: [PATCH 27/33] REV: AlignSectionsFeatureCentroid - Reject an out-of-range Reference Slice in preflight Preflight rejected only a negative Reference Slice. Since the L04 fix, the shift loops start at slice 0 when Use Reference Slice is on with a nonzero reference, so a one-slice geometry with Reference Slice 1 read past the end of the centroid vectors. A value at or above the Z dimension already did the same on develop for two or more slices. With Use Reference Slice on, preflight now rejects a Reference Slice that is at or above the Z dimension with error -68073. The geometry is read even when Store Alignment Shifts is off. The test covers one and three slices, the values Z and Z-1, and both settings of Use Reference Slice and Store Alignment Shifts. Fixes #1908 item L04 Fixes #1873 item AlignSectionsFeatureCentroidFilter#1 Signed-off-by: Michael Jackson --- .../AlignSectionsFeatureCentroidFilter.cpp | 21 +++++---- .../test/AlignSectionsFeatureCentroidTest.cpp | 47 +++++++++++++++++++ 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AlignSectionsFeatureCentroidFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AlignSectionsFeatureCentroidFilter.cpp index 53b6550dc7..db3715a531 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AlignSectionsFeatureCentroidFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AlignSectionsFeatureCentroidFilter.cpp @@ -29,6 +29,7 @@ constexpr nx::core::int32 k_OutputRepresentationTypeError = -68002; constexpr nx::core::int32 k_InputComponentDimensionError = -68003; constexpr nx::core::int32 k_InputComponentCountError = -68004; constexpr nx::core::int32 k_OutOfRangeReferenceSliceValue = -68064; +constexpr nx::core::int32 k_ReferenceSliceExceedsZDimension = -68073; } // namespace @@ -156,17 +157,21 @@ IFilter::PreflightResult AlignSectionsFeatureCentroidFilter::preflightImpl(const return MakePreflightErrorResult(k_OutOfRangeReferenceSliceValue, fmt::format("Reference Slice value ({}) must be ZERO or greater.", pReferenceSliceValue)); } + const auto* gridGeom = dataStructure.getDataAs(inputImageGeometry); + if(gridGeom == nullptr) + { + return MakePreflightErrorResult(-68070, fmt::format("The selected Image Geometry '{}' was not found or is not an Image Geometry.", inputImageGeometry.toString())); + } + const usize dims = gridGeom->getDimensions().getZ(); + if(filterArgs.value(k_UseReferenceSlice_Key) && static_cast(pReferenceSliceValue) >= dims) + { + return MakePreflightErrorResult(k_ReferenceSliceExceedsZDimension, fmt::format("Reference Slice value ({}) is too large. Image Geometry '{}' has Z dimension {}. Use a value from 0 to {}.", + pReferenceSliceValue, inputImageGeometry.toString(), dims, static_cast(dims) - 1)); + } + // Handle Array Creation if(pStoreAlignmentShifts) { - const auto* gridGeom = dataStructure.getDataAs(inputImageGeometry); - - if(gridGeom == nullptr) - { - return MakePreflightErrorResult(-68070, fmt::format("Store Alignment Shifts was selected, but an invalid image geometry was provided. Input Geometry Path :{}", inputImageGeometry.toString())); - } - - const usize dims = gridGeom->getDimensions().getZ(); auto pAlignmentAMName = filterArgs.value(k_AlignmentAMName_Key); const DataPath amPath = inputImageGeometry.createChildPath(pAlignmentAMName); diff --git a/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp b/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp index cc17a76f37..02f1d74e18 100644 --- a/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp +++ b/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp @@ -342,3 +342,50 @@ TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Empty slices", "[Rec } UnitTest::CheckArraysInheritTupleDims(dataStructure); } + +TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Reference slice bounds", "[SimplnxCore][AlignSectionsFeatureCentroidFilter]") +{ + UnitTest::LoadPlugins(); + using FilterType = AlignSectionsFeatureCentroidFilter; + const usize zDim = GENERATE(usize{1}, usize{3}); + const bool useReference = GENERATE(true, false); + const bool atUpperBound = GENERATE(true, false); + const bool storeShifts = GENERATE(false, true); + // Z slices have exactly the integer indices 0 through Z-1. Z itself is not an index. + const int32 reference = static_cast(atUpperBound ? zDim : zDim - 1); + CAPTURE(zDim, useReference, reference, storeShifts); + DataStructure dataStructure; + auto* geom = ImageGeom::Create(dataStructure, "Image"); + REQUIRE(geom != nullptr); + geom->setDimensions({3, 3, zDim}); + auto* cells = AttributeMatrix::Create(dataStructure, "Cells", ShapeType{zDim, 3, 3}, geom->getId()); + REQUIRE(cells != nullptr); + geom->setCellData(*cells); + REQUIRE(UInt8Array::Create(dataStructure, "Mask", std::make_shared>(ShapeType{zDim, 3, 3}, ShapeType{1}, 0), cells->getId()) != nullptr); + + FilterType filter; + Arguments args; + args.insertOrAssign(FilterType::k_SelectedImageGeometryPath_Key, std::make_any(DataPath({"Image"}))); + args.insertOrAssign(FilterType::k_MaskArrayPath_Key, std::make_any(DataPath({"Image", "Cells", "Mask"}))); + args.insertOrAssign(FilterType::k_UseReferenceSlice_Key, std::make_any(useReference)); + args.insertOrAssign(FilterType::k_ReferenceSlice_Key, std::make_any(reference)); + args.insertOrAssign(FilterType::k_StoreAlignmentShifts_Key, std::make_any(storeShifts)); + // Stop at preflight: invalid references must never reach the alignment algorithm. + IFilter::PreflightResult result; + REQUIRE_NOTHROW(result = filter.preflight(dataStructure, args)); + if(useReference && atUpperBound) + { + SIMPLNX_RESULT_REQUIRE_INVALID(result.outputActions); + REQUIRE(result.outputActions.errors().size() == 1); + const auto& error = result.outputActions.errors()[0]; + REQUIRE(error.code == -68073); + CHECK(error.message.find(fmt::format("Reference Slice value ({}) is too large.", reference)) != std::string::npos); + CHECK(error.message.find(fmt::format("Z dimension {}", zDim)) != std::string::npos); + CHECK(error.message.find(fmt::format("0 to {}", zDim - 1)) != std::string::npos); + } + else + { + SIMPLNX_RESULT_REQUIRE_VALID(result.outputActions); + } + UnitTest::CheckArraysInheritTupleDims(dataStructure); +} From 4533bbc8693d4c55484ee827857c8f8b1518ccef Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Thu, 5 Nov 2026 11:05:09 -0500 Subject: [PATCH 28/33] DOC: ProjectionImageFilters - Qualify which objects warning -8343 names The seven projection pages said that warning -8343 names every discarded object. When the input array is outside Cell Data, a Cell Data array with the same name as the input is discarded but is not named, because the Cell Data loop skips children by name. The pages now state this exception. The code is unchanged; #1917 item M31 tracks the fix. Signed-off-by: Michael Jackson --- .../NXImageProcessing/docs/BinaryProjectionImageFilter.md | 2 +- .../NXImageProcessing/docs/MaximumProjectionImageFilter.md | 2 +- src/Plugins/NXImageProcessing/docs/MeanProjectionImageFilter.md | 2 +- .../NXImageProcessing/docs/MedianProjectionImageFilter.md | 2 +- .../NXImageProcessing/docs/MinimumProjectionImageFilter.md | 2 +- .../docs/StandardDeviationProjectionImageFilter.md | 2 +- src/Plugins/NXImageProcessing/docs/SumProjectionImageFilter.md | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Plugins/NXImageProcessing/docs/BinaryProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/BinaryProjectionImageFilter.md index 10dd512f47..d3c441c9af 100644 --- a/src/Plugins/NXImageProcessing/docs/BinaryProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/BinaryProjectionImageFilter.md @@ -14,7 +14,7 @@ The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. The **Foreground Value** and **Background Value** are supplied as floating-point numbers and cast to the input element type; the foreground equality test is performed in the input element type. This matches the legacy ITK Binary Projection accumulator, which initializes each column to background and switches it to foreground the first time a voxel equal to the foreground value is encountered. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names the discarded objects by their full paths, including other children of the geometry such as Cell Feature Data. There is one exception when the input array is outside Cell Data. A Cell Data array with the same name as the input array is discarded but is not named in the warning. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the scalar numeric types (`int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`, `float32`, or `float64`). This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Binary Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/MaximumProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/MaximumProjectionImageFilter.md index da6c772431..ca1e8c83c4 100644 --- a/src/Plugins/NXImageProcessing/docs/MaximumProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/MaximumProjectionImageFilter.md @@ -12,7 +12,7 @@ Collapses the selected **Projection Dimension** of a scalar Image Geometry to a The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names the discarded objects by their full paths, including other children of the geometry such as Cell Feature Data. There is one exception when the input array is outside Cell Data. A Cell Data array with the same name as the input array is discarded but is not named in the warning. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the supported types: `uint8`, `int16`, `uint16`, or `float32`. This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Maximum Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/MeanProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/MeanProjectionImageFilter.md index ac4e0513f1..740cac7c6b 100644 --- a/src/Plugins/NXImageProcessing/docs/MeanProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/MeanProjectionImageFilter.md @@ -14,7 +14,7 @@ The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. The output element type is always **Float64** (double), regardless of the input element type, matching the legacy ITK Mean Projection Image Filter (the mean of an integer column is generally not an integer). The mean is accumulated with a Kahan-compensated running sum so that long columns do not lose precision. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names the discarded objects by their full paths, including other children of the geometry such as Cell Feature Data. There is one exception when the input array is outside Cell Data. A Cell Data array with the same name as the input array is discarded but is not named in the warning. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the scalar numeric types (`int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`, `float32`, or `float64`). This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Mean Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/MedianProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/MedianProjectionImageFilter.md index f33d0e3029..f4ebce71fe 100644 --- a/src/Plugins/NXImageProcessing/docs/MedianProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/MedianProjectionImageFilter.md @@ -12,7 +12,7 @@ Collapses the selected **Projection Dimension** of a scalar Image Geometry to a The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names the discarded objects by their full paths, including other children of the geometry such as Cell Feature Data. There is one exception when the input array is outside Cell Data. A Cell Data array with the same name as the input array is discarded but is not named in the warning. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the supported types: `uint8`, `int16`, `uint16`, or `float32`. This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Median Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/MinimumProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/MinimumProjectionImageFilter.md index 4a5e0f2bea..ae18506d7f 100644 --- a/src/Plugins/NXImageProcessing/docs/MinimumProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/MinimumProjectionImageFilter.md @@ -12,7 +12,7 @@ Collapses the selected **Projection Dimension** of a scalar Image Geometry to a The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names the discarded objects by their full paths, including other children of the geometry such as Cell Feature Data. There is one exception when the input array is outside Cell Data. A Cell Data array with the same name as the input array is discarded but is not named in the warning. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the supported types: `uint8`, `int16`, `uint16`, or `float32`. This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Minimum Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/StandardDeviationProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/StandardDeviationProjectionImageFilter.md index b24f7f3168..95f542bf4b 100644 --- a/src/Plugins/NXImageProcessing/docs/StandardDeviationProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/StandardDeviationProjectionImageFilter.md @@ -14,7 +14,7 @@ The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. The standard deviation is the *sample* standard deviation: the column mean is formed with the population divisor *N*, but the sum of squared deviations is divided by *N − 1* before taking the square root, matching the legacy ITK Standard Deviation Projection Image Filter. A column of length 1 (or a degenerate projected axis) yields 0. The output element type is always **Float64** (double), regardless of the input element type. The statistic uses Welford's online update to avoid cancellation when large values have small differences. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names the discarded objects by their full paths, including other children of the geometry such as Cell Feature Data. There is one exception when the input array is outside Cell Data. A Cell Data array with the same name as the input array is discarded but is not named in the warning. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the scalar numeric types (`int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`, `float32`, or `float64`). This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Standard Deviation Projection Image Filter. diff --git a/src/Plugins/NXImageProcessing/docs/SumProjectionImageFilter.md b/src/Plugins/NXImageProcessing/docs/SumProjectionImageFilter.md index 121e704dae..dc937ead49 100644 --- a/src/Plugins/NXImageProcessing/docs/SumProjectionImageFilter.md +++ b/src/Plugins/NXImageProcessing/docs/SumProjectionImageFilter.md @@ -14,7 +14,7 @@ The **Projection Dimension** selects the collapsed axis: 0 = X, 1 = Y, 2 = Z. The output element type is always **Float64** (double), regardless of the input element type, matching the legacy ITK Sum Projection Image Filter (the sum of an integer column readily overflows a narrow integer type). The sum is accumulated with a Kahan-compensated running sum so that long columns do not lose precision. -When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names every discarded object by its full path, including other children of the geometry such as Cell Feature Data. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. +When **Perform In-Place** is enabled, the input Image Geometry is replaced by the projected (collapsed) geometry containing the output array. Because the whole original geometry is replaced, any *other* arrays that were in its cell-data Attribute Matrix are discarded (they have the original, non-collapsed shape and cannot survive the projection). Preflight warning `-8343` names the discarded objects by their full paths, including other children of the geometry such as Cell Feature Data. There is one exception when the input array is outside Cell Data. A Cell Data array with the same name as the input array is discarded but is not named in the warning. Disable **Perform In-Place** to keep the original geometry: the input geometry is then preserved and the result is written to a newly created geometry named by **Created Image Geometry**, whose cell-data Attribute Matrix name is copied from the input geometry. The input array must be single-component (scalar) and one of the scalar numeric types (`int8`, `uint8`, `int16`, `uint16`, `int32`, `uint32`, `int64`, `uint64`, `float32`, or `float64`). This is an ITK-free, out-of-core-capable reimplementation of the legacy ITK Sum Projection Image Filter. From 857b89faa2978082c277dd74e3d0e22e285fa8c9 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Fri, 13 Nov 2026 11:05:30 -0500 Subject: [PATCH 29/33] REV: Tests - Drop unneeded plugin loading, fix tags and split long comments Address the review of ce1472576: - 1.1: Remove UnitTest::LoadPlugins() from 23 new test cases that construct their filter or utility directly. None of them looks up a filter by UUID, loads a pipeline, runs a filter that gets subfilters from the filter list or uses PreferencesSentinel. The three new projection-filter cases that use PreferencesSentinel keep the call: the sentinel changes the preferences of the Application instance that LoadPlugins() creates, and the cases crash without it. The coding knowledge base rule now names this case. - 2.1: Tag the five new ImageRotationUtilities cases [simplnx]. The new AlignSectionsFeatureCentroid and FeatureFaceCurvature cases now start with [SimplnxCore]. - 2.2: Document the Reference Slice bound and error -68073. - 2.3: Split four comment sentences that were longer than 25 words. Signed-off-by: Michael Jackson Co-Authored-By: Claude Opus 5.5 --- docs/Coding_Knowledge_Base.md | 11 ++++++----- .../test/ReadImageStackTest.cpp | 1 - .../NXImageProcessing/test/ReadImageTest.cpp | 1 - .../test/ReadH5OimDataTest.cpp | 1 - .../test/WriteINLFileTest.cpp | 1 - .../test/WriteStatsGenOdfAngleFileTest.cpp | 1 - .../AlignSectionsFeatureCentroidFilter.md | 2 ++ .../SimplnxCore/test/AddBadDataTest.cpp | 1 - .../test/AlignSectionsFeatureCentroidTest.cpp | 7 ++----- .../ApplyTransformationToGeometryTest.cpp | 1 - .../test/ComputeFeatureClusteringTest.cpp | 1 - .../test/ComputeVectorColorsTest.cpp | 2 -- .../SimplnxCore/test/ExecuteProcessTest.cpp | 2 -- .../test/FeatureFaceCurvatureTest.cpp | 3 +-- .../test/QuickSurfaceMeshFilterTest.cpp | 1 - .../SimplnxCore/test/ReadStlFileTest.cpp | 8 ++------ .../test/ReadVtkStructuredPointsTest.cpp | 8 ++------ .../test/WriteVtkRectilinearGridTest.cpp | 4 ---- .../test/WriteVtkStructuredPointsTest.cpp | 2 -- test/ImageRotationUtilitiesTest.cpp | 19 +++++++++---------- 20 files changed, 24 insertions(+), 53 deletions(-) diff --git a/docs/Coding_Knowledge_Base.md b/docs/Coding_Knowledge_Base.md index 15885e16cc..e1ca2c4164 100644 --- a/docs/Coding_Knowledge_Base.md +++ b/docs/Coding_Knowledge_Base.md @@ -1147,9 +1147,10 @@ set. **Rule:** a test calls `UnitTest::LoadPlugins();` only when it calls `createFilter()` on the filter list, loads a pipeline (`Pipeline::FromJson()`, `FromFile()`, `FromSIMPLJson()`, `FromSIMPLFile()`; every SIMPL backwards-compatibility test does), or runs a filter whose code gets other filters from the filter list (`ReadH5Ebsd` -does). A test that constructs a filter or algorithm directly does not call it. A test that needs it calls it itself: -ctest runs each visible, individually registered `TEST_CASE` in its own process (a few hidden groups, such as -`[.OocStoreContract]`, run together in one). +does), or uses `UnitTest::PreferencesSentinel`, which changes the preferences of the `Application` instance that the +call creates. A test that constructs a filter or algorithm directly and does none of these does not call it. A test +that needs it calls it itself: ctest runs each visible, individually registered `TEST_CASE` in its own process (a few +hidden groups, such as `[.OocStoreContract]`, run together in one). **Example of the broken rule:** the synthetic tuple-mismatch cases of `ComputeAvgCAxesTest.cpp` and `ReplaceElementAttributesWithNeighborValuesTest.cpp` load the plugins although they construct the filter directly, and @@ -1158,8 +1159,8 @@ ctest runs each visible, individually registered `TEST_CASE` in its own process **Why:** the call loads every plugin library and fails the test when one does not load, so an unneeded call makes a test fail for a plugin it does not use. -**What to look for:** `UnitTest::LoadPlugins()` in a test with no UUID lookup, pipeline load or registry-dependent -subfilter. +**What to look for:** `UnitTest::LoadPlugins()` in a test with no UUID lookup, pipeline load, registry-dependent +subfilter or `PreferencesSentinel`. Without the call, a test that uses `PreferencesSentinel` crashes (PR #1915). **Pattern to use:** direct filter construction without plugin loading, as in `test/GeometryTest.cpp`. diff --git a/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp b/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp index c3585bbff9..f278c6bec8 100644 --- a/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp +++ b/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp @@ -1492,7 +1492,6 @@ TEST_CASE("NXImageProcessing::ReadImageStackFilter::MultiPage_FirstPagePerFile", TEST_CASE("ImageProcessing::ReadImageStackFilter::MixedSliceDataTypes", "[ImageProcessing][ReadImageStackFilter]") { - UnitTest::LoadPlugins(); const bool firstSliceIsUint16 = GENERATE(false, true); CAPTURE(firstSliceIsUint16); const fs::path inputDir = fs::path(std::string(unit_test::k_BinaryTestOutputDir.view())) / "ReadImageStackMixedSliceDataTypes"; diff --git a/src/Plugins/NXImageProcessing/test/ReadImageTest.cpp b/src/Plugins/NXImageProcessing/test/ReadImageTest.cpp index 46b9d15f99..c52ea28ed9 100644 --- a/src/Plugins/NXImageProcessing/test/ReadImageTest.cpp +++ b/src/Plugins/NXImageProcessing/test/ReadImageTest.cpp @@ -738,7 +738,6 @@ TEST_CASE("NXImageProcessing::ReadImageFilter: MultiPage_TIFF_ZStack", "[NXImage TEST_CASE("NXImageProcessing::ReadImageFilter: MultiPage_TIFF_RGB_Then_Grayscale_Rejected_Before_Copy", "[NXImageProcessing][ReadImageFilter]") { - UnitTest::LoadPlugins(); const bool convertData = GENERATE(false, true); CAPTURE(convertData); const fs::path tiffPath = ReadImageOutputDir() / "rgb_then_grayscale.tif"; diff --git a/src/Plugins/OrientationAnalysis/test/ReadH5OimDataTest.cpp b/src/Plugins/OrientationAnalysis/test/ReadH5OimDataTest.cpp index 48b6348d79..9d6a02d6bb 100644 --- a/src/Plugins/OrientationAnalysis/test/ReadH5OimDataTest.cpp +++ b/src/Plugins/OrientationAnalysis/test/ReadH5OimDataTest.cpp @@ -87,7 +87,6 @@ void RequireAcquisitionCoordinates(const DataStructure& dataStructure, usize sca TEST_CASE("OrientationAnalysis::ReadH5OimDataFilter: Scan Stacking Order", "[OrientationAnalysis][ReadH5OimDataFilter]") { - UnitTest::LoadPlugins(); const UnitTest::TestFileSentinel testDataSentinel(unit_test::k_TestFilesDir, "7_read_oem_ebsd_h5_files_v3.tar.gz", "7_read_oem_ebsd_h5_files_v3"); const auto sourceFile = fs::path(fmt::format("{}/7_read_oem_ebsd_h5_files_v3/EdaxOIMData.h5", unit_test::k_TestFilesDir)); const auto inputFile = fs::path(unit_test::k_BinaryTestOutputDir.view()) / "ReadH5OimData_StackingOrder.h5"; diff --git a/src/Plugins/OrientationAnalysis/test/WriteINLFileTest.cpp b/src/Plugins/OrientationAnalysis/test/WriteINLFileTest.cpp index 72813f8b7b..2135a3c1e8 100644 --- a/src/Plugins/OrientationAnalysis/test/WriteINLFileTest.cpp +++ b/src/Plugins/OrientationAnalysis/test/WriteINLFileTest.cpp @@ -262,7 +262,6 @@ TEST_CASE("OrientationAnalysis::WriteINLFileFilter: Valid Filter Execution", "[O TEST_CASE("OrientationAnalysis::WriteINLFileFilter: All Laue symmetry codes", "[OrientationAnalysis][WriteINLFileFilter]") { - UnitTest::LoadPlugins(); const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); CAPTURE(scenario); UnitTest::AlgorithmTestScope scope(scenario); diff --git a/src/Plugins/OrientationAnalysis/test/WriteStatsGenOdfAngleFileTest.cpp b/src/Plugins/OrientationAnalysis/test/WriteStatsGenOdfAngleFileTest.cpp index 42211eae94..772ae3dd2c 100644 --- a/src/Plugins/OrientationAnalysis/test/WriteStatsGenOdfAngleFileTest.cpp +++ b/src/Plugins/OrientationAnalysis/test/WriteStatsGenOdfAngleFileTest.cpp @@ -208,7 +208,6 @@ TEST_CASE("OrientationAnalysis::WriteStatsGenOdfAngleFileFilter: analytical Bool TEST_CASE("OrientationAnalysis::WriteStatsGenOdfAngleFileFilter: Colon delimiter writes colon separated rows", "[OrientationAnalysis][WriteStatsGenOdfAngleFileFilter]") { - UnitTest::LoadPlugins(); const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); CAPTURE(scenario); UnitTest::AlgorithmTestScope scope(scenario); diff --git a/src/Plugins/SimplnxCore/docs/AlignSectionsFeatureCentroidFilter.md b/src/Plugins/SimplnxCore/docs/AlignSectionsFeatureCentroidFilter.md index faed33999a..06a45b5efc 100644 --- a/src/Plugins/SimplnxCore/docs/AlignSectionsFeatureCentroidFilter.md +++ b/src/Plugins/SimplnxCore/docs/AlignSectionsFeatureCentroidFilter.md @@ -24,6 +24,8 @@ Unlike the misorientation-based and mutual-information-based alignment methods, If *Use Reference Slice* is enabled, each section is shifted to align with a single fixed reference slice rather than its immediate neighbor. This prevents small errors from accumulating across many sections. +When **Use Reference Slice** is enabled, **Reference Slice** must be between 0 and Z-1, where Z is the geometry's Z dimension. Preflight rejects larger values with error `-68073`. + The highest-Z section is also shifted when the reference slice is not 0. This corrects DREAM3D 6.5.171 behavior, which left that section unchanged. An empty mask section has no finite centroid. If either centroid used for a shift is not finite, the relative shift is zero. In consecutive mode, the cumulative shift stays equal to the previous section's shift. In reference mode, the section stays unchanged. This defines behavior that was undefined in DREAM3D 6.5.171. diff --git a/src/Plugins/SimplnxCore/test/AddBadDataTest.cpp b/src/Plugins/SimplnxCore/test/AddBadDataTest.cpp index 548d7102b8..07dfe68e46 100644 --- a/src/Plugins/SimplnxCore/test/AddBadDataTest.cpp +++ b/src/Plugins/SimplnxCore/test/AddBadDataTest.cpp @@ -233,7 +233,6 @@ TEST_CASE("SimplnxCore::AddBadData: rejects nonnumeric input arrays", "[SimplnxC TEST_CASE("SimplnxCore::AddBadDataFilter: Reject nonnumeric cell arrays", "[SimplnxCore][AddBadDataFilter]") { - UnitTest::LoadPlugins(); const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); CAPTURE(scenario); UnitTest::AlgorithmTestScope scope(scenario); diff --git a/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp b/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp index 02f1d74e18..0bdf7116fb 100644 --- a/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp +++ b/src/Plugins/SimplnxCore/test/AlignSectionsFeatureCentroidTest.cpp @@ -184,9 +184,8 @@ TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Geometry cell tuple } } -TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Nonzero reference top slice", "[Reconstruction][AlignSectionsFeatureCentroidFilter]") +TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Nonzero reference top slice", "[SimplnxCore][AlignSectionsFeatureCentroidFilter]") { - UnitTest::LoadPlugins(); const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); const bool storeShifts = GENERATE(false, true); CAPTURE(scenario, storeShifts); @@ -253,9 +252,8 @@ TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Nonzero reference to UnitTest::CheckArraysInheritTupleDims(dataStructure); } -TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Empty slices", "[Reconstruction][AlignSectionsFeatureCentroidFilter]") +TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Empty slices", "[SimplnxCore][AlignSectionsFeatureCentroidFilter]") { - UnitTest::LoadPlugins(); const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); const bool storeShifts = GENERATE(false, true); const int emptyCase = GENERATE(0, 1, 2); // Empty top, middle, or fixed reference. @@ -345,7 +343,6 @@ TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Empty slices", "[Rec TEST_CASE("SimplnxCore::AlignSectionsFeatureCentroidFilter: Reference slice bounds", "[SimplnxCore][AlignSectionsFeatureCentroidFilter]") { - UnitTest::LoadPlugins(); using FilterType = AlignSectionsFeatureCentroidFilter; const usize zDim = GENERATE(usize{1}, usize{3}); const bool useReference = GENERATE(true, false); diff --git a/src/Plugins/SimplnxCore/test/ApplyTransformationToGeometryTest.cpp b/src/Plugins/SimplnxCore/test/ApplyTransformationToGeometryTest.cpp index 892563cc7d..b6a0b46f58 100644 --- a/src/Plugins/SimplnxCore/test/ApplyTransformationToGeometryTest.cpp +++ b/src/Plugins/SimplnxCore/test/ApplyTransformationToGeometryTest.cpp @@ -1026,7 +1026,6 @@ TEST_CASE("SimplnxCore::ApplyTransformationToGeometryFilter:Manual_Image", "[Sim TEST_CASE("SimplnxCore::ApplyTransformationToGeometryFilter: Uneven scaling keeps the classified source axis", "[SimplnxCore][ApplyTransformationToGeometryFilter]") { - UnitTest::LoadPlugins(); const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); CAPTURE(scenario); diff --git a/src/Plugins/SimplnxCore/test/ComputeFeatureClusteringTest.cpp b/src/Plugins/SimplnxCore/test/ComputeFeatureClusteringTest.cpp index eee1a23524..8081d59de1 100644 --- a/src/Plugins/SimplnxCore/test/ComputeFeatureClusteringTest.cpp +++ b/src/Plugins/SimplnxCore/test/ComputeFeatureClusteringTest.cpp @@ -340,7 +340,6 @@ TEST_CASE("SimplnxCore::ComputeFeatureClustering: positive bin count domain", "[ TEST_CASE("SimplnxCore::ComputeFeatureClusteringFilter: Complete reference pair normalization", "[SimplnxCore][ComputeFeatureClusteringFilter]") { - UnitTest::LoadPlugins(); DataStructure dataStructure; auto* geometry = ImageGeom::Create(dataStructure, "Image"); REQUIRE(geometry != nullptr); diff --git a/src/Plugins/SimplnxCore/test/ComputeVectorColorsTest.cpp b/src/Plugins/SimplnxCore/test/ComputeVectorColorsTest.cpp index 24369f6289..a49ad3903c 100644 --- a/src/Plugins/SimplnxCore/test/ComputeVectorColorsTest.cpp +++ b/src/Plugins/SimplnxCore/test/ComputeVectorColorsTest.cpp @@ -29,8 +29,6 @@ const std::string k_VecColorsNX = "Vector Colors"; TEST_CASE("SimplnxCore::ComputeVectorColorsFilter: Rounded full-turn trend stays red", "[SimplnxCore][ComputeVectorColorsFilter]") { - UnitTest::LoadPlugins(); - DataStructure dataStructure; const DataPath vectorsPath({"Vectors"}); auto vectorsStore = DataStoreUtilities::CreateDataStore(dataStructure, vectorsPath, {1}, {3}); diff --git a/src/Plugins/SimplnxCore/test/ExecuteProcessTest.cpp b/src/Plugins/SimplnxCore/test/ExecuteProcessTest.cpp index 7c1d5ab259..25007c9336 100644 --- a/src/Plugins/SimplnxCore/test/ExecuteProcessTest.cpp +++ b/src/Plugins/SimplnxCore/test/ExecuteProcessTest.cpp @@ -150,8 +150,6 @@ TEST_CASE("SimplnxCore::ExecuteProcessFilter: SIMPL Backwards Compatibility", "[ TEST_CASE("SimplnxCore::ExecuteProcessFilter: Argument separator regression", "[SimplnxCore][ExecuteProcessFilter]") { - UnitTest::LoadPlugins(); - // Oracle: spaces outside quotes separate tokens; spaces inside quotes are literal. // Each command below therefore has exactly the explicitly listed arguments. const std::vector>> cases = { diff --git a/src/Plugins/SimplnxCore/test/FeatureFaceCurvatureTest.cpp b/src/Plugins/SimplnxCore/test/FeatureFaceCurvatureTest.cpp index 24fc7530ad..3bffd87709 100644 --- a/src/Plugins/SimplnxCore/test/FeatureFaceCurvatureTest.cpp +++ b/src/Plugins/SimplnxCore/test/FeatureFaceCurvatureTest.cpp @@ -268,9 +268,8 @@ TEST_CASE("SimplnxCore::FeatureFaceCurvatureFilter: NaN patch data", "[FeatureFa UnitTest::CheckArraysInheritTupleDims(dataStructure); } -TEST_CASE("SimplnxCore::FeatureFaceCurvatureFilter: Single triangle face", "[FeatureFaceCurvatureFilter][SingleTriangle]") +TEST_CASE("SimplnxCore::FeatureFaceCurvatureFilter: Single triangle face", "[SimplnxCore][FeatureFaceCurvatureFilter][SingleTriangle]") { - UnitTest::LoadPlugins(); const bool useNormals = GENERATE(false, true); const bool optionalOutputs = GENERATE(false, true); CAPTURE(useNormals, optionalOutputs); diff --git a/src/Plugins/SimplnxCore/test/QuickSurfaceMeshFilterTest.cpp b/src/Plugins/SimplnxCore/test/QuickSurfaceMeshFilterTest.cpp index ea9577fce1..a8761c73d5 100644 --- a/src/Plugins/SimplnxCore/test/QuickSurfaceMeshFilterTest.cpp +++ b/src/Plugins/SimplnxCore/test/QuickSurfaceMeshFilterTest.cpp @@ -177,7 +177,6 @@ TEST_CASE("SimplnxCore::QuickSurfaceMeshFilter: Rectilinear Grid without a Cell TEST_CASE("SimplnxCore::QuickSurfaceMeshFilter: Transferred sides match face labels", "[SimplnxCore][QuickSurfaceMeshFilter]") { - UnitTest::LoadPlugins(); const auto scenario = GENERATE(from_range(UnitTest::SelectAlgorithmTestScenariosForInMemoryStores())); const usize axis = GENERATE(0, 1, 2); const bool ascending = GENERATE(false, true); diff --git a/src/Plugins/SimplnxCore/test/ReadStlFileTest.cpp b/src/Plugins/SimplnxCore/test/ReadStlFileTest.cpp index ddb9277970..035f377458 100644 --- a/src/Plugins/SimplnxCore/test/ReadStlFileTest.cpp +++ b/src/Plugins/SimplnxCore/test/ReadStlFileTest.cpp @@ -167,8 +167,6 @@ TEST_CASE("SimplnxCore::ReadStlFileFilter:Valid_File", "[SimplnxCore][ReadStlFil TEST_CASE("SimplnxCore::ReadStlFileFilter:CorruptTriangleCount", "[SimplnxCore][ReadStlFileFilter]") { - UnitTest::LoadPlugins(); - const fs::path inputFile = fs::path(unit_test::k_BinaryTestOutputDir.view()) / "ReadStlFileTest" / "corrupt_triangle_count.stl"; WriteBinaryStlFile(inputFile, "Corrupt triangle count", 0x7FFFFFFF, std::vector(1)); @@ -422,12 +420,10 @@ TEST_CASE("SimplnxCore::ReadStlFileFilter:ShortFileWithAttributePayload", "[Simp TEST_CASE("SimplnxCore::ReadStlFileFilter:TruncatedRecordAfterPayload", "[SimplnxCore][ReadStlFileFilter]") { - UnitTest::LoadPlugins(); - const DataPath triangleGeomDataPath({"[Triangle Geometry]"}); - // Triangle 0 carries 10 real payload bytes, so the file is larger than 84 + 50 * 2 = 184 bytes and - // passes the minimum size check with the attribute counts honored. Triangle 1 starts at byte + // Triangle 0 contains 10 payload bytes. The file exceeds the 184-byte minimum for two records, + // so the reader honors attribute counts. Triangle 1 starts at byte // 84 + 50 + 10 = 144 and is cut short, so the read loop itself must report where it stopped. // - 44 trailing bytes (file size 188): only 11 of the 12 floats can be read. // - 48 trailing bytes (file size 192): the 12 floats are read, the 2 byte attribute count is not. diff --git a/src/Plugins/SimplnxCore/test/ReadVtkStructuredPointsTest.cpp b/src/Plugins/SimplnxCore/test/ReadVtkStructuredPointsTest.cpp index dab092a1ab..828f1cf5c2 100644 --- a/src/Plugins/SimplnxCore/test/ReadVtkStructuredPointsTest.cpp +++ b/src/Plugins/SimplnxCore/test/ReadVtkStructuredPointsTest.cpp @@ -98,8 +98,6 @@ void WriteSectionValues(std::ostream& output, nonstd::span values, bool TEST_CASE("SimplnxCore::ReadVtkStructuredPointsFilter: Singleton and Zero Dimensions", "[SimplnxCore][ReadVtkStructuredPointsFilter]") { - UnitTest::LoadPlugins(); - const fs::path filePath = fs::path(unit_test::k_BinaryDir.view()) / "ReadVtkDimensions.vtk"; auto fileGuard = MakeScopeGuard([&filePath]() noexcept { std::error_code errorCode; @@ -201,13 +199,11 @@ TEST_CASE("SimplnxCore::ReadVtkStructuredPointsFilter: Singleton and Zero Dimens TEST_CASE("SimplnxCore::ReadVtkStructuredPointsFilter: Singleton Axis Physical Position", "[SimplnxCore][ReadVtkStructuredPointsFilter]") { - UnitTest::LoadPlugins(); - const bool binary = GENERATE(false, true); const usize grid = GENERATE(0, 1, 2, 3, 4); CAPTURE(binary, grid); - // Hand calculation: for origin (2, 6, 10) and spacing (2, 6, 4), a singleton - // axis needs origin - spacing/2 so its voxel center stays at the VTK point. + // Hand calculation: The origin is (2, 6, 10), and spacing is (2, 6, 4). On a singleton + // axis, subtract half the spacing to center the voxel on the VTK point. // The Z plane therefore has origin Z = 8 and center Z = 10. The next three // cases are X, Y and Z lines; the last is a 3D control with unchanged origin. // Active axes have n-1 cells and retain their original origin and spacing. diff --git a/src/Plugins/SimplnxCore/test/WriteVtkRectilinearGridTest.cpp b/src/Plugins/SimplnxCore/test/WriteVtkRectilinearGridTest.cpp index cc118ac4a6..e5b58dd9d9 100644 --- a/src/Plugins/SimplnxCore/test/WriteVtkRectilinearGridTest.cpp +++ b/src/Plugins/SimplnxCore/test/WriteVtkRectilinearGridTest.cpp @@ -300,8 +300,6 @@ TEST_CASE("SimplnxCore::WriteVtkRectilinearGridFilter: ASCII comparison preserve TEST_CASE("SimplnxCore::WriteVtkRectilinearGridFilter: ASCII small coordinates", "[SimplnxCore][WriteVtkRectilinearGridFilter][VtkAsciiCoordinates]") { - UnitTest::LoadPlugins(); - DataStructure dataStructure; const DataPath imagePath({"SmallImage"}); const DataPath cellPath = imagePath.createChildPath("CellData"); @@ -624,8 +622,6 @@ TEST_CASE("SimplnxCore::WriteVtkRectilinearGridFilter: SIMPL Backwards Compatibi TEST_CASE("SimplnxCore::WriteVtkRectilinearGridFilter: Legacy scalar component limits", "[SimplnxCore][WriteVtkRectilinearGridFilter]") { - UnitTest::LoadPlugins(); - const usize components = GENERATE(1, 2, 3, 4, 5, 6, 9); const bool binary = GENERATE(false, true); CAPTURE(components, binary); diff --git a/src/Plugins/SimplnxCore/test/WriteVtkStructuredPointsTest.cpp b/src/Plugins/SimplnxCore/test/WriteVtkStructuredPointsTest.cpp index ff39b72a75..4bc36f9672 100644 --- a/src/Plugins/SimplnxCore/test/WriteVtkStructuredPointsTest.cpp +++ b/src/Plugins/SimplnxCore/test/WriteVtkStructuredPointsTest.cpp @@ -212,8 +212,6 @@ TEST_CASE("SimplnxCore::WriteVtkStructuredPointsFilter: ASCII correctness", "[Si TEST_CASE("SimplnxCore::WriteVtkStructuredPointsFilter: Legacy scalar component limits", "[SimplnxCore][WriteVtkStructuredPointsFilter]") { - UnitTest::LoadPlugins(); - const usize components = GENERATE(1, 2, 3, 4, 5, 6, 9); const bool binary = GENERATE(false, true); CAPTURE(components, binary); diff --git a/test/ImageRotationUtilitiesTest.cpp b/test/ImageRotationUtilitiesTest.cpp index 093d19d146..62457f5274 100644 --- a/test/ImageRotationUtilitiesTest.cpp +++ b/test/ImageRotationUtilitiesTest.cpp @@ -62,7 +62,7 @@ TEST_CASE("ImageRotationUtilities: Octant offsets match the trilinear corner ord } } -TEST_CASE("ImageRotationUtilities: Scaled three-cycle takes spacing from the scaled source axis", "[ImageRotationUtilities][CreateRotationArgs]") +TEST_CASE("ImageRotationUtilities: Scaled three-cycle takes spacing from the scaled source axis", "[simplnx][ImageRotationUtilities][CreateRotationArgs]") { DataStructure dataStructure; ImageGeom* image = ImageGeom::Create(dataStructure, "Input"); @@ -94,7 +94,7 @@ TEST_CASE("ImageRotationUtilities: Scaled three-cycle takes spacing from the sca } } -TEST_CASE("ImageRotationUtilities: Uneven scaling keeps the classified source axis", "[ImageRotationUtilities][CreateRotationArgs]") +TEST_CASE("ImageRotationUtilities: Uneven scaling keeps the classified source axis", "[simplnx][ImageRotationUtilities][CreateRotationArgs]") { DataStructure dataStructure; ImageGeom* image = ImageGeom::Create(dataStructure, "Input"); @@ -125,7 +125,7 @@ TEST_CASE("ImageRotationUtilities: Uneven scaling keeps the classified source ax } } -TEST_CASE("ImageRotationUtilities: Off-axis scaling keeps the column-based spacing", "[ImageRotationUtilities][CreateRotationArgs]") +TEST_CASE("ImageRotationUtilities: Off-axis scaling keeps the column-based spacing", "[simplnx][ImageRotationUtilities][CreateRotationArgs]") { DataStructure dataStructure; ImageGeom* image = ImageGeom::Create(dataStructure, "Input"); @@ -138,8 +138,8 @@ TEST_CASE("ImageRotationUtilities: Off-axis scaling keeps the column-based spaci ImageRotationUtilities::Matrix4fR transform = ImageRotationUtilities::Matrix4fR::Identity(); transform.block<3, 3>(0, 0) << 2 * c, -c, 0, 2 * c, c, 0, 0, 0, 1; - // The column-based rule selects spacing by each column's largest absolute direction cosine, - // breaking the 45-degree tie toward X, then multiplies by that column's norm. + // Each column selects spacing from its largest absolute direction cosine. A 45-degree tie + // selects X. The result is multiplied by the column norm. // Column norms (2,1,1) therefore give spacing (2*2,2*1,5*1) = (4,2,5). // Source extents are (4,9,20). Rotated XY extents are (2*4+9)/sqrt(2). // nearbyint gives dimensions (round(17/(4*sqrt(2))),round(17/(2*sqrt(2))),4) = (3,6,4). @@ -153,7 +153,7 @@ TEST_CASE("ImageRotationUtilities: Off-axis scaling keeps the column-based spaci } } -TEST_CASE("ImageRotationUtilities: Near-grid three-cycle accepted by Rotate Sample Reference Frame uses source-axis spacing", "[ImageRotationUtilities][CreateRotationArgs]") +TEST_CASE("ImageRotationUtilities: Near-grid three-cycle accepted by Rotate Sample Reference Frame uses source-axis spacing", "[simplnx][ImageRotationUtilities][CreateRotationArgs]") { DataStructure dataStructure; ImageGeom* image = ImageGeom::Create(dataStructure, "Input"); @@ -164,8 +164,8 @@ TEST_CASE("ImageRotationUtilities: Near-grid three-cycle accepted by Rotate Samp // 119.995 degrees about (111) differs from the exact three-cycle by about 5e-5 per entry. // Rotate Sample Reference Frame accepts it as a grid rotation (tolerance 1e-4). - // The exact map is R(x,y,z) = (z,x,y): output X comes from source Z, output Y from source X - // and output Z from source Y. Spacing (2,3,5) becomes (5,2,3) and dimensions (2,3,4) become (4,2,3). + // The exact map is R(x,y,z) = (z,x,y). Output axes X, Y and Z take source axes Z, X and Y. + // Spacing (2,3,5) becomes (5,2,3) and dimensions (2,3,4) become (4,2,3). const ImageRotationUtilities::Matrix4fR transform = ImageRotationUtilities::GenerateRotationTransformationMatrix({1.0F, 1.0F, 1.0F, 119.995F}); const auto args = ImageRotationUtilities::CreateRotationArgs(*image, transform); const std::array expectedSpacing = {5.0F, 2.0F, 3.0F}; @@ -177,9 +177,8 @@ TEST_CASE("ImageRotationUtilities: Near-grid three-cycle accepted by Rotate Samp } } -TEST_CASE("ImageRotationUtilities: Raw grid tolerance accounts for column normalization", "[ImageRotationUtilities][CreateRotationArgs]") +TEST_CASE("ImageRotationUtilities: Raw grid tolerance accounts for column normalization", "[simplnx][ImageRotationUtilities][CreateRotationArgs]") { - UnitTest::LoadPlugins(); DataStructure dataStructure; ImageGeom* imageGeomPtr = ImageGeom::Create(dataStructure, "Input"); REQUIRE(imageGeomPtr != nullptr); From 23eddcf1c9b00ef3906da030039383fae4b0c8b5 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Fri, 13 Nov 2026 11:40:47 -0500 Subject: [PATCH 30/33] REV: NXImageProcessing - Use the renamed plugin prefix in new test names develop renamed the ImageProcessing plugin to NXImageProcessing (#1904). Four test cases that this branch added still used the old ImageProcessing prefix and tag. Rename them to match the rest of the plugin's tests. Signed-off-by: Michael Jackson Co-Authored-By: Claude Opus 5.5 Signed-off-by: Michael Jackson --- .../test/MaximumProjectionImageFilterTest.cpp | 4 ++-- src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp | 2 +- .../test/StandardDeviationProjectionImageFilterTest.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp b/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp index 2b209eca6c..1d224a3436 100644 --- a/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp +++ b/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp @@ -125,7 +125,7 @@ TEST_CASE("NXImageProcessing::MaximumProjectionImageFilter: ITK real-image golde projection_test::RunProjectionMd5ItkGolden("Ramp-Up-Short.nrrd", /*projDim=*/1, /*removeOriginalGeometry=*/true, "5390344262c91e83bc9208b0991a2fc9"); } -TEST_CASE("ImageProcessing::MaximumProjectionImageFilter: Warning names discarded objects", "[ImageProcessing][MaximumProjectionImageFilter]") +TEST_CASE("NXImageProcessing::MaximumProjectionImageFilter: Warning names discarded objects", "[NXImageProcessing][MaximumProjectionImageFilter]") { UnitTest::LoadPlugins(); const UnitTest::PreferencesSentinel prefsSentinel(DataStorageMode::ForceInCore, 0); @@ -187,7 +187,7 @@ TEST_CASE("ImageProcessing::MaximumProjectionImageFilter: Warning names discarde UnitTest::CheckArraysInheritTupleDims(ds); } -TEST_CASE("ImageProcessing::MaximumProjectionImageFilter: Warning excludes an input outside cell data", "[ImageProcessing][MaximumProjectionImageFilter]") +TEST_CASE("NXImageProcessing::MaximumProjectionImageFilter: Warning excludes an input outside cell data", "[NXImageProcessing][MaximumProjectionImageFilter]") { UnitTest::LoadPlugins(); const UnitTest::PreferencesSentinel prefsSentinel(DataStorageMode::ForceInCore, 0); diff --git a/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp b/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp index f278c6bec8..314c0a4750 100644 --- a/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp +++ b/src/Plugins/NXImageProcessing/test/ReadImageStackTest.cpp @@ -1490,7 +1490,7 @@ TEST_CASE("NXImageProcessing::ReadImageStackFilter::MultiPage_FirstPagePerFile", REQUIRE(hasMultiPageWarning); } -TEST_CASE("ImageProcessing::ReadImageStackFilter::MixedSliceDataTypes", "[ImageProcessing][ReadImageStackFilter]") +TEST_CASE("NXImageProcessing::ReadImageStackFilter::MixedSliceDataTypes", "[NXImageProcessing][ReadImageStackFilter]") { const bool firstSliceIsUint16 = GENERATE(false, true); CAPTURE(firstSliceIsUint16); diff --git a/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp b/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp index c24c14e680..735d55bb09 100644 --- a/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp +++ b/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp @@ -265,7 +265,7 @@ TEST_CASE("NXImageProcessing::StandardDeviationProjectionImageFilter: ITK real-i /*tolerance=*/0.0001); } -TEST_CASE("ImageProcessing::StandardDeviationProjectionImageFilter: Warning names discarded objects", "[ImageProcessing][StandardDeviationProjectionImageFilter]") +TEST_CASE("NXImageProcessing::StandardDeviationProjectionImageFilter: Warning names discarded objects", "[NXImageProcessing][StandardDeviationProjectionImageFilter]") { UnitTest::LoadPlugins(); const UnitTest::PreferencesSentinel prefsSentinel(DataStorageMode::ForceInCore, 0); From 66966ce0784469c08c2989a50b09fdb554d9f752 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Fri, 13 Nov 2026 11:50:58 -0500 Subject: [PATCH 31/33] REV: ComputeFeatureClustering - Count every reference pair in the four-bin test develop added the four-bin control test (#1949) with reference-pair counts that omit pairs involving sample point 0, matching the old normalization. This branch counts those pairs, so the RDF values in the test were about 0.2% too high. The new counts come from an independent lattice-cell population enumeration of the seed-5489 sample. It sums 999000 ordered pairs. Signed-off-by: Michael Jackson Co-Authored-By: Claude Opus 5.5 Signed-off-by: Michael Jackson --- src/Plugins/SimplnxCore/test/ComputeFeatureClusteringTest.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Plugins/SimplnxCore/test/ComputeFeatureClusteringTest.cpp b/src/Plugins/SimplnxCore/test/ComputeFeatureClusteringTest.cpp index 8081d59de1..62fd0f49cd 100644 --- a/src/Plugins/SimplnxCore/test/ComputeFeatureClusteringTest.cpp +++ b/src/Plugins/SimplnxCore/test/ComputeFeatureClusteringTest.cpp @@ -264,7 +264,8 @@ TEST_CASE("SimplnxCore::ComputeFeatureClustering: four bins control", "[SimplnxC REQUIRE(maxMin.getSize() == 4); // Distances 1, 2, and 3 each occur twice. The last distance stays in the last bin. // Independent lattice-cell population enumeration gives these ordered reference-pair counts for seed 5489. - const std::array referencePairs = {175186, 53046, 292346, 46722}; + // The enumeration includes all 999000 ordered pairs of the 1000 sample points, including pairs with sample 0. + const std::array referencePairs = {175500, 53124, 292846, 46806}; const std::array observedPairs = {2, 0, 2, 2}; for(usize bin = 0; bin < 4; bin++) { From 4830a1716c35cea6af516851d15c1626b1809be3 Mon Sep 17 00:00:00 2001 From: Jessica Marquis Date: Fri, 13 Nov 2026 12:11:46 -0500 Subject: [PATCH 32/33] REV: Initialize projection test preferences directly Create the Application before constructing PreferencesSentinel in the three projection warning tests. Update the coding knowledge base to explain when tests need application initialization or plugin loading. Signed-off-by: Jessica Marquis --- docs/Coding_Knowledge_Base.md | 14 ++++++++------ .../test/MaximumProjectionImageFilterTest.cpp | 6 ++++-- .../StandardDeviationProjectionImageFilterTest.cpp | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/docs/Coding_Knowledge_Base.md b/docs/Coding_Knowledge_Base.md index e1ca2c4164..ed3cde86cb 100644 --- a/docs/Coding_Knowledge_Base.md +++ b/docs/Coding_Knowledge_Base.md @@ -1147,10 +1147,10 @@ set. **Rule:** a test calls `UnitTest::LoadPlugins();` only when it calls `createFilter()` on the filter list, loads a pipeline (`Pipeline::FromJson()`, `FromFile()`, `FromSIMPLJson()`, `FromSIMPLFile()`; every SIMPL backwards-compatibility test does), or runs a filter whose code gets other filters from the filter list (`ReadH5Ebsd` -does), or uses `UnitTest::PreferencesSentinel`, which changes the preferences of the `Application` instance that the -call creates. A test that constructs a filter or algorithm directly and does none of these does not call it. A test -that needs it calls it itself: ctest runs each visible, individually registered `TEST_CASE` in its own process (a few -hidden groups, such as `[.OocStoreContract]`, run together in one). +does). Each test that needs plugin loading calls it itself. CTest runs each visible, individually registered +`TEST_CASE` in its own process. A few hidden groups, such as `[.OocStoreContract]`, run together in one process. +`UnitTest::PreferencesSentinel` needs an existing `Application` instance. If the test only needs that instance, +call `Application::GetOrCreateInstance()` before constructing the sentinel. **Example of the broken rule:** the synthetic tuple-mismatch cases of `ComputeAvgCAxesTest.cpp` and `ReplaceElementAttributesWithNeighborValuesTest.cpp` load the plugins although they construct the filter directly, and @@ -1160,9 +1160,11 @@ hidden groups, such as `[.OocStoreContract]`, run together in one). test fail for a plugin it does not use. **What to look for:** `UnitTest::LoadPlugins()` in a test with no UUID lookup, pipeline load, registry-dependent -subfilter or `PreferencesSentinel`. Without the call, a test that uses `PreferencesSentinel` crashes (PR #1915). +subfilter, or other need for plugin registration. A `PreferencesSentinel` constructed before the `Application` +instance exists dereferences a null pointer (PR #1915). -**Pattern to use:** direct filter construction without plugin loading, as in `test/GeometryTest.cpp`. +**Pattern to use:** construct filters directly as in `test/GeometryTest.cpp`. For a test that also uses a sentinel, +initialize the `Application` directly as in the projection warning cases in `MaximumProjectionImageFilterTest.cpp`. ### Give Catch2 a bool when you compare file times diff --git a/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp b/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp index 1d224a3436..cdd58058a6 100644 --- a/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp +++ b/src/Plugins/NXImageProcessing/test/MaximumProjectionImageFilterTest.cpp @@ -3,6 +3,8 @@ #include "NXImageProcessing/Filters/MaximumProjectionImageFilter.hpp" +#include "simplnx/Core/Application.hpp" + #include using namespace nx::core; @@ -127,7 +129,7 @@ TEST_CASE("NXImageProcessing::MaximumProjectionImageFilter: ITK real-image golde TEST_CASE("NXImageProcessing::MaximumProjectionImageFilter: Warning names discarded objects", "[NXImageProcessing][MaximumProjectionImageFilter]") { - UnitTest::LoadPlugins(); + Application::GetOrCreateInstance(); const UnitTest::PreferencesSentinel prefsSentinel(DataStorageMode::ForceInCore, 0); // No extra cell array, an extra one, and an old array with the output name (also discarded in place). const std::string extraName = GENERATE(std::string(""), std::string("Extra"), std::string("Output")); @@ -189,7 +191,7 @@ TEST_CASE("NXImageProcessing::MaximumProjectionImageFilter: Warning names discar TEST_CASE("NXImageProcessing::MaximumProjectionImageFilter: Warning excludes an input outside cell data", "[NXImageProcessing][MaximumProjectionImageFilter]") { - UnitTest::LoadPlugins(); + Application::GetOrCreateInstance(); const UnitTest::PreferencesSentinel prefsSentinel(DataStorageMode::ForceInCore, 0); DataStructure ds; const DataPath cellInputPath = ip_test::BuildRampImage(ds, 3, 0.0, 1.0); diff --git a/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp b/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp index 735d55bb09..e8df7c469f 100644 --- a/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp +++ b/src/Plugins/NXImageProcessing/test/StandardDeviationProjectionImageFilterTest.cpp @@ -3,6 +3,7 @@ #include "NXImageProcessing/Filters/StandardDeviationProjectionImageFilter.hpp" +#include "simplnx/Core/Application.hpp" #include "simplnx/Utilities/ImageProcessing/AxisProjectionEngine.hpp" #include "simplnx/Utilities/ImageProcessing/ProjectionReducers.hpp" @@ -267,7 +268,7 @@ TEST_CASE("NXImageProcessing::StandardDeviationProjectionImageFilter: ITK real-i TEST_CASE("NXImageProcessing::StandardDeviationProjectionImageFilter: Warning names discarded objects", "[NXImageProcessing][StandardDeviationProjectionImageFilter]") { - UnitTest::LoadPlugins(); + Application::GetOrCreateInstance(); const UnitTest::PreferencesSentinel prefsSentinel(DataStorageMode::ForceInCore, 0); // No extra cell array, an extra one, and an old array with the output name (also discarded in place). const std::string extraName = GENERATE(std::string(""), std::string("Extra"), std::string("Output")); From 92823db33bb0c32be9dc73bb43e5790322bb34dd Mon Sep 17 00:00:00 2001 From: Jessica Marquis Date: Fri, 13 Nov 2026 14:00:15 -0500 Subject: [PATCH 33/33] REV: Remove unused include from WriteINLFile tests Signed-off-by: Jessica Marquis --- src/Plugins/OrientationAnalysis/test/WriteINLFileTest.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Plugins/OrientationAnalysis/test/WriteINLFileTest.cpp b/src/Plugins/OrientationAnalysis/test/WriteINLFileTest.cpp index 2135a3c1e8..f8ceb3da30 100644 --- a/src/Plugins/OrientationAnalysis/test/WriteINLFileTest.cpp +++ b/src/Plugins/OrientationAnalysis/test/WriteINLFileTest.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include