g2o
Loading...
Searching...
No Matches
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"
34#include "vertex_segment2d.h"
35
36namespace g2o {
37
39 : public BaseBinaryEdge<2, Vector2, VertexSE2,
40 VertexSegment2D> // Avoid redefinition of BaseEdge
41 // in MSVC
42{
43 public:
44 G2O_TYPES_SLAM2D_ADDONS_API EIGEN_MAKE_ALIGNED_OPERATOR_NEW
47
48 G2O_TYPES_SLAM2D_ADDONS_API double theta() const { return _measurement[0]; }
49 G2O_TYPES_SLAM2D_ADDONS_API double rho() const { return _measurement[1]; }
50
53
55 const VertexSE2* v1 = static_cast<const VertexSE2*>(_vertices[0]);
56 const VertexSegment2D* l2 =
57 static_cast<const VertexSegment2D*>(_vertices[1]);
58 SE2 iEst = v1->estimate().inverse();
59 Vector2 predP1 = iEst * l2->estimateP1();
60 Vector2 predP2 = iEst * l2->estimateP2();
61 Vector2 dP = predP2 - predP1;
62 Vector2 normal(dP.y(), -dP.x());
63 normal.normalize();
64 Vector2 prediction(std::atan2(normal.y(), normal.x()),
65 predP1.dot(normal) * .5 + predP2.dot(normal) * .5);
66
67 _error = prediction - _measurement;
69 }
70
71 G2O_TYPES_SLAM2D_ADDONS_API virtual bool setMeasurementData(const double* d) {
72 Eigen::Map<const Vector2> data(d);
73 _measurement = data;
74 return true;
75 }
76
77 G2O_TYPES_SLAM2D_ADDONS_API virtual bool getMeasurementData(double* d) const {
78 Eigen::Map<Vector2> data(d);
79 data = _measurement;
80 return true;
81 }
82
84 return 2;
85 }
86
88 const VertexSE2* v1 = static_cast<const VertexSE2*>(_vertices[0]);
89 const VertexSegment2D* l2 =
90 static_cast<const VertexSegment2D*>(_vertices[1]);
91 SE2 iEst = v1->estimate().inverse();
92 Vector2 predP1 = iEst * l2->estimateP1();
93 Vector2 predP2 = iEst * l2->estimateP2();
94 Vector2 dP = predP2 - predP1;
95 Vector2 normal(dP.y(), -dP.x());
96 normal.normalize();
97 Vector2 prediction(std::atan2(normal.y(), normal.x()),
98 predP1.dot(normal) * .5 + predP2.dot(normal) * .5);
99 _measurement = prediction;
100 return true;
101 }
102
103 G2O_TYPES_SLAM2D_ADDONS_API virtual bool read(std::istream& is);
104 G2O_TYPES_SLAM2D_ADDONS_API virtual bool write(std::ostream& os) const;
105
106 /* #ifndef NUMERIC_JACOBIAN_TWO_D_TYPES */
107 /* virtual void linearizeOplus(); */
108 /* #endif */
109};
110
111/* class G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2DLineWriteGnuplotAction:
112 * public WriteGnuplotAction { */
113/* public: */
114/* EdgeSE2Segment2DLineWriteGnuplotAction(); */
115/* virtual HyperGraphElementAction*
116 * operator()(HyperGraph::HyperGraphElement* element, */
117/* HyperGraphElementAction::Parameters* params_); */
118/* }; */
119
120/* #ifdef G2O_HAVE_OPENGL */
121/* class G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2DLineDrawAction: public
122 * DrawAction{ */
123/* public: */
124/* EdgeSE2Segment2DLineDrawAction(); */
125/* virtual HyperGraphElementAction*
126 * operator()(HyperGraph::HyperGraphElement* element, */
127/* HyperGraphElementAction::Parameters* params_); */
128/* }; */
129/* #endif */
130
131} // namespace g2o
132
133#endif
Measurement _measurement
the measurement of the edge
Definition base_edge.h:146
ErrorVector _error
Definition base_edge.h:149
const EstimateType & estimate() const
return the current estimate of the vertex
G2O_TYPES_SLAM2D_ADDONS_API EIGEN_MAKE_ALIGNED_OPERATOR_NEW G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2DLine()
G2O_TYPES_SLAM2D_ADDONS_API void setTheta(double t)
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
virtual G2O_TYPES_SLAM2D_ADDONS_API bool setMeasurementFromState()
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 getMeasurementData(double *d) const
G2O_TYPES_SLAM2D_ADDONS_API double theta() const
G2O_TYPES_SLAM2D_ADDONS_API void setRho(double r)
virtual G2O_TYPES_SLAM2D_ADDONS_API bool setMeasurementData(const double *d)
virtual G2O_TYPES_SLAM2D_ADDONS_API int measurementDimension() const
G2O_TYPES_SLAM2D_ADDONS_API double rho() const
G2O_TYPES_SLAM2D_ADDONS_API void computeError()
VertexContainer _vertices
represent SE2
Definition se2.h:43
SE2 inverse() const
invert :-)
Definition se2.h:83
2D pose Vertex, (x,y,theta)
Definition vertex_se2.h:41
Vector2 estimateP1() const
Vector2 estimateP2() const
#define G2O_TYPES_SLAM2D_ADDONS_API
double normalize_theta(double theta)
Definition misc.h:103
VectorN< 2 > Vector2
Definition eigen_types.h:50