gpt4 book ai didi

android - 如何在 Project Tango 中使用实验性网格化 API

转载 作者:太空宇宙 更新时间:2023-11-03 10:42:02 25 4
gpt4 key购买 nike

我提前为我的长篇博文道歉。

我的目的是为 Project Tango Yellowstone 设备创建一个网格应用程序,以创建建筑物内部的 3D map 。我打算使用在最新版本的 tango-examples-c 代码中添加的实验性网格化 API。

我使用 point-cloud-jni-example (turing) 作为起点,到目前为止已经完成了以下工作:

  1. 在 point_cloud_app.cc 中设置 config_experimental_enable_scene_reconstruction 探戈配置参数(参见 docs )

    // Enable scene reconstruction
    ret = TangoConfig_setBool(tango_config_,
    config_experimental_enable_scene_reconstruction", true);
    if (ret != TANGO_SUCCESS) {
    LOGE("PointCloudApp: config_experimental_enable_scene_reconstruction() failed"
    "with error code: %d", ret);
    return ret;
    }
  2. 在 TangoJNINative.java 中添加了 extractMesh 原生方法

    // Extracts the full mesh from the scene reconstruction.
    public static native float extractMesh();
  3. 在 jni_interface.cc 中添加了匹配的 extractMesh 函数

    JNIEXPORT void JNICALL
    Java_com_projecttango_experiments_nativepointcloud_TangoJNINative_extractMesh(
    JNIEnv*, jobject) {
    app.ExtractMesh();
    }
  4. 在point_cloud_app.cc中添加ExtractMesh方法

    void PointCloudApp::ExtractMesh() {
    // see line 1245 of tango_client_api.h
    mesh_ptr = new TangoMesh_Experimental();
    TangoService_Experimental_extractMesh(mesh_ptr);
    mesh = *mesh_ptr;
    LOGE("PointCloudApp: num_vertices: %d", mesh.num_vertices);

    float float1, float2, float3;
    float1 = mesh.vertices[1][0];
    float2 = mesh.vertices[1][1];
    float3 = float1 + float2; // these lines show I can use the vertex data
    LOGE("PointCloudApp: First vertex, x: %f", mesh.vertices[1][0]); // this line causes app to crash; printing the vertex data seems to be the problem
    }
  5. 将 TangoMesh_Experimental 声明添加到 point_cloud_app.h

    // see line 1131 of tango_client_api.h
    TangoMesh_Experimental* mesh_ptr;
    TangoMesh_Experimental mesh;
  6. 添加了一个额外的按钮来调用 extractMesh native 方法。 (不显示这个,因为它非常简单)

作为引用,这里是来自 API 的 TangoMesh_Experimental 结构:

    // A mesh, described by vertices and face indices, with optional per-vertex
// normals and colors.
typedef struct TangoMesh_Experimental {
// Index into a three-dimensional fixed grid.
int32_t index[3];

// Array of vertices. Each vertex is an {x, y, z} coordinate triplet, in
// meters.
float (*vertices)[3];

// Array of faces. Each face is an index triplet into the vertices array.
uint32_t (*faces)[3];

// Array of per-vertex normals. Each normal is a normalized {x, y, z} vector.
float (*normals)[3];

// Array of per-vertex colors. Each color is a 4-tuple of 8-bit {R, G, B, A}
// values.
uint8_t (*colors)[4];

// Number of vertices, describing the size of the vertices array.
uint32_t num_vertices;

// Number of faces, describing the size of the faces array.
uint32_t num_faces;

// If true, each vertex will have an associated normal. In that case, the
// size of the normals array will be equal to num_vertices. Otherwise, the
// size of the normals array will be 0.
bool has_normals;

// If true, each vertex will have an associated color. In that case, the size
// of the colors array will be equal to num_vertices. Otherwise, the size of
// the colors array will be 0.
bool has_colors;
} TangoMesh_Experimental;

我目前对这个结构体的理解是:

  1. float (*vertices)[3]; 中的三个指针指向三个内存块开始处的地址,用于顶点的 x、y 和 z 坐标对于网格(法线和颜色颜色也是如此)。特定顶点由在三个数组中的特定索引处找到的 x、y 和 z 分量组成。

  2. 类似地,uint32_t (*faces)[3] 数组有三个指针指向三个内存块的开头,但这里的一组特定的三个元素包含索引号,这些索引号指示哪三个顶点(来自顶点数组(每个具有三个坐标))构成该面。

目前的状态是我能够提取网格,并将其中的一些打印到控制台,然后在没有错误的情况下崩溃

PointCloudApp: PointCloudApp: num_vertices: 8044 

如果我省略我在 point_cloud_app.cc(上面的#4)中添加的最后一行,应用程序不会崩溃。我能够访问顶点数据并对它做一些事情,但是使用 LOGE 打印它会导致 10 次中有 9 次崩溃。偶尔,它会正确打印值而不会崩溃。顶点数据是否有空洞或无效值?

我曾尝试将 test_float 从 JNI 返回到 java,但当我尝试这样做时它再次崩溃。

建议?

最佳答案

vertices 是点的动态数组,其中每个点都是一个 float[3]。试试这个例子:

for (int i = 0; i < mesh.num_vertices; ++i) {
printf("%d: x=%f y=%f z=%f\n", i, mesh.vertices[i][0],
mesh.vertices[i][1], mesh.vertices[i][2]);
}

如果您查看内存布局,它将是 x0 y0 z0 x1 y1 z1 等,每个都是 float 。

关于android - 如何在 Project Tango 中使用实验性网格化 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31994262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com