a/util: Resolve warnings

This commit is contained in:
Ryan Pavlik 2022-07-13 12:21:51 -05:00
parent 88389ae0ca
commit 107f56b6d9
4 changed files with 50 additions and 53 deletions

View file

@ -27,51 +27,51 @@ DEBUG_GET_ONCE_NUM_OPTION(mesh_size, "XRT_MESH_SIZE", 64)
typedef bool (*func_calc)(struct xrt_device *xdev, int view, float u, float v, struct xrt_uv_triplet *result);
static int
index_for(int row, int col, int stride, int offset)
index_for(int row, int col, uint32_t stride, uint32_t offset)
{
return row * stride + col + offset;
}
void
run_func(struct xrt_device *xdev, func_calc calc, int view_count, struct xrt_hmd_parts *target, size_t num)
static void
run_func(struct xrt_device *xdev, func_calc calc, int view_count, struct xrt_hmd_parts *target, uint32_t num)
{
assert(calc != NULL);
assert(view_count == 2);
assert(view_count <= 2);
size_t vertex_offsets[2] = {0};
size_t index_offsets[2] = {0};
uint32_t vertex_offsets[2] = {0};
uint32_t index_offsets[2] = {0};
int cells_cols = num;
int cells_rows = num;
int vert_cols = cells_cols + 1;
int vert_rows = cells_rows + 1;
uint32_t cells_cols = num;
uint32_t cells_rows = num;
uint32_t vert_cols = cells_cols + 1;
uint32_t vert_rows = cells_rows + 1;
size_t vertex_count_per_view = vert_rows * vert_cols;
size_t vertex_count = vertex_count_per_view * view_count;
uint32_t vertex_count_per_view = vert_rows * vert_cols;
uint32_t vertex_count = vertex_count_per_view * view_count;
size_t uv_channels_count = 3;
size_t stride_in_floats = 2 + uv_channels_count * 2;
size_t float_count = vertex_count * stride_in_floats;
uint32_t uv_channels_count = 3;
uint32_t stride_in_floats = 2 + uv_channels_count * 2;
uint32_t float_count = vertex_count * stride_in_floats;
float *verts = U_TYPED_ARRAY_CALLOC(float, float_count);
// Setup the vertices for all views.
size_t i = 0;
uint32_t i = 0;
for (int view = 0; view < view_count; view++) {
vertex_offsets[view] = i / stride_in_floats;
for (int r = 0; r < vert_rows; r++) {
for (uint32_t r = 0; r < vert_rows; r++) {
// This goes from 0 to 1.0 inclusive.
float v = (float)r / (float)cells_rows;
for (int c = 0; c < vert_cols; c++) {
for (uint32_t c = 0; c < vert_cols; c++) {
// This goes from 0 to 1.0 inclusive.
float u = (float)c / (float)cells_cols;
// Make the position in the range of [-1, 1]
verts[i + 0] = u * 2.0 - 1.0;
verts[i + 1] = v * 2.0 - 1.0;
verts[i + 0] = u * 2.0f - 1.0f;
verts[i + 1] = v * 2.0f - 1.0f;
if (!calc(xdev, view, u, v, (struct xrt_uv_triplet *)&verts[i + 2])) {
// bail on error, without updating
@ -84,8 +84,8 @@ run_func(struct xrt_device *xdev, func_calc calc, int view_count, struct xrt_hmd
}
}
size_t index_count_per_view = cells_rows * (vert_cols * 2 + 2);
size_t index_count_total = index_count_per_view * view_count;
uint32_t index_count_per_view = cells_rows * (vert_cols * 2 + 2);
uint32_t index_count_total = index_count_per_view * view_count;
int *indices = U_TYPED_ARRAY_CALLOC(int, index_count_total);
// Set up indices for all views.
@ -93,13 +93,13 @@ run_func(struct xrt_device *xdev, func_calc calc, int view_count, struct xrt_hmd
for (int view = 0; view < view_count; view++) {
index_offsets[view] = i;
size_t off = vertex_offsets[view];
uint32_t off = vertex_offsets[view];
for (int r = 0; r < cells_rows; r++) {
for (uint32_t r = 0; r < cells_rows; r++) {
// Top vertex row for this cell row, left most vertex.
indices[i++] = index_for(r, 0, vert_cols, off);
for (int c = 0; c < vert_cols; c++) {
for (uint32_t c = 0; c < vert_cols; c++) {
indices[i++] = index_for(r, c, vert_cols, off);
indices[i++] = index_for(r + 1, c, vert_cols, off);
}
@ -129,20 +129,20 @@ u_compute_distortion_vive(struct u_vive_values *values, float u, float v, struct
// Reading the whole struct like this gives the compiler more opportunity to optimize.
const struct u_vive_values val = *values;
const float common_factor_value = 0.5 / (1.0 + val.grow_for_undistort);
const float common_factor_value = 0.5f / (1.0f + val.grow_for_undistort);
const struct xrt_vec2 factor = {
common_factor_value,
common_factor_value * val.aspect_x_over_y,
};
// Results r/g/b.
struct xrt_vec2 tc[3];
struct xrt_vec2 tc[3] = {{0, 0}, {0, 0}, {0, 0}};
// Dear compiler, please vectorize.
for (int i = 0; i < 3; i++) {
struct xrt_vec2 texCoord = {
2.0 * u - 1.0,
2.0 * v - 1.0,
2.f * u - 1.f,
2.f * v - 1.f,
};
texCoord.y /= val.aspect_x_over_y;
@ -167,11 +167,11 @@ u_compute_distortion_vive(struct u_vive_values *values, float u, float v, struct
* 1.0 + r^2 * ((k1 + r^2 * k2) + r^2 * k3)
*/
float top = 1.0;
float bottom = 1.0 + r2 * (k1 + r2 * (k2 + r2 * k3));
float top = 1.f;
float bottom = 1.f + r2 * (k1 + r2 * (k2 + r2 * k3));
float d = (top / bottom) + k4;
struct xrt_vec2 offset = {0.5, 0.5};
struct xrt_vec2 offset = {0.5f, 0.5f};
tc[i].x = offset.x + (texCoord.x * d + val.center[i].x) * factor.x;
tc[i].y = offset.y + (texCoord.y * d + val.center[i].y) * factor.y;
@ -294,7 +294,7 @@ u_compute_distortion_ns_p2d(struct u_ns_p2d_values *values, int view, float u, f
{
// I think that OpenCV and Monado have different definitions of v coordinates, but not sure. if not,
// unexplainable
v = 1.0 - v;
v = 1.0f - v;
float x_ray = u_ns_polyval2d(u, v, view ? values->x_coefficients_left : values->x_coefficients_right);
float y_ray = u_ns_polyval2d(u, v, view ? values->y_coefficients_left : values->y_coefficients_right);
@ -306,9 +306,9 @@ u_compute_distortion_ns_p2d(struct u_ns_p2d_values *values, int view, float u, f
float up_ray_bound = tanf(fov.angle_up);
float down_ray_bound = tanf(fov.angle_down);
float u_eye = math_map_ranges(x_ray, left_ray_bound, right_ray_bound, 0, 1);
float u_eye = (float)math_map_ranges(x_ray, left_ray_bound, right_ray_bound, 0, 1);
float v_eye = math_map_ranges(y_ray, down_ray_bound, up_ray_bound, 0, 1);
float v_eye = (float)math_map_ranges(y_ray, down_ray_bound, up_ray_bound, 0, 1);
// boilerplate, put the UV coordinates in all the RGB slots
result->r.x = u_eye;
@ -333,8 +333,8 @@ u_compute_distortion_ns_p2d(struct u_ns_p2d_values *values, int view, float u, f
bool
u_compute_distortion_ns_vipd(struct u_ns_vipd_values *values, int view, float u, float v, struct xrt_uv_triplet *result)
{
int u_index_int = floorf(u * 64);
int v_index_int = floorf(v * 64);
int u_index_int = (int)floorf(u * 64);
int v_index_int = (int)floorf(v * 64);
float u_index_frac = (u * 64) - u_index_int;
float v_index_frac = (v * 64) - v_index_int;
@ -349,12 +349,12 @@ u_compute_distortion_ns_vipd(struct u_ns_vipd_values *values, int view, float u,
struct xrt_vec2 topright = values->grid_for_use.grid[view][v_index_int][u_index_int + 1];
struct xrt_vec2 bottomleft = values->grid_for_use.grid[view][v_index_int + 1][u_index_int];
struct xrt_vec2 bottomright = values->grid_for_use.grid[view][v_index_int + 1][u_index_int + 1];
struct xrt_vec2 leftcorrect = {math_map_ranges(v_index_frac, 0, 1, topleft.x, bottomleft.x),
math_map_ranges(v_index_frac, 0, 1, topleft.y, bottomleft.y)};
struct xrt_vec2 rightcorrect = {math_map_ranges(v_index_frac, 0, 1, topright.x, bottomright.x),
math_map_ranges(v_index_frac, 0, 1, topright.y, bottomright.y)};
y_ray = math_map_ranges(u_index_frac, 0, 1, leftcorrect.x, rightcorrect.x);
x_ray = math_map_ranges(u_index_frac, 0, 1, leftcorrect.y, rightcorrect.y);
struct xrt_vec2 leftcorrect = {(float)math_map_ranges(v_index_frac, 0, 1, topleft.x, bottomleft.x),
(float)math_map_ranges(v_index_frac, 0, 1, topleft.y, bottomleft.y)};
struct xrt_vec2 rightcorrect = {(float)math_map_ranges(v_index_frac, 0, 1, topright.x, bottomright.x),
(float)math_map_ranges(v_index_frac, 0, 1, topright.y, bottomright.y)};
y_ray = (float)math_map_ranges(u_index_frac, 0, 1, leftcorrect.x, rightcorrect.x);
x_ray = (float)math_map_ranges(u_index_frac, 0, 1, leftcorrect.y, rightcorrect.y);
} else {
// probably this path if grid size is 65x65 like normal
x_ray = values->grid_for_use.grid[view][v_index_int][u_index_int].y;
@ -369,9 +369,9 @@ u_compute_distortion_ns_vipd(struct u_ns_vipd_values *values, int view, float u,
float down_ray_bound = tanf(fov.angle_down);
// printf("%f %f", fov.angle_down, fov.angle_up);
float u_eye = math_map_ranges(x_ray, left_ray_bound, right_ray_bound, 0, 1);
float u_eye = (float)math_map_ranges(x_ray, left_ray_bound, right_ray_bound, 0, 1);
float v_eye = math_map_ranges(y_ray, down_ray_bound, up_ray_bound, 0, 1);
float v_eye = (float)math_map_ranges(y_ray, down_ray_bound, up_ray_bound, 0, 1);
// boilerplate, put the UV coordinates in all the RGB slots
result->r.x = u_eye;
@ -462,6 +462,6 @@ u_distortion_mesh_fill_in_compute(struct xrt_device *xdev)
struct xrt_hmd_parts *target = xdev->hmd;
size_t num = debug_get_num_option_mesh_size();
uint32_t num = (uint32_t)debug_get_num_option_mesh_size();
run_func(xdev, calc, 2, target, num);
}

View file

@ -131,12 +131,6 @@ u_hand_joint_is_intermediate(enum xrt_hand_joint joint);
bool
u_hand_joint_is_distal(enum xrt_hand_joint joint);
/*!
* @ingroup aux_util
*/
bool
u_hand_joint_is_tip(enum xrt_hand_joint joint);
/*!
* @ingroup aux_util
*/

View file

@ -42,6 +42,9 @@ extern "C" struct time_state *
time_state_create()
{
time_state *state = new (std::nothrow) time_state;
if (!state) {
return state;
}
state->offset = os_monotonic_get_ns();
return state;
}

View file

@ -55,8 +55,8 @@ class Tracker
public:
std::unordered_map<std::string, size_t> counters = {};
std::unordered_map<ptrdiff_t, Obj> map = {};
bool on;
bool tested;
bool on = false;
bool tested = false;
public:
int