The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

tests: Add case for Levenberg-Marquardt optimizer

+81 -14
+21 -14
tests/CMakeLists.txt
··· 10 10 endif() 11 11 12 12 set(tests 13 - tests_cxx_wrappers 14 - tests_generic_callbacks 15 - tests_history_buf 16 - tests_id_ringbuffer 17 - tests_input_transform 18 - tests_json 19 - tests_lowpass_float 20 - tests_lowpass_integer 21 - tests_pacing 22 - tests_quatexpmap 23 - tests_rational 24 - tests_worker 25 - tests_pose 13 + tests_cxx_wrappers 14 + tests_generic_callbacks 15 + tests_history_buf 16 + tests_id_ringbuffer 17 + tests_input_transform 18 + tests_json 19 + tests_lowpass_float 20 + tests_lowpass_integer 21 + tests_pacing 22 + tests_quatexpmap 23 + tests_rational 24 + tests_worker 25 + tests_pose 26 26 ) 27 27 if(XRT_HAVE_D3D11) 28 28 list(APPEND tests tests_aux_d3d tests_comp_client_d3d11) ··· 30 30 if(XRT_HAVE_VULKAN) 31 31 list(APPEND tests tests_comp_client_vulkan) 32 32 endif() 33 - foreach(testname ${tests}) 33 + if(XRT_BUILD_DRIVER_HANDTRACKING) 34 + list(APPEND tests tests_levenbergmarquardt) 35 + endif() 34 36 37 + foreach(testname ${tests}) 35 38 add_executable(${testname} ${testname}.cpp) 36 39 target_link_libraries(${testname} PRIVATE tests_main) 37 40 target_link_libraries(${testname} PRIVATE aux_util) ··· 48 51 target_link_libraries(tests_quatexpmap PRIVATE aux_math) 49 52 target_link_libraries(tests_rational PRIVATE aux_math) 50 53 target_link_libraries(tests_pose PRIVATE aux_math) 54 + 55 + if(XRT_BUILD_DRIVER_HANDTRACKING) 56 + target_link_libraries(tests_levenbergmarquardt PRIVATE aux_math t_ht_mercury_includes t_ht_mercury_kine_lm_includes t_ht_mercury t_ht_mercury_kine_lm) 57 + endif() 51 58 52 59 if(XRT_HAVE_D3D11) 53 60 target_link_libraries(tests_aux_d3d PRIVATE aux_d3d)
+60
tests/tests_levenbergmarquardt.cpp
··· 1 + // Copyright 2022, Collabora, Inc. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Test for Levenberg-Marquardt kinematic optimizer 6 + * @author Moses Turner <moses@collabora.com> 7 + * @author Ryan Pavlik <ryan.pavlik@collabora.com> 8 + */ 9 + #include "util/u_logging.h" 10 + #include "xrt/xrt_defines.h" 11 + #include <util/u_worker.hpp> 12 + #include <math/m_space.h> 13 + #include <math/m_vec3.h> 14 + 15 + #include "kine_common.hpp" 16 + #include "lm_interface.hpp" 17 + 18 + #include "catch/catch.hpp" 19 + 20 + #include <thread> 21 + #include <chrono> 22 + #include "fenv.h" 23 + 24 + using namespace xrt::tracking::hand::mercury; 25 + 26 + TEST_CASE("LevenbergMarquardt") 27 + { 28 + // This does very little at the moment: 29 + // * It will explode if any floating point exceptions are generated 30 + // * You should run it with `valgrind --track-origins=yes` (and compile without optimizations so that origin 31 + // tracking works well) to see if we are using any uninitialized values. 32 + 33 + fetestexcept(FE_ALL_EXCEPT); 34 + 35 + struct one_frame_input input = {}; 36 + 37 + for (int i = 0; i < 21; i++) { 38 + 39 + input.views[0].rays[i] = m_vec3_normalize({0, (float)i, -1}); //{0,(float)i,-1}; 40 + input.views[1].rays[i] = m_vec3_normalize({(float)i, 0, -1}); 41 + input.views[0].confidences[i] = 1; 42 + input.views[1].confidences[i] = 1; 43 + } 44 + 45 + lm::KinematicHandLM *hand; 46 + 47 + xrt_pose left_in_right = XRT_POSE_IDENTITY; 48 + left_in_right.position.x = 1; 49 + 50 + lm::optimizer_create(left_in_right, false, U_LOGGING_TRACE, &hand); 51 + 52 + 53 + xrt_hand_joint_set out; 54 + float out_hand_size; 55 + float out_reprojection_error; 56 + lm::optimizer_run(hand, input, true, true, 0.09, 0.5, out, out_hand_size, out_reprojection_error); 57 + 58 + CHECK(std::isfinite(out_reprojection_error)); 59 + CHECK(std::isfinite(out_hand_size)); 60 + }