Main MRPT website > C++ reference for MRPT 1.9.9
graph_slam_levmarq_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
11 
12 #include <gtest/gtest.h>
14 
15 using namespace mrpt;
16 using namespace mrpt::random;
17 using namespace mrpt::poses;
18 using namespace mrpt::graphs;
19 using namespace mrpt::math;
20 using namespace std;
21 
22 template <class my_graph_t>
23 class GraphSlamLevMarqTester : public GraphSlamLevMarqTest<my_graph_t>,
24  public ::testing::Test
25 {
26  protected:
27  virtual void SetUp() {}
28  virtual void TearDown() {}
30  {
31  // This is the initial input graph (make a copy for later use):
32  my_graph_t graph;
34 
35  const my_graph_t graph_initial = graph;
36 
37  // ----------------------------
38  // Run graph slam:
39  // ----------------------------
41  // params["verbose"] = 1;
42  // params["profiler"] = 1;
43  params["max_iterations"] = 1000;
44 
46 
48  graph, levmarq_info, nullptr, params);
49 
50  // Do some basic checks on the results:
51  EXPECT_GE(levmarq_info.num_iters, 10U);
52  EXPECT_LE(levmarq_info.final_total_sq_error, 1e-2);
53 
54  } // end test_ring_path
55 
57  {
58  my_graph_t graph;
60 
61  // binary dump:
63  auto arch = mrpt::serialization::archiveFrom(mem);
64  arch << graph;
65 
66  {
67  my_graph_t read_graph;
68  mem.Seek(0);
69  arch >> read_graph;
70 
71  EXPECT_EQ(read_graph.edges.size(), graph.edges.size());
72  EXPECT_EQ(read_graph.nodes.size(), graph.nodes.size());
73 
74  // Also check that the edge values are OK:
75  typename my_graph_t::const_iterator it1, it2;
76  for (it1 = read_graph.edges.begin(), it2 = graph.edges.begin();
77  it1 != read_graph.edges.end(); ++it1, ++it2)
78  {
79  EXPECT_EQ(it1->first, it2->first);
80  EXPECT_NEAR(
81  0, (it1->second.getPoseMean().getAsVectorVal() -
82  it2->second.getPoseMean().getAsVectorVal())
83  .array()
84  .abs()
85  .sum(),
86  1e-9);
87  }
88  }
89  }
90 };
91 
94 
95 TEST_F(GraphSlamLevMarqTester2D, OptimizeSampleRingPath)
96 {
97  for (int seed = 1; seed < 5; seed++)
98  {
100  test_ring_path();
101  }
102 }
103 TEST_F(GraphSlamLevMarqTester2D, BinarySerialization)
104 {
106  test_graph_bin_serialization();
107 }
108 
109 TEST_F(GraphSlamLevMarqTester3D, OptimizeSampleRingPath)
110 {
111  for (int seed = 1; seed < 5; seed++)
112  {
114  test_ring_path();
115  }
116 }
117 TEST_F(GraphSlamLevMarqTester3D, BinarySerialization)
118 {
120  test_graph_bin_serialization();
121 }
A namespace of pseudo-random numbers generators of diferent distributions.
void optimize_graph_spa_levmarq(GRAPH_T &graph, TResultInfoSpaLevMarq &out_info, const std::set< mrpt::graphs::TNodeID > *in_nodes_to_optimize=nullptr, const mrpt::system::TParametersDouble &extra_params=mrpt::system::TParametersDouble(), typename graphslam_traits< GRAPH_T >::TFunctorFeedback functor_feedback=typename graphslam_traits< GRAPH_T >::TFunctorFeedback())
Optimize a graph of pose constraints using the Sparse Pose Adjustment (SPA) sparse representation and...
Definition: levmarq.h:80
Abstract graph and tree data structures, plus generic graph algorithms.
void randomize(const uint32_t seed)
Initialize the PRNG from the given random seed.
size_t num_iters
The number of LM iterations executed.
STL namespace.
TEST_F(GraphSlamLevMarqTester2D, OptimizeSampleRingPath)
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT&#39;s CStream, std::istream, std::ostream, std::stringstream
Definition: CArchive.h:561
This base provides a set of functions for maths stuff.
This CStream derived class allow using a memory buffer as a CStream.
uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) override
Introduces a pure virtual method for moving to a specified position in the streamed resource...
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Output information for mrpt::graphslam::optimize_graph_spa_levmarq()
static void create_ring_path(my_graph_t &graph, size_t N_VERTEX=50, double DIST_THRES=7, double NODES_XY_MAX=20)
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
GLenum const GLfloat * params
Definition: glext.h:3534
const Scalar * const_iterator
Definition: eigen_plugins.h:27
double final_total_sq_error
The sum of all the squared errors for every constraint involved in the problem.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019