Skip to content

Commit

Permalink
refactor: don't update progress on UI thread
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhulbert committed Dec 16, 2024
1 parent 4df5e9d commit aadbaee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
import net.imglib2.type.numeric.integer.UnsignedLongType;
import net.imglib2.util.Intervals;
import net.imglib2.util.Pair;
import net.imglib2.util.Util;
import net.imglib2.view.IntervalView;
import net.imglib2.view.Views;
import org.janelia.saalfeldlab.fx.util.InvokeOnJavaFXApplicationThread;
import org.janelia.saalfeldlab.labels.blocks.LabelBlockLookup;
import org.janelia.saalfeldlab.labels.blocks.LabelBlockLookupKey;
import org.janelia.saalfeldlab.labels.downsample.WinnerTakesAll;
Expand Down Expand Up @@ -226,7 +224,7 @@ public List<TLongObjectMap<BlockDiff>> persistCanvas(final CachedCellImg<Unsigne

LOG.info(() -> "Committing canvas: %d blocks".formatted(blocks.length));
LOG.debug(() -> "Affected blocks in grid %s: %s".formatted(canvas.getCellGrid(), blocks));
InvokeOnJavaFXApplicationThread.invoke(() -> progress.set(0.1));
progress.set(0.1);
try {
final String datasetPath = getDatasetPath();
final String highestResDatasetPath = getHighestResolutionDatasetPath();
Expand All @@ -253,7 +251,7 @@ public List<TLongObjectMap<BlockDiff>> persistCanvas(final CachedCellImg<Unsigne
writeBlocksLabelIntegerType(canvas, blocks, highestResolutionDataset, highestResolutionBlockSpec, blockDiffsAtHighestLevel);
}

InvokeOnJavaFXApplicationThread.invoke(() -> progress.set(0.4));
progress.set(0.4);

/* If multiscale, downscale and write the lower scales*/
if (isMultiscale()) {
Expand Down Expand Up @@ -317,7 +315,7 @@ public List<TLongObjectMap<BlockDiff>> persistCanvas(final CachedCellImg<Unsigne
blockDiffsAt);

}
InvokeOnJavaFXApplicationThread.invoke(() -> progress.set(1.0));
progress.set(1.0);

}
LOG.info(() -> "Finished commiting canvas");
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/org/janelia/saalfeldlab/paintera/Paintera.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Paintera : Application() {
private lateinit var painteraArgs: PainteraCommandLineArgs
private var projectDir: String? = null

internal lateinit var mainWindow : PainteraMainWindow
internal lateinit var mainWindow: PainteraMainWindow

init {
application = this
Expand Down Expand Up @@ -108,7 +108,7 @@ class Paintera : Application() {
} ?: notifyPreloader(SplashScreenUpdateNotification("Launching Paintera...", true))
paintable = true
runPaintable()
PlatformImpl.runAndWait {
InvokeOnJavaFXApplicationThread.invokeAndWait {
paintera.properties.loggingConfig.apply {
painteraArgs.logLevel?.let { rootLoggerLevel = it }
painteraArgs.logLevelsByName?.forEach { (name, level) -> name?.let { setLogLevelFor(it, level) } }
Expand Down Expand Up @@ -324,7 +324,7 @@ class Paintera : Application() {
SaalFxStyle.registerStylesheets(styleable)
}

private val stylesheets : List<String> = listOf(
private val stylesheets: List<String> = listOf(
"style/glyphs.css",
"style/toolbar.css",
"style/navigation.css",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import gnu.trove.map.hash.TLongObjectHashMap
import gnu.trove.set.TLongSet
import gnu.trove.set.hash.TLongHashSet
import io.github.oshai.kotlinlogging.KotlinLogging
import javafx.application.Platform
import net.imglib2.Interval
import net.imglib2.RandomAccessibleInterval
import net.imglib2.Volatile
Expand All @@ -21,7 +20,6 @@ import net.imglib2.type.numeric.integer.UnsignedLongType
import net.imglib2.util.IntervalIndexer
import net.imglib2.util.Intervals
import net.imglib2.view.Views
import org.janelia.saalfeldlab.fx.util.InvokeOnJavaFXApplicationThread
import org.janelia.saalfeldlab.labels.blocks.LabelBlockLookupKey
import org.janelia.saalfeldlab.labels.blocks.n5.LabelBlockLookupFromN5Relative
import org.janelia.saalfeldlab.n5.*
Expand All @@ -36,8 +34,8 @@ import org.janelia.saalfeldlab.paintera.state.metadata.N5ContainerState
import org.janelia.saalfeldlab.util.n5.ImagesWithTransform
import org.janelia.saalfeldlab.util.n5.N5Helpers
import org.janelia.saalfeldlab.util.n5.N5TestUtil
import org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.util.Random
import java.util.stream.IntStream
Expand Down

0 comments on commit aadbaee

Please sign in to comment.