g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
apps
g2o_simulator
simulator.cpp
Go to the documentation of this file.
1
// g2o - General Graph Optimization
2
// Copyright (C) 2011 G. Grisetti, R. Kuemmerle, 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 "
simulator.h
"
28
29
#include <cassert>
30
#include <iostream>
31
namespace
g2o
{
32
using namespace
std;
33
34
// BaseWorldObject
35
BaseWorldObject::~BaseWorldObject
() {}
36
OptimizableGraph
*
BaseWorldObject::graph
() {
37
if
(
_world
)
return
_world
->graph();
38
return
0;
39
}
40
41
void
BaseWorldObject::setVertex
(
OptimizableGraph::Vertex
* vertex_) {
42
_vertex
= vertex_;
43
}
44
45
// BaseRobot
46
OptimizableGraph
*
BaseRobot::graph
()
const
{
47
if
(
_world
)
return
_world
->graph();
48
return
0;
49
}
50
51
bool
BaseRobot::addSensor
(
BaseSensor
* sensor) {
52
assert(
graph
());
53
std::pair<std::set<BaseSensor*>::iterator,
bool
> result =
54
_sensors
.insert(sensor);
55
if
(result.second) {
56
sensor->
setRobot
(
this
);
57
sensor->
addParameters
();
58
}
59
return
result.second;
60
}
61
62
void
BaseRobot::sense
() {
63
for
(std::set<BaseSensor*>::iterator it =
_sensors
.begin();
64
it !=
_sensors
.end(); ++it) {
65
BaseSensor
* s = *it;
66
s->
sense
();
67
}
68
}
69
70
// Sensor
71
World
*
BaseSensor::world
()
const
{
72
if
(!
_robot
)
return
0;
73
return
_robot
->world();
74
}
75
76
OptimizableGraph
*
BaseSensor::graph
()
const
{
77
if
(!
_robot
)
return
0;
78
return
_robot
->graph();
79
}
80
81
// World
82
bool
World::addRobot
(
BaseRobot
* robot) {
83
std::pair<std::set<BaseRobot*>::iterator,
bool
> result =
84
_robots
.insert(robot);
85
if
(result.second) {
86
robot->
setWorld
(
this
);
87
}
88
return
result.second;
89
}
90
91
bool
World::addWorldObject
(
BaseWorldObject
*
object
) {
92
std::pair<std::set<BaseWorldObject*>::iterator,
bool
> result =
93
_objects
.insert(
object
);
94
if
(result.second) {
95
object
->setWorld(
this
);
96
}
97
if
(
graph
() && object->
vertex
()) {
98
object
->vertex()->setId(
_runningId
++);
99
graph
()->
addVertex
(object->
vertex
());
100
}
101
return
result.second;
102
}
103
104
bool
World::addParameter
(
Parameter
* param) {
105
if
(!
graph
())
return
false
;
106
param->
setId
(
_paramId
);
107
graph
()->
addParameter
(param);
108
_paramId
++;
109
return
true
;
110
}
111
112
}
// namespace g2o
simulator.h
g2o::BaseRobot
Definition
simulator.h:83
g2o::BaseRobot::sense
virtual void sense()
Definition
simulator.cpp:62
g2o::BaseRobot::setWorld
void setWorld(World *world_)
Definition
simulator.h:89
g2o::BaseRobot::_world
World * _world
Definition
simulator.h:98
g2o::BaseRobot::addSensor
bool addSensor(BaseSensor *sensor)
Definition
simulator.cpp:51
g2o::BaseRobot::graph
OptimizableGraph * graph() const
Definition
simulator.cpp:46
g2o::BaseRobot::_sensors
std::set< BaseSensor * > _sensors
Definition
simulator.h:99
g2o::BaseSensor
Definition
simulator.h:159
g2o::BaseSensor::_robot
BaseRobot * _robot
Definition
simulator.h:173
g2o::BaseSensor::graph
OptimizableGraph * graph() const
Definition
simulator.cpp:76
g2o::BaseSensor::sense
virtual void sense()=0
g2o::BaseSensor::world
World * world() const
Definition
simulator.cpp:71
g2o::BaseSensor::addParameters
virtual void addParameters()
Definition
simulator.h:168
g2o::BaseSensor::setRobot
void setRobot(BaseRobot *robot_)
Definition
simulator.h:163
g2o::BaseWorldObject
Definition
simulator.h:44
g2o::BaseWorldObject::graph
OptimizableGraph * graph()
Definition
simulator.cpp:36
g2o::BaseWorldObject::setVertex
virtual void setVertex(OptimizableGraph::Vertex *vertex_)
Definition
simulator.cpp:41
g2o::BaseWorldObject::_world
World * _world
Definition
simulator.h:60
g2o::BaseWorldObject::_vertex
OptimizableGraph::Vertex * _vertex
Definition
simulator.h:59
g2o::BaseWorldObject::~BaseWorldObject
virtual ~BaseWorldObject()
Definition
simulator.cpp:35
g2o::BaseWorldObject::vertex
OptimizableGraph::Vertex * vertex()
Definition
simulator.h:54
g2o::OptimizableGraph::Vertex
A general case Vertex for optimization.
Definition
optimizable_graph.h:108
g2o::Parameter
Definition
parameter.h:36
g2o::Parameter::setId
void setId(int id_)
Definition
parameter.cpp:33
g2o::World
Definition
simulator.h:103
g2o::World::_objects
std::set< BaseWorldObject * > _objects
Definition
simulator.h:119
g2o::World::_paramId
int _paramId
Definition
simulator.h:123
g2o::World::addRobot
bool addRobot(BaseRobot *robot)
Definition
simulator.cpp:82
g2o::World::_robots
std::set< BaseRobot * > _robots
Definition
simulator.h:120
g2o::World::addParameter
bool addParameter(Parameter *p)
Definition
simulator.cpp:104
g2o::World::_runningId
int _runningId
Definition
simulator.h:122
g2o::World::addWorldObject
bool addWorldObject(BaseWorldObject *worldObject)
Definition
simulator.cpp:91
g2o::World::graph
OptimizableGraph * graph()
Definition
simulator.h:110
g2o
Definition
dl_wrapper.cpp:55
g2o::OptimizableGraph
Definition
optimizable_graph.h:62
g2o::OptimizableGraph::addParameter
bool addParameter(Parameter *p)
Definition
optimizable_graph.h:715
g2o::OptimizableGraph::addVertex
virtual bool addVertex(HyperGraph::Vertex *v, Data *userData)
Definition
optimizable_graph.cpp:212
Generated on
for g2o by
1.17.0