Skip to content

Commit

Permalink
Update CreateDataArray to require comp dims instead of number of comps.
Browse files Browse the repository at this point in the history
Signed-off-by: Joey Kleingers <[email protected]>
  • Loading branch information
joeykleingers committed Sep 6, 2024
1 parent 571a0f4 commit b5cab71
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
5 changes: 2 additions & 3 deletions src/Plugins/SimplnxCore/docs/CreateDataArrayFilter.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Core (Generation)

## Description

This **Filter** creates an **Data Array** of any primitive type with any number of components along a *single component dimension*. For example, a scalar as (1) or a 3-vector as (3), but *not* a matrix as (3, 3). The array is initialized to a user define value or with random values within a specified range.
This **Filter** creates a **Data Array** of any primitive type with any set of component dimensions. The array is initialized to a user define value or with random values within a specified range.

When initializing a multicomponent array square bracket notation can be used to specify different initialization values for each component. For example say that I want to intialize a 2 component array where the first component is 0 and the second component is 1 we would use the following input string for the *Initialization Value*

Expand Down Expand Up @@ -52,8 +52,7 @@ If the parent is **NOT an Attribute Matrix**, then the user ***MUST*** set the t
| Double | 64 bit | -1.7e+308 to -2.2e-308, 0.0, 2.2e-308 to 1.7e+308 (15 digits)|
| Boolean | 8 bit |0 = false and any other value will be forced to 1 = true|

The number of components should be at least 1. Examples of *Number of Components* would be 3 for an RGB Image, 1 for a gray scale image, 1 for a scalar array, 4 for a quaternions array, etc. All values of the array will be initialized to the user set value. The initialization value text box
must have a user entry or the default value *0* will be used.
The component dimensions should multiply together into a total number of components equal to at least 1. Examples of *Component Dimensions* would be [3] for an RGB Image, [1] for a gray scale image, [1] for a scalar array, [4] for a quaternions array, [10x5] for an array with 10x5 grids at each tuple, etc. All values of the array will be initialized using the chosen initialization option.

% Auto generated parameter table will be inserted here

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ Parameters CreateDataArrayFilter::parameters() const

params.insertSeparator(Parameters::Separator{"Input Parameter(s)"});
params.insert(std::make_unique<NumericTypeParameter>(k_NumericType_Key, "Output Numeric Type", "Numeric Type of data to create", NumericType::int32));
// params.insert(std::make_unique<StringParameter>(k_InitializationValue_Key, "Initialization Value", "This value will be used to fill the new array", "0"));
params.insert(std::make_unique<UInt64Parameter>(k_NumComps_Key, "Number of Components", "Number of components", 1));

params.insertSeparator(Parameters::Separator{"Component Handling"});
{
DynamicTableInfo tableInfo;
tableInfo.setRowsInfo(DynamicTableInfo::StaticVectorInfo(1));
tableInfo.setColsInfo(DynamicTableInfo::DynamicVectorInfo(1, "COMP DIM {}"));
params.insert(std::make_unique<DynamicTableParameter>(k_CompDims_Key, "Data Array Component Dimensions (Slowest to Fastest Dimensions)", "Slowest to Fastest Dimensions.", tableInfo));
}

params.insertSeparator(Parameters::Separator{"Initialization Options"});
params.insertLinkableParameter(std::make_unique<ChoicesParameter>(k_InitType_Key, "Initialization Type", "Method for determining the what values of the data in the array should be initialized to",
Expand Down Expand Up @@ -108,12 +114,14 @@ Parameters CreateDataArrayFilter::parameters() const
params.insertLinkableParameter(std::make_unique<BoolParameter>(
k_AdvancedOptions_Key, "Set Tuple Dimensions [not required if creating inside an Attribute Matrix]",
"This allows the user to set the tuple dimensions directly rather than just inheriting them. This option is NOT required if you are creating the Data Array in an Attribute Matrix", true));
DynamicTableInfo tableInfo;
tableInfo.setRowsInfo(DynamicTableInfo::StaticVectorInfo(1));
tableInfo.setColsInfo(DynamicTableInfo::DynamicVectorInfo(1, "DIM {}"));

params.insert(std::make_unique<DynamicTableParameter>(k_TupleDims_Key, "Data Array Dimensions (Slowest to Fastest Dimensions)",
"Slowest to Fastest Dimensions. Note this might be opposite displayed by an image geometry.", tableInfo));
{
DynamicTableInfo tableInfo;
tableInfo.setRowsInfo(DynamicTableInfo::StaticVectorInfo(1));
tableInfo.setColsInfo(DynamicTableInfo::DynamicVectorInfo(1, "TUPLE DIM {}"));
params.insert(std::make_unique<DynamicTableParameter>(k_TupleDims_Key, "Data Array Tuple Dimensions (Slowest to Fastest Dimensions)",
"Slowest to Fastest Dimensions. Note this might be opposite displayed by an image geometry.", tableInfo));
}

// Associate the Linkable Parameter(s) to the children parameters that they control
params.linkParameters(k_AdvancedOptions_Key, k_TupleDims_Key, true);
Expand Down Expand Up @@ -155,26 +163,24 @@ IFilter::PreflightResult CreateDataArrayFilter::preflightImpl(const DataStructur
{
auto useDims = filterArgs.value<bool>(k_AdvancedOptions_Key);
auto numericType = filterArgs.value<NumericType>(k_NumericType_Key);
auto numComponents = filterArgs.value<uint64>(k_NumComps_Key);
auto compDimsData = filterArgs.value<DynamicTableParameter::ValueType>(k_CompDims_Key);
auto dataArrayPath = filterArgs.value<DataPath>(k_DataPath_Key);
auto tableData = filterArgs.value<DynamicTableParameter::ValueType>(k_TupleDims_Key);
auto dataFormat = filterArgs.value<std::string>(k_DataFormat_Key);
// auto initValue = filterArgs.value<std::string>(k_InitializationValue_Key);

nx::core::Result<OutputActions> resultOutputActions;

// if(initValue.empty())
// {
// return MakePreflightErrorResult(k_EmptyParameterError, fmt::format("{}: Init Value cannot be empty.{}({})", humanName(), __FILE__, __LINE__));
// }
// // Sanity check that what the user entered for an init value can be converted safely to the final numeric type
// Result<> result = CheckValueConverts(initValue, numericType);
// if(result.invalid())
// {
// return {ConvertResultTo<OutputActions>(std::move(result), {})};
// }

std::vector<usize> compDims = std::vector<usize>{numComponents};
std::vector<usize> compDims(compDimsData[0].size());
std::transform(compDimsData[0].begin(), compDimsData[0].end(), compDims.begin(), [](double val) { return static_cast<usize>(val); });
usize numComponents = std::accumulate(compDims.begin(), compDims.end(), static_cast<usize>(1), std::multiplies<>());
if(numComponents <= 0)
{
std::string compDimsStr = std::accumulate(compDims.begin() + 1, compDims.end(), std::to_string(compDims[0]), [](const std::string& a, int b) { return a + " x " + std::to_string(b); });
return MakePreflightErrorResult(
-78601,
fmt::format("The chosen component dimensions ({}) results in 0 total components. Please choose component dimensions that result in a positive number of total components.", compDimsStr));
}

std::vector<usize> tupleDims = {};

auto* parentAM = dataStructure.getDataAs<AttributeMatrix>(dataArrayPath.getParent());
Expand Down Expand Up @@ -223,8 +229,6 @@ IFilter::PreflightResult CreateDataArrayFilter::preflightImpl(const DataStructur
// nx::core::Result<OutputActions> resultOutputActions;
std::vector<PreflightValue> preflightUpdatedValues;

// auto& iDataArray = dataStructure.getDataRefAs<IDataArray>(filterArgs.value<DataPath>(k_ArrayPath_Key));

if(arrayDataType == DataType::boolean)
{
std::stringstream updatedValStrm;
Expand Down Expand Up @@ -406,7 +410,6 @@ Result<> CreateDataArrayFilter::executeImpl(DataStructure& dataStructure, const
const std::atomic_bool& shouldCancel) const
{
auto path = filterArgs.value<DataPath>(k_DataPath_Key);
// auto initValue = filterArgs.value<std::string>(k_InitializationValue_Key);

ExecuteNeighborFunction(CreateAndInitArrayFunctor{}, ConvertNumericTypeToDataType(filterArgs.value<NumericType>(k_NumericType_Key)), dataStructure.getDataAs<IDataArray>(path), "0");

Expand Down Expand Up @@ -459,7 +462,6 @@ Result<Arguments> CreateDataArrayFilter::FromSIMPLJson(const nlohmann::json& jso
std::vector<Result<>> results;

results.push_back(SIMPLConversion::ConvertParameter<SIMPLConversion::ScalarTypeParameterToNumericTypeConverter>(args, json, SIMPL::k_ScalarTypeKey, k_NumericType_Key));
results.push_back(SIMPLConversion::ConvertParameter<SIMPLConversion::IntFilterParameterConverter<uint64>>(args, json, SIMPL::k_NumberOfComponentsKey, k_NumComps_Key));
// Initialize Type parameter is not applicable in NX
results.push_back(SIMPLConversion::ConvertParameter<SIMPLConversion::StringFilterParameterConverter>(args, json, SIMPL::k_InitializationValueKey, k_InitValue_Key));
// Initialization Range parameter is not applicable in NX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class SIMPLNXCORE_EXPORT CreateDataArrayFilter : public IFilter
// Parameter Keys
static inline constexpr StringLiteral k_NumericType_Key = "numeric_type_index";
static inline constexpr StringLiteral k_AdvancedOptions_Key = "set_tuple_dimensions";
static inline constexpr StringLiteral k_NumComps_Key = "component_count";
// static inline constexpr StringLiteral k_NumComps_Key = "component_count";
static inline constexpr StringLiteral k_CompDims_Key = "component_dimensions";
static inline constexpr StringLiteral k_TupleDims_Key = "tuple_dimensions";
static inline constexpr StringLiteral k_DataPath_Key = "output_array_path";
static inline constexpr StringLiteral k_DataFormat_Key = "data_format";
Expand Down
14 changes: 7 additions & 7 deletions src/Plugins/SimplnxCore/test/CreateDataArrayTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Instantiate)", "[SimplnxCore][Crea
Arguments args;

args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any<NumericType>(NumericType::int32));
args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any<uint64>(k_NComp));
args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any<DynamicTableParameter::ValueType>(DynamicTableInfo::TableDataType{{static_cast<double>(k_NComp)}}));
args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any<DynamicTableParameter::ValueType>(k_TupleDims));
args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any<DataPath>(k_DataPath));

Expand All @@ -43,7 +43,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor
SECTION("Section1")
{
args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any<NumericType>(NumericType::uint16));
args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any<uint64>(k_NComp));
args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any<DynamicTableParameter::ValueType>(DynamicTableInfo::TableDataType{{static_cast<double>(k_NComp)}}));
args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any<DynamicTableParameter::ValueType>(k_TupleDims));
args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any<DataPath>(k_DataPath));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>("-1"));
Expand All @@ -54,7 +54,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor
SECTION("Section2")
{
args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any<NumericType>(NumericType::int8));
args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any<uint64>(k_NComp));
args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any<DynamicTableParameter::ValueType>(DynamicTableInfo::TableDataType{{static_cast<double>(k_NComp)}}));
args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any<DynamicTableParameter::ValueType>(k_TupleDims));
args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any<DataPath>(k_DataPath));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>("1024"));
Expand All @@ -65,7 +65,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor
SECTION("Section3")
{
args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any<NumericType>(NumericType::float32));
args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any<uint64>(0));
args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any<DynamicTableParameter::ValueType>(DynamicTableInfo::TableDataType{{0.0}}));
args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any<DynamicTableParameter::ValueType>(k_TupleDims));
args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any<DataPath>(k_DataPath));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>("1"));
Expand All @@ -76,7 +76,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor
SECTION("Section4")
{
args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any<NumericType>(NumericType::float32));
args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any<uint64>(1));
args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any<DynamicTableParameter::ValueType>(DynamicTableInfo::TableDataType{{1.0}}));

DynamicTableInfo::TableDataType tupleDims = {{static_cast<double>(0.0)}};
args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any<DynamicTableParameter::ValueType>(tupleDims));
Expand All @@ -89,7 +89,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor
SECTION("Section5")
{
args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any<NumericType>(NumericType::int8));
args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any<uint64>(1));
args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any<DynamicTableParameter::ValueType>(DynamicTableInfo::TableDataType{{1.0}}));
DynamicTableInfo::TableDataType tupleDims = {{static_cast<double>(1.0)}};
args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any<DynamicTableParameter::ValueType>(tupleDims));
args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any<DataPath>(k_DataPath));
Expand All @@ -101,7 +101,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor
SECTION("Section6")
{
args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any<NumericType>(NumericType::int8));
args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any<uint64>(1));
args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any<DynamicTableParameter::ValueType>(DynamicTableInfo::TableDataType{{1.0}}));
DynamicTableInfo::TableDataType tupleDims = {{static_cast<double>(1.0)}};
args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any<DynamicTableParameter::ValueType>(tupleDims));
args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any<DataPath>(k_DataPath));
Expand Down

0 comments on commit b5cab71

Please sign in to comment.