From c3be139e2ca0bbbb151d239834e8364ad70aaad1 Mon Sep 17 00:00:00 2001 From: Joey Kleingers Date: Thu, 18 Jul 2024 09:48:13 -0400 Subject: [PATCH] ENH: Allow Crop Image Geometry to only crop a specific dimension (#1021) Signed-off-by: Joey Kleingers Signed-off-by: Michael Jackson Co-authored-by: Michael Jackson --- .../docs/CropImageGeometryFilter.md | 1 + .../Filters/CropImageGeometryFilter.cpp | 84 +- .../Filters/CropImageGeometryFilter.hpp | 3 + src/Plugins/SimplnxCore/test/CMakeLists.txt | 2 +- .../test/ComputeSurfaceFeaturesTest.cpp | 4 +- ...CreateFeatureArrayFromElementArrayTest.cpp | 4 +- .../test/CropImageGeometryTest.cpp | 1020 ++++++++++++++++- .../test/RequireMinNumNeighborsTest.cpp | 4 +- .../test/ScalarSegmentFeaturesFilterTest.cpp | 4 +- 9 files changed, 1076 insertions(+), 50 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/CropImageGeometryFilter.md b/src/Plugins/SimplnxCore/docs/CropImageGeometryFilter.md index 99b429078b..06955dbc50 100644 --- a/src/Plugins/SimplnxCore/docs/CropImageGeometryFilter.md +++ b/src/Plugins/SimplnxCore/docs/CropImageGeometryFilter.md @@ -4,6 +4,7 @@ This **Filter** allows the user to crop a region of interest (ROI) from an **Image Geometry**. The input parameters are in units of voxels or physical coordinates. +It is possible to also crop specific dimensions of the **Image Geometry** by toggling **Crop X Dimension**, **Crop Y Dimension**, and **Crop Z Dimension** ON and OFF. ## WARNING: NeighborList Removal diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropImageGeometryFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropImageGeometryFilter.cpp index 22d9056e67..7e59ec80fd 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropImageGeometryFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropImageGeometryFilter.cpp @@ -185,6 +185,9 @@ Parameters CropImageGeometryFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insertLinkableParameter( std::make_unique(k_UsePhysicalBounds_Key, "Use Physical Units For Bounds", "If true define physical coordinates for bounds, If false define voxel indices for bounds", false)); + params.insert(std::make_unique(k_CropXDim_Key, "Crop X Dimension", "Enable cropping in the X dimension.", true)); + params.insert(std::make_unique(k_CropYDim_Key, "Crop Y Dimension", "Enable cropping in the Y dimension.", true)); + params.insert(std::make_unique(k_CropZDim_Key, "Crop Z Dimension", "Enable cropping in the Z dimension.", true)); params.insert(std::make_unique(k_MinVoxel_Key, "Min Voxel", "Lower bound of voxels of the volume to crop out", std::vector{0, 0, 0}, std::vector{"X (Column)", "Y (Row)", "Z (Plane)"})); params.insert(std::make_unique(k_MaxVoxel_Key, "Max Voxel [Inclusive]", "Upper bound in voxels of the volume to crop out", std::vector{0, 0, 0}, @@ -240,6 +243,11 @@ IFilter::PreflightResult CropImageGeometryFilter::preflightImpl(const DataStruct auto cellFeatureAmPath = filterArgs.value(k_FeatureAttributeMatrixPath_Key); auto pRemoveOriginalGeometry = filterArgs.value(k_RemoveOriginalGeometry_Key); auto pUsePhysicalBounds = filterArgs.value(k_UsePhysicalBounds_Key); + auto pCropXDim = filterArgs.value(k_CropXDim_Key); + auto pCropYDim = filterArgs.value(k_CropYDim_Key); + auto pCropZDim = filterArgs.value(k_CropZDim_Key); + + auto& srcImageGeom = dataStructure.getDataRefAs(srcImagePath); uint64& xMin = s_HeaderCache[m_InstanceId].xMin; uint64& xMax = s_HeaderCache[m_InstanceId].xMax; @@ -248,30 +256,34 @@ IFilter::PreflightResult CropImageGeometryFilter::preflightImpl(const DataStruct uint64& zMax = s_HeaderCache[m_InstanceId].zMax; uint64& zMin = s_HeaderCache[m_InstanceId].zMin; - xMin = minVoxels[0]; - xMax = maxVoxels[0]; - yMax = maxVoxels[1]; - yMin = minVoxels[1]; - zMax = maxVoxels[2]; - zMin = minVoxels[2]; + if(!pCropXDim && !pCropYDim && !pCropZDim) + { + return {MakeErrorResult(-4010, "At least one dimension must be selected to crop!")}; + } - nx::core::Result resultOutputActions; + xMin = pCropXDim ? minVoxels[0] : 0; + xMax = pCropXDim ? maxVoxels[0] : srcImageGeom.getNumXCells() - 1; + yMin = pCropYDim ? minVoxels[1] : 0; + yMax = pCropYDim ? maxVoxels[1] : srcImageGeom.getNumYCells() - 1; + zMin = pCropZDim ? minVoxels[2] : 0; + zMax = pCropZDim ? maxVoxels[2] : srcImageGeom.getNumZCells() - 1; + nx::core::Result resultOutputActions; std::vector preflightUpdatedValues; if(!pUsePhysicalBounds) { - if(xMax < xMin) + if(pCropXDim && xMax < xMin) { - const std::string errMsg = fmt::format("X Max (%1) less than X Min (%2)", xMax, xMin); + const std::string errMsg = fmt::format("X Max ({}) less than X Min ({})", xMax, xMin); return {MakeErrorResult(-5550, errMsg)}; } - if(yMax < yMin) + if(pCropYDim && yMax < yMin) { const std::string errMsg = fmt::format("Y Max ({}) less than Y Min ({})", yMax, yMin); return {MakeErrorResult(-5551, errMsg)}; } - if(zMax < zMin) + if(pCropZDim && zMax < zMin) { const std::string errMsg = fmt::format("Z Max ({}) less than Z Min ({})", zMax, zMin); return {MakeErrorResult(-5552, errMsg)}; @@ -290,7 +302,20 @@ IFilter::PreflightResult CropImageGeometryFilter::preflightImpl(const DataStruct auto min = filterArgs.value(k_MinCoord_Key); // Validate basic information about the coordinates - if(max == min) + bool equalCoords = true; + if(pCropXDim && min[0] != max[0]) + { + equalCoords = false; + } + if(pCropYDim && min[1] != max[1]) + { + equalCoords = false; + } + if(pCropZDim && min[2] != max[2]) + { + equalCoords = false; + } + if(equalCoords) { const std::string errMsg = "All minimum and maximum values are equal. The cropped region would be a ZERO volume. Please change the maximum values to be larger than the minimum values."; return {MakeErrorResult(-50556, errMsg)}; @@ -301,16 +326,17 @@ IFilter::PreflightResult CropImageGeometryFilter::preflightImpl(const DataStruct const Point3Df& maxPoint = bounds.getMaxPoint(); std::vector errLabels = {"X", "Y", "Z"}; + std::vector dimEnabled = {pCropXDim, pCropYDim, pCropZDim}; for(uint8 i = 0; i < 3; i++) { - if(max[i] < min[i]) + if(dimEnabled[i] && max[i] < min[i]) { const std::string errMsg = fmt::format("The max value {} ({}) is lower then the min value {} ({}). Please ensure the maximum value is greater than the minimum value.", errLabels[i], max[i], errLabels[i], min[i]); return {MakeErrorResult(-50559, errMsg)}; } - if(max[i] < minPoint[i] && min[i] < minPoint[i]) + if(dimEnabled[i] && max[i] < minPoint[i] && min[i] < minPoint[i]) { const std::string errMsg = fmt::format( "Both the Minimum and Maximum {} crop values are less than the minimum {} bounds ({}). Please ensure at least part of the crop is within the bounding box of min=[{}] and max=[{}]", @@ -318,7 +344,7 @@ IFilter::PreflightResult CropImageGeometryFilter::preflightImpl(const DataStruct return {MakeErrorResult(-50560, errMsg)}; } - if(max[i] > maxPoint[i] && min[i] > maxPoint[i]) + if(dimEnabled[i] && max[i] > maxPoint[i] && min[i] > maxPoint[i]) { const std::string errMsg = fmt::format( "Both the Minimum and Maximum {} crop values are greater than the maximum {} bounds ({}). Please ensure at least part of the crop is within the bounding box of min=[{}] and max=[{}]", @@ -326,13 +352,13 @@ IFilter::PreflightResult CropImageGeometryFilter::preflightImpl(const DataStruct return {MakeErrorResult(-50560, errMsg)}; } - if(min[i] < minPoint[i]) + if(dimEnabled[i] && min[i] < minPoint[i]) { resultOutputActions.m_Warnings.push_back( Warning({-50503, fmt::format("The {} minimum crop value {} is less than the {} minimum bounds value of {}. The filter will use the minimum bounds value instead.", errLabels[i], min[i], errLabels[i], minPoint[i])})); } - if(max[i] > maxPoint[i]) + if(dimEnabled[i] && max[i] > maxPoint[i]) { resultOutputActions.m_Warnings.push_back( Warning({-50503, fmt::format("The {} maximum crop value {} is greater than the {} maximum bounds value of {}. The filter will use the maximum bounds value instead.", errLabels[i], max[i], @@ -342,28 +368,28 @@ IFilter::PreflightResult CropImageGeometryFilter::preflightImpl(const DataStruct // if we have made it here the coordinate bounds are valid so figure out and assign index values to xMax, xMin, ... auto srcSpacing = srcImageGeomPtr->getSpacing(); - xMin = (min[0] < srcOrigin[0]) ? 0 : static_cast(std::floor((min[0] - srcOrigin[0]) / spacing[0])); - yMin = (min[1] < srcOrigin[1]) ? 0 : static_cast(std::floor((min[1] - srcOrigin[1]) / spacing[1])); - zMin = (min[2] < srcOrigin[2]) ? 0 : static_cast(std::floor((min[2] - srcOrigin[2]) / spacing[2])); + xMin = (pCropXDim && min[0] >= srcOrigin[0]) ? static_cast(std::floor((min[0] - srcOrigin[0]) / spacing[0])) : 0; + yMin = (pCropYDim && min[1] >= srcOrigin[1]) ? static_cast(std::floor((min[1] - srcOrigin[1]) / spacing[1])) : 0; + zMin = (pCropZDim && min[2] >= srcOrigin[2]) ? static_cast(std::floor((min[2] - srcOrigin[2]) / spacing[2])) : 0; - xMax = (max[0] > maxPoint[0]) ? srcImageGeomPtr->getNumXCells() - 1 : static_cast(std::floor((max[0] - srcOrigin[0]) / spacing[0])); - yMax = (max[1] > maxPoint[1]) ? srcImageGeomPtr->getNumYCells() - 1 : static_cast(std::floor((max[1] - srcOrigin[1]) / spacing[1])); - zMax = (max[2] > maxPoint[2]) ? srcImageGeomPtr->getNumZCells() - 1 : static_cast(std::floor((max[2] - srcOrigin[2]) / spacing[2])); + xMax = (pCropXDim && max[0] <= maxPoint[0]) ? static_cast(std::floor((max[0] - srcOrigin[0]) / spacing[0])) : srcImageGeomPtr->getNumXCells() - 1; + yMax = (pCropYDim && max[1] <= maxPoint[1]) ? static_cast(std::floor((max[1] - srcOrigin[1]) / spacing[1])) : srcImageGeomPtr->getNumYCells() - 1; + zMax = (pCropZDim && max[2] <= maxPoint[2]) ? static_cast(std::floor((max[2] - srcOrigin[2]) / spacing[2])) : srcImageGeomPtr->getNumZCells() - 1; } - if(xMax > srcImageGeomPtr->getNumXCells() - 1) + if(pCropXDim && xMax > srcImageGeomPtr->getNumXCells() - 1) { const std::string errMsg = fmt::format("The X Max ({}) is greater than the Image Geometry X extent ({})", xMax, srcImageGeomPtr->getNumXCells() - 1); return {MakeErrorResult(-5553, errMsg)}; } - if(yMax > srcImageGeomPtr->getNumYCells() - 1) + if(pCropYDim && yMax > srcImageGeomPtr->getNumYCells() - 1) { const std::string errMsg = fmt::format("The Y Max ({}) is greater than the Image Geometry Y extent ({})", yMax, srcImageGeomPtr->getNumYCells() - 1); return {MakeErrorResult(-5554, errMsg)}; } - if(zMax > srcImageGeomPtr->getNumZCells() - 1) + if(pCropZDim && zMax > srcImageGeomPtr->getNumZCells() - 1) { const std::string errMsg = fmt::format("The Z Max ({}) is greater than the Image Geometry Z extent ({})", zMax, srcImageGeomPtr->getNumZCells() - 1); return {MakeErrorResult(-5555, errMsg)}; @@ -441,6 +467,12 @@ IFilter::PreflightResult CropImageGeometryFilter::preflightImpl(const DataStruct } // Store the preflight updated value(s) into the preflightUpdatedValues vector using the appropriate methods. + std::string cropOptionsStr = "This filter will crop the image in the following dimension(s): "; + cropOptionsStr.append(pCropXDim ? "X" : ""); + cropOptionsStr.append(pCropYDim ? "Y" : ""); + cropOptionsStr.append(pCropZDim ? "Z" : ""); + preflightUpdatedValues.push_back({"Crop Dimensions", cropOptionsStr}); + preflightUpdatedValues.push_back({"Input Geometry Info", nx::core::GeometryHelpers::Description::GenerateGeometryInfo(srcImageGeomPtr->getDimensions(), srcImageGeomPtr->getSpacing(), srcImageGeomPtr->getOrigin(), srcImageGeomPtr->getUnits())}); preflightUpdatedValues.push_back( diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropImageGeometryFilter.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropImageGeometryFilter.hpp index 7406f60437..063839131e 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropImageGeometryFilter.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CropImageGeometryFilter.hpp @@ -22,6 +22,9 @@ class SIMPLNXCORE_EXPORT CropImageGeometryFilter : public IFilter // Parameter Keys static inline constexpr StringLiteral k_UsePhysicalBounds_Key = "use_physical_bounds"; + static inline constexpr StringLiteral k_CropXDim_Key = "crop_x_dim"; + static inline constexpr StringLiteral k_CropYDim_Key = "crop_y_dim"; + static inline constexpr StringLiteral k_CropZDim_Key = "crop_z_dim"; static inline constexpr StringLiteral k_MinVoxel_Key = "min_voxel"; static inline constexpr StringLiteral k_MaxVoxel_Key = "max_voxel"; static inline constexpr StringLiteral k_MinCoord_Key = "min_coord"; diff --git a/src/Plugins/SimplnxCore/test/CMakeLists.txt b/src/Plugins/SimplnxCore/test/CMakeLists.txt index feeb0ebf07..aff2cb33d2 100644 --- a/src/Plugins/SimplnxCore/test/CMakeLists.txt +++ b/src/Plugins/SimplnxCore/test/CMakeLists.txt @@ -178,7 +178,7 @@ if(EXISTS "${DREAM3D_DATA_DIR}" AND SIMPLNX_DOWNLOAD_TEST_FILES) file(MAKE_DIRECTORY "${DREAM3D_DATA_DIR}/TestFiles/") endif() - download_test_data(DREAM3D_DATA_DIR ${DREAM3D_DATA_DIR} ARCHIVE_NAME 6_5_test_data_1.tar.gz SHA512 6e21118a882c6a0cc54341eec8928b89ee84ac3a41b1d5b534193f4fabcb49c363db22028055622ad777787be0163cf5525e6c548c11c2c369748feb23031651) + download_test_data(DREAM3D_DATA_DIR ${DREAM3D_DATA_DIR} ARCHIVE_NAME 6_5_test_data_1_v2.tar.gz SHA512 585b51ba1da9784a204fe88073ca562b45afd7007cf451b0193079b885c4b4caff7cf21b13e016433b84155546ac0f73f003a8b8ebb1c58360b2c56de3027d6c) download_test_data(DREAM3D_DATA_DIR ${DREAM3D_DATA_DIR} ARCHIVE_NAME 6_5_Goldfeather.tar.gz SHA512 3ad4a8f2bd578d81ce1ca67213ec846b7de4394e0c0e7796077bac51f7b58ae36340e2abd315665d9ee5fe745315458d5c1559766765e20dbe2c35eb693e8e26) download_test_data(DREAM3D_DATA_DIR ${DREAM3D_DATA_DIR} ARCHIVE_NAME 6_6_align_sections_feature_centroid.tar.gz SHA512 e79a4c8e59bc856d40e91daf4cdce8b82c2e5ccfa6de51e23a0b8c6628282b03701bd5b5d7ddde76c4378142e3d9fe7c1cd6db261360c91751cf7c63747b054b) download_test_data(DREAM3D_DATA_DIR ${DREAM3D_DATA_DIR} ARCHIVE_NAME 6_6_align_sections_feature_centroids.tar.gz SHA512 96ca08eca2ac3839a1d7ded6287c138cac49140d1b80713d747f6143a90b75335b351cd291e2e438621cdfb32bcb5f0ec5bf2f59ec0e0d61250e423f289bdad8) diff --git a/src/Plugins/SimplnxCore/test/ComputeSurfaceFeaturesTest.cpp b/src/Plugins/SimplnxCore/test/ComputeSurfaceFeaturesTest.cpp index e1ab33ade5..896739ae5a 100644 --- a/src/Plugins/SimplnxCore/test/ComputeSurfaceFeaturesTest.cpp +++ b/src/Plugins/SimplnxCore/test/ComputeSurfaceFeaturesTest.cpp @@ -109,10 +109,10 @@ void test_impl(const std::vector& geometryDims, const std::string& featu TEST_CASE("SimplnxCore::ComputeSurfaceFeaturesFilter: 3D", "[SimplnxCore][ComputeSurfaceFeaturesFilter]") { Application::GetOrCreateInstance()->loadPlugins(unit_test::k_BuildDir.view(), true); - const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1.tar.gz", "6_5_test_data_1"); + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); // Read the Small IN100 Data set - auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1/6_5_test_data_1.dream3d", nx::core::unit_test::k_TestFilesDir)); + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); const std::string k_SurfaceFeaturesExemplar("SurfaceFeatures"); diff --git a/src/Plugins/SimplnxCore/test/CreateFeatureArrayFromElementArrayTest.cpp b/src/Plugins/SimplnxCore/test/CreateFeatureArrayFromElementArrayTest.cpp index 5f9cb531ab..a6230ab131 100644 --- a/src/Plugins/SimplnxCore/test/CreateFeatureArrayFromElementArrayTest.cpp +++ b/src/Plugins/SimplnxCore/test/CreateFeatureArrayFromElementArrayTest.cpp @@ -19,10 +19,10 @@ template void testElementArray(const DataPath& cellDataPath) { Application::GetOrCreateInstance()->loadPlugins(unit_test::k_BuildDir.view(), true); - const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1.tar.gz", "6_5_test_data_1"); + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); // Read the Small IN100 Data set - auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1/6_5_test_data_1.dream3d", nx::core::unit_test::k_TestFilesDir)); + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); DataPath smallIn100Group({nx::core::Constants::k_DataContainer}); diff --git a/src/Plugins/SimplnxCore/test/CropImageGeometryTest.cpp b/src/Plugins/SimplnxCore/test/CropImageGeometryTest.cpp index 69573d5728..8aa189a727 100644 --- a/src/Plugins/SimplnxCore/test/CropImageGeometryTest.cpp +++ b/src/Plugins/SimplnxCore/test/CropImageGeometryTest.cpp @@ -16,6 +16,7 @@ using namespace nx::core; namespace { +inline constexpr StringLiteral k_DataContainer("DataContainer2"); struct CompareDataArrayFunctor { @@ -170,19 +171,19 @@ TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter)", "[SimplnxCore] const std::vector k_MaxVector{60, 40, 50}; // static constexpr bool k_UpdateOrigin = false; - const DataPath k_ImageGeomPath({Constants::k_DataContainer}); + const DataPath k_ImageGeomPath({k_DataContainer}); const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); static constexpr bool k_RenumberFeatures = true; - const DataPath k_FeatureIdsPath({Constants::k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); - const DataPath k_CellFeatureAMPath({Constants::k_DataContainer, Constants::k_CellFeatureData}); + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); - const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1.tar.gz", "6_5_test_data_1"); + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); CropImageGeometryFilter filter; // Read the Small IN100 Data set - auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1/6_5_test_data_1.dream3d", nx::core::unit_test::k_TestFilesDir)); + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); Arguments args; @@ -243,24 +244,679 @@ TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter)", "[SimplnxCore] } } +TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter) - XY", "[SimplnxCore][CropImageGeometryFilter]") +{ + Application::GetOrCreateInstance()->loadPlugins(unit_test::k_BuildDir.view(), true); + + const std::vector k_MinVector{10, 15, 0}; + const std::vector k_MaxVector{60, 40, 50}; + + // static constexpr bool k_UpdateOrigin = false; + const DataPath k_ImageGeomPath({k_DataContainer}); + const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); + DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); + static constexpr bool k_RenumberFeatures = true; + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); + DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); + + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); + + CropImageGeometryFilter filter; + // Read the Small IN100 Data set + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); + DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); + Arguments args; + + args.insert(CropImageGeometryFilter::k_MinVoxel_Key, std::make_any>(k_MinVector)); + args.insert(CropImageGeometryFilter::k_MaxVoxel_Key, std::make_any>(k_MaxVector)); + // args.insert(CropImageGeometryFilter::k_UpdateOrigin_Key, std::make_any(k_UpdateOrigin)); + args.insert(CropImageGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); + args.insert(CropImageGeometryFilter::k_CreatedImageGeometryPath_Key, std::make_any(k_NewImageGeomPath)); + args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any(k_RenumberFeatures)); + args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(k_FeatureIdsPath)); + args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any(k_CellFeatureAMPath)); + args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropZDim_Key, std::make_any(false)); + + // Preflight the filter and check result + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + auto result = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + + { + // Write out the DataStructure for later viewing/debugging + Result ioResult = nx::core::HDF5::FileWriter::CreateFile(fmt::format("{}/crop_image_geom_test.dream3d", unit_test::k_BinaryDir)); + nx::core::HDF5::FileWriter fileWriter = std::move(ioResult.value()); + auto resultH5 = HDF5::DataStructureWriter::WriteFile(dataStructure, fileWriter); + SIMPLNX_RESULT_REQUIRE_VALID(resultH5); + } + + auto& imageGeom = dataStructure.getDataRefAs(k_ImageGeomPath); + auto& newImageGeom = dataStructure.getDataRefAs(k_NewImageGeomPath); + auto newDimensions = newImageGeom.getDimensions(); + + for(usize i = 0; i < 2; i++) + { + REQUIRE(newDimensions[i] == (k_MaxVector[i] - k_MinVector[i] + 1)); + } + REQUIRE(newDimensions[2] == imageGeom.getNumZCells()); + + DataPath exemplarGeoPath({"6_5_Cropped_XY_ImageGeom"}); + DataPath exemplarCellDataPath = exemplarGeoPath.createChildPath(Constants::k_CellData); + DataPath exemplarCellFeatureDataPath = exemplarGeoPath.createChildPath(Constants::k_CellFeatureData); + + // check the data arrays + const auto exemplarCellDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellDataPath).value(); + const auto calculatedCellDataArrays = GetAllChildArrayDataPaths(dataStructure, destCellDataPath).value(); + for(usize i = 0; i < exemplarCellDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarCellDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedCellDataArrays[i]); + ::ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } + + const auto exemplarFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellFeatureDataPath).value(); + const auto calculatedFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, k_DestCellFeatureDataPath).value(); + for(usize i = 0; i < exemplarFeatureDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarFeatureDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedFeatureDataArrays[i]); + ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } +} + +TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter) - XZ", "[SimplnxCore][CropImageGeometryFilter]") +{ + Application::GetOrCreateInstance()->loadPlugins(unit_test::k_BuildDir.view(), true); + + const std::vector k_MinVector{10, 15, 0}; + const std::vector k_MaxVector{60, 40, 50}; + + // static constexpr bool k_UpdateOrigin = false; + const DataPath k_ImageGeomPath({k_DataContainer}); + const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); + DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); + static constexpr bool k_RenumberFeatures = true; + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); + DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); + + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); + + CropImageGeometryFilter filter; + // Read the Small IN100 Data set + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); + DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); + Arguments args; + + args.insert(CropImageGeometryFilter::k_MinVoxel_Key, std::make_any>(k_MinVector)); + args.insert(CropImageGeometryFilter::k_MaxVoxel_Key, std::make_any>(k_MaxVector)); + // args.insert(CropImageGeometryFilter::k_UpdateOrigin_Key, std::make_any(k_UpdateOrigin)); + args.insert(CropImageGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); + args.insert(CropImageGeometryFilter::k_CreatedImageGeometryPath_Key, std::make_any(k_NewImageGeomPath)); + args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any(k_RenumberFeatures)); + args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(k_FeatureIdsPath)); + args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any(k_CellFeatureAMPath)); + args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropYDim_Key, std::make_any(false)); + + // Preflight the filter and check result + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + auto result = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + + { + // Write out the DataStructure for later viewing/debugging + Result ioResult = nx::core::HDF5::FileWriter::CreateFile(fmt::format("{}/crop_image_geom_test.dream3d", unit_test::k_BinaryDir)); + nx::core::HDF5::FileWriter fileWriter = std::move(ioResult.value()); + auto resultH5 = HDF5::DataStructureWriter::WriteFile(dataStructure, fileWriter); + SIMPLNX_RESULT_REQUIRE_VALID(resultH5); + } + + auto& imageGeom = dataStructure.getDataRefAs(k_ImageGeomPath); + auto& newImageGeom = dataStructure.getDataRefAs(k_NewImageGeomPath); + auto newDimensions = newImageGeom.getDimensions(); + + REQUIRE(newDimensions[0] == (k_MaxVector[0] - k_MinVector[0] + 1)); + REQUIRE(newDimensions[1] == imageGeom.getNumYCells()); + REQUIRE(newDimensions[2] == (k_MaxVector[2] - k_MinVector[2] + 1)); + + DataPath exemplarGeoPath({"6_5_Cropped_XZ_ImageGeom"}); + DataPath exemplarCellDataPath = exemplarGeoPath.createChildPath(Constants::k_CellData); + DataPath exemplarCellFeatureDataPath = exemplarGeoPath.createChildPath(Constants::k_CellFeatureData); + + // check the data arrays + const auto exemplarCellDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellDataPath).value(); + const auto calculatedCellDataArrays = GetAllChildArrayDataPaths(dataStructure, destCellDataPath).value(); + for(usize i = 0; i < exemplarCellDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarCellDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedCellDataArrays[i]); + ::ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } + + const auto exemplarFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellFeatureDataPath).value(); + const auto calculatedFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, k_DestCellFeatureDataPath).value(); + for(usize i = 0; i < exemplarFeatureDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarFeatureDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedFeatureDataArrays[i]); + ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } +} + +TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter) - YZ", "[SimplnxCore][CropImageGeometryFilter]") +{ + Application::GetOrCreateInstance()->loadPlugins(unit_test::k_BuildDir.view(), true); + + const std::vector k_MinVector{10, 15, 0}; + const std::vector k_MaxVector{60, 40, 50}; + + // static constexpr bool k_UpdateOrigin = false; + const DataPath k_ImageGeomPath({k_DataContainer}); + const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); + DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); + static constexpr bool k_RenumberFeatures = true; + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); + DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); + + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); + + CropImageGeometryFilter filter; + // Read the Small IN100 Data set + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); + DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); + Arguments args; + + args.insert(CropImageGeometryFilter::k_MinVoxel_Key, std::make_any>(k_MinVector)); + args.insert(CropImageGeometryFilter::k_MaxVoxel_Key, std::make_any>(k_MaxVector)); + // args.insert(CropImageGeometryFilter::k_UpdateOrigin_Key, std::make_any(k_UpdateOrigin)); + args.insert(CropImageGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); + args.insert(CropImageGeometryFilter::k_CreatedImageGeometryPath_Key, std::make_any(k_NewImageGeomPath)); + args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any(k_RenumberFeatures)); + args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(k_FeatureIdsPath)); + args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any(k_CellFeatureAMPath)); + args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropXDim_Key, std::make_any(false)); + + // Preflight the filter and check result + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + auto result = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + + { + // Write out the DataStructure for later viewing/debugging + Result ioResult = nx::core::HDF5::FileWriter::CreateFile(fmt::format("{}/crop_image_geom_test.dream3d", unit_test::k_BinaryDir)); + nx::core::HDF5::FileWriter fileWriter = std::move(ioResult.value()); + auto resultH5 = HDF5::DataStructureWriter::WriteFile(dataStructure, fileWriter); + SIMPLNX_RESULT_REQUIRE_VALID(resultH5); + } + + auto& imageGeom = dataStructure.getDataRefAs(k_ImageGeomPath); + auto& newImageGeom = dataStructure.getDataRefAs(k_NewImageGeomPath); + auto newDimensions = newImageGeom.getDimensions(); + + REQUIRE(newDimensions[0] == imageGeom.getNumXCells()); + REQUIRE(newDimensions[1] == (k_MaxVector[1] - k_MinVector[1] + 1)); + REQUIRE(newDimensions[2] == (k_MaxVector[2] - k_MinVector[2] + 1)); + + DataPath exemplarGeoPath({"6_5_Cropped_YZ_ImageGeom"}); + DataPath exemplarCellDataPath = exemplarGeoPath.createChildPath(Constants::k_CellData); + DataPath exemplarCellFeatureDataPath = exemplarGeoPath.createChildPath(Constants::k_CellFeatureData); + + // check the data arrays + const auto exemplarCellDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellDataPath).value(); + const auto calculatedCellDataArrays = GetAllChildArrayDataPaths(dataStructure, destCellDataPath).value(); + for(usize i = 0; i < exemplarCellDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarCellDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedCellDataArrays[i]); + ::ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } + + const auto exemplarFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellFeatureDataPath).value(); + const auto calculatedFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, k_DestCellFeatureDataPath).value(); + for(usize i = 0; i < exemplarFeatureDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarFeatureDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedFeatureDataArrays[i]); + ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } +} + +TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter) - X", "[SimplnxCore][CropImageGeometryFilter]") +{ + Application::GetOrCreateInstance()->loadPlugins(unit_test::k_BuildDir.view(), true); + + const std::vector k_MinVector{10, 15, 0}; + const std::vector k_MaxVector{60, 40, 50}; + + // static constexpr bool k_UpdateOrigin = false; + const DataPath k_ImageGeomPath({k_DataContainer}); + const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); + DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); + static constexpr bool k_RenumberFeatures = true; + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); + DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); + + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); + + CropImageGeometryFilter filter; + // Read the Small IN100 Data set + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); + DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); + Arguments args; + + args.insert(CropImageGeometryFilter::k_MinVoxel_Key, std::make_any>(k_MinVector)); + args.insert(CropImageGeometryFilter::k_MaxVoxel_Key, std::make_any>(k_MaxVector)); + // args.insert(CropImageGeometryFilter::k_UpdateOrigin_Key, std::make_any(k_UpdateOrigin)); + args.insert(CropImageGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); + args.insert(CropImageGeometryFilter::k_CreatedImageGeometryPath_Key, std::make_any(k_NewImageGeomPath)); + args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any(k_RenumberFeatures)); + args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(k_FeatureIdsPath)); + args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any(k_CellFeatureAMPath)); + args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropYDim_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropZDim_Key, std::make_any(false)); + + // Preflight the filter and check result + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + auto result = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + + { + // Write out the DataStructure for later viewing/debugging + Result ioResult = nx::core::HDF5::FileWriter::CreateFile(fmt::format("{}/crop_image_geom_test.dream3d", unit_test::k_BinaryDir)); + nx::core::HDF5::FileWriter fileWriter = std::move(ioResult.value()); + auto resultH5 = HDF5::DataStructureWriter::WriteFile(dataStructure, fileWriter); + SIMPLNX_RESULT_REQUIRE_VALID(resultH5); + } + + auto& imageGeom = dataStructure.getDataRefAs(k_ImageGeomPath); + auto& newImageGeom = dataStructure.getDataRefAs(k_NewImageGeomPath); + auto newDimensions = newImageGeom.getDimensions(); + + REQUIRE(newDimensions[0] == (k_MaxVector[0] - k_MinVector[0] + 1)); + REQUIRE(newDimensions[1] == imageGeom.getNumYCells()); + REQUIRE(newDimensions[2] == imageGeom.getNumZCells()); + + DataPath exemplarGeoPath({"6_5_Cropped_X_ImageGeom"}); + DataPath exemplarCellDataPath = exemplarGeoPath.createChildPath(Constants::k_CellData); + DataPath exemplarCellFeatureDataPath = exemplarGeoPath.createChildPath(Constants::k_CellFeatureData); + + // check the data arrays + const auto exemplarCellDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellDataPath).value(); + const auto calculatedCellDataArrays = GetAllChildArrayDataPaths(dataStructure, destCellDataPath).value(); + for(usize i = 0; i < exemplarCellDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarCellDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedCellDataArrays[i]); + ::ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } + + const auto exemplarFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellFeatureDataPath).value(); + const auto calculatedFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, k_DestCellFeatureDataPath).value(); + for(usize i = 0; i < exemplarFeatureDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarFeatureDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedFeatureDataArrays[i]); + ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } +} + +TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter) - Y", "[SimplnxCore][CropImageGeometryFilter]") +{ + Application::GetOrCreateInstance()->loadPlugins(unit_test::k_BuildDir.view(), true); + + const std::vector k_MinVector{10, 15, 0}; + const std::vector k_MaxVector{60, 40, 50}; + + // static constexpr bool k_UpdateOrigin = false; + const DataPath k_ImageGeomPath({k_DataContainer}); + const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); + DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); + static constexpr bool k_RenumberFeatures = true; + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); + DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); + + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); + + CropImageGeometryFilter filter; + // Read the Small IN100 Data set + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); + DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); + Arguments args; + + args.insert(CropImageGeometryFilter::k_MinVoxel_Key, std::make_any>(k_MinVector)); + args.insert(CropImageGeometryFilter::k_MaxVoxel_Key, std::make_any>(k_MaxVector)); + // args.insert(CropImageGeometryFilter::k_UpdateOrigin_Key, std::make_any(k_UpdateOrigin)); + args.insert(CropImageGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); + args.insert(CropImageGeometryFilter::k_CreatedImageGeometryPath_Key, std::make_any(k_NewImageGeomPath)); + args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any(k_RenumberFeatures)); + args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(k_FeatureIdsPath)); + args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any(k_CellFeatureAMPath)); + args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropXDim_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropZDim_Key, std::make_any(false)); + + // Preflight the filter and check result + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + auto result = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + + { + // Write out the DataStructure for later viewing/debugging + Result ioResult = nx::core::HDF5::FileWriter::CreateFile(fmt::format("{}/crop_image_geom_test.dream3d", unit_test::k_BinaryDir)); + nx::core::HDF5::FileWriter fileWriter = std::move(ioResult.value()); + auto resultH5 = HDF5::DataStructureWriter::WriteFile(dataStructure, fileWriter); + SIMPLNX_RESULT_REQUIRE_VALID(resultH5); + } + + auto& imageGeom = dataStructure.getDataRefAs(k_ImageGeomPath); + auto& newImageGeom = dataStructure.getDataRefAs(k_NewImageGeomPath); + auto newDimensions = newImageGeom.getDimensions(); + + REQUIRE(newDimensions[0] == imageGeom.getNumXCells()); + REQUIRE(newDimensions[1] == (k_MaxVector[1] - k_MinVector[1] + 1)); + REQUIRE(newDimensions[2] == imageGeom.getNumZCells()); + + DataPath exemplarGeoPath({"6_5_Cropped_Y_ImageGeom"}); + DataPath exemplarCellDataPath = exemplarGeoPath.createChildPath(Constants::k_CellData); + DataPath exemplarCellFeatureDataPath = exemplarGeoPath.createChildPath(Constants::k_CellFeatureData); + + // check the data arrays + const auto exemplarCellDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellDataPath).value(); + const auto calculatedCellDataArrays = GetAllChildArrayDataPaths(dataStructure, destCellDataPath).value(); + for(usize i = 0; i < exemplarCellDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarCellDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedCellDataArrays[i]); + ::ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } + + const auto exemplarFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellFeatureDataPath).value(); + const auto calculatedFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, k_DestCellFeatureDataPath).value(); + for(usize i = 0; i < exemplarFeatureDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarFeatureDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedFeatureDataArrays[i]); + ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } +} + +TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter) - Z", "[SimplnxCore][CropImageGeometryFilter]") +{ + Application::GetOrCreateInstance()->loadPlugins(unit_test::k_BuildDir.view(), true); + + const std::vector k_MinVector{10, 15, 0}; + const std::vector k_MaxVector{60, 40, 50}; + + // static constexpr bool k_UpdateOrigin = false; + const DataPath k_ImageGeomPath({k_DataContainer}); + const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); + DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); + static constexpr bool k_RenumberFeatures = true; + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); + DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); + + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); + + CropImageGeometryFilter filter; + // Read the Small IN100 Data set + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); + DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); + Arguments args; + + args.insert(CropImageGeometryFilter::k_MinVoxel_Key, std::make_any>(k_MinVector)); + args.insert(CropImageGeometryFilter::k_MaxVoxel_Key, std::make_any>(k_MaxVector)); + // args.insert(CropImageGeometryFilter::k_UpdateOrigin_Key, std::make_any(k_UpdateOrigin)); + args.insert(CropImageGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); + args.insert(CropImageGeometryFilter::k_CreatedImageGeometryPath_Key, std::make_any(k_NewImageGeomPath)); + args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any(k_RenumberFeatures)); + args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(k_FeatureIdsPath)); + args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any(k_CellFeatureAMPath)); + args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropXDim_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropYDim_Key, std::make_any(false)); + + // Preflight the filter and check result + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + auto result = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + + { + // Write out the DataStructure for later viewing/debugging + Result ioResult = nx::core::HDF5::FileWriter::CreateFile(fmt::format("{}/crop_image_geom_test.dream3d", unit_test::k_BinaryDir)); + nx::core::HDF5::FileWriter fileWriter = std::move(ioResult.value()); + auto resultH5 = HDF5::DataStructureWriter::WriteFile(dataStructure, fileWriter); + SIMPLNX_RESULT_REQUIRE_VALID(resultH5); + } + + auto& imageGeom = dataStructure.getDataRefAs(k_ImageGeomPath); + auto& newImageGeom = dataStructure.getDataRefAs(k_NewImageGeomPath); + auto newDimensions = newImageGeom.getDimensions(); + + REQUIRE(newDimensions[0] == imageGeom.getNumXCells()); + REQUIRE(newDimensions[1] == imageGeom.getNumYCells()); + REQUIRE(newDimensions[2] == (k_MaxVector[2] - k_MinVector[2] + 1)); + + DataPath exemplarGeoPath({"6_5_Cropped_Z_ImageGeom"}); + DataPath exemplarCellDataPath = exemplarGeoPath.createChildPath(Constants::k_CellData); + DataPath exemplarCellFeatureDataPath = exemplarGeoPath.createChildPath(Constants::k_CellFeatureData); + + // check the data arrays + const auto exemplarCellDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellDataPath).value(); + const auto calculatedCellDataArrays = GetAllChildArrayDataPaths(dataStructure, destCellDataPath).value(); + for(usize i = 0; i < exemplarCellDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarCellDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedCellDataArrays[i]); + ::ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } + + const auto exemplarFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellFeatureDataPath).value(); + const auto calculatedFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, k_DestCellFeatureDataPath).value(); + for(usize i = 0; i < exemplarFeatureDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarFeatureDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedFeatureDataArrays[i]); + ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } +} + TEST_CASE("SimplnxCore::CropImageGeometryFilter: Crop Physical Bounds", "[SimplnxCore][CropImageGeometryFilter]") { - const std::vector k_MinVector{10, 15, 0}; - const std::vector k_MaxVector{60, 40, 50}; + const std::vector k_MinVector{-5, 57.5, 30}; + const std::vector k_MaxVector{20, 70, 55}; + + const DataPath k_ImageGeomPath({k_DataContainer}); + const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); + DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); + static constexpr bool k_RenumberFeatures = true; + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); + DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); + + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); + + CropImageGeometryFilter filter; + // Read the Small IN100 Data set + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); + DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); + Arguments args; + + args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any(true)); + args.insert(CropImageGeometryFilter::k_MinCoord_Key, std::make_any>(k_MinVector)); + args.insert(CropImageGeometryFilter::k_MaxCoord_Key, std::make_any>(k_MaxVector)); + args.insert(CropImageGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); + args.insert(CropImageGeometryFilter::k_CreatedImageGeometryPath_Key, std::make_any(k_NewImageGeomPath)); + args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any(k_RenumberFeatures)); + args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(k_FeatureIdsPath)); + args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any(k_CellFeatureAMPath)); + args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any(false)); + + // const auto oldDimensions = dataStructure.getDataRefAs(k_ImageGeomPath).getDimensions(); + // const auto oldOrigin = dataStructure.getDataRefAs(k_ImageGeomPath).getOrigin(); + // const auto oldSpacing = dataStructure.getDataRefAs(k_ImageGeomPath).getSpacing(); + // Preflight the filter and check result + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + auto result = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + + auto& imageGeom = dataStructure.getDataRefAs(k_ImageGeomPath); + auto& newImageGeom = dataStructure.getDataRefAs(k_NewImageGeomPath); + auto origin = imageGeom.getOrigin(); + auto spacing = imageGeom.getSpacing(); + auto newDimensions = newImageGeom.getDimensions(); + + for(usize i = 0; i < 3; i++) + { + auto min = static_cast(std::floor((k_MinVector[i] - origin[i]) / spacing[i])); + auto max = static_cast(std::floor((k_MaxVector[i] - origin[i]) / spacing[i])); + REQUIRE(newDimensions[i] == (max - min + 1)); + } + + DataPath exemplarGeoPath({"6_5_Cropped_ImageGeom"}); + DataPath exemplarCellDataPath = exemplarGeoPath.createChildPath(Constants::k_CellData); + DataPath exemplarCellFeatureDataPath = exemplarGeoPath.createChildPath(Constants::k_CellFeatureData); + + // check the data arrays + const auto exemplarCellDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellDataPath).value(); + const auto calculatedCellDataArrays = GetAllChildArrayDataPaths(dataStructure, destCellDataPath).value(); + for(usize i = 0; i < exemplarCellDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarCellDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedCellDataArrays[i]); + ::ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } + + const auto exemplarFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellFeatureDataPath).value(); + const auto calculatedFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, k_DestCellFeatureDataPath).value(); + for(usize i = 0; i < exemplarFeatureDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarFeatureDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedFeatureDataArrays[i]); + ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } +} + +TEST_CASE("SimplnxCore::CropImageGeometryFilter: Crop XY Physical Bounds", "[SimplnxCore][CropImageGeometryFilter]") +{ + const std::vector k_MinVector{-5, 57.5, 30}; + const std::vector k_MaxVector{20, 70, 55}; + + const DataPath k_ImageGeomPath({k_DataContainer}); + const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); + DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); + static constexpr bool k_RenumberFeatures = true; + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); + DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); + + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); + + CropImageGeometryFilter filter; + // Read the Small IN100 Data set + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); + DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); + Arguments args; + + args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any(true)); + args.insert(CropImageGeometryFilter::k_MinCoord_Key, std::make_any>(k_MinVector)); + args.insert(CropImageGeometryFilter::k_MaxCoord_Key, std::make_any>(k_MaxVector)); + args.insert(CropImageGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); + args.insert(CropImageGeometryFilter::k_CreatedImageGeometryPath_Key, std::make_any(k_NewImageGeomPath)); + args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any(k_RenumberFeatures)); + args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(k_FeatureIdsPath)); + args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any(k_CellFeatureAMPath)); + args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropZDim_Key, std::make_any(false)); + + // const auto oldDimensions = dataStructure.getDataRefAs(k_ImageGeomPath).getDimensions(); + // const auto oldOrigin = dataStructure.getDataRefAs(k_ImageGeomPath).getOrigin(); + // const auto oldSpacing = dataStructure.getDataRefAs(k_ImageGeomPath).getSpacing(); + // Preflight the filter and check result + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + auto result = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + + auto& imageGeom = dataStructure.getDataRefAs(k_ImageGeomPath); + auto& newImageGeom = dataStructure.getDataRefAs(k_NewImageGeomPath); + auto origin = imageGeom.getOrigin(); + auto spacing = imageGeom.getSpacing(); + auto newDimensions = newImageGeom.getDimensions(); + + for(usize i = 0; i < 2; i++) + { + auto min = static_cast(std::floor((k_MinVector[i] - origin[i]) / spacing[i])); + auto max = static_cast(std::floor((k_MaxVector[i] - origin[i]) / spacing[i])); + REQUIRE(newDimensions[i] == (max - min + 1)); + } + REQUIRE(newDimensions[2] == imageGeom.getNumZCells()); + + DataPath exemplarGeoPath({"6_5_Cropped_XY_ImageGeom"}); + DataPath exemplarCellDataPath = exemplarGeoPath.createChildPath(Constants::k_CellData); + DataPath exemplarCellFeatureDataPath = exemplarGeoPath.createChildPath(Constants::k_CellFeatureData); + + // check the data arrays + const auto exemplarCellDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellDataPath).value(); + const auto calculatedCellDataArrays = GetAllChildArrayDataPaths(dataStructure, destCellDataPath).value(); + for(usize i = 0; i < exemplarCellDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarCellDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedCellDataArrays[i]); + ::ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } + + const auto exemplarFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellFeatureDataPath).value(); + const auto calculatedFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, k_DestCellFeatureDataPath).value(); + for(usize i = 0; i < exemplarFeatureDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarFeatureDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedFeatureDataArrays[i]); + ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } +} + +TEST_CASE("SimplnxCore::CropImageGeometryFilter: Crop XZ Physical Bounds", "[SimplnxCore][CropImageGeometryFilter]") +{ + const std::vector k_MinVector{-5, 57.5, 30}; + const std::vector k_MaxVector{20, 70, 55}; - const DataPath k_ImageGeomPath({Constants::k_DataContainer}); + const DataPath k_ImageGeomPath({k_DataContainer}); const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); static constexpr bool k_RenumberFeatures = true; - const DataPath k_FeatureIdsPath({Constants::k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); - const DataPath k_CellFeatureAMPath({Constants::k_DataContainer, Constants::k_CellFeatureData}); + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); - const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1.tar.gz", "6_5_test_data_1"); + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); CropImageGeometryFilter filter; // Read the Small IN100 Data set - auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1/6_5_test_data_1.dream3d", nx::core::unit_test::k_TestFilesDir)); + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); Arguments args; @@ -273,6 +929,7 @@ TEST_CASE("SimplnxCore::CropImageGeometryFilter: Crop Physical Bounds", "[Simpln args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(k_FeatureIdsPath)); args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any(k_CellFeatureAMPath)); args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropYDim_Key, std::make_any(false)); // const auto oldDimensions = dataStructure.getDataRefAs(k_ImageGeomPath).getDimensions(); // const auto oldOrigin = dataStructure.getDataRefAs(k_ImageGeomPath).getOrigin(); @@ -284,15 +941,348 @@ TEST_CASE("SimplnxCore::CropImageGeometryFilter: Crop Physical Bounds", "[Simpln auto result = filter.execute(dataStructure, args); SIMPLNX_RESULT_REQUIRE_VALID(result.result); + auto& imageGeom = dataStructure.getDataRefAs(k_ImageGeomPath); auto& newImageGeom = dataStructure.getDataRefAs(k_NewImageGeomPath); + auto origin = imageGeom.getOrigin(); + auto spacing = imageGeom.getSpacing(); auto newDimensions = newImageGeom.getDimensions(); - for(usize i = 0; i < 3; i++) { - REQUIRE(newDimensions[i] == (k_MaxVector[i] - k_MinVector[i] + 1)); + auto min = static_cast(std::floor((k_MinVector[0] - origin[0]) / spacing[0])); + auto max = static_cast(std::floor((k_MaxVector[0] - origin[0]) / spacing[0])); + REQUIRE(newDimensions[0] == (max - min + 1)); + } + REQUIRE(newDimensions[1] == imageGeom.getNumYCells()); + { + auto min = static_cast(std::floor((k_MinVector[2] - origin[2]) / spacing[2])); + auto max = static_cast(std::floor((k_MaxVector[2] - origin[2]) / spacing[2])); + REQUIRE(newDimensions[2] == (max - min + 1)); } - DataPath exemplarGeoPath({"6_5_Cropped_ImageGeom"}); + DataPath exemplarGeoPath({"6_5_Cropped_XZ_ImageGeom"}); + DataPath exemplarCellDataPath = exemplarGeoPath.createChildPath(Constants::k_CellData); + DataPath exemplarCellFeatureDataPath = exemplarGeoPath.createChildPath(Constants::k_CellFeatureData); + + // check the data arrays + const auto exemplarCellDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellDataPath).value(); + const auto calculatedCellDataArrays = GetAllChildArrayDataPaths(dataStructure, destCellDataPath).value(); + for(usize i = 0; i < exemplarCellDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarCellDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedCellDataArrays[i]); + ::ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } + + const auto exemplarFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellFeatureDataPath).value(); + const auto calculatedFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, k_DestCellFeatureDataPath).value(); + for(usize i = 0; i < exemplarFeatureDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarFeatureDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedFeatureDataArrays[i]); + ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } +} + +TEST_CASE("SimplnxCore::CropImageGeometryFilter: Crop YZ Physical Bounds", "[SimplnxCore][CropImageGeometryFilter]") +{ + const std::vector k_MinVector{-5, 57.5, 30}; + const std::vector k_MaxVector{20, 70, 55}; + + const DataPath k_ImageGeomPath({k_DataContainer}); + const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); + DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); + static constexpr bool k_RenumberFeatures = true; + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); + DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); + + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); + + CropImageGeometryFilter filter; + // Read the Small IN100 Data set + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); + DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); + Arguments args; + + args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any(true)); + args.insert(CropImageGeometryFilter::k_MinCoord_Key, std::make_any>(k_MinVector)); + args.insert(CropImageGeometryFilter::k_MaxCoord_Key, std::make_any>(k_MaxVector)); + args.insert(CropImageGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); + args.insert(CropImageGeometryFilter::k_CreatedImageGeometryPath_Key, std::make_any(k_NewImageGeomPath)); + args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any(k_RenumberFeatures)); + args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(k_FeatureIdsPath)); + args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any(k_CellFeatureAMPath)); + args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropXDim_Key, std::make_any(false)); + + // const auto oldDimensions = dataStructure.getDataRefAs(k_ImageGeomPath).getDimensions(); + // const auto oldOrigin = dataStructure.getDataRefAs(k_ImageGeomPath).getOrigin(); + // const auto oldSpacing = dataStructure.getDataRefAs(k_ImageGeomPath).getSpacing(); + // Preflight the filter and check result + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + auto result = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + + auto& imageGeom = dataStructure.getDataRefAs(k_ImageGeomPath); + auto& newImageGeom = dataStructure.getDataRefAs(k_NewImageGeomPath); + auto origin = imageGeom.getOrigin(); + auto spacing = imageGeom.getSpacing(); + auto newDimensions = newImageGeom.getDimensions(); + + REQUIRE(newDimensions[0] == imageGeom.getNumXCells()); + for(usize i = 1; i < 3; i++) + { + auto min = static_cast(std::floor((k_MinVector[i] - origin[i]) / spacing[i])); + auto max = static_cast(std::floor((k_MaxVector[i] - origin[i]) / spacing[i])); + REQUIRE(newDimensions[i] == (max - min + 1)); + } + + DataPath exemplarGeoPath({"6_5_Cropped_YZ_ImageGeom"}); + DataPath exemplarCellDataPath = exemplarGeoPath.createChildPath(Constants::k_CellData); + DataPath exemplarCellFeatureDataPath = exemplarGeoPath.createChildPath(Constants::k_CellFeatureData); + + // check the data arrays + const auto exemplarCellDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellDataPath).value(); + const auto calculatedCellDataArrays = GetAllChildArrayDataPaths(dataStructure, destCellDataPath).value(); + for(usize i = 0; i < exemplarCellDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarCellDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedCellDataArrays[i]); + ::ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } + + const auto exemplarFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellFeatureDataPath).value(); + const auto calculatedFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, k_DestCellFeatureDataPath).value(); + for(usize i = 0; i < exemplarFeatureDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarFeatureDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedFeatureDataArrays[i]); + ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } +} + +TEST_CASE("SimplnxCore::CropImageGeometryFilter: Crop X Physical Bounds", "[SimplnxCore][CropImageGeometryFilter]") +{ + const std::vector k_MinVector{-5, 57.5, 30}; + const std::vector k_MaxVector{20, 70, 55}; + + const DataPath k_ImageGeomPath({k_DataContainer}); + const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); + DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); + static constexpr bool k_RenumberFeatures = true; + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); + DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); + + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); + + CropImageGeometryFilter filter; + // Read the Small IN100 Data set + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); + DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); + Arguments args; + + args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any(true)); + args.insert(CropImageGeometryFilter::k_MinCoord_Key, std::make_any>(k_MinVector)); + args.insert(CropImageGeometryFilter::k_MaxCoord_Key, std::make_any>(k_MaxVector)); + args.insert(CropImageGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); + args.insert(CropImageGeometryFilter::k_CreatedImageGeometryPath_Key, std::make_any(k_NewImageGeomPath)); + args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any(k_RenumberFeatures)); + args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(k_FeatureIdsPath)); + args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any(k_CellFeatureAMPath)); + args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropYDim_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropZDim_Key, std::make_any(false)); + + // const auto oldDimensions = dataStructure.getDataRefAs(k_ImageGeomPath).getDimensions(); + // const auto oldOrigin = dataStructure.getDataRefAs(k_ImageGeomPath).getOrigin(); + // const auto oldSpacing = dataStructure.getDataRefAs(k_ImageGeomPath).getSpacing(); + // Preflight the filter and check result + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + auto result = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + + auto& imageGeom = dataStructure.getDataRefAs(k_ImageGeomPath); + auto& newImageGeom = dataStructure.getDataRefAs(k_NewImageGeomPath); + auto origin = imageGeom.getOrigin(); + auto spacing = imageGeom.getSpacing(); + auto newDimensions = newImageGeom.getDimensions(); + + { + auto min = static_cast(std::floor((k_MinVector[0] - origin[0]) / spacing[0])); + auto max = static_cast(std::floor((k_MaxVector[0] - origin[0]) / spacing[0])); + REQUIRE(newDimensions[0] == (max - min + 1)); + } + REQUIRE(newDimensions[1] == imageGeom.getNumYCells()); + REQUIRE(newDimensions[2] == imageGeom.getNumZCells()); + + DataPath exemplarGeoPath({"6_5_Cropped_X_ImageGeom"}); + DataPath exemplarCellDataPath = exemplarGeoPath.createChildPath(Constants::k_CellData); + DataPath exemplarCellFeatureDataPath = exemplarGeoPath.createChildPath(Constants::k_CellFeatureData); + + // check the data arrays + const auto exemplarCellDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellDataPath).value(); + const auto calculatedCellDataArrays = GetAllChildArrayDataPaths(dataStructure, destCellDataPath).value(); + for(usize i = 0; i < exemplarCellDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarCellDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedCellDataArrays[i]); + ::ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } + + const auto exemplarFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellFeatureDataPath).value(); + const auto calculatedFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, k_DestCellFeatureDataPath).value(); + for(usize i = 0; i < exemplarFeatureDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarFeatureDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedFeatureDataArrays[i]); + ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } +} + +TEST_CASE("SimplnxCore::CropImageGeometryFilter: Crop Y Physical Bounds", "[SimplnxCore][CropImageGeometryFilter]") +{ + const std::vector k_MinVector{-5, 57.5, 30}; + const std::vector k_MaxVector{20, 70, 55}; + + const DataPath k_ImageGeomPath({k_DataContainer}); + const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); + DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); + static constexpr bool k_RenumberFeatures = true; + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); + DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); + + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); + + CropImageGeometryFilter filter; + // Read the Small IN100 Data set + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); + DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); + Arguments args; + + args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any(true)); + args.insert(CropImageGeometryFilter::k_MinCoord_Key, std::make_any>(k_MinVector)); + args.insert(CropImageGeometryFilter::k_MaxCoord_Key, std::make_any>(k_MaxVector)); + args.insert(CropImageGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); + args.insert(CropImageGeometryFilter::k_CreatedImageGeometryPath_Key, std::make_any(k_NewImageGeomPath)); + args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any(k_RenumberFeatures)); + args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(k_FeatureIdsPath)); + args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any(k_CellFeatureAMPath)); + args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropXDim_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropZDim_Key, std::make_any(false)); + + // const auto oldDimensions = dataStructure.getDataRefAs(k_ImageGeomPath).getDimensions(); + // const auto oldOrigin = dataStructure.getDataRefAs(k_ImageGeomPath).getOrigin(); + // const auto oldSpacing = dataStructure.getDataRefAs(k_ImageGeomPath).getSpacing(); + // Preflight the filter and check result + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + auto result = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + + auto& imageGeom = dataStructure.getDataRefAs(k_ImageGeomPath); + auto& newImageGeom = dataStructure.getDataRefAs(k_NewImageGeomPath); + auto origin = imageGeom.getOrigin(); + auto spacing = imageGeom.getSpacing(); + auto newDimensions = newImageGeom.getDimensions(); + + REQUIRE(newDimensions[0] == imageGeom.getNumXCells()); + { + auto min = static_cast(std::floor((k_MinVector[1] - origin[1]) / spacing[1])); + auto max = static_cast(std::floor((k_MaxVector[1] - origin[1]) / spacing[1])); + REQUIRE(newDimensions[1] == (max - min + 1)); + } + REQUIRE(newDimensions[2] == imageGeom.getNumZCells()); + + DataPath exemplarGeoPath({"6_5_Cropped_Y_ImageGeom"}); + DataPath exemplarCellDataPath = exemplarGeoPath.createChildPath(Constants::k_CellData); + DataPath exemplarCellFeatureDataPath = exemplarGeoPath.createChildPath(Constants::k_CellFeatureData); + + // check the data arrays + const auto exemplarCellDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellDataPath).value(); + const auto calculatedCellDataArrays = GetAllChildArrayDataPaths(dataStructure, destCellDataPath).value(); + for(usize i = 0; i < exemplarCellDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarCellDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedCellDataArrays[i]); + ::ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } + + const auto exemplarFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, exemplarCellFeatureDataPath).value(); + const auto calculatedFeatureDataArrays = GetAllChildArrayDataPaths(dataStructure, k_DestCellFeatureDataPath).value(); + for(usize i = 0; i < exemplarFeatureDataArrays.size(); ++i) + { + const IDataArray& exemplarArray = dataStructure.getDataRefAs(exemplarFeatureDataArrays[i]); + const IDataArray& calculatedArray = dataStructure.getDataRefAs(calculatedFeatureDataArrays[i]); + ExecuteDataFunction(CompareDataArrayFunctor{}, exemplarArray.getDataType(), exemplarArray, calculatedArray); + } +} + +TEST_CASE("SimplnxCore::CropImageGeometryFilter: Crop Z Physical Bounds", "[SimplnxCore][CropImageGeometryFilter]") +{ + const std::vector k_MinVector{-5, 57.5, 30}; + const std::vector k_MaxVector{20, 70, 55}; + + const DataPath k_ImageGeomPath({k_DataContainer}); + const DataPath k_NewImageGeomPath({"7_0_Cropped_ImageGeom"}); + DataPath destCellDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellData); + static constexpr bool k_RenumberFeatures = true; + const DataPath k_FeatureIdsPath({k_DataContainer, Constants::k_CellData, Constants::k_FeatureIds}); + const DataPath k_CellFeatureAMPath({k_DataContainer, Constants::k_CellFeatureData}); + DataPath k_DestCellFeatureDataPath = k_NewImageGeomPath.createChildPath(Constants::k_CellFeatureData); + + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); + + CropImageGeometryFilter filter; + // Read the Small IN100 Data set + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); + DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); + Arguments args; + + args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any(true)); + args.insert(CropImageGeometryFilter::k_MinCoord_Key, std::make_any>(k_MinVector)); + args.insert(CropImageGeometryFilter::k_MaxCoord_Key, std::make_any>(k_MaxVector)); + args.insert(CropImageGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); + args.insert(CropImageGeometryFilter::k_CreatedImageGeometryPath_Key, std::make_any(k_NewImageGeomPath)); + args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any(k_RenumberFeatures)); + args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any(k_FeatureIdsPath)); + args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any(k_CellFeatureAMPath)); + args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropXDim_Key, std::make_any(false)); + args.insert(CropImageGeometryFilter::k_CropYDim_Key, std::make_any(false)); + + // const auto oldDimensions = dataStructure.getDataRefAs(k_ImageGeomPath).getDimensions(); + // const auto oldOrigin = dataStructure.getDataRefAs(k_ImageGeomPath).getOrigin(); + // const auto oldSpacing = dataStructure.getDataRefAs(k_ImageGeomPath).getSpacing(); + // Preflight the filter and check result + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + auto result = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(result.result); + + auto& imageGeom = dataStructure.getDataRefAs(k_ImageGeomPath); + auto& newImageGeom = dataStructure.getDataRefAs(k_NewImageGeomPath); + auto origin = imageGeom.getOrigin(); + auto spacing = imageGeom.getSpacing(); + auto newDimensions = newImageGeom.getDimensions(); + + REQUIRE(newDimensions[0] == imageGeom.getNumXCells()); + REQUIRE(newDimensions[1] == imageGeom.getNumYCells()); + { + auto min = static_cast(std::floor((k_MinVector[2] - origin[2]) / spacing[2])); + auto max = static_cast(std::floor((k_MaxVector[2] - origin[2]) / spacing[2])); + REQUIRE(newDimensions[2] == (max - min + 1)); + } + + DataPath exemplarGeoPath({"6_5_Cropped_Z_ImageGeom"}); DataPath exemplarCellDataPath = exemplarGeoPath.createChildPath(Constants::k_CellData); DataPath exemplarCellFeatureDataPath = exemplarGeoPath.createChildPath(Constants::k_CellFeatureData); diff --git a/src/Plugins/SimplnxCore/test/RequireMinNumNeighborsTest.cpp b/src/Plugins/SimplnxCore/test/RequireMinNumNeighborsTest.cpp index 6e713f39d6..9fb814d624 100644 --- a/src/Plugins/SimplnxCore/test/RequireMinNumNeighborsTest.cpp +++ b/src/Plugins/SimplnxCore/test/RequireMinNumNeighborsTest.cpp @@ -50,9 +50,9 @@ const std::vector k_NumberElements = { TEST_CASE("SimplnxCore::RequireMinNumNeighborsFilter", "[SimplnxCore][RequireMinNumNeighborsFilter]") { - const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1.tar.gz", "6_5_test_data_1"); + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); // Read the Small IN100 Data set - auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1/6_5_test_data_1.dream3d", nx::core::unit_test::k_TestFilesDir)); + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); DataPath smallIn100Group({nx::core::Constants::k_DataContainer}); DataPath cellDataAttributeMatrix = smallIn100Group.createChildPath(k_CellData); diff --git a/src/Plugins/SimplnxCore/test/ScalarSegmentFeaturesFilterTest.cpp b/src/Plugins/SimplnxCore/test/ScalarSegmentFeaturesFilterTest.cpp index bb0b042f74..2ead8e010b 100644 --- a/src/Plugins/SimplnxCore/test/ScalarSegmentFeaturesFilterTest.cpp +++ b/src/Plugins/SimplnxCore/test/ScalarSegmentFeaturesFilterTest.cpp @@ -16,10 +16,10 @@ using namespace nx::core::Constants; TEST_CASE("SimplnxCore::ScalarSegmentFeatures", "[Reconstruction][ScalarSegmentFeatures]") { - const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1.tar.gz", "6_5_test_data_1"); + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "6_5_test_data_1_v2.tar.gz", "6_5_test_data_1_v2"); // Read the Small IN100 Data set - auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1/6_5_test_data_1.dream3d", nx::core::unit_test::k_TestFilesDir)); + auto baseDataFilePath = fs::path(fmt::format("{}/6_5_test_data_1_v2/6_5_test_data_1_v2.dream3d", nx::core::unit_test::k_TestFilesDir)); DataStructure dataStructure = UnitTest::LoadDataStructure(baseDataFilePath); {