From 68b40ed5dd134630322f07522979ea0da67580c6 Mon Sep 17 00:00:00 2001 From: George Hilley Date: Mon, 13 May 2019 21:45:53 -0700 Subject: [PATCH] debugged bindings --- libmcc_lidar/Algorithm.cpp | 2 +- libmcc_lidar/src/mcc.cpp | 11 +++---- python/pymcc_lidar.pyx | 61 +++++++++++++++++++++++--------------- 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/libmcc_lidar/Algorithm.cpp b/libmcc_lidar/Algorithm.cpp index f6b11d2..2fa37ab 100644 --- a/libmcc_lidar/Algorithm.cpp +++ b/libmcc_lidar/Algorithm.cpp @@ -73,8 +73,8 @@ namespace mcc // points not yet classified - UnclassifiedPoints splinePoints(points); IUnclassifiedPoints & U = points; + UnclassifiedPoints splinePoints(points); // Locate points that are vertically stacked (at same x,y coordinates), and // within each stack, classify all points but the lowest one as non-ground. diff --git a/libmcc_lidar/src/mcc.cpp b/libmcc_lidar/src/mcc.cpp index cde7e0f..fe868df 100644 --- a/libmcc_lidar/src/mcc.cpp +++ b/libmcc_lidar/src/mcc.cpp @@ -29,11 +29,12 @@ shared_ptr readPoints(double *x, for(int i=0; i < n; i++) { - (*pts)[i].setCoordinates(XyzPoint(x[n], y[n], z[n])); - xyExtent.minX = (std::isnan(xyExtent.minX) | (x[n] < xyExtent.minX)) ? x[n] : xyExtent.minX; - xyExtent.maxX = (std::isnan(xyExtent.maxX) | (x[n] > xyExtent.maxX)) ? x[n] : xyExtent.maxX; - xyExtent.minY = (std::isnan(xyExtent.minY) | (y[n] < xyExtent.minY)) ? y[n] : xyExtent.minY; - xyExtent.maxY = (std::isnan(xyExtent.maxY) | (y[n] > xyExtent.maxY)) ? y[n] : xyExtent.maxY; + (*pts)[i].setCoordinates(XyzPoint(x[i], y[i], z[i])); + + xyExtent.minX = (std::isnan(xyExtent.minX) | (x[i] < xyExtent.minX)) ? x[i] : xyExtent.minX; + xyExtent.maxX = (std::isnan(xyExtent.maxX) | (x[i] > xyExtent.maxX)) ? x[i] : xyExtent.maxX; + xyExtent.minY = (std::isnan(xyExtent.minY) | (y[i] < xyExtent.minY)) ? y[i] : xyExtent.minY; + xyExtent.maxY = (std::isnan(xyExtent.maxY) | (y[i] > xyExtent.maxY)) ? y[i] : xyExtent.maxY; } return pts; diff --git a/python/pymcc_lidar.pyx b/python/pymcc_lidar.pyx index 247787a..f1ee578 100644 --- a/python/pymcc_lidar.pyx +++ b/python/pymcc_lidar.pyx @@ -3,52 +3,65 @@ cimport pymcc_lidar cimport numpy as np from libc.stdlib cimport malloc, free -def pymcc_classification(np.ndarray[double, ndim = 1, mode = 'c'] x not None, np.ndarray[double, ndim = 1, mode = 'c'] y not None, np.ndarray[double, ndim = 1, mode = 'c'] z not None, scaleDomain2Spacing not None, curvatureThreshold not None): +def pymcc_classification(np.ndarray[double, ndim = 2, mode = 'c'] xyz not None, scaleDomain2Spacing not None, curvatureThreshold not None): - m_x = x.size - m_y = y.size - m_z = z.size + m_xyz = xyz.shape[0] + n_xyz = xyz.shape[1] - assert m_x == m_y - assert m_y == m_z + 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] + - cdef double *xd = &x[0]; - cdef double *yd = &y[0]; - cdef double *zd = &z[0]; - cdef int32_t n = m_x; with nogil: - classification = pymcc_classify(xd, yd, zd, n, resolution, thresh); + classification = pymcc_classify(x, y, z, n, resolution, thresh); - cdef np.ndarray[np.int32_t, ndim=1] np_classification = np.empty(m_x, dtype=np.int32); - for i in range(m_x): + 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 pymcc_singlepass(np.ndarray[double, ndim = 1, mode = 'c'] x not None, np.ndarray[double, ndim = 1, mode = 'c'] y not None, np.ndarray[double, ndim = 1, mode = 'c'] z not None, scaleDomainSpacing not None): - - m_x = x.size - m_y = y.size - m_z = z.size +def pymcc_singlepass(np.ndarray[double, ndim = 2, mode = 'c'] xyz not None, scaleDomainSpacing not None): - assert m_x == m_y - assert m_y == m_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_x; + 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[0], &y[0], &z[0], n, resolution); + h = pymcc_pass(x, y, z, n, resolution); - cdef np.ndarray[ndim=1, dtype=np.float] np_h = np.empty(m_x); - for i in range(m_x): + 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