diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AppendImageGeometryFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AppendImageGeometryFilter.cpp index 78a86dfd53..f017e24343 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AppendImageGeometryFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AppendImageGeometryFilter.cpp @@ -1,6 +1,5 @@ #include "AppendImageGeometryFilter.hpp" -#include "ComputeArrayStatisticsFilter.hpp" #include "SimplnxCore/Filters/Algorithms/AppendImageGeometry.hpp" #include "simplnx/DataStructure/DataArray.hpp" @@ -15,10 +14,8 @@ #include "simplnx/Parameters/BoolParameter.hpp" #include "simplnx/Parameters/DataGroupCreationParameter.hpp" #include "simplnx/Parameters/GeometrySelectionParameter.hpp" - -#include "simplnx/Utilities/SIMPLConversion.hpp" - #include "simplnx/Utilities/GeometryHelpers.hpp" +#include "simplnx/Utilities/SIMPLConversion.hpp" using namespace nx::core; @@ -93,7 +90,6 @@ IFilter::PreflightResult AppendImageGeometryFilter::preflightImpl(const DataStru auto pCheckResolutionValue = filterArgs.value(k_CheckResolution_Key); auto pSaveAsNewGeometry = filterArgs.value(k_SaveAsNewGeometry_Key); - PreflightResult preflightResult; Result resultOutputActions; std::vector preflightUpdatedValues; diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AppendImageGeometryZSliceFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AppendImageGeometryZSliceFilter.cpp deleted file mode 100644 index 3a19783847..0000000000 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/AppendImageGeometryZSliceFilter.cpp +++ /dev/null @@ -1,298 +0,0 @@ -#include "AppendImageGeometryZSliceFilter.hpp" - -#include "SimplnxCore/Filters/Algorithms/AppendImageGeometryZSlice.hpp" - -#include "simplnx/DataStructure/DataArray.hpp" -#include "simplnx/DataStructure/DataPath.hpp" -#include "simplnx/DataStructure/Geometry/ImageGeom.hpp" -#include "simplnx/DataStructure/NeighborList.hpp" -#include "simplnx/DataStructure/StringArray.hpp" -#include "simplnx/Filter/Actions/CreateArrayAction.hpp" -#include "simplnx/Filter/Actions/CreateImageGeometryAction.hpp" -#include "simplnx/Filter/Actions/CreateNeighborListAction.hpp" -#include "simplnx/Filter/Actions/CreateStringArrayAction.hpp" -#include "simplnx/Parameters/BoolParameter.hpp" -#include "simplnx/Parameters/DataGroupCreationParameter.hpp" -#include "simplnx/Parameters/GeometrySelectionParameter.hpp" - -#include "simplnx/Utilities/SIMPLConversion.hpp" - -#include "simplnx/Utilities/GeometryHelpers.hpp" - -using namespace nx::core; - -namespace nx::core -{ -//------------------------------------------------------------------------------ -std::string AppendImageGeometryZSliceFilter::name() const -{ - return FilterTraits::name.str(); -} - -//------------------------------------------------------------------------------ -std::string AppendImageGeometryZSliceFilter::className() const -{ - return FilterTraits::className; -} - -//------------------------------------------------------------------------------ -Uuid AppendImageGeometryZSliceFilter::uuid() const -{ - return FilterTraits::uuid; -} - -//------------------------------------------------------------------------------ -std::string AppendImageGeometryZSliceFilter::humanName() const -{ - return "Append Z Slice (Image Geometry)"; -} - -//------------------------------------------------------------------------------ -std::vector AppendImageGeometryZSliceFilter::defaultTags() const -{ - return {className(), "Core", "Memory Management"}; -} - -//------------------------------------------------------------------------------ -Parameters AppendImageGeometryZSliceFilter::parameters() const -{ - Parameters params; - - params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); - params.insert(std::make_unique(k_InputGeometry_Key, "Input Image Geometry", "The incoming image geometry (cell data) that is to be appended.", DataPath{}, - GeometrySelectionParameter::AllowedTypes{IGeometry::Type::Image})); - params.insert(std::make_unique(k_DestinationGeometry_Key, "Destination Image Geometry", - "The destination image geometry (cell data) that is the final location for the appended data.", DataPath{}, - GeometrySelectionParameter::AllowedTypes{IGeometry::Type::Image})); - params.insert(std::make_unique(k_CheckResolution_Key, "Check Spacing", "Checks to make sure the spacing for the input geometry and destination geometry match", false)); - params.insertLinkableParameter(std::make_unique(k_SaveAsNewGeometry_Key, "Save as new geometry", - "Save the combined data as a new geometry instead of appending the input data to the destination geometry", false)); - params.insert(std::make_unique(k_NewGeometry_Key, "New Image Geometry", "The path to the new geometry with the combined data from the input & destination geometry", - DataPath({"AppendedImageGeom"}))); - params.linkParameters(k_SaveAsNewGeometry_Key, k_NewGeometry_Key, true); - - return params; -} - -//------------------------------------------------------------------------------ -IFilter::UniquePointer AppendImageGeometryZSliceFilter::clone() const -{ - return std::make_unique(); -} - -//------------------------------------------------------------------------------ -IFilter::PreflightResult AppendImageGeometryZSliceFilter::preflightImpl(const DataStructure& dataStructure, const Arguments& filterArgs, const MessageHandler& messageHandler, - const std::atomic_bool& shouldCancel) const -{ - auto pInputGeometryPathValue = filterArgs.value(k_InputGeometry_Key); - auto pDestinationGeometryPathValue = filterArgs.value(k_DestinationGeometry_Key); - auto pCheckResolutionValue = filterArgs.value(k_CheckResolution_Key); - auto pSaveAsNewGeometry = filterArgs.value(k_SaveAsNewGeometry_Key); - - PreflightResult preflightResult; - Result resultOutputActions; - std::vector preflightUpdatedValues; - - const auto& inputGeometry = dataStructure.getDataRefAs(pInputGeometryPathValue); - const auto& destGeometry = dataStructure.getDataRefAs(pDestinationGeometryPathValue); - SizeVec3 inputGeomDims = inputGeometry.getDimensions(); - SizeVec3 destGeomDims = destGeometry.getDimensions(); - if(destGeomDims[0] != inputGeomDims[0]) - { - return MakePreflightErrorResult(-8200, fmt::format("Input X Dim ({}) not equal to Destination X Dim ({})", inputGeomDims[0], destGeomDims[0])); - } - if(destGeomDims[1] != inputGeomDims[1]) - { - return MakePreflightErrorResult(-8201, fmt::format("Input Y Dim ({}) not equal to Destination Y Dim ({})", inputGeomDims[1], destGeomDims[1])); - } - if(pCheckResolutionValue) - { - FloatVec3 inputRes = inputGeometry.getSpacing(); - FloatVec3 destRes = destGeometry.getSpacing(); - - if(inputRes[0] != destRes[0]) - { - return MakePreflightErrorResult(-8202, fmt::format("Input X Spacing ({}) not equal to Destination X Spacing ({})", inputRes[0], destRes[0])); - } - if(inputRes[1] != destRes[1]) - { - return MakePreflightErrorResult(-8203, fmt::format("Input Y Spacing ({}) not equal to Destination Y Spacing ({})", inputRes[1], destRes[1])); - } - if(inputRes[2] != destRes[2]) - { - return MakePreflightErrorResult(-8204, fmt::format("Input Z Spacing ({}) not equal to Destination Z Spacing ({})", inputRes[2], destRes[2])); - } - } - - DataPath pNewImageGeomPath; - std::vector newDims = {destGeomDims[0], destGeomDims[1], inputGeomDims[2] + destGeomDims[2]}; - FloatVec3 origin = destGeometry.getOrigin(); - FloatVec3 spacing = destGeometry.getSpacing(); - if(pSaveAsNewGeometry) - { - pNewImageGeomPath = filterArgs.value(k_NewGeometry_Key); - auto createGeomAction = std::make_unique(pNewImageGeomPath, newDims, std::vector{origin[0], origin[1], origin[2]}, - std::vector{spacing[0], spacing[1], spacing[2]}, ImageGeom::k_CellDataName); - resultOutputActions.value().appendAction(std::move(createGeomAction)); - } - - std::vector newCellDataDims(newDims.rbegin(), newDims.rend()); - const usize numNewCellDataTuples = std::accumulate(newCellDataDims.cbegin(), newCellDataDims.cend(), static_cast(1), std::multiplies<>()); - usize tupleOffset = destGeometry.getNumberOfCells(); - if(tupleOffset > numNewCellDataTuples) - { - return MakePreflightErrorResult(-8205, fmt::format("Calculated tuple offset ({}) for appending the input data is larger than the total number of tuples ({}).", tupleOffset, numNewCellDataTuples)); - } - const AttributeMatrix* inputCellData = inputGeometry.getCellData(); - const AttributeMatrix* destCellData = destGeometry.getCellData(); - const DataPath destCellDataPath = pDestinationGeometryPathValue.createChildPath(destCellData->getName()); - const DataPath inputCellDataPath = pInputGeometryPathValue.createChildPath(inputGeometry.getCellData()->getName()); - DataPath newCellDataPath; - if(pSaveAsNewGeometry) - { - newCellDataPath = pNewImageGeomPath.createChildPath(ImageGeom::k_CellDataName); - } - std::vector childNames1 = inputCellData->getDataMap().getNames(); - std::vector childNames2 = destCellData->getDataMap().getNames(); - std::vector combinedArrayNames; - std::sort(childNames1.begin(), childNames1.end()); - std::sort(childNames2.begin(), childNames2.end()); - std::set_intersection(childNames1.begin(), childNames1.end(), childNames2.begin(), childNames2.end(), back_inserter(combinedArrayNames)); - for(const auto& name : combinedArrayNames) - { - auto* dataArray1 = dataStructure.getDataAs(inputCellDataPath.createChildPath(name)); - if(dataArray1 == nullptr) - { - resultOutputActions.warnings().push_back( - {-8206, fmt::format("Cannot append data array {} in cell data attribute matrix at path '{}' because it is not of type IArray.", name, inputCellDataPath.toString())}); - continue; - } - auto* dataArray2 = dataStructure.getDataAs(destCellDataPath.createChildPath(name)); - if(dataArray2 == nullptr) - { - resultOutputActions.warnings().push_back( - {-8207, fmt::format("Cannot append data array {} in cell data attribute matrix at path '{}' because it is not of type IArray.", name, destCellDataPath.toString())}); - continue; - } - const IArray::ArrayType arrayType = dataArray2->getArrayType(); - if(arrayType != dataArray1->getArrayType()) - { - const std::string inputArrayStr = *IArray::StringListFromArrayType({dataArray1->getArrayType()}).begin(); - const std::string destArrayStr = *IArray::StringListFromArrayType({arrayType}).begin(); - resultOutputActions.warnings().push_back({-8208, fmt::format("Cannot append data from input data object of array type {} to destination data object of array type {} because " - "the array types do not match.", - inputArrayStr, destArrayStr)}); - continue; - } - const usize srcNumComps = dataArray1->getNumberOfComponents(); - const usize numComps = dataArray2->getNumberOfComponents(); - if(srcNumComps != numComps) - { - resultOutputActions.warnings().push_back( - {-8209, fmt::format("Cannot append data from input data array with {} components to destination data array with {} components.", srcNumComps, numComps)}); - continue; - } - const usize srcNumElements = dataArray1->getNumberOfTuples() * srcNumComps; - const usize numElements = numNewCellDataTuples * numComps; - if(srcNumElements + tupleOffset * numComps > numElements) - { - resultOutputActions.warnings().push_back( - {-8210, fmt::format("Cannot append data from input data array {} with {} total elements to destination data array with {} total elements starting at tuple " - "{} because there are not enough elements in the destination array.", - name, srcNumElements, numElements, tupleOffset)}); - continue; - } - - if(arrayType == IArray::ArrayType::DataArray) - { - DataType dataType1 = dynamic_cast(dataArray1)->getDataType(); - DataType dataType2 = dynamic_cast(dataArray2)->getDataType(); - if(dataType1 != dataType2) - { - resultOutputActions.warnings().push_back( - {-8211, fmt::format("Cannot append data from input data array with type {} to destination data array with type {} because the data array types do not match.", - DataTypeToString(dataType1).str(), DataTypeToString(dataType2).str())}); - continue; - } - - if(pSaveAsNewGeometry) - { - auto createArrayAction = std::make_unique(dataType1, newCellDataDims, dataArray1->getComponentShape(), newCellDataPath.createChildPath(name)); - resultOutputActions.value().appendAction(std::move(createArrayAction)); - } - } - if(arrayType == IArray::ArrayType::NeighborListArray) - { - DataType dataType1 = dynamic_cast(dataArray1)->getDataType(); - DataType dataType2 = dynamic_cast(dataArray2)->getDataType(); - if(dataType1 != dataType2) - { - resultOutputActions.warnings().push_back( - {-8211, fmt::format("Cannot append data from input data array with type {} to destination data array with type {} because the data array types do not match.", - DataTypeToString(dataType1).str(), DataTypeToString(dataType2).str())}); - continue; - } - - if(pSaveAsNewGeometry) - { - auto createArrayAction = std::make_unique(dataType1, numNewCellDataTuples, newCellDataPath.createChildPath(name)); - resultOutputActions.value().appendAction(std::move(createArrayAction)); - } - } - if(arrayType == IArray::ArrayType::StringArray && pSaveAsNewGeometry) - { - auto createArrayAction = std::make_unique(newCellDataDims, newCellDataPath.createChildPath(name)); - resultOutputActions.value().appendAction(std::move(createArrayAction)); - } - } - - if(!pSaveAsNewGeometry) - { - resultOutputActions.warnings().push_back( - {-8412, "You are appending cell data together which may change the number of features. As a result, any feature level attribute matrix data will likely be invalidated!"}); - preflightUpdatedValues.push_back({"Appended Image Geometry Info", GeometryHelpers::Description::GenerateGeometryInfo(newDims, spacing, origin, inputGeometry.getUnits())}); - } - - return {std::move(resultOutputActions), std::move(preflightUpdatedValues)}; -} - -//------------------------------------------------------------------------------ -Result<> AppendImageGeometryZSliceFilter::executeImpl(DataStructure& dataStructure, const Arguments& filterArgs, const PipelineFilter* pipelineNode, const MessageHandler& messageHandler, - const std::atomic_bool& shouldCancel) const -{ - AppendImageGeometryZSliceInputValues inputValues; - - inputValues.InputGeometryPath = filterArgs.value(k_InputGeometry_Key); - inputValues.DestinationGeometryPath = filterArgs.value(k_DestinationGeometry_Key); - inputValues.CheckResolution = filterArgs.value(k_CheckResolution_Key); - inputValues.SaveAsNewGeometry = filterArgs.value(k_SaveAsNewGeometry_Key); - inputValues.NewGeometryPath = filterArgs.value(k_NewGeometry_Key); - - return AppendImageGeometryZSlice(dataStructure, messageHandler, shouldCancel, &inputValues)(); -} - -namespace -{ -namespace SIMPL -{ -constexpr StringLiteral k_InputAttributeMatrixKey = "InputAttributeMatrix"; -constexpr StringLiteral k_DestinationAttributeMatrixKey = "DestinationAttributeMatrix"; -constexpr StringLiteral k_CheckResolutionKey = "CheckResolution"; -} // namespace SIMPL -} // namespace - -Result AppendImageGeometryZSliceFilter::FromSIMPLJson(const nlohmann::json& json) -{ - Arguments args = AppendImageGeometryZSliceFilter().getDefaultArguments(); - - std::vector> results; - - results.push_back(SIMPLConversion::ConvertParameter(args, json, SIMPL::k_InputAttributeMatrixKey, k_InputGeometry_Key)); - results.push_back(SIMPLConversion::ConvertParameter(args, json, SIMPL::k_DestinationAttributeMatrixKey, k_DestinationGeometry_Key)); - results.push_back(SIMPLConversion::ConvertParameter(args, json, SIMPL::k_CheckResolutionKey, k_CheckResolution_Key)); - - Result<> conversionResult = MergeResults(std::move(results)); - - return ConvertResultTo(std::move(conversionResult), std::move(args)); -} -} // namespace nx::core