From 2b3526b83ce45bae7aece90665aa0c6aba48b1ea 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 | 16 +++++++- .../test/EBSDSegmentFeaturesFilterTest.cpp | 9 +++++ src/complex/Filter/Output.hpp | 39 +++++++++++++++++++ src/complex/Pipeline/PipelineFilter.cpp | 20 ++++++++-- src/complex/Pipeline/PipelineFilter.hpp | 7 ++++ 5 files changed, 86 insertions(+), 5 deletions(-) diff --git a/src/Plugins/ComplexCore/src/ComplexCore/Filters/RemoveMinimumSizeFeaturesFilter.cpp b/src/Plugins/ComplexCore/src/ComplexCore/Filters/RemoveMinimumSizeFeaturesFilter.cpp index 19b3279b35..8022b29ba0 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 @@ -386,6 +386,20 @@ IFilter::PreflightResult RemoveMinimumSizeFeaturesFilter::preflightImpl(const Da outputActions.appendAction(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())}})}; + } + std::vector featureDataGroupChildren = result.value(); + for(const auto& child : featureDataGroupChildren) + { + auto action = std::make_unique(child); + outputActions.appendAction(std::move(action)); + } + + preflightResult.outputActions.warnings().push_back(Warning{k_NeighborListRemoval, ss}); return preflightResult; diff --git a/src/Plugins/OrientationAnalysis/test/EBSDSegmentFeaturesFilterTest.cpp b/src/Plugins/OrientationAnalysis/test/EBSDSegmentFeaturesFilterTest.cpp index 35b8222b78..f5742219b3 100644 --- a/src/Plugins/OrientationAnalysis/test/EBSDSegmentFeaturesFilterTest.cpp +++ b/src/Plugins/OrientationAnalysis/test/EBSDSegmentFeaturesFilterTest.cpp @@ -78,6 +78,15 @@ TEST_CASE("OrientationAnalysis::EBSDSegmentFeatures: Valid Execution", "[Orienta auto preflightResult = filter.preflight(dataStructure, args); COMPLEX_RESULT_REQUIRE_VALID(preflightResult.outputActions); + + auto preflightAcctions = preflightResult.outputActions.value().actions; + + for(const auto& action : preflightAcctions) + { + const IDataCreationAction* creationActionPtr = dynamic_cast(action.get()); + std::cout << creationActionPtr->getCreatedPath().toString() << "\n"; + } + // Execute the filter and check the result auto executeResult = filter.execute(dataStructure, args); COMPLEX_RESULT_REQUIRE_VALID(executeResult.result); diff --git a/src/complex/Filter/Output.hpp b/src/complex/Filter/Output.hpp index 9d82067dc4..d9c5b8a2a2 100644 --- a/src/complex/Filter/Output.hpp +++ b/src/complex/Filter/Output.hpp @@ -107,6 +107,45 @@ class COMPLEX_EXPORT IDataCreationAction : public IDataAction DataPath m_CreatedPath; }; +class COMPLEX_EXPORT DataModifiedAction : public IDataAction +{ +public: + DataModifiedAction(const DataPath& modifiedPath) + : m_ModifiedPath(modifiedPath) + { + } + ~DataModifiedAction() noexcept override = default; + + DataModifiedAction(const DataModifiedAction&) = delete; + DataModifiedAction(DataModifiedAction&&) noexcept = delete; + DataModifiedAction& operator=(const DataModifiedAction&) = delete; + DataModifiedAction& operator=(DataModifiedAction&&) noexcept = delete; + + /** + * @brief Returns the DataPath of the top level object to be created. + * @return DataPath + */ + DataPath getModifiedPath() const + { + return m_ModifiedPath; + } + + Result<> apply(DataStructure& dataStructure, Mode mode) const + { + return {}; + } + UniquePointer clone() const + { + return std::make_unique(m_ModifiedPath); + } + +protected: + DataModifiedAction() = default; + +private: + DataPath m_ModifiedPath; +}; + /** * @brief Container for IDataActions */ diff --git a/src/complex/Pipeline/PipelineFilter.cpp b/src/complex/Pipeline/PipelineFilter.cpp index 93cf16fdf6..e062bb04e7 100644 --- a/src/complex/Pipeline/PipelineFilter.cpp +++ b/src/complex/Pipeline/PipelineFilter.cpp @@ -140,25 +140,32 @@ 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()); } + if(const auto* modifiedActionPtr = dynamic_cast(action.get()); modifiedActionPtr != nullptr) + { + newModifiedPaths.emplace_back(modifiedActionPtr->getModifiedPath()); + } + } 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()); } } // Do not clear the created paths unless the preflight succeeded m_CreatedPaths = newCreatedPaths; + m_ModifiedPaths = newModifiedPaths; setPreflightStructure(data); sendFilterFaultMessage(m_Index, getFaultState()); @@ -219,6 +226,11 @@ std::vector PipelineFilter::getCreatedPaths() const return m_CreatedPaths; } +std::vector PipelineFilter::getModifieldPaths() const +{ + return m_ModifiedPaths; +} + namespace { /** diff --git a/src/complex/Pipeline/PipelineFilter.hpp b/src/complex/Pipeline/PipelineFilter.hpp index 0eee2d285e..7b88fd22af 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 getModifieldPaths() 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