Skip to content

Commit fb42f3f

Browse files
Updated for large data
* Converted std::vector data to AbstractDataStore<T> using DataStoreUtilities.
1 parent e1e8b99 commit fb42f3f

1 file changed

Lines changed: 29 additions & 22 deletions

File tree

src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/MultiThresholdObjects.cpp

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "simplnx/Common/TypeTraits.hpp"
44
#include "simplnx/DataStructure/DataArray.hpp"
55
#include "simplnx/Utilities/ArrayThreshold.hpp"
6+
#include "simplnx/Utilities/DataStoreUtilities.hpp"
67
#include "simplnx/Utilities/FilterUtilities.hpp"
78

89
#include <algorithm>
@@ -20,9 +21,9 @@ namespace
2021
* @param inverse
2122
*/
2223
template <typename T>
23-
void InsertThreshold(std::vector<T>& currentVector, nx::core::IArrayThreshold::UnionOperator unionOperator, std::vector<T>& newVector, bool inverse, T trueValue, T falseValue)
24+
void InsertThreshold(AbstractDataStore<T>& currentVector, nx::core::IArrayThreshold::UnionOperator unionOperator, AbstractDataStore<T>& newVector, bool inverse, T trueValue, T falseValue)
2425
{
25-
usize numItems = currentVector.size();
26+
usize numItems = currentVector.getNumberOfTuples();
2627

2728
for(usize i = 0; i < numItems; i++)
2829
{
@@ -46,14 +47,14 @@ void InsertThreshold(std::vector<T>& currentVector, nx::core::IArrayThreshold::U
4647
/**
4748
* @brief Consolidate all assignment calls to a single method to prevent unintended diverging behavior.
4849
* @param arrayThreshold Current threshold to pull settings from.
49-
* @param outputResultVector Output vector for the current ThresholdSet.
50-
* @param inputThresholdVector Resulting output for the target array threshold.
50+
* @param outputResultStore Output DataStore for the current ThresholdSet.
51+
* @param inputThresholdStore Resulting output for the target array threshold.
5152
* @param replaceInput The first threshould in every set has its output applied to the output regardless of union operator.
5253
* @param trueValue Output mask value when the threshold is satisfied.
5354
* @param falseValue Output mask value when the threshold is not satisfied.
5455
*/
5556
template <typename T>
56-
void ApplyThresholdValues(const IArrayThreshold& arrayThreshold, std::vector<T>& outputResultVector, std::vector<T>& inputThresholdVector, bool replaceInput, T trueValue, T falseValue)
57+
void ApplyThresholdValues(const IArrayThreshold& arrayThreshold, AbstractDataStore<T>& outputResultStore, AbstractDataStore<T>& inputThresholdStore, bool replaceInput, T trueValue, T falseValue)
5758
{
5859
auto unionOperator = arrayThreshold.getUnionOperator();
5960
bool inverse = arrayThreshold.isInverted();
@@ -64,14 +65,14 @@ void ApplyThresholdValues(const IArrayThreshold& arrayThreshold, std::vector<T>&
6465
}
6566

6667
// insert into current threshold
67-
InsertThreshold<T>(outputResultVector, unionOperator, inputThresholdVector, inverse, trueValue, falseValue);
68+
InsertThreshold<T>(outputResultStore, unionOperator, inputThresholdStore, inverse, trueValue, falseValue);
6869
}
6970

7071
template <class U>
7172
class ThresholdFilterHelper
7273
{
7374
public:
74-
ThresholdFilterHelper(ArrayThreshold::ComparisonType compType, ArrayThreshold::ComparisonValue compValue, usize componentIndex, std::vector<U>& output)
75+
ThresholdFilterHelper(ArrayThreshold::ComparisonType compType, ArrayThreshold::ComparisonValue compValue, usize componentIndex, AbstractDataStore<U>& output)
7576
: m_ComparisonOperator(compType)
7677
, m_ComparisonValue(compValue)
7778
, m_ComponentIndex(componentIndex)
@@ -123,7 +124,7 @@ class ThresholdFilterHelper
123124
ArrayThreshold::ComparisonType m_ComparisonOperator;
124125
ArrayThreshold::ComparisonValue m_ComparisonValue;
125126
usize m_ComponentIndex = 0;
126-
std::vector<U>& m_Output;
127+
AbstractDataStore<U>& m_Output;
127128
};
128129

129130
struct ExecuteThresholdHelper
@@ -137,11 +138,13 @@ struct ExecuteThresholdHelper
137138
};
138139

139140
template <typename T>
140-
void ThresholdValue(const ArrayThreshold& comparisonValue, const DataStructure& dataStructure, std::vector<T>& outputResultVector, int32_t& err, bool replaceInput, T trueValue, T falseValue)
141+
void ThresholdValue(const ArrayThreshold& comparisonValue, const DataStructure& dataStructure, AbstractDataStore<T>& outputResultVector, int32_t& err, bool replaceInput, T trueValue, T falseValue)
141142
{
142143
// Get the total number of tuples, create and initialize an array with FALSE to use for these results
143-
size_t totalTuples = outputResultVector.size();
144-
std::vector<T> tempResultVector(totalTuples, falseValue);
144+
size_t totalTuples = outputResultVector.getNumberOfTuples();
145+
auto tempResultStorePtr = DataStoreUtilities::CreateDataStore<T>({totalTuples}, {1}, IDataAction::Mode::Execute);
146+
AbstractDataStore<T>& tempResultStore = *tempResultStorePtr.get();
147+
std::fill(tempResultStore.begin(), tempResultStore.end(), falseValue);
145148

146149
nx::core::ArrayThreshold::ComparisonType compOperator = comparisonValue.getComparisonType();
147150
nx::core::ArrayThreshold::ComparisonValue compValue = comparisonValue.getComparisonValue();
@@ -151,21 +154,23 @@ void ThresholdValue(const ArrayThreshold& comparisonValue, const DataStructure&
151154

152155
usize componentIndex = comparisonValue.getComponentIndex();
153156

154-
ThresholdFilterHelper<T> helper(compOperator, compValue, componentIndex, tempResultVector);
157+
ThresholdFilterHelper<T> helper(compOperator, compValue, componentIndex, tempResultStore);
155158

156159
const auto& iDataArray = dataStructure.getDataRefAs<IDataArray>(inputDataArrayPath);
157160

158161
ExecuteDataFunction(ExecuteThresholdHelper{}, iDataArray.getDataType(), helper, iDataArray, trueValue, falseValue);
159162

160-
ApplyThresholdValues<T>(comparisonValue, outputResultVector, tempResultVector, replaceInput, trueValue, falseValue);
163+
ApplyThresholdValues<T>(comparisonValue, outputResultVector, tempResultStore, replaceInput, trueValue, falseValue);
161164
}
162165

163166
template <typename T>
164-
void ThresholdSet(const ArrayThresholdSet& inputComparisonSet, const DataStructure& dataStructure, std::vector<T>& outputResultVector, int32_t& err, bool replaceInput, T trueValue, T falseValue)
167+
void ThresholdSet(const ArrayThresholdSet& inputComparisonSet, const DataStructure& dataStructure, AbstractDataStore<T>& outputResultVector, int32_t& err, bool replaceInput, T trueValue, T falseValue)
165168
{
166169
// Get the total number of tuples, create and initialize an array with FALSE to use for these results
167-
size_t totalTuples = outputResultVector.size();
168-
std::vector<T> tempResultVector(totalTuples, falseValue);
170+
size_t totalTuples = outputResultVector.getNumberOfTuples();
171+
auto tempResultStorePtr = DataStoreUtilities::CreateDataStore<T>({totalTuples}, {1}, IDataAction::Mode::Execute);
172+
AbstractDataStore<T>& tempResultStore = *tempResultStorePtr.get();
173+
std::fill(tempResultStore.begin(), tempResultStore.end(), falseValue);
169174

170175
bool firstValueFound = false;
171176

@@ -175,18 +180,18 @@ void ThresholdSet(const ArrayThresholdSet& inputComparisonSet, const DataStructu
175180
const IArrayThreshold* thresholdPtr = threshold.get();
176181
if(const auto* comparisonSet = dynamic_cast<const ArrayThresholdSet*>(thresholdPtr); comparisonSet != nullptr)
177182
{
178-
ThresholdSet<T>(*comparisonSet, dataStructure, tempResultVector, err, !firstValueFound, trueValue, falseValue);
183+
ThresholdSet<T>(*comparisonSet, dataStructure, tempResultStore, err, !firstValueFound, trueValue, falseValue);
179184
firstValueFound = true;
180185
}
181186
else if(const auto* comparisonValue = dynamic_cast<const ArrayThreshold*>(thresholdPtr); comparisonValue != nullptr)
182187
{
183-
ThresholdValue<T>(*comparisonValue, dataStructure, tempResultVector, err, !firstValueFound, trueValue, falseValue);
188+
ThresholdValue<T>(*comparisonValue, dataStructure, tempResultStore, err, !firstValueFound, trueValue, falseValue);
184189
firstValueFound = true;
185190
}
186191
}
187192

188193
// Apply resulting values to output
189-
ApplyThresholdValues<T>(inputComparisonSet, outputResultVector, tempResultVector, replaceInput, trueValue, falseValue);
194+
ApplyThresholdValues<T>(inputComparisonSet, outputResultVector, tempResultStore, replaceInput, trueValue, falseValue);
190195
}
191196

192197
struct ThresholdSetFunctor
@@ -198,12 +203,14 @@ struct ThresholdSetFunctor
198203
// was essentially done in the preflight part.
199204
auto& outputDataStore = outputResultArray.template getIDataStoreRefAs<AbstractDataStore<T>>();
200205
usize totalTuples = outputDataStore.getNumberOfTuples();
201-
std::vector<T> tmpVector(totalTuples, falseValue);
202-
ThresholdSet<T>(inputComparisonSet, dataStructure, tmpVector, err, replaceInput, trueValue, falseValue);
206+
auto tempResultStorePtr = DataStoreUtilities::CreateDataStore<T>({totalTuples}, {1}, IDataAction::Mode::Execute);
207+
AbstractDataStore<T>& tempResultStore = *tempResultStorePtr.get();
208+
std::fill(tempResultStore.begin(), tempResultStore.end(), falseValue);
209+
ThresholdSet<T>(inputComparisonSet, dataStructure, tempResultStore, err, replaceInput, trueValue, falseValue);
203210

204211
for(size_t i = 0; i < totalTuples; i++)
205212
{
206-
outputDataStore[i] = tmpVector[i];
213+
outputDataStore[i] = tempResultStore[i];
207214
}
208215
}
209216
};

0 commit comments

Comments
 (0)