abreza commited on
Commit
e154ec4
·
1 Parent(s): 8e295b3

try to fix subject renderring

Browse files
Files changed (2) hide show
  1. visualization/logger.py +39 -22
  2. visualization/mesh.py +0 -26
visualization/logger.py CHANGED
@@ -1,8 +1,17 @@
1
  import rerun as rr
2
  import numpy as np
3
- from typing import Dict, Any, List, Optional
4
  from utils.geometry import vector3_to_numpy, euler_to_quaternion
5
- from visualization.mesh import create_subject_mesh
 
 
 
 
 
 
 
 
 
6
 
7
 
8
  class SimulationLogger:
@@ -31,26 +40,35 @@ class SimulationLogger:
31
  if not subjects:
32
  return
33
 
34
- for idx, subject in enumerate(subjects):
35
- try:
36
- vertices, faces = create_subject_mesh(subject)
37
- subject_color = [0.8, 0.2, 0.2, 1.0]
38
-
39
- rr.log(
40
- f"world/subject_{idx}",
41
- rr.Mesh3D(
42
- vertex_positions=vertices,
43
- indices=faces,
44
- colors=np.tile(subject_color, (len(vertices), 1))
45
- ),
46
- timeless=True
47
- )
48
 
49
- rr.log(f"world/subject_{idx}/class",
50
- rr.TextDocument(subject.get('objectClass', 'Unknown')),
51
- timeless=True)
 
 
 
 
52
  except Exception as e:
53
- print(f"Error creating mesh for subject {idx}: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  def log_camera_trajectory(self, camera_frames: List[Dict[str, Any]]) -> None:
56
  if not camera_frames:
@@ -94,8 +112,7 @@ class SimulationLogger:
94
  rr.log(
95
  "world/camera/view",
96
  rr.Pinhole(
97
- focal_length=camera_frame.get(
98
- 'focalLength', 50), # Added default
99
  width=1920,
100
  height=1080
101
  )
 
1
  import rerun as rr
2
  import numpy as np
3
+ from typing import Dict, Any, List
4
  from utils.geometry import vector3_to_numpy, euler_to_quaternion
5
+
6
+
7
+ def create_subject_box(subject: Dict) -> Dict[str, np.ndarray]:
8
+ position = vector3_to_numpy(subject['position'])
9
+ size = vector3_to_numpy(subject['size'])
10
+
11
+ return {
12
+ 'center': position,
13
+ 'half_size': size / 2 # Boxes3D uses half-sizes
14
+ }
15
 
16
 
17
  class SimulationLogger:
 
40
  if not subjects:
41
  return
42
 
43
+ # Prepare batch data for all subjects
44
+ centers = []
45
+ half_sizes = []
46
+ colors = []
47
+ labels = []
 
 
 
 
 
 
 
 
 
48
 
49
+ for subject in subjects:
50
+ try:
51
+ box_params = create_subject_box(subject)
52
+ centers.append(box_params['center'])
53
+ half_sizes.append(box_params['half_size'])
54
+ colors.append([0.8, 0.2, 0.2, 1.0]) # Red color with alpha
55
+ labels.append(subject.get('objectClass', 'Unknown'))
56
  except Exception as e:
57
+ print(f"Error creating box parameters: {str(e)}")
58
+ continue
59
+
60
+ if centers: # Only log if we have valid subjects
61
+ rr.log(
62
+ "world/subjects",
63
+ rr.Boxes3D(
64
+ centers=np.array(centers),
65
+ half_sizes=np.array(half_sizes),
66
+ colors=np.array(colors),
67
+ labels=labels,
68
+ fill_mode="solid" # Use solid fill for better visualization
69
+ ),
70
+ timeless=True
71
+ )
72
 
73
  def log_camera_trajectory(self, camera_frames: List[Dict[str, Any]]) -> None:
74
  if not camera_frames:
 
112
  rr.log(
113
  "world/camera/view",
114
  rr.Pinhole(
115
+ focal_length=camera_frame.get('focalLength', 50),
 
116
  width=1920,
117
  height=1080
118
  )
visualization/mesh.py DELETED
@@ -1,26 +0,0 @@
1
- import numpy as np
2
- from typing import Dict, Tuple
3
- from utils.geometry import vector3_to_numpy
4
-
5
-
6
- def create_subject_mesh(subject: Dict) -> Tuple[np.ndarray, np.ndarray]:
7
- position = vector3_to_numpy(subject['position'])
8
- size = vector3_to_numpy(subject['size'])
9
-
10
- # Create cube vertices
11
- vertices = np.array([
12
- [-0.5, -0.5, -0.5], [0.5, -0.5, -0.5], [0.5, 0.5, -0.5], [-0.5, 0.5, -0.5],
13
- [-0.5, -0.5, 0.5], [0.5, -0.5, 0.5], [0.5, 0.5, 0.5], [-0.5, 0.5, 0.5]
14
- ]) * size.reshape(1, 3) + position.reshape(1, 3)
15
-
16
- # Create cube faces (updated to use vertex_indices instead of indices)
17
- faces = np.array([
18
- [0, 1, 2], [0, 2, 3], # front
19
- [1, 5, 6], [1, 6, 2], # right
20
- [5, 4, 7], [5, 7, 6], # back
21
- [4, 0, 3], [4, 3, 7], # left
22
- [3, 2, 6], [3, 6, 7], # top
23
- [4, 5, 1], [4, 1, 0] # bottom
24
- ])
25
-
26
- return vertices, faces