edge_se3_priorxy.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_SE3_PRIORXY_HPP
  27. #define EDGE_SE3_PRIORXY_HPP
  28. #include <g2o/types/slam3d/types_slam3d.h>
  29. #include <g2o/types/slam3d_addons/types_slam3d_addons.h>
  30. namespace g2o {
  31. class EdgeSE3PriorXY : public g2o::BaseUnaryEdge<2, Eigen::Vector2d, g2o::VertexSE3> {
  32. public:
  33. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  34. EdgeSE3PriorXY() : g2o::BaseUnaryEdge<2, Eigen::Vector2d, g2o::VertexSE3>() {}
  35. void computeError() override {
  36. const g2o::VertexSE3* v1 = static_cast<const g2o::VertexSE3*>(_vertices[0]);
  37. Eigen::Vector2d estimate = v1->estimate().translation().head<2>();
  38. _error = estimate - _measurement;
  39. }
  40. void setMeasurement(const Eigen::Vector2d& m) override {
  41. _measurement = m;
  42. }
  43. virtual bool read(std::istream& is) override {
  44. Eigen::Vector2d v;
  45. is >> v(0) >> v(1);
  46. setMeasurement(v);
  47. for(int i = 0; i < information().rows(); ++i)
  48. for(int j = i; j < information().cols(); ++j) {
  49. is >> information()(i, j);
  50. if(i != j) information()(j, i) = information()(i, j);
  51. }
  52. return true;
  53. }
  54. virtual bool write(std::ostream& os) const override {
  55. Eigen::Vector2d v = _measurement;
  56. os << v(0) << " " << v(1) << " ";
  57. for(int i = 0; i < information().rows(); ++i)
  58. for(int j = i; j < information().cols(); ++j) os << " " << information()(i, j);
  59. return os.good();
  60. }
  61. };
  62. } // namespace g2o
  63. #endif // EDGE_SE3_PRIORXY_HPP