Monado OpenXR Runtime
u_distortion_mesh.h
Go to the documentation of this file.
1 // Copyright 2019, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Code to generate disortion meshes.
6  * @author Jakob Bornecrantz <jakob@collabora.com>
7  * @author Moses Turner <moses@collabora.com>
8  * @ingroup aux_distortion
9  */
10 
11 #pragma once
12 
13 #include "xrt/xrt_device.h"
14 #include "xrt/xrt_defines.h"
15 
16 #include "util/u_distortion.h"
17 
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 
24 /*
25  *
26  * Panotools distortion
27  *
28  */
29 
30 /*!
31  * Values to create a distortion mesh from panotools values.
32  *
33  * @ingroup aux_distortion
34  */
36 {
37  //! Panotools universal distortion k (reverse order from OpenHMD).
38  float distortion_k[5];
39  //! Panotools post distortion scale, <r, g, b>.
40  float aberration_k[3];
41  //! Panotools warp scale.
42  float scale;
43  //! Center of the lens.
44  struct xrt_vec2 lens_center;
45  //! Viewport size.
46  struct xrt_vec2 viewport_size;
47 };
48 
49 /*!
50  * Distortion correction implementation for Panotools distortion values.
51  *
52  * @ingroup aux_distortion
53  */
54 bool
55 u_compute_distortion_panotools(struct u_panotools_values *values, float u, float v, struct xrt_uv_triplet *result);
56 
57 
58 /*
59  *
60  * Vive, Vive Pro & Index distortion
61  *
62  */
63 
64 /*!
65  * Values to create a distortion mesh from Vive configuration values.
66  *
67  * @ingroup aux_distortion
68  */
70 {
71  float aspect_x_over_y;
72  float grow_for_undistort;
73 
74  float undistort_r2_cutoff;
75 
76  //! r/g/b
77  struct xrt_vec2 center[3];
78 
79  //! r/g/b, a/b/c/d
80  float coefficients[3][4];
81 };
82 
83 /*!
84  * Distortion correction implementation for the Vive, Vive Pro, Valve Index
85  * distortion values found in the HMD configuration.
86  *
87  * @ingroup aux_distortion
88  */
89 bool
90 u_compute_distortion_vive(struct u_vive_values *values, float u, float v, struct xrt_uv_triplet *result);
91 
92 
93 /*
94  *
95  * Cardboard mesh distortion parameters.
96  *
97  */
98 
99 /*!
100  * Distortion correction implementation for the Cardboard devices.
101  *
102  * @ingroup aux_distortion
103  */
104 bool
106  float u,
107  float v,
108  struct xrt_uv_triplet *result);
109 
110 
111 /*
112  *
113  * Values for North Star 2D/Polynomial distortion correction.
114  *
115  */
116 
118 {
119  float x_coefficients_left[16];
120  float x_coefficients_right[16];
121  float y_coefficients_left[16];
122  float y_coefficients_right[16];
123  struct xrt_fov fov[2]; // left, right
124  float ipd;
125 };
126 
127 /*!
128  * Distortion correction implementation for North Star 2D/Polynomial.
129  *
130  * @ingroup aux_distortion
131  */
132 bool
133 u_compute_distortion_ns_p2d(struct u_ns_p2d_values *values, int view, float u, float v, struct xrt_uv_triplet *result);
134 
135 /*
136  *
137  * Values for Moshi Turner's North Star distortion correction.
138  *
139  */
141 {
142  int number_of_ipds;
143  float *ipds;
144  int num_grid_points_u;
145  int num_grid_points_v;
146  struct xrt_vec2 *grid[2];
147  struct xrt_fov fov[2]; // left, right
148  float ipd;
149 };
150 
151 /*!
152  * Moshi Turner's North Star distortion correction implementation
153  *
154  * @ingroup aux_distortion
155  */
156 bool
158  struct u_ns_meshgrid_values *values, int view, float u, float v, struct xrt_uv_triplet *result);
159 
160 
161 /*
162  *
163  * None distortion
164  *
165  */
166 
167 /*!
168  * Identity distortion correction sets all result coordinates to u,v.
169  *
170  * @ingroup aux_distortion
171  */
172 bool
173 u_compute_distortion_none(float u, float v, struct xrt_uv_triplet *result);
174 
175 /*!
176  * Helper function for none distortion devices.
177  *
178  * @ingroup aux_distortion
179  */
180 bool
181 u_distortion_mesh_none(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result);
182 
183 
184 /*
185  *
186  * Mesh generation functions.
187  *
188  */
189 
190 /*!
191  * Given a @ref xrt_device generates meshes by calling
192  * xdev->compute_distortion(), populates `xdev->hmd_parts.distortion.mesh` &
193  * `xdev->hmd_parts.distortion.models`.
194  *
195  * @relatesalso xrt_device
196  * @ingroup aux_distortion
197  */
198 void
200 
201 /*!
202  * Given a @ref xrt_device generates a no distortion mesh, populates
203  * `xdev->hmd_parts.distortion.mesh` & `xdev->hmd_parts.distortion.models`.
204  *
205  * @relatesalso xrt_device
206  * @ingroup aux_distortion
207  */
208 void
210 
211 /*!
212  * Given a @ref xrt_device generates a no distortion mesh, also sets
213  * `xdev->compute_distortion()` and populates `xdev->hmd_parts.distortion.mesh`
214  * & `xdev->hmd_parts.distortion.models`.
215  *
216  * @relatesalso xrt_device
217  * @ingroup aux_distortion
218  */
219 void
221 
222 
223 #ifdef __cplusplus
224 }
225 #endif
bool u_compute_distortion_ns_p2d(struct u_ns_p2d_values *values, int view, float u, float v, struct xrt_uv_triplet *result)
Distortion correction implementation for North Star 2D/Polynomial.
Definition: u_distortion_mesh.c:294
void u_distortion_mesh_fill_in_none(struct xrt_device *xdev)
Given a xrt_device generates a no distortion mesh, populates xdev->hmd_parts.distortion....
Definition: u_distortion_mesh.c:436
bool u_compute_distortion_vive(struct u_vive_values *values, float u, float v, struct xrt_uv_triplet *result)
Distortion correction implementation for the Vive, Vive Pro, Valve Index distortion values found in t...
Definition: u_distortion_mesh.c:128
void u_distortion_mesh_fill_in_compute(struct xrt_device *xdev)
Given a xrt_device generates meshes by calling xdev->compute_distortion(), populates xdev->hmd_parts....
Definition: u_distortion_mesh.c:474
bool u_compute_distortion_none(float u, float v, struct xrt_uv_triplet *result)
Identity distortion correction sets all result coordinates to u,v.
Definition: u_distortion_mesh.c:410
bool u_compute_distortion_ns_meshgrid(struct u_ns_meshgrid_values *values, int view, float u, float v, struct xrt_uv_triplet *result)
Moshi Turner's North Star distortion correction implementation.
Definition: u_distortion_mesh.c:334
bool u_compute_distortion_panotools(struct u_panotools_values *values, float u, float v, struct xrt_uv_triplet *result)
Distortion correction implementation for Panotools distortion values.
Definition: u_distortion_mesh.c:199
bool u_compute_distortion_cardboard(struct u_cardboard_distortion_values *values, float u, float v, struct xrt_uv_triplet *result)
Distortion correction implementation for the Cardboard devices.
Definition: u_distortion_mesh.c:237
bool u_distortion_mesh_none(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result)
Helper function for none distortion devices.
Definition: u_distortion_mesh.c:430
void u_distortion_mesh_set_none(struct xrt_device *xdev)
Given a xrt_device generates a no distortion mesh, also sets xdev->compute_distortion() and populates...
Definition: u_distortion_mesh.c:450
Values to create a distortion mesh from cardboard values.
Definition: u_distortion.h:70
Definition: u_distortion_mesh.h:141
Definition: u_distortion_mesh.h:118
Values to create a distortion mesh from panotools values.
Definition: u_distortion_mesh.h:36
struct xrt_vec2 viewport_size
Viewport size.
Definition: u_distortion_mesh.h:46
float scale
Panotools warp scale.
Definition: u_distortion_mesh.h:42
float distortion_k[5]
Panotools universal distortion k (reverse order from OpenHMD).
Definition: u_distortion_mesh.h:38
float aberration_k[3]
Panotools post distortion scale, <r, g, b>.
Definition: u_distortion_mesh.h:40
struct xrt_vec2 lens_center
Center of the lens.
Definition: u_distortion_mesh.h:44
Values to create a distortion mesh from Vive configuration values.
Definition: u_distortion_mesh.h:70
float coefficients[3][4]
r/g/b, a/b/c/d
Definition: u_distortion_mesh.h:80
struct xrt_vec2 center[3]
r/g/b
Definition: u_distortion_mesh.h:77
A single HMD or input device.
Definition: xrt_device.h:230
Describes a projection matrix fov.
Definition: xrt_defines.h:486
Represents a uv triplet for distortion, basically just three xrt_vec2.
Definition: xrt_defines.h:261
A 2 element vector with single floats.
Definition: xrt_defines.h:250
Code to handle distortion parameters and fov.
Common defines and enums for XRT.
Header defining an xrt display or controller device.