36namespace xrt::tracking::constellation {
38using namespace xrt::auxiliary::tracking;
48constexpr float kAxisLength = 0.03f;
49constexpr float kBlobRadiusPixels = 3.0f;
50constexpr float kTrajectoryPointRadiusM = 0.005f;
51constexpr float kTrajectoryLineRadiusM = 0.002f;
64 math_pose_invert(&Tcv_world_cam, &Tcv_cam_world);
67 math_pose_transform(&Tcv_cam_world, &Tcv_world_device, &Tcv_cam_device);
69 return Tcv_cam_device;
77 math_quat_invert(&a, &a_inverse);
80 math_quat_rotate(&a_inverse, &b, &error);
86 float w = std::min(std::abs(error.w), 1.0f);
88 return static_cast<float>(2.0 * std::acos(w) * (180.0 / M_PI));
96 std::span<const xrt_vec2> points2d,
97 std::span<const xrt_vec3> points3d)
99 const xrt_pose Tcv_cam_device = predictedCameraDevicePose(Tcv_world_cam, Tcv_world_device);
101 double sum_squared_error = 0.0;
102 size_t num_projected = 0;
104 for (
size_t i = 0; i < num_points; i++) {
106 math_quat_rotate_vec3(&Tcv_cam_device.orientation, &points3d[i], &T_cam_led);
107 T_cam_led = T_cam_led + Tcv_cam_device.position;
109 if (T_cam_led.z <= 0.0f) {
114 float projected_x = 0.0f;
115 float projected_y = 0.0f;
116 if (!camera_models::project<float>(dist, T_cam_led.x, T_cam_led.y, T_cam_led.z, projected_x,
121 const float error_x = projected_x - points2d[i].x;
122 const float error_y = projected_y - points2d[i].y;
124 sum_squared_error += (error_x * error_x) + (error_y * error_y);
128 if (num_projected == 0) {
132 return static_cast<float>(std::sqrt(sum_squared_error /
static_cast<double>(num_projected)));
151 std::unique_ptr<rerun::RecordingStream> stream{};
154 explicit RerunStream(
const std::string_view &recording_id)
155 : stream(std::make_unique<rerun::RecordingStream>(recording_id))
167 this->stream->spawn().exit_on_failure();
177inline rerun::components::Translation3D
183inline rerun::Rotation3D
186 return rerun::Rotation3D(
190inline rerun::Transform3D
191toRerunTransform(
const xrt_pose &pose,
bool from_parent =
true)
193 auto transform = rerun::Transform3D()
194 .with_translation(toRerunTranslation(pose.position))
195 .with_rotation(toRerunRotation(pose.orientation));
198 transform = std::move(transform).with_relation(rerun::components::TransformRelation::ParentFromChild);
209 std::array<float, 9> image_from_camera = {
210 static_cast<float>(calibration.
intrinsics[0][0]),
211 static_cast<float>(calibration.
intrinsics[1][0]),
212 static_cast<float>(calibration.
intrinsics[2][0]),
214 static_cast<float>(calibration.
intrinsics[0][1]),
215 static_cast<float>(calibration.
intrinsics[1][1]),
216 static_cast<float>(calibration.
intrinsics[2][1]),
218 static_cast<float>(calibration.
intrinsics[0][2]),
219 static_cast<float>(calibration.
intrinsics[1][2]),
220 static_cast<float>(calibration.
intrinsics[2][2]),
223 return rerun::Pinhole(rerun::components::PinholeProjection(image_from_camera))
225 .with_image_plane_distance(0.2f);
232 assert(
frame.format == XRT_FORMAT_L8);
234 std::vector<uint8_t> image_data(
frame.width *
frame.height);
236 for (uint32_t y = 0; y <
frame.height; ++y) {
242 rerun::archetypes::Image::from_grayscale8(std::move(image_data), {
frame.width,
frame.height})
243 .with_opacity(0.5f));
253inline rerun::components::Color
254deviceColor(t_constellation_device_id_t device_id,
float brightness)
257 uint8_t r = (((device_id + 1) * 37) % 127) + 128;
258 uint8_t g = (((device_id + 1) * 57) % 127) + 128;
259 uint8_t b = (((device_id + 1) * 97) % 127) + 128;
261 return rerun::components::Color(r, g, b,
static_cast<uint8_t
>(255 * brightness));
265inline rerun::components::Color
266cameraColor(
size_t mosaic_idx,
size_t camera_idx,
float brightness)
269 size_t seed = (mosaic_idx * 16) + camera_idx + 1;
271 uint8_t r = ((seed * 71) % 127) + 128;
272 uint8_t g = ((seed * 113) % 127) + 128;
273 uint8_t b = ((seed * 29) % 127) + 128;
275 return rerun::components::Color(r, g, b,
static_cast<uint8_t
>(255 * brightness));
285inline std::string_view
float orientationErrorDegrees(const xrt_quat &a, const xrt_quat &b)
The angle between two orientations, in degrees.
Definition constellation_rerun_common.hpp:74
xrt_pose predictedCameraDevicePose(const xrt_pose &Tcv_world_cam, const xrt_pose &Tcv_world_device)
The pose the solved poses predict this camera would have observed the device at.
Definition constellation_rerun_common.hpp:61
std::string_view getWorldEntityName()
The root every 3D entity hangs off, so the recorders agree on where the world is.
Definition constellation_rerun_common.hpp:286
rerun::components::Color deviceColor(t_constellation_device_id_t device_id, float brightness)
A stable colour per device, so one device keeps its colour across every recorder and every view.
Definition constellation_rerun_common.hpp:254
std::string getWorldCameraEntityName(size_t mosaic_idx, size_t camera_idx)
Where a camera sits in the world. Its image, observations and metrics are logged under this.
Definition constellation_rerun_common.hpp:293
rerun::components::Color cameraColor(size_t mosaic_idx, size_t camera_idx, float brightness)
A stable colour per camera, chosen the same way as deviceColor and for the same reason.
Definition constellation_rerun_common.hpp:266
rerun::Pinhole makePinhole(const t_camera_calibration &calibration)
The camera's intrinsics as the projection rerun needs to place an image in the 3D scene.
Definition constellation_rerun_common.hpp:206
constexpr float kLedPointRadiusM
How large a LED is drawn in the 3D views, in meters.
Definition constellation_rerun_common.hpp:47
C interface to math library.
static Eigen::Map< const Eigen::Vector3f > position(const struct xrt_pose &pose)
Return a Eigen type wrapping a pose's position (const).
Definition m_eigen_interop.hpp:250
static Eigen::Map< const Eigen::Quaternionf > orientation(const struct xrt_pose &pose)
Return a Eigen type wrapping a pose's orientation (const).
Definition m_eigen_interop.hpp:232
Definition u_pacing_compositor.c:58
Essential calibration data for a single camera, or single lens/sensor of a stereo camera.
Definition t_tracking.h:269
double intrinsics[3][3]
Camera intrinsics matrix.
Definition t_tracking.h:274
struct xrt_size image_size_pixels
Source image size.
Definition t_tracking.h:271
Floating point calibration data for a single calibrated camera.
Definition t_camera_models.h:62
The recording stream a rerun recorder logs through.
Definition constellation_rerun_common.hpp:149
void spawnViewer() const
Starts a viewer for this stream and points the stream at it.
Definition constellation_rerun_common.hpp:165
Basic frame data structure - holds a pointer to buffer.
Definition xrt_frame.h:25
A pose composed of a position and orientation.
Definition xrt_defines.h:522
A quaternion with single floats.
Definition xrt_defines.h:246
A 3 element vector with single floats.
Definition xrt_defines.h:310
Camera (un)projection C++ API for various camera models.
Header defining the tracking system integration in Monado.
Common defines and enums for XRT.