diff --git a/pcl/_pcl.pyx b/pcl/_pcl.pyx index 05e4500e4..21e124508 100644 --- a/pcl/_pcl.pyx +++ b/pcl/_pcl.pyx @@ -303,6 +303,36 @@ cdef class PointCloud: cseg.setInputNormals (normals.makeShared()); return seg + + def calc_normals(self, int ksearch=-1, double searchRadius=-1.0): + """ + Return a numpy 2D array containing the normal of the pointcloud + :TODO: using a loop may be slow, maybe with some numpy magic it can be performed at once. + """ +<<<<<<< HEAD + if ksearch == -1 and searchRadius == -1.0: + raise ValueError, "At least one input parameter must be entered" + +======= +>>>>>>> 05f77676c7447e16fd664c45813bfb6497085ecc + cdef cpp.PointNormalCloud_t normals + mpcl_compute_normals(deref(self.thisptr), ksearch, searchRadius, normals) + cdef float x,y,z + cdef int n = self.thisptr.size() + cdef cnp.ndarray[float, ndim=2] result = np.empty([n,3], dtype=np.float32) + cdef int i = 0 + while i < n: + result[i,0] = normals.at(i).normal_x + result[i,1] = normals.at(i).normal_y + result[i,2] = normals.at(i).normal_z + i += 1 + return result + +<<<<<<< HEAD + + +======= +>>>>>>> 05f77676c7447e16fd664c45813bfb6497085ecc def make_statistical_outlier_filter(self): """ diff --git a/pcl/pcl_defs.pxd b/pcl/pcl_defs.pxd index 19452c119..47532add3 100644 --- a/pcl/pcl_defs.pxd +++ b/pcl/pcl_defs.pxd @@ -34,7 +34,15 @@ cdef extern from "pcl/point_types.h" namespace "pcl": float y float z cdef struct Normal: +<<<<<<< HEAD +======= pass +>>>>>>> 05f77676c7447e16fd664c45813bfb6497085ecc + Normal() + float normal_x + float normal_y + float normal_z + float curvature cdef extern from "pcl/features/normal_3d.h" namespace "pcl": cdef cppclass NormalEstimation[T, N]: diff --git a/tests/test.py b/tests/test.py index 29469ad4a..60ae47f87 100644 --- a/tests/test.py +++ b/tests/test.py @@ -221,6 +221,16 @@ def testResize(self): # better exceptions. self.assertRaises(MemoryError, self.p.resize, -1) +class TestCalcNormals(unittest.TestCase): + def setUp(self): + self.p = pcl.PointCloud() + self.p.from_list([[0,0,0],[1,0,0],[0,1,0]]) + def testCalcNormals(self): + normals = self.p.calc_normals(20) + truth = np.array([[0,0,1],[0,0,1],[0,0,1]]) + self.assertEqual(normals, truth) + self.assertEqual(normals.size, self.p.size) + class TestSegmenterNormal(unittest.TestCase): def setUp(self):