Skip to content

Commit

Permalink
More utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
goord committed Jan 25, 2018
1 parent 129bb44 commit 51e7b3f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
23 changes: 21 additions & 2 deletions laserchicken/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ def test_GetPointCloudPoint(self):
self.assertEqual(3,y)
self.assertEqual(4,z)

def test_GetPointCloudPointFeature(self):
""" Should not raise exception. """
pc = test_tools.generate_test_point_cloud()
cols = 0.5*(pc[keys.point]["x"]["data"] + pc[keys.point]["y"]["data"])
pc[keys.point]["color"] = {"type" : "double", "data" : cols}
x,y,z = utils.get_point(pc,1)
c = utils.get_feature(pc,1,"color")
self.assertEqual(c,0.5*(x + y))

def test_GetPointCloudPointFeatures(self):
""" Should not raise exception. """
pc = test_tools.generate_test_point_cloud()
cols = 0.5*(pc[keys.point]["x"]["data"] + pc[keys.point]["y"]["data"])
flavs = 0.5*(pc[keys.point]["x"]["data"] - pc[keys.point]["y"]["data"])
pc[keys.point]["color"] = {"type" : "double", "data" : cols}
pc[keys.point]["flavor"] = {"type" : "double", "data" : flavs}
x,y,z = utils.get_point(pc,2)
c,f = utils.get_features(pc,2,("color","flavor"))
self.assertEqual(c,0.5*(x + y))
self.assertEqual(f,0.5*(x - y))

def test_CopyEmptyPointCloud(self):
""" Should not raise exception. """
pc = test_tools.generate_test_point_cloud()
Expand Down Expand Up @@ -79,5 +100,3 @@ def test_AddMetaDataToPointCloud(self):
from laserchicken import select as somemodule
utils.add_metadata(pc,somemodule,params = (0.5,"cylinder",4))
self.assertEqual(len(pc[keys.provenance]),1)
print(pc["log"])
raise Exception
6 changes: 6 additions & 0 deletions laserchicken/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
def get_point(pc,index):
return pc[keys.point]["x"]["data"][index],pc[keys.point]["y"]["data"][index],pc[keys.point]["z"]["data"][index]

def get_feature(pc,index,featurename):
return pc[keys.point][featurename]["data"][index]

def get_features(pc,index,featurenames):
return (pc[keys.point][f]["data"][index] for f in featurenames)

def copy_pointcloud(pc_in, array_mask = []):
"""
Makes a deep copy of a point cloud dict using the array mask when copying the points.
Expand Down

0 comments on commit 51e7b3f

Please sign in to comment.