Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,18 @@ Result<> RequireMinNumNeighbors::operator()()
// Mark all features to be removed with a -1 value.
for(usize i = 0; i < totalPoints; i++)
{
int32 featureId = featureIds[i];
const int32 featureId = featureIds[i];

if(featureId < 0)
{
continue;
}

if(static_cast<usize>(featureId) >= totalFeatures)
{
return MakeErrorResult(-55567, fmt::format("Feature ID '{}' in array '{}' is outside the valid range [0, {}).", featureId, m_InputValues->FeatureIdsPath.toString(), totalFeatures));
}

if(!activeObjects[featureId])
{
featureIds[i] = -1;
Expand Down Expand Up @@ -235,12 +246,6 @@ Result<> RequireMinNumNeighbors::operator()()
// Reset the voteCount array to all zeros
std::fill(voteCount.begin(), voteCount.end(), 0);
}
else if(featureName >= numFeatures)
{
std::string message = fmt::format("Error: Found a feature Id '{}' that is >= the number of features '{}' at voxel index X={},Y={},Z={}.", featureName, numFeatures, xIdx, yIdx, zIdx);
m_MessageHandler(nx::core::IFilter::Message{nx::core::IFilter::Message::Type::Info, message});
return MakeErrorResult(-55567, message);
}
}
}
}
Expand All @@ -262,7 +267,11 @@ Result<> RequireMinNumNeighbors::operator()()
{
return {};
}
CopyTupleFromArray(m_DataStructure, cellArrayPath, badFeatureIdIndexes, featureIds, neighbors, m_MessageHandler);
auto copyResult = CopyTupleFromArray(m_DataStructure, cellArrayPath, badFeatureIdIndexes, featureIds, neighbors, m_MessageHandler);
if(copyResult.invalid())
{
return copyResult;
}
}
}

Expand All @@ -277,7 +286,11 @@ Result<> RequireMinNumNeighbors::operator()()

m_MessageHandler(IFilter::Message::Type::Info, fmt::format("Feature Count Changed: Previous: {} New: {}", totalFeatures, count));
DataPath cellFeatureGroupPath = m_InputValues->NumNeighborsPath.getParent();
nx::core::RemoveInactiveObjects(m_DataStructure, cellFeatureGroupPath, activeObjects, featureIds, totalFeatures, m_MessageHandler, m_ShouldCancel);
if(!nx::core::RemoveInactiveObjects(m_DataStructure, cellFeatureGroupPath, activeObjects, featureIds, totalFeatures, m_MessageHandler, m_ShouldCancel))
{
return MakeErrorResult(-55570, fmt::format("Failed to remove inactive feature tuples from feature group '{}'. Check that its arrays match the tuple count of '{}'.",
cellFeatureGroupPath.toString(), m_InputValues->NumNeighborsPath.toString()));
}

return {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace nx::core
namespace
{
constexpr int32 k_InconsistentTupleCount = -252;
constexpr int32 k_FeatureIdsTupleCountMismatch = -55571;

} // namespace

Expand Down Expand Up @@ -119,10 +120,15 @@ IFilter::PreflightResult RequireMinNumNeighborsFilter::preflightImpl(const DataS

std::vector<DataPath> dataArrayPaths;

ShapeType cDims = {1};
auto& featureIds = dataStructure.getDataRefAs<Int32Array>(featureIdsPath);
auto& imageGeom = dataStructure.getDataRefAs<ImageGeom>(imageGeomPath);
if(featureIds.getNumberOfTuples() != imageGeom.getNumberOfCells())
{
return MakePreflightErrorResult(k_FeatureIdsTupleCountMismatch,
fmt::format("FeatureIds array '{}' contains {} tuples, but Image Geometry '{}' contains {} cells. Select a FeatureIds array that matches the Image Geometry.",
featureIdsPath.toString(), featureIds.getNumberOfTuples(), imageGeomPath.toString(), imageGeom.getNumberOfCells()));
}

auto& numNeighborsArray = dataStructure.getDataRefAs<Int32Array>(numNeighborsPath);
dataArrayPaths.push_back(numNeighborsPath);

if(applyToSinglePhase)
Expand Down
Loading
Loading