Skip to content
Browse files

Refactored code.

  • Loading branch information...
1 parent 07fe258 commit e6c254410d7b6ae7e1f6d36afa0471308d3e9745 @ushadow committed Dec 3, 2012
View
1 src/edu/mit/yingyin/tabletop/apps/HandTrackingApp.java
@@ -26,6 +26,7 @@
import edu.mit.yingyin.tabletop.models.HandTrackingEngine;
import edu.mit.yingyin.tabletop.models.HandTrackingEngine.IHandEventListener;
import edu.mit.yingyin.tabletop.models.InteractionSurface;
+import edu.mit.yingyin.tabletop.views.Table3DFrame;
import edu.mit.yingyin.util.CommandLineOptions;
import edu.mit.yingyin.util.FileUtil;
import edu.mit.yingyin.util.ObjectIO;
View
19 src/edu/mit/yingyin/tabletop/models/DiecticGestureHandler.java
@@ -14,18 +14,28 @@
*
*/
public class DiecticGestureHandler {
+
public List<Point3f> update(List<Forelimb> forelimbs) {
InteractionSurface is = InteractionSurface.instance();
List<Point3f> res = new ArrayList<Point3f>();
if (is == null)
return res;
for (Forelimb fl : forelimbs) {
-
+ Point3f p = computeIntersection(fl, is);
+ if (p != null) {
+ res.add(p);
+ }
}
return res;
}
+ /**
+ *
+ * @param fl
+ * @param is
+ * @return null if there is no fingertip or arm joint in {@code fl}.
+ */
private Point3f computeIntersection(Forelimb fl, InteractionSurface is) {
if (fl.numFingertips() <= 0)
return null;
@@ -37,7 +47,10 @@ private Point3f computeIntersection(Forelimb fl, InteractionSurface is) {
if (armJoint == null)
return null;
- return Geometry.linePlaneIntersection(armJoint, fingertip, is.center(),
- is.surfaceNormal());
+ if (is.center().isNone())
+ return null;
+
+ return Geometry.linePlaneIntersection(armJoint, fingertip,
+ is.center().value(), is.surfaceNormal());
}
}
View
1 src/edu/mit/yingyin/tabletop/models/HandTracker.java
@@ -57,6 +57,7 @@ public String toString() {
/** True if finger is pressed, false otherwise. */
private boolean pressed = false;
private CalibModel calibExample;
+ private DiecticGestureHandler dgh = new DiecticGestureHandler();
public HandTracker(CalibModel calibExample) {
this.calibExample = calibExample;
View
12 src/edu/mit/yingyin/tabletop/models/InteractionSurface.java
@@ -18,6 +18,9 @@
import com.googlecode.javacv.cpp.opencv_core.CvMat;
import edu.mit.yingyin.util.Geometry;
+import edu.mit.yingyin.util.Option;
+import edu.mit.yingyin.util.Option.None;
+import edu.mit.yingyin.util.Option.Some;
/**
* Model of a tabletop.
@@ -133,8 +136,13 @@ public Vector3f surfaceNormal() {
return surfaceNormal == null ? null : new Vector3f(surfaceNormal);
}
- public Point3f center() {
- return center == null ? null : new Point3f(center);
+ /**
+ * Returns the optional center of the interface in the world coordinates.
+ * @return a new point of the center of the interface.
+ */
+ public Option<Point3f> center() {
+ return center == null ? new None<Point3f>() :
+ new Some<Point3f>(new Point3f(center));
}
/**
View
20 ...t/yingyin/tabletop/apps/Table3DFrame.java → .../yingyin/tabletop/views/Table3DFrame.java
@@ -1,4 +1,4 @@
-package edu.mit.yingyin.tabletop.apps;
+package edu.mit.yingyin.tabletop.views;
import java.awt.BorderLayout;
import java.awt.Color;
@@ -160,6 +160,10 @@ private void startDrawing() {
}
private void getScene() {
+ if (table.center().isNone())
+ return;
+
+ Point3f tableCenter = table.center().value();
addLights(scene);
frontImage = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT,
@@ -172,15 +176,15 @@ private void getScene() {
axesTransformGroup.addChild(createAxesGroup());
Transform3D axesTransform = new Transform3D();
axesTransform.setScale(200);
- axesTransform.setTranslation(new Vector3f(0, 0, table.center().z + 100));
+ axesTransform.setTranslation(new Vector3f(0, 0, tableCenter.z + 100));
axesTransformGroup.setTransform(axesTransform);
-
- worldTransformGroup.addChild(createTable());
+ Group tableGroup = createTable();
+ if (tableGroup != null)
+ worldTransformGroup.addChild(tableGroup);
worldTransformGroup.addChild(axesTransformGroup);
MouseRotate behavior = new MouseRotate();
- BoundingSphere bounds = new BoundingSphere(new Point3d(table.center()),
- 1200);
+ BoundingSphere bounds = new BoundingSphere(new Point3d(tableCenter), 1200);
behavior.setSchedulingBounds(bounds);
behavior.setTransformGroup(worldTransformGroup);
worldTransformGroup.addChild(behavior);
@@ -191,7 +195,9 @@ private void getScene() {
}
private Group createTable() {
- Point3f center = table.center();
+ if (table.center().isNone())
+ return null;
+ Point3f center = table.center().value();
Vector3f n = table.surfaceNormal();
Point3f p1 = Geometry.pointOnPlaneZ(center.x + TABLE_WIDTH / 2,
center.y + TABLE_HEIGHT / 2, center, n);

0 comments on commit e6c2544

Please sign in to comment.
Something went wrong with that request. Please try again.