g2o
Loading...
Searching...
No Matches
edge_se3_plane_calib.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
28
29#include <iostream>
30
32
33namespace g2o {
34using namespace std;
35using namespace Eigen;
36
41
42bool EdgeSE3PlaneSensorCalib::read(std::istream& is) {
43 Vector4 v;
44 bool state = internal::readVector(is, v);
46 state &= internal::readVector(is, color);
47 state &= readInformationMatrix(is);
48 return state;
49}
50
51bool EdgeSE3PlaneSensorCalib::write(std::ostream& os) const {
52 internal::writeVector(os, measurement().toVector());
54 return writeInformationMatrix(os);
55}
56
57#ifdef G2O_HAVE_OPENGL
58EdgeSE3PlaneSensorCalibDrawAction::EdgeSE3PlaneSensorCalibDrawAction()
59 : DrawAction(typeid(EdgeSE3PlaneSensorCalib).name()),
60 _planeWidth(nullptr),
61 _planeHeight(nullptr) {}
62
63bool EdgeSE3PlaneSensorCalibDrawAction::refreshPropertyPtrs(
64 HyperGraphElementAction::Parameters* params_) {
65 if (!DrawAction::refreshPropertyPtrs(params_)) return false;
66 if (_previousParams) {
67 _planeWidth = _previousParams->makeProperty<FloatProperty>(
68 _typeName + "::PLANE_WIDTH", 0.5f);
69 _planeHeight = _previousParams->makeProperty<FloatProperty>(
70 _typeName + "::PLANE_HEIGHT", 0.5f);
71 } else {
72 _planeWidth = 0;
73 _planeHeight = 0;
74 }
75 return true;
76}
77
78HyperGraphElementAction* EdgeSE3PlaneSensorCalibDrawAction::operator()(
79 HyperGraph::HyperGraphElement* element,
80 HyperGraphElementAction::Parameters* params_) {
81 if (typeid(*element).name() != _typeName) return nullptr;
82
83 refreshPropertyPtrs(params_);
84 if (!_previousParams) return this;
85
86 if (_show && !_show->value()) return this;
87
88 EdgeSE3PlaneSensorCalib* that =
89 dynamic_cast<EdgeSE3PlaneSensorCalib*>(element);
90
91 if (!that) return this;
92
93 const VertexSE3* robot = dynamic_cast<const VertexSE3*>(that->vertex(0));
94 const VertexSE3* sensor = dynamic_cast<const VertexSE3*>(that->vertex(2));
95 if (!robot || !sensor) return nullptr;
96
97 if (_planeWidth && _planeHeight) {
98 double d = that->measurement().distance();
99 double azimuth = Plane3D::azimuth(that->measurement().normal());
100 double elevation = Plane3D::elevation(that->measurement().normal());
101
102 glColor3f(float(that->color(0)), float(that->color(1)),
103 float(that->color(2)));
104 glPushMatrix();
105 Isometry3 robotAndSensor = robot->estimate() * sensor->estimate();
106 glMultMatrixd(robotAndSensor.matrix().cast<double>().eval().data());
107
108 glRotatef(float(RAD2DEG(azimuth)), 0.f, 0.f, 1.f);
109 glRotatef(float(RAD2DEG(elevation)), 0.f, -1.f, 0.f);
110 glTranslatef(float(d), 0.f, 0.f);
111
112 float planeWidth = _planeWidth->value();
113 float planeHeight = _planeHeight->value();
114 glBegin(GL_QUADS);
115 glNormal3f(-1, 0, 0);
116 glVertex3f(0, -planeWidth, -planeHeight);
117 glVertex3f(0, planeWidth, -planeHeight);
118 glVertex3f(0, planeWidth, planeHeight);
119 glVertex3f(0, -planeWidth, planeHeight);
120 glEnd();
121 glPopMatrix();
122 }
123
124 return this;
125}
126#endif
127
128} // namespace g2o
bool writeInformationMatrix(std::ostream &os) const
write the upper trinagular part of the information matrix into the stream
Definition base_edge.h:165
bool readInformationMatrix(std::istream &is)
Definition base_edge.h:173
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
Definition base_edge.h:119
base class to represent an edge connecting an arbitrary number of nodes
virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)
plane measurement that also calibrates an offset for the sensor
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
void setMeasurement(const Plane3D &m)
static double elevation(const Vector3 &v)
Definition plane3d.h:59
static double azimuth(const Vector3 &v)
Definition plane3d.h:57
#define RAD2DEG(x)
Definition macros.h:35
Definition jet.h:938
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
Eigen::Transform< double, 3, Eigen::Isometry, Eigen::ColMajor > Isometry3
Definition eigen_types.h:77
Property< float > FloatProperty
Definition property.h:150
Definition jet.h:876