forked from DLR-RM/BlenderProc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPOI.py
64 lines (50 loc) · 2.17 KB
/
POI.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
import mathutils
import numpy as np
from src.main.Provider import Provider
from src.utility.BlenderUtility import get_bounds, get_all_mesh_objects
class POI(Provider):
""" Computes a point of interest in the scene. Point is defined as a location of the one of the selected objects
that is the closest one to the mean location of the bboxes of the selected objects.
Example 1: Return a location of the object that is the closest one to the mean bbox location of all MESH objects.
{
"provider": "getter.POI"
}
Example 2: Return a location of the object that is the closest one to the mean bbox location of MESH objects
that have their custom property set to True.
{
"provider": "getter.POI",
"selector": {
"provider": "getter.Entity",
"conditions": {
"cp_shape_net_object": True,
"type": "MESH"
}
}
}
**Configuration**:
.. csv-table::
:header: "Parameter", "Description"
"selector", "Objects to take part in the POI computation. Type: Provider. Default: all mesh objects."
"""
def __init__(self, config):
Provider.__init__(self, config)
def run(self):
"""
:return: Point of interest in the scene. Type: mathutils Vector.
"""
# Init matrix for all points of all bounding boxes
mean_bb_points = []
# For every selected object in the scene
selected_objects = self.config.get_list("selector", get_all_mesh_objects())
if len(selected_objects) == 0:
raise Exception("No objects were selected!")
for obj in selected_objects:
# Get bounding box corners
bb_points = get_bounds(obj)
# Compute mean coords of bounding box
mean_bb_points.append(np.mean(bb_points, axis=0))
# Query point - mean of means
mean_bb_point = np.mean(mean_bb_points, axis=0)
# Closest point (from means) to query point (mean of means)
poi = mathutils.Vector(mean_bb_points[np.argmin(np.linalg.norm(mean_bb_points - mean_bb_point, axis=1))])
return poi