n-Dimensional Fast Methods  0.7
 All Classes Functions Variables Typedefs Pages
test_fm2.cpp
1 /* Runs different versions of FM2 and FM2* over grid map generated from a text file. */
2 
3 #include <iostream>
4 #include <array>
5 
6 #include <fast_methods/ndgridmap/fmcell.h>
7 #include <fast_methods/ndgridmap/ndgridmap.hpp>
8 #include <fast_methods/console/console.h>
9 
10 #include <fast_methods/fm2/fm2.hpp>
11 #include <fast_methods/fm2/fm2star.hpp>
12 #include <fast_methods/datastructures/fmfibheap.hpp>
13 #include <fast_methods/datastructures/fmpriorityqueue.hpp>
14 
15 #include <fast_methods/io/maploader.hpp>
16 #include <fast_methods/io/gridplotter.hpp>
17 #include <fast_methods/io/gridwriter.hpp>
18 
19 using namespace std;
20 using namespace std::chrono;
21 
22 int main(int argc, const char ** argv)
23 {
24  console::info("Parsing input arguments.");
25  string filename;
26  if (argc > 2)
27  console::parseArguments(argc, argv, "-map", filename);
28  else {
29  console::info("No enough arguments given. Use as ./test_fm2 -map path_to_file.txt");
30  exit(1);
31  }
32 
33  // A bit of shorthand.
34  constexpr unsigned int ndims2 = 2; // Setting two dimensions.
35  typedef nDGridMap<FMCell, ndims2> FMGrid2D;
36  typedef typename std::vector< std::array<double, ndims2> > Path2D; // A bit of short-hand.
37 
38  // Loading grid.
39  FMGrid2D grid_fm2;
40 
41  // Solvers declaration.
42  std::vector<Solver<FMGrid2D>*> solvers;
43  solvers.push_back(new FM2<FMGrid2D>("FM2_Dary"));
44  solvers.push_back(new FM2<FMGrid2D, FMFibHeap<FMCell> >("FM2_Fib"));
45  solvers.push_back(new FM2<FMGrid2D, FMPriorityQueue<FMCell> >("FM2_SFMM"));
46  solvers.push_back(new FM2Star<FMGrid2D>("FM2*_Dary_Dist", DISTANCE));
47  solvers.push_back(new FM2Star<FMGrid2D>("FM2*_Dary_Time"));
48  solvers.push_back(new FM2Star<FMGrid2D, FMFibHeap<FMCell> >("FM2*_Fib_Time"));
49  solvers.push_back(new FM2Star<FMGrid2D, FMFibHeap<FMCell> >("FM2*_Fib_Dist", DISTANCE));
50  solvers.push_back(new FM2Star<FMGrid2D, FMPriorityQueue<FMCell> >("FM2*_SFMM_Time"));
51  solvers.push_back(new FM2Star<FMGrid2D, FMPriorityQueue<FMCell> >("FM2*_SFMM_Dist", DISTANCE));
52 
53  // Executing every solver individually over the same grid.
54  for (Solver<FMGrid2D>* s :solvers)
55  {
56  // For FM2 and its variations, it is better to completely reinitialize the grid.
57  //if(!MapLoader::loadMapFromText(filename.c_str(), grid_fm2)) // Loading from text file.
58  //exit(1);
59  MapLoader::loadMapFromImg(filename.c_str(), grid_fm2); // Loading from image.
60  s->setEnvironment(&grid_fm2);
61  s->setInitialAndGoalPoints({30, 20}, {375, 280}); // Init and goal points directly set.
62  s->compute();
63  cout << "\tElapsed "<< s->getName() <<" time: " << s->getTime() << " ms" << '\n';
64 
65  Path2D path;
66  vector<double> path_vels;
67  s->as<FM2<FMGrid2D>>()->computePath(&path, &path_vels);
68  GridPlotter::plotArrivalTimesPath(grid_fm2, path);
69  }
70 
71  // Preventing memory leaks.
72  for (auto & s : solvers)
73  delete s;
74 
75  return 0;
76 }
Wrap for the Boost Priority Queue class to be used in the FM algorithms. Ready to be used with FMCell...
static int parseArguments(int argc, const char **argv, const char *str, std::string &val)
Implements the Fast Marching Square Star (FM2*) planning algorithm.
Definition: fm2star.hpp:51
Templated class which represents a n-dimensional grid map. Its cells are assumed to be cubic...
Definition: ndgridmap.hpp:47
static void info(const std::string &val)
static void plotArrivalTimesPath(nDGridMap< T, ndims > &grid, const Path2D &path, std::string name="")
Plots the values map of a given grid. It is based on the nDGridMap::getValue(). This function has to ...
Abstract class that serves as interface for the actual solvers implemented. It requires (at least) th...
Definition: solver.hpp:40
static void loadMapFromImg(const char *filename, nDGridMap< T, ndims > &grid)
Loads the initial binary map for a given grid. It is based on the nDGridMap::setOccupancy() which has...
Definition: maploader.hpp:51
Implements the Fast Marching Square (FM2) planning algorithm.
Definition: fm2.hpp:49