#! /usr/bin/env python3 #command line arguments: # --help, -h, outputs usage of the program # -x, -y, outputs width and hight of the output image # --output, -o, name of output file. if there are multiple input files, there will be a number prepended to this. # after all comamnd line arguments, file or files(space seperated) to process. import numpy as np import sys, argparse, laspy, logging import seaborn as sns; sns.set_theme() import matplotlib.pyplot as plt from PIL import Image logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO) imgX=100 imgY=100 #TODO: make it iterate over multiple files. inFile = sys.argv[1] lasFile = laspy.file.File(inFile, mode = "r") #import each dimention scaled. x = lasFile.x y = lasFile.y z = lasFile.z maxes = np.array(lasFile.header.max)*np.array(lasFile.header.scale) mins = np.array(lasFile.header.min)*np.array(lasFile.header.scale) logging.debug(f'max values is {maxes}') logging.debug(f'min values is {mins}') intensity = lasFile.intensity #dimention that will be z(top down) dimention in final heatmap. TODO: auto detect this based on dimention with least variance. zDim=0 xDim=1 yDim=2 points = np.stack((x,y,z,intensity), axis=-1) #points should now look like #[[x,y,z,intensity] # [x,y,z,intensity] # ... # [x,y,z,intensity] # [x,y,z,intensity]] logging.debug(f'points is\n{points}') xRange = maxes[xDim]-mins[xDim] yRange = maxes[yDim]-mins[yDim] zRange = maxes[zDim]-mins[zDim] def sort(array): #sort by zDim column, first to last. logging.debug(f'zDim sliced points is\n{array[:,zDim]}') #the [::-1] reverses the resulting array, so that sortedPoints will be from biggest to smallest. ind = np.argsort(array[:,zDim])[::-1] sortedPoints = array[ind] logging.debug(f'sortedPoints is\n{sortedPoints}') return sortedPoints sortedPoints = sort(points) imageArray = np.zeros((imgX, imgY)) def scale(array, xRange, yRange, maxX, maxY): logging.debug(f'xRange is {xRange} and yRange is {yRange}') xScale = maxX/xRange yScale = maxY/yRange scaledArray = sortedPoints[:, 0:3] scaledArray[:,xDim]=scaledArray[:,xDim]-mins[xDim] scaledArray[:,xDim]=scaledArray[:,xDim]*xScale logging.debug(f'xmin in scaledArray is {scaledArray[:,xDim].min()}') logging.debug(f'xmin in scaledArray is {scaledArray[:,xDim].max()}') scaledArray[:,yDim]=scaledArray[:,yDim]-mins[yDim] scaledArray[:,yDim]=scaledArray[:,yDim]*yScale logging.debug(f'ymin in scaledArray is {scaledArray[:,yDim].min()}') logging.debug(f'ymin in scaledArray is {scaledArray[:,yDim].max()}') logging.debug(f'scaledArray is\n{scaledArray}') return scaledArray scaledArray = scale(points, xRange, yRange, imgX, imgY) def isInxyRange(xMin, xMax, yMin, yMax, xVal, yVal): return (xMin<=xVal) and (xVal