/
point_cloud.py
69 lines (49 loc) · 1.58 KB
/
point_cloud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""Contains the PointCloud class."""
import numpy
import _zivid
class PointCloud:
"""A point cloud."""
def __init__(self, internal_point_cloud):
"""Create a point cloud from an internal point cloud.
Args:
internal_point_cloud: a internal point cloud
Raises:
TypeError: unsupported type provided for internal point cloud
"""
if not isinstance(internal_point_cloud, _zivid.PointCloud):
raise TypeError(
"Unsupported type for argument internal_point_cloud. Got {}, expected {}".format(
type(internal_point_cloud), type(_zivid.PointCloud)
)
)
self.__impl = internal_point_cloud
def to_array(self):
"""Convert point cloud to numpy array.
Returns:
a numpy array
"""
self.__impl.assert_not_released()
return numpy.array(self.__impl)
@property
def height(self):
"""Return height (number of rows) of point cloud.
Returns:
a positive integer
"""
return self.__impl.height()
@property
def width(self):
"""Return width (number of columns) of point cloud.
Returns:
a positive integer
"""
return self.__impl.width()
def release(self):
"""Release the underlying resources."""
self.__impl.release()
def __enter__(self):
return self
def __exit__(self, exception_type, exception_value, traceback):
self.release()
def __del__(self):
self.release()