9 #include <fast_methods/ndgridmap/fmcell.h>
10 #include <fast_methods/ndgridmap/ndgridmap.hpp>
11 #include <fast_methods/console/console.h>
12 #include <fast_methods/fm/fmm.hpp>
13 #include <fast_methods/fm2/fm2.hpp>
14 #include <fast_methods/fm2/fm2star.hpp>
15 #include <fast_methods/datastructures/fmfibheap.hpp>
16 #include <fast_methods/datastructures/fmpriorityqueue.hpp>
17 #include <fast_methods/datastructures/fmdaryheap.hpp>
18 #include <fast_methods/io/maploader.hpp>
19 #include <fast_methods/io/gridplotter.hpp>
20 #include <fast_methods/io/gridwriter.hpp>
21 #include <fast_methods/io/gridpoints.hpp>
22 #include <fast_methods/gradientdescent/gradientdescent.hpp>
25 using namespace std::chrono;
27 int main(
int argc,
const char ** argv)
29 constexpr
unsigned int ndims = 2;
30 constexpr
unsigned int ndims3 = 3;
32 time_point<std::chrono::steady_clock> start, end;
36 string filename1, filename2, filename_vels;
41 console::info(
"Creating grid from image and testing Fast Marching Method..");
45 std::array<unsigned int, ndims> coords_init, coords_goal;
48 vector<unsigned int> init_points;
49 unsigned int idx, goal;
51 init_points.push_back(idx);
58 cout <<
"\tElapsed FM time: " << fmm.getTime() <<
" ms" << endl;
59 console::info(
"Plotting the results and saving into test_fm.txt");
64 typedef typename std::vector< std::array<double, ndims> > Path;
67 std::vector <double> path_velocity;
69 start = steady_clock::now();
71 grad.
apply(grid,goal,path,path_velocity);
72 end = steady_clock::now();
73 time_elapsed = duration_cast<milliseconds>(end-start).count();
74 cout <<
"\tElapsed gradient descent time: " << time_elapsed <<
" ms" << endl;
80 path_velocity.clear();
88 fm2.setInitialAndGoalPoints(init_points, goal);
90 cout <<
"\tElapsed FM2 time: " << fm2.getTime() <<
" ms" << endl;
91 start = steady_clock::now();
92 fm2.computePath(&pathFM2, &path_velocity);
93 end = steady_clock::now();
94 time_elapsed = duration_cast<milliseconds>(end-start).count();
95 cout <<
"\tElapsed gradient descent time: " << time_elapsed <<
" ms" << endl;
106 cout <<
"\tElapsed FM2* time: " << fm2star.getTime() <<
" ms" << endl;
107 start = steady_clock::now();
109 end = steady_clock::now();
110 time_elapsed = duration_cast<milliseconds>(end-start).count();
111 cout <<
"\tElapsed gradient descent time: " << time_elapsed <<
" ms" << endl;
114 std::vector <Path> paths;
115 paths.push_back(pathFM2);
116 paths.push_back(pathFM2star);
128 init_points.push_back(80000);
132 cout <<
"\tElapsed FM time: " << fmm_vels.getTime() <<
" ms" << endl;
140 grid3.coord2idx(std::array<unsigned int,ndims3>{50,50,25},idx);
141 init_points.push_back(idx);
142 grid3.coord2idx(std::array<unsigned int, ndims3> {20, 10, 45}, goal);
148 cout <<
"\tElapsed FM time: " << fmm3.getTime() <<
" ms" << endl;
154 typedef typename std::vector< std::array<double, ndims3> > Path3D;
156 grid3.coord2idx(std::array<unsigned int, ndims3> {20, 10, 45}, goal);
159 start = steady_clock::now();
161 grad3D.
apply(grid3,goal,path3D,path_velocity);
162 end = steady_clock::now();
163 time_elapsed = duration_cast<milliseconds>(end-start).count();
164 cout <<
"\tElapsed gradient descent time: " << time_elapsed <<
" ms" << endl;
static void savePathVelocity(const char *filename, nDGridMap< T, ndims > &grid, std::vector< std::array< double, ndims > > &path, std::vector< double > path_velocity)
Saves the 2D path with velocity values in an ASCII file with the following format: ...
virtual void setInitialAndGoalPoints(const std::vector< unsigned int > &init_points, unsigned int goal_idx)
Overloaded from FM2. In this case the precomputeDistances() method is called.
static void plotOccupancyMap(nDGridMap< T, ndims > &grid, std::string name="")
Plots the occupancy map of a given grid. It is based on the nDGridMap::getOccupancy(), This function has to be overloaded if another occupancy type is being used.
virtual void setEnvironment(grid_t *g)
Sets and cleans the grid in which operations will be performed.
static void saveGridValues(const char *filename, nDGridMap< T, ndims > &grid)
Saves grid values in ASCII format into the specified file.
static int parseArguments(int argc, const char **argv, const char *str, std::string &val)
static void selectMapPoints(nDGridMap< T, ndims > &grid, std::array< unsigned int, ndims > &coords_init, std::array< unsigned int, ndims > &coords_goal, const bool flipY=1)
Plots the binary map of a given grid and allows the user to select a couple of points (start and goal...
Implements gradient descent to be used together with nDGridMap and FMCell or derived types...
virtual void setEnvironment(grid_t *g)
Sets the environment to run the solver and sets the sources for the velocities map computation...
void compute()
Computes the distances map. Will call setup() if not done already.
Implements the Fast Marching Square Star (FM2*) planning algorithm.
Templated class which represents a n-dimensional grid map. Its cells are assumed to be cubic...
virtual void computePath(path_t *p, std::vector< double > *path_velocity, double step=1)
Encapsulates the path extraction.
static void info(const std::string &val)
static void plotOccupancyPath(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 ...
virtual void setInitialAndGoalPoints(const std::vector< unsigned int > &init_points, unsigned int goal_idx)
Sets the initial and goal points by the indices of the grid.
static void plotMapPath(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 ...
void clear()
Deallocates heap memory.
void clear()
Erases the content of the grid. Must be resized later.
virtual void setInitialPoints(const std::vector< unsigned int > &init_points)
Sets the initial points by the indices of the grid.
static void apply(grid_t &grid, unsigned int &idx, Path &path, std::vector< double > &path_velocity, double step=1)
Computes the path over grid from idx to a minimum and extracts the velocity in every point...
static void plotArrivalTimes(nDGridMap< T, ndims > &grid, std::string name="")
Plots the values map of a given grid. It is based on the nDGridMap::getValue(). This function has to ...
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...
Implements the Fast Marching Square (FM2) planning algorithm.
static void savePath(const char *filename, nDGridMap< T, ndims > &grid, std::vector< std::array< double, ndims > > &path)
Saves the 2D path in an ASCII file with the following format:
static void plotMapPaths(nDGridMap< T, ndims > &grid, const Paths2D &paths, std::string name="")
Plots the values map of a given grid. It is based on the nDGridMap::getValue(). This function has to ...
unsigned int coord2idx(const std::array< unsigned int, ndims > &coords, unsigned int &idx)
Transforms from coordinates to index.
Implements the Fast Marching Method (FMM).