g2o
Loading...
Searching...
No Matches
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
29#include "g2o/core/factory.h"
30#ifdef G2O_HAVE_OPENGL
33#endif
34
35#include "g2o/core/cache.h"
36
37using namespace Eigen;
38
39namespace g2o {
40
41VertexSE3::VertexSE3() : BaseVertex<6, Isometry3>(), _numOplusCalls(0) {
44}
45
46bool VertexSE3::read(std::istream& is) {
47 Vector7 est;
48 bool state = internal::readVector(is, est);
50 return state;
51}
52
53bool VertexSE3::write(std::ostream& os) const {
55}
56
59
63 if (typeid(*element).name() != _typeName) return nullptr;
65 static_cast<WriteGnuplotAction::Parameters*>(params_);
66 if (!params->os) {
67 return nullptr;
68 }
69
70 VertexSE3* v = static_cast<VertexSE3*>(element);
72 for (int i = 0; i < 6; i++) *(params->os) << est[i] << " ";
73 *(params->os) << std::endl;
74 return this;
75}
76
77#ifdef G2O_HAVE_OPENGL
78void drawTriangle(float xSize, float ySize) {
79 Vector3F p[3];
80 glBegin(GL_TRIANGLES);
81 p[0] << 0., 0., 0.;
82 p[1] << -xSize, ySize, 0.;
83 p[2] << -xSize, -ySize, 0.;
84 for (int i = 1; i < 2; ++i) {
85 Vector3F normal = (p[i] - p[0]).cross(p[i + 1] - p[0]);
86 glNormal3f(normal.x(), normal.y(), normal.z());
87 glVertex3f(p[0].x(), p[0].y(), p[0].z());
88 glVertex3f(p[i].x(), p[i].y(), p[i].z());
89 glVertex3f(p[i + 1].x(), p[i + 1].y(), p[i + 1].z());
90 }
91 glEnd();
92}
93
94VertexSE3DrawAction::VertexSE3DrawAction()
95 : DrawAction(typeid(VertexSE3).name()),
96 _triangleX(nullptr),
97 _triangleY(nullptr) {
98 _cacheDrawActions = 0;
99}
100
101bool VertexSE3DrawAction::refreshPropertyPtrs(
102 HyperGraphElementAction::Parameters* params_) {
103 if (!DrawAction::refreshPropertyPtrs(params_)) return false;
104 if (_previousParams) {
105 _triangleX = _previousParams->makeProperty<FloatProperty>(
106 _typeName + "::TRIANGLE_X", .2f);
107 _triangleY = _previousParams->makeProperty<FloatProperty>(
108 _typeName + "::TRIANGLE_Y", .05f);
109 } else {
110 _triangleX = 0;
111 _triangleY = 0;
112 }
113 return true;
114}
115
116HyperGraphElementAction* VertexSE3DrawAction::operator()(
117 HyperGraph::HyperGraphElement* element,
118 HyperGraphElementAction::Parameters* params_) {
119 if (typeid(*element).name() != _typeName) return nullptr;
120 initializeDrawActionsCache();
121 refreshPropertyPtrs(params_);
122
123 if (!_previousParams) return this;
124
125 if (_show && !_show->value()) return this;
126
127 VertexSE3* that = static_cast<VertexSE3*>(element);
128
129 glColor3f(POSE_VERTEX_COLOR);
130 glPushMatrix();
131 glMultMatrixd(that->estimate().matrix().cast<double>().eval().data());
132 opengl::drawArrow2D(_triangleX->value(), _triangleY->value(),
133 _triangleX->value() * .3f);
134 drawCache(that->cacheContainer(), params_);
135 drawUserData(that->userData(), params_);
136 glPopMatrix();
137 return this;
138}
139#endif
140
141} // namespace g2o
Templatized BaseVertex.
Definition base_vertex.h:51
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 bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)
Abstract action that operates on a graph entity.
virtual HyperGraphElementAction * operator()(HyperGraph::HyperGraphElement *element, HyperGraphElementAction::Parameters *params_)
3D pose Vertex, represented as an Isometry3
Definition vertex_se3.h:50
virtual bool write(std::ostream &os) const
write the vertex to a stream
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
virtual void setToOriginImpl()
sets the node to the origin (used in the multilevel stuff)
Definition vertex_se3.h:59
Definition jet.h:938
Isometry3 fromVectorQT(const Vector7 &v)
Vector6 toVectorMQT(const Isometry3 &t)
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
Vector7 toVectorQT(const Isometry3 &t)
void drawArrow2D(float len, float head_width, float head_len)
VectorN< 7 > Vector7
Definition eigen_types.h:54
Eigen::Matrix< float, 3, 1, Eigen::ColMajor > Vector3F
Definition eigen_types.h:44
Eigen::Transform< double, 3, Eigen::Isometry, Eigen::ColMajor > Isometry3
Definition eigen_types.h:77
VectorN< 6 > Vector6
Definition eigen_types.h:53
Property< float > FloatProperty
Definition property.h:150
#define POSE_VERTEX_COLOR