g2o
vertex_plane.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_plane.h"
28 
30 
31 namespace g2o
32 {
33 
35  color << .2, .2, .2;
36  }
37 
38  bool VertexPlane::read(std::istream& is) {
39  Vector4D lv;
40  for (int i=0; i<4; i++)
41  is >> lv[i];
42  setEstimate(Plane3D(lv));
43  is >> color(0) >> color(1) >> color(2);
44  return true;
45  }
46 
47  bool VertexPlane::write(std::ostream& os) const {
49  for (int i=0; i<4; i++){
50  os << lv[i] << " ";
51  }
52  os << color(0) << " " << color(1) << " " << color(2) << " ";
53  return os.good();
54  }
55 
56 #ifdef G2O_HAVE_OPENGL
57 
58  VertexPlaneDrawAction::VertexPlaneDrawAction(): DrawAction(typeid(VertexPlane).name())
59  {
60  }
61 
62  bool VertexPlaneDrawAction::refreshPropertyPtrs(HyperGraphElementAction::Parameters* params_)
63  {
64  if (!DrawAction::refreshPropertyPtrs(params_))
65  return false;
66  if (_previousParams){
67  _planeWidth = _previousParams->makeProperty<FloatProperty>(_typeName + "::PLANE_WIDTH", 3);
68  _planeHeight = _previousParams->makeProperty<FloatProperty>(_typeName + "::PLANE_HEIGHT", 3);
69  } else {
70  _planeWidth = 0;
71  _planeHeight = 0;
72  }
73  return true;
74  }
75 
76  HyperGraphElementAction* VertexPlaneDrawAction::operator()(HyperGraph::HyperGraphElement* element,
78  {
79  if (typeid(*element).name()!=_typeName)
80  return 0;
81 
82  refreshPropertyPtrs(params_);
83  if (! _previousParams)
84  return this;
85 
86  if (_show && !_show->value())
87  return this;
88 
89  VertexPlane* that = static_cast<VertexPlane*>(element);
90  double d = that->estimate().distance();
91  double azimuth = Plane3D::azimuth(that->estimate().normal());
92  double elevation = Plane3D::elevation(that->estimate().normal());
93  glColor3f(float(that->color(0)), float(that->color(1)), float(that->color(2)));
94  glPushMatrix();
95  glRotatef(float(RAD2DEG(azimuth)), 0.f, 0.f, 1.f);
96  glRotatef(float(RAD2DEG(elevation)), 0.f, -1.f, 0.f);
97  glTranslatef(float(d), 0.f ,0.f);
98 
99  if (_planeWidth && _planeHeight){
100  glBegin(GL_QUADS);
101  glNormal3f(-1.f, 0.f, 0.f);
102  glVertex3f(0.f, -_planeWidth->value(), -_planeHeight->value());
103  glVertex3f(0.f, _planeWidth->value(), -_planeHeight->value());
104  glVertex3f(0.f, _planeWidth->value(), _planeHeight->value());
105  glVertex3f(0.f, -_planeWidth->value(), _planeHeight->value());
106  glEnd();
107  }
108 
109  glPopMatrix();
110  return this;
111  }
112 #endif
113 
114 }
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
static double elevation(const Eigen::Vector3d &v)
Definition: plane3d.h:68
Abstract action that operates on a graph entity.
Eigen::Matrix< double, 4, 1, Eigen::ColMajor > Vector4D
Definition: eigen_types.h:47
static double azimuth(const Eigen::Vector3d &v)
Definition: plane3d.h:64
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
Eigen::Vector3d normal() const
Definition: plane3d.h:76
const EstimateType & estimate() const
return the current estimate of the vertex
Definition: base_vertex.h:99
virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)
#define RAD2DEG(x)
Definition: macros.h:35
Eigen::Vector4d toVector() const
Definition: plane3d.h:53
double distance() const
Definition: plane3d.h:72