From 31c1deedc014c257d04bb7bd6a52f63ccdc8ee37 Mon Sep 17 00:00:00 2001 From: nyoungbq Date: Wed, 15 Jan 2025 12:50:20 -0500 Subject: [PATCH] [compiling, passing] finish review feedback --- .../Common/ProjectionUtils.hpp | 4 +- .../ITKMaximumProjectionImageFilter.cpp | 163 +----------------- .../ITKMedianProjectionImageFilter.cpp | 3 - .../ITKMinimumProjectionImageFilter.cpp | 163 +----------------- 4 files changed, 20 insertions(+), 313 deletions(-) diff --git a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Common/ProjectionUtils.hpp b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Common/ProjectionUtils.hpp index 49ac7cd0c4..8995b1771a 100644 --- a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Common/ProjectionUtils.hpp +++ b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Common/ProjectionUtils.hpp @@ -27,7 +27,7 @@ struct RunITKProjectionDataCheckFunctor template auto operator()(const DataStructure& dataStructure, const DataPath& selectedInputArray, const DataPath& imageGeomPath, const DataPath& outputArrayPath) const { - return ITK::DataCheck::FilterOutputType>(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath); + return ITK::DataCheck::template FilterOutputType>(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath); } }; @@ -38,7 +38,7 @@ struct RunITKProjectionExecuteFunctor auto operator()(DataStructure& dataStructure, const DataPath& selectedInputArray, const DataPath& imageGeomPath, const DataPath& outputArrayPath, ITKFunctorType&& itkFunctor, const std::atomic_bool& shouldCancel) const { - return ITK::Execute::FilterOutputType>(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath, itkFunctor, + return ITK::Execute::template FilterOutputType>(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath, itkFunctor, shouldCancel); } }; diff --git a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKMaximumProjectionImageFilter.cpp b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKMaximumProjectionImageFilter.cpp index 715b001db2..0ccce7029a 100644 --- a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKMaximumProjectionImageFilter.cpp +++ b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKMaximumProjectionImageFilter.cpp @@ -1,10 +1,7 @@ #include "ITKMaximumProjectionImageFilter.hpp" -#include "ITKImageProcessing/Common/ITKArrayHelper.hpp" - #include "simplnx/Common/TypesUtility.hpp" #include "simplnx/DataStructure/IDataArray.hpp" -#include "simplnx/Filter/Actions/CreateImageGeometryAction.hpp" #include "simplnx/Parameters/ArraySelectionParameter.hpp" #include "simplnx/Parameters/BoolParameter.hpp" #include "simplnx/Parameters/DataObjectNameParameter.hpp" @@ -12,6 +9,8 @@ #include "simplnx/Parameters/NumberParameter.hpp" #include "simplnx/Parameters/StringParameter.hpp" +#include "ITKImageProcessing/Common/ProjectionUtils.hpp" + #include using namespace nx::core; @@ -21,18 +20,6 @@ namespace cxITKMaximumProjectionImageFilter using ArrayOptionsType = ITK::ScalarPixelIdTypeList; // VectorPixelIDTypeList; -template -using FilterOutputTypeUI8 = uint8; - -template -using FilterOutputTypeI16 = int16; - -template -using FilterOutputTypeUI16 = uint16; - -template -using FilterOutputTypeF32 = float32; - struct ITKMaximumProjectionImageFilterFunctor { uint32 projectionDimension = 0u; @@ -124,77 +111,11 @@ IFilter::PreflightResult ITKMaximumProjectionImageFilter::preflightImpl(const Da auto selectedInputArray = filterArgs.value(k_InputImageDataPath_Key); auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); - auto preformInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); + auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); - DataPath outputArrayPath = selectedInputArray.replaceName(outputArrayName); - - Result resultOutputActions; - // The input geometry must be preserved, so we will just copy the needed array into newly created output geometry - if(!preformInPlace) - { - DataPath outputGeomPath({outputGeomName}); - - const auto& originalGeometry = dataStructure.getDataRefAs(imageGeomPath); - - // Make copy of input geometry - resultOutputActions.value().appendAction(std::make_unique( - outputGeomPath, originalGeometry.getDimensions().toContainer(), originalGeometry.getOrigin().toContainer(), - originalGeometry.getSpacing().toContainer(), originalGeometry.getCellDataPath().getTargetName())); - - outputArrayPath = outputGeomPath.createChildPath(originalGeometry.getCellDataPath().getTargetName()).createChildPath(outputArrayName); - } - - Result helperOutputActions = {}; - DataType type = dataStructure.getDataAs(selectedInputArray)->getDataType(); - switch(type) - { - case DataType::uint8: { - helperOutputActions = - ITK::DataCheck(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath); - break; - } - case DataType::int16: { - helperOutputActions = - ITK::DataCheck(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath); - break; - } - case DataType::uint16: { - helperOutputActions = - ITK::DataCheck(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath); - break; - } - case DataType::float32: { - helperOutputActions = - ITK::DataCheck(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath); - break; - } - case DataType::int8: - [[fallthrough]]; - case DataType::int32: - [[fallthrough]]; - case DataType::uint32: - [[fallthrough]]; - case DataType::int64: - [[fallthrough]]; - case DataType::uint64: { - [[fallthrough]]; - } - case DataType::float64: { - [[fallthrough]]; - } - case DataType::boolean: { - return MakePreflightErrorResult(-76600, fmt::format("Input {} type is not currently supported. Please reach out to devs if you have a use case.", DataTypeToString(type))); - } - } - if(helperOutputActions.invalid()) - { - return {std::move(helperOutputActions)}; - } - - // Consolidate actions - resultOutputActions.value().actions.insert(resultOutputActions.value().actions.end(), helperOutputActions.value().actions.begin(), helperOutputActions.value().actions.end()); - return {std::move(resultOutputActions)}; + return ProjectionUtilities::RunITKProjectionDataCheck(dataStructure, selectedInputArray, imageGeomPath, outputGeomName, performInPlace, + outputArrayName); } //------------------------------------------------------------------------------ @@ -204,79 +125,13 @@ Result<> ITKMaximumProjectionImageFilter::executeImpl(DataStructure& dataStructu auto imageGeomPath = filterArgs.value(k_InputImageGeomPath_Key); auto selectedInputArray = filterArgs.value(k_InputImageDataPath_Key); auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); - DataPath outputArrayPath = selectedInputArray.replaceName(outputArrayName); - - auto preformInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); - - if(!preformInPlace) - { - const auto& originalGeometry = dataStructure.getDataRefAs(imageGeomPath); - - imageGeomPath = DataPath({filterArgs.value(k_OutputImageGeomName_Key)}); - outputArrayPath = imageGeomPath.createChildPath(originalGeometry.getCellDataPath().getTargetName()).createChildPath(outputArrayName); - } - + auto outputImageGeomName = filterArgs.value(k_OutputImageGeomName_Key); + auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); const cxITKMaximumProjectionImageFilter::ITKMaximumProjectionImageFilterFunctor itkFunctor = {projectionDimension}; - Result<> result = {}; - DataType type = dataStructure.getDataAs(selectedInputArray)->getDataType(); - switch(type) - { - case DataType::uint8: { - result = ITK::Execute(dataStructure, selectedInputArray, imageGeomPath, - outputArrayPath, itkFunctor, shouldCancel); - break; - } - case DataType::int16: { - result = ITK::Execute(dataStructure, selectedInputArray, imageGeomPath, - outputArrayPath, itkFunctor, shouldCancel); - break; - } - case DataType::uint16: { - result = ITK::Execute(dataStructure, selectedInputArray, imageGeomPath, - outputArrayPath, itkFunctor, shouldCancel); - break; - } - case DataType::float32: { - result = ITK::Execute(dataStructure, selectedInputArray, imageGeomPath, - outputArrayPath, itkFunctor, shouldCancel); - break; - } - case DataType::int8: - [[fallthrough]]; - case DataType::int32: - [[fallthrough]]; - case DataType::uint32: - [[fallthrough]]; - case DataType::int64: - [[fallthrough]]; - case DataType::uint64: { - [[fallthrough]]; - } - case DataType::float64: { - [[fallthrough]]; - } - case DataType::boolean: { - return MakeErrorResult(-76601, fmt::format("Input {} type is not currently supported. Please reach out to devs if you have a use case.", DataTypeToString(type))); - } - } - if(result.invalid()) - { - return result; - } - - auto& imageGeom = dataStructure.getDataRefAs(imageGeomPath); - auto iArrayTupleShape = dataStructure.getDataAs(outputArrayPath)->getTupleShape(); - - // Update the Image Geometry with the new dimensions - imageGeom.setDimensions({iArrayTupleShape[2], iArrayTupleShape[1], iArrayTupleShape[0]}); - - // Update the AttributeMatrix with the new tuple shape. THIS WILL ALSO CHANGE ANY OTHER DATA ARRAY THAT IS ALSO - // STORED IN THAT ATTRIBUTE MATRIX - dataStructure.getDataAs(outputArrayPath.getParent())->resizeTuples(iArrayTupleShape); - - return {}; + return ProjectionUtilities::RunITKProjectionExecute(dataStructure, selectedInputArray, imageGeomPath, shouldCancel, outputArrayName, + performInPlace, itkFunctor, outputImageGeomName); } } // namespace nx::core diff --git a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKMedianProjectionImageFilter.cpp b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKMedianProjectionImageFilter.cpp index c39f219134..612c56aa92 100644 --- a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKMedianProjectionImageFilter.cpp +++ b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKMedianProjectionImageFilter.cpp @@ -1,10 +1,7 @@ #include "ITKMedianProjectionImageFilter.hpp" -#include "ITKImageProcessing/Common/ITKArrayHelper.hpp" - #include "simplnx/Common/TypesUtility.hpp" #include "simplnx/DataStructure/IDataArray.hpp" -#include "simplnx/Filter/Actions/CreateImageGeometryAction.hpp" #include "simplnx/Parameters/ArraySelectionParameter.hpp" #include "simplnx/Parameters/BoolParameter.hpp" #include "simplnx/Parameters/DataObjectNameParameter.hpp" diff --git a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKMinimumProjectionImageFilter.cpp b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKMinimumProjectionImageFilter.cpp index 004bf9e614..8e2daa213f 100644 --- a/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKMinimumProjectionImageFilter.cpp +++ b/src/Plugins/ITKImageProcessing/src/ITKImageProcessing/Filters/ITKMinimumProjectionImageFilter.cpp @@ -1,10 +1,7 @@ #include "ITKMinimumProjectionImageFilter.hpp" -#include "ITKImageProcessing/Common/ITKArrayHelper.hpp" - #include "simplnx/Common/TypesUtility.hpp" #include "simplnx/DataStructure/IDataArray.hpp" -#include "simplnx/Filter/Actions/CreateImageGeometryAction.hpp" #include "simplnx/Parameters/ArraySelectionParameter.hpp" #include "simplnx/Parameters/BoolParameter.hpp" #include "simplnx/Parameters/DataObjectNameParameter.hpp" @@ -12,6 +9,8 @@ #include "simplnx/Parameters/NumberParameter.hpp" #include "simplnx/Parameters/StringParameter.hpp" +#include "ITKImageProcessing/Common/ProjectionUtils.hpp" + #include using namespace nx::core; @@ -21,18 +20,6 @@ namespace cxITKMinimumProjectionImageFilter using ArrayOptionsType = ITK::ScalarPixelIdTypeList; // VectorPixelIDTypeList; -template -using FilterOutputTypeUI8 = uint8; - -template -using FilterOutputTypeI16 = int16; - -template -using FilterOutputTypeUI16 = uint16; - -template -using FilterOutputTypeF32 = float32; - struct ITKMinimumProjectionImageFilterFunctor { uint32 projectionDimension = 0u; @@ -124,77 +111,11 @@ IFilter::PreflightResult ITKMinimumProjectionImageFilter::preflightImpl(const Da auto selectedInputArray = filterArgs.value(k_InputImageDataPath_Key); auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); - auto preformInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); + auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); auto outputGeomName = filterArgs.value(k_OutputImageGeomName_Key); - DataPath outputArrayPath = selectedInputArray.replaceName(outputArrayName); - - Result resultOutputActions; - // The input geometry must be preserved, so we will just copy the needed array into newly created output geometry - if(!preformInPlace) - { - DataPath outputGeomPath({outputGeomName}); - - const auto& originalGeometry = dataStructure.getDataRefAs(imageGeomPath); - - // Make copy of input geometry - resultOutputActions.value().appendAction(std::make_unique( - outputGeomPath, originalGeometry.getDimensions().toContainer(), originalGeometry.getOrigin().toContainer(), - originalGeometry.getSpacing().toContainer(), originalGeometry.getCellDataPath().getTargetName())); - - outputArrayPath = outputGeomPath.createChildPath(originalGeometry.getCellDataPath().getTargetName()).createChildPath(outputArrayName); - } - - Result helperOutputActions = {}; - DataType type = dataStructure.getDataAs(selectedInputArray)->getDataType(); - switch(type) - { - case DataType::uint8: { - helperOutputActions = - ITK::DataCheck(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath); - break; - } - case DataType::int16: { - helperOutputActions = - ITK::DataCheck(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath); - break; - } - case DataType::uint16: { - helperOutputActions = - ITK::DataCheck(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath); - break; - } - case DataType::float32: { - helperOutputActions = - ITK::DataCheck(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath); - break; - } - case DataType::int8: - [[fallthrough]]; - case DataType::int32: - [[fallthrough]]; - case DataType::uint32: - [[fallthrough]]; - case DataType::int64: - [[fallthrough]]; - case DataType::uint64: { - [[fallthrough]]; - } - case DataType::float64: { - [[fallthrough]]; - } - case DataType::boolean: { - return MakePreflightErrorResult(-76610, fmt::format("Input {} type is not currently supported. Please reach out to devs if you have a use case.", DataTypeToString(type))); - } - } - if(helperOutputActions.invalid()) - { - return {std::move(helperOutputActions)}; - } - - // Consolidate actions - resultOutputActions.value().actions.insert(resultOutputActions.value().actions.end(), helperOutputActions.value().actions.begin(), helperOutputActions.value().actions.end()); - return {std::move(resultOutputActions)}; + return ProjectionUtilities::RunITKProjectionDataCheck(dataStructure, selectedInputArray, imageGeomPath, outputGeomName, performInPlace, + outputArrayName); } //------------------------------------------------------------------------------ @@ -204,79 +125,13 @@ Result<> ITKMinimumProjectionImageFilter::executeImpl(DataStructure& dataStructu auto imageGeomPath = filterArgs.value(k_InputImageGeomPath_Key); auto selectedInputArray = filterArgs.value(k_InputImageDataPath_Key); auto outputArrayName = filterArgs.value(k_OutputImageArrayName_Key); - DataPath outputArrayPath = selectedInputArray.replaceName(outputArrayName); - - auto preformInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); - - if(!preformInPlace) - { - const auto& originalGeometry = dataStructure.getDataRefAs(imageGeomPath); - - imageGeomPath = DataPath({filterArgs.value(k_OutputImageGeomName_Key)}); - outputArrayPath = imageGeomPath.createChildPath(originalGeometry.getCellDataPath().getTargetName()).createChildPath(outputArrayName); - } - + auto outputImageGeomName = filterArgs.value(k_OutputImageGeomName_Key); + auto performInPlace = filterArgs.value(k_RemoveOriginalGeometry_Key); auto projectionDimension = filterArgs.value(k_ProjectionDimension_Key); const cxITKMinimumProjectionImageFilter::ITKMinimumProjectionImageFilterFunctor itkFunctor = {projectionDimension}; - Result<> result = {}; - DataType type = dataStructure.getDataAs(selectedInputArray)->getDataType(); - switch(type) - { - case DataType::uint8: { - result = ITK::Execute(dataStructure, selectedInputArray, imageGeomPath, - outputArrayPath, itkFunctor, shouldCancel); - break; - } - case DataType::int16: { - result = ITK::Execute(dataStructure, selectedInputArray, imageGeomPath, - outputArrayPath, itkFunctor, shouldCancel); - break; - } - case DataType::uint16: { - result = ITK::Execute(dataStructure, selectedInputArray, imageGeomPath, - outputArrayPath, itkFunctor, shouldCancel); - break; - } - case DataType::float32: { - result = ITK::Execute(dataStructure, selectedInputArray, imageGeomPath, - outputArrayPath, itkFunctor, shouldCancel); - break; - } - case DataType::int8: - [[fallthrough]]; - case DataType::int32: - [[fallthrough]]; - case DataType::uint32: - [[fallthrough]]; - case DataType::int64: - [[fallthrough]]; - case DataType::uint64: { - [[fallthrough]]; - } - case DataType::float64: { - [[fallthrough]]; - } - case DataType::boolean: { - return MakeErrorResult(-76601, fmt::format("Input {} type is not currently supported. Please reach out to devs if you have a use case.", DataTypeToString(type))); - } - } - if(result.invalid()) - { - return result; - } - - auto& imageGeom = dataStructure.getDataRefAs(imageGeomPath); - auto iArrayTupleShape = dataStructure.getDataAs(outputArrayPath)->getTupleShape(); - - // Update the Image Geometry with the new dimensions - imageGeom.setDimensions({iArrayTupleShape[2], iArrayTupleShape[1], iArrayTupleShape[0]}); - - // Update the AttributeMatrix with the new tuple shape. THIS WILL ALSO CHANGE ANY OTHER DATA ARRAY THAT IS ALSO - // STORED IN THAT ATTRIBUTE MATRIX - dataStructure.getDataAs(outputArrayPath.getParent())->resizeTuples(iArrayTupleShape); - - return {}; + return ProjectionUtilities::RunITKProjectionExecute(dataStructure, selectedInputArray, imageGeomPath, shouldCancel, outputArrayName, + performInPlace, itkFunctor, outputImageGeomName); } } // namespace nx::core