g2o
edge_se2_segment2d_line.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_LINE_H
28 #define G2O_EDGE_SE2_SEGMENT2D_LINE_H
29 
30 #include "g2o/config.h"
32 #include "vertex_segment2d.h"
35 
36 namespace g2o {
37 
38  class EdgeSE2Segment2DLine : public BaseBinaryEdge<2, Vector2D, 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 double theta() const {return _measurement[0];}
45  G2O_TYPES_SLAM2D_ADDONS_API double rho() const {return _measurement[1];}
46 
49 
50 
52  {
53  const VertexSE2* v1 = static_cast<const VertexSE2*>(_vertices[0]);
54  const VertexSegment2D* l2 = static_cast<const VertexSegment2D*>(_vertices[1]);
55  SE2 iEst=v1->estimate().inverse();
56  Vector2D predP1 = iEst * l2->estimateP1();
57  Vector2D predP2 = iEst * l2->estimateP2();
58  Vector2D dP = predP2 - predP1;
59  Vector2D normal(dP.y(), -dP.x()); normal.normalize();
60  Vector2D prediction(atan2(normal.y(), normal.x()),
61  predP1.dot(normal)*.5 + predP2.dot(normal)*.5);
62 
63  _error=prediction-_measurement;
65  }
66 
67  G2O_TYPES_SLAM2D_ADDONS_API virtual bool setMeasurementData(const double* d){
68  Eigen::Map<const Vector2D> data(d);
69  _measurement = data;
70  return true;
71  }
72 
73  G2O_TYPES_SLAM2D_ADDONS_API virtual bool getMeasurementData(double* d) const{
74  Eigen::Map<Vector2D> data(d);
75  data = _measurement;
76  return true;
77  }
78 
79  G2O_TYPES_SLAM2D_ADDONS_API virtual int measurementDimension() const {return 2;}
80 
82  const VertexSE2* v1 = static_cast<const VertexSE2*>(_vertices[0]);
83  const VertexSegment2D* l2 = static_cast<const VertexSegment2D*>(_vertices[1]);
84  SE2 iEst=v1->estimate().inverse();
85  Vector2D predP1 = iEst * l2->estimateP1();
86  Vector2D predP2 = iEst * l2->estimateP2();
87  Vector2D dP = predP2 - predP1;
88  Vector2D normal(dP.y(), -dP.x()); normal.normalize();
89  Vector2D prediction(atan2(normal.y(), normal.x()),
90  predP1.dot(normal)*.5 + predP2.dot(normal)*.5);
91  _measurement = prediction;
92  return true;
93  }
94 
95  G2O_TYPES_SLAM2D_ADDONS_API virtual bool read(std::istream& is);
96  G2O_TYPES_SLAM2D_ADDONS_API virtual bool write(std::ostream& os) const;
97 
98 
99 /* #ifndef NUMERIC_JACOBIAN_TWO_D_TYPES */
100 /* virtual void linearizeOplus(); */
101 /* #endif */
102  };
103 
104 /* class G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2DLineWriteGnuplotAction: public WriteGnuplotAction { */
105 /* public: */
106 /* EdgeSE2Segment2DLineWriteGnuplotAction(); */
107 /* virtual HyperGraphElementAction* operator()(HyperGraph::HyperGraphElement* element, */
108 /* HyperGraphElementAction::Parameters* params_); */
109 /* }; */
110 
111 /* #ifdef G2O_HAVE_OPENGL */
112 /* class G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2DLineDrawAction: public DrawAction{ */
113 /* public: */
114 /* EdgeSE2Segment2DLineDrawAction(); */
115 /* virtual HyperGraphElementAction* operator()(HyperGraph::HyperGraphElement* element, */
116 /* HyperGraphElementAction::Parameters* params_); */
117 /* }; */
118 /* #endif */
119 
120 } // end namespace
121 
122 #endif
G2O_TYPES_SLAM2D_ADDONS_API double theta() const
virtual G2O_TYPES_SLAM2D_ADDONS_API bool getMeasurementData(double *d) const
Eigen::Matrix< double, 2, 1, Eigen::ColMajor > Vector2D
Definition: eigen_types.h:45
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 bool setMeasurementData(const double *d)
represent SE2
Definition: se2.h:40
G2O_TYPES_SLAM2D_ADDONS_API double rho() const
G2O_TYPES_SLAM2D_ADDONS_API void setTheta(double t)
2D pose Vertex, (x,y,theta)
Definition: vertex_se2.h:41
G2O_TYPES_SLAM2D_ADDONS_API void computeError()
virtual G2O_TYPES_SLAM2D_ADDONS_API int measurementDimension() const
G2O_TYPES_SLAM2D_ADDONS_API EIGEN_MAKE_ALIGNED_OPERATOR_NEW G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2DLine()
double normalize_theta(double theta)
Definition: misc.h:94
#define G2O_TYPES_SLAM2D_ADDONS_API
Vector2D estimateP1() const
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
Vector2D estimateP2() const
SE2 inverse() const
invert :-)
Definition: se2.h:82
G2O_TYPES_SLAM2D_ADDONS_API void setRho(double r)
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
VertexContainer _vertices
Definition: hyper_graph.h:202