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 
30 
31 #include <cstdio>
32 #include <typeinfo>
33 
34 namespace g2o {
35 namespace deprecated {
36 
37  // TRACK VERTEX
38 
39  bool VertexPointXYZ::read(std::istream& is) {
40  Eigen::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  const Eigen::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.f);
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 
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  glPushAttrib(GL_ENABLE_BIT | GL_POINT_BIT);
88  glDisable(GL_LIGHTING);
89  glColor3f(0.8f,0.5f,0.3f);
90  if (_pointSize) {
91  glPointSize(_pointSize->value());
92  }
93  glBegin(GL_POINTS);
94  glVertex3f((float)that->estimate()(0),(float)that->estimate()(1),(float)that->estimate()(2));
95  glEnd();
96  glPopAttrib();
97  return this;
98  }
99 #endif
100 
102  WriteGnuplotAction(typeid(VertexPointXYZ).name())
103  {
104  }
105 
107  {
108  if (typeid(*element).name()!=_typeName)
109  return 0;
110  WriteGnuplotAction::Parameters* params=static_cast<WriteGnuplotAction::Parameters*>(params_);
111  if (!params->os){
112  std::cerr << __PRETTY_FUNCTION__ << ": warning, no valid os specified" << std::endl;
113  return 0;
114  }
115 
116  VertexPointXYZ* v = static_cast<VertexPointXYZ*>(element);
117  *(params->os) << v->estimate().x() << " " << v->estimate().y() << " " << v->estimate().z() << " " << std::endl;
118  return this;
119  }
120 
121 } // end namespace
122 } // end namespace
#define __PRETTY_FUNCTION__
Definition: macros.h:89
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
Abstract action that operates on a graph entity.
virtual bool write(std::ostream &os) const
write the vertex to a stream
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
Definition: base_vertex.h:101
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 ...
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)