g2o
Loading...
Searching...
No Matches
vertex_tag.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_tag.h"
28
29#include "g2o/stuff/macros.h"
30
31#ifdef G2O_HAVE_OPENGL
35#endif
36
37#include <iomanip>
38using namespace std;
39
40namespace g2o {
41
43
45
46bool VertexTag::read(std::istream& is) {
47 is >> _name;
48 is >> _position.x() >> _position.y() >> _position.z();
49 is >> _odom2d.x() >> _odom2d.y() >> _odom2d.z();
50 is >> _timestamp;
51 is >> _hostname;
52 is >> _loggerTimestamp;
53 return true;
54}
55
56bool VertexTag::write(std::ostream& os) const {
57 os << _name << " ";
58 os << FIXED(_position.x()
59 << " " << _position.y() << " " << _position.z() << " ");
60 os << FIXED(_odom2d.x() << " " << _odom2d.y() << " " << _odom2d.z() << " ");
61 os << FIXED(" " << timestamp() << " " << hostname() << " "
62 << loggerTimestamp());
63 return os.good();
64}
65
66#ifdef G2O_HAVE_OPENGL
67VertexTagDrawAction::VertexTagDrawAction()
68 : DrawAction(typeid(VertexTag).name()), _textSize(nullptr) {}
69
70bool VertexTagDrawAction::refreshPropertyPtrs(
71 HyperGraphElementAction::Parameters* params_) {
72 if (!DrawAction::refreshPropertyPtrs(params_)) return false;
73 if (_previousParams) {
74 _textSize = _previousParams->makeProperty<DoubleProperty>(
75 _typeName + "::TEXT_SIZE", 1);
76 } else {
77 _textSize = 0;
78 }
79 return true;
80}
81
82HyperGraphElementAction* VertexTagDrawAction::operator()(
83 HyperGraph::HyperGraphElement* element,
84 HyperGraphElementAction::Parameters* params_) {
85 if (typeid(*element).name() != _typeName) return nullptr;
86
87 refreshPropertyPtrs(params_);
88 if (!_previousParams) {
89 return this;
90 }
91 VertexTag* that = static_cast<VertexTag*>(element);
92
93 glPushMatrix();
94 glColor3f(1.f, 0.2f, 1.f);
95 glTranslatef(that->position().x(), that->position().y(),
96 that->position().z());
97 float textSize = 1;
98 if (_textSize) textSize = (float)_textSize->value();
99 opengl::drawBox(0.1f * textSize, 0.1f * textSize, 0.1f * textSize);
100 glTranslatef(0.2f * textSize, 0.f, 0.f);
101 glScalef(0.003f * textSize, 0.003f * textSize, 1.f);
103 that->name().c_str());
104 glPopMatrix();
105 return this;
106}
107#endif
108
109} // namespace g2o
virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)
data recorded by the robot
Definition robot_data.h:41
double timestamp() const
Definition robot_data.h:46
double _loggerTimestamp
timestamp when the measurement was recorded
Definition robot_data.h:60
double loggerTimestamp() const
Definition robot_data.h:49
const std::string & hostname() const
Definition robot_data.h:55
std::string _hostname
name of the computer/robot generating the data
Definition robot_data.h:63
double _timestamp
timestamp when the measurement was generated
Definition robot_data.h:59
string tag to be attached to a vertex
Definition vertex_tag.h:43
Vector3F _odom2d
Definition vertex_tag.h:60
std::string _name
Definition vertex_tag.h:58
virtual bool read(std::istream &is)
read the data from a stream
Vector3F _position
Definition vertex_tag.h:59
virtual bool write(std::ostream &os) const
write the data to a stream
void glutStrokeString(FontID fontID, const char *string_)
void drawBox(GLfloat l, GLfloat w, GLfloat h)
Property< double > DoubleProperty
Definition property.h:151
Definition jet.h:876