g2o
vertex_se3.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_se3.h"
28 #include "g2o/core/factory.h"
29 #ifdef G2O_HAVE_OPENGL
32 #endif
33 
34 #include <iostream>
35 #include "g2o/core/cache.h"
36 
37 using namespace Eigen;
38 
39 namespace g2o {
40 
41  VertexSE3::VertexSE3() :
42  BaseVertex<6, Isometry3D>(),
43  _numOplusCalls(0)
44  {
46  updateCache();
47  }
48 
49  bool VertexSE3::read(std::istream& is)
50  {
51  Vector7d est;
52  for (int i=0; i<7; i++)
53  is >> est[i];
55  return true;
56  }
57 
58  bool VertexSE3::write(std::ostream& os) const
59  {
61  for (int i=0; i<7; i++)
62  os << est[i] << " ";
63  return os.good();
64  }
65 
67 
69  if (typeid(*element).name()!=_typeName)
70  return 0;
72  if (!params->os){
73  std::cerr << __PRETTY_FUNCTION__ << ": warning, no valid os specified" << std::endl;
74  return 0;
75  }
76 
77  VertexSE3* v = static_cast<VertexSE3*>(element);
79  for (int i=0; i<6; i++)
80  *(params->os) << est[i] << " ";
81  *(params->os) << std::endl;
82  return this;
83  }
84 
85 #ifdef G2O_HAVE_OPENGL
86  void drawTriangle(float xSize, float ySize){
87  Vector3F p[3];
88  glBegin(GL_TRIANGLES);
89  p[0] << 0., 0., 0.;
90  p[1] << -xSize, ySize, 0.;
91  p[2] << -xSize, -ySize, 0.;
92  for (int i = 1; i < 2; ++i) {
93  Vector3F normal = (p[i] - p[0]).cross(p[i+1] - p[0]);
94  glNormal3f(normal.x(), normal.y(), normal.z());
95  glVertex3f(p[0].x(), p[0].y(), p[0].z());
96  glVertex3f(p[i].x(), p[i].y(), p[i].z());
97  glVertex3f(p[i+1].x(), p[i+1].y(), p[i+1].z());
98  }
99  glEnd();
100  }
101 
102  VertexSE3DrawAction::VertexSE3DrawAction(): DrawAction(typeid(VertexSE3).name()){
103  _cacheDrawActions = 0;
104  }
105 
106  bool VertexSE3DrawAction::refreshPropertyPtrs(HyperGraphElementAction::Parameters* params_){
107  if (!DrawAction::refreshPropertyPtrs(params_))
108  return false;
109  if (_previousParams){
110  _triangleX = _previousParams->makeProperty<FloatProperty>(_typeName + "::TRIANGLE_X", .2f);
111  _triangleY = _previousParams->makeProperty<FloatProperty>(_typeName + "::TRIANGLE_Y", .05f);
112  } else {
113  _triangleX = 0;
114  _triangleY = 0;
115  }
116  return true;
117  }
118 
119  HyperGraphElementAction* VertexSE3DrawAction::operator()(HyperGraph::HyperGraphElement* element,
121  if (typeid(*element).name()!=_typeName)
122  return 0;
123  initializeDrawActionsCache();
124  refreshPropertyPtrs(params_);
125 
126  if (! _previousParams)
127  return this;
128 
129  if (_show && !_show->value())
130  return this;
131 
132  VertexSE3* that = static_cast<VertexSE3*>(element);
133 
134  glColor3f(POSE_VERTEX_COLOR);
135  glPushMatrix();
136  glMultMatrixd(that->estimate().matrix().data());
137  opengl::drawArrow2D(_triangleX->value(), _triangleY->value(), _triangleX->value()*.3f);
138  drawCache(that->cacheContainer(), params_);
139  drawUserData(that->userData(), params_);
140  glPopMatrix();
141  return this;
142  }
143 #endif
144 
145 }
Eigen::Matrix< float, 3, 1, Eigen::ColMajor > Vector3F
Definition: eigen_types.h:41
#define __PRETTY_FUNCTION__
Definition: macros.h:89
const Data * userData() const
the user data associated with this vertex
Definition: hyper_graph.h:126
Isometry3D fromVectorQT(const Vector7d &v)
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_se3.cpp:68
Templatized BaseVertex.
Definition: base_vertex.h:50
Eigen::Matrix< double, 7, 1 > Vector7d
Definition: sim3.h:35
const std::string & name() const
returns the name of an action, e.g "draw"
void drawArrow2D(float len, float head_width, float head_len)
virtual bool write(std::ostream &os) const
write the vertex to a stream
Definition: vertex_se3.cpp:58
#define POSE_VERTEX_COLOR
virtual void setToOriginImpl()
sets the node to the origin (used in the multilevel stuff)
Definition: vertex_se3.h:59
Eigen::Transform< double, 3, Eigen::Isometry, Eigen::ColMajor > Isometry3D
Definition: eigen_types.h:66
Vector6d toVectorMQT(const Isometry3D &t)
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
Definition: base_vertex.h:101
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)
3D pose Vertex, represented as an Isometry3D
Definition: vertex_se3.h:50
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
Definition: vertex_se3.cpp:49
Vector7d toVectorQT(const Isometry3D &t)
Matrix< double, 6, 1, Eigen::ColMajor > Vector6d
Definition: types_icp.cpp:75