Skip to content

Commit

Permalink
BUG: ITK Filters should check total number of tuples for input compat…
Browse files Browse the repository at this point in the history
…ibility

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Sep 26, 2023
1 parent 42bd7f1 commit f8a6d19
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

using namespace complex;

bool ITK::DoTuplesMatch(const IDataStore& dataStore, const ImageGeom& imageGeom)
{
return imageGeom.getNumberOfCells() == dataStore.getNumberOfTuples();
}

bool ITK::DoDimensionsMatch(const IDataStore& dataStore, const ImageGeom& imageGeom)
{
// Stored fastest to slowest i.e. X Y Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ inline constexpr int32 k_ImageComponentDimensionMismatch = -2001;

} // namespace Constants

/**
* @brief Compares the total number of cells of the image geometry and the total number of tuples from the data store
* @param dataStore
* @param imageGeom
* @return True if the Image Geometry's numCells() == the DataStore's numberOfTuples()
*/
bool DoTuplesMatch(const IDataStore& dataStore, const ImageGeom& imageGeom);

/**
* @brief Checks to see if the dimensions of the Image Geometry and the DataStore are the same.
* @param dataStore
* @param imageGeom
* @return
*/
bool DoDimensionsMatch(const IDataStore& dataStore, const ImageGeom& imageGeom);

/**
Expand Down Expand Up @@ -466,10 +480,8 @@ Result<ResultT> ArraySwitchFuncDimsImpl(const IDataStore& dataStore, const Image
{
return ArraySwitchFuncComponentImpl<InputT, OutputT, 2, ComponentOptionsT, ResultT, FunctorT>(nComp, errorCode, args...);
}
else
{
return ArraySwitchFuncComponentImpl<InputT, OutputT, 3, ComponentOptionsT, ResultT, FunctorT>(nComp, errorCode, args...);
}

return ArraySwitchFuncComponentImpl<InputT, OutputT, 3, ComponentOptionsT, ResultT, FunctorT>(nComp, errorCode, args...);
}

template <class InputPixelT, class OutputPixelT, uint32 Dimension>
Expand All @@ -484,11 +496,13 @@ Result<OutputActions> DataCheckImpl(const DataStructure& dataStructure, const Da

const IDataStore& dataStore = dataArray.getIDataStoreRef();

if(!complex::ITK::DoDimensionsMatch(dataStore, imageGeom))
if(!complex::ITK::DoDimensionsMatch(dataStore, imageGeom) && !complex::ITK::DoTuplesMatch(dataStore, imageGeom))
{

std::string errMessage = fmt::format("DataArray '{}' tuple dimensions '{}' do not match Image Geometry '{}' dimensions '{}'", inputArrayPath.toString(), fmt::join(dataStore.getTupleShape(), ", "),
imageGeomPath.toString(), fmt::join(imageGeom.getDimensions(), ", "));
std::string errMessage = fmt::format("DataArray '{}' tuple dimensions '{}' do not match Image Geometry '{}' with dimensions 'XYZ={}' and the total number of ImageGeometry Cells {} does not match "
"the total number of DataArray tuples {}.",
inputArrayPath.toString(), fmt::join(dataStore.getTupleShape(), ", "), imageGeomPath.toString(), fmt::join(imageGeom.getDimensions(), ", "),
imageGeom.getNumberOfCells(), dataStore.getNumberOfTuples());
return MakeErrorResult<OutputActions>(complex::ITK::Constants::k_ImageGeometryDimensionMismatch, errMessage);
}

Expand All @@ -497,7 +511,8 @@ Result<OutputActions> DataCheckImpl(const DataStructure& dataStructure, const Da

if(cDims != inputPixelDims)
{
std::string errMessage = fmt::format("DataArray component dimensions of '{}' do not match output image component dimensions of '{}'", fmt::join(inputPixelDims, ", "), fmt::join(cDims, ", "));
const std::string errMessage =
fmt::format("DataArray component dimensions of '{}' do not match output image component dimensions of '{}'", fmt::join(inputPixelDims, ", "), fmt::join(cDims, ", "));
return MakeErrorResult<OutputActions>(complex::ITK::Constants::k_ImageComponentDimensionMismatch, errMessage);
}

Expand Down

0 comments on commit f8a6d19

Please sign in to comment.