Skip to content
This repository has been archived by the owner on Mar 2, 2018. It is now read-only.

Commit

Permalink
release-leibniz
Browse files Browse the repository at this point in the history
  • Loading branch information
r4ravi2008 committed Apr 16, 2015
1 parent 24dde1d commit 7482501
Show file tree
Hide file tree
Showing 13 changed files with 444 additions and 319 deletions.
Binary file modified AreaLearningJava/libs/tango_java_lib.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@
import com.projecttango.tangoutils.renderables.Trajectory;

/**
* OpenGL rendering class for the AreaLearningActivity API sample. This class manages
* the objects visible in the OpenGL view which are the {@link CameraFrustum},
* {@link CameraFrustumAndAxis}, {@link Trajectory}, and the {@link Grid}. These
* objects are implemented in the TangoUtils library in the package
* {@link com.projecttango.tangoutils.renderables}.
* OpenGL rendering class for the AreaLearningActivity API sample. This class manages the objects
* visible in the OpenGL view which are the {@link CameraFrustum}, {@link CameraFrustumAndAxis},
* {@link Trajectory}, and the {@link Grid}. These objects are implemented in the TangoUtils library
* in the package {@link com.projecttango.tangoutils.renderables}.
*
* This class receives also handles the user-selected camera view, which can be
* 1st person, 3rd person, or top-down.
* This class receives also handles the user-selected camera view, which can be 1st person, 3rd
* person, or top-down.
*/
public class ALRenderer extends Renderer implements GLSurfaceView.Renderer {

Expand All @@ -57,33 +56,32 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
mFloorGrid = new Grid();
mCameraFrustumAndAxis = new CameraFrustumAndAxis();
mGreenTrajectory = new Trajectory(3);
mGreenTrajectory.setColor(
new float[] { 0.39f, 0.56f, 0.03f, 1.0f});
mGreenTrajectory.setColor(new float[] { 0.39f, 0.56f, 0.03f, 1.0f });
mBlueTrajectory = new Trajectory(3);
mBlueTrajectory.setColor(
new float[] { 0.22f, 0.28f, 0.67f, 1.0f});
mBlueTrajectory.setColor(new float[] { 0.22f, 0.28f, 0.67f, 1.0f });
// Construct the initial view matrix
Matrix.setIdentityM(mViewMatrix, 0);
Matrix.setLookAtM(mViewMatrix, 0, 5f, 5f, 5f, 0f, 0f, 0f, 0f, 1f, 0f);
mCameraFrustumAndAxis.setModelMatrix(getModelMatCalculator()
.getModelMatrix());
mCameraFrustumAndAxis.setModelMatrix(getModelMatCalculator().getModelMatrix());
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
GLES20.glViewport(0, 0, width, height);
mCameraAspect = (float) width / height;
Matrix.perspectiveM(mProjectionMatrix, 0, THIRD_PERSON_FOV,
mCameraAspect, CAMERA_NEAR, CAMERA_FAR);
Matrix.perspectiveM(mProjectionMatrix, 0, THIRD_PERSON_FOV, mCameraAspect, CAMERA_NEAR,
CAMERA_FAR);
}

@Override
public void onDrawFrame(GL10 gl) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
mGreenTrajectory.draw(getViewMatrix(), mProjectionMatrix);
mBlueTrajectory.draw(getViewMatrix(), mProjectionMatrix);
mFloorGrid.draw(getViewMatrix(), mProjectionMatrix);
mCameraFrustumAndAxis.draw(getViewMatrix(), mProjectionMatrix);
synchronized (AreaLearningActivity.sharedLock) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
mGreenTrajectory.draw(getViewMatrix(), mProjectionMatrix);
mBlueTrajectory.draw(getViewMatrix(), mProjectionMatrix);
mFloorGrid.draw(getViewMatrix(), mProjectionMatrix);
mCameraFrustumAndAxis.draw(getViewMatrix(), mProjectionMatrix);
}
}

public CameraFrustum getCameraFrustum() {
Expand All @@ -97,7 +95,7 @@ public CameraFrustumAndAxis getCameraFrustumAndAxis() {
public Trajectory getBlueTrajectory() {
return mBlueTrajectory;
}

public Trajectory getGreenTrajectory() {
return mGreenTrajectory;
}
Expand Down

Large diffs are not rendered by default.

Binary file modified MotionTrackingJava/libs/tango_java_lib.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ public void onSurfaceChanged(GL10 gl, int width, int height) {

@Override
public void onDrawFrame(GL10 gl) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
mTrajectory.draw(getViewMatrix(), mProjectionMatrix);
mFloorGrid.draw(getViewMatrix(), mProjectionMatrix);
mCameraFrustumAndAxis.draw(getViewMatrix(), mProjectionMatrix);
synchronized (MotionTrackingActivity.sharedLock) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
mTrajectory.draw(getViewMatrix(), mProjectionMatrix);
mFloorGrid.draw(getViewMatrix(), mProjectionMatrix);
mCameraFrustumAndAxis.draw(getViewMatrix(), mProjectionMatrix);
}
}

public CameraFrustum getCameraFrustum() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public class MotionTrackingActivity extends Activity implements View.OnClickList
private boolean mIsAutoRecovery;
private MTGLRenderer mRenderer;
private GLSurfaceView mGLView;
private boolean mIsProcessing = false;
private TangoPoseData mPose;
private static final int UPDATE_INTERVAL_MS = 100;
public static Object sharedLock = new Object();

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -106,7 +110,6 @@ protected void onCreate(Bundle savedInstanceState) {
mRenderer = new MTGLRenderer();
mGLView.setEGLContextClientVersion(2);
mGLView.setRenderer(mRenderer);
mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

// Instantiate the Tango service
mTango = new Tango(this);
Expand Down Expand Up @@ -137,7 +140,7 @@ protected void onCreate(Bundle savedInstanceState) {

// Display the library version for debug purposes
mTangoServiceVersionTextView.setText(mConfig.getString("tango_service_library_version"));

startUIThread();
}

/**
Expand All @@ -147,8 +150,7 @@ protected void onCreate(Bundle savedInstanceState) {
private void setTangoListeners() {
// Lock configuration and connect to Tango
// Select coordinate frame pair
final ArrayList<TangoCoordinateFramePair> framePairs =
new ArrayList<TangoCoordinateFramePair>();
final ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
framePairs.add(new TangoCoordinateFramePair(
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_DEVICE));
Expand All @@ -157,55 +159,30 @@ private void setTangoListeners() {

@Override
public void onPoseAvailable(final TangoPoseData pose) {
// Log whenever Motion Tracking enters a n invalid state
if (!mIsAutoRecovery && (pose.statusCode == TangoPoseData.POSE_INVALID)) {
Log.w(TAG, "Invalid State");
}
if (mPreviousPoseStatus != pose.statusCode) {
count = 0;
}
count++;
mPreviousPoseStatus = pose.statusCode;
mDeltaTime = (float) (pose.timestamp - mPreviousTimeStamp) * SECS_TO_MILLISECS;
mPreviousTimeStamp = (float) pose.timestamp;
// Update the OpenGL renderable objects with the new Tango Pose
// data
float[] translation = pose.getTranslationAsFloats();
mRenderer.getTrajectory().updateTrajectory(translation);
mRenderer.getModelMatCalculator().updateModelMatrix(translation,
pose.getRotationAsFloats());
mRenderer.updateViewMatrix();
mGLView.requestRender();

// Update the UI with TangoPose information
runOnUiThread(new Runnable() {
@Override
public void run() {
DecimalFormat threeDec = new DecimalFormat("0.000");
String translationString = "[" + threeDec.format(pose.translation[0])
+ ", " + threeDec.format(pose.translation[1]) + ", "
+ threeDec.format(pose.translation[2]) + "] ";
String quaternionString = "[" + threeDec.format(pose.rotation[0]) + ", "
+ threeDec.format(pose.rotation[1]) + ", "
+ threeDec.format(pose.rotation[2]) + ", "
+ threeDec.format(pose.rotation[3]) + "] ";

// Display pose data on screen in TextViews
mPoseTextView.setText(translationString);
mQuatTextView.setText(quaternionString);
mPoseCountTextView.setText(Integer.toString(count));
mDeltaTextView.setText(threeDec.format(mDeltaTime));
if (pose.statusCode == TangoPoseData.POSE_VALID) {
mPoseStatusTextView.setText(R.string.pose_valid);
} else if (pose.statusCode == TangoPoseData.POSE_INVALID) {
mPoseStatusTextView.setText(R.string.pose_invalid);
} else if (pose.statusCode == TangoPoseData.POSE_INITIALIZING) {
mPoseStatusTextView.setText(R.string.pose_initializing);
} else if (pose.statusCode == TangoPoseData.POSE_UNKNOWN) {
mPoseStatusTextView.setText(R.string.pose_unknown);
}
//Make sure to have atomic access to Tango Pose Data so that
//render loop doesn't interfere while Pose call back is updating
// the data.
synchronized (sharedLock) {
mPose = pose;
mDeltaTime = (float) (pose.timestamp - mPreviousTimeStamp) * SECS_TO_MILLISECS;
mPreviousTimeStamp = (float) pose.timestamp;
// Log whenever Motion Tracking enters an invalid state
if (!mIsAutoRecovery && (pose.statusCode == TangoPoseData.POSE_INVALID)) {
Log.w(TAG, "Invalid State");
}
});
if (mPreviousPoseStatus != pose.statusCode) {
count = 0;
}
count++;
mPreviousPoseStatus = pose.statusCode;
// Update the OpenGL renderable objects with the new Tango Pose
// data
float[] translation = pose.getTranslationAsFloats();
mRenderer.getTrajectory().updateTrajectory(translation);
mRenderer.getModelMatCalculator().updateModelMatrix(translation,
pose.getRotationAsFloats());
mRenderer.updateViewMatrix();
}
}

@Override
Expand Down Expand Up @@ -302,7 +279,10 @@ public void onClick(View v) {
public boolean onTouchEvent(MotionEvent event) {
return mRenderer.onTouchEvent(event);
}


/**
* Setup the extrinsics of the device.
*/
private void setUpExtrinsics() {
// Get device to imu matrix.
TangoPoseData device2IMUPose = new TangoPoseData();
Expand All @@ -322,4 +302,64 @@ private void setUpExtrinsics() {
mRenderer.getModelMatCalculator().SetColorCamera2IMUMatrix(
color2IMUPose.getTranslationAsFloats(), color2IMUPose.getRotationAsFloats());
}
/**
* Create a separate thread to update Log information on UI at the specified
* interval of UPDATE_INTERVAL_MS. This function also makes sure to have access
* to the mPose atomically.
*/
private void startUIThread() {
new Thread(new Runnable() {
DecimalFormat threeDec = new DecimalFormat("00.000");
@Override
public void run() {
while (true) {
try {
Thread.sleep(UPDATE_INTERVAL_MS);
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
synchronized (sharedLock) {
if (mPose == null) {
return;
}

String translationString = "["
+ threeDec.format(mPose.translation[0]) + ", "
+ threeDec.format(mPose.translation[1]) + ", "
+ threeDec.format(mPose.translation[2]) + "] ";
String quaternionString = "["
+ threeDec.format(mPose.rotation[0]) + ", "
+ threeDec.format(mPose.rotation[1]) + ", "
+ threeDec.format(mPose.rotation[2]) + ", "
+ threeDec.format(mPose.rotation[3]) + "] ";

// Display pose data on screen in TextViews
mPoseTextView.setText(translationString);
mQuatTextView.setText(quaternionString);
mPoseCountTextView.setText(Integer.toString(count));
mDeltaTextView.setText(threeDec.format(mDeltaTime));
if (mPose.statusCode == TangoPoseData.POSE_VALID) {
mPoseStatusTextView.setText(R.string.pose_valid);
} else if (mPose.statusCode == TangoPoseData.POSE_INVALID) {
mPoseStatusTextView.setText(R.string.pose_invalid);
} else if (mPose.statusCode == TangoPoseData.POSE_INITIALIZING) {
mPoseStatusTextView.setText(R.string.pose_initializing);
} else if (mPose.statusCode == TangoPoseData.POSE_UNKNOWN) {
mPoseStatusTextView.setText(R.string.pose_unknown);
}
}
} catch (NullPointerException e) {
e.printStackTrace();
}
}
});

} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
}
Binary file modified PointCloudJava/libs/tango_java_lib.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@
import com.projecttango.tangoutils.renderables.PointCloud;

/**
* OpenGL rendering class for the Motion Tracking API sample. This class
* managers the objects visible in the OpenGL view which are the
* {@link CameraFrustum}, {@link PointCloud} and the {@link Grid}. These objects
* are implemented in the TangoUtils library in the package
* OpenGL rendering class for the Motion Tracking API sample. This class managers the objects
* visible in the OpenGL view which are the {@link CameraFrustum}, {@link PointCloud} and the
* {@link Grid}. These objects are implemented in the TangoUtils library in the package
* {@link com.projecttango.tangoutils.renderables}.
*
* This class receives {@link TangoPose} data from the {@link MotionTracking}
* class and updates the model and view matrices of the {@link Renderable}
* objects appropriately. It also handles the user-selected camera view, which
* can be 1st person, 3rd person, or top-down.
* This class receives {@link TangoPose} data from the {@link MotionTracking} class and updates the
* model and view matrices of the {@link Renderable} objects appropriately. It also handles the
* user-selected camera view, which can be 1st person, 3rd person, or top-down.
*
*/
public class PCRenderer extends Renderer implements GLSurfaceView.Renderer {
Expand All @@ -62,24 +60,27 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
mCameraFrustumAndAxis = new CameraFrustumAndAxis();
Matrix.setIdentityM(mViewMatrix, 0);
Matrix.setLookAtM(mViewMatrix, 0, 5f, 5f, 5f, 0f, 0f, 0f, 0f, 1f, 0f);
mCameraFrustumAndAxis.setModelMatrix(getModelMatCalculator()
.getModelMatrix());
mCameraFrustumAndAxis.setModelMatrix(getModelMatCalculator().getModelMatrix());
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
GLES20.glViewport(0, 0, width, height);
mCameraAspect = (float) width / height;
Matrix.perspectiveM(mProjectionMatrix, 0, CAMERA_FOV, mCameraAspect,
CAMERA_NEAR, CAMERA_FAR);
Matrix.perspectiveM(mProjectionMatrix, 0, CAMERA_FOV, mCameraAspect, CAMERA_NEAR,
CAMERA_FAR);
}

@Override
public void onDrawFrame(GL10 gl) {
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
mGrid.draw(mViewMatrix, mProjectionMatrix);
mPointCloud.draw(mViewMatrix, mProjectionMatrix);
mCameraFrustumAndAxis.draw(mViewMatrix, mProjectionMatrix);
synchronized (PointCloudActivity.depthLock) {
mPointCloud.draw(mViewMatrix, mProjectionMatrix);
}
synchronized (PointCloudActivity.poseLock) {
mCameraFrustumAndAxis.draw(mViewMatrix, mProjectionMatrix);
}
}

public PointCloud getPointCloud() {
Expand Down
Loading

0 comments on commit 7482501

Please sign in to comment.