Go to the documentation of this file.00001
00009 #ifndef HISTORYMANAGER_HPP_
00010 #define HISTORYMANAGER_HPP_
00011
00012 #include "rtslam/mapAbstract.hpp"
00013 #include "rtslam/mapObject.hpp"
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 namespace jafar {
00053 namespace rtslam {
00054
00055
00056 class HistoryManagerAbstract
00057 {
00058 protected:
00059 map_ptr_t map;
00060 jblas::ind_array ia_state;
00061
00062 jblas::ind_array duplicate()
00063 {
00064 jblas::ind_array ia_newstate = map->reserveStates(ia_state.size());
00065 ublas::project(map->x(), ia_newstate) = ublas::project(map->x(), ia_state);
00066 ublas::project(map->P(), ia_state, ia_newstate) = ublas::project(map->P(), ia_state, ia_state);
00067 ublas::project(map->P(), ia_newstate, map->ia_used_states()) = ublas::project(map->P(), ia_state, map->ia_used_states());
00068 return ia_newstate;
00069 }
00070
00071 public:
00072 HistoryManagerAbstract(map_ptr_t map, jblas::ind_array ia_state):
00073 map(map), ia_state(ia_state) {}
00074 virtual void process(double date) = 0;
00075 virtual void print() = 0;
00076 };
00077
00078
00082 class HistoryManagerSparse: public HistoryManagerAbstract
00083 {
00084 protected:
00085 struct State { double date; jblas::ind_array ia; };
00086
00087 struct Gate { double delay_end, delay; State *state; };
00088 typedef std::vector<Gate> GateVector;
00089 GateVector gates;
00090
00091 double start_date;
00092 double end_date;
00093 bool ended;
00094 double first_gate_factor;
00095 double last_date;
00096 bool processed;
00097
00098 double horizon_date;
00099
00100 public:
00107 HistoryManagerSparse(map_ptr_t map, jblas::ind_array ia_state, double first, double factor, int count):
00108 HistoryManagerAbstract(map, ia_state)
00109 {
00110 double delay = first;
00111 for(int i = 0; i < count; ++i) { gates.push_back((Gate){delay,0.0,NULL}); delay *= factor; }
00112 horizon_date = -1;
00113 ended = false;
00114 first_gate_factor = gates.back().delay_end / (gates.back().delay_end - gates.front().delay_end);
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 void process(double date)
00128 {
00129 last_date = date;
00130 processed = false;
00131
00132
00133 if (horizon_date < 0)
00134 {
00135 start_date = date;
00136 end_date = date + gates.back().delay_end;
00137 for(GateVector::iterator it = gates.begin(); it != gates.end(); ++it)
00138 {
00139 it->state = new State();
00140 it->state->date = date;
00141 it->state->ia = duplicate();
00142 }
00143 horizon_date = date;
00144 return;
00145 }
00146
00147
00148
00149 if (date >= horizon_date)
00150 {
00151 processed = true;
00152
00153 if (!ended)
00154 {
00155 double scale = date - start_date;
00156 if (date > end_date) { scale = gates.back().delay_end; first_gate_factor = 1.0; ended = true; }
00157 for(GateVector::iterator it = gates.begin(); it != gates.end(); ++it)
00158 it->delay = it->delay_end * scale/gates.back().delay_end;
00159 }
00160
00161 State *new_state = new State();
00162 new_state->date = date;
00163
00164 State *state_to_pass = new_state;
00165 for(GateVector::iterator it = gates.begin(); it != gates.end(); ++it)
00166 {
00167 if (it->state->date <= date - it->delay)
00168 {
00169 State *tmp = state_to_pass;
00170 state_to_pass = it->state;
00171 it->state = tmp;
00172 } else
00173 break;
00174 }
00175
00176
00177 map->liberateStates(state_to_pass->ia);
00178 delete state_to_pass;
00179
00180 new_state->ia = duplicate();
00181
00182 horizon_date = date + gates.front().delay * first_gate_factor;
00183 }
00184 }
00185
00186 void print()
00187 {
00188 const int cwidth = 150;
00189 double dwidth = gates[gates.size()-1].delay_end + gates[gates.size()-2].delay_end;
00190
00191 printf("%7.3f%c", last_date-start_date, processed ? '*' : ' ');
00192
00193 int pos = 8;
00194 for(GateVector::reverse_iterator it = gates.rbegin(); it != gates.rend(); ++it)
00195 {
00196 int p = cwidth - (int)(it->delay * cwidth/dwidth + 0.5) - pos;
00197 for(int i = 0; i < p-1; ++i) std::cout << " ";
00198 if (p != 0) std::cout << "@";
00199 pos += p;
00200 }
00201 int p = cwidth - pos + 1;
00202 for(int i = 0; i < p-1; ++i) std::cout << " ";
00203 std::cout << "|" << std::endl;
00204
00205 pos = 0;
00206 for(GateVector::reverse_iterator it = gates.rbegin(); it != gates.rend(); ++it)
00207 {
00208 int p = cwidth - (int)((last_date - it->state->date) * cwidth/dwidth + 0.5) - pos;
00209 for(int i = 0; i < p-1; ++i) std::cout << " ";
00210 if (p != 0) std::cout << "X";
00211 pos += p;
00212 }
00213 std::cout << std::endl;
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 }
00226
00227 };
00228
00229
00230
00231
00232
00233 }
00234 }
00235
00236 #endif // #ifndef HISTORYMANAGER_HPP_
00237