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 #95 from googlesamples/release-gankino
Browse files Browse the repository at this point in the history
release gankino
  • Loading branch information
jguomoto authored Apr 7, 2017
2 parents a9a709d + 91a67dc commit daba2ad
Show file tree
Hide file tree
Showing 22 changed files with 313 additions and 197 deletions.
Binary file modified TangoReleaseLibs/aar/tango_support_java_lib.aar
100644 → 100755
Binary file not shown.
Binary file modified TangoReleaseLibs/aar/tango_ux_support_library.aar
100644 → 100755
Binary file not shown.
Binary file modified TangoReleaseLibs/jar/tango_java_lib.jar
100644 → 100755
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public void onDisplayRemoved(int displayId) {
@Override
protected void onStart() {
super.onStart();
mSurfaceView.onResume();

// 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.
Expand All @@ -142,7 +141,7 @@ protected void onStart() {
@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
Expand Down Expand Up @@ -340,6 +339,7 @@ public void onPreFrame(long sceneTime, double deltaTime) {
TangoPoseData.COORDINATE_FRAME_AREA_DESCRIPTION,
TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR,
TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL,
TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL,
mDisplayRotation);
if (lastFramePose.statusCode == TangoPoseData.POSE_VALID) {
// Update the camera pose from the renderer
Expand Down
2 changes: 1 addition & 1 deletion java_basic_examples/hello_area_description/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 19
compileSdkVersion 23
buildToolsVersion "21.1.2"

defaultConfig {
Expand Down
2 changes: 1 addition & 1 deletion java_basic_examples/hello_video/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 19
compileSdkVersion 23
buildToolsVersion "21.1.2"

defaultConfig {
Expand Down
2 changes: 1 addition & 1 deletion java_examples_utils/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 19
compileSdkVersion 23
buildToolsVersion "21.1.2"

defaultConfig {
Expand Down
19 changes: 19 additions & 0 deletions java_floor_plan_reconstruction_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This sample shows how to use the experimental Floor plan API from the 3D
Reconstruction packages.

This sample is a small Java application that creates simple 2D floor
plans. This application uses the depth sensor to scan the rooms
and gets simplified 2D floor plans in the form of polygons through
callbacks. These polygons are drawn on a SurfaceView using regular
Android canvas 2D drawing functions.

The most important code parts to note are the following:
- TangoFloorplanner.java is a convenience class that abstracts some of
the mechanics of the Floor plan reconstruction library. It uses
a separate thread to push point clouds through the reconstruction
library and generates callback events whenever new floor plan polygons
are available for consumption. You can reuse this class for your own
application.
- In FloorPlanReconstructionActivity.java, you can see how to tie this
TangoFloorplanner utility with the rest of the Tango lifecycle,
callback functions and events.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.projecttango.examples.java.floorplanreconstruction;

import com.google.atap.tango.reconstruction.TangoFloorplanLevel;
import com.google.atap.tango.reconstruction.TangoPolygon;
import com.google.atap.tangoservice.Tango;
import com.google.atap.tangoservice.TangoCameraIntrinsics;
Expand All @@ -36,6 +37,7 @@
import android.content.pm.PackageManager;
import android.hardware.display.DisplayManager;
import android.os.Bundle;
import android.support.annotation.UiThread;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
Expand All @@ -54,10 +56,10 @@
/**
* An example showing how to use the 3D reconstruction floor planning features to create a
* floor plan in Java.
*
* <p/>
* This sample uses the APIs that extract a set of simplified 2D polygons and renders them on a
* SurfaceView. The device orientation is used to automatically translate and rotate the map.
*
* <p/>
* Rendering is done in a simplistic way, using the canvas API over a SurfaceView.
*/
public class FloorPlanReconstructionActivity extends Activity implements FloorplanView
Expand All @@ -75,6 +77,8 @@ public class FloorPlanReconstructionActivity extends Activity implements Floorpl
private Button mPauseButton;
private FloorplanView mFloorplanView;
private TextView mAreaText;
private TextView mHeightText;
private TextView mDistanceText;

private int mDisplayRotation = 0;

Expand All @@ -93,6 +97,8 @@ protected void onCreate(Bundle savedInstanceState) {
mFloorplanView = (FloorplanView) findViewById(R.id.floorplan);
mFloorplanView.registerCallback(this);
mAreaText = (TextView) findViewById(R.id.area_text);
mHeightText = (TextView) findViewById(R.id.height_text);
mDistanceText = (TextView) findViewById(R.id.floordistance_text);

DisplayManager displayManager = (DisplayManager) getSystemService(DISPLAY_SERVICE);
if (displayManager != null) {
Expand Down Expand Up @@ -166,6 +172,12 @@ public void run() {
startupTango();
mIsConnected = true;
mIsPaused = false;
runOnUiThread(new Runnable() {
@Override
public void run() {
pauseOrResumeFloorplanning(mIsPaused);
}
});
setDisplayRotation();
} catch (TangoOutOfDateException e) {
Log.e(TAG, getString(R.string.exception_out_of_date), e);
Expand Down Expand Up @@ -206,8 +218,10 @@ private void startupTango() {
mTangoFloorplanner = new TangoFloorplanner(new TangoFloorplanner
.OnFloorplanAvailableListener() {
@Override
public void onFloorplanAvailable(List<TangoPolygon> polygons) {
public void onFloorplanAvailable(List<TangoPolygon> polygons,
List<TangoFloorplanLevel> levels) {
mFloorplanView.setFloorplan(polygons);
updateFloorAndCeiling(levels);
calculateAndUpdateArea(polygons);
}
});
Expand Down Expand Up @@ -268,6 +282,7 @@ public void onPreDrawing() {
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_DEVICE,
TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL,
TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL,
mDisplayRotation);

if (devicePose.statusCode == TangoPoseData.POSE_VALID) {
Expand Down Expand Up @@ -303,7 +318,7 @@ private static float yRotationFromQuaternion(float x, float y, float z, float w)
*/
private void calculateAndUpdateArea(List<TangoPolygon> polygons) {
double area = 0;
for (TangoPolygon polygon: polygons) {
for (TangoPolygon polygon : polygons) {
if (polygon.layer == TangoPolygon.TANGO_3DR_LAYER_SPACE) {
// If there is more than one free space polygon, only count those
// that have an area larger than two square meters to suppress unconnected
Expand All @@ -322,15 +337,58 @@ public void run() {
});
}

/**
* Given the Floorplan levels, calculate the ceiling height and the current distance from the
* device to the floor.
*/
private void updateFloorAndCeiling(List<TangoFloorplanLevel> levels) {
if (levels.size() > 0) {
// Currently only one level is supported by the floorplanning API.
TangoFloorplanLevel level = levels.get(0);
float ceilingHeight = level.maxZ - level.minZ;
final String ceilingHeightText = String.format("%.2f", ceilingHeight);
// Query current device pose and calculate the distance from it to the floor.
TangoPoseData devicePose;
// Synchronize against disconnecting while using the service.
synchronized (FloorPlanReconstructionActivity.this) {
// Don't execute any Tango API actions if we're not connected to
// the service.
if (!mIsConnected) {
return;
}
devicePose = TangoSupport.getPoseAtTime(0.0,
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_DEVICE,
TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL,
TangoSupport.TANGO_SUPPORT_ENGINE_OPENGL,
mDisplayRotation);
}
float devToFloorDistance = devicePose.getTranslationAsFloats()[1] - level.minZ;
final String distanceText = String.format("%.2f", devToFloorDistance);
runOnUiThread(new Runnable() {
@Override
public void run() {
mHeightText.setText(ceilingHeightText);
mDistanceText.setText(distanceText);
}
});
}
}

public void onPauseButtonClick(View v) {
if (mIsPaused) {
mIsPaused = !mIsPaused;
pauseOrResumeFloorplanning(mIsPaused);
}

@UiThread
private void pauseOrResumeFloorplanning(boolean isPaused){
if (!isPaused) {
mTangoFloorplanner.startFloorplanning();
mPauseButton.setText("Pause");
} else {
mTangoFloorplanner.stopFloorplanning();
mPauseButton.setText("Resume");
}
mIsPaused = !mIsPaused;
}

public void onClearButtonClicked(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.projecttango.examples.java.floorplanreconstruction;

import com.google.atap.tango.reconstruction.TangoFloorplanLevel;
import com.google.atap.tango.reconstruction.TangoPolygon;

import android.content.Context;
Expand Down Expand Up @@ -246,7 +247,7 @@ private void doDraw(Canvas canvas) {
}

/**
* Sets the new floorplan polygons model.
* Sets the new floorplan polygons model and levels.
*/
public void setFloorplan(List<TangoPolygon> polygons) {
mPolygons = polygons;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.atap.tango.reconstruction.Tango3dReconstruction;
import com.google.atap.tango.reconstruction.Tango3dReconstructionConfig;
import com.google.atap.tango.reconstruction.TangoFloorplanLevel;
import com.google.atap.tango.reconstruction.TangoPolygon;
import com.google.atap.tangoservice.Tango;
import com.google.atap.tangoservice.TangoCameraIntrinsics;
Expand Down Expand Up @@ -58,7 +59,7 @@ public class TangoFloorplanner extends Tango.OnTangoUpdateListener {
* Callback for when meshes are available.
*/
public interface OnFloorplanAvailableListener {
void onFloorplanAvailable(List<TangoPolygon> polygons);
void onFloorplanAvailable(List<TangoPolygon> polygons, List<TangoFloorplanLevel> levels);
}

public TangoFloorplanner(OnFloorplanAvailableListener callback) {
Expand All @@ -84,6 +85,8 @@ public TangoFloorplanner(OnFloorplanAvailableListener callback) {
mRunnableCallback = new Runnable() {
@Override
public void run() {
List<TangoPolygon> polygons;
List<TangoFloorplanLevel> levels;
// Synchronize access to mTango3dReconstruction. This runs in TangoFloorplanner
// thread.
synchronized (TangoFloorplanner.this) {
Expand All @@ -101,6 +104,7 @@ public void run() {
TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE,
TangoPoseData.COORDINATE_FRAME_CAMERA_DEPTH,
TangoSupport.TANGO_SUPPORT_ENGINE_TANGO,
TangoSupport.TANGO_SUPPORT_ENGINE_TANGO,
TangoSupport.ROTATION_IGNORED);
if (depthPose.statusCode != TangoPoseData.POSE_VALID) {
Log.e(TAG, "couldn't extract a valid depth pose");
Expand All @@ -111,11 +115,13 @@ public void run() {
mTango3dReconstruction.updateFloorplan(cloudData, depthPose);

// Extract the full set of floorplan polygons.
List<TangoPolygon> polygons = mTango3dReconstruction.extractFloorplan();
polygons = mTango3dReconstruction.extractFloorplan();

// Provide the new floorplan polygons to the app via callback.
mCallback.onFloorplanAvailable(polygons);
// Extract the full set of floorplan levels.
levels = mTango3dReconstruction.extractFloorplanLevels();
}
// Provide the new floorplan polygons to the app via callback.
mCallback.onFloorplanAvailable(polygons, levels);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,49 @@
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<TextView
android:id="@+id/height_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ceiling height [m]: "
android:layout_above="@+id/floordistance_label"
android:layout_toStartOf="@+id/height_text"
/>

<TextView
android:id="@+id/height_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="n/a"
android:layout_above="@+id/floordistance_label"
android:layout_alignParentEnd="true"
android:paddingRight="5dp"
/>

<TextView
android:id="@+id/floordistance_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Distance from device to the floor [m]: "
android:layout_above="@+id/area_label"
android:layout_toStartOf="@+id/floordistance_text"
/>

<TextView
android:id="@+id/floordistance_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="n/a"
android:layout_above="@+id/area_label"
android:layout_alignParentEnd="true"
android:paddingRight="5dp"
/>

<TextView
android:id="@+id/area_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Area (m2): "
android:text="Area [m2]: "
android:layout_alignLeft="@+id/pause_button"
android:layout_above="@+id/pause_button"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import android.hardware.display.DisplayManager;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.support.annotation.UiThread;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
Expand Down Expand Up @@ -146,6 +147,12 @@ public void run() {
startupTango();
mIsConnected = true;
mIsPaused = false;
runOnUiThread(new Runnable() {
@Override
public void run() {
pauseOrResumeReconstruction(mIsPaused);
}
});
setDisplayRotation();
} catch (TangoOutOfDateException e) {
Log.e(TAG, getString(R.string.exception_out_of_date), e);
Expand Down Expand Up @@ -319,14 +326,19 @@ public void preRender() {

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

@UiThread
private void pauseOrResumeReconstruction(boolean isPaused){
if (!isPaused) {
mTangoMesher.startSceneReconstruction();
mPauseButton.setText("Pause");
} else {
mTangoMesher.stopSceneReconstruction();
mPauseButton.setText("Resume");
}
}

Expand Down
Loading

0 comments on commit daba2ad

Please sign in to comment.