Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Del key and add commands #492

Merged
merged 5 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/kotlin/sc/iview/Controls.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import sc.iview.controls.behaviours.Ruler
import java.io.File
import java.util.*
import java.util.function.Supplier
import kotlin.concurrent.thread
import kotlin.math.acos

/**
Expand Down Expand Up @@ -185,6 +184,9 @@ open class Controls(val sciview: SciView) {
h.addKeyBinding("node: move selected one closer or further away", "ctrl scroll")
h.addBehaviour("node: rotate selected one", NodeRotateControl(sciview))
h.addKeyBinding("node: rotate selected one", "ctrl shift button1")
h.addBehaviour("node: delete selected one", ClickBehaviour { _, _ -> sciview.deleteActiveNode() })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to warn the user? I think Blender throws up a dialog before deletion. This could be a call to the DeleteObject command and we could have that command contain the dialog warning?

h.addKeyBinding("node: delete selected one", "DELETE")


// within-scene navigation: ArcBall and FPS
enableArcBallControl()
Expand Down
14 changes: 12 additions & 2 deletions src/main/kotlin/sc/iview/SciView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,14 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
* @param num_segments number of segments to represent the cylinder
* @return the Node corresponding to the cylinder
*/
fun addCylinder(position: Vector3f, radius: Float, height: Float, num_segments: Int, block: Cylinder.() -> Unit = {}): Cylinder {
fun addCylinder(position: Vector3f, radius: Float, height: Float, color: ColorRGB = DEFAULT_COLOR, num_segments: Int, block: Cylinder.() -> Unit = {}): Cylinder {
val cyl = Cylinder(radius, height, num_segments)
cyl.spatial().position = position
cyl.material {
ambient = Vector3f(1.0f, 0.0f, 0.0f)
diffuse = Utils.convertToVector3f(color)
specular = Vector3f(1.0f, 1.0f, 1.0f)
}
return addNode(cyl, block = block)
}

Expand All @@ -636,9 +641,14 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
* @param num_segments number of segments used to represent cone
* @return the Node corresponding to the cone
*/
fun addCone(position: Vector3f, radius: Float, height: Float, num_segments: Int, block: Cone.() -> Unit = {}): Cone {
fun addCone(position: Vector3f, radius: Float, height: Float, color: ColorRGB = DEFAULT_COLOR, num_segments: Int, block: Cone.() -> Unit = {}): Cone {
val cone = Cone(radius, height, num_segments, Vector3f(0.0f, 0.0f, 1.0f))
cone.spatial().position = position
cone.material {
ambient = Vector3f(1.0f, 0.0f, 0.0f)
diffuse = Utils.convertToVector3f(color)
specular = Vector3f(1.0f, 1.0f, 1.0f)
}
return addNode(cone, block = block)
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/sc/iview/commands/MenuWeights.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ object MenuWeights {
// Edit/Add
const val EDIT_ADD_BOX = 0.0
const val EDIT_ADD_SPHERE = 1.0
const val EDIT_ADD_CYLINDER = 1.3
const val EDIT_ADD_CONE = 1.6
const val EDIT_ADD_LINE = 2.0
const val EDIT_ADD_POINTLIGHT = 3.0
const val EDIT_ADD_LABELIMAGE = 4.0
Expand Down
80 changes: 80 additions & 0 deletions src/main/kotlin/sc/iview/commands/edit/add/AddCone.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*-
* #%L
* Scenery-backed 3D visualization package for ImageJ.
* %%
* Copyright (C) 2016 - 2021 SciView developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package sc.iview.commands.edit.add

import org.joml.Vector3f
import org.scijava.command.Command
import org.scijava.plugin.Menu
import org.scijava.plugin.Parameter
import org.scijava.plugin.Plugin
import org.scijava.util.ColorRGB
import sc.iview.SciView
import sc.iview.commands.MenuWeights.EDIT
import sc.iview.commands.MenuWeights.EDIT_ADD
import sc.iview.commands.MenuWeights.EDIT_ADD_CONE
import sc.iview.commands.MenuWeights.EDIT_ADD_CYLINDER

/**
* Command to add a box to the scene
*
* @author Jan Tiemann
*/
@Plugin(
type = Command::class,
menuRoot = "SciView",
menu = [Menu(label = "Edit", weight = EDIT), Menu(label = "Add", weight = EDIT_ADD), Menu(
label = "Cone...",
weight = EDIT_ADD_CONE
)]
)
class AddCone : Command {

@Parameter
private lateinit var sciView: SciView

// FIXME
// @Parameter
// private String position = "0; 0; 0";

@Parameter
private var height = 1.0f

@Parameter
private var radius = 1.0f

@Parameter
private var color: ColorRGB = SciView.DEFAULT_COLOR;

override fun run() {
//final Vector3 pos = ClearGLVector3.parse( position );
val pos = Vector3f(0f, 0f, 0f)

sciView.addCone(pos,radius,height,color,20)
}
}
80 changes: 80 additions & 0 deletions src/main/kotlin/sc/iview/commands/edit/add/AddCylinder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*-
* #%L
* Scenery-backed 3D visualization package for ImageJ.
* %%
* Copyright (C) 2016 - 2021 SciView developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package sc.iview.commands.edit.add

import org.joml.Vector3f
import org.scijava.command.Command
import org.scijava.plugin.Menu
import org.scijava.plugin.Parameter
import org.scijava.plugin.Plugin
import org.scijava.util.ColorRGB
import sc.iview.SciView
import sc.iview.Utils
import sc.iview.commands.MenuWeights.EDIT
import sc.iview.commands.MenuWeights.EDIT_ADD
import sc.iview.commands.MenuWeights.EDIT_ADD_CYLINDER

/**
* Command to add a box to the scene
*
* @author Jan Tiemann
*/
@Plugin(
type = Command::class,
menuRoot = "SciView",
menu = [Menu(label = "Edit", weight = EDIT), Menu(label = "Add", weight = EDIT_ADD), Menu(
label = "Cylinder...",
weight = EDIT_ADD_CYLINDER
)]
)
class AddCylinder : Command {

@Parameter
private lateinit var sciView: SciView

// FIXME
// @Parameter
// private String position = "0; 0; 0";

@Parameter
private var height = 1.0f

@Parameter
private var radius = 1.0f

@Parameter
private var color: ColorRGB = SciView.DEFAULT_COLOR;

override fun run() {
//final Vector3 pos = ClearGLVector3.parse( position );
val pos = Vector3f(0f, 0f, 0f)

sciView.addCylinder(pos,radius,height,color,20)
}
}