Commit 5ce6383e authored by Nicolas Gilmard's avatar Nicolas Gilmard

Fix issue #18 : inconsitent path assinment

parent 16ba572e
......@@ -13,10 +13,10 @@
<attribute name="javadoc_location" value="jar:platform:/resource/TUI%20Framework/libs/guava-15.0-javadoc.jar!/"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="libs/tuio-1.4.jar" sourcepath="C:/Users/tobias/.m2/repository/net/sourceforge/tuio/tuio/1.4/tuio-1.4-sources.jar"/>
<classpathentry exported="true" kind="lib" path="libs/dbc.annotation.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="libs/bluecove-2.1.1-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="libs/RXTXcomm.jar"/>
<classpathentry kind="lib" path="libs/libTUIO.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
......@@ -51,6 +51,9 @@ public abstract class TangibleObjectManager {
/** This dictionary stores all cursors detected by reacTIVision. */
protected volatile static ConcurrentHashMap<Integer, BaseWidget> cursorList = new ConcurrentHashMap<>();
/** This dictionary stores all blobs detected by reacTIVision. */
protected volatile static ConcurrentHashMap<Integer, BaseWidget> blobList = new ConcurrentHashMap<>();
/** A {@link Logger} to log all messages during execution. */
protected Logger logger;
......@@ -180,6 +183,12 @@ public abstract class TangibleObjectManager {
}
break;
case BLOB:
blobList.putIfAbsent(tangibleObject.getObjectId(), new BaseWidgetBuilder().withCorona(tangibleObject.getObjectId(), new ShadowBuilder(new Point()).withShape(ShapeFactory.buildCircle(5)).build()).build());
blobList.get(tangibleObject.getObjectId()).actionDrop(tangibleObject);
ensureConsistency();
default:
logger.log(Level.WARNING, "The recognised symbol was not assigned to a widget!"); //$NON-NLS-1$
break;
......@@ -211,7 +220,10 @@ public abstract class TangibleObjectManager {
logger.log(Level.WARNING, "The recognised symbol was not assigned to a widget!"); //$NON-NLS-1$
}
break;
case BLOB:
if (blobList.containsKey(tangibleObject.getObjectId())) {
blobList.remove(tangibleObject.getObjectId()).actionLift(tangibleObject);
}
default:
logger.log(Level.WARNING, "The recognised symbol was not assigned to a widget!"); //$NON-NLS-1$
break;
......@@ -243,6 +255,12 @@ public abstract class TangibleObjectManager {
logger.log(Level.WARNING, "The recognised symbol was not assigned to a widget!"); //$NON-NLS-1$
}
break;
case BLOB:
if (blobList.containsKey(tangibleObject.getObjectId())) {
blobList.get(tangibleObject.getObjectId()).actionMove(tangibleObject);
} else {
logger.log(Level.WARNING, "The blob could not be recognised!"); //$NON-NLS-1$
}
default:
logger.log(Level.WARNING, "The recognised symbol was not assigned to a widget!"); //$NON-NLS-1$
break;
......
......@@ -18,7 +18,7 @@ import lu.list.itis.dkd.tui.utility.Point;
import lu.tudor.ssi.kiss.dbc.annotation.NonNullByDefault;
import java.util.Vector;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -40,7 +40,10 @@ public class TangibleObject {
* Type denoting that the object is a cursor, most likely a finger or pen used to manipulate
* the interface.
*/
CURSOR
CURSOR,
/** Type denoting that the object is any untagged generic object */
BLOB
}
/** A {@link Logger} to log all messages during execution. */
......@@ -77,7 +80,7 @@ public class TangibleObject {
protected float rotationAccel;
/** A Vector of {@link Point} containing all the previous positions of the tangible object. */
protected Vector<Point> path;
protected ArrayList<Point> path;
/** Reflects the current state of the {@link TangibleObject} */
protected State state;
......@@ -123,6 +126,15 @@ public class TangibleObject {
}
}
/** The width value. */
protected float width;
/** The height value. */
protected float height;
/** The area value. */
protected float area;
/**
* Default constructor
......@@ -162,7 +174,7 @@ public class TangibleObject {
* @return the x coordinates of the object.
*/
public float getX() {
return (float) path.lastElement().getX();
return (float) path.get(path.size() - 1).getX();
}
/**
......@@ -171,7 +183,7 @@ public class TangibleObject {
* @return the y coordinates of the object.
*/
public float getY() {
return (float) path.lastElement().getY();
return (float) path.get(path.size() - 1).getY();
}
/**
......@@ -180,7 +192,7 @@ public class TangibleObject {
* @return The value of angle.
*/
public float getAngle() {
return path.lastElement().getAngle();
return path.get(path.size() - 1).getAngle();
}
/**
......@@ -368,7 +380,7 @@ public class TangibleObject {
*
* @return the path of the object
*/
public Vector<Point> getPath() {
public ArrayList<Point> getPath() {
return path;
}
......@@ -377,7 +389,7 @@ public class TangibleObject {
*
* @param path
*/
public void setPath(Vector<Point> path) {
public void setPath(ArrayList<Point> path) {
this.path = path;
}
......@@ -405,4 +417,61 @@ public class TangibleObject {
public void setState(int state) {
this.state = State.getState(state);
}
/**
* Simple getter method for width.
*
* @return The value of width.
*/
public float getWidth() {
return width;
}
/**
* Simple setter method for width.
*
* @param width
* The value to set width to.
*/
public void setWidth(float width) {
this.width = width;
}
/**
* Simple getter method for height.
*
* @return The value of height.
*/
public float getHeight() {
return height;
}
/**
* Simple setter method for height.
*
* @param height
* The value to set height to.
*/
public void setHeight(float height) {
this.height = height;
}
/**
* Simple getter method for area.
*
* @return The value of area.
*/
public float getArea() {
return area;
}
/**
* Simple setter method for area.
*
* @param area
* The value to set area to.
*/
public void setArea(float area) {
this.area = area;
}
}
......@@ -19,7 +19,7 @@ import lu.list.itis.dkd.tui.utility.Point;
import lu.tudor.ssi.kiss.dbc.annotation.NonNullByDefault;
import java.util.Vector;
import java.util.ArrayList;
/**
* REFACTORED Method names should be refactored due to them not being additions as suggested. Use
......@@ -66,10 +66,19 @@ public class TangibleObjectBuilder {
/** The rotation acceleration value. */
protected float rotationAccel = 0;
/** The width value. */
protected float width = 0;
/** The height value. */
protected float height = 0;
/** The area value. */
protected float area = 0;
/**
* A Vector of {@link Point} containing all the previous positions of the tangible object.
*/
protected Vector<Point> path = new Vector<>();
protected ArrayList<Point> path = new ArrayList<>();
/** Reflects the current state of the {@link TangibleObject} */
protected State state = TangibleObject.State.ADDED;
......@@ -88,7 +97,7 @@ public class TangibleObjectBuilder {
public TangibleObjectBuilder(int objectId, Type type, float x, float y) {
this.objectId = objectId;
this.type = type;
path.addElement(new Point(x, y, 0));
path.add(new Point(x, y, 0));
}
......@@ -196,7 +205,7 @@ public class TangibleObjectBuilder {
* object.
* @return An instance of the builder for chain calling.
*/
public TangibleObjectBuilder withPath(Vector<Point> path) {
public TangibleObjectBuilder withPath(ArrayList<Point> path) {
this.path = path;
return this;
}
......@@ -222,6 +231,42 @@ public class TangibleObjectBuilder {
return this;
}
/**
* Method for adding width to the tangible object
*
* @param width
* The width value.
* @return An instance of the builder for chain calling.
*/
public TangibleObjectBuilder withWidth(float width) {
this.width = width;
return this;
}
/**
* Method for adding height to the tangible object
*
* @param height
* The height value.
* @return An instance of the builder for chain calling.
*/
public TangibleObjectBuilder withHeight(float height) {
this.height = height;
return this;
}
/**
* Method for adding area to the tangible object
*
* @param area
* The area value.
* @return An instance of the builder for chain calling.
*/
public TangibleObjectBuilder withArea(float area) {
this.area = area;
return this;
}
/**
* Method for building a {@link TangibleObject} with the values set by the builder.
*
......
......@@ -23,6 +23,7 @@ import lu.list.itis.dkd.tui.utility.Point;
import lu.tudor.ssi.kiss.dbc.annotation.NonNullByDefault;
import lu.tudor.ssi.kiss.dbc.annotation.Nullable;
import TUIO.TuioBlob;
import TUIO.TuioClient;
import TUIO.TuioCursor;
import TUIO.TuioListener;
......@@ -31,8 +32,10 @@ import TUIO.TuioTime;
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
/**
* Adapter class managing interaction with reacTIVision tangible table using TUIO protocol.
......@@ -55,6 +58,9 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
*/
protected TangibleObjectManager objectManager;
/** This dictionary stores all the objects detected by reacTIVision */
protected volatile static ConcurrentHashMap<Integer, TangibleObject> tangibleObjectList = new ConcurrentHashMap<>();
/**
* Constructor initialising several fields and setting up the interfaceManager for refresh.
*
......@@ -121,12 +127,23 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
*/
private TangibleObject convertTuioObjectToTangibleObject(TuioObject tuioObject) {
Preconditions.checkArgument(tuioObject != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$
Vector<Point> tempPath = new Vector<>();
tuioObject.getPath().forEach(path -> tempPath.addElement(new Point(path.getX(), path.getY(), tuioObject.getAngle())));
// path.getAngle(tuioObject)
TangibleObject convertedTangibleObject = new TangibleObjectBuilder(tuioObject.getSymbolID(), Type.OBJECT, tuioObject.getPath().lastElement().getX(), tuioObject.getPath().lastElement().getY()).withSeconds(tuioObject.getTuioTime().getSeconds()).withMicroSeconds(tuioObject.getTuioTime().getMicroseconds()).withxSpeed(tuioObject.getXSpeed()).withySpeed(tuioObject.getYSpeed()).withMotionSpeed(tuioObject.getMotionSpeed()).withMotionAccel(tuioObject.getMotionAccel()).withRotationSpeed(tuioObject.getRotationSpeed()).withRotationAccel(tuioObject.getRotationAccel()).withPath(tempPath).withState(tuioObject.getTuioState()).build();
// get the object if present
TangibleObject updateObject = tangibleObjectList.get(tuioObject.getSymbolID()) != null ? tangibleObjectList.get(tuioObject.getSymbolID()) : null;
TangibleObject convertedTangibleObject;
if (updateObject == null) {
// if the object is not present simply convert the tuioPath
ArrayList<Point> tempPath = new ArrayList<>();
tuioObject.getPath().forEach(path -> tempPath.add(new Point(path.getX(), path.getY(), tuioObject.getAngle())));
convertedTangibleObject = new TangibleObjectBuilder(tuioObject.getSymbolID(), Type.OBJECT, tuioObject.getPath().get(tuioObject.getPath().size() - 1).getX(), tuioObject.getPath().get(tuioObject.getPath().size() - 1).getY()).withSeconds(tuioObject.getTuioTime().getSeconds()).withMicroSeconds(tuioObject.getTuioTime().getMicroseconds()).withxSpeed(tuioObject.getXSpeed()).withySpeed(tuioObject.getYSpeed()).withMotionSpeed(tuioObject.getMotionSpeed()).withMotionAccel(tuioObject.getMotionAccel()).withRotationSpeed(tuioObject.getRotationSpeed()).withRotationAccel(tuioObject.getRotationAccel()).withPath(tempPath).withState(tuioObject.getTuioState()).build();
} else {
// if the object is present in the list, get previous path and add the last point
ArrayList<Point> tempPath = new ArrayList<>();
tempPath = updateObject.getPath();
int index = tuioObject.getPath().size() - 1;
tempPath.add(new Point(tuioObject.getPath().get(index).getX(), tuioObject.getPath().get(index).getY(), tuioObject.getAngle()));
convertedTangibleObject = new TangibleObjectBuilder(tuioObject.getSymbolID(), Type.OBJECT, tuioObject.getPath().get(tuioObject.getPath().size() - 1).getX(), tuioObject.getPath().get(tuioObject.getPath().size() - 1).getY()).withSeconds(tuioObject.getTuioTime().getSeconds()).withMicroSeconds(tuioObject.getTuioTime().getMicroseconds()).withxSpeed(tuioObject.getXSpeed()).withySpeed(tuioObject.getYSpeed()).withMotionSpeed(tuioObject.getMotionSpeed()).withMotionAccel(tuioObject.getMotionAccel()).withRotationSpeed(tuioObject.getRotationSpeed()).withRotationAccel(tuioObject.getRotationAccel()).withPath(tempPath).withState(tuioObject.getTuioState()).build();
}
return convertedTangibleObject;
}
......@@ -142,10 +159,29 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
private TangibleObject convertTuioCursorToTangibleObject(TuioCursor tuioCursor) {
Preconditions.checkArgument(tuioCursor != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$
Vector<Point> tempPath = new Vector<>();
tuioCursor.getPath().forEach(path -> tempPath.addElement(new Point(path.getX(), path.getY(), 0)));
ArrayList<Point> tempPath = new ArrayList<>();
tuioCursor.getPath().forEach(path -> tempPath.add(new Point(path.getX(), path.getY(), 0)));
TangibleObject convertedTangibleObject = new TangibleObjectBuilder(IDMapper.remapCursorID(tuioCursor.getCursorID()), Type.CURSOR, tuioCursor.getPath().get(tuioCursor.getPath().size() - 1).getX(), tuioCursor.getPath().get(tuioCursor.getPath().size() - 1).getY()).withSeconds(tuioCursor.getTuioTime().getSeconds()).withMicroSeconds(tuioCursor.getTuioTime().getMicroseconds()).withxSpeed(tuioCursor.getXSpeed()).withySpeed(tuioCursor.getYSpeed()).withMotionSpeed(tuioCursor.getMotionSpeed()).withMotionAccel(tuioCursor.getMotionAccel()).withPath(tempPath).withState(tuioCursor.getTuioState()).build();
return convertedTangibleObject;
}
/**
* Convert a TUIO cursor into a tangibleObject
*
* @param tuioCursor
* != null
* @pre tangibleCursor != null
* @return tangibleObject with TuioCursor's values
*/
private TangibleObject convertTuioBlobToTangibleObject(TuioBlob tuioBlob) {
Preconditions.checkArgument(tuioBlob != null, "The passed tangible cursor cannot be null!"); //$NON-NLS-1$
TangibleObject convertedTangibleObject = new TangibleObjectBuilder(IDMapper.remapCursorID(tuioCursor.getCursorID()), Type.CURSOR, tuioCursor.getPath().lastElement().getX(), tuioCursor.getPath().lastElement().getY()).withSeconds(tuioCursor.getTuioTime().getSeconds()).withMicroSeconds(tuioCursor.getTuioTime().getMicroseconds()).withxSpeed(tuioCursor.getXSpeed()).withySpeed(tuioCursor.getYSpeed()).withMotionSpeed(tuioCursor.getMotionSpeed()).withMotionAccel(tuioCursor.getMotionAccel()).withPath(tempPath).withState(tuioCursor.getTuioState()).build();
ArrayList<Point> tempPath = new ArrayList<>();
tuioBlob.getPath().forEach(path -> tempPath.add(new Point(path.getX(), path.getY(), tuioBlob.getAngle())));
// !!! MAPPING ID !!!!!!!!!!!
TangibleObject convertedTangibleObject = new TangibleObjectBuilder(IDMapper.remapCursorID(tuioBlob.getBlobID()), Type.BLOB, tuioBlob.getPath().get(tuioBlob.getPath().size() - 1).getX(), tuioBlob.getPath().get(tuioBlob.getPath().size() - 1).getY()).withSeconds(tuioBlob.getTuioTime().getSeconds()).withMicroSeconds(tuioBlob.getTuioTime().getMicroseconds()).withxSpeed(tuioBlob.getXSpeed()).withySpeed(tuioBlob.getYSpeed()).withMotionSpeed(tuioBlob.getMotionSpeed()).withMotionAccel(tuioBlob.getMotionAccel()).withRotationSpeed(tuioBlob.getRotationSpeed()).withRotationAccel(tuioBlob.getRotationAccel()).withPath(tempPath).withState(tuioBlob.getTuioState()).withWidth(tuioBlob.getWidth()).withHeight(tuioBlob.getHeight()).withArea(tuioBlob.getArea()).build();
return convertedTangibleObject;
}
......@@ -174,6 +210,19 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
Preconditions.checkArgument(tangibleObject != null, "The passed tangible object cannot be null!"); //$NON-NLS-1$
TangibleObject convertedTangibleObject = convertTuioObjectToTangibleObject(tangibleObject);
tangibleObjectList.put(convertedTangibleObject.getObjectId(), convertedTangibleObject);
super.addObjInfo(convertedTangibleObject, "down"); //$NON-NLS-1$
objectManager.dropObject(convertedTangibleObject);
}
/** {@inheritDoc} */
@Override
public void addTuioBlob(TuioBlob tangibleObject) {
Preconditions.checkArgument(tangibleObject != null, "The passed tangible object cannot be null!"); //$NON-NLS-1$
TangibleObject convertedTangibleObject = convertTuioBlobToTangibleObject(tangibleObject);
super.addObjInfo(convertedTangibleObject, "down"); //$NON-NLS-1$
......@@ -213,13 +262,20 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
Preconditions.checkArgument(tangibleObject != null, "The passed tangible object cannot be null!"); //$NON-NLS-1$
TangibleObject convertedTangibleObject = convertTuioObjectToTangibleObject(tangibleObject);
tangibleObjectList.remove(convertedTangibleObject.getObjectId());
super.addObjInfo(convertedTangibleObject, "up"); //$NON-NLS-1$
objectManager.liftObject(convertedTangibleObject);
}
/** {@inheritDoc} */
@Override
public void removeTuioBlob(TuioBlob arg0) {
// TODO Auto-generated method stub
}
/**
* {@inheritDoc} It will output several notices to the {@link EventLogger} before issuing a call
* to the {@link TangibleObjectManager} which move mapped handle.
......@@ -244,13 +300,19 @@ public class TuioAdapter extends TuiAdapter implements TuioListener {
Preconditions.checkArgument(tangibleObject != null, "The passed tangible object cannot be null!"); //$NON-NLS-1$
TangibleObject convertedTangibleObject = convertTuioObjectToTangibleObject(tangibleObject);
super.addObjInfo(convertedTangibleObject, "move"); //$NON-NLS-1$
objectManager.updateObject(convertedTangibleObject);
}
/** {@inheritDoc} */
@Override
public void updateTuioBlob(TuioBlob arg0) {
// TODO Auto-generated method stub
}
/**
* Method returning a collection of {@link TangibleObject} (cursor) instances held by this.
*
......
......@@ -27,6 +27,7 @@ import org.junit.Before;
import org.junit.Test;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Vector;
/**
......@@ -52,9 +53,9 @@ public class TangibleObjectTest {
public void setUp() throws Exception {
application = new TestTangibleApplication(propertiesLocation);
Vector<Point> temp = new Vector<>();
ArrayList<Point> temp = new ArrayList<>();
temp.add(new Point(10f, 11f, 0));
to = new TangibleObjectBuilder(1, TangibleObject.Type.OBJECT, (float) temp.lastElement().getX(), (float) temp.lastElement().getY()).withSeconds(0).withMicroSeconds(0).withxSpeed(0).withySpeed(0).withMotionSpeed(0).withMotionAccel(0).withRotationSpeed(0).withRotationAccel(0).withPath(temp).withState(TangibleObject.State.ADDED).build();
to = new TangibleObjectBuilder(1, TangibleObject.Type.OBJECT, (float) temp.get(temp.size() - 1).getX(), (float) temp.get(temp.size() - 1).getY()).withSeconds(0).withMicroSeconds(0).withxSpeed(0).withySpeed(0).withMotionSpeed(0).withMotionAccel(0).withRotationSpeed(0).withRotationAccel(0).withPath(temp).withState(TangibleObject.State.ADDED).build();
}
......@@ -354,7 +355,7 @@ public class TangibleObjectTest {
*/
@Test
public void testSetPath() {
Vector<Point> temp = new Vector<>();
ArrayList<Point> temp = new ArrayList<>();
temp.add(new Point(3f, 4f, 0));
to.setPath(temp);
Vector<Point> getter = new Vector<>(to.getPath());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment