This repository has been archived by the owner on Jul 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aakash Shah
committed
Jun 5, 2013
0 parents
commit cd09991
Showing
14 changed files
with
416 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="lib" path="interfacesdk-0.0.5-jar-with-dependencies.jar"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.classpath | ||
.project | ||
.settings/ | ||
.lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>SimpleModule</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/main/java=UTF-8 | ||
encoding//src/test/java=UTF-8 | ||
encoding/<project>=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 | ||
org.eclipse.jdt.core.compiler.compliance=1.5 | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.source=1.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<OpenNI> | ||
<Licenses> | ||
<!-- Add application-specific licenses here | ||
<License vendor="vendor" key="key"/> | ||
--> | ||
</Licenses> | ||
<Log writeToConsole="false" writeToFile="false"> | ||
<!-- 0 - Verbose, 1 - Info, 2 - Warning, 3 - Error (default) --> | ||
<LogLevel value="3"/> | ||
<Masks> | ||
<Mask name="ALL" on="true"/> | ||
</Masks> | ||
<Dumps> | ||
</Dumps> | ||
</Log> | ||
<ProductionNodes> | ||
<!-- Uncomment following line, in order to run from a recording | ||
<Recording file="sampleRec.oni" /> | ||
--> | ||
|
||
<!-- Set global mirror --> | ||
<GlobalMirror on="true"/> | ||
|
||
<!-- Create a depth node and give it a name alias (useful if referenced ahead in this script) --> | ||
<Node type="Depth" name="MyDepth"> | ||
<Query> | ||
<!-- Uncomment to filter by vendor name, product name, etc. | ||
<Vendor>MyVendor inc.</Vendor> | ||
<Name>MyProduct</Name> | ||
<MinVersion>1.2.3.4</MinVersion> | ||
<Capabilities> | ||
<Capability>Cropping</Capability> | ||
</Capabilities> | ||
--> | ||
</Query> | ||
<Configuration> | ||
<!-- Uncomment to set requested mode | ||
<MapOutputMode xRes="640" yRes="480" FPS="30"/> | ||
--> | ||
|
||
<!-- Uncomment to override global mirror | ||
<Mirror on="false" /> | ||
--> | ||
</Configuration> | ||
</Node> | ||
|
||
<!-- Create an image node. If it fails, continue anyway. --> | ||
<Node type="Image" stopOnError="false" /> | ||
|
||
<!-- Uncomment nodes from here if you need them.--> | ||
<!--<Node type="Audio" /> | ||
<Node type="User" />--> | ||
<Node type="Hands" /> | ||
<Node type="Gesture" /> | ||
<!-- | ||
<Node type="Scene" />--> | ||
</ProductionNodes> | ||
</OpenNI> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>edu.mines.aashah.modules</groupId> | ||
<artifactId>SimpleModule</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>SimpleModule</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<url>https://s3-us-west-2.amazonaws.com/jar.download.andrewdemaria.com/libs</url> | ||
<id>additional_libraries</id> | ||
</repository> | ||
<repository> | ||
<url>https://s3-us-west-2.amazonaws.com/acmx.mines.edu/release</url> | ||
<id>interface_sdk_library</id> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>processing</groupId> | ||
<artifactId>core</artifactId> | ||
<version>1.5.1</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.OpenNI</groupId> | ||
<artifactId>OpenNI</artifactId> | ||
<version>1.5.4.0</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
205 changes: 205 additions & 0 deletions
205
src/main/java/edu/mines/aashah/modules/SimpleModule/SimpleModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
package edu.mines.aashah.modules.SimpleModule; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.nio.ByteBuffer; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import processing.core.PApplet; | ||
import processing.core.PConstants; | ||
import processing.core.PImage; | ||
import edu.mines.acmX.exhibit.input_services.events.HandReceiver; | ||
import edu.mines.acmX.exhibit.input_services.hardware.BadFunctionalityRequestException; | ||
import edu.mines.acmX.exhibit.input_services.hardware.DeviceConnectionException; | ||
import edu.mines.acmX.exhibit.input_services.hardware.HardwareManager; | ||
import edu.mines.acmX.exhibit.input_services.hardware.HardwareManagerManifestException; | ||
import edu.mines.acmX.exhibit.input_services.hardware.devicedata.HandTrackerInterface; | ||
import edu.mines.acmX.exhibit.input_services.hardware.devicedata.RGBImageInterface; | ||
import edu.mines.acmX.exhibit.module_management.modules.ProcessingModule; | ||
import edu.mines.acmX.exhibit.stdlib.graphics.Coordinate3D; | ||
import edu.mines.acmX.exhibit.stdlib.graphics.HandPosition; | ||
import edu.mines.acmX.exhibit.stdlib.input_processing.imaging.RGBImageUtilities; | ||
|
||
/** | ||
* A simple module example to demonstrate communicating with the | ||
* HardwareManager all managing received events within a ProcessingModule | ||
* | ||
* @author Aakash Shah | ||
* | ||
* @see {@link HardwareManager} {@link ProcessingModule} | ||
*/ | ||
public class SimpleModule extends ProcessingModule { | ||
|
||
public static HardwareManager hm; | ||
|
||
private RGBImageInterface imageDriver; | ||
private HandTrackerInterface handDriver; | ||
private MyHandReceiver receiver; | ||
|
||
/* | ||
* A processing module inherits the paradigms of a Processing applet. Here, | ||
* we implement the setup method that acts as an entry point for our module. | ||
* As such, we initialize a lot of our member variables and register for | ||
* events here. | ||
*/ | ||
public void setup() { | ||
/* | ||
* The hardware manager is a singleton that forms a bridge to | ||
* retrieve and communicate with drivers supported (as specified in the | ||
* HardwareManager manifest file). | ||
* | ||
* The actual creation of the manager | ||
* involves loading and verifying the integrity of the manifest file, | ||
* as well as ensuring that a device is connected so that we may | ||
* actually obtain information from it. | ||
*/ | ||
try { | ||
hm = HardwareManager.getInstance(); | ||
} catch (HardwareManagerManifestException e) { | ||
System.out.println("Error in the HardwareManager manifest file."); | ||
e.printStackTrace(); | ||
} catch (DeviceConnectionException e) { | ||
System.out.println( "No devices are currently connected to " + | ||
"retrieve data from."); | ||
e.printStackTrace(); | ||
} | ||
|
||
/* | ||
* To actually retrieve the driver, such that we can receive | ||
* information, requires requesting it from our instance of the | ||
* HardwareManager. | ||
* | ||
* In this case, we want to set the size to be the same as the rgbimage | ||
* we are going to receive from the driver. | ||
*/ | ||
try { | ||
imageDriver = (RGBImageInterface) hm.getInitialDriver("rgbimage"); | ||
size(imageDriver.getRGBImageWidth(), imageDriver.getRGBImageHeight()); | ||
handDriver = (HandTrackerInterface) hm.getInitialDriver("handtracking"); | ||
} catch (BadFunctionalityRequestException e) { | ||
System.out.println("Functionality unknown (may not be supported)"); | ||
e.printStackTrace(); | ||
} | ||
|
||
/* | ||
* This creates a "MyHandReceiver" instance that acts a layer of | ||
* abstraction towards dealing with data received by the event manager. | ||
*/ | ||
receiver = new MyHandReceiver(); | ||
/* | ||
* Since hand tracking takes an event-based approach towards delivering | ||
* information, we should register our receiver with the EventManager. | ||
* In this case, this is done through the driver. However, we can also | ||
* do it alternatively with: | ||
* | ||
* EventManager.getInstance().registerReceiver(EventType.HAND_CREATED, receiver); | ||
*/ | ||
handDriver.registerHandCreated(receiver); | ||
handDriver.registerHandUpdated(receiver); | ||
handDriver.registerHandDestroyed(receiver); | ||
|
||
} | ||
|
||
public void draw() { | ||
/* | ||
* For some hand tracking drivers, it may be necessary to allow it to | ||
* refresh information before re-polling for new data. | ||
*/ | ||
handDriver.updateDriver(); | ||
|
||
/* | ||
* The RGBImageInterface provides getVisualData() as a method to | ||
* retrieve the raw data from a driver that supports the "rgbimage" | ||
* functionality. | ||
* | ||
* Here we grab this ByteBuffer, convert it into a BufferedImage, and | ||
* then finally into a PImage (Processing's form of an image) so that | ||
* we may display it on the screeen. | ||
*/ | ||
ByteBuffer rawRGBImageData = imageDriver.getVisualData(); | ||
BufferedImage bImg = RGBImageUtilities.byteBufferToImage( | ||
rawRGBImageData, | ||
imageDriver.getRGBImageWidth(), | ||
imageDriver.getRGBImageHeight()); | ||
PImage pImg = buffImageToPImage(bImg); | ||
image(pImg, 0, 0); | ||
|
||
noFill(); | ||
stroke(255, 0, 0); | ||
/* | ||
* To actually display a circle indicated the latest position for a | ||
* hand, we must first ask our receiver (which in our example is | ||
* keeping track of each hand's latest position) for the hand IDs that | ||
* it is tracking. | ||
* | ||
* Scroll down to read more about this example's receiver object. | ||
*/ | ||
for (int id : receiver.getHandIDs()) { | ||
/* | ||
* We grab the latest position and draw a red circle which will | ||
* follow the hand. Keep in the mind that we are retrieving a | ||
* Coordinate3D, so that should we want to incorporate the depth of | ||
* the hand into our module, we may do so. | ||
*/ | ||
Coordinate3D handPosition = receiver.getHandPosition(id); | ||
ellipse(handPosition.getX(), handPosition.getY(), 20, 20); | ||
} | ||
} | ||
|
||
/** | ||
* A utility function to convert a BufferedImage into a PImage. | ||
* @param bimg BufferedImage to convert | ||
* @return a PImage | ||
*/ | ||
public PImage buffImageToPImage(BufferedImage bimg) { | ||
PImage img = new PImage(bimg.getWidth(), bimg.getHeight(), PConstants.ARGB); | ||
bimg.getRGB(0, 0, img.width, img.height, img.pixels, 0, img.width); | ||
return img; | ||
} | ||
|
||
|
||
/** | ||
* This class acts as an extension of the HandReceiver adapter. In this | ||
* class, we may override the methods handCreated, handUpdated, and | ||
* handDestroyed to handle the lifecycle of a hand being tracked. | ||
* | ||
* In this example, we also include functionality to keep track of a hand's | ||
* most recent position. | ||
* | ||
* The hand tracking API provides the end-programmer an integer id, and | ||
* a Coordinate3D to manage the position of the hand. These two attributes | ||
* are wrapped into the class HandPosition which will allow you to grab | ||
* this information through getters. | ||
* | ||
* @author Aakash Shah | ||
*/ | ||
class MyHandReceiver extends HandReceiver { | ||
|
||
private Map<Integer, Coordinate3D> handPositions; | ||
|
||
public MyHandReceiver() { | ||
handPositions = new HashMap<Integer, Coordinate3D>(); | ||
} | ||
|
||
public void handCreated(HandPosition handPos) { | ||
handPositions.put(handPos.id, handPos.position); | ||
} | ||
|
||
public void handUpdated(HandPosition handPos) { | ||
handPositions.put(handPos.id, handPos.position); | ||
} | ||
|
||
public void handDestroyed(int id) { | ||
handPositions.remove(id); | ||
} | ||
|
||
public Set<Integer> getHandIDs() { | ||
return handPositions.keySet(); | ||
} | ||
|
||
public Coordinate3D getHandPosition(int id) { | ||
return handPositions.get(id); | ||
} | ||
} | ||
} |
Oops, something went wrong.