|
| 1 | +#include "ComputeCoordinatesImageGeomFilter.hpp" |
| 2 | + |
| 3 | +#include "SimplnxCore/Filters/Algorithms/ComputeCoordinatesImageGeom.hpp" |
| 4 | + |
| 5 | +#include "simplnx/Common/TypeTraits.hpp" |
| 6 | +#include "simplnx/DataStructure/DataPath.hpp" |
| 7 | +#include "simplnx/DataStructure/Geometry/ImageGeom.hpp" |
| 8 | +#include "simplnx/Filter/Actions/CreateArrayAction.hpp" |
| 9 | +#include "simplnx/Parameters/ArrayCreationParameter.hpp" |
| 10 | +#include "simplnx/Parameters/ChoicesParameter.hpp" |
| 11 | +#include "simplnx/Parameters/GeometrySelectionParameter.hpp" |
| 12 | + |
| 13 | +using namespace nx::core; |
| 14 | + |
| 15 | +namespace nx::core |
| 16 | +{ |
| 17 | +//------------------------------------------------------------------------------ |
| 18 | +std::string ComputeCoordinatesImageGeomFilter::name() const |
| 19 | +{ |
| 20 | + return FilterTraits<ComputeCoordinatesImageGeomFilter>::name.str(); |
| 21 | +} |
| 22 | + |
| 23 | +//------------------------------------------------------------------------------ |
| 24 | +std::string ComputeCoordinatesImageGeomFilter::className() const |
| 25 | +{ |
| 26 | + return FilterTraits<ComputeCoordinatesImageGeomFilter>::className; |
| 27 | +} |
| 28 | + |
| 29 | +//------------------------------------------------------------------------------ |
| 30 | +Uuid ComputeCoordinatesImageGeomFilter::uuid() const |
| 31 | +{ |
| 32 | + return FilterTraits<ComputeCoordinatesImageGeomFilter>::uuid; |
| 33 | +} |
| 34 | + |
| 35 | +//------------------------------------------------------------------------------ |
| 36 | +std::string ComputeCoordinatesImageGeomFilter::humanName() const |
| 37 | +{ |
| 38 | + return "Compute Coordinates/Indices Array From Image Geom"; |
| 39 | +} |
| 40 | + |
| 41 | +//------------------------------------------------------------------------------ |
| 42 | +std::vector<std::string> ComputeCoordinatesImageGeomFilter::defaultTags() const |
| 43 | +{ |
| 44 | + return {className(), "stats", "statistics"}; |
| 45 | +} |
| 46 | + |
| 47 | +//------------------------------------------------------------------------------ |
| 48 | +Parameters ComputeCoordinatesImageGeomFilter::parameters() const |
| 49 | +{ |
| 50 | + Parameters params; |
| 51 | + |
| 52 | + // Create the parameter descriptors that are needed for this filter |
| 53 | + params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); |
| 54 | + params.insertLinkableParameter(std::make_unique<ChoicesParameter>(k_OutputType_Key, "Output Array(s) Type", "The selection here effects which arrays will be produced by the filter", |
| 55 | + to_underlying(ComputeCoordinatesImageGeom::OutputType::Physical), |
| 56 | + ChoicesParameter::Choices{"Physical Coordinates", "Indices", "Both"})); // sequence dependent DO NOT REORDER |
| 57 | + |
| 58 | + params.insertSeparator(Parameters::Separator{"Input Data Objects"}); |
| 59 | + params.insert(std::make_unique<GeometrySelectionParameter>(k_SelectedImageGeomPath_Key, "Selected Image Geometry", |
| 60 | + "The DataPath to the Image Geometry that produced coordinates or indices will map to", DataPath{}, |
| 61 | + GeometrySelectionParameter::AllowedTypes{IGeometry::Type::Image})); |
| 62 | + |
| 63 | + params.insertSeparator(Parameters::Separator{"Output Data Array(s)"}); |
| 64 | + params.insert(std::make_unique<ArrayCreationParameter>(k_CoordsArrayPath_Key, "Created Physical Coordinate Array Path", |
| 65 | + "name and path of a new float32 DataArray containing the physical XYZ coordinate of the selected Image Geometry in global space", |
| 66 | + DataPath({"Image Physical Coordinates"}))); |
| 67 | + params.insert(std::make_unique<ArrayCreationParameter>(k_IndicesArrayPath_Key, "Created Indices Array Path", |
| 68 | + "name and path of a new int32 DataArray containing the XYZ indices of the selected Image Geometry", DataPath({"Image Indices"}))); |
| 69 | + |
| 70 | + // Associate the Linkable Parameter(s) to the children parameters that they control |
| 71 | + params.linkParameters(k_OutputType_Key, k_CoordsArrayPath_Key, static_cast<ChoicesParameter::ValueType>(to_underlying(ComputeCoordinatesImageGeom::OutputType::Physical))); |
| 72 | + |
| 73 | + params.linkParameters(k_OutputType_Key, k_IndicesArrayPath_Key, static_cast<ChoicesParameter::ValueType>(to_underlying(ComputeCoordinatesImageGeom::OutputType::Index))); |
| 74 | + |
| 75 | + params.linkParameters(k_OutputType_Key, k_CoordsArrayPath_Key, static_cast<ChoicesParameter::ValueType>(to_underlying(ComputeCoordinatesImageGeom::OutputType::Both))); |
| 76 | + params.linkParameters(k_OutputType_Key, k_IndicesArrayPath_Key, static_cast<ChoicesParameter::ValueType>(to_underlying(ComputeCoordinatesImageGeom::OutputType::Both))); |
| 77 | + |
| 78 | + return params; |
| 79 | +} |
| 80 | + |
| 81 | +//------------------------------------------------------------------------------ |
| 82 | +IFilter::VersionType ComputeCoordinatesImageGeomFilter::parametersVersion() const |
| 83 | +{ |
| 84 | + return 1; |
| 85 | +} |
| 86 | + |
| 87 | +//------------------------------------------------------------------------------ |
| 88 | +IFilter::UniquePointer ComputeCoordinatesImageGeomFilter::clone() const |
| 89 | +{ |
| 90 | + return std::make_unique<ComputeCoordinatesImageGeomFilter>(); |
| 91 | +} |
| 92 | + |
| 93 | +//------------------------------------------------------------------------------ |
| 94 | +IFilter::PreflightResult ComputeCoordinatesImageGeomFilter::preflightImpl(const DataStructure& dataStructure, const Arguments& filterArgs, const MessageHandler& messageHandler, |
| 95 | + const std::atomic_bool& shouldCancel, const ExecutionContext& executionContext) const |
| 96 | +{ |
| 97 | + auto pOutputTypeValue = filterArgs.value<ChoicesParameter::ValueType>(k_OutputType_Key); |
| 98 | + auto pSelectedImageGeomValue = filterArgs.value<GeometrySelectionParameter::ValueType>(k_SelectedImageGeomPath_Key); |
| 99 | + auto pCoordsArrayPathValue = filterArgs.value<ArrayCreationParameter::ValueType>(k_CoordsArrayPath_Key); |
| 100 | + auto pIndicesArrayPathValue = filterArgs.value<ArrayCreationParameter::ValueType>(k_IndicesArrayPath_Key); |
| 101 | + |
| 102 | + nx::core::Result<OutputActions> resultOutputActions; |
| 103 | + |
| 104 | + usize numberOfCells = dataStructure.getDataRefAs<ImageGeom>(pSelectedImageGeomValue).getNumberOfCells(); |
| 105 | + |
| 106 | + if(pOutputTypeValue != to_underlying(ComputeCoordinatesImageGeom::OutputType::Index)) |
| 107 | + { |
| 108 | + auto createAction = std::make_unique<CreateArrayAction>(DataType::float32, std::vector<usize>{numberOfCells}, std::vector<usize>{3}, pCoordsArrayPathValue); |
| 109 | + resultOutputActions.value().appendAction(std::move(createAction)); |
| 110 | + } |
| 111 | + |
| 112 | + if(pOutputTypeValue != to_underlying(ComputeCoordinatesImageGeom::OutputType::Physical)) |
| 113 | + { |
| 114 | + auto createAction = std::make_unique<CreateArrayAction>(DataType::int32, std::vector<usize>{numberOfCells}, std::vector<usize>{3}, pIndicesArrayPathValue); |
| 115 | + resultOutputActions.value().appendAction(std::move(createAction)); |
| 116 | + } |
| 117 | + |
| 118 | + // Return both the resultOutputActions and the preflightUpdatedValues via std::move() |
| 119 | + return {std::move(resultOutputActions)}; |
| 120 | +} |
| 121 | + |
| 122 | +//------------------------------------------------------------------------------ |
| 123 | +Result<> ComputeCoordinatesImageGeomFilter::executeImpl(DataStructure& dataStructure, const Arguments& filterArgs, const PipelineFilter* pipelineNode, const MessageHandler& messageHandler, |
| 124 | + const std::atomic_bool& shouldCancel, const ExecutionContext& executionContext) const |
| 125 | +{ |
| 126 | + ComputeCoordinatesImageGeomInputValues inputValues; |
| 127 | + |
| 128 | + inputValues.CoordinateOption = filterArgs.value<ChoicesParameter::ValueType>(k_OutputType_Key); |
| 129 | + inputValues.ImageGeomPath = filterArgs.value<GeometrySelectionParameter::ValueType>(k_SelectedImageGeomPath_Key); |
| 130 | + inputValues.CoordArrayPath = filterArgs.value<ArrayCreationParameter::ValueType>(k_CoordsArrayPath_Key); |
| 131 | + inputValues.IndexArrayPath = filterArgs.value<ArrayCreationParameter::ValueType>(k_IndicesArrayPath_Key); |
| 132 | + |
| 133 | + return ComputeCoordinatesImageGeom(dataStructure, messageHandler, shouldCancel, &inputValues)(); |
| 134 | +} |
| 135 | +} // namespace nx::core |
0 commit comments