Skip to content

Commit

Permalink
Fix 3DE vec3d division issues for Copy/Export Tracks tool.
Browse files Browse the repository at this point in the history
The original traceback reported was:

Traceback (most recent call last):
 File "<string>", line 1071, in <module>
 File "<string>", line 164, in main
 File "<string>", line 594, in generate
 File "<string>", line 1066, in _generate_v4
 File "<string>", line 897, in _generate_v2_v3_and_v4
 File "<string>", line 398, in _remove_rs_from_2d_point
 File "<string>", line 290, in _apply_rs_correction
TypeError: unsupported operand type(s) for /: 'vec3d' and 'float'

When using the "copy_track_mmsolver.py" (v1.9) tool in 3DE R6 on
Windows.

The fix is two fold;
1) do not perform maths on integer numbers when floats are expected.
2) Fall back to float-float division per-component in a vec3d to avoid
the use of 3DE's vec3d operator overloading - in case this happens again
the future.
  • Loading branch information
david-cattermole committed Dec 19, 2022
1 parent 5002f65 commit 3b4844e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion share/3dequalizer/python/copy_track_mmsolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
# 3DE4.script.name: Copy 2D Tracks (MM Solver)
#
# 3DE4.script.version: v1.10
# 3DE4.script.version: v1.11
#
# 3DE4.script.gui: Object Browser::Context Menu Point
# 3DE4.script.gui: Object Browser::Context Menu Points
Expand Down
2 changes: 1 addition & 1 deletion share/3dequalizer/python/export_track_mmsolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
# 3DE4.script.name: Export 2D Tracks (MM Solver)...
#
# 3DE4.script.version: v1.10
# 3DE4.script.version: v1.11
#
# 3DE4.script.gui: Main Window::3DE4::File::Export
# 3DE4.script.gui: Object Browser::Context Menu Point
Expand Down
12 changes: 7 additions & 5 deletions share/3dequalizer/python/uvtrack_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ def _apply_rs_correction(dt, q_minus, q_center, q_plus):
:return: 2D point blended.
"""
a = q_center
b = (q_plus - q_minus) / 2.0
c = -q_center + (q_plus + q_minus) / 2.0
b = q_plus - q_minus
b = vl_sdv.vec3d(b[0] / 2.0, b[1] / 2.0, b[2] / 2.0)
c = -q_center + (q_plus + q_minus)
c = vl_sdv.vec3d(c[0] / 2.0, c[1] / 2.0, c[2] / 2.0)
return a + dt * b + dt * dt * c


Expand Down Expand Up @@ -226,7 +228,7 @@ def _convert_2d_to_3d_point_undistort(
p3d = vl_sdv.vec3d(tde4.getPGroupPosition3D(point_group, camera, frame))
left, right, bottom, top = camera_fov

p2d = [0, 0]
p2d = [0.0, 0.0]
p2d[0] = (pos[0] - left) / (right - left)
p2d[1] = (pos[1] - bottom) / (top - bottom)
p2d = tde4.removeDistortion2D(camera, frame, p2d)
Expand Down Expand Up @@ -267,7 +269,7 @@ def _remove_rs_from_2d_point(point_group, camera, frame, input_2d, depth):
rs_value = rs_time_shift * camera_fps

# Sample at previous frame
prev_pos = vl_sdv.vec3d(0, 0, 0)
prev_pos = vl_sdv.vec3d(0.0, 0.0, 0.0)
prev_frame = frame - 1
if frame > 1:
prev_pos = _convert_2d_to_3d_point_undistort(
Expand All @@ -284,7 +286,7 @@ def _remove_rs_from_2d_point(point_group, camera, frame, input_2d, depth):
)

# Sample at next frame
next_pos = vl_sdv.vec3d(0, 0, 0)
next_pos = vl_sdv.vec3d(0.0, 0.0, 0.0)
next_frame = frame + 1
if frame < num_frames:
next_pos = _convert_2d_to_3d_point_undistort(
Expand Down
14 changes: 8 additions & 6 deletions share/3dequalizer/scriptdb/copy_track_mmsolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
# 3DE4.script.name: Copy 2D Tracks (MM Solver)
#
# 3DE4.script.version: v1.10
# 3DE4.script.version: v1.11
#
# 3DE4.script.gui: Object Browser::Context Menu Point
# 3DE4.script.gui: Object Browser::Context Menu Points
Expand Down Expand Up @@ -284,8 +284,10 @@ def _apply_rs_correction(dt, q_minus, q_center, q_plus):
:return: 2D point blended.
"""
a = q_center
b = (q_plus - q_minus) / 2.0
c = -q_center + (q_plus + q_minus) / 2.0
b = q_plus - q_minus
b = vl_sdv.vec3d(b[0] / 2.0, b[1] / 2.0, b[2] / 2.0)
c = -q_center + (q_plus + q_minus)
c = vl_sdv.vec3d(c[0] / 2.0, c[1] / 2.0, c[2] / 2.0)
return a + dt * b + dt * dt * c


Expand Down Expand Up @@ -315,7 +317,7 @@ def _convert_2d_to_3d_point_undistort(
p3d = vl_sdv.vec3d(tde4.getPGroupPosition3D(point_group, camera, frame))
left, right, bottom, top = camera_fov

p2d = [0, 0]
p2d = [0.0, 0.0]
p2d[0] = (pos[0] - left) / (right - left)
p2d[1] = (pos[1] - bottom) / (top - bottom)
p2d = tde4.removeDistortion2D(camera, frame, p2d)
Expand Down Expand Up @@ -356,7 +358,7 @@ def _remove_rs_from_2d_point(point_group, camera, frame, input_2d, depth):
rs_value = rs_time_shift * camera_fps

# Sample at previous frame
prev_pos = vl_sdv.vec3d(0, 0, 0)
prev_pos = vl_sdv.vec3d(0.0, 0.0, 0.0)
prev_frame = frame - 1
if frame > 1:
prev_pos = _convert_2d_to_3d_point_undistort(
Expand All @@ -373,7 +375,7 @@ def _remove_rs_from_2d_point(point_group, camera, frame, input_2d, depth):
)

# Sample at next frame
next_pos = vl_sdv.vec3d(0, 0, 0)
next_pos = vl_sdv.vec3d(0.0, 0.0, 0.0)
next_frame = frame + 1
if frame < num_frames:
next_pos = _convert_2d_to_3d_point_undistort(
Expand Down
14 changes: 8 additions & 6 deletions share/3dequalizer/scriptdb/export_track_mmsolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
# 3DE4.script.name: Export 2D Tracks (MM Solver)...
#
# 3DE4.script.version: v1.10
# 3DE4.script.version: v1.11
#
# 3DE4.script.gui: Main Window::3DE4::File::Export
# 3DE4.script.gui: Object Browser::Context Menu Point
Expand Down Expand Up @@ -294,8 +294,10 @@ def _apply_rs_correction(dt, q_minus, q_center, q_plus):
:return: 2D point blended.
"""
a = q_center
b = (q_plus - q_minus) / 2.0
c = -q_center + (q_plus + q_minus) / 2.0
b = q_plus - q_minus
b = vl_sdv.vec3d(b[0] / 2.0, b[1] / 2.0, b[2] / 2.0)
c = -q_center + (q_plus + q_minus)
c = vl_sdv.vec3d(c[0] / 2.0, c[1] / 2.0, c[2] / 2.0)
return a + dt * b + dt * dt * c


Expand Down Expand Up @@ -325,7 +327,7 @@ def _convert_2d_to_3d_point_undistort(
p3d = vl_sdv.vec3d(tde4.getPGroupPosition3D(point_group, camera, frame))
left, right, bottom, top = camera_fov

p2d = [0, 0]
p2d = [0.0, 0.0]
p2d[0] = (pos[0] - left) / (right - left)
p2d[1] = (pos[1] - bottom) / (top - bottom)
p2d = tde4.removeDistortion2D(camera, frame, p2d)
Expand Down Expand Up @@ -366,7 +368,7 @@ def _remove_rs_from_2d_point(point_group, camera, frame, input_2d, depth):
rs_value = rs_time_shift * camera_fps

# Sample at previous frame
prev_pos = vl_sdv.vec3d(0, 0, 0)
prev_pos = vl_sdv.vec3d(0.0, 0.0, 0.0)
prev_frame = frame - 1
if frame > 1:
prev_pos = _convert_2d_to_3d_point_undistort(
Expand All @@ -383,7 +385,7 @@ def _remove_rs_from_2d_point(point_group, camera, frame, input_2d, depth):
)

# Sample at next frame
next_pos = vl_sdv.vec3d(0, 0, 0)
next_pos = vl_sdv.vec3d(0.0, 0.0, 0.0)
next_frame = frame + 1
if frame < num_frames:
next_pos = _convert_2d_to_3d_point_undistort(
Expand Down

0 comments on commit 3b4844e

Please sign in to comment.