Commit Graph

44 Commits

Author SHA1 Message Date
Sergiu Deitsch 93e66f0d94 Fixed discrepancy in QuaternionRotatePoint for different orders
Fixes #1178

Change-Id: I0430ffb384ea53a863ba72f076043f0f772db4e1
2025-08-17 10:52:12 +02:00
Sergiu Deitsch 8c50a34a1c Reuse rotation functionality in (Eigen)QuaternionManifold
Allow to specify the memory layout of quaternion coefficients using a
template parameter which defaults to Ceres coefficients order.

The changes are, for the most part, backwards compatible unless the
floating-point type is explicitly specified, e.g., as
&ceres::QuaternionToAngleAxis<double> to obtain a pointer to the
corresponding function. In such rare use cases, the coefficients order
must be given explicitly first as
ceres::QuaternionToAngleAxis<ceres::CeresQuaternionOrder>. In normal
situations, however, this should not be needed.

Change-Id: I05dd80f0593672dec656cc785cf06fe5268aee74
2025-06-19 18:15:51 +02:00
Sergiu Deitsch 4148d6a353 Allow AngleAxisRotatePoint to be applied in-place
Thanks to @CatInTheRain for the suggestion.

Fixes #1163

Change-Id: I4e148c62891979e1ec01b91f95d3e2d04501c8ef
2025-06-10 23:14:28 +02:00
Sergiu Deitsch 83133357dd Partially revert hypot arguments zero checks
Unfortunately, libc++'s 3-argument std::hypot implementation is
numerically unstable until LLVM 19.x. Therefore, checking the arguments
for zeros is insufficient since an underflow can still occur resulting
in a zero norm which requires another check. As such, division by zero
cannot be reliably avoided.

Change-Id: I189c8dc722aaec1ebc3ec8b1a177e1d8ac3b36db
2025-05-20 21:31:10 +02:00
Sergiu Deitsch c15da00398 Avoid division by zero
Run cleanly under -fsanitize=float-divide-by-zero.

Change-Id: I99e92a50c60971c9f771774e58dbe65be7c675ec
2025-05-18 10:02:39 -07:00
Sameer Agarwal 0a53aa9054 Take abseil as a dependency
1. Add abseil-cpp as a submodule. We are tracking the latest LTS
release, which is lts_2024_01_16.
2. Replace glog/gflags with absl::log and absl::flags.
3. Remove miniglog
4. Also take a whack at making the bazel build work with
   abseil-cpp and gtest.

There are a number of TODOs in this CL that still need to be resolved.

Change-Id: I39355ed7d61375be4ebcbc8596d9cc70acc1c678
2024-07-18 00:24:49 -07:00
Sergiu Deitsch 4519b8d774 Drop use of POSIX M_PI
Change-Id: I37342a366161bb13d6456ecc67569fe12705e05c
2023-10-04 22:59:15 +02:00
Hs293Go 96fdfd2e7a Implement tests for Euler conversion with jets
https://github.com/ceres-solver/ceres-solver/issues/965

Change-Id: I6bdabf5ee09c000e49ea1757fde724d4bc4ccb92
2023-04-27 16:42:25 -04:00
Sameer Agarwal db1ebd3ff5 Work around lack of constexpr constructors for Jet
https://github.com/ceres-solver/ceres-solver/issues/965

Change-Id: Ia74a64568815605586c1f326a55cc36b09f33f30
2023-04-18 16:26:24 -07:00
Sameer Agarwal 16a4fa04e2 Further Jet conversion fixes
https://github.com/ceres-solver/ceres-solver/issues/965

Change-Id: Ib80467eda4120b0483814e9e01e9644dd7ee91a7
2023-04-18 14:58:22 -07:00
Sameer Agarwal 92ad18b8ae Fix a Jet conversion bug in rotation.h
https: //github.com/ceres-solver/ceres-solver/issues/965
Change-Id: I4c99639be6afbfbefea3f9d56b6eaddbe4f23fe9
2023-04-18 09:18:01 -07:00
Sameer Agarwal 79a554ffcf Fix a bug in QuaternionRotatePoint.
In https://ceres-solver-review.git.corp.google.com/c/ceres-solver/+/23802

the computation of the norm of a quaternion

scale = 1/sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]);

was replaced by

scale = 1/hypot(q[0], q[1], hypot(q[2], q[3]));

while this appear to be a more accurate computation because of the
use of hypot which can handle over and underflow it introduces a
bug for the case where q[2] = q[3] = 0.

While the hypot(q[2], q[3]) == 0 as scalars, if q[2] and q[3] are
jets, then the derivative will be NaN. Which means that even though
q[0] or q[1] is non-zero and the norm of the quaternion is non-zero,
and the resulting derivative is finite, this way of computing the
scale will produce nans in the derivative of scale.

The following quaternion will replicate the problem described above.

using Jet = ceres::Jet<double, 4>;
std::array<Jet, 4> quaternion = {Jet(1.0, 0), Jet(0.0, 1), Jet(0.0, 2), Jet(0.0, 3)};

This CL reverts the change to QuaternionRotatePoint and
adds a test for it.

Thanks to Jonathan Taylor for reproducing this bug.

Change-Id: I0fbbcc77d6945a38563d82efba4429f4b5278cd5
2023-01-13 11:37:27 -08:00
Sergiu Deitsch cb6b306623 Use hypot to compute the L^2 norm
Change-Id: I908eaaa279452aa16346dfd3f25aac53685e3172
2023-01-05 21:44:53 +01:00
hs293go 2b89ce66f0 Add generalized Euler Angle conversions
Conversions function include Euler Angles to / from Rotation Matrices
and Quaternions. They are generalized for any Euler convention that can
be specified in the arguments. Algorithm is from "Euler angle
conversion", Ken Shoemake, Graphics Gems IV

Change-Id: I7f9ddc0b8d686efca16299d2ba374295744376ce
2022-09-20 22:14:19 +00:00
Evan Levine f1414cb5bd Correct spelling in comments and docs.
Change-Id: Iad9a0599d644d3b3cd54244edaf64d408cb1308e
2022-04-24 21:40:13 -07:00
Sameer Agarwal 4dff3ea2c4 Fix a number of typos in rotation.h
Thanks to @yiping for reporting these.
https://github.com/ceres-solver/ceres-solver/issues/672

Change-Id: I9c59d2b666430edf33f10aaba0d0ee4cd520e0a4
2021-09-13 17:19:49 -07:00
Mykyta Kozlov 66b4c33e81 updated unit quaternion rotation
Change-Id: I3e5a2ca8e19c1d66437ac16d615867e2a12f8e60
2020-11-18 17:00:13 +00:00
Alex Stewart 5cb5b35a93 Fixed incorrect argument name in RotationMatrixToQuaternion()
- Raised as: https://github.com/ceres-solver/ceres-solver/pull/607 by
  Frank Dellaert

Change-Id: Id3e9f190e814cf18206e2f8c3b1b67b995c21dd5
2020-07-26 20:42:12 +01:00
Darius Rueckert e751d6e4f0 Remove AutodiffCodegen
- Remove Codegen files
- Revert Jet and Rotation

Change-Id: I005c5f98f2b6dfa5c7fd88d998b6aa83e47dab60
2020-04-08 10:43:53 +02:00
Darius Rueckert edd54b83e1 Update Jet.h and rotation.h to use the new IF/ELSE macros
Also use branchless implementation for isfinite(Jet),
isinf(Jet), isnan(Jet), and isnormal(Jet).

Change-Id: Ia881df03ba873e0560d67e976ab1e99e199eb523
2019-12-09 18:30:30 +01:00
Sameer Agarwal 4362a21699 Run clang-format on the public headers.
Also update copyright year.

Change-Id: I8508d4fd4564c646ec2281a1b3b2c36136b54b46
2019-12-03 14:50:37 -08:00
Sameer Agarwal d7f428e5c7 Add a missing cast in rotation.h
Thanks to Lukas Post (@deutschepost) for reporting this.

https://github.com/ceres-solver/ceres-solver/issues/497

Change-Id: I6d9d0ca5feab3a1f4cf47613537e8cd7ab1ba479
2019-08-07 06:42:28 -07:00
Sameer Agarwal 57441fe909 Fix two bugs.
1. ProblemEvaluateResidualTest was leaking the loss_function in cases
where it was not being used.
2. Fix a grammo in rotation.h

Change-Id: If94ae1624033c8f6d1934dc2f40fa0dfe4e025c3
2019-04-29 10:59:09 -07:00
Johannes Beck c0aa9a2631 Add checks in rotation.h for inplace operations.
Some rotation functions like UnitQuaternionRotatePoint,
QuaternionRotatePoint, etc. will calculate bad results if the input
point and output point points to the same memory (inplace operation).

This CL adds checks in debug mode to guard against it.

Change-Id: Id0a30e9a0286b340757f0790d417d9f9a3409810
2019-04-16 21:45:36 +02:00
Kuang Fangjun 0d3a84fce5 Fix typos in doc and errors in the demo code.
Change-Id: I237402958ed8747ae438643132fcab90113ac27d
2018-09-22 12:01:20 +08:00
Rob Carroll e69bd2a206 Add missing T() wrappers for constants.
Needed for instantiation with Jet<float,N>.

Change-Id: I8ec07a844cc911a3c7f24c25797bd21c0bee07b5
2016-10-31 12:51:44 -07:00
Sameer Agarwal 8590e6e8e0 Remove two checks from rotation.h
This allows rotation.h to remove its dependency on glog.

Change-Id: Ia6aede93ee51a4bd4039570dc8edd100a7045329
2016-10-27 12:36:13 -07:00
Keir Mierle 7492b0d8de Update copyright headers with new year and URL
Since Ceres is moving to using GitHub for issues, and the Google
Code URL in the current copyright header will soon become invalid,
update all the headers.

Change-Id: I1fce70375d1bcf098591f07b4d8f01a5c1e0789c
2015-03-18 05:43:23 +00:00
Sameer Agarwal bcc865f81c Remove using namespace std;
For historical reasons we had a "using namespace std;" in port.h. This
is generally a bad idea. So removing it and along the way doing a bunch
of cpplint cleanup.

Change-Id: Ia125601a55ae62695e247fb0250df4c6f86c46c6
2015-01-07 14:26:53 -08:00
Sameer Agarwal c9be6a6f3e More lint cleanup.
Change-Id: I74f586ac357df055e944f359463562197db79f1d
2014-11-13 23:19:05 -08:00
Sameer Agarwal 730aa537cd Add RotationMatrixToQuaternion.
Use this function to implement RotationMatrixToAngleAxis.
This simplifies the implementation of RotationMatrixToAngleAxis,
just like Eigen does. It is also autodiff compatible, unlike the
Eigen based version.

Also significantly improve the test coverage of
RotationMatrixToAngleAxis.

Change-Id: Ic192a12fb5de952197ee24b0deedc45f195477f1
2014-11-14 06:57:30 +00:00
Sameer Agarwal cd358c760f Fix RotationMatrixToAngleAxis near Pi.
Use Eigen's much more complicated conversion routine
when we encounter cases where the angle of rotation is
close to Pi.

Along the way also fix the way angle_axis vectors are
compared by making the matcher more robust.

Thanks to Tobias Strauss for reporting this.

Change-Id: Ia7e65dafad92c48d29d5f3cd22c4d6534789c183
2014-11-12 22:56:38 -08:00
Sameer Agarwal c6bafdd02c Comments from Jim Roseborough.
1. Fix the tolerance on the rotation matrix conversion test.
2. Fix some out of date comments.

Change-Id: I65e80da1f96d7b4d9ac0630ad8cb708c41739840
2013-10-28 19:38:08 -07:00
Sameer Agarwal 21d6a99fe6 Fix AngleAxisToRotationMatrix near zero.
The Taylor series approximation had its sign flipped and the
tests did not catch it since we were switching exactly at zero,
which was not getting triggered.

This changes modifies the tolerance, adds a test that triggers
and fixes the bug.

Thanks to Michael Samples for reporting this.

Change-Id: I6f92f6348e5d4421ffe194fba92c04285449484c
2013-10-25 13:53:52 -07:00
Sameer Agarwal 39a427c736 Speed up AngleAxisRotatePoint.
This leads to a ~11% speedup on my mac using clang.

Based on suggestions by Thad Hughes.

Change-Id: If8495c8de6e28f63fb065e35bd6f382dd9fcbbea
2013-10-23 11:45:57 -07:00
Sameer Agarwal 58b8c68f29 Clean up rotation.h
Change-Id: I3370c9883728cda068c9650a2c2a50641fd8299c
2013-03-09 17:17:43 -08:00
Sameer Agarwal 509f68cfe3 Problem::Evaluate implementation.
1. Add Problem::Evaluate and tests.
2. Remove Solver::Summary::initial/final_*
3. Remove Solver::Options::return_* members.
4. Various cpplint cleanups.

Change-Id: I4266de53489896f72d9c6798c5efde6748d68a47
2013-02-24 19:04:21 +00:00
Sameer Agarwal beb4505311 Minor fixes
Based on William Rucklidge's review, including
a nasty bug in parameter block removal.

Change-Id: I3a692e589f600ff560ecae9fa85bb0b76063d403
2013-02-22 13:37:05 -08:00
Keir Mierle 3e2c4ef9ad Add adapters for column/row-major matrices to rotation.h
This patch introduces a matrix wrapper (MatrixAdapter) that allows to
transparently pass pointers to row-major or column-major matrices
to the conversion functions.

Change-Id: I7f1683a8722088cffcc542f593ce7eb46fca109b
2013-02-19 08:40:09 +00:00
Sameer Agarwal 383c04f423 Fix QuaternionToAngleAxis to ensure rotations are between -pi and pi.
Thanks to Guoxuan Zhang for reporting this.

Change-Id: I2831ca3a04d5dc6467849c290461adbe23faaea3
2012-08-17 14:32:23 -07:00
Sameer Agarwal 0beab86dfa Fix glog includes and include sorting order.
Change-Id: I0ec85218e82d1714279d41f7635104d480fb91c3
2012-08-13 15:47:24 -07:00
Sameer Agarwal 104ad902b6 Fixed Jet to integer comparison.
Thanks to Keith Leung for reporting this.

Change-Id: I97c2eb87a5cf6779779e659aaa716dc507824def
2012-07-17 11:30:31 -07:00
Keir Mierle efe7ac60a0 Port Ceres to Windows
This is a preliminary, but full, port of Ceres to Windows.
Currently all tests compile and run, with only system_test
failing to work correctly due to a path issue.

Change-Id: I4152c1588bf51ffd7f4d9401ef9759f5d28c299c
2012-06-24 23:22:04 -07:00
Keir Mierle 8ebb073038 Initial commit of Ceres Solver. 2012-04-30 23:09:08 -07:00