g2o
vertex_segment2d.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_segment2d.h"
28 
29 #ifdef WINDOWS
30 #include <windows.h>
31 #endif
32 
33 #ifdef G2O_HAVE_OPENGL
35 #endif
36 
37 #include <typeinfo>
38 
39 #include "g2o/stuff/macros.h"
40 
41 namespace g2o {
42 
44  BaseVertex<4, Vector4D>()
45  {
46  _estimate.setZero();
47  }
48 
49  bool VertexSegment2D::read(std::istream& is)
50  {
51  for (size_t i=0; i<4; i++)
52  is >> _estimate[i];
53  return true;
54  }
55 
56  bool VertexSegment2D::write(std::ostream& os) const
57  {
58  for (size_t i=0; i<4; i++)
59  os << _estimate[i] << " ";
60  return os.good();
61  }
62 
64 
66  if (typeid(*element).name()!=_typeName)
67  return 0;
68 
70  if (!params->os){
71  std::cerr << __PRETTY_FUNCTION__ << ": warning, on valid os specified" << std::endl;
72  return 0;
73  }
74 
75  VertexSegment2D* v = static_cast<VertexSegment2D*>(element);
76  *(params->os) << v->estimateP1().x() << " " << v->estimateP1().y() << std::endl;
77  *(params->os) << v->estimateP2().x() << " " << v->estimateP2().y() << std::endl;
78  *(params->os) << std::endl;
79  return this;
80  }
81 
82 #ifdef G2O_HAVE_OPENGL
83  VertexSegment2DDrawAction::VertexSegment2DDrawAction(): DrawAction(typeid(VertexSegment2D).name()){}
84 
85  bool VertexSegment2DDrawAction::refreshPropertyPtrs(HyperGraphElementAction::Parameters* params_){
86  if (! DrawAction::refreshPropertyPtrs(params_))
87  return false;
88  if (_previousParams){
89  _pointSize = _previousParams->makeProperty<FloatProperty>(_typeName + "::POINT_SIZE", 1.);
90  } else {
91  _pointSize = 0;
92  }
93  return true;
94  }
95 
96  HyperGraphElementAction* VertexSegment2DDrawAction::operator()(HyperGraph::HyperGraphElement* element,
98 
99  if (typeid(*element).name()!=_typeName)
100  return 0;
101 
102  refreshPropertyPtrs(params_);
103  if (! _previousParams)
104  return this;
105 
106  if (_show && !_show->value())
107  return this;
108 
109 
110  VertexSegment2D* that = static_cast<VertexSegment2D*>(element);
111  glColor3f(0.8f,0.5f,0.3f);
112  if (_pointSize) {
113  glPointSize(_pointSize->value());
114  }
115  glBegin(GL_LINES);
116  glVertex3f((float)that->estimateP1().x(),(float)that->estimateP1().y(),0.f);
117  glVertex3f((float)that->estimateP2().x(),(float)that->estimateP2().y(),0.f);
118  glEnd();
119  return this;
120  }
121 #endif
122 
123 } // end namespace
#define __PRETTY_FUNCTION__
Definition: macros.h:89
Abstract action that operates on a graph entity.
Eigen::Matrix< double, 4, 1, Eigen::ColMajor > Vector4D
Definition: eigen_types.h:47
Templatized BaseVertex.
Definition: base_vertex.h:50
const std::string & name() const
returns the name of an action, e.g "draw"
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 ...
Vector2D estimateP1() const
Vector2D estimateP2() const
virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)
virtual bool write(std::ostream &os) const
write the vertex to a stream
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex