g2o
vertex_se2.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 "vertex_se2.h"
28 #include <typeinfo>
29 
30 #ifdef G2O_HAVE_OPENGL
33 #endif
34 
35 namespace g2o {
36 
38  BaseVertex<3, SE2>()
39  {
40  }
41 
42  bool VertexSE2::read(std::istream& is)
43  {
44  Vector3D p;
45  is >> p[0] >> p[1] >> p[2];
46  setEstimate(p);
47  return true;
48  }
49 
50  bool VertexSE2::write(std::ostream& os) const
51  {
52  Vector3D p = estimate().toVector();
53  os << p[0] << " " << p[1] << " " << p[2];
54  return os.good();
55  }
56 
58 
60  if (typeid(*element).name()!=_typeName)
61  return 0;
63  if (!params || !params->os){
64  std::cerr << __PRETTY_FUNCTION__ << ": warning, no valid output stream specified" << std::endl;
65  return 0;
66  }
67 
68  VertexSE2* v = static_cast<VertexSE2*>(element);
69  *(params->os) << v->estimate().translation().x() << " " << v->estimate().translation().y()
70  << " " << v->estimate().rotation().angle() << std::endl;
71  return this;
72  }
73 
74 #ifdef G2O_HAVE_OPENGL
75  VertexSE2DrawAction::VertexSE2DrawAction(): DrawAction(typeid(VertexSE2).name()){
76  _drawActions = 0;
77  }
78 
79  bool VertexSE2DrawAction::refreshPropertyPtrs(HyperGraphElementAction::Parameters* params_){
80  if (!DrawAction::refreshPropertyPtrs(params_))
81  return false;
82  if (_previousParams){
83  _triangleX = _previousParams->makeProperty<FloatProperty>(_typeName + "::TRIANGLE_X", .2f);
84  _triangleY = _previousParams->makeProperty<FloatProperty>(_typeName + "::TRIANGLE_Y", .05f);
85  } else {
86  _triangleX = 0;
87  _triangleY = 0;
88  }
89  return true;
90  }
91 
92 
93  HyperGraphElementAction* VertexSE2DrawAction::operator()(HyperGraph::HyperGraphElement* element,
95  if (typeid(*element).name()!=_typeName)
96  return 0;
97  initializeDrawActionsCache();
98  refreshPropertyPtrs(params_);
99 
100  if (! _previousParams)
101  return this;
102 
103  if (_show && !_show->value())
104  return this;
105 
106  VertexSE2* that = static_cast<VertexSE2*>(element);
107 
108  glColor3f(POSE_VERTEX_COLOR);
109  glPushMatrix();
110  glTranslatef((float)that->estimate().translation().x(),(float)that->estimate().translation().y(),0.f);
111  glRotatef((float)RAD2DEG(that->estimate().rotation().angle()),0.f,0.f,1.f);
112  opengl::drawArrow2D((float)_triangleX->value(), (float)_triangleY->value(), (float)_triangleX->value()*.3f);
113  drawCache(that->cacheContainer(), params_);
114  drawUserData(that->userData(), params_);
115  glPopMatrix();
116  return this;
117  }
118 #endif
119 
120 
121 } // end namespace
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
Definition: vertex_se2.cpp:42
#define __PRETTY_FUNCTION__
Definition: macros.h:89
const Data * userData() const
the user data associated with this vertex
Definition: hyper_graph.h:126
Vector3D toVector() const
convert to a 3D vector (x, y, theta)
Definition: se2.h:108
Eigen::Matrix< double, 3, 1, Eigen::ColMajor > Vector3D
Definition: eigen_types.h:46
Abstract action that operates on a graph entity.
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 ...
Definition: vertex_se2.cpp:59
represent SE2
Definition: se2.h:40
Templatized BaseVertex.
Definition: base_vertex.h:50
EIGEN_MAKE_ALIGNED_OPERATOR_NEW VertexSE2()
Definition: vertex_se2.cpp:37
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"
void drawArrow2D(float len, float head_width, float head_len)
#define POSE_VERTEX_COLOR
const Eigen::Rotation2Dd & rotation() const
rotational component
Definition: se2.h:58
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
Definition: base_vertex.h:101
virtual bool write(std::ostream &os) const
write the vertex to a stream
Definition: vertex_se2.cpp:50
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)
const Vector2D & translation() const
translational component
Definition: se2.h:54
#define RAD2DEG(x)
Definition: macros.h:35