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

Commit

Permalink
Merge pull request #89 from googlesamples/release-caporales
Browse files Browse the repository at this point in the history
release-caporales
  • Loading branch information
jguomoto committed Jan 20, 2017
2 parents adffbcd + d178dcd commit ad5ce28
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 68 deletions.
Binary file modified TangoReleaseLibs/aar/tango-ux-support-library.aar
Binary file not shown.
Binary file modified TangoReleaseLibs/aar/tango_support_java_lib.aar
Binary file not shown.
Binary file modified TangoReleaseLibs/jar/tango_java_lib.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions java_augmented_reality_example/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 19
compileSdkVersion 23
buildToolsVersion "21.1.2"

defaultConfig {
applicationId "com.projecttango.experiments.augmentedrealitysample"
minSdkVersion 19
targetSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
Expand Down Expand Up @@ -42,4 +42,5 @@ dependencies {
compile fileTree(dir: external_lib_prefix + '/jar', include: ['**/*.jar'])
compile (name: 'tango_support_java_lib', ext: 'aar')
compile 'org.rajawali3d:rajawali:1.1.668@aar'
compile 'com.android.support:appcompat-v7:23.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
android:versionName="0" >

<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
android:minSdkVersion="19"
android:targetSdkVersion="23" />

<uses-permission android:name="android.permission.CAMERA" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,22 @@
import com.google.atap.tangoservice.TangoPoseData;
import com.google.atap.tangoservice.TangoXyzIjData;

import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.display.DisplayManager;
import android.opengl.GLSurfaceView;
import android.opengl.Matrix;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.Display;
import android.view.Surface;
import android.widget.Toast;

import org.rajawali3d.scene.ASceneFrameCallback;
import org.rajawali3d.view.SurfaceView;
Expand Down Expand Up @@ -75,6 +82,9 @@ public class AugmentedRealityActivity extends Activity {
// For all current Tango devices, color camera is in the camera id 0.
private static final int COLOR_CAMERA_ID = 0;

private static final String CAMERA_PERMISSION = Manifest.permission.CAMERA;
private static final int CAMERA_PERMISSION_CODE = 0;

private SurfaceView mSurfaceView;
private AugmentedRealityRenderer mRenderer;
private TangoCameraIntrinsics mIntrinsics;
Expand Down Expand Up @@ -102,7 +112,8 @@ protected void onCreate(Bundle savedInstanceState) {
if (displayManager != null) {
displayManager.registerDisplayListener(new DisplayManager.DisplayListener() {
@Override
public void onDisplayAdded(int displayId) {}
public void onDisplayAdded(int displayId) {
}

@Override
public void onDisplayChanged(int displayId) {
Expand All @@ -112,36 +123,73 @@ public void onDisplayChanged(int displayId) {
}

@Override
public void onDisplayRemoved(int displayId) {}
public void onDisplayRemoved(int displayId) {
}
}, null);
}

setupRenderer();
}

@Override
protected void onResume() {
super.onResume();
protected void onStart() {
super.onStart();
mSurfaceView.onResume();

setAndroidOrientation();

// Set render mode to RENDERMODE_CONTINUOUSLY to force getting onDraw callbacks until the
// Tango service is properly set-up and we start getting onFrameAvailable callbacks.
// Set render mode to RENDERMODE_CONTINUOUSLY to force getting onDraw callbacks until
// the Tango service is properly set-up and we start getting onFrameAvailable callbacks.
mSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
// Check and request camera permission at run time.
if (hasCameraPermission()) {
bindTangoService();
} else {
requestCameraPermission();
}
}

@Override
public void onStop() {
super.onStop();
mSurfaceView.onPause();
// Synchronize against disconnecting while the service is being used in the OpenGL thread or
// in the UI thread.
// NOTE: DO NOT lock against this same object in the Tango callback thread. Tango.disconnect
// will block here until all Tango callback calls are finished. If you lock against this
// object in a Tango callback thread it will cause a deadlock.
synchronized (this) {
if (mIsConnected) {
try {
mIsConnected = false;
mTango.disconnectCamera(TangoCameraIntrinsics.TANGO_CAMERA_COLOR);
// We need to invalidate the connected texture ID so that we cause a
// re-connection in the OpenGL thread after resume.
mConnectedTextureIdGlThread = INVALID_TEXTURE_ID;
mTango.disconnect();
mTango = null;
} catch (TangoErrorException e) {
Log.e(TAG, getString(R.string.exception_tango_error), e);
}
}
}
}

// Initialize Tango Service as a normal Android Service, since we call mTango.disconnect()
// in onPause, this will unbind Tango Service, so every time when onResume gets called, we
// should create a new Tango object.
/**
* Initialize Tango Service as a normal Android Service.
*/
private void bindTangoService() {
// Since we call mTango.disconnect() in onStop, this will unbind Tango Service, so every
// time when onStart gets called, we should create a new Tango object.
mTango = new Tango(AugmentedRealityActivity.this, new Runnable() {
// Pass in a Runnable to be called from UI thread when Tango is ready, this Runnable
// will be running on a new thread.
// When Tango is ready, we can call Tango functions safely here only when there is no UI
// thread changes involved.
// When Tango is ready, we can call Tango functions safely here only when there
// is no UI thread changes involved.
@Override
public void run() {
// Synchronize against disconnecting while the service is being used in the OpenGL
// thread or in the UI thread.
// Synchronize against disconnecting while the service is being used in the
// OpenGL thread or in the UI thread.
synchronized (AugmentedRealityActivity.this) {
try {
TangoSupport.initialize();
Expand All @@ -161,29 +209,6 @@ public void run() {
});
}

@Override
protected void onPause() {
super.onPause();
mSurfaceView.onPause();
// Synchronize against disconnecting while the service is being used in the OpenGL thread or
// in the UI thread.
// NOTE: DO NOT lock against this same object in the Tango callback thread. Tango.disconnect
// will block here until all Tango callback calls are finished. If you lock against this
// object in a Tango callback thread it will cause a deadlock.
synchronized (this) {
try {
mIsConnected = false;
mTango.disconnectCamera(TangoCameraIntrinsics.TANGO_CAMERA_COLOR);
// We need to invalidate the connected texture ID so that we cause a re-connection
// in the OpenGL thread after resume.
mConnectedTextureIdGlThread = INVALID_TEXTURE_ID;
mTango.disconnect();
} catch (TangoErrorException e) {
Log.e(TAG, getString(R.string.exception_tango_error), e);
}
}
}

/**
* Sets up the tango configuration object. Make sure mTango object is initialized before
* making this call.
Expand Down Expand Up @@ -392,8 +417,9 @@ private static int getColorCameraToDisplayAndroidRotation(int displayRotation,

/**
* Use Tango camera intrinsics to calculate the projection Matrix for the Rajawali scene.
*
* @param intrinsics camera instrinsics for computing the project matrix.
* @param rotation the relative rotation between the camera intrinsics and display glContext.
* @param rotation the relative rotation between the camera intrinsics and display glContext.
*/
private static float[] projectionMatrixFromCameraIntrinsics(TangoCameraIntrinsics intrinsics,
int rotation) {
Expand Down Expand Up @@ -471,4 +497,53 @@ public void run() {
}
});
}

/**
* Check we have the necessary permissions for this app.
*/
private boolean hasCameraPermission() {
return ContextCompat.checkSelfPermission(this, CAMERA_PERMISSION) ==
PackageManager.PERMISSION_GRANTED;
}

/**
* Request the necessary permissions for this app.
*/
private void requestCameraPermission() {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, CAMERA_PERMISSION)) {
showRequestPermissionRationale();
} else {
ActivityCompat.requestPermissions(this, new String[]{CAMERA_PERMISSION},
CAMERA_PERMISSION_CODE);
}
}

/**
* If the user has declined the permission before, we have to explain him the app needs this
* permission.
*/
private void showRequestPermissionRationale() {
final AlertDialog dialog = new AlertDialog.Builder(this)
.setMessage("Java Augmented Reality Example requires camera permission")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ActivityCompat.requestPermissions(AugmentedRealityActivity.this,
new String[]{CAMERA_PERMISSION}, CAMERA_PERMISSION_CODE);
}
})
.create();
dialog.show();
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,
int[] grantResults) {
if (hasCameraPermission()) {
bindTangoService();
} else {
Toast.makeText(this, "Java Augmented Reality Example requires camera permission",
Toast.LENGTH_LONG).show();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -522,17 +522,20 @@ private WallMeasurement doWallMeasurement(float u, float v, double rgbTimestamp)
// We need to calculate the transform between the color camera at the
// time the user clicked and the depth camera at the time the depth
// cloud was acquired.
TangoPoseData colorTdepthPose = TangoSupport.calculateRelativePose(
rgbTimestamp, TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR,
pointCloud.timestamp, TangoPoseData.COORDINATE_FRAME_CAMERA_DEPTH);
TangoPoseData depthTcolorPose = TangoSupport.calculateRelativePose(
pointCloud.timestamp, TangoPoseData.COORDINATE_FRAME_CAMERA_DEPTH,
rgbTimestamp, TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR);

// Perform plane fitting with the latest available point cloud data.
try {
float[] uv = getColorCameraUVFromDisplay(u, v, mColorCameraToDisplayAndroidRotation);

double[] identityTranslation = {0.0, 0.0, 0.0};
double[] identityRotation = {0.0, 0.0, 0.0, 1.0};
IntersectionPointPlaneModelPair intersectionPointPlaneModelPair =
TangoSupport.fitPlaneModelNearPoint(pointCloud,
colorTdepthPose, uv[0], uv[1]);
identityTranslation, identityRotation, uv[0], uv[1],
depthTcolorPose.translation, depthTcolorPose.rotation);

// Get the depth camera transform at the time the plane data was acquired.
TangoSupport.TangoMatrixTransformData transform =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void preRender() {
// In the following code, we define t0 as the depth timestamp
// and t1 as the color camera timestamp.

// Calculate the relative pose from color camera frame at
// Calculate the relative pose between color camera frame at
// timestamp color_timestamp t1 and depth.
TangoPoseData poseColort1Tdeptht0;
poseColort1Tdeptht0 = TangoSupport.calculateRelativePose(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,23 @@ public void preRender() {
}

public void onPauseButtonClick(View v) {
if (mIsPaused) {
mTangoMesher.startSceneReconstruction();
mPauseButton.setText("Pause");
} else {
mTangoMesher.stopSceneReconstruction();
mPauseButton.setText("Resume");
if (mTangoMesher != null) {
if (mIsPaused) {
mTangoMesher.startSceneReconstruction();
mPauseButton.setText("Pause");
} else {
mTangoMesher.stopSceneReconstruction();
mPauseButton.setText("Resume");
}
mIsPaused = !mIsPaused;
}
mIsPaused = !mIsPaused;
}

public void onClearButtonClicked(View v) {
mTangoMesher.resetSceneReconstruction();
mClearMeshes = true;
if (mTangoMesher != null) {
mTangoMesher.resetSceneReconstruction();
mClearMeshes = true;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,11 @@ private float[] doPointMeasurement(float u, float v, double rgbTimestamp) {
float[] uv = getColorCameraUVFromDisplay(u, v, mColorCameraToDisplayAndroidRotation);

// Get depth point with the latest available point cloud data.
double[] identityTranslation = {0.0, 0.0, 0.0};
double[] identityRotation = {0.0, 0.0, 0.0, 1.0};
float[] point = TangoSupport.getDepthAtPointNearestNeighbor(pointCloud,
colorTdepthPose, uv[0], uv[1]);
colorTdepthPose.translation, colorTdepthPose.rotation, uv[0], uv[1],
identityTranslation, identityRotation);

// Get the transform from depth camera to OpenGL world at the timestamp of the cloud.
TangoSupport.TangoMatrixTransformData transform =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,16 +511,19 @@ private float[] doFitPlane(float u, float v, double rgbTimestamp) {
// We need to calculate the transform between the color camera at the
// time the user clicked and the depth camera at the time the depth
// cloud was acquired.
TangoPoseData colorTdepthPose = TangoSupport.calculateRelativePose(
rgbTimestamp, TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR,
pointCloud.timestamp, TangoPoseData.COORDINATE_FRAME_CAMERA_DEPTH);
TangoPoseData depthTcolorPose = TangoSupport.calculateRelativePose(
pointCloud.timestamp, TangoPoseData.COORDINATE_FRAME_CAMERA_DEPTH,
rgbTimestamp, TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR);

float[] uv = getColorCameraUVFromDisplay(u, v, mColorCameraToDisplayAndroidRotation);

// Perform plane fitting with the latest available point cloud data.
double[] identityTranslation = {0.0, 0.0, 0.0};
double[] identityRotation = {0.0, 0.0, 0.0, 1.0};
TangoSupport.IntersectionPointPlaneModelPair intersectionPointPlaneModelPair =
TangoSupport.fitPlaneModelNearPoint(pointCloud,
colorTdepthPose, uv[0], uv[1]);
identityTranslation, identityRotation, uv[0], uv[1],
depthTcolorPose.translation, depthTcolorPose.rotation);

// Get the transform from depth camera to OpenGL world at the timestamp of the cloud.
TangoSupport.TangoMatrixTransformData transform =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public interface OnTangoMeshesAvailableListener {
public TangoMesher(OnTangoMeshesAvailableListener callback) {
mCallback = callback;

mTango3dReconstruction = new Tango3dReconstruction(new Tango3dReconstructionConfig());
Tango3dReconstructionConfig config = new Tango3dReconstructionConfig();
config.putBoolean("generate_color", false);
mTango3dReconstruction = new Tango3dReconstruction(config);
mPointCloudBuffer = new TangoPointCloudManager();

mHandlerThread = new HandlerThread("mesherCallback");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,16 +469,19 @@ private float[] doFitPlane(float u, float v, double rgbTimestamp) {
// We need to calculate the transform between the color camera at the
// time the user clicked and the depth camera at the time the depth
// cloud was acquired.
TangoPoseData colorTdepthPose = TangoSupport.calculateRelativePose(
rgbTimestamp, TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR,
pointCloud.timestamp, TangoPoseData.COORDINATE_FRAME_CAMERA_DEPTH);
TangoPoseData depthTcolorPose = TangoSupport.calculateRelativePose(
pointCloud.timestamp, TangoPoseData.COORDINATE_FRAME_CAMERA_DEPTH,
rgbTimestamp, TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR);

float[] uv = getColorCameraUVFromDisplay(u, v, mColorCameraToDisplayAndroidRotation);

// Perform plane fitting with the latest available point cloud data.
double[] identityTranslation = {0.0, 0.0, 0.0};
double[] identityRotation = {0.0, 0.0, 0.0, 1.0};
IntersectionPointPlaneModelPair intersectionPointPlaneModelPair =
TangoSupport.fitPlaneModelNearPoint(pointCloud,
colorTdepthPose, uv[0], uv[1]);
identityTranslation, identityRotation, uv[0], uv[1],
depthTcolorPose.translation, depthTcolorPose.rotation);

// Get the transform from depth camera to OpenGL world at the timestamp of the cloud.
TangoSupport.TangoMatrixTransformData transform =
Expand Down

0 comments on commit ad5ce28

Please sign in to comment.