Skip to content

Commit

Permalink
Merge pull request #2 from rmsare/update-api
Browse files Browse the repository at this point in the history
Clean up Python API
  • Loading branch information
rmsare authored May 31, 2019
2 parents 111ddc9 + 98f221a commit ebef81a
Showing 1 changed file with 59 additions and 56 deletions.
115 changes: 59 additions & 56 deletions python/pymcc_lidar.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,68 @@ 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):

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 = <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:
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 pymcc_singlepass(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 = <double *> malloc(n * sizeof(double));
cdef double *y = <double *> malloc(n * sizeof(double));
cdef double *z = <double *> 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 = <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:
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);
return np_h
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 = <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, 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

0 comments on commit ebef81a

Please sign in to comment.