Skip to content

Commit

Permalink
adding pointcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
boehm-e committed Apr 19, 2019
1 parent 8f634be commit a4f5343
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
23 changes: 20 additions & 3 deletions ofxARCoreLib/src/main/java/cc/ofxarcorelib/ofxARCoreLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.ar.core.Pose;
import com.google.ar.core.Session;
import com.google.ar.core.TrackingState;
import com.google.ar.core.PointCloud;
import com.google.ar.core.exceptions.CameraNotAvailableException;
import com.google.ar.core.exceptions.NotTrackingException;
import com.google.ar.core.exceptions.UnavailableApkTooOldException;
Expand Down Expand Up @@ -76,6 +77,11 @@ public class ofxARCoreLib extends OFAndroidObject {
public float verticalAngle;
public float screenDpi;

// point cloud
private PointCloud pointcloud_data = null;
private FloatBuffer pcloud_buffer;
private float[] pcloud_array;


public void setup(int texId, final int width, final int height){
Context context = OFAndroid.getContext();
Expand All @@ -85,15 +91,13 @@ public void setup(int texId, final int width, final int height){

CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
calculateFOV(manager);
Log.d("DEBUG_ERWAN", "h : " + horizontalAngle + " w : " + verticalAngle);

// calculate dpi
DisplayMetrics displaymetrics = new DisplayMetrics();

activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);

screenDpi = context.getResources().getDisplayMetrics().xdpi;
Log.d("DEBUG_ERWAN", "dpi : " + screenDpi);



Expand Down Expand Up @@ -160,7 +164,13 @@ public float[] getViewMatrix(){
return mViewMatrix;
}

public float[] getProjectionMatrix(float near, float far){
/* point cloud and plane @kashimAstro */
public float[] getPointCloud()
{
return pcloud_array;
}

public float[] getProjectionMatrix(float near, float far){
if(mIsReady) {
try {
mSession.update().getCamera().getProjectionMatrix(mProjectionMatrix, 0, near, far);
Expand Down Expand Up @@ -223,6 +233,13 @@ public void update(){
mPose = frame.getCamera().getPose();
frame.getCamera().getViewMatrix(mViewMatrix, 0);


/* point cloud @kashimAstro */
pointcloud_data = frame.acquirePointCloud();
pcloud_buffer = pointcloud_data.getPoints();
pcloud_array = new float[pcloud_buffer.limit()];
pcloud_buffer.get(pcloud_array);

mIsReady = true;

// final float lightIntensity = frame.getLightEstimate().getPixelIntensity();
Expand Down
14 changes: 14 additions & 0 deletions src/ofxARCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@ float ofxARCore::getCameraFOV() {
return fov;
}

/* point cloud and plane */
std::vector<float> ofxARCore::getPointCloud() {
JNIEnv *env = ofGetJNIEnv();
jfloatArray data = (jfloatArray) env->CallObjectMethod(javaTango,
env->GetMethodID(javaClass,"getPointCloud","()[F"));

jsize size = env->GetArrayLength(data);
std::vector<float> result;
result.resize((int)size);
env->GetFloatArrayRegion(data, 0, size, (jfloat*)&result[0]);
return result;
}


float ofxARCore::getDpi() {

JNIEnv *env = ofGetJNIEnv();
Expand Down
2 changes: 2 additions & 0 deletions src/ofxARCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class ofxARCore : ofThread{
ofMatrix4x4 getViewMatrix();
ofMatrix4x4 getProjectionMatrix(float near=0.1f, float far=100.0f);

std::vector<float> getPointCloud(); /* get point cloud arcore */

ofTexture texture;

private:
Expand Down

0 comments on commit a4f5343

Please sign in to comment.