g2o
vertex_pointxyz.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_pointxyz.h"
28 #include <stdio.h>
29 
30 #ifdef G2O_HAVE_OPENGL
33 #endif
34 
35 #include <typeinfo>
36 
37 namespace g2o {
38 
39  bool VertexPointXYZ::read(std::istream& is) {
40  Vector3D lv;
41  for (int i=0; i<3; i++)
42  is >> lv[i];
43  setEstimate(lv);
44  return true;
45  }
46 
47  bool VertexPointXYZ::write(std::ostream& os) const {
48  Vector3D lv=estimate();
49  for (int i=0; i<3; i++){
50  os << lv[i] << " ";
51  }
52  return os.good();
53  }
54 
55 
56 #ifdef G2O_HAVE_OPENGL
57  VertexPointXYZDrawAction::VertexPointXYZDrawAction(): DrawAction(typeid(VertexPointXYZ).name()){
58  }
59 
60  bool VertexPointXYZDrawAction::refreshPropertyPtrs(HyperGraphElementAction::Parameters* params_){
61  if (! DrawAction::refreshPropertyPtrs(params_))
62  return false;
63  if (_previousParams){
64  _pointSize = _previousParams->makeProperty<FloatProperty>(_typeName + "::POINT_SIZE", 1.);
65  } else {
66  _pointSize = 0;
67  }
68  return true;
69  }
70 
71 
72  HyperGraphElementAction* VertexPointXYZDrawAction::operator()(HyperGraph::HyperGraphElement* element,
74 
75  if (typeid(*element).name()!=_typeName)
76  return 0;
77  initializeDrawActionsCache();
78  refreshPropertyPtrs(params);
79  if (! _previousParams)
80  return this;
81 
82  if (_show && !_show->value())
83  return this;
84  VertexPointXYZ* that = static_cast<VertexPointXYZ*>(element);
85 
86 
87  glPushMatrix();
88  glPushAttrib(GL_ENABLE_BIT | GL_POINT_BIT);
89  glDisable(GL_LIGHTING);
90  glColor3f(LANDMARK_VERTEX_COLOR);
91  float ps = _pointSize ? _pointSize->value() : 1.f;
92  glTranslatef((float)that->estimate()(0),(float)that->estimate()(1),(float)that->estimate()(2));
94  glPopAttrib();
95  drawCache(that->cacheContainer(), params);
96  drawUserData(that->userData(), params);
97  glPopMatrix();
98  return this;
99  }
100 #endif
101 
103  WriteGnuplotAction(typeid(VertexPointXYZ).name())
104  {
105  }
106 
108  {
109  if (typeid(*element).name()!=_typeName)
110  return 0;
111  WriteGnuplotAction::Parameters* params=static_cast<WriteGnuplotAction::Parameters*>(params_);
112  if (!params->os){
113  std::cerr << __PRETTY_FUNCTION__ << ": warning, no valid os specified" << std::endl;
114  return 0;
115  }
116 
117  VertexPointXYZ* v = static_cast<VertexPointXYZ*>(element);
118  *(params->os) << v->estimate().x() << " " << v->estimate().y() << " " << v->estimate().z() << " " << std::endl;
119  return this;
120  }
121 
122 }
123 
#define __PRETTY_FUNCTION__
Definition: macros.h:89
const Data * userData() const
the user data associated with this vertex
Definition: hyper_graph.h:126
Eigen::Matrix< double, 3, 1, Eigen::ColMajor > Vector3D
Definition: eigen_types.h:46
Abstract action that operates on a graph entity.
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
#define LANDMARK_VERTEX_COLOR
virtual bool write(std::ostream &os) const
write the vertex to a stream
void drawPoint(float pointSize)
Vertex for a tracked point in space.
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_)
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 ...