This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_pointcloud.py
102 lines (76 loc) · 2.89 KB
/
get_pointcloud.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# generate data
import numpy as np
from copy import deepcopy
from typing import Union, Tuple, List
class point_cloud_data:
def __init__(
self,
fileName: str,
) -> None:
"""creates a pointcloud object from a .ply file
:param fileName: sets the path to the ply file
:type fileName: str
:param apply_rand_transform: if we want to set a baselink, defaults to False
:type apply_rand_transform: bool, optional
"""
# the pointcloud data will be a dictionary
# with keys identifying the
self.data = {}
self.data_numpy = []
# load the point cloud from the ply file
self.succ = self.load_point_cloud(fileName)
if not self.succ:
print("ERROR in ply file")
return
def convert_data_array(self) -> None:
"""gets the data in a numpy format shape = (..., 3)
"""
self.data_numpy = np.stack(tuple(self.data.values()), axis=1).T
return
def get_point_cloud(
self,
numpy_array: bool=False
) -> Union[dict, np.array]:
"""outputs the data in either dictionary type of numpy
:param numpy_array: set the output to be numpy, defaults to False
:type numpy_array: bool, optional
:return: dictionary with the data or numpy if setted
:rtype: Union[dict, np.array]
"""
if numpy_array:
if self.data_numpy == []:
self.convert_data_array()
return self.data_numpy
else:
return self.data
def gets_point_cloud_center(self) -> Tuple[float, float, float]:
"""Outputs the center coordinates of the point cloud
:return: x, y, and z coordinates of the point clouds' center point
:rtype: Tuple[float, float, float]
"""
if self.data_numpy == []:
self.convert_data_array()
return tuple(np.average(self.data_numpy, axis=0))
def load_point_cloud(
self,
file: str
) -> bool:
"""Loads a point cloud from a ply file
:param file: path to the ply file
:type file: str
"""
pass
def plot_list_points(self) -> None:
maxPlotPoints = 5
numPointPlot = min([maxPlotPoints,len(self.dataScanOne.keys())])
print('Data in Scan One:')
for key in list(self.dataScanOne.keys())[0:numPointPlot]:
print(self.dataScanOne[key])
if len(self.dataScanOne.keys()) > maxPlotPoints:
print('...')
print('Data in Scan Two:')
for key in list(self.dataScanTwo.keys())[0:numPointPlot]:
print(self.dataScanTwo[key])
if len(self.dataScanOne.keys()) > maxPlotPoints:
print('...')
return