g2o
Loading...
Searching...
No Matches
vertex_point_xy.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_point_xy.h"
28
29#ifdef G2O_HAVE_OPENGL
32#endif
33
34#include <typeinfo>
35
36#include "g2o/stuff/macros.h"
37
38namespace g2o {
39
43
44bool VertexPointXY::read(std::istream& is) {
46}
47
48bool VertexPointXY::write(std::ostream& os) const {
49 return internal::writeVector(os, estimate());
50}
51
54
58 if (typeid(*element).name() != _typeName) return nullptr;
59
61 static_cast<WriteGnuplotAction::Parameters*>(params_);
62 if (!params->os) {
63 return nullptr;
64 }
65
66 VertexPointXY* v = static_cast<VertexPointXY*>(element);
67 *(params->os) << v->estimate().x() << " " << v->estimate().y() << std::endl;
68 return this;
69}
70
71#ifdef G2O_HAVE_OPENGL
72VertexPointXYDrawAction::VertexPointXYDrawAction()
73 : DrawAction(typeid(VertexPointXY).name()), _pointSize(nullptr) {}
74
75bool VertexPointXYDrawAction::refreshPropertyPtrs(
76 HyperGraphElementAction::Parameters* params_) {
77 if (!DrawAction::refreshPropertyPtrs(params_)) return false;
78 if (_previousParams) {
79 _pointSize = _previousParams->makeProperty<FloatProperty>(
80 _typeName + "::POINT_SIZE", 1.);
81 } else {
82 _pointSize = 0;
83 }
84 return true;
85}
86
87HyperGraphElementAction* VertexPointXYDrawAction::operator()(
88 HyperGraph::HyperGraphElement* element,
89 HyperGraphElementAction::Parameters* params) {
90 if (typeid(*element).name() != _typeName) return nullptr;
91 initializeDrawActionsCache();
92 refreshPropertyPtrs(params);
93 if (!_previousParams) return this;
94
95 if (_show && !_show->value()) return this;
96 VertexPointXY* that = static_cast<VertexPointXY*>(element);
97
98 glPushMatrix();
99 glPushAttrib(GL_ENABLE_BIT | GL_POINT_BIT);
100 glDisable(GL_LIGHTING);
101 glColor3f(LANDMARK_VERTEX_COLOR);
102 float ps = _pointSize ? _pointSize->value() : 1.0f;
103 glTranslatef((float)that->estimate()(0), (float)that->estimate()(1), 0.0f);
105 glPopAttrib();
106 drawCache(that->cacheContainer(), params);
107 drawUserData(that->userData(), params);
108 glPopMatrix();
109 return this;
110}
111#endif
112
113} // namespace g2o
Templatized BaseVertex.
Definition base_vertex.h:51
const EstimateType & estimate() const
return the current estimate of the vertex
virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)
Abstract action that operates on a graph entity.
virtual HyperGraphElementAction * operator()(HyperGraph::HyperGraphElement *element, 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
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
void drawPoint(float pointSize)
VectorN< 2 > Vector2
Definition eigen_types.h:50
Property< float > FloatProperty
Definition property.h:150
#define LANDMARK_VERTEX_COLOR