我正在尝试使用 Python 为 Houdini 构建一个自定义 LiDAR 导入器。到目前为止,Laspy 模块 ( https://pypi.org/project/laspy ) 通过在 Houdini 中读取和写入 *.*las 文件以及过滤分类来完成一项快速而快速的工作。
但是我必须读取和写入 *.*las 文件并再次导入,而不是立即获取 Houdini 中的点。
现在我想知道,是否可以获取 LiDAR 点 xyz 位置,以将它们提供给 Houdini 内部的点。
我试图在 Laspy 手册中找到有用的信息,但找不到任何示例或功能。
我用 *.*csv 文件做了类似的事情,它有 xyz 位置来构建一个简单的 GPS 阅读器,以将位置输出为 Houdini 中的点(使用 csv 模块)。
我附上了原始 .las(灰色)和过滤后的 output.las(红色屋顶)的屏幕截图以及来自 Laspy 手册的脚本示例。
也许代替 Laspy 有一个更优雅的解决方案?我在 Houdini 中使用 Python 3,但 2.7 也可以。
更新,这里的答案几乎完美 https://forums.odforce.net/topic/46475-custom-lidar-importer-with-python/?tab=comments#comment-217104:
from laspy.file import File
import numpy as np
node = hou.pwd()
geo = node.geometry()
file_path = geo.attribValue("file_path")
inFile = File(file_path, mode='r')
# --- load point position
coords = np.vstack((inFile.x, inFile.y, inFile.z)).transpose()
scale = np.array(inFile.header.scale)
offset = np.array(inFile.header.offset) # there is no offset in simple.las example from laspy library
# offset = np.array([1000, 20000, 100000]) # just for testing that offset works
# geo.setPointFloatAttribValues("P", np.concatenate(coords)) # same as Lidar Import SOP - seems that it ignores scale (and offset?)
geo.setPointFloatAttribValues("P", np.concatenate(coords*scale+offset))
# --- load color
color = np.vstack((inFile.red, inFile.green, inFile.blue)).transpose()
geo.addAttrib(hou.attribType.Point, "Cd", (1.0,1.0,1.0), False, False) # add color atttribute
geo.setPointFloatAttribValues("Cd", np.concatenate(color / 255.0)) # transform from 1-255 to 0.0-1.0 range)
唯一不起作用的是 inFile.classifications == x 这使 Houdini 崩溃。