Ocean
Loading...
Searching...
No Matches
SLAMDebugElements.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_TRACKING_SLAM_SLAM_DEBUG_ELEMENTS_H
9#define META_OCEAN_TRACKING_SLAM_SLAM_DEBUG_ELEMENTS_H
10
16
18#include "ocean/base/Frame.h"
20
24#include "ocean/math/Vector2.h"
25#include "ocean/math/Vector3.h"
26
27namespace Ocean
28{
29
30namespace Tracking
31{
32
33namespace SLAM
34{
35
36/**
37 * The class extends DebugElements to provide visual debugging output for various SLAM components such as occupancy arrays, tracked image points, object points, and overall tracking results.
38 * Debug elements are only generated when the corresponding element is activated via the base class.
39 * @see DebugElements
40 * @ingroup trackingslam
41 */
42class OCEAN_TRACKING_SLAM_EXPORT SLAMDebugElements :
43 public DebugElements,
44 public Singleton<SLAMDebugElements>
45{
46 friend class Singleton<SLAMDebugElements>;
47
48 public:
49
50 /// True, to allow debugging and enable debug element generation; False, to disable debugging globally.
51 static constexpr bool allowDebugging_ = false;
52
53 /**
54 * Definition of element identifiers for debug visualizations.
55 */
56 enum ElementId : uint32_t
57 {
58 /// An invalid element id.
59 EI_INVALID = 0u,
60 /// The id of the debug element for the occupancy array visualization.
62 /// The id of the debug element for tracked image point correspondences.
64 /// The id of the debug element for newly detected features.
66 /// The id of the debug element for 3D object point projections.
68 /// The id of the debug element for 2D image point tracks.
70 /// The id of the debug element for the comprehensive SLAM tracking result.
71 EI_RESULT
72 };
73
74 /**
75 * Sets the angle of the output rotation.
76 * @param angle The angle of the output rotation, in degrees. Must be a multiple of 90.
77 */
78 inline void setOutputRotation(const int angle);
79
80 public:
81
82 /**
83 * Updates the debug element based on the occupancy array.
84 * The visualization overlays the occupancy state on the input frame.<br>
85 * Empty bins are darkened (reduced brightness), while occupied bins are highlighted in green.<br>
86 * Displays the coverage percentage and whether more feature points are needed.
87 * @param yFrame The frame for which the occupancy array has been created, must be valid
88 * @param occupancyArray The occupancy array to visualize, must be valid
89 */
90 void updateOccupancyArray(const Frame& yFrame, const OccupancyArray& occupancyArray);
91
92 /**
93 * Updates the debug element based on tracked image point correspondences.
94 * The visualization draws lines between previous and current image points to show optical flow.<br>
95 * Valid correspondences are drawn in green, invalid correspondences are drawn in red.
96 * @param yFrame The frame for which the tracking was performed, must be valid
97 * @param previousImagePoints The image points from the previous frame, can be nullptr if numberCorrespondences is 0
98 * @param currentImagePoints The corresponding image points in the current frame, can be nullptr if numberCorrespondences is 0
99 * @param validCorrespondences Array indicating valid (1) or invalid (0) correspondences, can be nullptr if numberCorrespondences is 0
100 * @param numberCorrespondences The number of point correspondences, with range [0, infinity)
101 */
102 void updateTrackedImagePoints(const Frame& yFrame, const Vector2* previousImagePoints, const Vector2* currentImagePoints, uint8_t* validCorrespondences, const size_t numberCorrespondences);
103
104 /**
105 * Updates the debug element based on projected 3D object points.
106 * The visualization projects localized 3D object points onto the 2D frame.<br>
107 * Object points observed in the current frame are drawn in blue, while other visible points (when showAll is true) are drawn in red.
108 * @param yFrame The frame onto which the object points will be projected, must be valid
109 * @param camera The camera profile to use for projection, must be valid
110 * @param cameraPose The camera pose to use for projection
111 * @param frameIndex The index of the current frame, with range [0, infinity)
112 * @param localizedObjectPointMap The map of localized 3D object points to visualize
113 * @param showAll True, to show all visible object points; False, to show only tracked object points
114 */
115 void updateObjectPoints(const Frame& yFrame, const AnyCamera& camera, const CameraPose& cameraPose, const Index32 frameIndex, const LocalizedObjectPointMap& localizedObjectPointMap, const bool showAll = true);
116
117 /**
118 * Updates the debug element based on 2D image point tracks.
119 * The visualization shows the trajectory of tracked points across frames.<br>
120 * New points (with only one observation) are drawn as yellow dots, while tracked points with history are connected with green lines.
121 * @param yFrame The frame for which the point tracks are visualized, must be valid
122 * @param frameIndex The index of the current frame, with range [0, infinity)
123 * @param pointTrackMap The map of point tracks to visualize
124 */
125 void updateImagePoints(const Frame& yFrame, const Index32 frameIndex, const PointTrackMap& pointTrackMap);
126
127 /**
128 * Updates the debug element based on the comprehensive SLAM tracking result.
129 * The visualization combines multiple elements: 2D point tracks with trajectory lines, 3D-2D correspondences with reprojection quality indicators, and optional triangle mesh visualization.<br>
130 * New 2D points are drawn as yellow dots, tracked points are connected with green lines.<br>
131 * 3D-2D correspondences are drawn with color-coded reprojection error indicators.
132 * @param yFrame The frame for which the tracking was performed, must be valid
133 * @param camera The camera profile used for projection, must be valid
134 * @param cameraPose The SLAM camera pose; if invalid, only 2D tracking information is visualized
135 * @param frameIndex The index of the current frame, with range [0, infinity)
136 * @param pointTrackMap The map of 2D point tracks to visualize
137 * @param localizedObjectPointMap The map of localized 3D object points to visualize
138 * @param objectTriangles Optional array of 3D triangles to visualize as mesh, nullptr if not used
139 * @param numberObjectTriangles The number of triangles in the objectTriangles array, with range [0, infinity)
140 */
141 void updateResult(const Frame& yFrame, const AnyCamera& camera, const CameraPose& cameraPose, const Index32 frameIndex, const PointTrackMap& pointTrackMap, const LocalizedObjectPointMap& localizedObjectPointMap, const Triangle3* objectTriangles, const size_t numberObjectTriangles);
142
143 protected:
144
145 /// The angle of the output rotation, in degrees.
146 int outputRotationAngle_ = 0;
147};
148
149inline void SLAMDebugElements::setOutputRotation(const int angle)
150{
151 ocean_assert(angle % 90 == 0);
152 outputRotationAngle_ = angle;
153}
154
155}
156
157}
158
159}
160
161#endif // META_OCEAN_TRACKING_SLAM_SLAM_DEBUG_ELEMENTS_H
This class implements the abstract base class for all AnyCamera objects.
Definition AnyCamera.h:131
This class implements the base class for a container for debug elements.
Definition DebugElements.h:29
This class implements Ocean's image class.
Definition Frame.h:1879
This template class is the base class for all singleton objects.
Definition Singleton.h:71
This class holds the camera pose of a camera in relation to the world.
Definition CameraPose.h:46
This class implements an occupancy array allowing to keep track of occupied and unoccupied bins in a ...
Definition OccupancyArray.h:32
The class extends DebugElements to provide visual debugging output for various SLAM components such a...
Definition SLAMDebugElements.h:45
void updateImagePoints(const Frame &yFrame, const Index32 frameIndex, const PointTrackMap &pointTrackMap)
Updates the debug element based on 2D image point tracks.
int outputRotationAngle_
The angle of the output rotation, in degrees.
Definition SLAMDebugElements.h:146
void updateObjectPoints(const Frame &yFrame, const AnyCamera &camera, const CameraPose &cameraPose, const Index32 frameIndex, const LocalizedObjectPointMap &localizedObjectPointMap, const bool showAll=true)
Updates the debug element based on projected 3D object points.
void updateResult(const Frame &yFrame, const AnyCamera &camera, const CameraPose &cameraPose, const Index32 frameIndex, const PointTrackMap &pointTrackMap, const LocalizedObjectPointMap &localizedObjectPointMap, const Triangle3 *objectTriangles, const size_t numberObjectTriangles)
Updates the debug element based on the comprehensive SLAM tracking result.
void updateTrackedImagePoints(const Frame &yFrame, const Vector2 *previousImagePoints, const Vector2 *currentImagePoints, uint8_t *validCorrespondences, const size_t numberCorrespondences)
Updates the debug element based on tracked image point correspondences.
void setOutputRotation(const int angle)
Sets the angle of the output rotation.
Definition SLAMDebugElements.h:149
void updateOccupancyArray(const Frame &yFrame, const OccupancyArray &occupancyArray)
Updates the debug element based on the occupancy array.
ElementId
Definition of element identifiers for debug visualizations.
Definition SLAMDebugElements.h:57
@ EI_OCCUPANCY_ARRAY
The id of the debug element for the occupancy array visualization.
Definition SLAMDebugElements.h:61
@ EI_NEW_FEATURES
The id of the debug element for newly detected features.
Definition SLAMDebugElements.h:65
@ EI_OBJECT_POINTS
The id of the debug element for 3D object point projections.
Definition SLAMDebugElements.h:67
@ EI_TRACKED_IMAGE_POINTS
The id of the debug element for tracked image point correspondences.
Definition SLAMDebugElements.h:63
@ EI_IMAGE_POINTS
The id of the debug element for 2D image point tracks.
Definition SLAMDebugElements.h:69
This class implements a 3D triangle.
Definition Triangle3.h:80
uint32_t Index32
Definition of a 32 bit index value.
Definition Base.h:84
std::unordered_map< Index32, LocalizedObjectPoint > LocalizedObjectPointMap
Definition of an unordered map mapping object point ids to localized object points.
Definition LocalizedObjectPoint.h:43
std::unordered_map< Index32, PointTrack > PointTrackMap
Definition of an unordered map mapping object point ids to point tracks.
Definition PointTrack.h:32
The namespace covering the entire Ocean framework.
Definition Accessor.h:15