package org.openrndr.extra.kinect import org.openrndr.Extension import org.openrndr.draw.* import org.openrndr.resourceUrl import java.lang.RuntimeException /** * Represents all the accessible kinects handled by a specific driver (V1, V2). * * @param data needed to make low level kinect support calls. */ interface Kinects { fun countDevices(): Int /** * Starts kinect device of a given number. * * @param num the kinect device index (starts with 0). If no value specified, * it will default to 0. * @throws KinectException if device of such a number does not exist * (better to count them first), or it was already started. * @see countDevices */ fun startDevice(num: Int = 0): KinectDevice /** * Executes low level Kinect commands in the kinect thread. */ fun execute(commands: (CTX) -> T) : T } /** * Represents specific device. * * @param CTX type of data needed to make low level kinect support calls (e.g. freenect contexts). */ interface KinectDevice : Extension { val depthCamera: KinectDepthCamera /** * Executes low level Kinect commands in the kinect thread in the context of this device. */ fun execute(commands: (CTX) -> T): T } interface KinectCamera { var enabled: Boolean val width: Int val height: Int var mirror: Boolean val currentFrame: ColorBuffer /** * Returns the latest frame, but only once. Useful for the scenarios * where each new frame triggers extra computation. Therefore the same * expensive operation might happen only once, especially when the refresh * rate of the target screen is higher than kinect's 30 fps. *

* Example usage: *

     * kinect.depthCamera.getLatestFrame()?.let { frame ->
     *     grayscaleFilter.apply(frame, grayscaleBuffer)
     * }
     * 
*/ fun getLatestFrame(): ColorBuffer? } interface KinectDepthCamera : KinectCamera { /* no special attributes at the moment */ } class KinectException(msg: String) : RuntimeException(msg) /** * Maps depth values to grayscale. */ class DepthToGrayscaleMapper : Filter( filterShaderFromUrl(resourceUrl("depth-to-grayscale.frag", Kinects::class)) ) /** * Maps depth values to color map according to natural light dispersion as described * by Alan Zucconi in the * Improving the Rainbow * article. */ class DepthToColorsZucconi6Mapper : Filter( filterShaderFromUrl(resourceUrl("depth-to-colors-zucconi6.frag", Kinects::class)) ) /** * Maps depth values to color map according to * * Turbo, An Improved Rainbow Colormap for Visualization * * by Google. */ class DepthToColorsTurboMapper : Filter( filterShaderFromUrl(resourceUrl("depth-to-colors-turbo.frag", Kinects::class)) )