如何在R中计算.ply文件边界框的尺寸?

omvjsjqw  于 2023-05-20  发布在  其他
关注(0)|答案(2)|浏览(100)

我有一些.ply文件,我需要计算它们的长度。所有网格都被定向为使得纵轴平行于边界框的z轴。
我还没能找到任何函数,将给予回轴尺寸的边界框的。ply文件。
我尝试使用rgl包。但它不读取.ply文件
有人知道我可以使用什么功能吗?
多谢了!
我厌倦了使用这个脚本。但它不适用于.ply文件。

library(rgl)

加载.ply文件:

my_ply <- readOBJ("my_file.ply")

获取z轴坐标:

z_coords <- my_ply$vb[,3]

计算z轴长度:

z_length <- diff(range(z_coords))

打印结果:

print(z_length)
h5qlskok

h5qlskok1#

我不太明白。

cgalMeshes包允许从PLY文件中读取网格,并允许计算网格的边界框(包含网格的最小等长方体)。这里有一个例子。

library(cgalMeshes)
# load the cyclide.ply file into a new mesh
mesh <- cgalMesh$new("cyclide.ply")
# compute its bounding box
bbox <- mesh$boundingBox()
# make a mesh of the bounding box in order to plot it
bxmesh <- isoCuboidMesh(bbox[["lcorner"]], bbox[["ucorner"]])
# convert the mesh of the cyclide to a rgl mesh
rmesh <- mesh$getMesh()
# plot the cyclide with its bounding box
library(rgl)
open3d(windowRect = 50 + c(0, 0, 512, 512))
view3d(0, -60)
shade3d(rmesh, color = "gold")
wire3d(bxmesh, color = "black")

h7wcgrx3

h7wcgrx32#

我刚刚发现如何在Python中做到这一点:

import os
import trimesh
folder_path = "C:/..."
# Iterate over files in folder
for filename in os.listdir(folder_path):
    # Check if file is a PLY file
    if filename.endswith(".ply"):
        file_path = os.path.join(folder_path, filename)
        # Load mesh from file
        mesh = trimesh.load(file_path)
        # Get bounding box dimensions
        bbox_dim = mesh.bounding_box.extents
        # Print results
        print(f"{filename}: Height={bbox_dim[2]}")

它就像一个魅力!

相关问题