-
Notifications
You must be signed in to change notification settings - Fork 221
/
base.py
52 lines (41 loc) · 1.35 KB
/
base.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
from abc import ABC, abstractmethod
class Structure(ABC):
"""Base class for structures."""
def __init__(self, *, points):
self._points = points
def get_and_set(self, pyntcloud):
pyntcloud.structures[self.id] = self
return self.id
@classmethod
def extract_info(cls, pyntcloud):
"""ABC API"""
info = {
"points": pyntcloud.xyz
}
return info
@abstractmethod
def compute(self):
pass
class StructuresDict(dict):
"""Custom class to restrict PyntCloud.structures assigment."""
def __init__(self, *args):
self.n_voxelgrids = 0
self.n_kdtrees = 0
self.n_delaunays = 0
self.n_convex_hulls = 0
super().__init__(*args)
def __setitem__(self, key, val):
if not issubclass(val.__class__, Structure):
raise TypeError("{} must be base.Structure subclass".format(key))
# TODO better structure.id check
if key.startswith("V"):
self.n_voxelgrids += 1
elif key.startswith("K"):
self.n_kdtrees += 1
elif key.startswith("D"):
self.n_delaunays += 1
elif key.startswith("CH"):
self.n_convex_hulls += 1
else:
raise ValueError("{} is not a valid structure.id".format(key))
super().__setitem__(key, val)