2014-01-30 02:02:51 +08:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
* Atlanta, Georgia 30332-0415
|
|
|
|
|
* All Rights Reserved
|
|
|
|
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
|
|
|
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
|
|
|
|
|
|
|
|
|
* See LICENSE for the license information
|
|
|
|
|
|
|
|
|
|
* -------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @file OrientedPlane3.cpp
|
|
|
|
|
* @date Dec 19, 2013
|
|
|
|
|
* @author Alex Trevor
|
|
|
|
|
* @brief A plane, represented by a normal direction and perpendicular distance
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <gtsam/geometry/OrientedPlane3.h>
|
|
|
|
|
#include <gtsam/geometry/Point2.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
namespace gtsam {
|
|
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
|
|
|
|
/// The print fuction
|
|
|
|
|
void OrientedPlane3::print(const std::string& s) const {
|
2015-02-12 23:31:04 +08:00
|
|
|
Vector coeffs = planeCoefficients();
|
2014-01-30 02:02:51 +08:00
|
|
|
cout << s << " : " << coeffs << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2015-02-12 23:31:04 +08:00
|
|
|
OrientedPlane3 OrientedPlane3::Transform(const gtsam::OrientedPlane3& plane,
|
|
|
|
|
const gtsam::Pose3& xr, OptionalJacobian<3, 6> Hr,
|
|
|
|
|
OptionalJacobian<3, 3> Hp) {
|
2015-02-12 21:22:25 +08:00
|
|
|
Matrix n_hr;
|
|
|
|
|
Matrix n_hp;
|
2015-02-12 23:31:04 +08:00
|
|
|
Unit3 n_rotated = xr.rotation().unrotate(plane.n_, n_hr, n_hp);
|
|
|
|
|
|
|
|
|
|
Vector n_unit = plane.n_.unitVector();
|
|
|
|
|
Vector unit_vec = n_rotated.unitVector();
|
|
|
|
|
double pred_d = n_unit.dot(xr.translation().vector()) + plane.d_;
|
|
|
|
|
OrientedPlane3 transformed_plane(unit_vec(0), unit_vec(1), unit_vec(2),
|
|
|
|
|
pred_d);
|
|
|
|
|
|
|
|
|
|
if (Hr) {
|
|
|
|
|
*Hr = gtsam::zeros(3, 6);
|
|
|
|
|
(*Hr).block<2, 3>(0, 0) = n_hr;
|
|
|
|
|
(*Hr).block<1, 3>(2, 3) = unit_vec;
|
2014-01-30 02:02:51 +08:00
|
|
|
}
|
2015-02-12 23:31:04 +08:00
|
|
|
if (Hp) {
|
|
|
|
|
Vector xrp = xr.translation().vector();
|
2015-02-12 21:22:25 +08:00
|
|
|
Matrix n_basis = plane.n_.basis();
|
|
|
|
|
Vector hpp = n_basis.transpose() * xrp;
|
2015-02-12 23:31:04 +08:00
|
|
|
*Hp = gtsam::zeros(3, 3);
|
|
|
|
|
(*Hp).block<2, 2>(0, 0) = n_hp;
|
|
|
|
|
(*Hp).block<1, 2>(2, 0) = hpp;
|
|
|
|
|
(*Hp)(2, 2) = 1;
|
2014-01-30 02:02:51 +08:00
|
|
|
}
|
2015-02-12 23:31:04 +08:00
|
|
|
|
2015-02-12 21:22:25 +08:00
|
|
|
return (transformed_plane);
|
|
|
|
|
}
|
2015-02-12 23:31:04 +08:00
|
|
|
|
2015-02-12 21:22:25 +08:00
|
|
|
/* ************************************************************************* */
|
2015-02-12 23:31:04 +08:00
|
|
|
Vector3 OrientedPlane3::error(const gtsam::OrientedPlane3& plane) const {
|
|
|
|
|
Vector2 n_error = -n_.localCoordinates(plane.n_);
|
2015-02-12 21:22:25 +08:00
|
|
|
double d_error = d_ - plane.d_;
|
|
|
|
|
Vector3 e;
|
2015-02-12 23:31:04 +08:00
|
|
|
e << n_error(0), n_error(1), d_error;
|
2015-02-12 21:22:25 +08:00
|
|
|
return (e);
|
|
|
|
|
}
|
2014-01-30 02:02:51 +08:00
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2015-05-14 13:26:24 +08:00
|
|
|
OrientedPlane3 OrientedPlane3::retract(const Vector3& v) const {
|
2015-02-12 03:46:02 +08:00
|
|
|
// Retract the Unit3
|
2015-02-12 23:31:04 +08:00
|
|
|
Vector2 n_v(v(0), v(1));
|
|
|
|
|
Unit3 n_retracted = n_.retract(n_v);
|
|
|
|
|
double d_retracted = d_ + v(2);
|
|
|
|
|
return OrientedPlane3(n_retracted, d_retracted);
|
2014-01-30 02:02:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2015-02-12 03:46:02 +08:00
|
|
|
Vector3 OrientedPlane3::localCoordinates(const OrientedPlane3& y) const {
|
2015-05-14 13:26:24 +08:00
|
|
|
Vector2 n_local = n_.localCoordinates(y.n_);
|
2014-01-30 02:02:51 +08:00
|
|
|
double d_local = d_ - y.d_;
|
2015-02-12 03:46:02 +08:00
|
|
|
Vector3 e;
|
2015-02-12 23:31:04 +08:00
|
|
|
e << n_local(0), n_local(1), -d_local;
|
2015-02-12 03:46:02 +08:00
|
|
|
return e;
|
2014-01-30 02:02:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|