g2o
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 #ifdef G2O_HAVE_OPENGL
32 #endif
33 
34 namespace g2o {
35 
38  {
39  }
40 
41  bool EdgeSE2PointXY::read(std::istream& is)
42  {
43  is >> _measurement[0] >> _measurement[1];
44  is >> information()(0,0) >> information()(0,1) >> information()(1,1);
45  information()(1,0) = information()(0,1);
46  return true;
47  }
48 
49  bool EdgeSE2PointXY::write(std::ostream& os) const
50  {
51  os << measurement()[0] << " " << measurement()[1] << " ";
52  os << information()(0,0) << " " << information()(0,1) << " " << information()(1,1);
53  return os.good();
54  }
55 
57  {
58  assert(from.size() == 1 && from.count(_vertices[0]) == 1 && "Can not initialize VertexSE2 position by VertexPointXY");
59 
60  VertexSE2* vi = static_cast<VertexSE2*>(_vertices[0]);
61  VertexPointXY* vj = static_cast<VertexPointXY*>(_vertices[1]);
62  if (from.count(vi) > 0 && to == vj) {
63  vj->setEstimate(vi->estimate() * _measurement);
64  }
65  }
66 
67 #ifndef NUMERIC_JACOBIAN_TWO_D_TYPES
69  {
70  const VertexSE2* vi = static_cast<const VertexSE2*>(_vertices[0]);
71  const VertexPointXY* vj = static_cast<const VertexPointXY*>(_vertices[1]);
72  const double& x1 = vi->estimate().translation()[0];
73  const double& y1 = vi->estimate().translation()[1];
74  const double& th1 = vi->estimate().rotation().angle();
75  const double& x2 = vj->estimate()[0];
76  const double& y2 = vj->estimate()[1];
77 
78  double aux_1 = cos(th1) ;
79  double aux_2 = -aux_1 ;
80  double aux_3 = sin(th1) ;
81 
82  _jacobianOplusXi( 0 , 0 ) = aux_2 ;
83  _jacobianOplusXi( 0 , 1 ) = -aux_3 ;
84  _jacobianOplusXi( 0 , 2 ) = aux_1*y2-aux_1*y1-aux_3*x2+aux_3*x1 ;
85  _jacobianOplusXi( 1 , 0 ) = aux_3 ;
86  _jacobianOplusXi( 1 , 1 ) = aux_2 ;
87  _jacobianOplusXi( 1 , 2 ) = -aux_3*y2+aux_3*y1-aux_1*x2+aux_1*x1 ;
88 
89  _jacobianOplusXj( 0 , 0 ) = aux_1 ;
90  _jacobianOplusXj( 0 , 1 ) = aux_3 ;
91  _jacobianOplusXj( 1 , 0 ) = -aux_3 ;
92  _jacobianOplusXj( 1 , 1 ) = aux_1 ;
93  }
94 #endif
95 
97 
99  if (typeid(*element).name()!=_typeName)
100  return 0;
101  WriteGnuplotAction::Parameters* params=static_cast<WriteGnuplotAction::Parameters*>(params_);
102  if (!params->os){
103  std::cerr << __PRETTY_FUNCTION__ << ": warning, on valid os specified" << std::endl;
104  return 0;
105  }
106 
107  EdgeSE2PointXY* e = static_cast<EdgeSE2PointXY*>(element);
108  if (e->numUndefinedVertices())
109  return this;
110  VertexSE2* fromEdge = static_cast<VertexSE2*>(e->vertex(0));
111  VertexPointXY* toEdge = static_cast<VertexPointXY*>(e->vertex(1));
112  *(params->os) << fromEdge->estimate().translation().x() << " " << fromEdge->estimate().translation().y()
113  << " " << fromEdge->estimate().rotation().angle() << std::endl;
114  *(params->os) << toEdge->estimate().x() << " " << toEdge->estimate().y() << std::endl;
115  *(params->os) << std::endl;
116  return this;
117  }
118 
119 #ifdef G2O_HAVE_OPENGL
120  EdgeSE2PointXYDrawAction::EdgeSE2PointXYDrawAction(): DrawAction(typeid(EdgeSE2PointXY).name()){}
121 
122  HyperGraphElementAction* EdgeSE2PointXYDrawAction::operator()(HyperGraph::HyperGraphElement* element,
124  if (typeid(*element).name()!=_typeName)
125  return 0;
126 
127  refreshPropertyPtrs(params_);
128  if (! _previousParams)
129  return this;
130 
131  if (_show && !_show->value())
132  return this;
133 
134 
135  EdgeSE2PointXY* e = static_cast<EdgeSE2PointXY*>(element);
136  VertexSE2* fromEdge = static_cast<VertexSE2*>(e->vertex(0));
137  VertexPointXY* toEdge = static_cast<VertexPointXY*>(e->vertex(1));
138  if (! fromEdge)
139  return this;
140  Vector2D p=e->measurement();
141  glPushAttrib(GL_ENABLE_BIT|GL_LIGHTING|GL_COLOR);
142  glDisable(GL_LIGHTING);
143  if (!toEdge){
144  p=fromEdge->estimate()*p;
145  glColor3f(LANDMARK_EDGE_GHOST_COLOR);
146  glPushAttrib(GL_POINT_SIZE);
147  glPointSize(3);
148  glBegin(GL_POINTS);
149  glVertex3f((float)p.x(),(float)p.y(),0.f);
150  glEnd();
151  glPopAttrib();
152  } else {
153  p=toEdge->estimate();
154  glColor3f(LANDMARK_EDGE_COLOR);
155  }
156  glBegin(GL_LINES);
157  glVertex3f((float)fromEdge->estimate().translation().x(),(float)fromEdge->estimate().translation().y(),0.f);
158  glVertex3f((float)p.x(),(float)p.y(),0.f);
159  glEnd();
160  glPopAttrib();
161  return this;
162  }
163 #endif
164 
165 } // end namespace
Eigen::Matrix< double, 2, 1, Eigen::ColMajor > Vector2D
Definition: eigen_types.h:45
virtual void initialEstimate(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
const Vertex * vertex(size_t i) const
Definition: hyper_graph.h:186
#define __PRETTY_FUNCTION__
Definition: macros.h:89
EIGEN_MAKE_ALIGNED_OPERATOR_NEW EdgeSE2PointXY()
Abstract action that operates on a graph entity.
virtual bool write(std::ostream &os) const
write the vertex to a stream
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
2D pose Vertex, (x,y,theta)
Definition: vertex_se2.h:41
const std::string & name() const
returns the name of an action, e.g "draw"
int numUndefinedVertices() const
Definition: hyper_graph.cpp:59
const Eigen::Rotation2Dd & rotation() const
rotational component
Definition: se2.h:58
#define LANDMARK_EDGE_COLOR
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
virtual HyperGraphElementAction * operator()(HyperGraph::HyperGraphElement *element, HyperGraphElementAction::Parameters *params_)
redefine this to do the action stuff. If successful, the action returns a pointer to itself ...
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
Definition: base_vertex.h:101
A general case Vertex for optimization.
EIGEN_STRONG_INLINE const InformationType & information() const
information matrix of the constraint
Definition: base_edge.h:67
virtual void linearizeOplus()
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
const Vector2D & translation() const
translational component
Definition: se2.h:54
#define LANDMARK_EDGE_GHOST_COLOR
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition: base_edge.h:75
VertexContainer _vertices
Definition: hyper_graph.h:202