Skip to content

Commit

Permalink
fix: don't hang when trying to Fill3D on non-visible source
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhulbert committed Oct 11, 2024
1 parent b804625 commit 95f13c2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,24 @@ public void intersectAt(final double x, final double y) {
final Source<?> currentSource = sourceInfo.currentSourceProperty().get();
final ViewerState viewerState = viewer.getState();
if (currentSource == null) {
LOG.info("No current source selected -- will not fill");
LOG.info("No current source selected -- will not intersect");
return;
}

final SourceState<?, ?> currentSourceState = sourceInfo.getState(currentSource);

if (!currentSourceState.isVisibleProperty().get()) {
LOG.info("Selected source is not visible -- will not fill");
LOG.info("Selected source is not visible -- will not intersect");
return;
}

if (!(currentSource instanceof MaskedSource<?, ?>)) {
LOG.info("Selected source is not painting-enabled -- will not fill");
LOG.info("Selected source is not painting-enabled -- will not intersect");
return;
}

if (maskForLabel == null) {
LOG.info("Cannot generate boolean mask for this source -- will not fill");
LOG.info("Cannot generate boolean mask for this source -- will not intersect");
return;
}

Expand All @@ -119,7 +119,7 @@ public void intersectAt(final double x, final double y) {
final Type<?> t = source.getDataType();

if (!(t instanceof IntegerType<?>)) {
LOG.info("Data type is not integer type or LabelMultisetType -- will not fill");
LOG.info("Data type is not integer type or LabelMultisetType -- will not intersect");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import java.util.concurrent.CancellationException
import java.util.concurrent.atomic.AtomicBoolean
import java.util.function.*
import java.util.stream.Collectors
import kotlin.coroutines.coroutineContext

class FloodFill<T : IntegerType<T>>(
private val activeViewerProperty: ObservableValue<ViewerPanelFX>,
Expand All @@ -39,20 +38,26 @@ class FloodFill<T : IntegerType<T>>(
private val isVisible: BooleanSupplier
) {

fun fillAt(x: Double, y: Double, fillSupplier: (() -> Long?)?): Job? {
fun fillAt(x: Double, y: Double, fillSupplier: (() -> Long?)?): Job {
val fill = fillSupplier?.invoke() ?: let {
LOG.info { "Received invalid label -- will not fill." }
return null
return Job().apply {
val reason = CancellationException("Received invalid label -- will not fill.")
LOG.debug(reason) { }
completeExceptionally(reason)
}
}
return fillAt(x, y, fill)
}

private fun fillAt(x: Double, y: Double, fill: Long): Job? {
private fun fillAt(x: Double, y: Double, fill: Long): Job {
// TODO should this check happen outside?

if (!isVisible.asBoolean) {
LOG.info { "Selected source is not visible -- will not fill" }
return null
return Job().apply {
val reason = CancellationException("Selected source is not visible -- will not fill")
LOG.debug(reason) { }
completeExceptionally(reason)
}
}

val level = 0
Expand All @@ -67,12 +72,12 @@ class FloodFill<T : IntegerType<T>>(
sourceSeed.setPosition(Math.round(realSourceSeed.getDoublePosition(d)), d)
}

LOG.debug("Filling source {} with label {} at {}", source, fill, sourceSeed)
LOG.debug { "Filling source $source with label $fill at $sourceSeed" }
try {
return fill(time, level, fill, sourceSeed, assignment)
} catch (e: MaskInUse) {
LOG.info(e) {}
return null
LOG.error(e) {}
return Job().apply { completeExceptionally(e) }
}
}

Expand All @@ -83,15 +88,16 @@ class FloodFill<T : IntegerType<T>>(
fill: Long,
seed: Localizable,
assignment: FragmentSegmentAssignment?
): Job? {
): Job {
val data = source.getDataSource(time, level)
val dataAccess = data.randomAccess()
dataAccess.setPosition(seed)
val seedValue = dataAccess.get()
val seedLabel = assignment?.getSegment(seedValue!!.integerLong) ?: seedValue!!.integerLong
if (!Label.regular(seedLabel)) {
LOG.info { "Cannot fill at irregular label: $seedLabel (${Point(seed)})" }
return null
val reason = CancellationException("Cannot fill at irregular label: $seedLabel (${Point(seed)})")
LOG.debug(reason) { }
return Job().apply { completeExceptionally(reason) }
}

val maskInfo = MaskInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Fill3DTool(activeSourceStateProperty: SimpleObjectProperty<SourceState<*,
paintera.baseView.isDisabledProperty.addListener(setFalseAndRemoveListener)
paintera.baseView.disabledPropertyBindings[this] = fillIsRunningProperty

task?.invokeOnCompletion { cause ->
task.invokeOnCompletion { cause ->
fillIsRunningProperty.set(false)
paintera.baseView.disabledPropertyBindings -= this
statePaintContext?.refreshMeshes?.invoke()
Expand Down

0 comments on commit 95f13c2

Please sign in to comment.