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

Commit

Permalink
release-ancha
Browse files Browse the repository at this point in the history
  • Loading branch information
jguomoto committed Nov 9, 2015
1 parent 7e7c91b commit 81a259e
Show file tree
Hide file tree
Showing 44 changed files with 272 additions and 401 deletions.
14 changes: 2 additions & 12 deletions AreaLearningJava/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ android {
}
}

if (project.hasProperty("Tango.signing")
&& new File(project.property("Tango.signing") + "/tango.gradle").exists()) {
apply from: project.property("Tango.signing") + "/tango.gradle";
}

def external_lib_prefix = null
if (project.hasProperty("Tango.catkin_devel_prefix")) {
external_lib_prefix = project.property("Tango.catkin_devel_prefix")
Expand All @@ -35,14 +30,9 @@ if (project.hasProperty("Tango.catkin_devel_prefix")) {
external_lib_prefix = "../../TangoReleaseLibs"
}


dependencies {
compile fileTree(dir: external_lib_prefix + '/jar', include: ['**/*.jar'])
compile(name: 'TangoUtils', ext: 'aar')
compile 'org.rajawali3d:rajawali:1.0.294-SNAPSHOT@aar'
}

repositories{
flatDir{
dirs external_lib_prefix + '/aar'
}
compile project(':TangoUtils')
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ protected void onCreate(Bundle savedInstanceState) {
mLoadADFToggleButton.setOnClickListener(this);
mStartButton.setOnClickListener(this);
startActivityForResult(
Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_MOTION_TRACKING), 0);
startActivityForResult(
Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_ADF_LOAD_SAVE), 1);

Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_ADF_LOAD_SAVE), 0);
}

@Override
Expand Down Expand Up @@ -96,12 +93,6 @@ private void startADFListView() {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == 0) {
// Make sure the request was successful
if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, R.string.motiontracking_permission, Toast.LENGTH_SHORT).show();
finish();
}
} else if (requestCode == 1) {
// Make sure the request was successful
if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, R.string.arealearning_permission, Toast.LENGTH_SHORT).show();
Expand Down
1 change: 0 additions & 1 deletion AreaLearningJava/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
Expand Down
4 changes: 2 additions & 2 deletions AreaLearningJava/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Mon Oct 26 08:02:00 ART 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
4 changes: 3 additions & 1 deletion AreaLearningJava/settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
include ':app'
include ':app'
include ':TangoUtils'
project(':TangoUtils').projectDir = new File('../TangoUtils/app')
20 changes: 8 additions & 12 deletions AugmentedRealitySample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ android {
}
}

if (project.hasProperty("Tango.signing")
&& new File(project.property("Tango.signing") + "/tango.gradle").exists()) {
apply from: project.property("Tango.signing") + "/tango.gradle";
}

def external_lib_prefix = null
if (project.hasProperty("Tango.catkin_devel_prefix")) {
Expand All @@ -36,14 +32,14 @@ if (project.hasProperty("Tango.catkin_devel_prefix")) {
external_lib_prefix = "../../TangoReleaseLibs"
}

dependencies {
compile (name: 'TangoUtils', ext: 'aar')
compile (name: 'tango_support_java_lib', ext: 'aar')
compile 'org.rajawali3d:rajawali:1.0.294-SNAPSHOT@aar'
}

repositories{
flatDir{
repositories {
flatDir {
dirs external_lib_prefix + '/aar'
}
}

dependencies {
compile 'org.rajawali3d:rajawali:1.0.294-SNAPSHOT@aar'
compile (name: 'tango_support_java_lib', ext: 'aar')
compile project(':TangoUtils')
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.projecttango.experiments.augmentedrealitysample;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
Expand All @@ -31,11 +29,15 @@
import com.google.atap.tangoservice.TangoConfig;
import com.google.atap.tangoservice.TangoCoordinateFramePair;
import com.google.atap.tangoservice.TangoEvent;
import com.google.atap.tangoservice.TangoException;
import com.google.atap.tangoservice.TangoOutOfDateException;
import com.google.atap.tangoservice.TangoPoseData;
import com.google.atap.tangoservice.TangoXyzIjData;
import com.projecttango.rajawali.ar.TangoRajawaliView;
import com.projecttango.tangosupport.TangoSupport;

import java.util.ArrayList;

/**
* An example showing how to build a very simple augmented reality application in Java.
* It uses Rajawali to do the rendering through the utility classes
Expand All @@ -44,7 +46,7 @@
* user clicks on the camera display, plane detection will be done on the surface closest to the
* click location and a 3D object will be placed in the scene anchored in that location.
* <p/>
* TangoRajawaliView is used in the same way as the TangoCamaraPreview: we first need initialize the
* TangoRajawaliView is used in the same way as the TangoCameraPreview: We first need initialize the
* TangoRajawaliView class with the activity's context and connect to the camera we want by using
* connectToTangoCamera method. Once the connection is established we need to update
* the view's texture by using the onFrameAvailable callbacks.
Expand All @@ -60,13 +62,12 @@
* the RGB camera.
*/
public class AugmentedRealityActivity extends Activity implements View.OnTouchListener {
private static final String TAG = "AugmentedRealityActiv";
private static final String TAG = AugmentedRealityActivity.class.getSimpleName();
private TangoRajawaliView mGLView;
private AugmentedRealityRenderer mRenderer;
private PointCloudManager mPointCloudManager;
private Tango mTango;
private boolean mIsConnected;
private boolean mIsPermissionGranted;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -76,87 +77,66 @@ protected void onCreate(Bundle savedInstanceState) {
mGLView.setSurfaceRenderer(mRenderer);
mGLView.setOnTouchListener(this);
mTango = new Tango(this);
startActivityForResult(
Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_MOTION_TRACKING),
Tango.TANGO_INTENT_ACTIVITYCODE);
setContentView(mGLView);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == Tango.TANGO_INTENT_ACTIVITYCODE) {
// Make sure the request was successful
if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Motion Tracking Permissions Required!",
Toast.LENGTH_SHORT).show();
finish();
} else {
startAugmentedreality();
mIsPermissionGranted = true;
}
}
}

// Augmented reality view and renderer
private void startAugmentedreality() {
if (!mIsConnected) {
mIsConnected = true;
// Connect to color camera
mGLView.connectToTangoCamera(mTango, TangoCameraIntrinsics.TANGO_CAMERA_COLOR);

// Use default configuration for Tango Service, plus low latency IMU integration.
TangoConfig config = mTango.getConfig(TangoConfig.CONFIG_TYPE_DEFAULT);
// 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);
config.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);
mTango.connect(config);

// No need to add any coordinate frame pairs since we are not using
// pose data. So just initialize.
ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
mTango.connectListener(framePairs, new OnTangoUpdateListener() {
@Override
public void onPoseAvailable(TangoPoseData pose) {
// We are not using OnPoseAvailable for this app
}

@Override
public void onFrameAvailable(int cameraId) {
// Check if the frame available is for the camera we want and
// update its frame on the view.
if (cameraId == TangoCameraIntrinsics.TANGO_CAMERA_COLOR) {
mGLView.onFrameAvailable();
try {
mIsConnected = true;
// Connect to color camera.
mGLView.connectToTangoCamera(mTango, TangoCameraIntrinsics.TANGO_CAMERA_COLOR);

// Use default configuration for Tango Service, plus low latency IMU integration.
TangoConfig config = mTango.getConfig(TangoConfig.CONFIG_TYPE_DEFAULT);
// 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);
config.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);
mTango.connect(config);

// No need to add any coordinate frame pairs since we are not using
// pose data. So just initialize.
ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
mTango.connectListener(framePairs, new OnTangoUpdateListener() {
@Override
public void onPoseAvailable(TangoPoseData pose) {
// We are not using OnPoseAvailable for this app.
}

@Override
public void onFrameAvailable(int cameraId) {
// Check if the frame available is for the camera we want and
// update its frame on the view.
if (cameraId == TangoCameraIntrinsics.TANGO_CAMERA_COLOR) {
mGLView.onFrameAvailable();
}
}
}

@Override
public void onXyzIjAvailable(TangoXyzIjData xyzIj) {
// Get the device pose at the time the point cloud was acquired
TangoCoordinateFramePair framePair = new TangoCoordinateFramePair(
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_DEVICE);
TangoPoseData cloudPose = mTango.getPoseAtTime(xyzIj.timestamp, framePair);

// Save the cloud and point data for later use
mPointCloudManager.updateXyzIjData(xyzIj, cloudPose);
}

@Override
public void onTangoEvent(TangoEvent event) {
// We are not using OnPoseAvailable for this app
}
});

// Get extrinsics from device for use in transforms
// This needs to be done after connecting Tango and listeners
setupExtrinsics();

// Set-up point cloud plane fitting library helper class
mPointCloudManager = new PointCloudManager(mTango.getCameraIntrinsics(
TangoCameraIntrinsics.TANGO_CAMERA_COLOR));

@Override
public void onXyzIjAvailable(TangoXyzIjData xyzIj) {
// Save the cloud and point data for later use.
mPointCloudManager.updateXyzIjData(xyzIj);
}

@Override
public void onTangoEvent(TangoEvent event) {
// We are not using OnPoseAvailable for this app.
}
});

// Get extrinsics from device for use in transforms. This needs to be done after
// connecting Tango and listeners.
setupExtrinsics();

// Setup point cloud plane fitting library helper class.
mPointCloudManager = new PointCloudManager(mTango.getCameraIntrinsics(
TangoCameraIntrinsics.TANGO_CAMERA_COLOR));
} catch (TangoOutOfDateException e) {
Toast.makeText(getApplicationContext(), R.string.TangoOutOfDateException,
Toast.LENGTH_SHORT).show();
}
}
}

Expand All @@ -165,17 +145,17 @@ public void onTangoEvent(TangoEvent event) {
* to be used later for transformations between frames.
*/
private void setupExtrinsics() {
// Create Camera to IMU Transform
// Create camera to IMU transform.
TangoCoordinateFramePair framePair = new TangoCoordinateFramePair();
framePair.baseFrame = TangoPoseData.COORDINATE_FRAME_IMU;
framePair.targetFrame = TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR;
TangoPoseData imuTrgbPose = mTango.getPoseAtTime(0.0, framePair);

// Create Device to IMU Transform
// Create device to IMU transform.
framePair.targetFrame = TangoPoseData.COORDINATE_FRAME_DEVICE;
TangoPoseData imuTdevicePose = mTango.getPoseAtTime(0.0, framePair);

// Create Depth camera to IMU Transform
// Create depth camera to IMU transform.
framePair.targetFrame = TangoPoseData.COORDINATE_FRAME_CAMERA_DEPTH;
TangoPoseData imuTdepthPose = mTango.getPoseAtTime(0.0, framePair);

Expand All @@ -196,22 +176,28 @@ protected void onPause() {
@Override
protected void onResume() {
super.onResume();
if (!mIsConnected && mIsPermissionGranted) {
if (!mIsConnected) {
startAugmentedreality();
}
}

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
// Calculate click location in u,v (0;1) coordinates
// Calculate click location in u,v (0;1) coordinates.
float u = motionEvent.getX() / view.getWidth();
float v = motionEvent.getY() / view.getHeight();

try {
doFitPlane(u, v);
} catch (Throwable t) {
Log.e(TAG, "Exception measuring nomral", t);
} catch (TangoException t) {
Toast.makeText(getApplicationContext(), R.string.failed_measurement,
Toast.LENGTH_SHORT).show();
Log.e(TAG, getString(R.string.failed_measurement), t);
} catch (SecurityException t) {
Toast.makeText(getApplicationContext(), R.string.failed_permissions,
Toast.LENGTH_SHORT).show();
Log.e(TAG, getString(R.string.failed_permissions), t);
}
}
return true;
Expand All @@ -223,15 +209,24 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
* renderer to show a 3D object in that location.
*/
private void doFitPlane(float u, float v) {
// Get the current device pose
// NOTE: We request measurement at the latest available time. If we wanted to be even more
// precise, we should use the timestamp of the RGB image rendered at the time the user
// clicked the screen
double measurementTimestamp = 0.0;

// Perform plane fitting with the latest available point cloud data.
PointCloudManager.FitPlaneResult planeModelAndTimestamp =
mPointCloudManager.fitPlane(u, v, measurementTimestamp);

// Get the device pose at the time the plane data was acquired.
TangoCoordinateFramePair framePair = new TangoCoordinateFramePair(
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_DEVICE);
TangoPoseData devicePose = mTango.getPoseAtTime(0.0, framePair);
TangoPoseData devicePose =
mTango.getPoseAtTime(planeModelAndTimestamp.cloudTimestamp, framePair);

// Perform plane fitting with the latest available point cloud data
TangoSupport.IntersectionPointPlaneModelPair planeModel =
mPointCloudManager.fitPlane(u, v, devicePose, mRenderer.getPoseCalculator());
mRenderer.updateObjectPose(planeModel.intersectionPoint, planeModel.planeModel, devicePose);
// Update the AR object location
mRenderer.updateObjectPose(planeModelAndTimestamp.planeModelPair.intersectionPoint,
planeModelAndTimestamp.planeModelPair.planeModel, devicePose);
}
}
Loading

0 comments on commit 81a259e

Please sign in to comment.