Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.

work of colin csl allowing to acces normal of point clouds #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions pcl/_pcl.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
8 changes: 8 additions & 0 deletions pcl/pcl_defs.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
10 changes: 10 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down