我正在尝试用Python为Houdini构建一个自定义激光雷达导入器。 到目前为止,Laspy模块(https://pypi.org/project/laspy)通过读取和写入Houdini中的*.las文件以及过滤分类,做了一件又好又快的工作
但是我必须读写*.las文件并再次导入,而不是立即在Houdini中获取点
现在我想知道,我是否可以获取激光雷达点xyz位置,以便在胡迪尼内部的点上提供数据
我试图在Laspy手册中找到有用的信息,但找不到任何示例或函数
我用一个*.csv文件做了类似的事情,它有xyz位置来构建一个简单的GPS读取器,将位置输出为Houdini中的点(使用csv模块)
我附加了一个带有原始.las(灰色)和过滤后的output.las(红色屋顶)的屏幕截图,以及Laspy手册中的脚本示例
也许有一个更优雅的解决方案取代Laspy? 我在Houdini中使用Python3,但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)
唯一不起作用的是infle.classifications==x 这是胡迪尼的崩溃
Odforce的Petr完成了激光雷达导入程序。 https://forums.odforce.net/topic/46475-custom-lidar-importer-with-python/
要加载和读取点,请执行以下操作:
并加载属性:
相关问题 更多 >
编程相关推荐