-
Notifications
You must be signed in to change notification settings - Fork 1
/
metric.py
65 lines (55 loc) · 2.19 KB
/
metric.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
import open3d as o3d
# import torch
import numpy as np
MESHTYPE = 6
TETRATYPE = 10
PCDTYPE = 1
class Metrics3D():
def prediction_is_empty(self, geom):
if isinstance(geom, o3d.geometry.Geometry):
geom_type = geom.get_geometry_type().value
if geom_type == MESHTYPE:
geom.remove_duplicated_vertices()
geom.remove_duplicated_triangles()
geom.remove_degenerate_triangles()
empty_v = self.is_empty(len(geom.vertices))
empty_t = self.is_empty(len(geom.triangles))
empty = empty_t or empty_v
elif geom_type == TETRATYPE:
geom.remove_duplicated_vertices()
geom.remove_duplicated_tetras()
geom.remove_degenerate_tetras()
empty_v = self.is_empty(len(geom.vertices))
empty_t = self.is_empty(len(geom.tetras))
empty = empty_t or empty_v
elif geom_type == PCDTYPE:
empty = self.is_empty(len(geom.points))
else:
assert False, '{} geometry not supported'.format(geom.get_geometry_type())
elif isinstance(geom, np.ndarray):
empty = self.is_empty(len(geom[:, :3]))
else:
assert False, '{} type not supported'.format(type(geom))
return empty
@staticmethod
def convert_to_pcd(geom):
if isinstance(geom, o3d.geometry.Geometry):
geom_type = geom.get_geometry_type().value
if geom_type == MESHTYPE or geom_type == TETRATYPE:
geom_pcd = geom.sample_points_uniformly(1000000)
elif geom_type == PCDTYPE:
geom_pcd = geom
else:
assert False, '{} geometry not supported'.format(geom.get_geometry_type())
elif isinstance(geom, np.ndarray):
geom_pcd = o3d.geometry.PointCloud()
geom_pcd.points = o3d.utility.Vector3dVector(geom[:, :3])
else:
assert False, '{} type not supported'.format(type(geom))
return geom_pcd
@staticmethod
def is_empty(length):
empty = True
if length:
empty = False
return empty