g2o
Loading...
Searching...
No Matches
edge_se2_segment2d_pointLine.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_POINTLINE_H
28#define G2O_EDGE_SE2_SEGMENT2D_POINTLINE_H
29
30#include "g2o/config.h"
34#include "vertex_segment2d.h"
35
36namespace g2o {
37
39 : public BaseBinaryEdge<3, Vector3, VertexSE2, VertexSegment2D> {
40 public:
41 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
43
44 double theta() const { return _measurement[2]; }
45 Vector2 point() const {
46 Eigen::Map<const Vector2> p(&_measurement[0]);
47 return p;
48 }
49
50 void setTheta(double t) { _measurement[2] = t; }
51 void setPoint(const Vector2& p_) {
52 Eigen::Map<Vector2> p(&_measurement[0]);
53 p = p_;
54 }
55
56 int pointNum() const { return _pointNum; }
57 void setPointNum(int pn) { _pointNum = pn; }
58
59 void computeError() {
60 const VertexSE2* v1 = static_cast<const VertexSE2*>(_vertices[0]);
61 const VertexSegment2D* l2 =
62 static_cast<const VertexSegment2D*>(_vertices[1]);
63 SE2 iEst = v1->estimate().inverse();
64 Vector2 predP1 = iEst * l2->estimateP1();
65 Vector2 predP2 = iEst * l2->estimateP2();
66 Vector2 dP = predP2 - predP1;
67 Vector2 normal(dP.y(), -dP.x());
68 normal.normalize();
69 Vector3 prediction;
70 prediction[2] = std::atan2(normal.y(), normal.x());
71 Eigen::Map<Vector2> pt(&prediction[0]);
72 pt = (_pointNum == 0) ? predP1 : predP2;
73 _error = prediction - _measurement;
74 _error[2] = normalize_theta(_error[2]);
75 }
76
77 virtual bool setMeasurementData(const double* d) {
78 Eigen::Map<const Vector3> data(d);
79 _measurement = data;
80 return true;
81 }
82
83 virtual bool getMeasurementData(double* d) const {
84 Eigen::Map<Vector3> data(d);
85 data = _measurement;
86 return true;
87 }
88
89 virtual int measurementDimension() const { return 3; }
90
91 virtual bool setMeasurementFromState() {
92 const VertexSE2* v1 = static_cast<const VertexSE2*>(_vertices[0]);
93 const VertexSegment2D* l2 =
94 static_cast<const VertexSegment2D*>(_vertices[1]);
95 SE2 iEst = v1->estimate().inverse();
96 Vector2 predP1 = iEst * l2->estimateP1();
97 Vector2 predP2 = iEst * l2->estimateP2();
98 Vector2 dP = predP2 - predP1;
99 Vector2 normal(dP.y(), -dP.x());
100 normal.normalize();
101 Vector3 prediction;
102 prediction[2] = std::atan2(normal.y(), normal.x());
103 Eigen::Map<Vector2> pt(&prediction[0]);
104 pt = (_pointNum == 0) ? predP1 : predP2;
105 setMeasurement(prediction);
106 return true;
107 }
108
109 virtual bool read(std::istream& is);
110 virtual bool write(std::ostream& os) const;
111
112 protected:
114
115 /* #ifndef NUMERIC_JACOBIAN_TWO_D_TYPES */
116 /* virtual void linearizeOplus(); */
117 /* #endif */
118};
119
120/* class G2O_TYPES_SLAM2D_ADDONS_API
121 * EdgeSE2Segment2DPointLineWriteGnuplotAction: public WriteGnuplotAction { */
122/* public: */
123/* EdgeSE2Segment2DPointLineWriteGnuplotAction(); */
124/* virtual HyperGraphElementAction*
125 * operator()(HyperGraph::HyperGraphElement* element, */
126/* HyperGraphElementAction::Parameters* params_); */
127/* }; */
128
129/* #ifdef G2O_HAVE_OPENGL */
130/* class G2O_TYPES_SLAM2D_ADDONS_API EdgeSE2Segment2DPointLineDrawAction:
131 * public DrawAction{ */
132/* public: */
133/* EdgeSE2Segment2DPointLineDrawAction(); */
134/* virtual HyperGraphElementAction*
135 * operator()(HyperGraph::HyperGraphElement* element, */
136/* HyperGraphElementAction::Parameters* params_); */
137/* }; */
138/* #endif */
139
140} // namespace g2o
141
142#endif
const EstimateType & estimate() const
return the current estimate of the vertex
virtual bool getMeasurementData(double *d) const
virtual bool setMeasurementData(const double *d)
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
VectorN< 3 > Vector3
Definition eigen_types.h:51
double normalize_theta(double theta)
Definition misc.h:103
VectorN< 2 > Vector2
Definition eigen_types.h:50