From c7b07c4fbc1bc809b674abaf97f89ea469c90b82 Mon Sep 17 00:00:00 2001 From: nyoungbq Date: Tue, 16 Jan 2024 14:30:47 -0500 Subject: [PATCH] Test updates --- .../test/ITKImportImageStackTest.cpp | 152 +++++++++++++----- 1 file changed, 108 insertions(+), 44 deletions(-) diff --git a/src/Plugins/ITKImageProcessing/test/ITKImportImageStackTest.cpp b/src/Plugins/ITKImageProcessing/test/ITKImportImageStackTest.cpp index 19e209950e..a66cb40832 100644 --- a/src/Plugins/ITKImageProcessing/test/ITKImportImageStackTest.cpp +++ b/src/Plugins/ITKImageProcessing/test/ITKImportImageStackTest.cpp @@ -1,6 +1,7 @@ #include #include "ITKImageProcessing/Filters/ITKImportImageStack.hpp" +#include "ITKImageProcessing/Filters/ITKImageReader.hpp" #include "ITKImageProcessing/ITKImageProcessing_test_dirs.hpp" #include "ITKTestBase.hpp" @@ -20,6 +21,7 @@ namespace const std::string k_ImageStackDir = unit_test::k_DataDir.str() + "/ImageStack"; const DataPath k_ImageGeomPath = {{"ImageGeometry"}}; const DataPath k_ImageDataPath = k_ImageGeomPath.createChildPath(ImageGeom::k_CellDataName).createChildPath("ImageData"); +const std::string k_FlippedImageStackDirName = "image_flip_test_images"; void FillFlippedArgs(Arguments& args) { @@ -31,34 +33,55 @@ void FillFlippedArgs(Arguments& args) args.insertOrAssign(ITKImportImageStack::k_ImageGeometryPath_Key, std::make_any(k_ImageGeomPath)); } -Result<> CompareFlippedGeometries(const ImageGeom* baseGeom, const ImageGeom* xFlipGeom, const ImageGeom* yFlipGeom) +void CompareFlippedGeometries(const DataStructure& dataStructure, const ImageGeom* baseGeom, const ImageGeom* xFlipGeom, const ImageGeom* yFlipGeom) { - Result<> result = {}; - REQUIRE(imageGeom != nullptr); + REQUIRE(baseGeom != nullptr); + REQUIRE(xFlipGeom != nullptr); + REQUIRE(yFlipGeom != nullptr); - SizeVec3 imageDims = imageGeom->getDimensions(); - FloatVec3 imageOrigin = imageGeom->getOrigin(); - FloatVec3 imageSpacing = imageGeom->getSpacing(); + SizeVec3 imageDims = baseGeom->getDimensions(); + FloatVec3 imageOrigin = baseGeom->getOrigin(); + FloatVec3 imageSpacing = baseGeom->getSpacing(); - std::array dims = {524, 390, 3}; + SizeVec3 dims = xFlipGeom->getDimensions(); REQUIRE(imageDims[0] == dims[0]); REQUIRE(imageDims[1] == dims[1]); REQUIRE(imageDims[2] == dims[2]); + FloatVec3 origin = xFlipGeom->getOrigin(); + REQUIRE(imageOrigin[0] == Approx(origin[0])); REQUIRE(imageOrigin[1] == Approx(origin[1])); REQUIRE(imageOrigin[2] == Approx(origin[2])); + FloatVec3 spacing = xFlipGeom->getSpacing(); + REQUIRE(imageSpacing[0] == Approx(spacing[0])); REQUIRE(imageSpacing[1] == Approx(spacing[1])); REQUIRE(imageSpacing[2] == Approx(spacing[2])); - const auto* imageData = dataStructure.getDataAs(k_ImageDataPath); - REQUIRE(imageData != nullptr); + dims = yFlipGeom->getDimensions(); + + REQUIRE(imageDims[0] == dims[0]); + REQUIRE(imageDims[1] == dims[1]); + REQUIRE(imageDims[2] == dims[2]); + + origin = yFlipGeom->getOrigin(); + + REQUIRE(imageOrigin[0] == Approx(origin[0])); + REQUIRE(imageOrigin[1] == Approx(origin[1])); + REQUIRE(imageOrigin[2] == Approx(origin[2])); + + spacing = yFlipGeom->getSpacing(); + + REQUIRE(imageSpacing[0] == Approx(spacing[0])); + REQUIRE(imageSpacing[1] == Approx(spacing[1])); + REQUIRE(imageSpacing[2] == Approx(spacing[2])); - return result; + //const auto* imageData = dataStructure.getDataAs(k_ImageDataPath); + //REQUIRE(imageData != nullptr); } } // namespace @@ -197,33 +220,74 @@ TEST_CASE("ITKImageProcessing::ITKImportImageStack: CompareImage", "[ITKImagePro TEST_CASE("ITKImageProcessing::ITKImportImageStack: Flipped Image Even-Even X/Y", "[ITKImageProcessing][ITKImportImageStack]") { - ITKImportImageStack filter; - DataStructure dataStructure; - Arguments args; + const nx::core::UnitTest::TestFileSentinel testDataSentinel(nx::core::unit_test::k_CMakeExecutable, nx::core::unit_test::k_TestFilesDir, "image_flip_test_images.tar.gz", k_FlippedImageStackDirName); - GeneratedFileListParameter::ValueType fileListInfo; - fileListInfo.inputPath = k_ImageStackDir; - fileListInfo.startIndex = 11; - fileListInfo.endIndex = 13; - fileListInfo.incrementIndex = 1; - fileListInfo.fileExtension = ".tif"; - fileListInfo.filePrefix = "slice_"; - fileListInfo.fileSuffix = ""; - fileListInfo.paddingDigits = 2; - fileListInfo.ordering = GeneratedFileListParameter::Ordering::LowToHigh; - - args.insertOrAssign(ITKImportImageStack::k_InputFileListInfo_Key, std::make_any(fileListInfo)); - ::FillFlippedArgs(args); + fs::path k_ImageFlipStackDir = fs::path(fmt::format("{}/{}", unit_test::k_TestFilesDir, k_FlippedImageStackDirName)); + const std::string k_FilePrefix = "image_flip_even_even_"; - auto preflightResult = filter.preflight(dataStructure, args); - SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions) - - auto executeResult = filter.execute(dataStructure, args); - SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result) - - auto compareResult = - ::CompareFlippedGeometries(dataStructure.getDataAs(k_BaseGeomPath), dataStructure.getDataAs(k_XFlippedGeomPath), dataStructure.getDataAs(k_YFlippedGeomPath)); - SIMPLNX_RESULT_REQUIRE_VALID(compareResult.result) + DataStructure dataStructure; + { + ITKImportImageStack filter; + Arguments args; + + GeneratedFileListParameter::ValueType fileListInfo; + fileListInfo.inputPath = k_ImageFlipStackDir; + fileListInfo.startIndex = 1; + fileListInfo.endIndex = 1; + fileListInfo.incrementIndex = 1; + fileListInfo.fileExtension = ".png"; + fileListInfo.filePrefix = k_FilePrefix; + fileListInfo.fileSuffix = ""; + fileListInfo.paddingDigits = 1; + fileListInfo.ordering = GeneratedFileListParameter::Ordering::LowToHigh; + + args.insertOrAssign(ITKImportImageStack::k_InputFileListInfo_Key, std::make_any(fileListInfo)); + ::FillFlippedArgs(args); + + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions) + + auto executeResult = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result) + } + { + ITKImageReader filter; + Arguments args; + + fs::path filePath = k_ImageFlipStackDir / (k_FilePrefix + "flip_x.png"); + DataPath arrayPath{{"ImageGeom", "ImageArray"}}; + DataPath imagePath = arrayPath.getParent(); + args.insertOrAssign(ITKImageReader::k_FileName_Key, filePath); + args.insertOrAssign(ITKImageReader::k_ImageGeometryPath_Key, imagePath); + args.insertOrAssign(ITKImageReader::k_ImageDataArrayPath_Key, arrayPath); + + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions) + + auto executeResult = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result) + } + { + ITKImageReader filter; + Arguments args; + + fs::path filePath = k_ImageFlipStackDir / (k_FilePrefix + "flip_y.png"); + DataPath arrayPath{{"ImageGeom", "ImageArray"}}; + DataPath imagePath = arrayPath.getParent(); + args.insertOrAssign(ITKImageReader::k_FileName_Key, filePath); + args.insertOrAssign(ITKImageReader::k_ImageGeometryPath_Key, imagePath); + args.insertOrAssign(ITKImageReader::k_ImageDataArrayPath_Key, arrayPath); + + auto preflightResult = filter.preflight(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(preflightResult.outputActions) + + auto executeResult = filter.execute(dataStructure, args); + SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result) + } + +// auto compareResult = +// ::CompareFlippedGeometries(dataStructure, dataStructure.getDataAs(k_BaseGeomPath), dataStructure.getDataAs(k_XFlippedGeomPath), dataStructure.getDataAs(k_YFlippedGeomPath)); +// SIMPLNX_RESULT_REQUIRE_VALID(compareResult.result) } TEST_CASE("ITKImageProcessing::ITKImportImageStack: Flipped Image Even-Odd X/Y", "[ITKImageProcessing][ITKImportImageStack]") @@ -252,9 +316,9 @@ TEST_CASE("ITKImageProcessing::ITKImportImageStack: Flipped Image Even-Odd X/Y", auto executeResult = filter.execute(dataStructure, args); SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result) - auto compareResult = - ::CompareFlippedGeometries(dataStructure.getDataAs(k_BaseGeomPath), dataStructure.getDataAs(k_XFlippedGeomPath), dataStructure.getDataAs(k_YFlippedGeomPath)); - SIMPLNX_RESULT_REQUIRE_VALID(compareResult.result) +// auto compareResult = +// ::CompareFlippedGeometries(dataStructure, dataStructure.getDataAs(k_BaseGeomPath), dataStructure.getDataAs(k_XFlippedGeomPath), dataStructure.getDataAs(k_YFlippedGeomPath)); +// SIMPLNX_RESULT_REQUIRE_VALID(compareResult.result) } TEST_CASE("ITKImageProcessing::ITKImportImageStack: Flipped Image Odd-Even X/Y", "[ITKImageProcessing][ITKImportImageStack]") @@ -283,9 +347,9 @@ TEST_CASE("ITKImageProcessing::ITKImportImageStack: Flipped Image Odd-Even X/Y", auto executeResult = filter.execute(dataStructure, args); SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result) - auto compareResult = - ::CompareFlippedGeometries(dataStructure.getDataAs(k_BaseGeomPath), dataStructure.getDataAs(k_XFlippedGeomPath), dataStructure.getDataAs(k_YFlippedGeomPath)); - SIMPLNX_RESULT_REQUIRE_VALID(compareResult.result) +// auto compareResult = +// ::CompareFlippedGeometries(dataStructure, dataStructure.getDataAs(k_BaseGeomPath), dataStructure.getDataAs(k_XFlippedGeomPath), dataStructure.getDataAs(k_YFlippedGeomPath)); +// SIMPLNX_RESULT_REQUIRE_VALID(compareResult.result) } TEST_CASE("ITKImageProcessing::ITKImportImageStack: Flipped Image Odd-Odd X/Y", "[ITKImageProcessing][ITKImportImageStack]") @@ -314,7 +378,7 @@ TEST_CASE("ITKImageProcessing::ITKImportImageStack: Flipped Image Odd-Odd X/Y", auto executeResult = filter.execute(dataStructure, args); SIMPLNX_RESULT_REQUIRE_VALID(executeResult.result) - auto compareResult = - ::CompareFlippedGeometries(dataStructure.getDataAs(k_BaseGeomPath), dataStructure.getDataAs(k_XFlippedGeomPath), dataStructure.getDataAs(k_YFlippedGeomPath)); - SIMPLNX_RESULT_REQUIRE_VALID(compareResult.result) +// auto compareResult = +// ::CompareFlippedGeometries(dataStructure, dataStructure.getDataAs(k_BaseGeomPath), dataStructure.getDataAs(k_XFlippedGeomPath), dataStructure.getDataAs(k_YFlippedGeomPath)); +// SIMPLNX_RESULT_REQUIRE_VALID(compareResult.result) }