Skip to content

Commit

Permalink
[compiling, passing] finish review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nyoungbq authored and imikejackson committed Jan 16, 2025
1 parent 62ad45e commit 31c1dee
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 313 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct RunITKProjectionDataCheckFunctor
template <class FixedOutputType>
auto operator()(const DataStructure& dataStructure, const DataPath& selectedInputArray, const DataPath& imageGeomPath, const DataPath& outputArrayPath) const
{
return ITK::DataCheck<ArrayOptionsType, typename FixedOutputTypeHelper<FixedOutputType>::FilterOutputType>(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath);
return ITK::DataCheck<ArrayOptionsType, FixedOutputTypeHelper<FixedOutputType>::template FilterOutputType>(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath);
}
};

Expand All @@ -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<ArrayOptionsType, typename FixedOutputTypeHelper<FixedOutputType>::FilterOutputType>(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath, itkFunctor,
return ITK::Execute<ArrayOptionsType, FixedOutputTypeHelper<FixedOutputType>::template FilterOutputType>(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath, itkFunctor,
shouldCancel);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#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"
#include "simplnx/Parameters/GeometrySelectionParameter.hpp"
#include "simplnx/Parameters/NumberParameter.hpp"
#include "simplnx/Parameters/StringParameter.hpp"

#include "ITKImageProcessing/Common/ProjectionUtils.hpp"

#include <itkMaximumProjectionImageFilter.h>

using namespace nx::core;
Expand All @@ -21,18 +20,6 @@ namespace cxITKMaximumProjectionImageFilter
using ArrayOptionsType = ITK::ScalarPixelIdTypeList;
// VectorPixelIDTypeList;

template <class PixelT>
using FilterOutputTypeUI8 = uint8;

template <class PixelT>
using FilterOutputTypeI16 = int16;

template <class PixelT>
using FilterOutputTypeUI16 = uint16;

template <class PixelT>
using FilterOutputTypeF32 = float32;

struct ITKMaximumProjectionImageFilterFunctor
{
uint32 projectionDimension = 0u;
Expand Down Expand Up @@ -124,77 +111,11 @@ IFilter::PreflightResult ITKMaximumProjectionImageFilter::preflightImpl(const Da
auto selectedInputArray = filterArgs.value<DataPath>(k_InputImageDataPath_Key);
auto outputArrayName = filterArgs.value<DataObjectNameParameter::ValueType>(k_OutputImageArrayName_Key);
auto projectionDimension = filterArgs.value<uint32>(k_ProjectionDimension_Key);
auto preformInPlace = filterArgs.value<bool>(k_RemoveOriginalGeometry_Key);
auto performInPlace = filterArgs.value<bool>(k_RemoveOriginalGeometry_Key);
auto outputGeomName = filterArgs.value<std::string>(k_OutputImageGeomName_Key);
DataPath outputArrayPath = selectedInputArray.replaceName(outputArrayName);

Result<OutputActions> 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<ImageGeom>(imageGeomPath);

// Make copy of input geometry
resultOutputActions.value().appendAction(std::make_unique<CreateImageGeometryAction>(
outputGeomPath, originalGeometry.getDimensions().toContainer<CreateImageGeometryAction::DimensionType>(), originalGeometry.getOrigin().toContainer<CreateImageGeometryAction::OriginType>(),
originalGeometry.getSpacing().toContainer<CreateImageGeometryAction::SpacingType>(), originalGeometry.getCellDataPath().getTargetName()));

outputArrayPath = outputGeomPath.createChildPath(originalGeometry.getCellDataPath().getTargetName()).createChildPath(outputArrayName);
}

Result<OutputActions> helperOutputActions = {};
DataType type = dataStructure.getDataAs<IDataArray>(selectedInputArray)->getDataType();
switch(type)
{
case DataType::uint8: {
helperOutputActions =
ITK::DataCheck<cxITKMaximumProjectionImageFilter::ArrayOptionsType, cxITKMaximumProjectionImageFilter::FilterOutputTypeUI8>(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath);
break;
}
case DataType::int16: {
helperOutputActions =
ITK::DataCheck<cxITKMaximumProjectionImageFilter::ArrayOptionsType, cxITKMaximumProjectionImageFilter::FilterOutputTypeI16>(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath);
break;
}
case DataType::uint16: {
helperOutputActions =
ITK::DataCheck<cxITKMaximumProjectionImageFilter::ArrayOptionsType, cxITKMaximumProjectionImageFilter::FilterOutputTypeUI16>(dataStructure, selectedInputArray, imageGeomPath, outputArrayPath);
break;
}
case DataType::float32: {
helperOutputActions =
ITK::DataCheck<cxITKMaximumProjectionImageFilter::ArrayOptionsType, cxITKMaximumProjectionImageFilter::FilterOutputTypeF32>(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<cxITKMaximumProjectionImageFilter::ArrayOptionsType>(dataStructure, selectedInputArray, imageGeomPath, outputGeomName, performInPlace,
outputArrayName);
}

//------------------------------------------------------------------------------
Expand All @@ -204,79 +125,13 @@ Result<> ITKMaximumProjectionImageFilter::executeImpl(DataStructure& dataStructu
auto imageGeomPath = filterArgs.value<DataPath>(k_InputImageGeomPath_Key);
auto selectedInputArray = filterArgs.value<DataPath>(k_InputImageDataPath_Key);
auto outputArrayName = filterArgs.value<DataObjectNameParameter::ValueType>(k_OutputImageArrayName_Key);
DataPath outputArrayPath = selectedInputArray.replaceName(outputArrayName);

auto preformInPlace = filterArgs.value<bool>(k_RemoveOriginalGeometry_Key);

if(!preformInPlace)
{
const auto& originalGeometry = dataStructure.getDataRefAs<ImageGeom>(imageGeomPath);

imageGeomPath = DataPath({filterArgs.value<std::string>(k_OutputImageGeomName_Key)});
outputArrayPath = imageGeomPath.createChildPath(originalGeometry.getCellDataPath().getTargetName()).createChildPath(outputArrayName);
}

auto outputImageGeomName = filterArgs.value<std::string>(k_OutputImageGeomName_Key);
auto performInPlace = filterArgs.value<bool>(k_RemoveOriginalGeometry_Key);
auto projectionDimension = filterArgs.value<uint32>(k_ProjectionDimension_Key);

const cxITKMaximumProjectionImageFilter::ITKMaximumProjectionImageFilterFunctor itkFunctor = {projectionDimension};

Result<> result = {};
DataType type = dataStructure.getDataAs<IDataArray>(selectedInputArray)->getDataType();
switch(type)
{
case DataType::uint8: {
result = ITK::Execute<cxITKMaximumProjectionImageFilter::ArrayOptionsType, cxITKMaximumProjectionImageFilter::FilterOutputTypeUI8>(dataStructure, selectedInputArray, imageGeomPath,
outputArrayPath, itkFunctor, shouldCancel);
break;
}
case DataType::int16: {
result = ITK::Execute<cxITKMaximumProjectionImageFilter::ArrayOptionsType, cxITKMaximumProjectionImageFilter::FilterOutputTypeI16>(dataStructure, selectedInputArray, imageGeomPath,
outputArrayPath, itkFunctor, shouldCancel);
break;
}
case DataType::uint16: {
result = ITK::Execute<cxITKMaximumProjectionImageFilter::ArrayOptionsType, cxITKMaximumProjectionImageFilter::FilterOutputTypeUI16>(dataStructure, selectedInputArray, imageGeomPath,
outputArrayPath, itkFunctor, shouldCancel);
break;
}
case DataType::float32: {
result = ITK::Execute<cxITKMaximumProjectionImageFilter::ArrayOptionsType, cxITKMaximumProjectionImageFilter::FilterOutputTypeF32>(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<ImageGeom>(imageGeomPath);
auto iArrayTupleShape = dataStructure.getDataAs<IArray>(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<AttributeMatrix>(outputArrayPath.getParent())->resizeTuples(iArrayTupleShape);

return {};
return ProjectionUtilities::RunITKProjectionExecute<cxITKMaximumProjectionImageFilter::ArrayOptionsType>(dataStructure, selectedInputArray, imageGeomPath, shouldCancel, outputArrayName,
performInPlace, itkFunctor, outputImageGeomName);
}
} // namespace nx::core
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading

0 comments on commit 31c1dee

Please sign in to comment.