Skip to content

Commit

Permalink
ENH: Crop Image Geometry now crops by physical units by default. (#1196)
Browse files Browse the repository at this point in the history
* ENH: Crop Image Geometry now crops by physical units by default.
* Update unit tests


---------

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson authored Feb 11, 2025
1 parent 397ca6f commit cfc842b
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class RunCropImageGeometryImpl
args.insertOrAssign(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any<bool>(false));
args.insertOrAssign(CropImageGeometryFilter::k_SelectedImageGeometryPath_Key, std::make_any<DataPath>(m_ImageGeometryPath));
args.insertOrAssign(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any<bool>(false));
args.insertOrAssign(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any<bool>(false));

args.insertOrAssign(CropImageGeometryFilter::k_MinVoxel_Key, std::make_any<std::vector<uint64>>(m_MinVoxelVector));
args.insertOrAssign(CropImageGeometryFilter::k_MaxVoxel_Key, std::make_any<std::vector<uint64>>(m_MaxVoxelVector));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Parameters CropImageGeometryFilter::parameters() const

params.insertSeparator(Parameters::Separator{"Input Parameter(s)"});
params.insertLinkableParameter(
std::make_unique<BoolParameter>(k_UsePhysicalBounds_Key, "Use Physical Units For Bounds", "If true define physical coordinates for bounds, If false define voxel indices for bounds", false));
std::make_unique<BoolParameter>(k_UsePhysicalBounds_Key, "Use Physical Units For Bounds", "If true define physical coordinates for bounds, If false define voxel indices for bounds", true));
params.insert(std::make_unique<BoolParameter>(k_CropXDim_Key, "Crop X Dimension", "Enable cropping in the X dimension.", true));
params.insert(std::make_unique<BoolParameter>(k_CropYDim_Key, "Crop Y Dimension", "Enable cropping in the Y dimension.", true));
params.insert(std::make_unique<BoolParameter>(k_CropZDim_Key, "Crop Z Dimension", "Enable cropping in the Z dimension.", true));
Expand Down
2 changes: 2 additions & 0 deletions src/Plugins/SimplnxCore/test/AppendImageGeometryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void cropGeometry(DataStructure& dataStructure, const DataPath& selectedPath, co
args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any<DataPath>(DataPath{}));
args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any<bool>(false));

auto executeResult = filter.execute(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result)
Expand Down Expand Up @@ -294,6 +295,7 @@ TEST_CASE("SimplnxCore::AppendImageGeometryFilter: Invalid Filter Execution", "[
cropArgs.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any<bool>(false));
cropArgs.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any<DataPath>(DataPath{}));
cropArgs.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any<bool>(false));
cropArgs.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any<bool>(false));

auto cropResult = cropFilter.execute(dataStructure, cropArgs);
SIMPLNX_RESULT_REQUIRE_VALID(cropResult.result)
Expand Down
9 changes: 9 additions & 0 deletions src/Plugins/SimplnxCore/test/CropImageGeometryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ TEST_CASE("SimplnxCore::CropImageGeometryFilter(Instantiate)", "[SimplnxCore][Cr
args.insert(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any<bool>(k_RenumberFeatures));
args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any<DataPath>(k_FeatureIdsPath));
args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any<bool>(true));
args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any<bool>(false));

// Preflight the filter and check result
auto preflightResult = filter.preflight(dataStructure, args);
Expand Down Expand Up @@ -109,6 +110,7 @@ TEST_CASE("SimplnxCore::CropImageGeometryFilter Invalid Params", "[SimplnxCore][
args.insertOrAssign(CropImageGeometryFilter::k_RenumberFeatures_Key, std::make_any<bool>(k_RenumberFeatures));
args.insertOrAssign(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any<DataPath>(k_FeatureIdsPath));
args.insertOrAssign(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any<bool>(true));
args.insertOrAssign(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any<bool>(false));

// Preflight the filter and check result
auto preflightResult = filter.preflight(dataStructure, args);
Expand Down Expand Up @@ -196,6 +198,7 @@ TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter)", "[SimplnxCore]
args.insert(CropImageGeometryFilter::k_CellFeatureIdsArrayPath_Key, std::make_any<DataPath>(k_FeatureIdsPath));
args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any<DataPath>(k_CellFeatureAMPath));
args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any<bool>(false));
args.insertOrAssign(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any<bool>(false));

// Preflight the filter and check result
auto preflightResult = filter.preflight(dataStructure, args);
Expand Down Expand Up @@ -278,6 +281,7 @@ TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter) - XY", "[Simplnx
args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any<DataPath>(k_CellFeatureAMPath));
args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_CropZDim_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any<bool>(false));

// Preflight the filter and check result
auto preflightResult = filter.preflight(dataStructure, args);
Expand Down Expand Up @@ -362,6 +366,7 @@ TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter) - XZ", "[Simplnx
args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any<DataPath>(k_CellFeatureAMPath));
args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_CropYDim_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any<bool>(false));

// Preflight the filter and check result
auto preflightResult = filter.preflight(dataStructure, args);
Expand Down Expand Up @@ -444,6 +449,7 @@ TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter) - YZ", "[Simplnx
args.insert(CropImageGeometryFilter::k_FeatureAttributeMatrixPath_Key, std::make_any<DataPath>(k_CellFeatureAMPath));
args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_CropXDim_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any<bool>(false));

// Preflight the filter and check result
auto preflightResult = filter.preflight(dataStructure, args);
Expand Down Expand Up @@ -527,6 +533,7 @@ TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter) - X", "[SimplnxC
args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_CropYDim_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_CropZDim_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any<bool>(false));

// Preflight the filter and check result
auto preflightResult = filter.preflight(dataStructure, args);
Expand Down Expand Up @@ -610,6 +617,7 @@ TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter) - Y", "[SimplnxC
args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_CropXDim_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_CropZDim_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any<bool>(false));

// Preflight the filter and check result
auto preflightResult = filter.preflight(dataStructure, args);
Expand Down Expand Up @@ -693,6 +701,7 @@ TEST_CASE("SimplnxCore::CropImageGeometryFilter(Execute_Filter) - Z", "[SimplnxC
args.insert(CropImageGeometryFilter::k_RemoveOriginalGeometry_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_CropXDim_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_CropYDim_Key, std::make_any<bool>(false));
args.insert(CropImageGeometryFilter::k_UsePhysicalBounds_Key, std::make_any<bool>(false));

// Preflight the filter and check result
auto preflightResult = filter.preflight(dataStructure, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
min_voxel=[41, 41, 0],
remove_original_geometry=True,
renumber_features=True,
input_image_geometry_path=nx.DataPath("DataContainer")
input_image_geometry_path=nx.DataPath("DataContainer"),
use_physical_bounds=False
)
nxtest.check_filter_result(nx_filter, result)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
min_voxel=[0, 0, 0],
remove_original_geometry=True,
renumber_features=False,
input_image_geometry_path=nx.DataPath("Cugrid_after 2nd_15kv_2kx_2")
input_image_geometry_path=nx.DataPath("Cugrid_after 2nd_15kv_2kx_2"),
use_physical_bounds=False
# update_origin=True
)
nxtest.check_filter_result(nx_filter, result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
min_voxel=[488, 0, 0],
remove_original_geometry=True,
renumber_features=False,
input_image_geometry_path=nx.DataPath("Cugrid_after 2nd_15kv_2kx_2")
input_image_geometry_path=nx.DataPath("Cugrid_after 2nd_15kv_2kx_2"),
use_physical_bounds=False
)
nxtest.check_filter_result(nx_filter, result)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
min_voxel=[0, 0, 0],
remove_original_geometry=False,
renumber_features=False,
input_image_geometry_path=nx.DataPath("[Image Geometry]")
input_image_geometry_path=nx.DataPath("[Image Geometry]"),
use_physical_bounds=False
#update_origin=False
# cell_feature_attribute_matrix: DataPath = ..., # Not currently part of the code
# feature_ids: DataPath = ..., # Not currently part of the code
Expand All @@ -124,7 +125,8 @@
min_voxel=[0, 0, 51],
remove_original_geometry=False,
renumber_features=False,
input_image_geometry_path=nx.DataPath("[Image Geometry]")
input_image_geometry_path=nx.DataPath("[Image Geometry]"),
use_physical_bounds=False
# update_origin=True
# cell_feature_attribute_matrix: DataPath = ..., # Not currently part of the code
# feature_ids: DataPath = ..., # Not currently part of the code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
min_voxel=[25, 25, 0],
remove_original_geometry=True,
renumber_features=False,
input_image_geometry_path=nx.DataPath("DataContainer")
input_image_geometry_path=nx.DataPath("DataContainer"),
use_physical_bounds=False
# update_origin=False
)
nxtest.check_filter_result(nx_filter, result)
Expand Down

0 comments on commit cfc842b

Please sign in to comment.