g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
types
slam2d_addons
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
30
#include "
g2o/stuff/opengl_wrapper.h
"
31
#endif
32
33
#include <typeinfo>
34
35
#include "
g2o/stuff/macros.h
"
36
37
namespace
g2o
{
38
39
VertexSegment2D::VertexSegment2D
() :
BaseVertex
<4,
Vector4
>() {
40
_estimate
.setZero();
41
}
42
43
bool
VertexSegment2D::read
(std::istream& is) {
44
return
internal::readVector
(is,
_estimate
);
45
}
46
47
bool
VertexSegment2D::write
(std::ostream& os)
const
{
48
return
internal::writeVector
(os,
estimate
());
49
}
50
51
VertexSegment2DWriteGnuplotAction::VertexSegment2DWriteGnuplotAction
()
52
:
WriteGnuplotAction
(typeid(
VertexSegment2D
).
name
()) {}
53
54
HyperGraphElementAction
*
VertexSegment2DWriteGnuplotAction::operator()
(
55
HyperGraph::HyperGraphElement
* element,
56
HyperGraphElementAction::Parameters
* params_) {
57
if
(
typeid
(*element).name() !=
_typeName
)
return
nullptr
;
58
59
WriteGnuplotAction::Parameters
* params =
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
75
VertexSegment2DDrawAction::VertexSegment2DDrawAction()
76
:
DrawAction
(typeid(
VertexSegment2D
).name()), _pointSize(nullptr) {}
77
78
bool
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
90
HyperGraphElementAction
* 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
g2o::BaseVertex< 4, Vector4 >::BaseVertex
BaseVertex()
Definition
base_vertex.h:29
g2o::BaseVertex< 4, Vector4 >::estimate
const EstimateType & estimate() const
Definition
base_vertex.h:127
g2o::BaseVertex< 4, Vector4 >::_estimate
EstimateType _estimate
Definition
base_vertex.h:137
g2o::DrawAction
draw actions
Definition
hyper_graph_action.h:201
g2o::DrawAction::refreshPropertyPtrs
virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)
Definition
hyper_graph_action.cpp:221
g2o::HyperGraphElementAction
Abstract action that operates on a graph entity.
Definition
hyper_graph_action.h:74
g2o::HyperGraphElementAction::name
const std::string & name() const
returns the name of an action, e.g "draw"
Definition
hyper_graph_action.h:101
g2o::HyperGraphElementAction::_typeName
std::string _typeName
Definition
hyper_graph_action.h:107
g2o::VertexSegment2DWriteGnuplotAction::VertexSegment2DWriteGnuplotAction
VertexSegment2DWriteGnuplotAction()
Definition
vertex_segment2d.cpp:51
g2o::VertexSegment2DWriteGnuplotAction::operator()
virtual HyperGraphElementAction * operator()(HyperGraph::HyperGraphElement *element, HyperGraphElementAction::Parameters *params_)
Definition
vertex_segment2d.cpp:54
g2o::VertexSegment2D
Definition
vertex_segment2d.h:40
g2o::VertexSegment2D::VertexSegment2D
VertexSegment2D()
Definition
vertex_segment2d.cpp:39
g2o::VertexSegment2D::write
virtual bool write(std::ostream &os) const
write the vertex to a stream
Definition
vertex_segment2d.cpp:47
g2o::VertexSegment2D::estimateP1
Vector2 estimateP1() const
Definition
vertex_segment2d.h:45
g2o::VertexSegment2D::read
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
Definition
vertex_segment2d.cpp:43
g2o::VertexSegment2D::estimateP2
Vector2 estimateP2() const
Definition
vertex_segment2d.h:48
g2o::WriteGnuplotAction::WriteGnuplotAction
WriteGnuplotAction(const std::string &typeName_)
Definition
hyper_graph_action.cpp:206
macros.h
g2o::internal::writeVector
bool writeVector(std::ostream &os, const Eigen::DenseBase< Derived > &b)
Definition
io_helper.h:36
g2o::internal::readVector
bool readVector(std::istream &is, Eigen::DenseBase< Derived > &b)
Definition
io_helper.h:42
g2o
Definition
dl_wrapper.cpp:55
g2o::Vector4
VectorN< 4 > Vector4
Definition
eigen_types.h:52
g2o::FloatProperty
Property< float > FloatProperty
Definition
property.h:150
opengl_wrapper.h
g2o::HyperGraphElementAction::Parameters
Definition
hyper_graph_action.h:76
g2o::HyperGraph::HyperGraphElement
Definition
hyper_graph.h:80
g2o::WriteGnuplotAction::Parameters
Definition
hyper_graph_action.h:191
g2o::WriteGnuplotAction::Parameters::os
std::ostream * os
Definition
hyper_graph_action.h:192
vertex_segment2d.h
Generated on
for g2o by
1.17.0