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 @@ -2,7 +2,6 @@

#include "simplnx/DataStructure/AttributeMatrix.hpp"
#include "simplnx/DataStructure/DataArray.hpp"
#include "simplnx/DataStructure/DataStore.hpp"
#include "simplnx/Utilities/FilterUtilities.hpp"

using namespace nx::core;
Expand All @@ -17,30 +16,30 @@ struct CopyCellDataFunctor
const auto& selectedCellStore = selectedCellArray->template getIDataStoreRefAs<AbstractDataStore<T>>();
auto& createdDataStore = createdArray->template getIDataStoreRefAs<AbstractDataStore<T>>();

usize totalCellArrayComponents = selectedCellStore.getNumberOfComponents();
const usize totalCellArrayComponents = selectedCellStore.getNumberOfComponents();

std::map<int32, usize> featureMap;
Result<> result;

usize totalCellArrayTuples = selectedCellStore.getNumberOfTuples();
const usize totalCellArrayTuples = selectedCellStore.getNumberOfTuples();
for(usize cellTupleIdx = 0; cellTupleIdx < totalCellArrayTuples; cellTupleIdx++)
{
if(shouldCancel)
{
return {};
}

// Get the feature identifier (or what ever the user has selected as their "Feature" identifier
int32 featureIdx = featureIds[cellTupleIdx];
// Get the feature identifier (or whatever the user has selected as their "Feature" identifier
const int32 featureIdx = featureIds[cellTupleIdx];

// Store the index of the first tuple with this feature identifier in the map
if(featureMap.find(featureIdx) == featureMap.end())
if(!featureMap.contains(featureIdx))
{
featureMap[featureIdx] = totalCellArrayComponents * cellTupleIdx;
}

// Check that the values at the current index match the value at the first index
usize firstInstanceCellTupleIdx = featureMap[featureIdx];
const usize firstInstanceCellTupleIdx = featureMap[featureIdx];
for(usize cellCompIdx = 0; cellCompIdx < totalCellArrayComponents; cellCompIdx++)
{
T firstInstanceCellVal = selectedCellStore[firstInstanceCellTupleIdx + cellCompIdx];
Expand Down Expand Up @@ -83,13 +82,32 @@ Result<> CreateFeatureArrayFromElementArray::operator()()
auto* createdArray = m_DataStructure.getDataAs<IDataArray>(createdArrayPath);

// Resize the created array to the proper size
usize featureIdsMaxIdx = std::distance(featureIdsRef.begin(), std::max_element(featureIdsRef.cbegin(), featureIdsRef.cend()));
usize maxValue = featureIdsRef[featureIdsMaxIdx];
const usize featureIdsMaxIdx = std::distance(featureIdsRef.begin(), std::max_element(featureIdsRef.cbegin(), featureIdsRef.cend()));
const int32 maxValue = featureIdsRef[featureIdsMaxIdx];

// Validate no underflow
if(maxValue < 0)
{
return MakeErrorResult(-81880, "Invalid Input, Feature Ids Array must contain a positive value");
}

auto& cellFeatureAttrMat = m_DataStructure.getDataRefAs<AttributeMatrix>(m_InputValues->CellFeatureAttributeMatrixPath);

auto* createdArrayStore = createdArray->template getIDataStoreAs<IDataStore>();
createdArrayStore->resizeTuples(std::vector<usize>{maxValue + 1});
cellFeatureAttrMat.resizeTuples(std::vector<usize>{maxValue + 1});
// validate resize won't shrink child arrays
if(maxValue + 1 > cellFeatureAttrMat.getNumberOfTuples())
{
for(const auto& childObject : cellFeatureAttrMat)
{
const auto* iArray = dynamic_cast<IArray*>(childObject.second.get());
if(iArray != nullptr && iArray->getNumberOfTuples() > (maxValue + 1))
{
return MakeErrorResult(-81881, fmt::format("Resizing would cause data loss in {}. Make sure all objects in {} have tuple counts equal to or less then the max Feature ID {}!",
iArray->getName(), m_InputValues->CellFeatureAttributeMatrixPath.toString(), maxValue + 1));
}
}

cellFeatureAttrMat.resizeTuples(std::vector<usize>{static_cast<usize>(maxValue) + 1});
}

return ExecuteDataFunction(CopyCellDataFunctor{}, selectedCellArray->getDataType(), selectedCellArray, featureIdsRef, createdArray, m_ShouldCancel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "simplnx/DataStructure/DataArray.hpp"
#include "simplnx/DataStructure/DataPath.hpp"
#include "simplnx/DataStructure/DataStore.hpp"
#include "simplnx/Filter/Actions/CreateArrayAction.hpp"
#include "simplnx/Parameters/ArraySelectionParameter.hpp"
#include "simplnx/Parameters/AttributeMatrixSelectionParameter.hpp"
Expand Down Expand Up @@ -51,8 +50,7 @@ Parameters CreateFeatureArrayFromElementArrayFilter::parameters() const

// Create the parameter descriptors that are needed for this filter
params.insertSeparator(Parameters::Separator{"Input Data"});
params.insert(
std::make_unique<ArraySelectionParameter>(k_SelectedCellArrayPath_Key, "Data to Copy to Feature Data", "Element Data to Copy to Feature Data", DataPath{}, nx::core::GetAllDataTypes()));
params.insert(std::make_unique<ArraySelectionParameter>(k_SelectedCellArrayPath_Key, "Data to Copy to Feature Data", "Element Data to Copy to Feature Data", DataPath{}, GetAllDataTypes()));
params.insert(std::make_unique<ArraySelectionParameter>(k_CellFeatureIdsArrayPath_Key, "Cell Feature Ids", "Specifies to which feature each cell belongs.", DataPath({"Cell Data", "FeatureIds"}),
ArraySelectionParameter::AllowedTypes{DataType::int32}, ArraySelectionParameter::AllowedComponentShapes{{1}}));
params.insertSeparator(Parameters::Separator{"Input Feature Data"});
Expand Down Expand Up @@ -81,15 +79,15 @@ IFilter::UniquePointer CreateFeatureArrayFromElementArrayFilter::clone() const
IFilter::PreflightResult CreateFeatureArrayFromElementArrayFilter::preflightImpl(const DataStructure& dataStructure, const Arguments& filterArgs, const MessageHandler& messageHandler,
const std::atomic_bool& shouldCancel, const ExecutionContext& executionContext) const
{
auto pSelectedCellArrayPathValue = filterArgs.value<DataPath>(k_SelectedCellArrayPath_Key);
auto pFeatureIdsArrayPathValue = filterArgs.value<DataPath>(k_CellFeatureIdsArrayPath_Key);
auto pCellFeatureAttributeMatrixPathValue = filterArgs.value<DataPath>(k_CellFeatureAttributeMatrixPath_Key);
auto pCreatedArrayNameValue = filterArgs.value<std::string>(k_CreatedArrayName_Key);
const auto pSelectedCellArrayPathValue = filterArgs.value<DataPath>(k_SelectedCellArrayPath_Key);
const auto pFeatureIdsArrayPathValue = filterArgs.value<DataPath>(k_CellFeatureIdsArrayPath_Key);
const auto pCellFeatureAttributeMatrixPathValue = filterArgs.value<DataPath>(k_CellFeatureAttributeMatrixPath_Key);
const auto pCreatedArrayNameValue = filterArgs.value<std::string>(k_CreatedArrayName_Key);

const auto& selectedCellArray = dataStructure.getDataRefAs<IDataArray>(pSelectedCellArrayPathValue);
const IDataStore& selectedCellArrayStore = selectedCellArray.getIDataStoreRef();

nx::core::Result<OutputActions> resultOutputActions;
Result<OutputActions> resultOutputActions;
std::vector<PreflightValue> preflightUpdatedValues;

// Get the target Attribute Matrix that the output array will be stored with
Expand Down
Loading
Loading