g2o
Loading...
Searching...
No Matches
edge_se2_pointxy_bearing.cpp
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
28
29#include <cassert>
30
31#ifdef G2O_HAVE_OPENGL
34#endif
35
36namespace g2o {
37
39
42 assert(from.size() == 1 && from.count(_vertices[0]) == 1 &&
43 "Can not initialize VertexSE2 position by VertexPointXY");
44
45 if (from.count(_vertices[0]) != 1) return;
46 double r = 2.;
47 const VertexSE2* v1 = static_cast<const VertexSE2*>(_vertices[0]);
48 VertexPointXY* l2 = static_cast<VertexPointXY*>(_vertices[1]);
49 SE2 t = v1->estimate();
51 Vector2 vr(r, 0.);
52 l2->setEstimate(t * vr);
53}
54
55bool EdgeSE2PointXYBearing::read(std::istream& is) {
56 is >> _measurement >> information()(0, 0);
57 return true;
58}
59
60bool EdgeSE2PointXYBearing::write(std::ostream& os) const {
61 os << measurement() << " " << information()(0, 0);
62 return os.good();
63}
64
68
72 if (typeid(*element).name() != _typeName) return nullptr;
74 static_cast<WriteGnuplotAction::Parameters*>(params_);
75 if (!params->os) {
76 return nullptr;
77 }
78
79 EdgeSE2PointXYBearing* e = static_cast<EdgeSE2PointXYBearing*>(element);
80 VertexSE2* fromEdge = static_cast<VertexSE2*>(e->vertex(0));
81 VertexPointXY* toEdge = static_cast<VertexPointXY*>(e->vertex(1));
82 *(params->os) << fromEdge->estimate().translation().x() << " "
83 << fromEdge->estimate().translation().y() << " "
84 << fromEdge->estimate().rotation().angle() << std::endl;
85 *(params->os) << toEdge->estimate().x() << " " << toEdge->estimate().y()
86 << std::endl;
87 *(params->os) << std::endl;
88 return this;
89}
90
91#ifdef G2O_HAVE_OPENGL
92EdgeSE2PointXYBearingDrawAction::EdgeSE2PointXYBearingDrawAction()
93 : DrawAction(typeid(EdgeSE2PointXYBearing).name()) {}
94
95HyperGraphElementAction* EdgeSE2PointXYBearingDrawAction::operator()(
96 HyperGraph::HyperGraphElement* element,
97 HyperGraphElementAction::Parameters* params_) {
98 if (typeid(*element).name() != _typeName) return nullptr;
99
100 refreshPropertyPtrs(params_);
101 if (!_previousParams) return this;
102
103 if (_show && !_show->value()) return this;
104
105 EdgeSE2PointXYBearing* e = static_cast<EdgeSE2PointXYBearing*>(element);
106 VertexSE2* from = static_cast<VertexSE2*>(e->vertex(0));
107 VertexPointXY* to = static_cast<VertexPointXY*>(e->vertex(1));
108 if (!from) return this;
109 double guessRange = 5;
110 double theta = e->measurement();
111 Vector2 p(std::cos(theta) * guessRange, std::sin(theta) * guessRange);
112 glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING | GL_COLOR);
113 glDisable(GL_LIGHTING);
114 if (!to) {
115 p = from->estimate() * p;
116 glColor3f(LANDMARK_EDGE_GHOST_COLOR);
117 glPushAttrib(GL_POINT_SIZE);
118 glPointSize(3);
119 glBegin(GL_POINTS);
120 glVertex3f((float)p.x(), (float)p.y(), 0.f);
121 glEnd();
122 glPopAttrib();
123 } else {
124 p = to->estimate();
125 glColor3f(LANDMARK_EDGE_COLOR);
126 }
127 glBegin(GL_LINES);
128 glVertex3f((float)from->estimate().translation().x(),
129 (float)from->estimate().translation().y(), 0.f);
130 glVertex3f((float)p.x(), (float)p.y(), 0.f);
131 glEnd();
132 glPopAttrib();
133 return this;
134}
135#endif
136
137} // namespace g2o
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition base_edge.h:119
EIGEN_STRONG_INLINE const InformationType & information() const
information matrix of the constraint
Definition base_edge.h:107
Measurement _measurement
the measurement of the edge
Definition base_edge.h:146
const EstimateType & estimate() const
return the current estimate of the vertex
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
virtual HyperGraphElementAction * operator()(HyperGraph::HyperGraphElement *element, HyperGraphElementAction::Parameters *params_)
virtual bool write(std::ostream &os) const
write the vertex to a stream
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EdgeSE2PointXYBearing()
virtual void initialEstimate(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
Abstract action that operates on a graph entity.
VertexContainer _vertices
const Vertex * vertex(size_t i) const
std::set< Vertex * > VertexSet
A general case Vertex for optimization.
represent SE2
Definition se2.h:43
const Vector2 & translation() const
translational component
Definition se2.h:57
void setRotation(const Rotation2D &R_)
Definition se2.h:62
const Rotation2D & rotation() const
rotational component
Definition se2.h:61
2D pose Vertex, (x,y,theta)
Definition vertex_se2.h:41
Eigen::Rotation2D< double > Rotation2D
Definition eigen_types.h:80
VectorN< 2 > Vector2
Definition eigen_types.h:50
#define LANDMARK_EDGE_GHOST_COLOR
#define LANDMARK_EDGE_COLOR