Skip to content

Commit

Permalink
Update affected filters to emit a warning about the removal of neighb…
Browse files Browse the repository at this point in the history
…or lists.

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Apr 25, 2024
1 parent 2369fba commit 68eb4ae
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 78 deletions.
6 changes: 6 additions & 0 deletions src/Plugins/SimplnxCore/docs/CropImageGeometry.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

This **Filter** allows the user to crop a region of interest (ROI) from an **Image Geometry**. The input parameters are in units of voxels or physical coordinates.


## WARNING: NeighborList Removal

If the option to "Renumber Features" is turn ON and the Cell Feature AttributeMatrix contains any *NeighborList* data arrays, those arrays will be **REMOVED** because those lists are now invalid. Re-run the *Find Neighbors* filter to re-create the lists.


## Examples

In the following examples, the following image is being used.
Expand Down
4 changes: 2 additions & 2 deletions src/Plugins/SimplnxCore/docs/MinNeighbors.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ This **Filter** sets the minimum number of contiguous neighboring **Features** a

The **Filter** can be run in a mode where the minimum number of neighbors is applied to a single **Ensemble**. The user can select to apply the minimum to one specific **Ensemble**.

## Notes
## WARNING: NeighborList Removal

If any features are removed **and** the Cell Feature AttributeMatrix contains any *NeighborList* data arrays those arrays will be **REMOVED** because those lists are now invalid. Re-run the *Find Neighbors* filter to re-create the lists.
If the Cell Feature AttributeMatrix contains any *NeighborList* data arrays, those arrays will be **REMOVED** because those lists are now invalid. Re-run the *Find Neighbors* filter to re-create the lists.

% Auto generated parameter table will be inserted here

Expand Down
10 changes: 10 additions & 0 deletions src/Plugins/SimplnxCore/docs/RemoveFlaggedFeaturesFilter.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ Processing (Cleanup)

This **Filter** will remove **Features** that have been flagged by another **Filter** from the structure. The **Filter** requires that the user point to a boolean array at the **Feature** level that tells the **Filter** whether the **Feature** should remain in the structure. If the boolean array is *false* for a **Feature**, then all **Cells** that belong to that **Feature** are temporarily *unassigned*. Optionally, after all *undesired* **Features** are removed, the remaining **Features** are isotropically coarsened to fill in the gaps left by the removed **Features**.

| Operation | Meaning |
|-----------|---------|
| 0 | Remove features. |
| 1 | Extract features into new geometry. |
| 2 | Extract features and then remove them. |

## WARNING: NeighborList Removal

If the operation is [0] or [2] and the Cell Feature AttributeMatrix contains any *NeighborList* data arrays, those arrays will be **REMOVED** because those lists are now invalid. Re-run the *Find Neighbors* filter to re-create the lists.

## Caveats

This filter will **ONLY** run on an Image Geometry.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ This **Filter** removes **Features** that have a total number of **Cells** below

The **Filter** can be run in a mode where the minimum number of neighbors is applied to a single **Ensemble**. The user can select to apply the minimum to one specific **Ensemble**.

## Notes
## WARNING: NeighborList Removal

If any features are removed **and** the Cell Feature AttributeMatrix contains any *NeighborList* data arrays those arrays will be **REMOVED** because those lists are now invalid. Re-run the *Find Neighbors* filter to re-create the lists.
If the Cell Feature AttributeMatrix contains any *NeighborList* data arrays, those arrays will be **REMOVED** because those lists are now invalid. Re-run the *Find Neighbors* filter to re-create the lists.

% Auto generated parameter table will be inserted here

Expand Down
4 changes: 4 additions & 0 deletions src/Plugins/SimplnxCore/docs/ResampleImageGeomFilter.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Sampling (Resample)

This **Filter** changes the **Cell** spacing/resolution based on inputs from the user. There are several resampling modes:

## WARNING: NeighborList Removal

If the option to "Renumber Features" is turn ON and the Cell Feature AttributeMatrix contains any *NeighborList* data arrays, those arrays will be **REMOVED** because those lists are now invalid. Re-run the *Find Neighbors* filter to re-create the lists.

### Spacing

The values entered are the desired new spacings (not multiples of the current resolution). The number of **Cells** in the volume will change when the spacing values are changed and thus the user should be cautious of generating "too many" **Cells** by entering very small values (i.e., very high resolution).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
#include "simplnx/Parameters/VectorParameter.hpp"
#include "simplnx/Utilities/DataArrayUtilities.hpp"
#include "simplnx/Utilities/DataGroupUtilities.hpp"
#include "simplnx/Utilities/FilterUtilities.hpp"
#include "simplnx/Utilities/GeometryHelpers.hpp"
#include "simplnx/Utilities/ParallelAlgorithmUtilities.hpp"
#include "simplnx/Utilities/ParallelDataAlgorithm.hpp"
#include "simplnx/Utilities/ParallelTaskAlgorithm.hpp"
#include "simplnx/Utilities/SamplingUtils.hpp"

#include "simplnx/Utilities/SIMPLConversion.hpp"

#include "simplnx/Utilities/SamplingUtils.hpp"
#include "simplnx/Utilities/StringUtilities.hpp"

using namespace nx::core;
Expand Down Expand Up @@ -462,6 +461,7 @@ IFilter::PreflightResult CropImageGeometry::preflightImpl(const DataStructure& d
}
std::string warningMsg;
DataPath destCellFeatureAmPath = destImagePath.createChildPath(cellFeatureAmPath.getTargetName());
DataPath anyFeatureAMDataPath;
auto tDims = srcCellFeatureData->getShape();
resultOutputActions.value().appendAction(std::make_unique<CreateAttributeMatrixAction>(destCellFeatureAmPath, tDims));
for(const auto& [identifier, object] : *srcCellFeatureData)
Expand All @@ -480,9 +480,11 @@ IFilter::PreflightResult CropImageGeometry::preflightImpl(const DataStructure& d
}
if(!warningMsg.empty())
{
resultOutputActions.m_Warnings.push_back(
Warning({-55503, fmt::format("This filter modifies the Cell Level Array '{}', the following arrays are of type NeighborList and will not be copied over:{}", featureIdsArrayPath.toString(),
warningMsg)}));
resultOutputActions.m_Warnings.push_back(Warning(
{-55503,
fmt::format(
"This filter will modify the Cell Level Array '{}' which causes all Feature level NeighborLists to become invalid. These NeighborLists will not be copied to the new geometry:{}",
featureIdsArrayPath.toString(), warningMsg)}));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ Parameters FindFeatureClusteringFilter::parameters() const
params.insert(std::make_unique<AttributeMatrixSelectionParameter>(k_CellEnsembleAttributeMatrixPath_Key, "Cell Ensemble Attribute Matrix",
"The path to the cell ensemble attribute matrix where the RDF and RDF min and max distance arrays will be stored", DataPath{}));
params.insertSeparator(Parameters::Separator{"Created Cell Feature Data"});
params.insert(
std::make_unique<DataObjectNameParameter>(k_ClusteringListArrayName_Key, "Clustering List", "Distance of each Feature's centroid to every other Feature's centroid", "ClusteringList"));
params.insert(std::make_unique<DataObjectNameParameter>(k_ClusteringListArrayName_Key, "Clustering List", "Distance of each Feature's centroid to every other Feature's centroid", "ClusteringList"));
params.insertSeparator(Parameters::Separator{"Created Cell Ensemble Data"});
params.insert(std::make_unique<DataObjectNameParameter>(k_RDFArrayName_Key, "Radial Distribution Function", "A histogram of the normalized frequency at each bin", "RDF"));
params.insert(std::make_unique<DataObjectNameParameter>(k_MaxMinArrayName_Key, "Max and Min Separation Distances", "The max and min distance found between Features", "RDFMaxMinDistances"));
Expand Down
36 changes: 5 additions & 31 deletions src/Plugins/SimplnxCore/src/SimplnxCore/Filters/MinNeighbors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
#include "simplnx/DataStructure/DataArray.hpp"
#include "simplnx/DataStructure/Geometry/ImageGeom.hpp"
#include "simplnx/Filter/Actions/DeleteDataAction.hpp"

#include "simplnx/Parameters/ArraySelectionParameter.hpp"
#include "simplnx/Parameters/AttributeMatrixSelectionParameter.hpp"
#include "simplnx/Parameters/BoolParameter.hpp"
#include "simplnx/Parameters/GeometrySelectionParameter.hpp"
#include "simplnx/Parameters/MultiArraySelectionParameter.hpp"
#include "simplnx/Parameters/NumberParameter.hpp"

#include "simplnx/Utilities/SIMPLConversion.hpp"

#include "simplnx/Utilities/DataGroupUtilities.hpp"
#include "simplnx/Utilities/FilterUtilities.hpp"
#include "simplnx/Utilities/SIMPLConversion.hpp"

namespace nx::core
{
Expand All @@ -23,7 +20,6 @@ namespace
constexpr int64 k_TupleCountInvalidError = -250;
constexpr int64 k_MissingFeaturePhasesError = -251;
constexpr int32 k_InconsistentTupleCount = -252;
constexpr int32 k_NeighborListRemoval = -5558;
constexpr int32 k_FetchChildArrayError = -5559;

void assignBadPoints(DataStructure& data, const Arguments& args, const std::atomic_bool& shouldCancel)
Expand Down Expand Up @@ -405,33 +401,11 @@ IFilter::PreflightResult MinNeighbors::preflightImpl(const DataStructure& dataSt
// Feature Data is going to be modified
nx::core::AppendDataObjectModifications(dataStructure, resultOutputActions.value().modifiedActions, numNeighborsPath.getParent(), {});

// This section gives a warning to the user about NeighborLists possibly being removed
// This section will warn the user about the removal of NeighborLists
auto result = nx::core::NeighborListRemovalPreflightCode(dataStructure, featureIdsPath, numNeighborsPath, resultOutputActions);
if(result.outputActions.invalid())
{
DataPath featureGroupDataPath = numNeighborsPath.getParent();

// 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",
featureIdsPath.toString(), featureGroupDataPath.toString());

auto result = nx::core::GetAllChildDataPaths(dataStructure, featureGroupDataPath, DataObject::Type::NeighborList);
if(!result.has_value())
{
return {nonstd::make_unexpected(
std::vector<Error>{Error{k_FetchChildArrayError, fmt::format("Errors were encountered trying to retrieve the neighbor list children of group '{}'", featureGroupDataPath.toString())}})};
}
std::vector<DataPath> featureNeighborListArrays = result.value();
for(const auto& featureNeighborList : featureNeighborListArrays)
{
ss.append(" " + featureNeighborList.toString() + "\n");
auto action = std::make_unique<DeleteDataAction>(featureNeighborList);
resultOutputActions.value().deferredActions.emplace_back(std::move(action));
}

// Inform users that the following arrays are going to be modified in place
// Feature Data is going to be modified
nx::core::AppendDataObjectModifications(dataStructure, resultOutputActions.value().modifiedActions, featureGroupDataPath, {});

resultOutputActions.warnings().push_back(Warning{k_NeighborListRemoval, ss});
return result;
}

// Return both the resultOutputActions and the preflightUpdatedValues via std::move()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
#include "simplnx/Parameters/ChoicesParameter.hpp"
#include "simplnx/Parameters/GeometrySelectionParameter.hpp"
#include "simplnx/Parameters/MultiArraySelectionParameter.hpp"

#include "simplnx/Utilities/SIMPLConversion.hpp"

#include "simplnx/Parameters/StringParameter.hpp"
#include "simplnx/Utilities/FilterUtilities.hpp"
#include "simplnx/Utilities/SIMPLConversion.hpp"

using namespace nx::core;

Expand Down Expand Up @@ -171,6 +169,13 @@ IFilter::PreflightResult RemoveFlaggedFeaturesFilter::preflightImpl(const DataSt
nx::core::AppendDataObjectModifications(dataStructure, resultOutputActions.value().modifiedActions, pFeatureIdsArrayPathValue.getParent(), {});
// Feature Data is going to be modified
nx::core::AppendDataObjectModifications(dataStructure, resultOutputActions.value().modifiedActions, pFlaggedFeaturesArrayPathValue.getParent(), {});

// This section will warn the user about the removal of NeighborLists
auto result = nx::core::NeighborListRemovalPreflightCode(dataStructure, pFeatureIdsArrayPathValue, pFlaggedFeaturesArrayPathValue, resultOutputActions);
if(result.outputActions.invalid())
{
return result;
}
}

return {std::move(resultOutputActions), std::move(preflightUpdatedValues)};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,32 +370,13 @@ IFilter::PreflightResult RemoveMinimumSizeFeaturesFilter::preflightImpl(const Da
nx::core::Result<OutputActions> resultOutputActions;
std::vector<PreflightValue> preflightUpdatedValues;

// This section gives a warning to the user about NeighborLists possibly being removed
// This section will warn the user about the removal of NeighborLists
auto result = nx::core::NeighborListRemovalPreflightCode(dataStructure, featureIdsPath, featurePhasesPath, resultOutputActions);
if(result.outputActions.invalid())
{
// 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",
featureIdsPath.toString(), featureGroupDataPath.toString());

auto result = nx::core::GetAllChildDataPaths(dataStructure, featureGroupDataPath, DataObject::Type::NeighborList);
if(!result.has_value())
{
return {nonstd::make_unexpected(
std::vector<Error>{Error{k_FetchChildArrayError, fmt::format("Errors were encountered trying to retrieve the neighbor list children of group '{}'", featureGroupDataPath.toString())}})};
}
std::vector<DataPath> featureNeighborListArrays = result.value();
for(const auto& featureNeighborList : featureNeighborListArrays)
{
ss.append(" " + featureNeighborList.toString() + "\n");
auto action = std::make_unique<DeleteDataAction>(featureNeighborList);
resultOutputActions.value().deferredActions.emplace_back(std::move(action));
}

// Inform users that the following arrays are going to be modified in place
// Feature Data is going to be modified
nx::core::AppendDataObjectModifications(dataStructure, resultOutputActions.value().modifiedActions, featureGroupDataPath, {});

resultOutputActions.warnings().push_back(Warning{k_NeighborListRemoval, ss});
return result;
}

// Return both the resultOutputActions and the preflightUpdatedValues via std::move()
return {std::move(resultOutputActions), std::move(preflightUpdatedValues)};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,10 @@ IFilter::PreflightResult ResampleImageGeomFilter::preflightImpl(const DataStruct
}
if(!warningMsg.empty())
{
resultOutputActions.m_Warnings.push_back(
Warning({-55503, fmt::format("This filter modifies the Cell Level Array '{}', the following arrays are of type NeighborList and will not be copied over:{}", featureIdsArrayPath.toString(),
warningMsg)}));
resultOutputActions.m_Warnings.push_back(Warning(
{-55503,
fmt::format("This filter will modify the Cell Level Array '{}' which causes all Feature level NeighborLists to become invalid. These NeighborLists will not be copied to the new geometry:{}",

Check failure on line 297 in src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ResampleImageGeomFilter.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

code should be clang-formatted [-Wclang-format-violations]

Check failure on line 297 in src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ResampleImageGeomFilter.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

code should be clang-formatted [-Wclang-format-violations]
featureIdsArrayPath.toString(), warningMsg)}));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/simplnx/Filter/Actions/DeleteDataAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Result<> TerminateNode(DataStructure& dataStructure, const DataPath& path, IData
DataObject* targetObject = dataStructure.getData(path);
if(targetObject == nullptr)
{
return MakeWarningVoidResult(k_TargetNotFoundErrorCode, fmt::format("Trying to delete DataObject '{}' which does not exist.", path.getTargetName()));
return MakeErrorResult(k_TargetNotFoundErrorCode, fmt::format("Trying to delete DataObject '{}' which does not exist.", path.getTargetName()));
}

dataStructure.removeData(targetObject->getId());
Expand Down
3 changes: 1 addition & 2 deletions src/simplnx/Utilities/DataGroupUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ bool RemoveInactiveObjects(DataStructure& dataStructure, const DataPath& feature
std::vector<DataPath> neighborListDataPaths = result.value();
for(const auto& neighborListDataPath : neighborListDataPaths)
{
messageHandler(nx::core::IFilter::Message{nx::core::IFilter::Message::Type::Info, fmt::format("NeighborList '{}' was removed from the DataStructure.", neighborListDataPath.toString())});
dataStructure.removeData(neighborListDataPath);
messageHandler(nx::core::IFilter::Message{nx::core::IFilter::Message::Type::Info, fmt::format("NeighborList '{}' will be from the DataStructure.", neighborListDataPath.toString())});
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/simplnx/Utilities/DataGroupUtilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ namespace nx::core
{

/**
* @brief RemoveInactiveObjects This assumes a single Dimension TupleShape, i.e., a Linear array, (1D).
* @brief RemoveInactiveObjects This assumes a single Dimension TupleShape, i.e., a Linear array, (1D)
*
* NeighborLists are NO LONGER Removed. That is the responsibility of the filter.
*
* @param dataStructure
* @param featureDataGroupPath
Expand Down
38 changes: 38 additions & 0 deletions src/simplnx/Utilities/FilterUtilities.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "FilterUtilities.hpp"

#include "simplnx/Filter/Actions/DeleteDataAction.hpp"
#include "simplnx/Utilities/DataGroupUtilities.hpp"

#include <fmt/core.h>

#include <string>
Expand Down Expand Up @@ -39,4 +42,39 @@ void AppendDataObjectModifications(const DataStructure& dataStructure, std::vect
}
}

// -----------------------------------------------------------------------------
IFilter::PreflightResult NeighborListRemovalPreflightCode(const DataStructure& dataStructure, const DataPath& featureIdsPath, const DataPath& numNeighborsPath,
nx::core::Result<OutputActions>& resultOutputActions)
{
constexpr int32 k_FetchChildArrayError = -5559;
constexpr int32 k_NeighborListRemoval = -5558;

DataPath featureGroupDataPath = numNeighborsPath.getParent();

// Throw a warning to inform the user that the neighbor list arrays could be deleted by this filter
std::string ss =
fmt::format("This filter WILL remove all arrays of type NeighborList from the feature Attribute Matrix '{}'. These arrays are:\n", featureIdsPath.toString(), featureGroupDataPath.toString());

auto result = nx::core::GetAllChildDataPaths(dataStructure, featureGroupDataPath, DataObject::Type::NeighborList);
if(!result.has_value())
{
return {nonstd::make_unexpected(
std::vector<Error>{Error{k_FetchChildArrayError, fmt::format("Errors were encountered trying to retrieve the neighbor list children of group '{}'", featureGroupDataPath.toString())}})};
}
std::vector<DataPath> featureNeighborListArrays = result.value();
for(const auto& featureNeighborList : featureNeighborListArrays)
{
ss.append(" " + featureNeighborList.toString() + "\n");
auto action = std::make_unique<DeleteDataAction>(featureNeighborList);
resultOutputActions.value().deferredActions.emplace_back(std::move(action));
}

// Inform users that the following arrays are going to be modified in place
// Feature Data is going to be modified
nx::core::AppendDataObjectModifications(dataStructure, resultOutputActions.value().modifiedActions, featureGroupDataPath, {});

resultOutputActions.warnings().push_back(Warning{k_NeighborListRemoval, ss});
return {};
}

} // namespace nx::core
Loading

0 comments on commit 68eb4ae

Please sign in to comment.