Skip to content

Commit 5853156

Browse files
committed
copy constructor for point clouds
1 parent 3933130 commit 5853156

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pcl/_pcl.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ cdef class PointCloud:
135135
To load a point cloud from disk, use pcl.load.
136136
"""
137137
def __cinit__(self, init=None):
138+
cdef BasePointCloud other
139+
138140
sp_assign(self.thisptr_shared, new cpp.PointCloud[cpp.PointXYZ]())
139141

140142
if init is None:
@@ -145,6 +147,9 @@ cdef class PointCloud:
145147
self.from_array(init)
146148
elif isinstance(init, Sequence):
147149
self.from_list(init)
150+
elif isinstance(init, type(self)):
151+
other = init
152+
self.thisptr()[0] = other.thisptr()[0]
148153
else:
149154
raise TypeError("Can't initialize a PointCloud from a %s"
150155
% type(init))

tests/test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ def test_pcd_read():
148148
assert_array_equal(p.sensor_origin,
149149
np.array([.1, 0, .5, 0], dtype=np.float32))
150150

151+
152+
def test_copy():
153+
a = np.random.randn(100, 3).astype(np.float32)
154+
p1 = pcl.PointCloud(a)
155+
p2 = pcl.PointCloud(p1)
156+
assert_array_equal(p2.to_array(), a)
157+
158+
151159
SEGCYLMOD = [0.0552167, 0.0547035, 0.757707, -0.0270852, -4.41026, -2.88995, 0.0387603]
152160
SEGCYLIN = 11462
153161

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