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