From b1015426894d7865acb167a199151afbe9da8a02 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 9 Oct 2023 10:07:28 -0400 Subject: [PATCH] ENH: Create DataModifiedAction that marks DataObjects as being modified by a filter Signed-off-by: Michael Jackson --- .../RemoveMinimumSizeFeaturesFilter.cpp | 27 +++++++++++++------ src/complex/Filter/Output.hpp | 22 +++++++++++++++ src/complex/Pipeline/PipelineFilter.cpp | 21 ++++++++++++--- src/complex/Pipeline/PipelineFilter.hpp | 7 +++++ 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/src/Plugins/ComplexCore/src/ComplexCore/Filters/RemoveMinimumSizeFeaturesFilter.cpp b/src/Plugins/ComplexCore/src/ComplexCore/Filters/RemoveMinimumSizeFeaturesFilter.cpp index 19b3279b35..21d4426f11 100644 --- a/src/Plugins/ComplexCore/src/ComplexCore/Filters/RemoveMinimumSizeFeaturesFilter.cpp +++ b/src/Plugins/ComplexCore/src/ComplexCore/Filters/RemoveMinimumSizeFeaturesFilter.cpp @@ -277,7 +277,7 @@ std::string RemoveMinimumSizeFeaturesFilter::humanName() const //------------------------------------------------------------------------------ std::vector RemoveMinimumSizeFeaturesFilter::defaultTags() const { - return {className(), "Processing", "Cleanup", "MinSize"}; + return {className(), "Processing", "Cleanup", "MinSize", "Feature Removal"}; } Parameters RemoveMinimumSizeFeaturesFilter::parameters() const @@ -363,10 +363,8 @@ IFilter::PreflightResult RemoveMinimumSizeFeaturesFilter::preflightImpl(const Da } // Create the preflightResult object - IFilter::PreflightResult preflightResult; - - // Create our OutputActions Object - OutputActions outputActions; + complex::Result resultOutputActions; + std::vector preflightUpdatedValues; // Throw a warning to inform the user that the neighbor list arrays could be deleted by this filter std::string ss = fmt::format("If this filter modifies the Cell Level Array '{}', all arrays of type NeighborList will be deleted from the feature data group '{}'. These arrays are:\n", @@ -383,12 +381,25 @@ IFilter::PreflightResult RemoveMinimumSizeFeaturesFilter::preflightImpl(const Da { ss.append(" " + featureNeighborList.toString() + "\n"); auto action = std::make_unique(featureNeighborList); - outputActions.appendAction(std::move(action)); + resultOutputActions.value().actions.emplace_back(std::move(action)); + } + + result = complex::GetAllChildDataPaths(data, featureGroupDataPath); + if(!result.has_value()) + { + return {nonstd::make_unexpected( + std::vector{Error{k_FetchChildArrayError, fmt::format("Errors were encountered trying to retrieve the children of DataGroup '{}'", featureGroupDataPath.toString())}})}; + } + const std::vector featureDataGroupChildren = result.value(); + for(const auto& child : featureDataGroupChildren) + { + resultOutputActions.value().modifiedActions.emplace_back(DataModifiedAction{child, DataModifiedAction::ModifiedType::DataArrayModified}); } - preflightResult.outputActions.warnings().push_back(Warning{k_NeighborListRemoval, ss}); + resultOutputActions.warnings().push_back(Warning{k_NeighborListRemoval, ss}); - return preflightResult; + // Return both the resultOutputActions and the preflightUpdatedValues via std::move() + return {std::move(resultOutputActions), std::move(preflightUpdatedValues)}; } // ----------------------------------------------------------------------------- diff --git a/src/complex/Filter/Output.hpp b/src/complex/Filter/Output.hpp index 9d82067dc4..3d2b22eac6 100644 --- a/src/complex/Filter/Output.hpp +++ b/src/complex/Filter/Output.hpp @@ -107,6 +107,22 @@ class COMPLEX_EXPORT IDataCreationAction : public IDataAction DataPath m_CreatedPath; }; +/** + * @brief + */ +struct COMPLEX_EXPORT DataModifiedAction +{ + + enum class ModifiedType : uint64 + { + DataArrayModified = 0, + DataArrayPossiblyDeleted = 1, + }; + + DataPath m_ModifiedPath; + ModifiedType m_ModifiedType; +}; + /** * @brief Container for IDataActions */ @@ -114,6 +130,7 @@ struct COMPLEX_EXPORT OutputActions { std::vector actions = {}; std::vector deferredActions = {}; + std::vector modifiedActions = {}; OutputActions() = default; @@ -139,6 +156,11 @@ struct COMPLEX_EXPORT OutputActions deferredActions.emplace_back(std::move(action)); } + void appendModifiedAction(const DataPath& dataPath, DataModifiedAction::ModifiedType modifiedType) + { + modifiedActions.emplace_back(DataModifiedAction{dataPath, modifiedType}); + } + static Result<> ApplyActions(nonstd::span actions, DataStructure& dataStructure, IDataAction::Mode mode); Result<> applyRegular(DataStructure& dataStructure, IDataAction::Mode mode) const; diff --git a/src/complex/Pipeline/PipelineFilter.cpp b/src/complex/Pipeline/PipelineFilter.cpp index 93cf16fdf6..1cd1e6d6b2 100644 --- a/src/complex/Pipeline/PipelineFilter.cpp +++ b/src/complex/Pipeline/PipelineFilter.cpp @@ -140,25 +140,33 @@ bool PipelineFilter::preflight(DataStructure& data, RenamedPaths& renamedPaths, } std::vector newCreatedPaths; + std::vector newModifiedPaths; for(const auto& action : result.outputActions.value().actions) { - if(const auto* creationAction = dynamic_cast(action.get()); creationAction != nullptr) + if(const auto* creationActionPtr = dynamic_cast(action.get()); creationActionPtr != nullptr) { - auto allCreatedPaths = creationAction->getAllCreatedPaths(); + auto allCreatedPaths = creationActionPtr->getAllCreatedPaths(); newCreatedPaths.insert(newCreatedPaths.end(), allCreatedPaths.begin(), allCreatedPaths.end()); } } + for(const auto& action : result.outputActions.value().deferredActions) { - if(const auto* creationAction = dynamic_cast(action.get()); creationAction != nullptr) + if(const auto* creationActionPtr = dynamic_cast(action.get()); creationActionPtr != nullptr) { - auto allCreatedPaths = creationAction->getAllCreatedPaths(); + auto allCreatedPaths = creationActionPtr->getAllCreatedPaths(); newCreatedPaths.insert(newCreatedPaths.end(), allCreatedPaths.begin(), allCreatedPaths.end()); } } + for(const auto& action : result.outputActions.value().modifiedActions) + { + newModifiedPaths.emplace_back(action.m_ModifiedPath); + } + // Do not clear the created paths unless the preflight succeeded m_CreatedPaths = newCreatedPaths; + m_ModifiedPaths = newModifiedPaths; setPreflightStructure(data); sendFilterFaultMessage(m_Index, getFaultState()); @@ -219,6 +227,11 @@ std::vector PipelineFilter::getCreatedPaths() const return m_CreatedPaths; } +std::vector PipelineFilter::getModifiedPaths() const +{ + return m_ModifiedPaths; +} + namespace { /** diff --git a/src/complex/Pipeline/PipelineFilter.hpp b/src/complex/Pipeline/PipelineFilter.hpp index 0eee2d285e..7a6545dc08 100644 --- a/src/complex/Pipeline/PipelineFilter.hpp +++ b/src/complex/Pipeline/PipelineFilter.hpp @@ -146,6 +146,12 @@ class COMPLEX_EXPORT PipelineFilter : public AbstractPipelineNode */ std::vector getCreatedPaths() const; + /** + * @brief Returns a vector of DataPaths that would be modified when executing the node + * @return std::vector + */ + std::vector getModifiedPaths() const; + /** * @brief Returns a collection of warnings returned by the target filter. * This collection is cleared when the node is preflighted or executed. @@ -220,5 +226,6 @@ class COMPLEX_EXPORT PipelineFilter : public AbstractPipelineNode std::vector m_Errors; std::vector m_PreflightValues; std::vector m_CreatedPaths; + std::vector m_ModifiedPaths; }; } // namespace complex