Ocean
Loading...
Searching...
No Matches
TestJacobian.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_TEST_TESTGEOMETRY_TEST_JACOBIAN_H
9#define META_OCEAN_TEST_TESTGEOMETRY_TEST_JACOBIAN_H
10
12
14
17
19
20namespace Ocean
21{
22
23namespace Test
24{
25
26namespace TestGeometry
27{
28
29/**
30 * This class implements Jacobian tests.
31 * @ingroup testgeometry
32 */
33class OCEAN_TEST_GEOMETRY_EXPORT TestJacobian : protected Geometry::Jacobian
34{
35 protected:
36
37 /**
38 * Base class for calculating numerical derivatives using central finite differences.
39 * @tparam T The data type of the derivative
40 * @tparam TScalar The scalar type for epsilon, either 'float' or 'double'
41 * @tparam TVariable The data type of a variable object which can change while while everything else is constant
42 */
43 template <typename T, typename TScalar, typename TVariable>
45 {
46 public:
47
48 /**
49 * Default constructor.
50 */
51 virtual ~DerivativeCalculatorT() = default;
52
53 /**
54 * Calculates the numerical derivative using central finite differences: f'(x) ≈ [f(x + epsilon) - f(x - epsilon)] / (2 * epsilon)
55 * @param variable The variable to calculate the derivative for
56 * @param parameterIndex The index of the parameter to perturb
57 * @param epsilon The epsilon value to use for the finite difference calculation
58 * @return The calculated derivative
59 */
60 T calculateDerivative(const TVariable& variable, const size_t parameterIndex, const TScalar epsilon = NumericT<TScalar>::weakEps() * TScalar(0.05)) const;
61
62 /**
63 * Verifies an analytical derivative by comparing it with a numerical approximation.
64 * Tests multiple epsilon values to find one that produces a match within tolerance.
65 * @param variable The variable to calculate the derivative for
66 * @param parameterIndex The index of the parameter to verify
67 * @param analyticalDerivative The analytical derivative to verify
68 * @return True if the analytical derivative matches the numerical approximation within tolerance
69 * @tparam TAnalyticalDerivative The type of the analytical derivative (e.g., Vector2, Vector3)
70 */
71 template <typename TAnalyticalDerivative>
72 bool verifyDerivative(const TVariable& variable, const size_t parameterIndex, const TAnalyticalDerivative& analyticalDerivative) const;
73
74 protected:
75
76 /**
77 * Calculates the function value with an offset applied to a specific parameter.
78 * Must be implemented by derived classes.
79 * @param variable The variable to evaluate
80 * @param parameterIndex The index of the parameter to perturb
81 * @param offset The offset to apply
82 * @return The calculated function value
83 */
84 virtual T calculateValue(const TVariable& variable, const size_t parameterIndex, const TScalar offset) const = 0;
85 };
86
87 /**
88 * Base class for calculating numerical derivatives using central finite differences.
89 * This class is a specialization of DerivativeCalculatorT without a variable object.
90 * @tparam T The result type (e.g., VectorT2<Scalar>, VectorT3<Scalar>)
91 * @tparam TScalar The scalar type for epsilon, either 'float' or 'double'
92 */
93 template <typename T, typename TScalar>
94 class DerivativeCalculatorT<T, TScalar, void>
95 {
96 public:
97
98 /**
99 * Default constructor.
100 */
101 virtual ~DerivativeCalculatorT() = default;
102
103 /**
104 * Calculates the numerical derivative using central finite differences: f'(x) ≈ [f(x + epsilon) - f(x - epsilon)] / (2 * epsilon)
105 * @param parameterIndex The index of the parameter to perturb
106 * @param epsilon The epsilon value to use for the finite difference calculation
107 * @return The calculated derivative
108 */
109 T calculateDerivative(const size_t parameterIndex, const TScalar epsilon = NumericT<TScalar>::weakEps() * TScalar(0.05)) const;
110
111 /**
112 * Verifies an analytical derivative by comparing it with a numerical approximation.
113 * Tests multiple epsilon values to find one that produces a match within tolerance.
114 * @param parameterIndex The index of the parameter to verify
115 * @param analyticalDerivative The analytical derivative to verify
116 * @return True if the analytical derivative matches the numerical approximation within tolerance
117 * @tparam TAnalyticalDerivative The type of the analytical derivative (e.g., Vector2, Vector3)
118 */
119 template <typename TAnalyticalDerivative>
120 bool verifyDerivative(const size_t parameterIndex, const TAnalyticalDerivative& analyticalDerivative) const;
121
122 protected:
123
124 /**
125 * Calculates the function value with an offset applied to a specific parameter.
126 * Must be implemented by derived classes.
127 * @param parameterIndex The index of the parameter to perturb
128 * @param offset The offset to apply
129 * @return The calculated function value
130 */
131 virtual T calculateValue(const size_t parameterIndex, const TScalar offset) const = 0;
132 };
133
134 /// Forward declaration.
135 template <typename T>
137
138 /// Forward declaration.
139 template <typename T>
141
142 /// Forward declaration.
143 template <typename T>
145
146 /// Forward declaration.
147 template <typename T>
149
150 /// Forward declaration.
151 template <typename T>
153
154 /// Forward declaration.
155 template <typename T>
157
158 /// Forward declaration.
159 template <typename T>
161
162 /// Forward declaration.
163 template <typename T>
165
166 /// Forward declaration.
167 template <typename T>
169
170 /// Forward declaration.
171 template <typename T>
173
174 /// Forward declaration.
175 template <typename T>
177
178 /// Forward declaration.
179 template <typename T>
181
182 /// Forward declaration.
183 class DerivativeCalculatorSphericalObjectPoint3x3;
184
185 /// Forward declaration.
186 template <typename T>
188
189 /// Forward declaration.
190 template <typename T>
192
193 /// Forward declaration.
194 template <typename T>
196
197 /// Forward declaration.
198 template <typename T>
200
201 /// Forward declaration.
202 class DerivativeCalculatorPinholeCameraJacobian2x8;
203
204 /// Forward declaration.
205 class DerivativeCalculatorFisheyeCameraJacobian2x12;
206
207 /// Forward declaration.
208 template <typename T>
210
211 /// Forward declaration.
212 template <typename T>
214
215 /// Forward declaration.
216 template <typename T>
218
219 /// Forward declaration.
220 template <typename T>
222
223 /// Forward declaration.
224 class DerivativeCalculatorHomography2x8;
225
226 /// Forward declaration.
227 class DerivativeCalculatorHomography2x9;
228
229 /// Forward declaration.
230 class DerivativeCalculatorIdentityHomography2x8;
231
232 /// Forward declaration.
233 class DerivativeCalculatorIdentityHomography2x9;
234
235 /// Forward declaration.
236 class DerivativeCalculatorSimilarity2x4;
237
238 /// Forward declaration.
239 template <typename T>
241
242 public:
243
244 /**
245 * Tests the entire Jacobian functionality.
246 * @param testDuration Number of seconds for each test, with range (0, infinity)
247 * @param selector Selector for individual tests
248 * @return True, if succeeded
249 */
250 static bool test(const double testDuration, const TestSelector& selector);
251
252 /**
253 * Tests the Jacobian for the rotational part of extrinsic camera parameters.
254 * @param testDuration Number of seconds for each test, with range (0, infinity)
255 * @return True, if succeeded
256 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
257 */
258 template <typename T>
259 static bool testOrientationalJacobian2x3(const double testDuration);
260
261 /**
262 * Tests the Jacobian for the orientation of a camera.
263 * @param testDuration Number of seconds for each test, with range (0, infinity)
264 * @return True, if succeeded
265 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
266 */
267 template <typename T>
268 static bool testOrientationJacobian2nx3(const double testDuration);
269
270 /**
271 * Deprecated.
272 *
273 * Tests the Jacobian for the extrinsic camera parameters and a pinhole camera.
274 * @param testDuration Number of seconds for each test, with range (0, infinity)
275 * @return True, if succeeded
276 */
277 static bool testPinholeCameraPoseJacobian2nx6(const double testDuration);
278
279 /**
280 * Deprecated.
281 *
282 * Tests the Jacobian for the extrinsic camera parameters and fisheye camera.
283 * @param testDuration Number of seconds for each test, with range (0, infinity)
284 * @return True, if succeeded
285 */
286 static bool testFisheyeCameraPoseJacobian2x6(const double testDuration);
287
288 /**
289 * Tests the Jacobian for the extrinsic camera parameters and any camera.
290 * @param testDuration Number of seconds for each test, with range (0, infinity)
291 * @return True, if succeeded
292 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
293 */
294 template <typename T>
295 static bool testAnyCameraPoseJacobian2nx6(const double testDuration);
296
297 /**
298 * Tests the Jacobian for the extrinsic camera parameters using a damped distortion.
299 * @param testDuration Number of seconds for each test, with range (0, infinity)
300 * @return True, if succeeded
301 */
302 static bool testPoseJacobianDampedDistortion2nx6(const double testDuration);
303
304 /**
305 * Tests the Jacobian for the extrinsic camera parameters (including the zoom parameter).
306 * @param testDuration Number of seconds for each test, with range (0, infinity)
307 * @return True, if succeeded
308 */
309 static bool testPoseZoomJacobian2nx7(const double testDuration);
310
311 /**
312 * Tests the 2x6 Jacobian for a 6-DOF transformation with fixed camera pose.
313 * @param testDuration Number of seconds for each test, with range (0, infinity)
314 * @return True, if succeeded
315 */
316 static bool testPinholeCameraObjectTransformation2nx6(const double testDuration);
317
318 /**
319 * Tests the 2x6 Jacobian for a 6-DOF transformation with fixed camera pose.
320 * @param testDuration Number of seconds for each test, with range (0, infinity)
321 * @return True, if succeeded
322 */
323 static bool testFisheyeCameraObjectTransformation2nx6(const double testDuration);
324
325 /**
326 * Tests the Jacobian for an 2D image point projection in relation to an object point using a pinhole camera.
327 * @param testDuration Number of seconds for each test, with range (0, infinity)
328 * @return True, if succeeded
329 */
330 static bool testPinholeCameraPointJacobian2nx3(const double testDuration);
331
332 /**
333 * Tests the Jacobian for an 2D image point projection in relation to an object point using a fisheye camera.
334 * @param testDuration Number of seconds for each test, with range (0, infinity)
335 * @return True, if succeeded
336 */
337 static bool testFisheyeCameraPointJacobian2x3(const double testDuration);
338
339 /**
340 * Tests the Jacobian for an 2D image point projection in relation to an object point using any camera.
341 * @param testDuration Number of seconds for each test, with range (0, infinity)
342 * @return True, if succeeded
343 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
344 */
345 template <typename T>
346 static bool testAnyCameraPointJacobian2x3(const double testDuration);
347
348 /**
349 * Tests the Jacobian for two 6DOF poses and a set of 3D object points.
350 * @param testDuration Number of seconds for each test, with range (0, infinity)
351 * @return True, if succeeded
352 */
353 static bool testPosesPointsJacobian2nx12(const double testDuration);
354
355 /**
356 * Tests the Jacobian for an exponential map representing a 3D object point.
357 * @param testDuration Number of seconds for each test, with range (0, infinity)
358 * @return True, if succeeded
359 */
360 static bool testSphericalObjectPoint3x3(const double testDuration);
361
362 /**
363 * Tests the Jacobian for an exponential map representing a 3D object point which is projected into the camera frame.
364 * @param testDuration Number of seconds for each test, with range (0, infinity)
365 * @return True, if succeeded
366 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
367 */
368 template <typename T>
369 static bool testSphericalObjectPointOrientation2x3IF(const double testDuration);
370
371 /**
372 * Tests the Jacobian for the radial and tangential distortion camera parameters.
373 * @param testDuration Number of seconds for each test, with range (0, infinity)
374 * @return True, if succeeded
375 */
376 static bool testPinholeCameraDistortionJacobian2x4(const double testDuration);
377
378 /**
379 * Tests the Jacobian for the intrinsic and radial distortion of pinhole camera parameters.
380 * @param testDuration Number of seconds for each test, with range (0, infinity)
381 * @return True, if succeeded
382 */
383 static bool testPinholeCameraJacobian2x6(const double testDuration);
384
385 /**
386 * Tests the Jacobian for the intrinsic and radial and tangential distortion of pinhole camera parameters.
387 * @param testDuration Number of seconds for each test, with range (0, infinity)
388 * @return True, if succeeded
389 */
390 static bool testPinholeCameraJacobian2x7(const double testDuration);
391
392 /**
393 * Tests the Jacobian for the intrinsic, radial and tangential distortion of pinhole camera parameters.
394 * @param testDuration Number of seconds for each test, with range (0, infinity)
395 * @return True, if succeeded
396 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
397 */
398 template <typename T>
399 static bool testPinholeCameraJacobian2x8(const double testDuration);
400
401 /**
402 * Tests the Jacobian for the intrinsic, radial and tangential distortion of fisheye camera parameters.
403 * @param testDuration Number of seconds for each test, with range (0, infinity)
404 * @return True, if succeeded
405 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
406 */
407 template <typename T>
408 static bool testFisheyeCameraJacobian2x12(const double testDuration);
409
410 /**
411 * Tests the Jacobian for the rotational part of the extrinsic camera matrix, intrinsic and radial and tangential camera parameters.
412 * @param testDuration Number of seconds for each test, with range (0, infinity)
413 * @return True, if succeeded
414 */
415 static bool testOrientationPinholeCameraJacobian2x11(const double testDuration);
416
417 /**
418 * Tests the Jacobian for the extrinsic, intrinsic and radial camera parameters for a pinhole camera.
419 * @param testDuration Number of seconds for each test, with range (0, infinity)
420 * @return True, if succeeded
421 */
422 static bool testPosePinholeCameraJacobian2x12(const double testDuration);
423
424 /**
425 * Tests the Jacobian for the extrinsic, intrinsic and radial and tangential distortion camera parameters for a pinhole camera.
426 * @param testDuration Number of seconds for each test, with range (0, infinity)
427 * @return True, if succeeded
428 * @tparam T the data type of the scalar to be used, either 'float' or 'double'
429 */
430 template <typename T>
431 static bool testPosePinholeCameraJacobian2x14(const double testDuration);
432
433 /**
434 * Tests the Jacobian for the extrinsic, intrinsic and radial camera parameters and distortion parameters for a fisheye camera.
435 * @param testDuration Number of seconds for each test, with range (0, infinity)
436 * @return True, if succeeded
437 */
438 template <typename T>
439 static bool testPoseFisheyeCameraJacobian2x18(const double testDuration);
440
441 /**
442 * Tests the 2x8 Jacobian for the homography.
443 * @param testDuration Number of seconds for each test, with range (0, infinity)
444 * @return True, if succeeded
445 */
446 static bool testHomography2x8(const double testDuration);
447
448 /**
449 * Tests the 2x9 Jacobian for the homography.
450 * @param testDuration Number of seconds for each test, with range (0, infinity)
451 * @return True, if succeeded
452 */
453 static bool testHomography2x9(const double testDuration);
454
455 /**
456 * Tests the 2x8 Jacobian for the identity homography.
457 * @param testDuration Number of seconds for each test, with range (0, infinity)
458 * @return True, if succeeded
459 */
460 static bool testIdentityHomography2x8(const double testDuration);
461
462 /**
463 * Tests the 2x9 Jacobian for the identity homography.
464 * @param testDuration Number of seconds for each test, with range (0, infinity)
465 * @return True, if succeeded
466 */
467 static bool testIdentityHomography2x9(const double testDuration);
468
469 /**
470 * Tests the 2x4 Jacobian of a similarity transformation.
471 * @param testDuration Number of seconds for each test, with range (0, infinity)
472 * @return True, if succeeded
473 */
474 static bool testSimilarity2x4(const double testDuration);
475
476 /**
477 * Tests the 2x2 Jacobian of the distortion of a normalized image point for a fisheye camera.
478 * @param testDuration Number of seconds for each test, with range (0, infinity)
479 * @return True, if succeeded
480 * @tparam T the data type of the scalar to be used, 'float', or 'double'
481 */
482 template <typename T>
483 static bool testCalculateFisheyeDistortNormalized2x2(const double testDuration);
484
485 private:
486
487 /**
488 * Checks if an analytical derivative matches an approximated derivative within tolerance.
489 * @param analyticalDerivative The analytical derivative value
490 * @param approximatedDerivative The numerically approximated derivative value
491 * @return True if the derivatives match within tolerance
492 * @tparam T The data type of the derivative
493 */
494 template <typename T>
495 static bool checkDerivative(const T& analyticalDerivative, const T& approximatedDerivative);
496
497 /**
498 * Checks if an analytical derivative matches an approximated derivative within tolerance.
499 * @param analyticalDerivative The analytical derivative value
500 * @param approximatedDerivative The numerically approximated derivative value
501 * @return True if the derivatives match within tolerance
502 * @tparam T The data type of the scalar, either 'float' or 'double'
503 */
504 template <typename T>
505 static bool checkScalarDerivative(const T analyticalDerivative, const T approximatedDerivative);
506
507 /**
508 * Calculates the two Jacobian rows for a given pose and dynamic object point.
509 * The derivatives are calculated for the 3D object point only.<br>
510 * The resulting Jacobian rows have the following form:<br>
511 * | dfx / dX, dfx / dY, dfx / dZ |<br>
512 * | dfy / dX, dfy / dY, dfy / dZ |<br>
513 * @param jx First row position of the Jacobian, with 3 column entries receiving the point derivatives
514 * @param jy Second row position of the Jacobian, with 3 column entries receiving the point derivatives
515 * @param pinholeCamera The pinhole camera to determine the Jacobian values for
516 * @param flippedCamera_T_world Pose to determine the Jacobian for (inverted and flipped)
517 * @param objectPoint 3D object point to determine the Jacobian for
518 * @param distortImagePoint True, to force the distortion of the image point using the distortion parameters of this camera object
519 * @tparam tUseBorderDistortionIfOutside True, to apply the distortion from the nearest point lying on the frame border if the point lies outside the visible camera area; False to apply the distortion from the given position
520 */
521 template <bool tUseBorderDistortionIfOutside>
522 static void calculatePointJacobian2x3(Scalar* jx, Scalar* jy, const PinholeCamera& pinholeCamera, const HomogenousMatrix4& flippedCamera_T_world, const Vector3& objectPoint, const bool distortImagePoint);
523};
524
525template <>
526inline bool TestJacobian::checkDerivative(const float& analyticalDerivative, const float& approximatedDerivative)
527{
528 return checkScalarDerivative<float>(analyticalDerivative, approximatedDerivative);
529}
530
531template <>
532inline bool TestJacobian::checkDerivative(const double& analyticalDerivative, const double& approximatedDerivative)
533{
534 return checkScalarDerivative<double>(analyticalDerivative, approximatedDerivative);
535}
536
537template <>
538inline bool TestJacobian::checkDerivative(const VectorF2& analyticalDerivative, const VectorF2& approximatedDerivative)
539{
540 if (!checkScalarDerivative<float>(analyticalDerivative.x(), approximatedDerivative.x()))
541 {
542 return false;
543 }
544
545 if (!checkScalarDerivative<float>(analyticalDerivative.y(), approximatedDerivative.y()))
546 {
547 return false;
548 }
549
550 return true;
551}
552
553template <>
554inline bool TestJacobian::checkDerivative(const VectorD2& analyticalDerivative, const VectorD2& approximatedDerivative)
555{
556 if (!checkScalarDerivative<double>(analyticalDerivative.x(), approximatedDerivative.x()))
557 {
558 return false;
559 }
560
561 if (!checkScalarDerivative<double>(analyticalDerivative.y(), approximatedDerivative.y()))
562 {
563 return false;
564 }
565
566 return true;
567}
568
569template <>
570inline bool TestJacobian::checkDerivative(const VectorF3& analyticalDerivative, const VectorF3& approximatedDerivative)
571{
572 if (!checkScalarDerivative<float>(analyticalDerivative.x(), approximatedDerivative.x()))
573 {
574 return false;
575 }
576
577 if (!checkScalarDerivative<float>(analyticalDerivative.y(), approximatedDerivative.y()))
578 {
579 return false;
580 }
581
582 if (!checkScalarDerivative<float>(analyticalDerivative.z(), approximatedDerivative.z()))
583 {
584 return false;
585 }
586
587 return true;
588}
589
590template <>
591inline bool TestJacobian::checkDerivative(const VectorD3& analyticalDerivative, const VectorD3& approximatedDerivative)
592{
593 if (!checkScalarDerivative<double>(analyticalDerivative.x(), approximatedDerivative.x()))
594 {
595 return false;
596 }
597
598 if (!checkScalarDerivative<double>(analyticalDerivative.y(), approximatedDerivative.y()))
599 {
600 return false;
601 }
602
603 if (!checkScalarDerivative<double>(analyticalDerivative.z(), approximatedDerivative.z()))
604 {
605 return false;
606 }
607
608 return true;
609}
610
611template <typename T>
612inline bool TestJacobian::checkDerivative(const T& /*analyticalDerivative*/, const T& /*approximatedDerivative*/)
613{
614 OCEAN_WARNING_MISSING_IMPLEMENTATION;
615 return false;
616}
617
618template <typename T>
619bool TestJacobian::checkScalarDerivative(const T analyticalDerivative, const T approximatedDerivative)
620{
621 const double maxAbsValue = std::max(std::abs(analyticalDerivative), std::abs(approximatedDerivative));
622 const double absDiff = std::abs(analyticalDerivative - approximatedDerivative);
623
624 if (NumericT<T>::isEqualEps(analyticalDerivative) || NumericT<T>::isEqualEps(approximatedDerivative))
625 {
626 if (absDiff > T(0.001))
627 {
628 return false;
629 }
630 }
631 else
632 {
633 if (NumericT<T>::isNotEqualEps(T(maxAbsValue)) && T(absDiff / maxAbsValue) > T(0.05))
634 {
635 return false;
636 }
637 }
638
639 return true;
640}
641
642template <bool tUseBorderDistortionIfOutside>
643void TestJacobian::calculatePointJacobian2x3(Scalar* jx, Scalar* jy, const PinholeCamera& pinholeCamera, const HomogenousMatrix4& flippedCamera_T_world, const Vector3& objectPoint, const bool distortImagePoint)
644{
645 ocean_assert(jx != nullptr && jy != nullptr);
646 ocean_assert(flippedCamera_T_world.isValid());
647
648 /**
649 * | dfx / dX, dfx / dY, dfx / dZ |<br>
650 * | dfy / dX, dfy / dY, dfy / dZ |<br>
651 */
652
653 const Scalar eps = Numeric::weakEps();
654
655 const Vector2 imagePoint(pinholeCamera.projectToImageIF<tUseBorderDistortionIfOutside>(flippedCamera_T_world, objectPoint, distortImagePoint));
656
657 for (unsigned int n = 0u; n < 3u; ++n)
658 {
659 Vector3 dObjectPoint(objectPoint);
660
661 dObjectPoint[n] += eps;
662
663 const Vector2 dImagePoint(pinholeCamera.projectToImageIF<tUseBorderDistortionIfOutside>(flippedCamera_T_world, dObjectPoint, distortImagePoint));
664
665 const Scalar dx = (dImagePoint.x() - imagePoint.x()) / eps;
666 const Scalar dy = (dImagePoint.y() - imagePoint.y()) / eps;
667
668 jx[n] = dx;
669 jy[n] = dy;
670 }
671}
672
673}
674
675}
676
677}
678
679#endif // META_OCEAN_TEST_TESTGEOMETRY_TEST_JACOBIAN_H
This class implements function to calculate the jacobian matrices for geometry functions.
Definition Jacobian.h:37
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1806
This class provides basic numeric functionalities.
Definition Numeric.h:57
static constexpr T weakEps()
Returns a weak epsilon.
VectorT2< T > projectToImageIF(const HomogenousMatrixT4< T > &flippedCamera_T_world, const VectorT3< T > &objectPoint, const bool distortImagePoint, const T zoom=T(1)) const
Projects a 3D object point to the 2D image plane of the camera by a given inverse camera pose.
Definition PinholeCamera.h:2006
virtual T calculateValue(const size_t parameterIndex, const TScalar offset) const =0
Calculates the function value with an offset applied to a specific parameter.
T calculateDerivative(const size_t parameterIndex, const TScalar epsilon=NumericT< TScalar >::weakEps() *TScalar(0.05)) const
Calculates the numerical derivative using central finite differences: f'(x) ≈ [f(x + epsilon) - f(x -...
bool verifyDerivative(const size_t parameterIndex, const TAnalyticalDerivative &analyticalDerivative) const
Verifies an analytical derivative by comparing it with a numerical approximation.
Base class for calculating numerical derivatives using central finite differences.
Definition TestJacobian.h:45
T calculateDerivative(const TVariable &variable, const size_t parameterIndex, const TScalar epsilon=NumericT< TScalar >::weakEps() *TScalar(0.05)) const
Calculates the numerical derivative using central finite differences: f'(x) ≈ [f(x + epsilon) - f(x -...
bool verifyDerivative(const TVariable &variable, const size_t parameterIndex, const TAnalyticalDerivative &analyticalDerivative) const
Verifies an analytical derivative by comparing it with a numerical approximation.
virtual ~DerivativeCalculatorT()=default
Default constructor.
virtual T calculateValue(const TVariable &variable, const size_t parameterIndex, const TScalar offset) const =0
Calculates the function value with an offset applied to a specific parameter.
This class implements Jacobian tests.
Definition TestJacobian.h:34
static bool testAnyCameraPointJacobian2x3(const double testDuration)
Tests the Jacobian for an 2D image point projection in relation to an object point using any camera.
static bool testIdentityHomography2x8(const double testDuration)
Tests the 2x8 Jacobian for the identity homography.
static bool testOrientationPinholeCameraJacobian2x11(const double testDuration)
Tests the Jacobian for the rotational part of the extrinsic camera matrix, intrinsic and radial and t...
static bool testSphericalObjectPointOrientation2x3IF(const double testDuration)
Tests the Jacobian for an exponential map representing a 3D object point which is projected into the ...
static bool testPinholeCameraObjectTransformation2nx6(const double testDuration)
Tests the 2x6 Jacobian for a 6-DOF transformation with fixed camera pose.
static void calculatePointJacobian2x3(Scalar *jx, Scalar *jy, const PinholeCamera &pinholeCamera, const HomogenousMatrix4 &flippedCamera_T_world, const Vector3 &objectPoint, const bool distortImagePoint)
Calculates the two Jacobian rows for a given pose and dynamic object point.
Definition TestJacobian.h:643
static bool testPosePinholeCameraJacobian2x14(const double testDuration)
Tests the Jacobian for the extrinsic, intrinsic and radial and tangential distortion camera parameter...
static bool testPosesPointsJacobian2nx12(const double testDuration)
Tests the Jacobian for two 6DOF poses and a set of 3D object points.
static bool testAnyCameraPoseJacobian2nx6(const double testDuration)
Tests the Jacobian for the extrinsic camera parameters and any camera.
static bool testFisheyeCameraPointJacobian2x3(const double testDuration)
Tests the Jacobian for an 2D image point projection in relation to an object point using a fisheye ca...
static bool testCalculateFisheyeDistortNormalized2x2(const double testDuration)
Tests the 2x2 Jacobian of the distortion of a normalized image point for a fisheye camera.
static bool testHomography2x9(const double testDuration)
Tests the 2x9 Jacobian for the homography.
static bool checkDerivative(const T &analyticalDerivative, const T &approximatedDerivative)
Checks if an analytical derivative matches an approximated derivative within tolerance.
Definition TestJacobian.h:612
static bool testPoseZoomJacobian2nx7(const double testDuration)
Tests the Jacobian for the extrinsic camera parameters (including the zoom parameter).
static bool testSphericalObjectPoint3x3(const double testDuration)
Tests the Jacobian for an exponential map representing a 3D object point.
static bool testHomography2x8(const double testDuration)
Tests the 2x8 Jacobian for the homography.
static bool testSimilarity2x4(const double testDuration)
Tests the 2x4 Jacobian of a similarity transformation.
static bool testPoseFisheyeCameraJacobian2x18(const double testDuration)
Tests the Jacobian for the extrinsic, intrinsic and radial camera parameters and distortion parameter...
static bool testPinholeCameraDistortionJacobian2x4(const double testDuration)
Tests the Jacobian for the radial and tangential distortion camera parameters.
static bool testFisheyeCameraJacobian2x12(const double testDuration)
Tests the Jacobian for the intrinsic, radial and tangential distortion of fisheye camera parameters.
static bool checkScalarDerivative(const T analyticalDerivative, const T approximatedDerivative)
Checks if an analytical derivative matches an approximated derivative within tolerance.
Definition TestJacobian.h:619
static bool testPinholeCameraJacobian2x7(const double testDuration)
Tests the Jacobian for the intrinsic and radial and tangential distortion of pinhole camera parameter...
static bool test(const double testDuration, const TestSelector &selector)
Tests the entire Jacobian functionality.
static bool testPosePinholeCameraJacobian2x12(const double testDuration)
Tests the Jacobian for the extrinsic, intrinsic and radial camera parameters for a pinhole camera.
static bool testFisheyeCameraObjectTransformation2nx6(const double testDuration)
Tests the 2x6 Jacobian for a 6-DOF transformation with fixed camera pose.
static bool testOrientationJacobian2nx3(const double testDuration)
Tests the Jacobian for the orientation of a camera.
static bool testPinholeCameraJacobian2x6(const double testDuration)
Tests the Jacobian for the intrinsic and radial distortion of pinhole camera parameters.
static bool testPinholeCameraJacobian2x8(const double testDuration)
Tests the Jacobian for the intrinsic, radial and tangential distortion of pinhole camera parameters.
static bool testPinholeCameraPointJacobian2nx3(const double testDuration)
Tests the Jacobian for an 2D image point projection in relation to an object point using a pinhole ca...
static bool testIdentityHomography2x9(const double testDuration)
Tests the 2x9 Jacobian for the identity homography.
static bool testFisheyeCameraPoseJacobian2x6(const double testDuration)
Deprecated.
static bool testOrientationalJacobian2x3(const double testDuration)
Tests the Jacobian for the rotational part of extrinsic camera parameters.
static bool testPinholeCameraPoseJacobian2nx6(const double testDuration)
Deprecated.
static bool testPoseJacobianDampedDistortion2nx6(const double testDuration)
Tests the Jacobian for the extrinsic camera parameters using a damped distortion.
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
This class implements a vector with two elements.
Definition Vector2.h:96
const T & x() const noexcept
Returns the x value.
Definition Vector2.h:710
const T & y() const noexcept
Returns the y value.
Definition Vector2.h:722
const T & y() const noexcept
Returns the y value.
Definition Vector3.h:824
const T & x() const noexcept
Returns the x value.
Definition Vector3.h:812
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:836
float Scalar
Definition of a scalar type.
Definition Math.h:129
The namespace covering the entire Ocean framework.
Definition Accessor.h:15