Monado OpenXR Runtime
xrt_plane_detector.h
Go to the documentation of this file.
1// Copyright 2023-2025, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Header defining planes detector enum and structs.
6 * @author Christoph Haag <christoph.haag@collabora.com>
7 * @ingroup xrt_iface
8 */
9
10
11#pragma once
12
13#include "xrt/xrt_defines.h"
14#include "xrt/xrt_limits.h"
15
16#include <stdlib.h>
17#include <string.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23
24/*!
25 * Caps for a plane detector, see @ref xrt_device.
26 *
27 * @ingroup xrt_iface
28 */
30{
31 XRT_PLANE_DETECTION_CAPABILITY_PLANE_DETECTION_BIT_EXT = 0x00000001,
32 XRT_PLANE_DETECTION_CAPABILITY_PLANE_HOLES_BIT_EXT = 0x00000002,
33 XRT_PLANE_DETECTION_CAPABILITY_SEMANTIC_CEILING_BIT_EXT = 0x00000004,
34 XRT_PLANE_DETECTION_CAPABILITY_SEMANTIC_FLOOR_BIT_EXT = 0x00000008,
35 XRT_PLANE_DETECTION_CAPABILITY_SEMANTIC_WALL_BIT_EXT = 0x00000010,
36 XRT_PLANE_DETECTION_CAPABILITY_SEMANTIC_PLATFORM_BIT_EXT = 0x00000020,
37 XRT_PLANE_DETECTION_CAPABILITY_ORIENTATION_BIT_EXT = 0x00000040,
38};
39
40/*!
41 * Flags used when running plane detection.
42 *
43 * @ingroup xrt_iface
44 */
46{
47 XRT_PLANE_DETECTOR_FLAGS_CONTOUR_EXT = 1,
48};
49
50/*!
51 * Orientation of a plane.
52 *
53 * @ingroup xrt_iface
54 */
56{
57 XRT_PLANE_DETECTOR_ORIENTATION_HORIZONTAL_UPWARD_EXT = 0,
58 XRT_PLANE_DETECTOR_ORIENTATION_HORIZONTAL_DOWNWARD_EXT = 1,
59 XRT_PLANE_DETECTOR_ORIENTATION_VERTICAL_EXT = 2,
60 XRT_PLANE_DETECTOR_ORIENTATION_ARBITRARY_EXT = 3,
61};
62
63/*!
64 * Has this plane any semantic meaning?
65 *
66 * @ingroup xrt_iface
67 */
69{
70 XRT_PLANE_DETECTOR_SEMANTIC_TYPE_UNDEFINED_EXT = 0,
71 XRT_PLANE_DETECTOR_SEMANTIC_TYPE_CEILING_EXT = 1,
72 XRT_PLANE_DETECTOR_SEMANTIC_TYPE_FLOOR_EXT = 2,
73 XRT_PLANE_DETECTOR_SEMANTIC_TYPE_WALL_EXT = 3,
74 XRT_PLANE_DETECTOR_SEMANTIC_TYPE_PLATFORM_EXT = 4,
75};
76
77/*!
78 * State of a plane detector, see @ref xrt_device.
79 *
80 * @ingroup xrt_iface
81 */
83{
84 XRT_PLANE_DETECTOR_STATE_NONE_EXT = 0,
85 XRT_PLANE_DETECTOR_STATE_PENDING_EXT = 1,
86 XRT_PLANE_DETECTOR_STATE_DONE_EXT = 2,
87 XRT_PLANE_DETECTOR_STATE_ERROR_EXT = 3,
88 XRT_PLANE_DETECTOR_STATE_FATAL_EXT = 4,
89};
90
91/*!
92 * A query for a plane. Corresponds to XrPlaneDetectorBeginInfoEXT.
93 *
94 * @ingroup xrt_iface
95 */
97{
98 enum xrt_plane_detector_flags_ext detector_flags;
99 uint32_t orientation_count;
101 uint32_t semantic_type_count;
103 uint32_t max_planes;
104 float min_area;
105 struct xrt_pose bounding_box_pose;
106 //! width, height, depth
108};
109
110/*!
111 * Location and other info for a plane.
112 *
113 * @ingroup xrt_iface
114 */
116{
117 uint64_t planeId;
118 struct xrt_space_relation relation;
119 //! x = width, y = height
122 enum xrt_plane_detector_semantic_type_ext semantic_type;
123 uint32_t polygon_buffer_count;
124};
125
126/*!
127 * Helper struct to pair up metadata for one polygon.
128 *
129 * @ingroup xrt_iface
130 */
132{
133 uint32_t vertex_count;
134
135 //! Index into the continuous array of vertices for all planes of a query.
137};
138
139/*!
140 * Each plane has n polygons; ultimately plane metadata from @ref locations and @ref vetices is
141 * reconstructed. Therefore lay out the data in flattened arrays:
142 *
143 * @ref locations stores continuous metadata for each plane:
144 * location 1 | location 2 | location 3 | location 4 | ...
145 *
146 * @ref polygon_info_start_index is a helper array to go from a location entry to a polygon_info entry.
147 *
148 * @ref polygon_info stores info (metadata) for each polygon, flattened:
149 * plane 1 polygon 1 info | plane 1 polygon 2 info | ... | plane 2 polygon 1 info | ...
150 *
151 * @ref polygon_info.vertices_start_index is a helper array to go from a polygon_info entry to vertices
152 * entry.
153 *
154 * @ref vertices stores vertex data for each polygon, for each plane, flattened:
155 * plane 1 polygon 1 vertex 1 | plane 1 polygon 1 vertex 2 | ... | plane 1 polygon 2 vertex 1 | ...
156 *
157 * To reconstruct the vertices of a certain plane polygon:
158 * - Find the index i of the plane with the requested plane_id in the locations array.
159 * - Use this index i to generate a new index j = polygon_info_start_index[i].
160 * - polygon_info[j] is the info of the first polygon of the locations[i] plane.
161 * - polygon_info[j + polygonBufferIndex] is the info of the requested polygon.
162 * - polygon_info[j + polygonBufferIndex].vertex_count is the vertex count of this polygon.
163 * - polygon_info[j + polygonBufferIndex].vertices_start_index is another new index k.
164 * - vertices[k] is the first vertex of the requested polygon.
165 *
166 * Convention: Whoever writes to this struct checks the size values first and reallocates arrays if necessary.
167 *
168 * @ingroup xrt_iface
169 */
171{
172 //! How many locations were found.
174
175 //! size of @ref locations and @ref polygon_info_start_index arrays.
177
178 ///! array of detected locations.
180
181 //! Parallel array to @ref locations.
182 //! Index into @ref polygon_info of polygon_infos for all planes of a query.
184
185 //! size of @ref polygon_infos array.
187
188 //! Continuous array of polygon_infos of all polygons for all planes of a query.
190
191 //! size of @ref vertices array.
192 uint32_t vertex_size;
193
194 //! Continuous array of polygon vertices of all polygons for all planes of a query.
196};
197
198/*!
199 * Small helper to free any data of a @ref xrt_plane_detections_ext struct,
200 * does not free the struct itself.
201 *
202 * @ingroup xrt_iface
203 */
204static inline void
206{
207 free(detections->locations);
208 free(detections->polygon_info_start_index);
209 free(detections->polygon_infos);
210 free(detections->vertices);
211 memset(detections, 0, sizeof(*detections));
212}
213
214
215#ifdef __cplusplus
216}
217#endif
#define XRT_MAX_PLANE_ORIENTATIONS_EXT
Max number of plane orientations that can be requested at a time.
Definition: xrt_limits.h:44
xrt_plane_detection_capability_flags_ext
Caps for a plane detector, see xrt_device.
Definition: xrt_plane_detector.h:30
xrt_plane_detector_orientation_ext
Orientation of a plane.
Definition: xrt_plane_detector.h:56
#define XRT_MAX_PLANE_SEMANTIC_TYPE_EXT
Max number of plane semantic types that can be requested at a time.
Definition: xrt_limits.h:49
xrt_plane_detector_semantic_type_ext
Has this plane any semantic meaning?
Definition: xrt_plane_detector.h:69
xrt_plane_detector_flags_ext
Flags used when running plane detection.
Definition: xrt_plane_detector.h:46
xrt_plane_detector_state_ext
State of a plane detector, see xrt_device.
Definition: xrt_plane_detector.h:83
static void xrt_plane_detections_ext_clear(struct xrt_plane_detections_ext *detections)
Small helper to free any data of a xrt_plane_detections_ext struct, does not free the struct itself.
Definition: xrt_plane_detector.h:205
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:199
Each plane has n polygons; ultimately plane metadata from locations and vetices is reconstructed.
Definition: xrt_plane_detector.h:171
uint32_t location_size
size of locations and polygon_info_start_index arrays.
Definition: xrt_plane_detector.h:176
uint32_t polygon_info_size
size of polygon_infos array.
Definition: xrt_plane_detector.h:186
struct xrt_vec2 * vertices
Continuous array of polygon vertices of all polygons for all planes of a query.
Definition: xrt_plane_detector.h:195
struct xrt_plane_polygon_info_ext * polygon_infos
Continuous array of polygon_infos of all polygons for all planes of a query.
Definition: xrt_plane_detector.h:189
uint32_t location_count
How many locations were found.
Definition: xrt_plane_detector.h:173
uint32_t * polygon_info_start_index
Parallel array to locations.
Definition: xrt_plane_detector.h:183
uint32_t vertex_size
size of vertices array.
Definition: xrt_plane_detector.h:192
struct xrt_plane_detector_location_ext * locations
! array of detected locations.
Definition: xrt_plane_detector.h:179
A query for a plane.
Definition: xrt_plane_detector.h:97
struct xrt_vec3 bounding_box_extent
width, height, depth
Definition: xrt_plane_detector.h:107
Location and other info for a plane.
Definition: xrt_plane_detector.h:116
struct xrt_vec2 extents
x = width, y = height
Definition: xrt_plane_detector.h:120
Helper struct to pair up metadata for one polygon.
Definition: xrt_plane_detector.h:132
uint32_t vertices_start_index
Index into the continuous array of vertices for all planes of a query.
Definition: xrt_plane_detector.h:136
A pose composed of a position and orientation.
Definition: xrt_defines.h:465
A relation with two spaces, includes velocity and acceleration.
Definition: xrt_defines.h:657
A 2 element vector with single floats.
Definition: xrt_defines.h:250
A 3 element vector with single floats.
Definition: xrt_defines.h:271
Common defines and enums for XRT.
Header for limits of the XRT interfaces.