n-Dimensional Fast Methods  0.7
 All Classes Functions Variables Typedefs Pages
fim.hpp
1 
28 #ifndef FIM_HPP_
29 #define FIM_HPP_
30 
31 #include <list>
32 
33 #include <fast_methods/fm/eikonalsolver.hpp>
34 #include <fast_methods/utils/utils.h>
35 
36 template < class grid_t > class FIM : public EikonalSolver<grid_t> {
37 
38  public:
39  FIM(double error = 0) : EikonalSolver<grid_t>("FIM"), E_(error) {}
40  FIM(const char * name, double error = 0) : EikonalSolver<grid_t>(name), E_(error) {}
41 
42  virtual ~FIM() { clear(); }
43 
45  virtual void computeInternal
46  () {
47  if (!setup_)
48  setup();
49 
50  double q =-1;
51  double p =-1;
52  unsigned int n_neighs = 0;
53  unsigned int x_nb = 0;
54  bool stopWavePropagation = 0;
55 
56  // Algorithm initialization.
57  for (const unsigned int& i: init_points_) {
58  grid_->getCell(i).setArrivalTime(0);
59  grid_->getCell(i).setState(FMState::FROZEN);
60 
61  n_neighs = grid_->getNeighbors(i, neighbors_);
62  for (unsigned int s = 0; s < n_neighs; ++s) {// For each neighbor
63  x_nb = neighbors_[s];
64  if ( (grid_->getCell(x_nb).getState() == FMState::OPEN) && !grid_->getCell(x_nb).isOccupied()) {
65  active_list_.push_back(x_nb);
66  grid_->getCell(x_nb).setState(FMState::NARROW);
67  }
68  }
69  }
70 
71  // Main loop.
72  while(!stopWavePropagation && !active_list_.empty()) {
73  for (std::list<unsigned int>::iterator x = active_list_.begin(); x!=active_list_.end(); ++x) { // for each cell of active_list
74  p = grid_->getCell(*x).getArrivalTime();
75  q = solveEikonal(*x);
76  grid_->getCell(*x).setArrivalTime(q);
77  if (fabs(p - q) <= E_) { // if the cell has converged
78  n_neighs = grid_->getNeighbors(*x, neighbors_);
79  for (unsigned int s = 0; s < n_neighs; ++s){ // For each neighbor of converged cells of active_list
80  x_nb = neighbors_[s];
81  if (grid_->getCell(x_nb).getState() != FMState::NARROW && !grid_->getCell(x_nb).isOccupied()) {
82  p = grid_->getCell(x_nb).getArrivalTime();
83  q = solveEikonal(x_nb);
84  if (utils::isTimeBetterThan(q, p)) {
85  grid_->getCell(x_nb).setArrivalTime(q);
86  active_list_.insert(x, x_nb);
87  grid_->getCell(x_nb).setState(FMState::NARROW);
88  }
89  }
90  }// For each neighbor of converged cells of active_list
91  if (*x == goal_idx_)
92  stopWavePropagation = true;
93  grid_->getCell(*x).setState(FMState::FROZEN);
94  x = active_list_.erase(x);
95  --x;
96  }// if the cell has converged
97  }// for each cell of active_list
98  }//while active_list is not empty
99  }
100 
101  virtual void clear
102  () {
103  active_list_.clear();
104  }
105 
106  virtual void reset
107  () {
109  active_list_.clear();
110  }
111 
112  protected:
120 
121  private:
123  std::list<unsigned int> active_list_;
124 
126  double E_;
127 };
128 
129 #endif /* FIM_HPP_*/
Abstract class that serves as interface for the actual EikonalSolvers implemented. It requires (at least) the computeInternal method to be implemented,.
virtual void setup()
Checks that the solver is ready to run. Sets the grid unclean.
Definition: solver.hpp:94
std::list< unsigned int > active_list_
List wich stores the narrow band of each iteration.
Definition: fim.hpp:123
std::array< unsigned int, 2 *grid_t::getNDims()> neighbors_
Auxiliar array which stores the neighbor of each iteration of the computeFM() function.
virtual double solveEikonal(const int &idx)
Solves nD Eikonal equation for cell idx. If heuristics are activated, it will add the estimated trave...
grid_t * grid_
Grid container.
Definition: solver.hpp:219
std::vector< unsigned int > init_points_
Initial index.
Definition: solver.hpp:228
virtual void reset()
Clears temporal data, so it is ready to run again.
Definition: fim.hpp:107
virtual void clear()
Clears the solver, it is not recommended to be used out of the destructor.
Definition: fim.hpp:102
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
bool setup_
Setup status.
Definition: solver.hpp:225
Implements Fast Iterative Method.
Definition: fim.hpp:36
unsigned int goal_idx_
Goal index.
Definition: solver.hpp:231
virtual void computeInternal()
Actual method that implements FIM.
Definition: fim.hpp:46
double E_
Error threshold value that reveals if a cell has converged.
Definition: fim.hpp:126
virtual void reset()
Clears temporal data, so it is ready to run again.
Definition: solver.hpp:176