g2o
Loading...
Searching...
No Matches
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
31namespace g2o {
32
33VertexPlane::VertexPlane() { color << cst(.2), cst(.2), cst(.2); }
34
35bool VertexPlane::read(std::istream& is) {
36 Vector4 lv;
37 bool state = internal::readVector(is, lv);
39 state &= internal::readVector(is, color);
40 return state;
41}
42
43bool VertexPlane::write(std::ostream& os) const {
44 bool state = internal::writeVector(os, _estimate.toVector());
45 state &= internal::writeVector(os, color);
46 return state;
47}
48
49#ifdef G2O_HAVE_OPENGL
50
51VertexPlaneDrawAction::VertexPlaneDrawAction()
52 : DrawAction(typeid(VertexPlane).name()),
53 _planeWidth(nullptr),
54 _planeHeight(nullptr) {}
55
56bool VertexPlaneDrawAction::refreshPropertyPtrs(
57 HyperGraphElementAction::Parameters* params_) {
58 if (!DrawAction::refreshPropertyPtrs(params_)) return false;
59 if (_previousParams) {
60 _planeWidth = _previousParams->makeProperty<FloatProperty>(
61 _typeName + "::PLANE_WIDTH", 3);
62 _planeHeight = _previousParams->makeProperty<FloatProperty>(
63 _typeName + "::PLANE_HEIGHT", 3);
64 } else {
65 _planeWidth = 0;
66 _planeHeight = 0;
67 }
68 return true;
69}
70
71HyperGraphElementAction* VertexPlaneDrawAction::operator()(
72 HyperGraph::HyperGraphElement* element,
73 HyperGraphElementAction::Parameters* params_) {
74 if (typeid(*element).name() != _typeName) return nullptr;
75 refreshPropertyPtrs(params_);
76 if (!_previousParams) return this;
77 if (_show && !_show->value()) return this;
78
79 if (_planeWidth && _planeHeight) {
80 VertexPlane* that = static_cast<VertexPlane*>(element);
81 double d = that->estimate().distance();
82 double azimuth = Plane3D::azimuth(that->estimate().normal());
83 double elevation = Plane3D::elevation(that->estimate().normal());
84 glColor3f(float(that->color(0)), float(that->color(1)),
85 float(that->color(2)));
86 glPushMatrix();
87 glRotatef(float(RAD2DEG(azimuth)), 0.f, 0.f, 1.f);
88 glRotatef(float(RAD2DEG(elevation)), 0.f, -1.f, 0.f);
89 glTranslatef(float(d), 0.f, 0.f);
90
91 glBegin(GL_QUADS);
92 glNormal3f(-1.f, 0.f, 0.f);
93 glVertex3f(0.f, -_planeWidth->value(), -_planeHeight->value());
94 glVertex3f(0.f, _planeWidth->value(), -_planeHeight->value());
95 glVertex3f(0.f, _planeWidth->value(), _planeHeight->value());
96 glVertex3f(0.f, -_planeWidth->value(), _planeHeight->value());
97 glEnd();
98 glPopMatrix();
99 }
100
101 return this;
102}
103#endif
104
105} // namespace g2o
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)
Vector4 toVector() const
Definition plane3d.h:48
static double elevation(const Vector3 &v)
Definition plane3d.h:59
static double azimuth(const Vector3 &v)
Definition plane3d.h:57
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
virtual bool write(std::ostream &os) const
write the vertex to a stream
#define RAD2DEG(x)
Definition macros.h:35
bool writeVector(std::ostream &os, const Eigen::DenseBase< Derived > &b)
Definition io_helper.h:36
bool readVector(std::istream &is, Eigen::DenseBase< Derived > &b)
Definition io_helper.h:42
VectorN< 4 > Vector4
Definition eigen_types.h:52
constexpr double cst(long double v)
Definition misc.h:60
Property< float > FloatProperty
Definition property.h:150