gaze_residual.cpp
Go to the documentation of this file.
1#include "gaze_residual.h"
2
3#include <algorithm>
4#include <cmath>
5
7{
8
10 computeGazeResidual(const Eigen::Vector3f& currentGazeDirection,
11 const Eigen::Vector3f& targetDirection,
12 const float targetDistance)
13 {
14 const float currentNorm = currentGazeDirection.norm();
15 const float targetNorm = targetDirection.norm();
16
17 // Either direction is degenerate: the angle between them is not defined. Report no error
18 // rather than a NaN that would silently poison the scheduler's thresholds.
19 if (currentNorm < 1e-6F or targetNorm < 1e-6F)
20 {
21 return GazeResidual{.angularError = 0.F, .lateralError = 0.F};
22 }
23
24 const float cosAngle =
25 std::clamp((currentGazeDirection / currentNorm).dot(targetDirection / targetNorm),
26 -1.F,
27 1.F);
28 const float angularError = std::acos(cosAngle);
29
30 return GazeResidual{.angularError = angularError,
31 .lateralError = std::sin(angularError) * std::abs(targetDistance)};
32 }
33
34} // namespace armarx::view_selection::gaze_controller
GazeResidual computeGazeResidual(const Eigen::Vector3f &currentGazeDirection, const Eigen::Vector3f &targetDirection, const float targetDistance)
The gaze residual, in a form that means the same thing for every controller variant.
double dot(const Point &x, const Point &y)
Definition point.hpp:57
How far the gaze currently is from a target.