Skip to content

Commit 14f674a

Browse files
committed
test and document NumPy interop using buffer interface
1 parent 102ee66 commit 14f674a

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

readme.rst

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ point types
2929
* registration (ICP, GICP, ICP_NL)
3030

3131
The code tries to follow the Point Cloud API, and also provides helper function
32-
for interacting with numpy. For example (from tests/test.py)
32+
for interacting with NumPy. For example (from tests/test.py)
3333

3434
.. code-block:: python
3535
@@ -52,6 +52,20 @@ or, for smoothing
5252
fil.set_std_dev_mul_thresh (1.0)
5353
fil.filter().to_file("inliers.pcd")
5454
55+
Point clouds can be viewed as NumPy arrays, so modifying them is possible
56+
using all the familiar NumPy functionality:
57+
58+
.. code-block:: python
59+
60+
import numpy as np
61+
import pcl
62+
p = pcl.PointCloud(10) # "empty" point cloud
63+
a = np.asarray(p) # NumPy view on the cloud
64+
a[:] = 0 # fill with zeros
65+
print(p[3]) # prints (0.0, 0.0, 0.0)
66+
a[:, 0] = 1 # set x coordinates to 1
67+
print(p[3]) # prints (1.0, 0.0, 0.0)
68+
5569
More samples can be found in the `examples directory <https://github.com/strawlab/python-pcl/tree/master/examples>`_,
5670
and in the `unit tests <https://github.com/strawlab/python-pcl/blob/master/tests/test.py>`_.
5771

@@ -60,11 +74,11 @@ This work was supported by `Strawlab <http://strawlab.org/>`_.
6074
Requirements
6175
------------
6276

63-
This release has been tested on Ubuntu 13.10 with
77+
This release has been tested on Linux Mint 17 with
6478

65-
* Python 2.7.5
66-
* pcl 1.7.1
67-
* Cython 0.21
79+
* Python 2.7.6
80+
* pcl 1.7.2
81+
* Cython 0.21.2
6882

6983
and CentOS 6.5 with
7084

tests/test.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pcl
88
import numpy as np
99

10-
from numpy.testing import assert_array_equal
10+
from numpy.testing import assert_array_almost_equal, assert_array_equal
1111

1212

1313
_data = [(i,2*i,3*i+0.2) for i in range(5)]
@@ -38,7 +38,7 @@ def setUp(self):
3838
self.a = np.array(np.mat(_DATA, dtype=np.float32))
3939
self.p = pcl.PointCloud(self.a)
4040

41-
def testFromNumy(self):
41+
def testFromNumpy(self):
4242
for i,d in enumerate(_data):
4343
pt = self.p[i]
4444
assert np.allclose(pt, _data[i])
@@ -47,6 +47,13 @@ def testToNumpy(self):
4747
a = self.p.to_array()
4848
self.assertTrue(np.alltrue(a == self.a))
4949

50+
def test_asarray(self):
51+
p = pcl.PointCloud(self.p) # copy
52+
old0 = p[0]
53+
a = np.asarray(p) # view
54+
a[:] += 6
55+
assert_array_almost_equal(p[0], a[0])
56+
5057
def test_pickle(self):
5158
"""Test pickle support."""
5259
# In this testcase because picking reduces to pickling NumPy arrays.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy