g2o
edge_se2_segment2d.h
Go to the documentation of this file.
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 
27 #ifndef G2O_EDGE_SE2_SEGMENT2D_H
28 #define G2O_EDGE_SE2_SEGMENT2D_H
29 
30 #include "g2o/config.h"
32 #include "vertex_segment2d.h"
35 
36 namespace g2o {
37 
38  class EdgeSE2Segment2D : public BaseBinaryEdge<4, Vector4D, VertexSE2, VertexSegment2D> //Avoid redefinition of BaseEdge in MSVC
39  {
40  public:
41  G2O_TYPES_SLAM2D_ADDONS_API EIGEN_MAKE_ALIGNED_OPERATOR_NEW
43 
44  G2O_TYPES_SLAM2D_ADDONS_API Vector2D measurementP1(){ return Eigen::Map<const Vector2D>(&(_measurement[0])); }
45  G2O_TYPES_SLAM2D_ADDONS_API Vector2D measurementP2(){ return Eigen::Map<const Vector2D>(&(_measurement[2])); }
46  G2O_TYPES_SLAM2D_ADDONS_API void setMeasurementP1(const Vector2D& p1){ Eigen::Map<Vector2D> v(&_measurement[0]); v=p1; }
47  G2O_TYPES_SLAM2D_ADDONS_API void setMeasurementP2(const Vector2D& p2){ Eigen::Map<Vector2D> v(&_measurement[2]); v=p2; }
48 
50  {
51  const VertexSE2* v1 = static_cast<const VertexSE2*>(_vertices[0]);
52  const VertexSegment2D* l2 = static_cast<const VertexSegment2D*>(_vertices[1]);
53  Eigen::Map<Vector2D> error1(&_error(0));
54  Eigen::Map<Vector2D> error2(&_error(2));
55  SE2 iEst=v1->estimate().inverse();
56  error1 = (iEst * l2->estimateP1());
57  error2 = (iEst * l2->estimateP2());
59  }
60 
61  G2O_TYPES_SLAM2D_ADDONS_API virtual bool setMeasurementData(const double* d){
62  Eigen::Map<const Vector4D> data(d);
63  _measurement = data;
64  return true;
65  }
66 
67  G2O_TYPES_SLAM2D_ADDONS_API virtual bool getMeasurementData(double* d) const{
68  Eigen::Map<Vector4D> data(d);
69  data = _measurement;
70  return true;
71  }
72 
73  G2O_TYPES_SLAM2D_ADDONS_API virtual int measurementDimension() const {return 4;}
74 
76  const VertexSE2* v1 = static_cast<const VertexSE2*>(_vertices[0]);
77  const VertexSegment2D* l2 = static_cast<const VertexSegment2D*>(_vertices[1]);
78  SE2 iEst=v1->estimate().inverse();
79  setMeasurementP1(iEst*l2->estimateP1());
80  setMeasurementP2(iEst*l2->estimateP2());
81  return true;
82  }
83 
84  G2O_TYPES_SLAM2D_ADDONS_API virtual bool read(std::istream& is);
85  G2O_TYPES_SLAM2D_ADDONS_API virtual bool write(std::ostream& os) const;
86 
88  G2O_TYPES_SLAM2D_ADDONS_API virtual double initialEstimatePossible(const OptimizableGraph::VertexSet& from, OptimizableGraph::Vertex* to) { (void) to; return (from.count(_vertices[0]) == 1 ? 1.0 : -1.0);}
89 /* #ifndef NUMERIC_JACOBIAN_TWO_D_TYPES */
90 /* virtual void linearizeOplus(); */
91 /* #endif */
92  };
93 
94 /* class G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2DWriteGnuplotAction: public WriteGnuplotAction { */
95 /* public: */
96 /* EdgeSE2Segment2DWriteGnuplotAction(); */
97 /* virtual HyperGraphElementAction* operator()(HyperGraph::HyperGraphElement* element, */
98 /* HyperGraphElementAction::Parameters* params_); */
99 /* }; */
100 
101 /* #ifdef G2O_HAVE_OPENGL */
102 /* class G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2DDrawAction: public DrawAction{ */
103 /* public: */
104 /* EdgeSE2Segment2DDrawAction(); */
105 /* virtual HyperGraphElementAction* operator()(HyperGraph::HyperGraphElement* element, */
106 /* HyperGraphElementAction::Parameters* params_); */
107 /* }; */
108 /* #endif */
109 
110 } // end namespace
111 
112 #endif
Eigen::Matrix< double, 2, 1, Eigen::ColMajor > Vector2D
Definition: eigen_types.h:45
G2O_TYPES_SLAM2D_ADDONS_API EIGEN_MAKE_ALIGNED_OPERATOR_NEW G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2D()
G2O_TYPES_SLAM2D_ADDONS_API void computeError()
virtual G2O_TYPES_SLAM2D_ADDONS_API bool setMeasurementData(const double *d)
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
represent SE2
Definition: se2.h:40
2D pose Vertex, (x,y,theta)
Definition: vertex_se2.h:41
G2O_TYPES_SLAM2D_ADDONS_API void setMeasurementP1(const Vector2D &p1)
virtual G2O_TYPES_SLAM2D_ADDONS_API bool write(std::ostream &os) const
write the vertex to a stream
virtual G2O_TYPES_SLAM2D_ADDONS_API bool setMeasurementFromState()
virtual G2O_TYPES_SLAM2D_ADDONS_API double initialEstimatePossible(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
virtual G2O_TYPES_SLAM2D_ADDONS_API int measurementDimension() const
G2O_TYPES_SLAM2D_ADDONS_API Vector2D measurementP1()
A general case Vertex for optimization.
#define G2O_TYPES_SLAM2D_ADDONS_API
Vector2D estimateP1() const
G2O_TYPES_SLAM2D_ADDONS_API Vector2D measurementP2()
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
virtual G2O_TYPES_SLAM2D_ADDONS_API bool getMeasurementData(double *d) const
Vector2D estimateP2() const
SE2 inverse() const
invert :-)
Definition: se2.h:82
virtual G2O_TYPES_SLAM2D_ADDONS_API bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
G2O_TYPES_SLAM2D_ADDONS_API void setMeasurementP2(const Vector2D &p2)
virtual G2O_TYPES_SLAM2D_ADDONS_API void initialEstimate(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
VertexContainer _vertices
Definition: hyper_graph.h:202