g2o
slam_context_interface.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 "slam_context_interface.h"
28 
31 
32 #include <iostream>
33 using namespace std;
34 
35 namespace SlamParser {
36 
37  SlamContextInterface::SlamContextInterface(AbstractSlamInterface* slam) :
38  SlamContext(),
39  _slam(slam)
40  {
41  }
42 
44  {
45  }
46 
48  {
49  if (! _slam) {
50  return true;
51  }
52  switch (commandNode->commandType()) {
53  case CT_ADD_NODE:
54  {
55  AddNode* c = static_cast<AddNode*>(commandNode);
56  return _slam->addNode(c->tag(), c->id(), c->dimension(), c->values());
57  }
58  case CT_ADD_EDGE:
59  {
60  AddEdge* c = static_cast<AddEdge*>(commandNode);
61  return _slam->addEdge(c->tag(), c->id(), c->dimension(), c->id1(), c->id2(), c->values(), c->information());
62  }
63  case CT_SOLVE_STATE:
64  {
65  //SolveState* c = static_cast<SolveState*>(commandNode);
66  return _slam->solveState();
67  }
68  case CT_QUERY_STATE:
69  {
70  QueryState* c = static_cast<QueryState*>(commandNode);
71  return _slam->queryState(c->ids());
72  }
73  case CT_FIX:
74  {
75  FixNode* c = static_cast<FixNode*>(commandNode);
76  return _slam->fixNode(c->ids());
77  }
78  }
79  cerr << "SlamContextInterface::process: Unknown command type" << endl;
80  return false;
81  }
82 
83 } // end namespace
virtual bool fixNode(const std::vector< int > &nodes)=0
int id1() const
Definition: commands.h:86
int id() const
Definition: commands.h:84
virtual bool queryState(const std::vector< int > &nodes)=0
const std::vector< double > & values()
Definition: commands.h:88
CommandType commandType() const
Definition: commands.h:49
int id() const
Definition: commands.h:65
interface for communicating with the SLAM algorithm
const std::vector< double > & values()
Definition: commands.h:67
bool process(CommandNode *commandNode)
const std::vector< int > & ids()
Definition: commands.h:116
const std::string & tag() const
Definition: commands.h:50
const std::vector< int > & ids()
Definition: commands.h:128
const std::vector< double > & information()
Definition: commands.h:89
virtual bool addNode(const std::string &tag, int id, int dimension, const std::vector< double > &values)=0
virtual bool addEdge(const std::string &tag, int id, int dimension, int v1, int v2, const std::vector< double > &measurement, const std::vector< double > &information)=0
int dimension() const
Definition: commands.h:66
int dimension() const
Definition: commands.h:85
int id2() const
Definition: commands.h:87