Skip to content

Commit

Permalink
Merge pull request #502 from cmhulbert/feat/smoothAction
Browse files Browse the repository at this point in the history
Feat/smooth action
  • Loading branch information
cmhulbert authored Aug 25, 2023
2 parents 53e7262 + b177fc3 commit b6eac3d
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/main/java/bdv/fx/viewer/ViewerPanelFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public ViewerPanelFX(
transformListeners.add(tf -> Paintera.whenPaintable(getDisplay()::drawOverlays));

this.state = new ViewerState(numTimepoints, this);
state.addListener(obs -> Paintera.whenPaintable(this::requestRepaint));
state.addListener(obs -> Paintera.ifPaintable(this::requestRepaint));

Paintera.whenPaintable(() -> getDisplay().drawOverlays());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.janelia.saalfeldlab.util.n5.N5Helpers.getReaderOrWriterIfN5ContainerExists;
import static org.janelia.saalfeldlab.util.n5.N5Helpers.getReaderOrGetWriterIfExistsAndWritable;

@Command(name = "Paintera", showDefaultValues = true, resourceBundle = "org.janelia.saalfeldlab.paintera.PainteraCommandLineArgs", usageHelpWidth = 120,
parameterListHeading = "%n@|bold,underline Parameters|@:%n",
Expand Down Expand Up @@ -649,7 +649,7 @@ private void addToViewer(final PainteraBaseView viewer, final Supplier<String> p
for (final String container : containers) {
LOG.debug("Adding datasets for container {}", container);

N5Reader n5Container = getReaderOrWriterIfN5ContainerExists(container);
N5Reader n5Container = getReaderOrGetWriterIfExistsAndWritable(container);

final Predicate<String> datasetFilter = options.useDataset();
final ExecutorService es = getDiscoveryExecutorService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,6 @@ else if (blockOutlineRemoved instanceof Shape3D)
((PhongMaterial)meshAdded.getMaterial()).diffuseColorProperty().bind(this.state.premultipliedColor);
meshAdded.drawModeProperty().bind(this.state.settings.getDrawModeProperty());
meshAdded.cullFaceProperty().bind(this.state.settings.getCullFaceProperty());
meshAdded.scaleXProperty().bind(this.state.settings.getInflateProperty());
meshAdded.scaleYProperty().bind(this.state.settings.getInflateProperty());
meshAdded.scaleZProperty().bind(this.state.settings.getInflateProperty());
}

if (change.getValueAdded().getB() != null) {
Expand All @@ -284,9 +281,6 @@ else if (blockOutlineAdded instanceof Shape3D)
material = null;
if (material instanceof PhongMaterial)
((PhongMaterial)material).diffuseColorProperty().bind(this.state.premultipliedColor);
blockOutlineAdded.scaleXProperty().bind(this.state.settings.getInflateProperty());
blockOutlineAdded.scaleYProperty().bind(this.state.settings.getInflateProperty());
blockOutlineAdded.scaleZProperty().bind(this.state.settings.getInflateProperty());
blockOutlineAdded.setDisable(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class Smooth {
*/
private static final Logger LOG = LoggerFactory.getLogger(Smooth.class);

public static final double DEFAULT_LAMBDA = 0.5;
public static final double DEFAULT_LAMBDA = 1.0;

public static final int DEFAULT_ITERATIONS = 3;
public static final int DEFAULT_ITERATIONS = 1;

private static boolean isBoundary(
final ArrayList<TIntHashSet> vertexTriangleLUT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.janelia.saalfeldlab.paintera.serialization.sourcestate.SourceStateSerialization;
import org.janelia.saalfeldlab.paintera.state.SourceInfo;
import org.janelia.saalfeldlab.paintera.state.SourceState;
import org.janelia.saalfeldlab.paintera.state.raw.ConnectomicsRawState;
import org.janelia.saalfeldlab.util.n5.N5Helpers;
import org.scijava.plugin.Plugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -157,9 +157,11 @@ public static void populate(
}

final SourceState<?, ?>[] sourceStates = new SourceState[numStates];
final boolean[] removeState = new boolean[numStates];

for (int i = 0; i < numStates && Arrays.stream(sourceStates).anyMatch(Objects::isNull); ++i) {
for (int k = 0; k < numStates; ++k) {
if (removeState[k]) continue;
if (sourceStates[k] == null) {
final SourceState<?, ?>[] dependencies = IntStream
.of(dependsOn[k].toArray())
Expand All @@ -180,18 +182,36 @@ public static void populate(
@SuppressWarnings("unchecked") final Class<? extends SourceState<?, ?>> clazz = (Class<? extends SourceState<?, ?>>)Class
.forName(state.get(STATE_TYPE_KEY).getAsString());
LOG.debug("Deserializing state={}, class={}", state, clazz);
sourceStates[k] = gson.fromJson(state.get(STATE_KEY), clazz);
try {
sourceStates[k] = gson.fromJson(state.get(STATE_KEY), clazz);
} catch (Exception e) {
//noinspection ConstantValue
if (e instanceof N5Helpers.RemoveSourceException) {
LOG.info("Removing source: {}", stateName);
sourceStates[k] = null;
removeState[k] = true;
continue;
} else {
throw e;
}
}
logSourceForDependencies.accept(k, sourceStates[k]);
}
}
}
}

if (Arrays.stream(sourceStates).anyMatch(Objects::isNull)) {
throw new RuntimeException("Unable to deserialize all source states");
final ArrayList<SourceState<?, ?>> states = new ArrayList<>();
for (int i = 0; i < sourceStates.length; i++) {
final SourceState<?, ?> sourceState = sourceStates[i];
if (sourceState == null && !removeState[i])
throw new RuntimeException("Unable to deserialize all source states");
else if (sourceState != null)
states.add(sourceState);

}

return sourceStates;
return states.toArray(SourceState[]::new);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public class MeshSettingsSerializer implements PainteraSerialization.PainteraAda

private static final String CULL_FACE_KEY = "cullFace";

private static final String INFLATE_KEY = "inflate";

private static final String IS_VISIBLE_KEY = "isVisible";

public static MeshSettings deserializeInto(
Expand All @@ -54,7 +52,6 @@ public static MeshSettings deserializeInto(
Optional.ofNullable(map.get(SMOOTHING_ITERATIONS_KEY)).map(JsonElement::getAsInt).ifPresent(settings::setSmoothingIterations);
Optional.ofNullable(map.get(SMOOTHING_LAMBDA_KEY)).map(JsonElement::getAsDouble).ifPresent(settings::setSmoothingLambda);
Optional.ofNullable(map.get(OPACITY_KEY)).map(JsonElement::getAsDouble).ifPresent(settings::setOpacity);
Optional.ofNullable(map.get(INFLATE_KEY)).map(JsonElement::getAsDouble).ifPresent(settings::setInflate);
Optional.ofNullable(map.get(DRAW_MODE_KEY)).map(el -> (DrawMode)context.deserialize(el, DrawMode.class)).ifPresent(settings::setDrawMode);
Optional.ofNullable(map.get(CULL_FACE_KEY)).map(el -> (CullFace)context.deserialize(el, CullFace.class)).ifPresent(settings::setCullFace);
Optional.ofNullable(map.get(IS_VISIBLE_KEY)).map(JsonElement::getAsBoolean).ifPresent(settings::setVisible);
Expand Down Expand Up @@ -112,9 +109,6 @@ public JsonElement serialize(final MeshSettings src, final Type typeOfSrc, final
if (defaults.getOpacity() != src.getOpacityProperty().get())
map.addProperty(OPACITY_KEY, src.getOpacityProperty().get());

if (defaults.getInflate() != src.getInflate())
map.addProperty(INFLATE_KEY, src.getInflate());

if (defaults.isVisible() != src.isVisible())
map.addProperty(IS_VISIBLE_KEY, src.isVisible());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ private void createMultiIdsDialog(final ObservableList<Long> ids) {
int row = createCommonDialog(contents);

checkListView.setItems(ids);
checkListView.prefHeightProperty()
.bind(Bindings.size(checkListView.itemsProperty().get()).multiply(LIST_CELL_HEIGHT));
checkListView.getSelectionModel().selectAll();
selectAll.setSelected(true);
checkListView.prefHeightProperty().bind(Bindings.size(checkListView.itemsProperty().get()).multiply(LIST_CELL_HEIGHT));

final Button button = new Button("Browse");
button.setOnAction(event -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,22 @@ public class N5FactoryWithCache extends N5Factory {
readerCache.remove(url).close();
}
} else {
readerCache.put(url, super.openReader(url));
final N5Reader reader = super.openReader(url);
if (reader.getAttribute("/", N5Reader.VERSION_KEY, String.class) != null) {
readerCache.put(url, reader);
}
}
return readerCache.get(url);
}

@Override public N5Writer openWriter(String url) {

/* Check if writer is valid (it may have been closed by someone) */
final N5Reader cachedContainer = writerCache.get(url);
final N5Writer cachedContainer = writerCache.get(url);
if (cachedContainer != null) {
try {
cachedContainer.getVersion();
/* See if its open, and we still have write permissions */
cachedContainer.setAttribute("/", N5Reader.VERSION_KEY, cachedContainer.getVersion().toString());
} catch (Exception e) {
writerCache.remove(url).close();
if (readerCache.get(url) == cachedContainer) {
Expand All @@ -79,6 +83,8 @@ public class N5FactoryWithCache extends N5Factory {
}
} else {
final N5Writer n5Writer = super.openWriter(url);
/* See if we have write permissions before we declare success */
n5Writer.setAttribute("/", N5Reader.VERSION_KEY, n5Writer.getVersion());
writerCache.put(url, n5Writer);
if (readerCache.get(url) != null) {
readerCache.remove(url).close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ScreenScalesConfig @JvmOverloads constructor(vararg initialScales: Double

companion object {

private val DEFAULT_SCREEN_SCALES = doubleArrayOf(1.0, 0.5, 0.25, 0.125, 0.0625)
private val DEFAULT_SCREEN_SCALES = doubleArrayOf(0.5, 0.25, 0.125)

@JvmStatic
fun defaultScreenScalesCopy(): DoubleArray {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.janelia.saalfeldlab.paintera.Paintera.Companion.n5Factory
import org.janelia.saalfeldlab.paintera.serialization.GsonExtensions
import org.janelia.saalfeldlab.paintera.serialization.StatefulSerializer
import org.janelia.saalfeldlab.paintera.state.SourceState
import org.janelia.saalfeldlab.util.n5.N5Helpers.getReaderOrWriterIfN5ContainerExists
import org.janelia.saalfeldlab.util.n5.N5Helpers.getReaderOrGetWriterIfExistsAndWritable
import org.janelia.saalfeldlab.util.n5.N5Helpers.getWriterIfN5ContainerExists
import org.scijava.plugin.Plugin
import java.lang.reflect.Type
Expand Down Expand Up @@ -87,7 +87,7 @@ class N5HDF5ReaderAdapter : StatefulSerializer.SerializerAndDeserializer<N5HDF5R
): JsonDeserializer<N5HDF5Reader> = HDF5Deserializer(projectDirectory) { file, overrideBlockSize, defaultBlockSize ->
n5Factory.hdf5OverrideBlockSize(overrideBlockSize)
n5Factory.hdf5DefaultBlockSize(*(defaultBlockSize ?: intArrayOf()))
(getReaderOrWriterIfN5ContainerExists(file) as? N5HDF5Reader) ?: throw hdf5OpenError(file)
(getReaderOrGetWriterIfExistsAndWritable(file) as? N5HDF5Reader) ?: throw hdf5OpenError(file)
}

override fun getTargetClass() = N5HDF5Reader::class.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class MeshSettings @JvmOverloads constructor(
val opacity: Double
val drawMode: DrawMode
val cullFace: CullFace
val inflate: Double
val isVisible: Boolean
val minLabelRatio: Double
val levelOfDetail: Int
Expand All @@ -45,9 +44,6 @@ class MeshSettings @JvmOverloads constructor(
@JvmStatic
val cullFace = CullFace.FRONT

@JvmStatic
val inflate = 1.0

@JvmStatic
val isVisible = true

Expand Down Expand Up @@ -83,7 +79,6 @@ class MeshSettings @JvmOverloads constructor(
override var opacity: Double = Defaults.Values.opacity
override var drawMode: DrawMode = Defaults.Values.drawMode
override var cullFace: CullFace = Defaults.Values.cullFace
override var inflate: Double = Defaults.Values.inflate
override var isVisible: Boolean = Defaults.Values.isVisible
override var minLabelRatio: Double = Defaults.Values.minLabelRatio
override var levelOfDetail: Int = Defaults.Values.levelOfDetail
Expand All @@ -103,7 +98,6 @@ class MeshSettings @JvmOverloads constructor(
val opacityProperty: DoubleProperty = SimpleDoubleProperty(defaults.opacity)
val drawModeProperty: ObjectProperty<DrawMode> = SimpleObjectProperty(defaults.drawMode)
val cullFaceProperty: ObjectProperty<CullFace> = SimpleObjectProperty(defaults.cullFace)
val inflateProperty: DoubleProperty = SimpleDoubleProperty(defaults.inflate)
val isVisibleProperty: BooleanProperty = SimpleBooleanProperty(defaults.isVisible)
val minLabelRatioProperty: DoubleProperty = SimpleDoubleProperty(defaults.minLabelRatio)
val levelOfDetailProperty: IntegerProperty = SimpleIntegerProperty(defaults.levelOfDetail)
Expand All @@ -116,7 +110,6 @@ class MeshSettings @JvmOverloads constructor(
var opacity by opacityProperty.nonnull()
var drawMode by drawModeProperty.nonnull()
var cullFace by cullFaceProperty.nonnull()
var inflate by inflateProperty.nonnull()
var isVisible by isVisibleProperty.nonnull()
var minLabelRatio by minLabelRatioProperty.nonnull()
var levelOfDetail by levelOfDetailProperty.nonnull()
Expand Down Expand Up @@ -147,7 +140,6 @@ class MeshSettings @JvmOverloads constructor(
opacity = that.opacity
drawMode = that.drawMode
cullFace = that.cullFace
inflate = that.inflate
isVisible = that.isVisible
}

Expand All @@ -171,7 +163,6 @@ class MeshSettings @JvmOverloads constructor(
opacityProperty.bind(that.opacityProperty)
drawModeProperty.bind(that.drawModeProperty)
cullFaceProperty.bind(that.cullFaceProperty)
inflateProperty.bind(that.inflateProperty)
isVisibleProperty.bind(that.isVisibleProperty)
}

Expand All @@ -186,7 +177,6 @@ class MeshSettings @JvmOverloads constructor(
opacityProperty.unbind()
drawModeProperty.unbind()
cullFaceProperty.unbind()
inflateProperty.unbind()
isVisibleProperty.unbind()
}

Expand All @@ -201,7 +191,6 @@ class MeshSettings @JvmOverloads constructor(
opacityProperty.bindBidirectional(that.opacityProperty)
drawModeProperty.bindBidirectional(that.drawModeProperty)
cullFaceProperty.bindBidirectional(that.cullFaceProperty)
inflateProperty.bindBidirectional(that.inflateProperty)
isVisibleProperty.bindBidirectional(that.isVisibleProperty)
}

Expand All @@ -216,7 +205,6 @@ class MeshSettings @JvmOverloads constructor(
opacityProperty.unbindBidirectional(that.opacityProperty)
drawModeProperty.unbindBidirectional(that.drawModeProperty)
cullFaceProperty.unbindBidirectional(that.cullFaceProperty)
inflateProperty.unbindBidirectional(that.inflateProperty)
isVisibleProperty.unbindBidirectional(that.isVisibleProperty)
}

Expand All @@ -229,7 +217,6 @@ class MeshSettings @JvmOverloads constructor(
&& opacity == defaults.opacity
&& defaults.drawMode == drawMode
&& defaults.cullFace == cullFace
&& inflate == defaults.inflate
&& isVisible == defaults.isVisible
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class MeshSettingsController @JvmOverloads constructor(
private val smoothingLambda: DoubleProperty,
private val smoothingIterations: IntegerProperty,
private val minLabelRatio: DoubleProperty,
private val inflate: DoubleProperty,
private val drawMode: Property<DrawMode>,
private val cullFace: Property<CullFace>,
private val isVisible: BooleanProperty,
Expand All @@ -51,7 +50,6 @@ class MeshSettingsController @JvmOverloads constructor(
meshSettings.smoothingLambdaProperty,
meshSettings.smoothingIterationsProperty,
meshSettings.minLabelRatioProperty,
meshSettings.inflateProperty,
meshSettings.drawModeProperty,
meshSettings.cullFaceProperty,
meshSettings.isVisibleProperty,
Expand All @@ -74,10 +72,9 @@ class MeshSettingsController @JvmOverloads constructor(
it.slider.valueProperty().bindBidirectional(coarsestScaleLevel)
},
NumericSliderWithField(0, this.numScaleLevels - 1, finestScaleLevel.value).apply { slider.valueProperty().bindBidirectional(finestScaleLevel) },
NumericSliderWithField(0.0, 1.00, .05).apply { slider.valueProperty().bindBidirectional(smoothingLambda) },
NumericSliderWithField(0, 10, 5).apply { slider.valueProperty().bindBidirectional(smoothingIterations) },
NumericSliderWithField(0.0, 1.00, 1.0).apply { slider.valueProperty().bindBidirectional(smoothingLambda) },
NumericSliderWithField(0, 10, 1).apply { slider.valueProperty().bindBidirectional(smoothingIterations) },
NumericSliderWithField(0.0, 1.0, 0.5).apply { slider.valueProperty().bindBidirectional(minLabelRatio) },
NumericSliderWithField(0.5, 2.0, inflate.value).apply { slider.valueProperty().bindBidirectional(inflate) },
ComboBox(FXCollections.observableArrayList(*DrawMode.values())).apply { valueProperty().bindBidirectional(drawMode) },
ComboBox(FXCollections.observableArrayList(*CullFace.values())).apply { valueProperty().bindBidirectional(cullFace) })
}
Expand Down Expand Up @@ -154,7 +151,6 @@ class MeshSettingsController @JvmOverloads constructor(
smoothingLambdaSlider: NumericSliderWithField,
smoothingIterationsSlider: NumericSliderWithField,
minLabelRatioSlider: NumericSliderWithField,
inflateSlider: NumericSliderWithField,
drawModeChoice: ComboBox<DrawMode>,
cullFaceChoice: ComboBox<CullFace>,
): GridPane {
Expand Down Expand Up @@ -188,7 +184,6 @@ class MeshSettingsController @JvmOverloads constructor(
addGridOption("Min label ratio", minLabelRatioSlider, tooltipText)
}

addGridOption("Inflate", inflateSlider, "Inflate Meshes by Factor")
addGridOption("Draw Mode", drawModeChoice)
addGridOption("Cull Face", cullFaceChoice)
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.janelia.saalfeldlab.paintera.state.metadata.MetadataState.Companion.i
import org.janelia.saalfeldlab.util.n5.ImagesWithTransform
import org.janelia.saalfeldlab.util.n5.N5Data
import org.janelia.saalfeldlab.util.n5.N5Helpers
import org.janelia.saalfeldlab.util.n5.N5Helpers.getReaderOrWriterIfN5ContainerExists
import org.janelia.saalfeldlab.util.n5.N5Helpers.getReaderOrGetWriterIfExistsAndWritable
import org.janelia.saalfeldlab.util.n5.metadata.N5PainteraDataMultiScaleGroup
import java.util.Optional

Expand Down Expand Up @@ -229,7 +229,7 @@ class MetadataUtils {

@JvmStatic
fun createMetadataState(n5containerAndDataset: String): Optional<MetadataState> {
val reader = getReaderOrWriterIfN5ContainerExists(n5containerAndDataset) ?: return Optional.empty()
val reader = getReaderOrGetWriterIfExistsAndWritable(n5containerAndDataset) ?: return Optional.empty()

val n5ContainerState = N5ContainerState(reader)
return N5Helpers.parseMetadata(reader).map { treeNode ->
Expand All @@ -243,7 +243,7 @@ class MetadataUtils {

@JvmStatic
fun createMetadataState(n5container: String, dataset: String?): Optional<MetadataState> {
val reader = getReaderOrWriterIfN5ContainerExists(n5container) ?: return Optional.empty()
val reader = getReaderOrGetWriterIfExistsAndWritable(n5container) ?: return Optional.empty()

val n5ContainerState = N5ContainerState(reader)
val metadataRoot = N5Helpers.parseMetadata(reader)
Expand Down
Loading

0 comments on commit b6eac3d

Please sign in to comment.