Skip to content

Commit

Permalink
Unified naming scheme, extracted tracking functionality into separate…
Browse files Browse the repository at this point in the history
… classes
  • Loading branch information
smlpt committed Oct 11, 2024
1 parent 6d93dc0 commit 9cafe64
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 174 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package sc.iview.commands.demo.advanced

import graphics.scenery.*
import org.joml.*
import org.scijava.command.Command
import org.scijava.command.CommandService
import org.scijava.plugin.Menu
import org.scijava.plugin.Parameter
import org.scijava.plugin.Plugin
import sc.iview.SciView
import sc.iview.commands.MenuWeights
import java.util.HashMap

@Plugin(
type = Command::class,
menuRoot = "SciView",
menu = [Menu(label = "Demo", weight = MenuWeights.DEMO),
Menu(label = "Advanced", weight = MenuWeights.DEMO_ADVANCED),
Menu(label = "Utilize Eye Tracker for Cell Tracking", weight = MenuWeights.DEMO_ADVANCED_EYETRACKING)]
)
/**
* Command class that forwards to the [EyeTracking] class to perform the actual tracking and analysis.
*/
class EyeTrackingCommand : Command {

@Parameter
var mastodonCallbackLinkCreate: ((HedgehogAnalysis.SpineGraphVertex) -> Unit)? = null

@Parameter
var mastodonUpdateGraph: (() -> Unit)? = null

@Parameter
private lateinit var sv: SciView

override fun run() {
// the actual eye tracking logic happens in here
val eyeTracking = EyeTracking(mastodonCallbackLinkCreate, mastodonUpdateGraph, sv)
eyeTracking.run()
}

companion object {

@Throws(Exception::class)
@JvmStatic
fun main(args: Array<String>) {
val sv = SciView.create()
val command = sv.scijavaContext!!.getService(CommandService::class.java)
val argmap = HashMap<String, Any>()
argmap["sv"] = sv
command.run(EyeTrackingCommand::class.java, true, argmap)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,21 @@ import graphics.scenery.utils.extensions.xyz
import graphics.scenery.utils.extensions.xyzw
import graphics.scenery.volumes.Volume
import org.joml.*
import org.scijava.command.Command
import org.scijava.command.CommandService
import org.scijava.plugin.Menu
import org.scijava.plugin.Plugin
import sc.iview.SciView
import sc.iview.commands.MenuWeights
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
import java.text.DecimalFormat
import kotlin.concurrent.thread

@Plugin(type = Command::class,
menuRoot = "SciView",
menu = [Menu(label = "Demo", weight = MenuWeights.DEMO),
Menu(label = "Advanced", weight = MenuWeights.DEMO_ADVANCED),
Menu(label = "Test without VR and Eye Tracker", weight = MenuWeights.DEMO_ADVANCED_EYETRACKING)])
class Test: Command, CellTrackingBase() {
/**
* A class to test to show tracks and perform track analysis from saved CSV tracking files without
* the requirement of a VR headset.
*/
class TrackingTest(
sciview: SciView
): CellTrackingBase(sciview) {

//val calibrationTarget = Icosphere(0.02f, 2)
val TestTarget = Icosphere(0.1f, 2)
Expand All @@ -43,7 +40,7 @@ class Test: Command, CellTrackingBase() {

// var currentVolume = 0

override fun run() {
fun run() {

sciview.addNode(TestTarget)
TestTarget.visible = false
Expand Down Expand Up @@ -117,7 +114,7 @@ class Test: Command, CellTrackingBase() {
inputSetup()
}

launchHedgehogThread()
launchUpdaterThread()
}

override fun inputSetup()
Expand Down Expand Up @@ -295,16 +292,4 @@ class Test: Command, CellTrackingBase() {
}
}
}

companion object {

@Throws(Exception::class)
@JvmStatic
fun main(args: Array<String>) {
val sv = SciView.create()
val command = sv.scijavaContext!!.getService(CommandService::class.java)
val argmap = HashMap<String, Any>()
command.run(EyeTrackingDemo::class.java, true, argmap)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package sc.iview.commands.demo.advanced

import org.scijava.command.Command
import org.scijava.command.CommandService
import org.scijava.plugin.Menu
import org.scijava.plugin.Parameter
import org.scijava.plugin.Plugin
import sc.iview.SciView
import sc.iview.commands.MenuWeights

@Plugin(type = Command::class,
menuRoot = "SciView",
menu = [Menu(label = "Demo", weight = MenuWeights.DEMO),
Menu(label = "Advanced", weight = MenuWeights.DEMO_ADVANCED),
Menu(label = "Test without VR and Eye Tracker", weight = MenuWeights.DEMO_ADVANCED_EYETRACKING)])
class TrackingTestCommand: Command {

@Parameter
private lateinit var sv: SciView

override fun run() {
val test = TrackingTest(sv)
test.run()
}

companion object {

@Throws(Exception::class)
@JvmStatic
fun main(args: Array<String>) {
val sv = SciView.create()
val command = sv.scijavaContext!!.getService(CommandService::class.java)
val argmap = HashMap<String, Any>()
argmap["sv"] = sv
command.run(TrackingTestCommand::class.java, true, argmap)
}
}

}
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
package sc.iview.commands.demo.advanced

import graphics.scenery.*
import graphics.scenery.attribute.material.Material
import graphics.scenery.controls.OpenVRHMD
import graphics.scenery.controls.TrackedDevice
import graphics.scenery.controls.TrackedDeviceType
import graphics.scenery.primitives.Cylinder
import graphics.scenery.primitives.TextBoard
import graphics.scenery.utils.SystemHelpers
import graphics.scenery.utils.extensions.minus
import graphics.scenery.utils.extensions.xyz
import graphics.scenery.utils.extensions.xyzw
import graphics.scenery.volumes.Volume
import org.joml.*
import org.scijava.command.Command
import org.scijava.command.CommandService
import org.scijava.plugin.Menu
import org.scijava.plugin.Plugin
import org.joml.Matrix4f
import org.joml.Vector3f
import org.scijava.ui.behaviour.ClickBehaviour
import sc.iview.SciView
import sc.iview.commands.MenuWeights
import java.nio.file.Files
import java.nio.file.Paths
import java.util.HashMap
import kotlin.concurrent.thread
import graphics.scenery.attribute.material.Material
import graphics.scenery.controls.*
import graphics.scenery.primitives.Cylinder
import graphics.scenery.primitives.TextBoard

@Plugin(type = Command::class,
menuRoot = "SciView",
menu = [Menu(label = "Demo", weight = MenuWeights.DEMO),
Menu(label = "Advanced", weight = MenuWeights.DEMO_ADVANCED),
Menu(label = "Utilize VR Controller for Cell Tracking", weight = MenuWeights.DEMO_ADVANCED_EYETRACKING)])
class VRControllerTrackingDemo: Command, CellTrackingBase() {

/**
* This class utilizes VR controllers to track cells in volumetric datasets in a sciview environment.
*/
class VRControllerTracking(
sciview: SciView
): CellTrackingBase(sciview) {

val testTarget1 = Icosphere(0.01f, 2)
val testTarget2 = Icosphere(0.04f, 2)
Expand All @@ -40,7 +38,7 @@ class VRControllerTrackingDemo: Command, CellTrackingBase() {

// var currentVolume = 0

override fun run() {
fun run() {

sciview.toggleVRRendering()
hmd = sciview.hub.getWorkingHMD() as? OpenVRHMD ?: throw IllegalStateException("Could not find headset")
Expand Down Expand Up @@ -126,7 +124,7 @@ class VRControllerTrackingDemo: Command, CellTrackingBase() {
setupControllerforTracking()
}

launchHedgehogThread()
launchUpdaterThread()
}

private fun setupControllerforTracking( keybindingTracking: String = "U") {
Expand Down Expand Up @@ -196,25 +194,8 @@ class VRControllerTrackingDemo: Command, CellTrackingBase() {
addSpine(headCenter, direction, volume,0.8f, volume.viewerState.currentTimepoint)
}
}

}

}

}


}

companion object {

@Throws(Exception::class)
@JvmStatic
fun main(args: Array<String>) {
val sv = SciView.create()
val command = sv.scijavaContext!!.getService(CommandService::class.java)
val argmap = HashMap<String, Any>()
command.run(EyeTrackingDemo::class.java, true, argmap)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,72 +1,55 @@
package sc.iview.commands.demo.advanced

import graphics.scenery.*
import graphics.scenery.controls.OpenVRHMD
import graphics.scenery.controls.TrackedDeviceType
import graphics.scenery.controls.eyetracking.PupilEyeTracker
import graphics.scenery.textures.Texture
import graphics.scenery.utils.SystemHelpers
import graphics.scenery.utils.extensions.minus
import graphics.scenery.utils.extensions.xyz
import graphics.scenery.utils.extensions.xyzw
import graphics.scenery.volumes.Volume
import net.imglib2.type.numeric.integer.UnsignedByteType
import org.joml.*
import org.scijava.command.Command
import org.scijava.command.CommandService
import org.scijava.plugin.Menu
import org.scijava.plugin.Parameter
import org.scijava.plugin.Plugin
import org.scijava.ui.behaviour.ClickBehaviour
import sc.iview.SciView
import sc.iview.commands.MenuWeights
import java.awt.image.DataBufferByte
import java.io.ByteArrayInputStream
import java.nio.file.Files
import java.nio.file.Paths
import java.util.HashMap
import javax.imageio.ImageIO
import kotlin.concurrent.thread
import kotlin.math.PI
import graphics.scenery.attribute.material.Material
import graphics.scenery.controls.*
import graphics.scenery.primitives.Cylinder
import graphics.scenery.primitives.TextBoard
import org.scijava.plugin.Parameter

@Plugin(type = Command::class,
menuRoot = "SciView",
menu = [Menu(label = "Demo", weight = MenuWeights.DEMO),
Menu(label = "Advanced", weight = MenuWeights.DEMO_ADVANCED),
Menu(label = "Utilize Eye Tracker for Cell Tracking", weight = MenuWeights.DEMO_ADVANCED_EYETRACKING)])
/**
* Command class that forwards to the [EyeTracking] class to perform the actual tracking and analysis.
*/
class EyeTrackingDemo: Command {

@Parameter
var mastodonCallbackLinkCreate: ((HedgehogAnalysis.SpineGraphVertex) -> Unit)? = null

@Parameter
var mastodonUpdateGraph: (() -> Unit)? = null
@Plugin(
type = Command::class,
menuRoot = "SciView",
menu = [Menu(label = "Demo", weight = MenuWeights.DEMO),
Menu(label = "Advanced", weight = MenuWeights.DEMO_ADVANCED),
Menu(label = "Utilize VR Controller for Cell Tracking", weight = MenuWeights.DEMO_ADVANCED_EYETRACKING)]
)
class VRControllerTrackingCommand : Command {

@Parameter
private lateinit var sv: SciView

override fun run() {
// the actual eye tracking logic happens in here
val eyeTracking = EyeTracking(mastodonCallbackLinkCreate, mastodonUpdateGraph, sv)
eyeTracking.run()
val tracking = VRControllerTracking(sv)
tracking.run()
}

companion object {

@Throws(Exception::class)
@JvmStatic
fun main(args: Array<String>) {
val sv = SciView.create()
val command = sv.scijavaContext!!.getService(CommandService::class.java)
val argmap = HashMap<String, Any>()
argmap["sv"] = sv
command.run(EyeTrackingDemo::class.java, true, argmap)
command.run(VRControllerTrackingCommand::class.java, true, argmap)
}
}
}
Loading

0 comments on commit 9cafe64

Please sign in to comment.