From b5cab717282e20bf081adf9f4f32ee8333c311c6 Mon Sep 17 00:00:00 2001 From: Joey Kleingers Date: Fri, 6 Sep 2024 15:43:41 -0400 Subject: [PATCH] Update CreateDataArray to require comp dims instead of number of comps. Signed-off-by: Joey Kleingers --- .../SimplnxCore/docs/CreateDataArrayFilter.md | 5 +- .../Filters/CreateDataArrayFilter.cpp | 52 ++++++++++--------- .../Filters/CreateDataArrayFilter.hpp | 3 +- .../SimplnxCore/test/CreateDataArrayTest.cpp | 14 ++--- 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/src/Plugins/SimplnxCore/docs/CreateDataArrayFilter.md b/src/Plugins/SimplnxCore/docs/CreateDataArrayFilter.md index 9d4ee58da9..ba5b092cfa 100644 --- a/src/Plugins/SimplnxCore/docs/CreateDataArrayFilter.md +++ b/src/Plugins/SimplnxCore/docs/CreateDataArrayFilter.md @@ -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* @@ -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 diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CreateDataArrayFilter.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CreateDataArrayFilter.cpp index 3144c8e93d..af61b3ceba 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CreateDataArrayFilter.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CreateDataArrayFilter.cpp @@ -73,8 +73,14 @@ Parameters CreateDataArrayFilter::parameters() const params.insertSeparator(Parameters::Separator{"Input Parameter(s)"}); params.insert(std::make_unique(k_NumericType_Key, "Output Numeric Type", "Numeric Type of data to create", NumericType::int32)); - // params.insert(std::make_unique(k_InitializationValue_Key, "Initialization Value", "This value will be used to fill the new array", "0")); - params.insert(std::make_unique(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(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(k_InitType_Key, "Initialization Type", "Method for determining the what values of the data in the array should be initialized to", @@ -108,12 +114,14 @@ Parameters CreateDataArrayFilter::parameters() const params.insertLinkableParameter(std::make_unique( 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(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(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); @@ -155,26 +163,24 @@ IFilter::PreflightResult CreateDataArrayFilter::preflightImpl(const DataStructur { auto useDims = filterArgs.value(k_AdvancedOptions_Key); auto numericType = filterArgs.value(k_NumericType_Key); - auto numComponents = filterArgs.value(k_NumComps_Key); + auto compDimsData = filterArgs.value(k_CompDims_Key); auto dataArrayPath = filterArgs.value(k_DataPath_Key); auto tableData = filterArgs.value(k_TupleDims_Key); auto dataFormat = filterArgs.value(k_DataFormat_Key); - // auto initValue = filterArgs.value(k_InitializationValue_Key); nx::core::Result 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(std::move(result), {})}; - // } - - std::vector compDims = std::vector{numComponents}; + std::vector compDims(compDimsData[0].size()); + std::transform(compDimsData[0].begin(), compDimsData[0].end(), compDims.begin(), [](double val) { return static_cast(val); }); + usize numComponents = std::accumulate(compDims.begin(), compDims.end(), static_cast(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 tupleDims = {}; auto* parentAM = dataStructure.getDataAs(dataArrayPath.getParent()); @@ -223,8 +229,6 @@ IFilter::PreflightResult CreateDataArrayFilter::preflightImpl(const DataStructur // nx::core::Result resultOutputActions; std::vector preflightUpdatedValues; - // auto& iDataArray = dataStructure.getDataRefAs(filterArgs.value(k_ArrayPath_Key)); - if(arrayDataType == DataType::boolean) { std::stringstream updatedValStrm; @@ -406,7 +410,6 @@ Result<> CreateDataArrayFilter::executeImpl(DataStructure& dataStructure, const const std::atomic_bool& shouldCancel) const { auto path = filterArgs.value(k_DataPath_Key); - // auto initValue = filterArgs.value(k_InitializationValue_Key); ExecuteNeighborFunction(CreateAndInitArrayFunctor{}, ConvertNumericTypeToDataType(filterArgs.value(k_NumericType_Key)), dataStructure.getDataAs(path), "0"); @@ -459,7 +462,6 @@ Result CreateDataArrayFilter::FromSIMPLJson(const nlohmann::json& jso std::vector> results; results.push_back(SIMPLConversion::ConvertParameter(args, json, SIMPL::k_ScalarTypeKey, k_NumericType_Key)); - results.push_back(SIMPLConversion::ConvertParameter>(args, json, SIMPL::k_NumberOfComponentsKey, k_NumComps_Key)); // Initialize Type parameter is not applicable in NX results.push_back(SIMPLConversion::ConvertParameter(args, json, SIMPL::k_InitializationValueKey, k_InitValue_Key)); // Initialization Range parameter is not applicable in NX diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CreateDataArrayFilter.hpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CreateDataArrayFilter.hpp index 997c7e3c6a..8ebcccdf62 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CreateDataArrayFilter.hpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/CreateDataArrayFilter.hpp @@ -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"; diff --git a/src/Plugins/SimplnxCore/test/CreateDataArrayTest.cpp b/src/Plugins/SimplnxCore/test/CreateDataArrayTest.cpp index 700a88befc..bd6cfa76ee 100644 --- a/src/Plugins/SimplnxCore/test/CreateDataArrayTest.cpp +++ b/src/Plugins/SimplnxCore/test/CreateDataArrayTest.cpp @@ -21,7 +21,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Instantiate)", "[SimplnxCore][Crea Arguments args; args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any(NumericType::int32)); - args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any(k_NComp)); + args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any(DynamicTableInfo::TableDataType{{static_cast(k_NComp)}})); args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any(k_TupleDims)); args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any(k_DataPath)); @@ -43,7 +43,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor SECTION("Section1") { args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any(NumericType::uint16)); - args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any(k_NComp)); + args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any(DynamicTableInfo::TableDataType{{static_cast(k_NComp)}})); args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any(k_TupleDims)); args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any(k_DataPath)); args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any("-1")); @@ -54,7 +54,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor SECTION("Section2") { args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any(NumericType::int8)); - args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any(k_NComp)); + args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any(DynamicTableInfo::TableDataType{{static_cast(k_NComp)}})); args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any(k_TupleDims)); args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any(k_DataPath)); args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any("1024")); @@ -65,7 +65,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor SECTION("Section3") { args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any(NumericType::float32)); - args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any(0)); + args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any(DynamicTableInfo::TableDataType{{0.0}})); args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any(k_TupleDims)); args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any(k_DataPath)); args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any("1")); @@ -76,7 +76,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor SECTION("Section4") { args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any(NumericType::float32)); - args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any(1)); + args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any(DynamicTableInfo::TableDataType{{1.0}})); DynamicTableInfo::TableDataType tupleDims = {{static_cast(0.0)}}; args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any(tupleDims)); @@ -89,7 +89,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor SECTION("Section5") { args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any(NumericType::int8)); - args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any(1)); + args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any(DynamicTableInfo::TableDataType{{1.0}})); DynamicTableInfo::TableDataType tupleDims = {{static_cast(1.0)}}; args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any(tupleDims)); args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any(k_DataPath)); @@ -101,7 +101,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor SECTION("Section6") { args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any(NumericType::int8)); - args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any(1)); + args.insert(CreateDataArrayFilter::k_CompDims_Key, std::make_any(DynamicTableInfo::TableDataType{{1.0}})); DynamicTableInfo::TableDataType tupleDims = {{static_cast(1.0)}}; args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any(tupleDims)); args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any(k_DataPath));