Skip to content

Commit 5d22556

Browse files
authored
ENH: Isolate Largest Feature now checks for cancel button and sends progress (#1473)
1 parent 413e6fa commit 5d22556

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/Plugins/SimplnxCore/src/SimplnxCore/Filters/IdentifySampleFilter.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace
1717
struct IdentifySampleFunctor
1818
{
1919
template <typename T>
20-
void operator()(const ImageGeom* imageGeom, IDataArray* goodVoxelsPtr, bool fillHoles)
20+
void operator()(const ImageGeom* imageGeom, IDataArray* goodVoxelsPtr, bool fillHoles, const IFilter::MessageHandler& messageHandler, const std::atomic_bool& shouldCancel)
2121
{
2222
ShapeType cDims = {1};
2323
auto& goodVoxels = goodVoxelsPtr->template getIDataStoreRefAs<AbstractDataStore<T>>();
@@ -55,9 +55,14 @@ struct IdentifySampleFunctor
5555
float threshold = 0.0f;
5656
for(int64 i = 0; i < totalPoints; i++)
5757
{
58+
if(shouldCancel)
59+
{
60+
return;
61+
}
5862
const float percentIncrement = static_cast<float>(i) / static_cast<float>(totalPoints) * 100.0f;
5963
if(percentIncrement > threshold)
6064
{
65+
messageHandler(IFilter::Message::Type::Info, fmt::format("Completed: {}", percentIncrement));
6166
threshold = threshold + 5.0f;
6267
if(threshold < percentIncrement)
6368
{
@@ -138,9 +143,15 @@ struct IdentifySampleFunctor
138143
threshold = 0.0F;
139144
if(fillHoles)
140145
{
146+
messageHandler(IFilter::Message::Type::Info, fmt::format("Filling holes in sample..."));
147+
141148
bool touchesBoundary = false;
142149
for(int64 i = 0; i < totalPoints; i++)
143150
{
151+
if(shouldCancel)
152+
{
153+
return;
154+
}
144155
const float percentIncrement = static_cast<float>(i) / static_cast<float>(totalPoints) * 100.0f;
145156
if(percentIncrement > threshold)
146157
{
@@ -227,7 +238,7 @@ struct IdentifySampleSliceBySliceFunctor
227238
};
228239

229240
template <typename T>
230-
void operator()(const ImageGeom* imageGeom, IDataArray* goodVoxelsPtr, bool fillHoles, Plane plane)
241+
void operator()(const ImageGeom* imageGeom, IDataArray* goodVoxelsPtr, bool fillHoles, Plane plane, const IFilter::MessageHandler& messageHandler, const std::atomic_bool& shouldCancel)
231242
{
232243
auto& goodVoxels = goodVoxelsPtr->template getIDataStoreRefAs<AbstractDataStore<T>>();
233244

@@ -271,6 +282,12 @@ struct IdentifySampleSliceBySliceFunctor
271282

272283
for(int64 fixedIdx = 0; fixedIdx < fixedDim; ++fixedIdx) // Process each slice
273284
{
285+
if(shouldCancel)
286+
{
287+
return;
288+
}
289+
messageHandler(IFilter::Message::Type::Info, fmt::format("Slice {}", fixedIdx));
290+
274291
std::vector<bool> checked(planeDim1 * planeDim2, false);
275292
std::vector<bool> sample(planeDim1 * planeDim2, false);
276293
std::vector<int64> currentVList;
@@ -331,6 +348,10 @@ struct IdentifySampleSliceBySliceFunctor
331348
}
332349
}
333350
}
351+
if(shouldCancel)
352+
{
353+
return;
354+
}
334355

335356
for(int64 p2 = 0; p2 < planeDim2; ++p2)
336357
{
@@ -345,7 +366,10 @@ struct IdentifySampleSliceBySliceFunctor
345366
}
346367
}
347368
}
348-
369+
if(shouldCancel)
370+
{
371+
return;
372+
}
349373
if(fillHoles)
350374
{
351375
for(int64 p2 = 0; p2 < planeDim2; ++p2)
@@ -518,11 +542,11 @@ Result<> IdentifySampleFilter::executeImpl(DataStructure& dataStructure, const A
518542

519543
if(sliceBySlice)
520544
{
521-
ExecuteDataFunction(IdentifySampleSliceBySliceFunctor{}, inputData->getDataType(), imageGeom, inputData, fillHoles, sliceBySlicePlane);
545+
ExecuteDataFunction(IdentifySampleSliceBySliceFunctor{}, inputData->getDataType(), imageGeom, inputData, fillHoles, sliceBySlicePlane, messageHandler, shouldCancel);
522546
}
523547
else
524548
{
525-
ExecuteDataFunction(IdentifySampleFunctor{}, inputData->getDataType(), imageGeom, inputData, fillHoles);
549+
ExecuteDataFunction(IdentifySampleFunctor{}, inputData->getDataType(), imageGeom, inputData, fillHoles, messageHandler, shouldCancel);
526550
}
527551

528552
return {};

0 commit comments

Comments
 (0)