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

Commit

Permalink
release-tania-borealis
Browse files Browse the repository at this point in the history
  • Loading branch information
jguomoto committed Aug 8, 2016
1 parent 6bc9979 commit 62ec52a
Show file tree
Hide file tree
Showing 108 changed files with 664 additions and 409 deletions.
Empty file modified java_augmented_reality_example/app/src/main/AndroidManifest.xml
100755 → 100644
Empty file.
136 changes: 95 additions & 41 deletions ...c/main/java/com/projecttango/examples/java/augmentedreality/AugmentedRealityActivity.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.opengl.Matrix;
import android.os.Bundle;
import android.util.Log;
import android.view.Surface;
Expand Down Expand Up @@ -175,9 +176,16 @@ private TangoConfig setupTangoConfig(Tango tango) {
// low latency IMU integration.
TangoConfig config = tango.getConfig(TangoConfig.CONFIG_TYPE_DEFAULT);
config.putBoolean(TangoConfig.KEY_BOOLEAN_COLORCAMERA, true);

// NOTE: Low latency integration is necessary to achieve a precise alignment of
// virtual objects with the RBG image and produce a good AR effect.
config.putBoolean(TangoConfig.KEY_BOOLEAN_LOWLATENCYIMUINTEGRATION, true);

// Drift correction allows motion tracking to recover after it loses tracking.
//
// The drift corrected pose is is available through the frame pair with
// base frame AREA_DESCRIPTION and target frame DEVICE.
config.putBoolean(TangoConfig.KEY_BOOLEAN_DRIFT_CORRECTION, true);
return config;
}

Expand Down Expand Up @@ -246,52 +254,72 @@ public void onPreFrame(long sceneTime, double deltaTime) {

// Prevent concurrent access to {@code mIsFrameAvailableTangoThread} from the Tango
// callback thread and service disconnection from an onPause event.
synchronized (AugmentedRealityActivity.this) {
// Don't execute any tango API actions if we're not connected to the service.
if (!mIsConnected) {
return;
}

// Set-up scene camera projection to match RGB camera intrinsics.
if (!mRenderer.isSceneCameraConfigured()) {
mRenderer.setProjectionMatrix(mIntrinsics);
}
try {
synchronized (AugmentedRealityActivity.this) {
// Don't execute any tango API actions if we're not connected to the service
if (!mIsConnected) {
return;
}

// Connect the camera texture to the OpenGL Texture if necessary
// NOTE: When the OpenGL context is recycled, Rajawali may re-generate the
// texture with a different ID.
if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) {
mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR,
mRenderer.getTextureId());
mConnectedTextureIdGlThread = mRenderer.getTextureId();
Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId());
}
// Set-up scene camera projection to match RGB camera intrinsics.
if (!mRenderer.isSceneCameraConfigured()) {
mRenderer.setProjectionMatrix(
projectionMatrixFromCameraIntrinsics(mIntrinsics));
}
// Connect the camera texture to the OpenGL Texture if necessary
// NOTE: When the OpenGL context is recycled, Rajawali may re-generate the
// texture with a different ID.
if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) {
mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR,
mRenderer.getTextureId());
mConnectedTextureIdGlThread = mRenderer.getTextureId();
Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId());
}

// If there is a new RGB camera frame available, update the texture with it
if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) {
mRgbTimestampGlThread =
mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR);
}
// If there is a new RGB camera frame available, update the texture with it
if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) {
mRgbTimestampGlThread =
mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR);
}

// If a new RGB frame has been rendered, update the camera pose to match.
if (mRgbTimestampGlThread > mCameraPoseTimestamp) {
// Calculate the camera color pose at the camera frame update time in
// OpenGL engine.
TangoPoseData lastFramePose = TangoSupport.getPoseAtTime(
mRgbTimestampGlThread,
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR,
TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL,
Surface.ROTATION_0);
if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) {
// Update the camera pose from the renderer
mRenderer.updateRenderCameraPose(lastFramePose);
mCameraPoseTimestamp = lastFramePose.timestamp;
} else {
Log.w(TAG, "Can't get device pose at time: " +
mRgbTimestampGlThread);
// If a new RGB frame has been rendered, update the camera pose to match.
if (mRgbTimestampGlThread > mCameraPoseTimestamp) {
// Calculate the camera color pose at the camera frame update time in
// OpenGL engine.
//
// When drift correction mode is enabled in config file, we must query
// the device with respect to Area Description pose in order to use the
// drift corrected pose.
//
// Note that if you don't want to use the drift corrected pose, the
// normal device with respect to start of service pose is available.
TangoPoseData lastFramePose = TangoSupport.getPoseAtTime(
mRgbTimestampGlThread,
TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION,
TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR,
TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL,
Surface.ROTATION_0);
if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) {
// Update the camera pose from the renderer
mRenderer.updateRenderCameraPose(lastFramePose);
mCameraPoseTimestamp = lastFramePose.timestamp;
} else {
// When the pose status is not valid, it indicates the tracking has
// been lost. In this case, we simply stop rendering.
//
// This is also the place to display UI to suggest the user walk
// to recover tracking.
Log.w(TAG, "Can't get device pose at time: " +
mRgbTimestampGlThread);
}
}
}

// Avoid crashing the application due to unhandled exceptions
} catch (TangoErrorException e) {
Log.e(TAG, "Tango API call error within the OpenGL render thread", e);
} catch (Throwable t) {
Log.e(TAG, "Exception on the OpenGL thread", t);
}
}

Expand All @@ -313,4 +341,30 @@ public boolean callPreFrame() {

mSurfaceView.setSurfaceRenderer(mRenderer);
}

/**
* Use Tango camera intrinsics to calculate the projection Matrix for the Rajawali scene.
*/
private static float[] projectionMatrixFromCameraIntrinsics(TangoCameraIntrinsics intrinsics) {
// Uses frustumM to create a projection matrix taking into account calibrated camera
// intrinsic parameter.
// Reference: http://ksimek.github.io/2013/06/03/calibrated_cameras_in_opengl/
float near = 0.1f;
float far = 100;

float xScale = near / (float) intrinsics.fx;
float yScale = near / (float) intrinsics.fy;
float xOffset = (float) (intrinsics.cx - (intrinsics.width / 2.0)) * xScale;
// Color camera's coordinates has y pointing downwards so we negate this term.
float yOffset = (float) -(intrinsics.cy - (intrinsics.height / 2.0)) * yScale;

float m[] = new float[16];
Matrix.frustumM(m, 0,
xScale * (float) -intrinsics.width / 2.0f - xOffset,
xScale * (float) intrinsics.width / 2.0f - xOffset,
yScale * (float) -intrinsics.height / 2.0f - yOffset,
yScale * (float) intrinsics.height / 2.0f - yOffset,
near, far);
return m;
}
}
13 changes: 3 additions & 10 deletions ...c/main/java/com/projecttango/examples/java/augmentedreality/AugmentedRealityRenderer.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@

import javax.microedition.khronos.opengles.GL10;

import com.projecttango.rajawali.DeviceExtrinsics;
import com.projecttango.rajawali.Pose;
import com.projecttango.rajawali.ScenePoseCalculator;

/**
* Renderer that implements a basic augmented reality scene using Rajawali.
* It creates a scene with a background quad taking the whole screen, where the color camera is
Expand Down Expand Up @@ -197,14 +193,11 @@ public boolean isSceneCameraConfigured() {
}

/**
* Sets the projection matrix for the scen camera to match the parameters of the color camera,
* Sets the projection matrix for the scene camera to match the parameters of the color camera,
* provided by the {@code TangoCameraIntrinsics}.
*/
public void setProjectionMatrix(TangoCameraIntrinsics intrinsics) {
Matrix4 projectionMatrix = ScenePoseCalculator.calculateProjectionMatrix(
intrinsics.width, intrinsics.height,
intrinsics.fx, intrinsics.fy, intrinsics.cx, intrinsics.cy);
getCurrentCamera().setProjectionMatrix(projectionMatrix);
public void setProjectionMatrix(float[] matrixFloats) {
getCurrentCamera().setProjectionMatrix(new Matrix4(matrixFloats));
}

@Override
Expand Down
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Empty file.
Empty file.
Empty file modified java_basic_examples/hello_video/src/main/AndroidManifest.xml
100755 → 100644
Empty file.
78 changes: 42 additions & 36 deletions ...llo_video/src/main/java/com/projecttango/examples/java/hellovideo/HelloVideoActivity.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -234,47 +234,53 @@ public void preRender() {
return;
}

// Synchronize against concurrently disconnecting the service triggered from the
// UI thread.
synchronized (HelloVideoActivity.this) {
// Connect the Tango SDK to the OpenGL texture ID where we are going to
// render the camera.
// NOTE: This must be done after both the texture is generated and the Tango
// service is connected.
if (mConnectedTextureIdGlThread == INVALID_TEXTURE_ID) {
mConnectedTextureIdGlThread = mRenderer.getTextureId();
mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR,
mRenderer.getTextureId());
Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId());
}
try {
// Synchronize against concurrently disconnecting the service triggered from the
// UI thread.
synchronized (HelloVideoActivity.this) {
// Connect the Tango SDK to the OpenGL texture ID where we are going to
// render the camera.
// NOTE: This must be done after both the texture is generated and the Tango
// service is connected.
if (mConnectedTextureIdGlThread == INVALID_TEXTURE_ID) {
mConnectedTextureIdGlThread = mRenderer.getTextureId();
mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR,
mRenderer.getTextureId());
Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId());
}

// If there is a new RGB camera frame available, update the texture and
// scene camera pose.
if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) {
double rgbTimestamp =
mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR);
// {@code rgbTimestamp} contains the exact timestamp at which the
// rendered RGB frame was acquired.
// If there is a new RGB camera frame available, update the texture and
// scene camera pose.
if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) {
double rgbTimestamp =
mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR);
// {@code rgbTimestamp} contains the exact timestamp at which the
// rendered RGB frame was acquired.

// In order to see more details on how to use this timestamp to modify
// the scene camera and achieve an augmented reality effect, please
// refer to java_augmented_reality_example and/or
// java_augmented_reality_opengl_example projects.
// In order to see more details on how to use this timestamp to modify
// the scene camera and achieve an augmented reality effect, please
// refer to java_augmented_reality_example and/or
// java_augmented_reality_opengl_example projects.

// Log and display timestamp for informational purposes
Log.d(TAG, "Frame updated. Timestamp: " + rgbTimestamp);
// Log and display timestamp for informational purposes
Log.d(TAG, "Frame updated. Timestamp: " + rgbTimestamp);

// Updating the UI needs to be in a separate thread. Do it through a
// final local variable to avoid concurrency issues.
final String timestampText = String.format(sTimestampFormat,
rgbTimestamp);
runOnUiThread(new Runnable() {
@Override
public void run() {
mTimestampTextView.setText(timestampText);
}
});
// Updating the UI needs to be in a separate thread. Do it through a
// final local variable to avoid concurrency issues.
final String timestampText = String.format(sTimestampFormat,
rgbTimestamp);
runOnUiThread(new Runnable() {
@Override
public void run() {
mTimestampTextView.setText(timestampText);
}
});
}
}
} catch (TangoErrorException e) {
Log.e(TAG, "Tango API call error within the OpenGL thread", e);
} catch (Throwable t) {
Log.e(TAG, "Exception on the OpenGL thread", t);
}
}
});
Expand Down
Empty file.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Empty file modified java_basic_examples/hello_video/src/main/res/values/strings.xml
100755 → 100644
Empty file.
Empty file modified java_basic_examples/hello_video/src/main/res/values/styles.xml
100755 → 100644
Empty file.
Empty file modified java_floor_plan_example/app/src/main/AndroidManifest.xml
100755 → 100644
Empty file.
Empty file.
Loading

0 comments on commit 62ec52a

Please sign in to comment.