g2o
Loading...
Searching...
No Matches
vertex_pointxyz.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_pointxyz.h"
28
29#include <stdio.h>
30
31#ifdef G2O_HAVE_OPENGL
34#endif
35
36#include <typeinfo>
37
38namespace g2o {
39
40bool VertexPointXYZ::read(std::istream& is) {
42}
43
44bool VertexPointXYZ::write(std::ostream& os) const {
45 return internal::writeVector(os, estimate());
46}
47
48#ifdef G2O_HAVE_OPENGL
49VertexPointXYZDrawAction::VertexPointXYZDrawAction()
50 : DrawAction(typeid(VertexPointXYZ).name()), _pointSize(nullptr) {}
51
52bool VertexPointXYZDrawAction::refreshPropertyPtrs(
53 HyperGraphElementAction::Parameters* params_) {
54 if (!DrawAction::refreshPropertyPtrs(params_)) return false;
55 if (_previousParams) {
56 _pointSize = _previousParams->makeProperty<FloatProperty>(
57 _typeName + "::POINT_SIZE", 1.);
58 } else {
59 _pointSize = nullptr;
60 }
61 return true;
62}
63
64HyperGraphElementAction* VertexPointXYZDrawAction::operator()(
65 HyperGraph::HyperGraphElement* element,
66 HyperGraphElementAction::Parameters* params) {
67 if (typeid(*element).name() != _typeName) return nullptr;
68 initializeDrawActionsCache();
69 refreshPropertyPtrs(params);
70 if (!_previousParams) return this;
71
72 if (_show && !_show->value()) return this;
73 VertexPointXYZ* that = static_cast<VertexPointXYZ*>(element);
74
75 glPushMatrix();
76 glPushAttrib(GL_ENABLE_BIT | GL_POINT_BIT);
77 glDisable(GL_LIGHTING);
78 glColor3f(LANDMARK_VERTEX_COLOR);
79 float ps = _pointSize ? _pointSize->value() : 1.f;
80 glTranslatef((float)that->estimate()(0), (float)that->estimate()(1),
81 (float)that->estimate()(2));
83 glPopAttrib();
84 drawCache(that->cacheContainer(), params);
85 drawUserData(that->userData(), params);
86 glPopMatrix();
87 return this;
88}
89#endif
90
93
97 if (typeid(*element).name() != _typeName) return nullptr;
99 static_cast<WriteGnuplotAction::Parameters*>(params_);
100 if (!params->os) {
101 return nullptr;
102 }
103
104 VertexPointXYZ* v = static_cast<VertexPointXYZ*>(element);
105 *(params->os) << v->estimate().x() << " " << v->estimate().y() << " "
106 << v->estimate().z() << " " << std::endl;
107 return this;
108}
109
110} // namespace g2o
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_)
Vertex for a tracked point in space.
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
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)
Property< float > FloatProperty
Definition property.h:150
#define LANDMARK_VERTEX_COLOR