Skip to content

Commit 1bed4af

Browse files
committed
Merge pull request strawlab#56 from larsmans/sensor-info
get sensor origin and orientation from PointCloud
2 parents 3291cc7 + 93d1c9f commit 1bed4af

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

pcl/_pcl.pyx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,19 @@ cdef class PointCloud:
171171
def __reduce__(self):
172172
return type(self), (self.to_array(),)
173173

174+
property sensor_origin:
175+
def __get__(self):
176+
cdef cpp.Vector4f origin = self.thisptr().sensor_origin_
177+
cdef float *data = origin.data()
178+
return np.array([data[0], data[1], data[2], data[3]],
179+
dtype=np.float32)
180+
181+
property sensor_orientation:
182+
def __get__(self):
183+
# NumPy doesn't have a quaternion type, so we return a 4-vector.
184+
cdef cpp.Quaternionf o = self.thisptr().sensor_orientation_
185+
return np.array([o.w(), o.x(), o.y(), o.z()])
186+
174187
@cython.boundscheck(False)
175188
def from_array(self, cnp.ndarray[cnp.float32_t, ndim=2] arr not None):
176189
"""

pcl/pcl_defs.pxd

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ from libcpp cimport bool
77
from shared_ptr cimport shared_ptr
88
from vector cimport vector as vector2
99

10+
cdef extern from "Eigen/Eigen" namespace "Eigen" nogil:
11+
cdef cppclass Vector4f:
12+
float *data()
13+
cdef cppclass Quaternionf:
14+
float w()
15+
float x()
16+
float y()
17+
float z()
18+
cdef cppclass aligned_allocator[T]:
19+
pass
20+
1021
cdef extern from "pcl/point_cloud.h" namespace "pcl":
1122
cdef cppclass PointCloud[T]:
1223
PointCloud() except +
@@ -21,6 +32,9 @@ cdef extern from "pcl/point_cloud.h" namespace "pcl":
2132
#T& at(int, int) except +
2233
shared_ptr[PointCloud[T]] makeShared()
2334

35+
Quaternionf sensor_orientation_
36+
Vector4f sensor_origin_
37+
2438
cdef extern from "indexing.hpp":
2539
# Use these instead of operator[] or at.
2640
PointXYZ *getptr(PointCloud[PointXYZ] *, size_t)
@@ -81,10 +95,6 @@ cdef extern from "pcl/search/kdtree.h" namespace "pcl::search":
8195
cdef cppclass KdTree[T]:
8296
KdTree()
8397

84-
cdef extern from "Eigen/src/Core/util/Memory.h" namespace "Eigen":
85-
cdef cppclass aligned_allocator[T]:
86-
pass
87-
8898
ctypedef aligned_allocator[PointXYZ] aligned_allocator_t
8999
ctypedef vector2[PointXYZ, aligned_allocator_t] AlignedPointTVector_t
90100

tests/test.py

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

10+
from numpy.testing import assert_array_equal
11+
12+
1013
_data = [(i,2*i,3*i+0.2) for i in range(5)]
1114
_DATA = \
1215
"""0.0, 0.0, 0.2;
@@ -120,7 +123,7 @@ def test_pcd_read():
120123
COUNT 1 1 1
121124
WIDTH %(npts)d
122125
HEIGHT 1
123-
VIEWPOINT 0 0 0 0 1 0 0
126+
VIEWPOINT 0.1 0 0.5 0 1 0 0
124127
POINTS %(npts)d
125128
DATA ascii
126129
%(data)s"""
@@ -140,6 +143,11 @@ def test_pcd_read():
140143
ssd = sum((row - pt) ** 2)
141144
assert ssd < 1e-6
142145

146+
assert_array_equal(p.sensor_orientation,
147+
np.array([0, 1, 0, 0], dtype=np.float32))
148+
assert_array_equal(p.sensor_origin,
149+
np.array([.1, 0, .5, 0], dtype=np.float32))
150+
143151
SEGCYLMOD = [0.0552167, 0.0547035, 0.757707, -0.0270852, -4.41026, -2.88995, 0.0387603]
144152
SEGCYLIN = 11462
145153

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