g2o
Loading...
Searching...
No Matches
edge_se2_pointxy.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
27#include "edge_se2_pointxy.h"
28
29#include <cassert>
30
31#ifdef G2O_HAVE_OPENGL
34#endif
35
36namespace g2o {
37
40
41bool EdgeSE2PointXY::read(std::istream& is) {
44 return true;
45}
46
47bool EdgeSE2PointXY::write(std::ostream& os) const {
49 return writeInformationMatrix(os);
50}
51
54 assert(from.size() == 1 && from.count(_vertices[0]) == 1 &&
55 "Can not initialize VertexSE2 position by VertexPointXY");
56
57 VertexSE2* vi = static_cast<VertexSE2*>(_vertices[0]);
58 VertexPointXY* vj = static_cast<VertexPointXY*>(_vertices[1]);
59 if (from.count(vi) > 0 && to == vj) {
61 }
62}
63
64#ifndef NUMERIC_JACOBIAN_TWO_D_TYPES
66 const VertexSE2* vi = static_cast<const VertexSE2*>(_vertices[0]);
67 const VertexPointXY* vj = static_cast<const VertexPointXY*>(_vertices[1]);
68 const double& x1 = vi->estimate().translation()[0];
69 const double& y1 = vi->estimate().translation()[1];
70 const double& th1 = vi->estimate().rotation().angle();
71 const double& x2 = vj->estimate()[0];
72 const double& y2 = vj->estimate()[1];
73
74 double aux_1 = std::cos(th1);
75 double aux_2 = -aux_1;
76 double aux_3 = std::sin(th1);
77
78 _jacobianOplusXi(0, 0) = aux_2;
79 _jacobianOplusXi(0, 1) = -aux_3;
80 _jacobianOplusXi(0, 2) = aux_1 * y2 - aux_1 * y1 - aux_3 * x2 + aux_3 * x1;
81 _jacobianOplusXi(1, 0) = aux_3;
82 _jacobianOplusXi(1, 1) = aux_2;
83 _jacobianOplusXi(1, 2) = -aux_3 * y2 + aux_3 * y1 - aux_1 * x2 + aux_1 * x1;
84
85 _jacobianOplusXj(0, 0) = aux_1;
86 _jacobianOplusXj(0, 1) = aux_3;
87 _jacobianOplusXj(1, 0) = -aux_3;
88 _jacobianOplusXj(1, 1) = aux_1;
89}
90#endif
91
94
98 if (typeid(*element).name() != _typeName) return nullptr;
100 static_cast<WriteGnuplotAction::Parameters*>(params_);
101 if (!params->os) {
102 return nullptr;
103 }
104
105 EdgeSE2PointXY* e = static_cast<EdgeSE2PointXY*>(element);
106 if (e->numUndefinedVertices()) return this;
107 VertexSE2* fromEdge = static_cast<VertexSE2*>(e->vertex(0));
108 VertexPointXY* toEdge = static_cast<VertexPointXY*>(e->vertex(1));
109 *(params->os) << fromEdge->estimate().translation().x() << " "
110 << fromEdge->estimate().translation().y() << " "
111 << fromEdge->estimate().rotation().angle() << std::endl;
112 *(params->os) << toEdge->estimate().x() << " " << toEdge->estimate().y()
113 << std::endl;
114 *(params->os) << std::endl;
115 return this;
116}
117
118#ifdef G2O_HAVE_OPENGL
119EdgeSE2PointXYDrawAction::EdgeSE2PointXYDrawAction()
120 : DrawAction(typeid(EdgeSE2PointXY).name()) {}
121
122HyperGraphElementAction* EdgeSE2PointXYDrawAction::operator()(
123 HyperGraph::HyperGraphElement* element,
124 HyperGraphElementAction::Parameters* params_) {
125 if (typeid(*element).name() != _typeName) return nullptr;
126
127 refreshPropertyPtrs(params_);
128 if (!_previousParams) return this;
129
130 if (_show && !_show->value()) return this;
131
132 EdgeSE2PointXY* e = static_cast<EdgeSE2PointXY*>(element);
133 VertexSE2* fromEdge = static_cast<VertexSE2*>(e->vertex(0));
134 VertexPointXY* toEdge = static_cast<VertexPointXY*>(e->vertex(1));
135 if (!fromEdge) return this;
136 Vector2 p = e->measurement();
137 glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING | GL_COLOR);
138 glDisable(GL_LIGHTING);
139 if (!toEdge) {
140 p = fromEdge->estimate() * p;
141 glColor3f(LANDMARK_EDGE_GHOST_COLOR);
142 glPushAttrib(GL_POINT_SIZE);
143 glPointSize(3);
144 glBegin(GL_POINTS);
145 glVertex3f((float)p.x(), (float)p.y(), 0.f);
146 glEnd();
147 glPopAttrib();
148 } else {
149 p = toEdge->estimate();
150 glColor3f(LANDMARK_EDGE_COLOR);
151 }
152 glBegin(GL_LINES);
153 glVertex3f((float)fromEdge->estimate().translation().x(),
154 (float)fromEdge->estimate().translation().y(), 0.f);
155 glVertex3f((float)p.x(), (float)p.y(), 0.f);
156 glEnd();
157 glPopAttrib();
158 return this;
159}
160#endif
161
162} // namespace g2o
BaseFixedSizedEdge< D, Vector2, VertexSE2, VertexPointXY >::template JacobianType< D, VertexXj::Dimension > & _jacobianOplusXj
BaseFixedSizedEdge< D, Vector2, VertexSE2, VertexPointXY >::template JacobianType< D, VertexXi::Dimension > & _jacobianOplusXi
bool writeInformationMatrix(std::ostream &os) const
write the upper trinagular part of the information matrix into the stream
Definition base_edge.h:165
bool readInformationMatrix(std::istream &is)
Definition base_edge.h:173
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition base_edge.h:119
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 EdgeSE2PointXY()
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
virtual void linearizeOplus()
Abstract action that operates on a graph entity.
int numUndefinedVertices() const
VertexContainer _vertices
const Vertex * vertex(size_t i) const
std::set< Vertex * > VertexSet
A general case Vertex for optimization.
const Vector2 & translation() const
translational component
Definition se2.h:57
const Rotation2D & rotation() const
rotational component
Definition se2.h:61
2D pose Vertex, (x,y,theta)
Definition vertex_se2.h:41
bool writeVector(std::ostream &os, const Eigen::DenseBase< Derived > &b)
Definition io_helper.h:36
bool readVector(std::istream &is, Eigen::DenseBase< Derived > &b)
Definition io_helper.h:42
VectorN< 2 > Vector2
Definition eigen_types.h:50
#define LANDMARK_EDGE_GHOST_COLOR
#define LANDMARK_EDGE_COLOR