From 97a94e55d18f2b448864e016d8e821a9e4834a19 Mon Sep 17 00:00:00 2001 From: rmsare Date: Fri, 31 May 2019 11:25:56 -0700 Subject: [PATCH 1/2] Rename Python API functions for readability --- python/pymcc_lidar.pyx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/python/pymcc_lidar.pyx b/python/pymcc_lidar.pyx index f1ee578..678bbef 100644 --- a/python/pymcc_lidar.pyx +++ b/python/pymcc_lidar.pyx @@ -3,7 +3,7 @@ cimport pymcc_lidar cimport numpy as np from libc.stdlib cimport malloc, free -def pymcc_classification(np.ndarray[double, ndim = 2, mode = 'c'] xyz not None, scaleDomain2Spacing not None, curvatureThreshold not None): +def classify(np.ndarray[double, ndim = 2, mode = 'c'] xyz not None, scaleDomain2Spacing not None, curvatureThreshold not None): m_xyz = xyz.shape[0] n_xyz = xyz.shape[1] @@ -22,8 +22,6 @@ def pymcc_classification(np.ndarray[double, ndim = 2, mode = 'c'] xyz not None, x[i] = xyz[i, 0] y[i] = xyz[i, 1] z[i] = xyz[i, 2] - - with nogil: classification = pymcc_classify(x, y, z, n, resolution, thresh); @@ -34,7 +32,7 @@ def pymcc_classification(np.ndarray[double, ndim = 2, mode = 'c'] xyz not None, return np_classification -def pymcc_singlepass(np.ndarray[double, ndim = 2, mode = 'c'] xyz not None, scaleDomainSpacing not None): +def calculate_excess_height(np.ndarray[double, ndim = 2, mode = 'c'] xyz not None, scaleDomainSpacing not None): m_xyz = xyz.shape[0] n_xyz = xyz.shape[1] @@ -63,5 +61,3 @@ def pymcc_singlepass(np.ndarray[double, ndim = 2, mode = 'c'] xyz not None, scal free(y); free(z); return np_h - - From 98f221ada41c40f2b17caf2c9e2e5849b4f7c28f Mon Sep 17 00:00:00 2001 From: rmsare Date: Fri, 31 May 2019 11:30:22 -0700 Subject: [PATCH 2/2] Clean up formatting --- python/pymcc_lidar.pyx | 113 ++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 53 deletions(-) diff --git a/python/pymcc_lidar.pyx b/python/pymcc_lidar.pyx index 678bbef..3d32f05 100644 --- a/python/pymcc_lidar.pyx +++ b/python/pymcc_lidar.pyx @@ -3,61 +3,68 @@ cimport pymcc_lidar cimport numpy as np from libc.stdlib cimport malloc, free -def classify(np.ndarray[double, ndim = 2, mode = 'c'] xyz not None, scaleDomain2Spacing not None, curvatureThreshold not None): - m_xyz = xyz.shape[0] - n_xyz = xyz.shape[1] - - assert n_xyz == 3 - - cdef int * classification; - cdef double resolution = scaleDomain2Spacing; - cdef double thresh = curvatureThreshold; - cdef int32_t n = m_xyz; - cdef double *x = malloc(n * sizeof(double)); - cdef double *y = malloc(n * sizeof(double)); - cdef double *z = malloc(n * sizeof(double)); - - for i in range(n): - x[i] = xyz[i, 0] - y[i] = xyz[i, 1] - z[i] = xyz[i, 2] - - with nogil: - classification = pymcc_classify(x, y, z, n, resolution, thresh); +def classify(np.ndarray[double, ndim=2, mode='c'] xyz not None, + scaleDomain2Spacing not None, + curvatureThreshold not None): - cdef np.ndarray[int32_t, ndim=1] np_classification = np.empty(n, dtype=np.int32); - for i in range(n): - np_classification[i] = classification[i] - - return np_classification - -def calculate_excess_height(np.ndarray[double, ndim = 2, mode = 'c'] xyz not None, scaleDomainSpacing not None): - - m_xyz = xyz.shape[0] - n_xyz = xyz.shape[1] - - assert n_xyz == 3 - - cdef double *h; - cdef double resolution = scaleDomainSpacing; - cdef int32_t n = m_xyz; - cdef double *x = malloc(n * sizeof(double)); - cdef double *y = malloc(n * sizeof(double)); - cdef double *z = malloc(n * sizeof(double)); + m_xyz = xyz.shape[0] + n_xyz = xyz.shape[1] + + assert n_xyz == 3 + + cdef int * classification; + cdef double resolution = scaleDomain2Spacing; + cdef double thresh = curvatureThreshold; + cdef int32_t n = m_xyz; + cdef double *x = malloc(n * sizeof(double)); + cdef double *y = malloc(n * sizeof(double)); + cdef double *z = malloc(n * sizeof(double)); + + for i in range(n): + x[i] = xyz[i, 0] + y[i] = xyz[i, 1] + z[i] = xyz[i, 2] + + with nogil: + classification = pymcc_classify(x, y, z, n, resolution, thresh); - for i in range(n): - x[i] = xyz[i, 0] - y[i] = xyz[i, 1] - z[i] = xyz[i, 2] + cdef np.ndarray[int32_t, ndim=1] np_classification = np.empty(n, dtype=np.int32); + for i in range(n): + np_classification[i] = classification[i] + + return np_classification + + +def calculate_excess_height(np.ndarray[double, ndim=2, mode='c'] xyz not None, + scaleDomainSpacing not None): - with nogil: - h = pymcc_pass(x, y, z, n, resolution); - - cdef np.ndarray[double, ndim=1] np_h = np.empty(m_xyz); - for i in range(m_xyz): - np_h[i] = h[i] - free(x); - free(y); - free(z); + m_xyz = xyz.shape[0] + n_xyz = xyz.shape[1] + + assert n_xyz == 3 + + cdef double *h; + cdef double resolution = scaleDomainSpacing; + cdef int32_t n = m_xyz; + cdef double *x = malloc(n * sizeof(double)); + cdef double *y = malloc(n * sizeof(double)); + cdef double *z = malloc(n * sizeof(double)); + + for i in range(n): + x[i] = xyz[i, 0] + y[i] = xyz[i, 1] + z[i] = xyz[i, 2] + + with nogil: + h = pymcc_pass(x, y, z, n, resolution); + + cdef np.ndarray[double, ndim=1] np_h = np.empty(m_xyz); + for i in range(m_xyz): + np_h[i] = h[i] + + free(x); + free(y); + free(z); + return np_h