edge_plane_identity.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // g2o - General Graph Optimization
  2. // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
  3. // All rights reserved.
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright notice,
  10. // this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above copyright
  12. // notice, this list of conditions and the following disclaimer in the
  13. // documentation and/or other materials provided with the distribution.
  14. //
  15. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  16. // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  17. // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  18. // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19. // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  21. // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22. // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. #ifndef EDGE_PLANE_IDENTITY_HPP
  27. #define EDGE_PLANE_IDENTITY_HPP
  28. #include <Eigen/Dense>
  29. #include <g2o/core/base_binary_edge.h>
  30. #include <g2o/types/slam3d_addons/vertex_plane.h>
  31. namespace g2o {
  32. /**
  33. * @brief A modified version of g2o::EdgePlane. This class takes care of flipped plane normals.
  34. *
  35. */
  36. class EdgePlaneIdentity : public BaseBinaryEdge<4, Eigen::Vector4d, VertexPlane, VertexPlane> {
  37. public:
  38. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  39. EdgePlaneIdentity() : BaseBinaryEdge<4, Eigen::Vector4d, VertexPlane, VertexPlane>() {
  40. _information.setIdentity();
  41. _error.setZero();
  42. }
  43. void computeError() {
  44. const VertexPlane* v1 = static_cast<const VertexPlane*>(_vertices[0]);
  45. const VertexPlane* v2 = static_cast<const VertexPlane*>(_vertices[1]);
  46. Eigen::Vector4d p1 = v1->estimate().toVector();
  47. Eigen::Vector4d p2 = v2->estimate().toVector();
  48. if(p1.dot(p2) < 0.0) {
  49. p2 = -p2;
  50. }
  51. _error = (p2 - p1) - _measurement;
  52. }
  53. virtual bool read(std::istream& is) override {
  54. Eigen::Vector4d v;
  55. for(int i = 0; i < 4; ++i) {
  56. is >> v[i];
  57. }
  58. setMeasurement(v);
  59. for(int i = 0; i < information().rows(); ++i) {
  60. for(int j = i; j < information().cols(); ++j) {
  61. is >> information()(i, j);
  62. if(i != j) {
  63. information()(j, i) = information()(i, j);
  64. }
  65. }
  66. }
  67. return true;
  68. }
  69. virtual bool write(std::ostream& os) const override {
  70. for(int i = 0; i < 4; ++i) {
  71. os << _measurement[i] << " ";
  72. }
  73. for(int i = 0; i < information().rows(); ++i) {
  74. for(int j = i; j < information().cols(); ++j) {
  75. os << " " << information()(i, j);
  76. };
  77. }
  78. return os.good();
  79. }
  80. virtual void setMeasurement(const Eigen::Vector4d& m) override {
  81. _measurement = m;
  82. }
  83. virtual int measurementDimension() const override {
  84. return 4;
  85. }
  86. };
  87. } // namespace g2o
  88. #endif // EDGE_PLANE_PARALLEL_HPP