|
| 1 | +#ifndef EDGE_PLANE_PARALLEL_HPP |
| 2 | +#define EDGE_PLANE_PARALLEL_HPP |
| 3 | + |
| 4 | +#include <Eigen/Dense> |
| 5 | +#include <g2o/core/base_binary_edge.h> |
| 6 | +#include <g2o/types/slam3d_addons/vertex_plane.h> |
| 7 | + |
| 8 | +namespace g2o { |
| 9 | + |
| 10 | +class EdgePlaneParallel : public BaseBinaryEdge<3, Eigen::Vector3d, VertexPlane, VertexPlane> { |
| 11 | +public: |
| 12 | + EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
| 13 | + EdgePlaneParallel() : BaseBinaryEdge<3, Eigen::Vector3d, VertexPlane, VertexPlane>() { |
| 14 | + _information.setIdentity(); |
| 15 | + _error.setZero(); |
| 16 | + } |
| 17 | + |
| 18 | + void computeError() override { |
| 19 | + const VertexPlane* v1 = static_cast<const VertexPlane*>(_vertices[0]); |
| 20 | + const VertexPlane* v2 = static_cast<const VertexPlane*>(_vertices[1]); |
| 21 | + |
| 22 | + Eigen::Vector3d normal1 = v1->estimate().normal(); |
| 23 | + Eigen::Vector3d normal2 = v2->estimate().normal(); |
| 24 | + |
| 25 | + if (normal1.dot(normal2) < 0.0) { |
| 26 | + normal2 = -normal2; |
| 27 | + } |
| 28 | + |
| 29 | + _error = (normal2 - normal1) - _measurement; |
| 30 | + } |
| 31 | + virtual bool read(std::istream& is) override { |
| 32 | + Eigen::Vector3d v; |
| 33 | + for (int i = 0; i < 3; ++i) { |
| 34 | + is >> v[i]; |
| 35 | + } |
| 36 | + |
| 37 | + setMeasurement(v); |
| 38 | + for (int i = 0; i < 3; ++i) { |
| 39 | + for (int j = i; j < 3; ++j) { |
| 40 | + is >> information()(i, j); |
| 41 | + if (i != j) { |
| 42 | + information()(j, i) = information()(i, j); |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + return true; |
| 48 | + } |
| 49 | + |
| 50 | + virtual bool write(std::ostream& os) const override { |
| 51 | + for (int i = 0; i < 3; ++i) os << _measurement[i] << " "; |
| 52 | + for (int i = 0; i < 3; ++i) |
| 53 | + for (int j = i; j < 3; ++j) os << " " << information()(i, j); |
| 54 | + return os.good(); |
| 55 | + } |
| 56 | + |
| 57 | + virtual void setMeasurement(const Eigen::Vector3d& m) override { _measurement = m; } |
| 58 | + |
| 59 | + virtual int measurementDimension() const override { return 3; } |
| 60 | +}; |
| 61 | + |
| 62 | +class EdgePlanePerpendicular : public BaseBinaryEdge<3, Eigen::Vector3d, VertexPlane, VertexPlane> { |
| 63 | +public: |
| 64 | + EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
| 65 | + EdgePlanePerpendicular() : BaseBinaryEdge<3, Eigen::Vector3d, VertexPlane, VertexPlane>() { |
| 66 | + _information.setIdentity(); |
| 67 | + _error.setZero(); |
| 68 | + } |
| 69 | + |
| 70 | + void computeError() override { |
| 71 | + const VertexPlane* v1 = static_cast<const VertexPlane*>(_vertices[0]); |
| 72 | + const VertexPlane* v2 = static_cast<const VertexPlane*>(_vertices[1]); |
| 73 | + |
| 74 | + Eigen::Vector3d normal1 = v1->estimate().normal().normalized(); |
| 75 | + Eigen::Vector3d normal2 = v2->estimate().normal().normalized(); |
| 76 | + |
| 77 | + _error = normal1.array() * normal2.array(); |
| 78 | + } |
| 79 | + virtual bool read(std::istream& is) override { |
| 80 | + Eigen::Vector3d v; |
| 81 | + for (int i = 0; i < 3; ++i) { |
| 82 | + is >> v[i]; |
| 83 | + } |
| 84 | + |
| 85 | + setMeasurement(v); |
| 86 | + for (int i = 0; i < 3; ++i) { |
| 87 | + for (int j = i; j < 3; ++j) { |
| 88 | + is >> information()(i, j); |
| 89 | + if (i != j) { |
| 90 | + information()(j, i) = information()(i, j); |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + return true; |
| 96 | + } |
| 97 | + |
| 98 | + virtual bool write(std::ostream& os) const override { |
| 99 | + for (int i = 0; i < 3; ++i) os << _measurement[i] << " "; |
| 100 | + for (int i = 0; i < 3; ++i) |
| 101 | + for (int j = i; j < 3; ++j) os << " " << information()(i, j); |
| 102 | + return os.good(); |
| 103 | + } |
| 104 | + |
| 105 | + virtual void setMeasurement(const Eigen::Vector3d& m) override { _measurement = m; } |
| 106 | + |
| 107 | + virtual int measurementDimension() const override { return 3; } |
| 108 | +}; |
| 109 | + |
| 110 | +} // namespace g2o |
| 111 | + |
| 112 | +#endif // EDGE_PLANE_PARALLEL_HPP |
0 commit comments