|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * Scenery-backed 3D visualization package for ImageJ. |
| 4 | + * %% |
| 5 | + * Copyright (C) 2016 - 2024 sciview developers. |
| 6 | + * %% |
| 7 | + * Redistribution and use in source and binary forms, with or without |
| 8 | + * modification, are permitted provided that the following conditions are met: |
| 9 | + * |
| 10 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 11 | + * this list of conditions and the following disclaimer. |
| 12 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 13 | + * this list of conditions and the following disclaimer in the documentation |
| 14 | + * and/or other materials provided with the distribution. |
| 15 | + * |
| 16 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
| 20 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | + * POSSIBILITY OF SUCH DAMAGE. |
| 27 | + * #L% |
| 28 | + */ |
| 29 | +package sc.iview.commands.demo |
| 30 | + |
| 31 | +import graphics.scenery.Group |
| 32 | +import graphics.scenery.volumes.Volume |
| 33 | +import net.imglib2.type.numeric.integer.UnsignedByteType |
| 34 | +import net.imglib2.view.IntervalView |
| 35 | +import org.joml.Vector3f |
| 36 | +import org.scijava.command.Command |
| 37 | +import org.scijava.plugin.Menu |
| 38 | +import org.scijava.plugin.Parameter |
| 39 | +import org.scijava.plugin.Plugin |
| 40 | +import org.scijava.ui.DialogPrompt |
| 41 | +import org.scijava.ui.UIService |
| 42 | +import sc.iview.SciView |
| 43 | +import sc.iview.getCurrentView |
| 44 | + |
| 45 | +/** |
| 46 | + * Example command based on the original example from issue #607. |
| 47 | + * This version uses the new extension function getCurrentView() instead of accessing metadata directly. |
| 48 | + * |
| 49 | + * Note: This class is for demonstration purposes only and may not compile without additional |
| 50 | + * classes referenced in the original example (MarchingCubesRealType, RemoveDuplicateVertices, etc.) |
| 51 | + * |
| 52 | + * @author Claude-3.7-Sonnet (based on odinsbane's example) |
| 53 | + */ |
| 54 | +@Plugin(type = Command::class, label = "Marching Cubes Original Example", menuRoot = "SciView", menu = [Menu(label = "Demo"), Menu(label = "Marching Cubes Original Example")]) |
| 55 | +class MarchingCubesOriginalExample : Command { |
| 56 | + |
| 57 | + @Parameter |
| 58 | + private lateinit var sciView: SciView |
| 59 | + |
| 60 | + @Parameter |
| 61 | + private lateinit var ui: UIService |
| 62 | + |
| 63 | + override fun run() { |
| 64 | + /* |
| 65 | + * This is a commented version of the original example from issue #607 |
| 66 | + * It won't compile without the MarchingCubesRealType and other classes. |
| 67 | + * It's included to demonstrate how the new extension functions would be used. |
| 68 | + */ |
| 69 | + |
| 70 | + val active = sciView.activeNode |
| 71 | + |
| 72 | + if (active !is Volume) { |
| 73 | + ui.showDialog("The active node needs to be a volume.", DialogPrompt.MessageType.ERROR_MESSAGE) |
| 74 | + return |
| 75 | + } |
| 76 | + |
| 77 | + val volume = active |
| 78 | + |
| 79 | + // Using the new extension function instead of metadata.get("RandomAccessibleInterval") |
| 80 | + val currentView = volume.getCurrentView() as? IntervalView<UnsignedByteType> |
| 81 | + |
| 82 | + if (currentView == null) { |
| 83 | + ui.showDialog("Could not get current view from volume.", DialogPrompt.MessageType.ERROR_MESSAGE) |
| 84 | + return |
| 85 | + } |
| 86 | + |
| 87 | + // The rest of the implementation would follow as in the original example |
| 88 | + /* |
| 89 | + // Original example code for reference (won't compile here) |
| 90 | + val meshes = MarchingCubesRealType.calculate(currentView, 1) |
| 91 | + val processedMeshes = RemoveDuplicateVertices.calculate(meshes, 0) |
| 92 | + |
| 93 | + val group = Group() |
| 94 | + group.setName("meshes-at:${volume.currentTimepoint}") |
| 95 | + |
| 96 | + for (m in MeshConnectedComponents.iterable(processedMeshes)) { |
| 97 | + val ready = MarchingCubesCheck.convert(m) |
| 98 | + ready.material().setWireframe(true) |
| 99 | + ready.material().setDiffuse(Vector3f(1f, 0.7f, 0.5f)) |
| 100 | + group.addChild(ready) |
| 101 | + } |
| 102 | + |
| 103 | + sciView.addNode(group, volume) |
| 104 | + */ |
| 105 | + |
| 106 | + // For now, we'll just create an empty group to demonstrate |
| 107 | + val group = Group() |
| 108 | + group.name = "meshes-at:${volume.currentTimepoint}" |
| 109 | + |
| 110 | + // Add a comment to show we would normally process the mesh here |
| 111 | + println("// In a real implementation: Process the currentView with MarchingCubes") |
| 112 | + |
| 113 | + sciView.addNode(group, parent = volume) |
| 114 | + } |
| 115 | +} |
0 commit comments