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

Commit fdfd71c

Browse files
committed
Merge pull request #50 from googlesamples/release-ancha
release-ancha
2 parents 7e7c91b + 6f3c94f commit fdfd71c

File tree

47 files changed

+295
-428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+295
-428
lines changed

AreaLearningJava/app/build.gradle

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ android {
2222
}
2323
}
2424

25-
if (project.hasProperty("Tango.signing")
26-
&& new File(project.property("Tango.signing") + "/tango.gradle").exists()) {
27-
apply from: project.property("Tango.signing") + "/tango.gradle";
28-
}
29-
3025
def external_lib_prefix = null
3126
if (project.hasProperty("Tango.catkin_devel_prefix")) {
3227
external_lib_prefix = project.property("Tango.catkin_devel_prefix")
@@ -35,14 +30,9 @@ if (project.hasProperty("Tango.catkin_devel_prefix")) {
3530
external_lib_prefix = "../../TangoReleaseLibs"
3631
}
3732

33+
3834
dependencies {
3935
compile fileTree(dir: external_lib_prefix + '/jar', include: ['**/*.jar'])
40-
compile(name: 'TangoUtils', ext: 'aar')
4136
compile 'org.rajawali3d:rajawali:1.0.294-SNAPSHOT@aar'
42-
}
43-
44-
repositories{
45-
flatDir{
46-
dirs external_lib_prefix + '/aar'
47-
}
37+
compile project(':TangoUtils')
4838
}

AreaLearningJava/app/src/main/java/com/projecttango/experiments/javaarealearning/ALStartActivity.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ protected void onCreate(Bundle savedInstanceState) {
5454
mLoadADFToggleButton.setOnClickListener(this);
5555
mStartButton.setOnClickListener(this);
5656
startActivityForResult(
57-
Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_MOTION_TRACKING), 0);
58-
startActivityForResult(
59-
Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_ADF_LOAD_SAVE), 1);
60-
57+
Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_ADF_LOAD_SAVE), 0);
6158
}
6259

6360
@Override
@@ -96,12 +93,6 @@ private void startADFListView() {
9693
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
9794
// Check which request we're responding to
9895
if (requestCode == 0) {
99-
// Make sure the request was successful
100-
if (resultCode == RESULT_CANCELED) {
101-
Toast.makeText(this, R.string.motiontracking_permission, Toast.LENGTH_SHORT).show();
102-
finish();
103-
}
104-
} else if (requestCode == 1) {
10596
// Make sure the request was successful
10697
if (resultCode == RESULT_CANCELED) {
10798
Toast.makeText(this, R.string.arealearning_permission, Toast.LENGTH_SHORT).show();

AreaLearningJava/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2-
32
buildscript {
43
repositories {
54
jcenter()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Apr 10 15:27:10 PDT 2013
1+
#Mon Oct 26 08:02:00 ART 2015
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip

AreaLearningJava/settings.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
include ':app'
1+
include ':app'
2+
include ':TangoUtils'
3+
project(':TangoUtils').projectDir = new File('../TangoUtils/app')

AugmentedRealitySample/app/build.gradle

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ android {
2323
}
2424
}
2525

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

3127
def external_lib_prefix = null
3228
if (project.hasProperty("Tango.catkin_devel_prefix")) {
@@ -36,14 +32,14 @@ if (project.hasProperty("Tango.catkin_devel_prefix")) {
3632
external_lib_prefix = "../../TangoReleaseLibs"
3733
}
3834

39-
dependencies {
40-
compile (name: 'TangoUtils', ext: 'aar')
41-
compile (name: 'tango_support_java_lib', ext: 'aar')
42-
compile 'org.rajawali3d:rajawali:1.0.294-SNAPSHOT@aar'
43-
}
44-
45-
repositories{
46-
flatDir{
35+
repositories {
36+
flatDir {
4737
dirs external_lib_prefix + '/aar'
4838
}
4939
}
40+
41+
dependencies {
42+
compile 'org.rajawali3d:rajawali:1.0.294-SNAPSHOT@aar'
43+
compile (name: 'tango_support_java_lib', ext: 'aar')
44+
compile project(':TangoUtils')
45+
}

AugmentedRealitySample/app/src/main/java/com/projecttango/experiments/augmentedrealitysample/AugmentedRealityActivity.java

Lines changed: 86 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package com.projecttango.experiments.augmentedrealitysample;
1717

18-
import java.util.ArrayList;
19-
2018
import android.app.Activity;
2119
import android.content.Intent;
2220
import android.os.Bundle;
@@ -31,11 +29,15 @@
3129
import com.google.atap.tangoservice.TangoConfig;
3230
import com.google.atap.tangoservice.TangoCoordinateFramePair;
3331
import com.google.atap.tangoservice.TangoEvent;
32+
import com.google.atap.tangoservice.TangoException;
33+
import com.google.atap.tangoservice.TangoOutOfDateException;
3434
import com.google.atap.tangoservice.TangoPoseData;
3535
import com.google.atap.tangoservice.TangoXyzIjData;
3636
import com.projecttango.rajawali.ar.TangoRajawaliView;
3737
import com.projecttango.tangosupport.TangoSupport;
3838

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

7172
@Override
7273
protected void onCreate(Bundle savedInstanceState) {
@@ -76,87 +77,66 @@ protected void onCreate(Bundle savedInstanceState) {
7677
mGLView.setSurfaceRenderer(mRenderer);
7778
mGLView.setOnTouchListener(this);
7879
mTango = new Tango(this);
79-
startActivityForResult(
80-
Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_MOTION_TRACKING),
81-
Tango.TANGO_INTENT_ACTIVITYCODE);
8280
setContentView(mGLView);
8381
}
8482

85-
@Override
86-
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
87-
// Check which request we're responding to
88-
if (requestCode == Tango.TANGO_INTENT_ACTIVITYCODE) {
89-
// Make sure the request was successful
90-
if (resultCode == RESULT_CANCELED) {
91-
Toast.makeText(this, "Motion Tracking Permissions Required!",
92-
Toast.LENGTH_SHORT).show();
93-
finish();
94-
} else {
95-
startAugmentedreality();
96-
mIsPermissionGranted = true;
97-
}
98-
}
99-
}
100-
10183
// Augmented reality view and renderer
10284
private void startAugmentedreality() {
10385
if (!mIsConnected) {
104-
mIsConnected = true;
105-
// Connect to color camera
106-
mGLView.connectToTangoCamera(mTango, TangoCameraIntrinsics.TANGO_CAMERA_COLOR);
107-
108-
// Use default configuration for Tango Service, plus low latency IMU integration.
109-
TangoConfig config = mTango.getConfig(TangoConfig.CONFIG_TYPE_DEFAULT);
110-
// NOTE: low latency integration is necessary to achieve a precise alignment of
111-
// virtual objects with the RBG image and produce a good AR effect.
112-
config.putBoolean(TangoConfig.KEY_BOOLEAN_LOWLATENCYIMUINTEGRATION, true);
113-
config.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);
114-
mTango.connect(config);
115-
116-
// No need to add any coordinate frame pairs since we are not using
117-
// pose data. So just initialize.
118-
ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
119-
mTango.connectListener(framePairs, new OnTangoUpdateListener() {
120-
@Override
121-
public void onPoseAvailable(TangoPoseData pose) {
122-
// We are not using OnPoseAvailable for this app
123-
}
124-
125-
@Override
126-
public void onFrameAvailable(int cameraId) {
127-
// Check if the frame available is for the camera we want and
128-
// update its frame on the view.
129-
if (cameraId == TangoCameraIntrinsics.TANGO_CAMERA_COLOR) {
130-
mGLView.onFrameAvailable();
86+
try {
87+
mIsConnected = true;
88+
// Connect to color camera.
89+
mGLView.connectToTangoCamera(mTango, TangoCameraIntrinsics.TANGO_CAMERA_COLOR);
90+
91+
// Use default configuration for Tango Service, plus low latency IMU integration.
92+
TangoConfig config = mTango.getConfig(TangoConfig.CONFIG_TYPE_DEFAULT);
93+
// NOTE: Low latency integration is necessary to achieve a precise alignment of
94+
// virtual objects with the RBG image and produce a good AR effect.
95+
config.putBoolean(TangoConfig.KEY_BOOLEAN_LOWLATENCYIMUINTEGRATION, true);
96+
config.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true);
97+
mTango.connect(config);
98+
99+
// No need to add any coordinate frame pairs since we are not using
100+
// pose data. So just initialize.
101+
ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>();
102+
mTango.connectListener(framePairs, new OnTangoUpdateListener() {
103+
@Override
104+
public void onPoseAvailable(TangoPoseData pose) {
105+
// We are not using OnPoseAvailable for this app.
106+
}
107+
108+
@Override
109+
public void onFrameAvailable(int cameraId) {
110+
// Check if the frame available is for the camera we want and
111+
// update its frame on the view.
112+
if (cameraId == TangoCameraIntrinsics.TANGO_CAMERA_COLOR) {
113+
mGLView.onFrameAvailable();
114+
}
131115
}
132-
}
133-
134-
@Override
135-
public void onXyzIjAvailable(TangoXyzIjData xyzIj) {
136-
// Get the device pose at the time the point cloud was acquired
137-
TangoCoordinateFramePair framePair = new TangoCoordinateFramePair(
138-
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
139-
TangoPoseData.COORDINATE_FRAME_DEVICE);
140-
TangoPoseData cloudPose = mTango.getPoseAtTime(xyzIj.timestamp, framePair);
141-
142-
// Save the cloud and point data for later use
143-
mPointCloudManager.updateXyzIjData(xyzIj, cloudPose);
144-
}
145-
146-
@Override
147-
public void onTangoEvent(TangoEvent event) {
148-
// We are not using OnPoseAvailable for this app
149-
}
150-
});
151-
152-
// Get extrinsics from device for use in transforms
153-
// This needs to be done after connecting Tango and listeners
154-
setupExtrinsics();
155-
156-
// Set-up point cloud plane fitting library helper class
157-
mPointCloudManager = new PointCloudManager(mTango.getCameraIntrinsics(
158-
TangoCameraIntrinsics.TANGO_CAMERA_COLOR));
159116

117+
@Override
118+
public void onXyzIjAvailable(TangoXyzIjData xyzIj) {
119+
// Save the cloud and point data for later use.
120+
mPointCloudManager.updateXyzIjData(xyzIj);
121+
}
122+
123+
@Override
124+
public void onTangoEvent(TangoEvent event) {
125+
// We are not using OnPoseAvailable for this app.
126+
}
127+
});
128+
129+
// Get extrinsics from device for use in transforms. This needs to be done after
130+
// connecting Tango and listeners.
131+
setupExtrinsics();
132+
133+
// Setup point cloud plane fitting library helper class.
134+
mPointCloudManager = new PointCloudManager(mTango.getCameraIntrinsics(
135+
TangoCameraIntrinsics.TANGO_CAMERA_COLOR));
136+
} catch (TangoOutOfDateException e) {
137+
Toast.makeText(getApplicationContext(), R.string.TangoOutOfDateException,
138+
Toast.LENGTH_SHORT).show();
139+
}
160140
}
161141
}
162142

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

174-
// Create Device to IMU Transform
154+
// Create device to IMU transform.
175155
framePair.targetFrame = TangoPoseData.COORDINATE_FRAME_DEVICE;
176156
TangoPoseData imuTdevicePose = mTango.getPoseAtTime(0.0, framePair);
177157

178-
// Create Depth camera to IMU Transform
158+
// Create depth camera to IMU transform.
179159
framePair.targetFrame = TangoPoseData.COORDINATE_FRAME_CAMERA_DEPTH;
180160
TangoPoseData imuTdepthPose = mTango.getPoseAtTime(0.0, framePair);
181161

@@ -196,22 +176,28 @@ protected void onPause() {
196176
@Override
197177
protected void onResume() {
198178
super.onResume();
199-
if (!mIsConnected && mIsPermissionGranted) {
179+
if (!mIsConnected) {
200180
startAugmentedreality();
201181
}
202182
}
203183

204184
@Override
205185
public boolean onTouch(View view, MotionEvent motionEvent) {
206186
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
207-
// Calculate click location in u,v (0;1) coordinates
187+
// Calculate click location in u,v (0;1) coordinates.
208188
float u = motionEvent.getX() / view.getWidth();
209189
float v = motionEvent.getY() / view.getHeight();
210190

211191
try {
212192
doFitPlane(u, v);
213-
} catch (Throwable t) {
214-
Log.e(TAG, "Exception measuring nomral", t);
193+
} catch (TangoException t) {
194+
Toast.makeText(getApplicationContext(), R.string.failed_measurement,
195+
Toast.LENGTH_SHORT).show();
196+
Log.e(TAG, getString(R.string.failed_measurement), t);
197+
} catch (SecurityException t) {
198+
Toast.makeText(getApplicationContext(), R.string.failed_permissions,
199+
Toast.LENGTH_SHORT).show();
200+
Log.e(TAG, getString(R.string.failed_permissions), t);
215201
}
216202
}
217203
return true;
@@ -223,15 +209,24 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
223209
* renderer to show a 3D object in that location.
224210
*/
225211
private void doFitPlane(float u, float v) {
226-
// Get the current device pose
212+
// NOTE: We request measurement at the latest available time. If we wanted to be even more
213+
// precise, we should use the timestamp of the RGB image rendered at the time the user
214+
// clicked the screen
215+
double measurementTimestamp = 0.0;
216+
217+
// Perform plane fitting with the latest available point cloud data.
218+
PointCloudManager.FitPlaneResult planeModelAndTimestamp =
219+
mPointCloudManager.fitPlane(u, v, measurementTimestamp);
220+
221+
// Get the device pose at the time the plane data was acquired.
227222
TangoCoordinateFramePair framePair = new TangoCoordinateFramePair(
228223
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
229224
TangoPoseData.COORDINATE_FRAME_DEVICE);
230-
TangoPoseData devicePose = mTango.getPoseAtTime(0.0, framePair);
225+
TangoPoseData devicePose =
226+
mTango.getPoseAtTime(planeModelAndTimestamp.cloudTimestamp, framePair);
231227

232-
// Perform plane fitting with the latest available point cloud data
233-
TangoSupport.IntersectionPointPlaneModelPair planeModel =
234-
mPointCloudManager.fitPlane(u, v, devicePose, mRenderer.getPoseCalculator());
235-
mRenderer.updateObjectPose(planeModel.intersectionPoint, planeModel.planeModel, devicePose);
228+
// Update the AR object location
229+
mRenderer.updateObjectPose(planeModelAndTimestamp.planeModelPair.intersectionPoint,
230+
planeModelAndTimestamp.planeModelPair.planeModel, devicePose);
236231
}
237232
}

0 commit comments

Comments
 (0)