Skip to content

Commit

Permalink
debugged bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
gehilley committed May 14, 2019
1 parent 3139372 commit 68b40ed
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
2 changes: 1 addition & 1 deletion libmcc_lidar/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 6 additions & 5 deletions libmcc_lidar/src/mcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ shared_ptr<PointVector> 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;
Expand Down
61 changes: 37 additions & 24 deletions python/pymcc_lidar.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <double *> malloc(n * sizeof(double));
cdef double *y = <double *> malloc(n * sizeof(double));
cdef double *z = <double *> 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 = <double *> malloc(n * sizeof(double));
cdef double *y = <double *> malloc(n * sizeof(double));
cdef double *z = <double *> 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


0 comments on commit 68b40ed

Please sign in to comment.