n-Dimensional Fast Methods  0.7
 All Classes Functions Variables Typedefs Pages
ufmm.hpp
1 
31 #ifndef UFMM_HPP_
32 #define UFMM_HPP_
33 
34 #include <fast_methods/fm/eikonalsolver.hpp>
35 #include <fast_methods/datastructures/fmuntidyqueue.hpp>
36 
37 template <class grid_t, class cell_t = FMCell> class UFMM : public EikonalSolver<grid_t> {
38 
39  public:
40  UFMM
41  (unsigned s = 1000, double inc = 2) : EikonalSolver<grid_t>("UFMM"), heap_s_(s), heap_inc_(inc) {
43  }
44  UFMM
45  (const char * name, unsigned s = 1000, double inc = 2) : EikonalSolver<grid_t>(name), heap_s_(s), heap_inc_(inc) {
47  }
48 
49  virtual ~UFMM() { clear(); }
50 
52  virtual void computeInternal
53  () {
54  if (!setup_)
55  setup();
56 
57  unsigned int j= 0;
58  unsigned int n_neighs = 0;
59  bool stopWavePropagation = false;
60 
61  // Algorithm initialization
62  for (unsigned int &i : init_points_) { // For each initial point
63  grid_->getCell(i).setArrivalTime(0);
64  narrow_band_->push( &(grid_->getCell(i)) );
65  }
66 
67  // Main loop.
68  unsigned int idxMin = 0;
69  while (!stopWavePropagation && !narrow_band_->empty()) {
70  idxMin = narrow_band_->topIdx(); // pop() has to be called after pushing in this case (because
71  // of the untidy queue implementation.
72  grid_->getCell(idxMin).setState(FMState::FROZEN);
73  n_neighs = grid_->getNeighbors(idxMin, neighbors_);
74  for (unsigned int s = 0; s < n_neighs; ++s) { // For each neighbor.
75  j = neighbors_[s];
76  if ( (grid_->getCell(j).getState() == FMState::FROZEN) || grid_->getCell(j).isOccupied())
77  continue;
78  else {
79  double new_arrival_time = solveEikonal(j);
80  if (grid_->getCell(j).getState() == FMState::NARROW) { // Updating narrow band if necessary.
81  if (utils::isTimeBetterThan(new_arrival_time, grid_->getCell(j).getArrivalTime()) ) {
82  grid_->getCell(j).setArrivalTime(new_arrival_time);
83  narrow_band_->increase( &(grid_->getCell(j)) );
84  }
85  }
86  else {
87  grid_->getCell(j).setState(FMState::NARROW);
88  grid_->getCell(j).setArrivalTime(new_arrival_time);
89  narrow_band_->push( &(grid_->getCell(j)) );
90  } // neighbors open.
91  } // neighbors not frozen.
92  } // For each neighbor.
93  narrow_band_->pop();
94  if (idxMin == goal_idx_)
95  stopWavePropagation = true;
96  } // while narrow band is not empty
97  }
98 
99  virtual void printRunInfo
100  () const {
101  console::info("Untidy Fast Marching Method");
102  std::cout << '\t' << name_ << '\n'
103  << '\t' << "Number of buckets: " << heap_s_ << '\n'
104  << '\t' << "Maximum increment " << heap_inc_ << '\n'
105  << '\t' << "Elapsed time: " << time_ << " ms\n";
106  }
107 
108  virtual void clear
109  () {
110  delete narrow_band_;
111  }
112 
113  virtual void reset
114  () {
116  narrow_band_->clear();
117  }
118 
119  protected:
129 
130  private:
132  unsigned heap_s_;
133 
135  double heap_inc_;
136 
139 };
140 
141 #endif /* UFMM_HPP_*/
Abstract class that serves as interface for the actual EikonalSolvers implemented. It requires (at least) the computeInternal method to be implemented,.
Fast Marching Method using a untidy priority queue (UFMM).
Definition: ufmm.hpp:37
double time_
Time elapsed by the compute method.
Definition: solver.hpp:237
virtual void setup()
Checks that the solver is ready to run. Sets the grid unclean.
Definition: solver.hpp:94
Wraps the UntidyQueue implementation by Jerome Piovano
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.
Definition: ufmm.hpp:109
virtual double solveEikonal(const int &idx)
Solves nD Eikonal equation for cell idx. If heuristics are activated, it will add the estimated trave...
FMUntidyQueue< cell_t > * narrow_band_
Heap Instance of the priority queue used.
Definition: ufmm.hpp:138
grid_t * grid_
Grid container.
Definition: solver.hpp:219
static void info(const std::string &val)
std::vector< unsigned int > init_points_
Initial index.
Definition: solver.hpp:228
std::string name_
Solver name.
Definition: solver.hpp:222
static bool isTimeBetterThan(double t1, double t2)
Returns true if t1 is at least epsilon-lower than t2, provides robust comparions for doubles...
Definition: utils.h:32
virtual void reset()
Clears temporal data, so it is ready to run again.
Definition: ufmm.hpp:114
double heap_inc_
Size (maximum increment) of the heap.
Definition: ufmm.hpp:135
bool setup_
Setup status.
Definition: solver.hpp:225
unsigned int goal_idx_
Goal index.
Definition: solver.hpp:231
unsigned heap_s_
Number of buckets in the heap.
Definition: ufmm.hpp:132
virtual void computeInternal()
Actual method that implements UFMM.
Definition: ufmm.hpp:53
virtual void reset()
Clears temporal data, so it is ready to run again.
Definition: solver.hpp:176