From 0f84acfb1862279dbd17618c4b7a43f312a1cc07 Mon Sep 17 00:00:00 2001 From: Maciej Wielgosz <maciej.wielgosz@nibio.no> Date: Tue, 17 Jan 2023 09:51:47 +0100 Subject: [PATCH] helper script for density and volume --- helpers/density_and_volume_of_pc.py | 61 +++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 helpers/density_and_volume_of_pc.py diff --git a/helpers/density_and_volume_of_pc.py b/helpers/density_and_volume_of_pc.py new file mode 100644 index 0000000..42f19bf --- /dev/null +++ b/helpers/density_and_volume_of_pc.py @@ -0,0 +1,61 @@ +import argparse +import laspy +import numpy as np + + +class DensityAndVolumeOfPc: + ''' + This class is used to find the density of the pc + ''' + + def __init__(self, las_path)->None: + self.las_path = las_path + + def __call__(self)->float: + ''' + This function is used to find the density of the pc + ''' + # load the point cloud + pc = laspy.read(self.las_path) + + # get the points + points = np.vstack((pc.x, pc.y, pc.z)).transpose() + + # get the bounding box + bounding_box = np.array([points.min(axis=0), points.max(axis=0)]) + + # get the volume of the bounding box + volume = np.prod(bounding_box[1] - bounding_box[0]) + + # get the number of points + n_points = points.shape[0] + + # get the density + density = n_points / volume + + # put desity and volume in a dictionary + dict = { + "density": density, + "volume": volume + } + + return dict, + + +if __name__ == "__main__": + # use argparse to get the arguments + + parser = argparse.ArgumentParser() + parser.add_argument("--las_path", type=str, default="") + args = parser.parse_args() + + # run the main function + density_and_volume_of_pc = DensityAndVolumeOfPc( + las_path = args.las_path + ) + + # print desity and volume in a nice way + out_dict = density_and_volume_of_pc() + print("Density: " + str(out_dict[0]["density"])) + print("Volume: " + str(out_dict[0]["volume"])) + -- GitLab