16 #define duration(a) duration_cast<milliseconds>(a).count() 17 typedef high_resolution_clock
clk;
25 const float value_from = map.
at(layer_from, *iterator);
26 float& value_to = map.
at(layer_to, *iterator);
27 value_to = value_to > value_from ? value_to : value_from;
36 const auto& data_from = map[layer_from];
37 auto& data_to = map[layer_to];
39 const Index index(*iterator);
40 const float value_from = data_from(index(0), index(1));
41 float& value_to = data_to(index(0), index(1));
42 value_to = value_to > value_from ? value_to : value_from;
51 const auto& data_from = map[layer_from];
52 auto& data_to = map[layer_to];
54 const size_t i = iterator.getLinearIndex();
55 const float value_from = data_from(i);
56 float& value_to = data_to(i);
57 value_to = value_to > value_from ? value_to : value_from;
67 map[layer_to] = map[layer_to].cwiseMax(map[layer_from]);
75 const auto& data_from = map[layer_from];
76 auto& data_to = map[layer_to];
77 for (
size_t j = 0; j < data_to.cols(); ++j) {
78 for (
size_t i = 0; i < data_to.rows(); ++i) {
79 const float value_from = data_from(i, j);
80 float& value_to = data_to(i, j);
81 value_to = value_to > value_from ? value_to : value_from;
91 const auto& data_from = map[layer_from];
92 auto& data_to = map[layer_to];
93 for (
size_t i = 0; i < data_to.size(); ++i) {
94 data_to(i) = data_to(i) > data_from(i) ? data_to(i) : data_from(i);
98 int main(
int argc,
char* argv[])
103 map[
"random"].setRandom();
104 map.
add(
"layer1", 0.0);
105 map.
add(
"layer2", 0.0);
106 map.
add(
"layer3", 0.0);
107 map.
add(
"layer4", 0.0);
108 map.
add(
"layer5", 0.0);
109 map.
add(
"layer6", 0.0);
111 cout <<
"Results for iteration over " << map.
getSize()(0) <<
" x " << map.
getSize()(1) <<
" (" << map.
getSize().prod() <<
") grid cells." << endl;
112 cout <<
"=========================================" << endl;
114 clk::time_point t1 = clk::now();
116 clk::time_point t2 = clk::now();
117 cout <<
"Duration grid map iterator (convenient use): " <<
duration(t2 - t1) <<
" ms" << endl;
122 cout <<
"Duration grid map iterator (direct access to data layers): " <<
duration(t2 - t1) <<
" ms" << endl;
127 cout <<
"Duration grid map iterator (linear index): " <<
duration(t2 - t1) <<
" ms" << endl;
132 cout <<
"Duration Eigen function: " <<
duration(t2 - t1) <<
" ms" << endl;
137 cout <<
"Duration custom index iteration: " <<
duration(t2 - t1) <<
" ms" << endl;
142 cout <<
"Duration custom linear index iteration: " <<
duration(t2 - t1) <<
" ms" << endl;
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
void runCustomIndexIteration(GridMap &map, const string &layer_from, const string &layer_to)
void runEigenFunction(GridMap &map, const string &layer_from, const string &layer_to)
void runGridMapIteratorVersion1(GridMap &map, const string &layer_from, const string &layer_to)
void runGridMapIteratorVersion2(GridMap &map, const string &layer_from, const string &layer_to)
float & at(const std::string &layer, const Index &index)
void runGridMapIteratorVersion3(GridMap &map, const string &layer_from, const string &layer_to)
high_resolution_clock clk
void add(const std::string &layer, const double value=NAN)
int main(int argc, char *argv[])
void runCustomLinearIndexIteration(GridMap &map, const string &layer_from, const string &layer_to)
const Size & getSize() const