Skip to content

Commit c3f7db9

Browse files
committed
BUG FIX: Compute Euclidean Dist Map now does not create extra arrays.
Signed-off-by: Joey Kleingers <joey.kleingers@bluequartz.net>
1 parent ea4fafb commit c3f7db9

2 files changed

Lines changed: 46 additions & 15 deletions

File tree

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ComputeDistanceMapImpl
3333
void operator()() const
3434
{
3535
using DataArrayType = DataArray<T>;
36+
using DataStoreType = AbstractDataStore<T>;
3637

3738
const auto& selectedImageGeom = m_DataStructure.getDataRefAs<ImageGeom>(m_InputValues.InputImageGeometry);
3839

@@ -65,9 +66,21 @@ class ComputeDistanceMapImpl
6566

6667
const auto& featureIdsStore = m_DataStructure.getDataAs<Int32Array>(m_InputValues.FeatureIdsArrayPath)->getDataStoreRef();
6768

68-
auto* gbManhattanDistancesStore = m_DataStructure.template getDataAs<DataArrayType>(m_InputValues.GBDistancesArrayName)->getDataStore();
69-
auto* tjManhattanDistancesStore = m_DataStructure.template getDataAs<DataArrayType>(m_InputValues.TJDistancesArrayName)->getDataStore();
70-
auto* qpManhattanDistancesStore = m_DataStructure.template getDataAs<DataArrayType>(m_InputValues.QPDistancesArrayName)->getDataStore();
69+
DataStoreType* gbManhattanDistancesStore = nullptr;
70+
if(m_InputValues.DoBoundaries)
71+
{
72+
gbManhattanDistancesStore = m_DataStructure.template getDataAs<DataArrayType>(m_InputValues.GBDistancesArrayName)->getDataStore();
73+
}
74+
DataStoreType* tjManhattanDistancesStore = nullptr;
75+
if(m_InputValues.DoTripleLines)
76+
{
77+
tjManhattanDistancesStore = m_DataStructure.template getDataAs<DataArrayType>(m_InputValues.TJDistancesArrayName)->getDataStore();
78+
}
79+
DataStoreType* qpManhattanDistancesStore = nullptr;
80+
if(m_InputValues.DoQuadPoints)
81+
{
82+
qpManhattanDistancesStore = m_DataStructure.template getDataAs<DataArrayType>(m_InputValues.QPDistancesArrayName)->getDataStore();
83+
}
7184

7285
auto* nearestNeighborsStore = m_DataStructure.getDataAs<Int32Array>(m_InputValues.NearestNeighborsArrayName)->getDataStore();
7386

@@ -82,15 +95,15 @@ class ComputeDistanceMapImpl
8295
{
8396
voxel_NearestNeighbor[a] = -1;
8497
}
85-
if(m_MapType == ComputeEuclideanDistMap::MapType::FeatureBoundary)
98+
if(m_InputValues.DoBoundaries && m_MapType == ComputeEuclideanDistMap::MapType::FeatureBoundary)
8699
{
87100
voxel_Distance[a] = static_cast<double>((*gbManhattanDistancesStore)[a]);
88101
}
89-
else if(m_MapType == ComputeEuclideanDistMap::MapType::TripleJunction)
102+
else if(m_InputValues.DoTripleLines && m_MapType == ComputeEuclideanDistMap::MapType::TripleJunction)
90103
{
91104
voxel_Distance[a] = static_cast<double>((*tjManhattanDistancesStore)[a]);
92105
}
93-
else if(m_MapType == ComputeEuclideanDistMap::MapType::QuadPoint)
106+
else if(m_InputValues.DoQuadPoints && m_MapType == ComputeEuclideanDistMap::MapType::QuadPoint)
94107
{
95108
voxel_Distance[a] = static_cast<double>((*qpManhattanDistancesStore)[a]);
96109
}
@@ -212,15 +225,15 @@ class ComputeDistanceMapImpl
212225
for(size_t a = 0; a < totalPoints; ++a)
213226
{
214227
(*nearestNeighborsStore)[a * 3 + static_cast<uint32_t>(m_MapType)] = voxel_NearestNeighbor[a];
215-
if(m_MapType == ComputeEuclideanDistMap::MapType::FeatureBoundary)
228+
if(m_InputValues.DoBoundaries && m_MapType == ComputeEuclideanDistMap::MapType::FeatureBoundary)
216229
{
217230
(*gbManhattanDistancesStore)[a] = static_cast<T>(voxel_Distance[a]);
218231
}
219-
else if(m_MapType == ComputeEuclideanDistMap::MapType::TripleJunction)
232+
else if(m_InputValues.DoTripleLines && m_MapType == ComputeEuclideanDistMap::MapType::TripleJunction)
220233
{
221234
(*tjManhattanDistancesStore)[a] = static_cast<T>(voxel_Distance[a]);
222235
}
223-
else if(m_MapType == ComputeEuclideanDistMap::MapType::QuadPoint)
236+
else if(m_InputValues.DoQuadPoints && m_MapType == ComputeEuclideanDistMap::MapType::QuadPoint)
224237
{
225238
(*qpManhattanDistancesStore)[a] = static_cast<T>(voxel_Distance[a]);
226239
}
@@ -247,25 +260,29 @@ template <typename T>
247260
void findDistanceMap(DataStructure& dataStructure, const ComputeEuclideanDistMapInputValues* inputValues)
248261
{
249262
using DataArrayType = DataArray<T>;
263+
using DataStoreType = AbstractDataStore<T>;
250264

251265
const auto& featureIdsStore = dataStructure.getDataRefAs<Int32Array>(inputValues->FeatureIdsArrayPath).getDataStoreRef();
252266
size_t totalPoints = featureIdsStore.getNumberOfTuples();
253267

254-
auto* gbManhattanDistancesStore = dataStructure.template getDataAs<DataArrayType>(inputValues->GBDistancesArrayName)->getDataStore();
255-
if(gbManhattanDistancesStore != nullptr)
268+
DataStoreType* gbManhattanDistancesStore = nullptr;
269+
if(inputValues->DoBoundaries)
256270
{
271+
gbManhattanDistancesStore = dataStructure.template getDataAs<DataArrayType>(inputValues->GBDistancesArrayName)->getDataStore();
257272
gbManhattanDistancesStore->fill(static_cast<T>(-1));
258273
}
259274

260-
auto* tjManhattanDistancesStore = dataStructure.template getDataAs<DataArrayType>(inputValues->TJDistancesArrayName)->getDataStore();
261-
if(tjManhattanDistancesStore != nullptr)
275+
DataStoreType* tjManhattanDistancesStore = nullptr;
276+
if(inputValues->DoTripleLines)
262277
{
278+
tjManhattanDistancesStore = dataStructure.template getDataAs<DataArrayType>(inputValues->TJDistancesArrayName)->getDataStore();
263279
tjManhattanDistancesStore->fill(static_cast<T>(-1));
264280
}
265281

266-
auto* qpManhattanDistancesStore = dataStructure.template getDataAs<DataArrayType>(inputValues->QPDistancesArrayName)->getDataStore();
267-
if(qpManhattanDistancesStore != nullptr)
282+
DataStoreType* qpManhattanDistancesStore = nullptr;
283+
if(inputValues->DoQuadPoints)
268284
{
285+
qpManhattanDistancesStore = dataStructure.template getDataAs<DataArrayType>(inputValues->QPDistancesArrayName)->getDataStore();
269286
qpManhattanDistancesStore->fill(static_cast<T>(-1));
270287
}
271288

src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ComputeEuclideanDistMapFilter.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ IFilter::PreflightResult ComputeEuclideanDistMapFilter::preflightImpl(const Data
110110
{
111111
auto pCalcManhattanDistValue = filterArgs.value<bool>(k_CalcManhattanDist_Key);
112112
auto pSaveNearestNeighborsValue = filterArgs.value<bool>(k_SaveNearestNeighbors_Key);
113+
auto pCalculateDistToBoundaries = filterArgs.value<bool>(k_DoBoundaries_Key);
114+
auto pCalculateDistToTripleLines = filterArgs.value<bool>(k_DoTripleLines_Key);
115+
auto pCalculateDistToQuadPoints = filterArgs.value<bool>(k_DoQuadPoints_Key);
113116

114117
auto pFeatureIdsArrayPathValue = filterArgs.value<DataPath>(k_CellFeatureIdsArrayPath_Key);
115118
DataPath parentGroup = pFeatureIdsArrayPathValue.getParent();
@@ -139,19 +142,30 @@ IFilter::PreflightResult ComputeEuclideanDistMapFilter::preflightImpl(const Data
139142
outputDataType = DataType::float32;
140143
}
141144

145+
if(!pSaveNearestNeighborsValue && !pCalculateDistToBoundaries && !pCalculateDistToTripleLines && !pCalculateDistToQuadPoints)
146+
{
147+
return {MakeErrorResult<OutputActions>(
148+
-12802, fmt::format("There is no output. One of the following options must be selected: Calculate Distance To Boundaries, Calculate Distance to Triple Lines, Calculate "
149+
"Distance to Quadruple Points, or Store the Nearest Boundary Cells.",
150+
pFeatureIdsArrayPathValue.toString()))};
151+
}
152+
142153
// Create the GBDistancesArray
154+
if(pCalculateDistToBoundaries)
143155
{
144156
auto arrayPath = parentGroup.createChildPath(filterArgs.value<std::string>(k_GBDistancesArrayName_Key));
145157
auto action = std::make_unique<CreateArrayAction>(outputDataType, tupleShape, std::vector<usize>{1ULL}, arrayPath);
146158
resultOutputActions.value().appendAction(std::move(action));
147159
}
148160
// Create the TJDistancesArray
161+
if(pCalculateDistToTripleLines)
149162
{
150163
auto arrayPath = parentGroup.createChildPath(filterArgs.value<std::string>(k_TJDistancesArrayName_Key));
151164
auto action = std::make_unique<CreateArrayAction>(outputDataType, tupleShape, std::vector<usize>{1ULL}, arrayPath);
152165
resultOutputActions.value().appendAction(std::move(action));
153166
}
154167
// Create the QPDistancesArray
168+
if(pCalculateDistToQuadPoints)
155169
{
156170
auto arrayPath = parentGroup.createChildPath(filterArgs.value<std::string>(k_QPDistancesArrayName_Key));
157171
auto action = std::make_unique<CreateArrayAction>(outputDataType, tupleShape, std::vector<usize>{1ULL}, arrayPath);

0 commit comments

Comments
 (0)