From 4fe916a23b756322392155a01187d5d533b2962a Mon Sep 17 00:00:00 2001 From: gabriel venberg Date: Mon, 8 Mar 2021 20:38:31 -0600 Subject: [PATCH] old algorithm ran in O(a*b*c) time, where a is the number of points in the LIDAR file, b and c are the dimentions of the resulting heatmap. new algorithm runs in O(a) time... before, it took ~5 days on my machine to make a 1000*1000 heatmap. now it takes 5 seconds to make ANY size image. (the graph making library takes a bit longer, but it is very little compared to mapping the image array.) --- outputHightMap.py | 120 ++++++++++++++++++---------------------------- 1 file changed, 46 insertions(+), 74 deletions(-) diff --git a/outputHightMap.py b/outputHightMap.py index a085a0b..ab5837a 100755 --- a/outputHightMap.py +++ b/outputHightMap.py @@ -12,110 +12,82 @@ import seaborn as sns; sns.set_theme() import matplotlib.pyplot as plt from PIL import Image -logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', level=logging.INFO) +logging.basicConfig(format='%(asctime)s:%(message)s', level=logging.INFO) +#logging.basicConfig(format='%(asctime)s:%(message)s', level=logging.DEBUG) -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 +def scale(array, desiredmaxX, desiredmaxY): + logging.debug(f'xMax is {np.max(array[:,xDim])} and xMin is {np.min(array[:,xDim])}') + logging.debug(f'yMax is {np.max(array[:,yDim])} and yMin is {np.min(array[:,yDim])}') + ax=desiredmaxX/(np.max(array[:,xDim])-np.min(array[:,xDim])) + bx=-ax*np.min(array[:,xDim]) + ay=desiredmaxY/(np.max(array[:,yDim])-np.min(array[:,yDim])) + by=-ay*np.min(array[:,yDim]) -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()}') + #slice indexes 0-2 from the second dimention + array[:,xDim]=ax*array[:,xDim]+bx + array[:,yDim]=ay*array[:,yDim]+by - 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 + logging.debug(f'array is\n{array}') + logging.debug(f'xMax is {np.max(array[:,xDim])} and xMin is {np.min(array[:,xDim])}') + logging.debug(f'yMax is {np.max(array[:,yDim])} and yMin is {np.min(array[:,yDim])}') -def isInxyRange(xMin, xMax, yMin, yMax, xVal, yVal): - return (xMin<=xVal) and (xVal