g2o
Loading...
Searching...
No Matches
vertex_segment2d.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_segment2d.h"
28
29#ifdef G2O_HAVE_OPENGL
31#endif
32
33#include <typeinfo>
34
35#include "g2o/stuff/macros.h"
36
37namespace g2o {
38
42
43bool VertexSegment2D::read(std::istream& is) {
45}
46
47bool VertexSegment2D::write(std::ostream& os) const {
48 return internal::writeVector(os, estimate());
49}
50
53
57 if (typeid(*element).name() != _typeName) return nullptr;
58
60 static_cast<WriteGnuplotAction::Parameters*>(params_);
61 if (!params->os) {
62 return nullptr;
63 }
64
65 VertexSegment2D* v = static_cast<VertexSegment2D*>(element);
66 *(params->os) << v->estimateP1().x() << " " << v->estimateP1().y()
67 << std::endl;
68 *(params->os) << v->estimateP2().x() << " " << v->estimateP2().y()
69 << std::endl;
70 *(params->os) << std::endl;
71 return this;
72}
73
74#ifdef G2O_HAVE_OPENGL
75VertexSegment2DDrawAction::VertexSegment2DDrawAction()
76 : DrawAction(typeid(VertexSegment2D).name()), _pointSize(nullptr) {}
77
78bool VertexSegment2DDrawAction::refreshPropertyPtrs(
79 HyperGraphElementAction::Parameters* params_) {
80 if (!DrawAction::refreshPropertyPtrs(params_)) return false;
81 if (_previousParams) {
82 _pointSize = _previousParams->makeProperty<FloatProperty>(
83 _typeName + "::POINT_SIZE", 1.);
84 } else {
85 _pointSize = 0;
86 }
87 return true;
88}
89
90HyperGraphElementAction* VertexSegment2DDrawAction::operator()(
91 HyperGraph::HyperGraphElement* element,
92 HyperGraphElementAction::Parameters* params_) {
93 if (typeid(*element).name() != _typeName) return nullptr;
94
95 refreshPropertyPtrs(params_);
96 if (!_previousParams) return this;
97
98 if (_show && !_show->value()) return this;
99
100 VertexSegment2D* that = static_cast<VertexSegment2D*>(element);
101 glColor3f(0.8f, 0.5f, 0.3f);
102 if (_pointSize) {
103 glPointSize(_pointSize->value());
104 }
105 glBegin(GL_LINES);
106 glVertex3f((float)that->estimateP1().x(), (float)that->estimateP1().y(), 0.f);
107 glVertex3f((float)that->estimateP2().x(), (float)that->estimateP2().y(), 0.f);
108 glEnd();
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
Vector2 estimateP1() const
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
Vector2 estimateP2() const
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
Property< float > FloatProperty
Definition property.h:150