53 #include <fast_methods/fm/eikonalsolver.hpp>
55 #include <fast_methods/ndgridmap/fmcell.h>
56 #include <fast_methods/datastructures/fmdaryheap.hpp>
58 #include <fast_methods/ndgridmap/ndgridmap.hpp>
59 #include <fast_methods/console/console.h>
62 enum HeurStrategy {NOHEUR = 0, TIME, DISTANCE};
64 template <
class gr
id_t,
class heap_t = FMDaryHeap<FMCell> >
class FMM :
public EikonalSolver<grid_t> {
85 console::warning(
"FMM/SFMM: Heuristics set with no goal point. Deactivating heuristics.");
97 unsigned int n_neighs = 0;
98 bool stopWavePropagation =
false;
102 grid_->getCell(i).setArrivalTime(0);
112 unsigned int idxMin = 0;
116 grid_->getCell(idxMin).setState(FMState::FROZEN);
117 for (
unsigned int s = 0; s < n_neighs; ++s) {
119 if ((
grid_->getCell(j).getState() == FMState::FROZEN) ||
grid_->getCell(j).isOccupied())
131 if (
grid_->getCell(j).getState() == FMState::NARROW) {
133 grid_->getCell(j).setArrivalTime(new_arrival_time);
138 grid_->getCell(j).setState(FMState::NARROW);
139 grid_->getCell(j).setArrivalTime(new_arrival_time);
146 stopWavePropagation =
true;
185 std::array <unsigned int, grid_t::getNDims()> coords;
188 for (
size_t i = 0; i <
grid_->size(); ++i)
191 grid_->idx2coord(i, coords);
193 for (
size_t j = 0; j < coords.size(); ++j)
194 dist += coords[j]*coords[j];
204 (
const unsigned int idx) {
205 std::array <unsigned int, grid_t::getNDims()> position, distance;
206 grid_->idx2coord(idx, position);
208 for (
unsigned int i = 0; i < grid_t::getNDims(); ++i)
211 unsigned int idx_dist;
212 grid_->coord2idx(distance, idx_dist);
217 virtual void printRunInfo
220 std::cout <<
'\t' <<
name_ <<
'\n'
222 <<
'\t' <<
"Elapsed time: " <<
time_ <<
" ms\n";
Abstract class that serves as interface for the actual EikonalSolvers implemented. It requires (at least) the computeInternal method to be implemented,.
virtual void computeInternal()
Actual method that implements FMM.
heap_t narrow_band_
Instance of the heap used.
double time_
Time elapsed by the compute method.
std::array< unsigned int, grid_t::getNDims()> heur_coord_
Goal coord, goal of the second wave propagation (actually the initial point of the path)...
virtual void setup()
Checks that the solver is ready to run. Sets the grid unclean.
bool precomputed_
Flag to indicate if distances_ is already computed.
std::array< unsigned int, 2 *grid_t::getNDims()> neighbors_
Auxiliar array which stores the neighbor of each iteration of the computeFM() function.
virtual void clear()
Clears the solver, it is not recommended to be used out of the destructor.
virtual double solveEikonal(const int &idx)
Solves nD Eikonal equation for cell idx. If heuristics are activated, it will add the estimated trave...
FMM(HeurStrategy h=NOHEUR)
static unsigned int absUI(int a)
An user-implemented absolute value function for integer values.
grid_t * grid_
Grid container.
static void info(const std::string &val)
virtual void precomputeDistances()
Computes euclidean distance between goal and rest of cells.
std::vector< unsigned int > init_points_
Initial index.
std::string name_
Solver name.
virtual void setup()
Executes EikonalSolver setup and sets maximum size for the narrow band.
virtual double getPrecomputedDistance(const unsigned int idx)
Extracts the euclidean distance calculated from precomputeDistances function distance between two pos...
void setHeuristics(HeurStrategy h)
Set heuristics flag. True is activated. It will precompute distances if not done already.
static bool isTimeBetterThan(double t1, double t2)
Returns true if t1 is at least epsilon-lower than t2, provides robust comparions for doubles...
HeurStrategy heurStrategy_
Flag to activate heuristics and corresponding strategy.
virtual void reset()
Clears temporal data, so it is ready to run again.
unsigned int goal_idx_
Goal index.
static void warning(const std::string &val)
std::vector< double > distances_
Stores the precomputed heuristic distances.
HeurStrategy getHeuristics() const
Returns heuristics flag.
Implements the Fast Marching Method (FMM).
virtual void reset()
Clears temporal data, so it is ready to run again.