g2o
vertex_point_xy.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_point_xy.h"
28 
29 #ifdef G2O_HAVE_OPENGL
32 #endif
33 
34 #include <typeinfo>
35 
36 #include "g2o/stuff/macros.h"
37 
38 namespace g2o {
39 
41  BaseVertex<2, Vector2D>()
42  {
43  _estimate.setZero();
44  }
45 
46  bool VertexPointXY::read(std::istream& is)
47  {
48  is >> _estimate[0] >> _estimate[1];
49  return true;
50  }
51 
52  bool VertexPointXY::write(std::ostream& os) const
53  {
54  os << estimate()(0) << " " << estimate()(1);
55  return os.good();
56  }
57 
59 
61  if (typeid(*element).name()!=_typeName)
62  return 0;
63 
65  if (!params->os){
66  std::cerr << __PRETTY_FUNCTION__ << ": warning, on valid os specified" << std::endl;
67  return 0;
68  }
69 
70  VertexPointXY* v = static_cast<VertexPointXY*>(element);
71  *(params->os) << v->estimate().x() << " " << v->estimate().y() << std::endl;
72  return this;
73  }
74 
75 #ifdef G2O_HAVE_OPENGL
76  VertexPointXYDrawAction::VertexPointXYDrawAction(): DrawAction(typeid(VertexPointXY).name()){}
77 
78  bool VertexPointXYDrawAction::refreshPropertyPtrs(HyperGraphElementAction::Parameters* params_){
79  if (! DrawAction::refreshPropertyPtrs(params_))
80  return false;
81  if (_previousParams){
82  _pointSize = _previousParams->makeProperty<FloatProperty>(_typeName + "::POINT_SIZE", 1.);
83  } else {
84  _pointSize = 0;
85  }
86  return true;
87  }
88 
89  HyperGraphElementAction* VertexPointXYDrawAction::operator()(HyperGraph::HyperGraphElement* element,
91 
92  if (typeid(*element).name()!=_typeName)
93  return 0;
94  initializeDrawActionsCache();
95  refreshPropertyPtrs(params);
96  if (! _previousParams)
97  return this;
98 
99  if (_show && !_show->value())
100  return this;
101  VertexPointXY* that = static_cast<VertexPointXY*>(element);
102 
103  glPushMatrix();
104  glPushAttrib(GL_ENABLE_BIT | GL_POINT_BIT);
105  glDisable(GL_LIGHTING);
106  glColor3f(LANDMARK_VERTEX_COLOR);
107  float ps = _pointSize ? _pointSize->value() : 1.0f;
108  glTranslatef((float)that->estimate()(0),(float)that->estimate()(1),0.0f);
109  opengl::drawPoint(ps);
110  glPopAttrib();
111  drawCache(that->cacheContainer(), params);
112  drawUserData(that->userData(), params);
113  glPopMatrix();
114  return this;
115  }
116 #endif
117 
118 } // end namespace
Eigen::Matrix< double, 2, 1, Eigen::ColMajor > Vector2D
Definition: eigen_types.h:45
#define __PRETTY_FUNCTION__
Definition: macros.h:89
const Data * userData() const
the user data associated with this vertex
Definition: hyper_graph.h:126
Abstract action that operates on a graph entity.
#define LANDMARK_VERTEX_COLOR
Templatized BaseVertex.
Definition: base_vertex.h:50
const std::string & name() const
returns the name of an action, e.g "draw"
void drawPoint(float pointSize)
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 ...
virtual bool write(std::ostream &os) const
write the vertex to a stream
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex