I am trying to build a custom LiDAR importer for Houdini with Python. The Laspy Module (https://pypi.org/project/laspy) does so far a good and quick job by reading and writing *.*las files inside Houdini and also filtering the classifications.
But I have to read and write the *.*las file and import again instead of instantly getting the points inside Houdini.
Now I wonder, if I can fetch the LiDAR points xyz position, to feed them on points inside Houdini.
I was trying to find useful information in the Laspy manual, but couldn't find any example or function.
I made something similar with a *.*csv file, that has the xyz positions to build a simple GPS reader to output the positions as points in Houdini (with the csv module).
I attach a screenshot with the original .las (grey) and the filtered output.las (red roofs) and the script example from the Laspy manual.
Maybe instead of Laspy there is a more elegant Solution? I am using Python 3 in Houdini, but 2.7 works too.
Update, answer from here works almost perfect 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)
THe only thing that doesnt work yet is the inFile.classifications == x That is crashing Houdini.
Petr from Odforce finished the LiDAR Importer. https://forums.odforce.net/topic/46475-custom-lidar-importer-with-python/
To load and read the points:
and to load the attributes: