Skip to content

Commit

Permalink
feat: add export mesh options to virtual sources
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhulbert committed Dec 15, 2023
1 parent 54eba4c commit 976346c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public class MeshExporterObj<T> extends MeshExporter<T> {

private long numVertices = 0;

public void exportMaterial(String path, final long[] ids, final Color[] colors) {
public void exportMaterial(String path, final String[] ids, final Color[] colors) {
final String materialPath = path + ".mtl";
try (final FileWriter writer = new FileWriter(materialPath, false)) {
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < ids.length; i++) {
final long id = ids[i];
final String id = ids[i];
final Color specularColor = colors[i];
final double red = specularColor.getRed();
final double green = specularColor.getGreen();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package org.janelia.saalfeldlab.paintera.state

import javafx.geometry.Pos
import javafx.scene.Node
import javafx.scene.control.Button
import javafx.scene.control.ColorPicker
import javafx.scene.layout.HBox
import javafx.scene.layout.VBox
import org.janelia.saalfeldlab.fx.extensions.createNullableValueBinding
import org.janelia.saalfeldlab.paintera.meshes.MeshExporterObj
import org.janelia.saalfeldlab.paintera.meshes.MeshInfo
import org.janelia.saalfeldlab.paintera.meshes.managed.MeshManagerWithSingleMesh
import org.janelia.saalfeldlab.paintera.meshes.ui.MeshSettingsController
import org.janelia.saalfeldlab.paintera.meshes.ui.MeshSettingsController.Companion.addGridOption
import org.janelia.saalfeldlab.paintera.ui.source.mesh.MeshExporterDialog
import org.janelia.saalfeldlab.util.Colors

class IntersectingSourceStatePreferencePaneNode(private val state: IntersectingSourceState<*, *>) {

val node: Node
get() {
val manager = state.meshManager
val settings = manager.settings
val settings = manager.globalSettings

return SourceState.defaultPreferencePaneNode(state.compositeProperty()).apply {
children += MeshSettingsController(settings, state::refreshMeshes).createTitledPane(
Expand All @@ -29,7 +37,36 @@ class IntersectingSourceStatePreferencePaneNode(private val state: IntersectingS
}

addGridOption("Color", colorPicker)
}.also {
it.content = VBox(it.content).apply {
val exportMeshButton = Button("Export all")
exportMeshButton.setOnAction { _ ->
val manager = state.meshManager as MeshManagerWithSingleMesh<IntersectingSourceStateMeshCacheKey<*, *>>
val key = manager.meshKey!!
val exportDialog = MeshExporterDialog(MeshInfo(key, manager))
val result = exportDialog.showAndWait()
if (result.isPresent) {
result.get().run {
(meshExporter as? MeshExporterObj<*>)?.run {
exportMaterial(filePath, arrayOf(""), arrayOf(Colors.toColor(state.converter().color)))
}
meshExporter.exportMesh(
manager.getBlockListFor,
manager.getMeshFor,
manager.getSettings(key),
key,
scale,
filePath,
false
)
}
}
}
val buttonBox = HBox(exportMeshButton).also { it.alignment = Pos.BOTTOM_RIGHT }
children += buttonBox

}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import org.janelia.saalfeldlab.fx.TitledPanes
import org.janelia.saalfeldlab.fx.ui.NamedNode
import org.janelia.saalfeldlab.fx.ui.NumberField
import org.janelia.saalfeldlab.fx.ui.ObjectField
import org.janelia.saalfeldlab.paintera.meshes.MeshExporterObj
import org.janelia.saalfeldlab.paintera.meshes.MeshInfo
import org.janelia.saalfeldlab.paintera.meshes.ui.MeshSettingsController
import org.janelia.saalfeldlab.paintera.ui.PainteraAlerts
import org.janelia.saalfeldlab.paintera.ui.source.mesh.MeshExporterDialog

class ThresholdingSourceStatePreferencePaneNode(private val state: ThresholdingSourceState<*, *>) {

Expand All @@ -26,6 +29,7 @@ class ThresholdingSourceStatePreferencePaneNode(private val state: ThresholdingS
.also { it.children.addAll(createBasicNote(), createMeshesNode()) }

private fun createBasicNote(): Node {

val min = NumberField
.doubleField(state.minProperty().get(), { true }, ObjectField.SubmitOn.ENTER_PRESSED, ObjectField.SubmitOn.FOCUS_LOST)
.also { it.valueProperty().addListener { _, _, new -> state.minProperty().set(new.toDouble()) } }
Expand Down Expand Up @@ -82,6 +86,33 @@ class ThresholdingSourceStatePreferencePaneNode(private val state: ThresholdingS
state.meshManager.managedSettings.meshesEnabledProperty,
titledPaneGraphicsSettings = MeshSettingsController.TitledPaneGraphicsSettings("Meshes"),
helpDialogSettings = MeshSettingsController.HelpDialogSettings(headerText = "Meshes")
)
).also {
it.content = VBox(it.content).apply {
val exportMeshButton = Button("Export all")
exportMeshButton.setOnAction { _ ->
val exportDialog = MeshExporterDialog(MeshInfo(state.meshManager.meshKey, state.meshManager))
val result = exportDialog.showAndWait()
if (result.isPresent) {
result.get().run {
(meshExporter as? MeshExporterObj<*>)?.run {
exportMaterial(filePath, arrayOf(""), arrayOf(state.colorProperty().get()))
}
meshExporter.exportMesh(
state.meshManager.getBlockListFor,
state.meshManager.getMeshFor,
state.meshSettings,
state.thresholdBounds,
scale,
filePath,
false
)
}
}
}
val buttonBox = HBox(exportMeshButton).also { it.alignment = Pos.BOTTOM_RIGHT }
children += buttonBox

}
}

}

0 comments on commit 976346c

Please sign in to comment.