worked on raytracing
This commit is contained in:
@@ -40,39 +40,14 @@ public:
|
||||
DataMap(const DataMap&) = delete;
|
||||
DataMap* operator = (const DataMap& o) = delete;
|
||||
|
||||
/*
|
||||
void blured(DataMap<T>& dst) const {
|
||||
|
||||
const int s = 2;
|
||||
dst.resize(this->bbox, this->gridSize_cm);
|
||||
|
||||
for (int iy = 0; iy < ny; ++iy) {
|
||||
for (int ix = 0; ix < nx; ++ix) {
|
||||
|
||||
float valSum = 0;
|
||||
int cntSum = 0;
|
||||
|
||||
for (int oy = -s; oy <= +s; ++oy) {
|
||||
for (int ox = -s; ox <= +s; ++ox) {
|
||||
|
||||
const int x = ix+ox;
|
||||
const int y = iy+oy;
|
||||
|
||||
if (containsGrid(x,y)) {
|
||||
valSum += getGrid(x,y);
|
||||
++cntSum;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
dst.setGrid(ix, iy, valSum/cntSum);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
T& operator [] (const int idx) {
|
||||
return data[idx];
|
||||
}
|
||||
*/
|
||||
|
||||
const T& operator [] (const int idx) const {
|
||||
return data[idx];
|
||||
}
|
||||
|
||||
|
||||
/** does the map contain the given indices? */
|
||||
bool containsGrid(const int x, const int y) const {
|
||||
@@ -84,6 +59,10 @@ public:
|
||||
return bbox.contains(Point2(x_m, y_m));
|
||||
}
|
||||
|
||||
void resize(const DataMap& other) {
|
||||
resize(other.bbox, other.gridSize_cm);
|
||||
}
|
||||
|
||||
void resize(const BBox2 bbox, const int gridSize_cm) {
|
||||
|
||||
// cleanup
|
||||
@@ -122,6 +101,10 @@ public:
|
||||
setGrid(ix, iy, val);
|
||||
}
|
||||
|
||||
T& getRef(const int idx) const {
|
||||
return data[idx];
|
||||
}
|
||||
|
||||
T get(const float x_m, const float y_m) const {
|
||||
const int ix = std::round( ((x_m-sx_m)) * 100 / gridSize_cm );
|
||||
const int iy = std::round( ((y_m-sy_m)) * 100 / gridSize_cm );
|
||||
@@ -148,6 +131,13 @@ public:
|
||||
return data[idx];
|
||||
}
|
||||
|
||||
const T& getGridRef(const int ix, const int iy) const {
|
||||
Assert::isBetween(ix, 0, nx-1, "x out of range");
|
||||
Assert::isBetween(iy, 0, ny-1, "y out of range");
|
||||
const int idx = ix + iy*nx;
|
||||
return data[idx];
|
||||
}
|
||||
|
||||
void setGrid(const int ix, const int iy, const T val) {
|
||||
Assert::isBetween(ix, 0, nx-1, "x out of range");
|
||||
Assert::isBetween(iy, 0, ny-1, "y out of range");
|
||||
@@ -155,41 +145,43 @@ public:
|
||||
data[idx] = val;
|
||||
}
|
||||
|
||||
void forEach(std::function<void(float,float,T)> func) const {
|
||||
/** convert grid indices to point coordinates */
|
||||
Point2 gridToPos(const int ix, const int iy) const {
|
||||
return Point2(
|
||||
(ix * gridSize_cm / 100.0f) + sx_m,
|
||||
(iy * gridSize_cm / 100.0f) + sy_m
|
||||
);
|
||||
}
|
||||
|
||||
/** convert 1D array index to point coordinates */
|
||||
Point2 idxToPos(const int idx) const {
|
||||
const int ix = idx % nx;
|
||||
const int iy = idx / nx;
|
||||
return gridToPos(ix, iy);
|
||||
}
|
||||
|
||||
/** convert 2D to 1D index */
|
||||
int getIndex(const int ix, const int iy) const {
|
||||
return ix + iy*nx;
|
||||
}
|
||||
|
||||
void forEach(std::function<void(float,float,const T&)> func) const {
|
||||
for (int iy = 0; iy < ny; ++iy) {
|
||||
for (int ix = 0; ix < nx; ++ix) {
|
||||
const float x = (ix * gridSize_cm / 100.0f) + sx_m;
|
||||
const float y = (iy * gridSize_cm / 100.0f) + sy_m;
|
||||
func(x,y,getGrid(ix, iy));
|
||||
func(x,y,getGridRef(ix, iy));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void dump() {
|
||||
|
||||
std::ofstream os("/tmp/1.dat");
|
||||
const float s = 1;//gridSize_cm / 100.0f;
|
||||
// for (int y = 0; y < ny; ++y) {
|
||||
// for (int x = 0; x < nx; ++x) {
|
||||
// float rssi = data[x+y*nx];
|
||||
// rssi = (rssi == 0) ? (-100) : (rssi);
|
||||
// os << (x*s) << " " << (y*s) << " " << rssi << "\n";
|
||||
// }
|
||||
// os << "\n";
|
||||
// }
|
||||
for (int y = 0; y < ny; ++y) {
|
||||
for (int x = 0; x < nx; ++x) {
|
||||
float rssi = data[x+y*nx];
|
||||
rssi = (rssi == 0) ? (-100) : (rssi);
|
||||
os << rssi << " ";
|
||||
void forEachGrid(std::function<void(int,int,T&)> func) {
|
||||
for (int iy = 0; iy < ny; ++iy) {
|
||||
for (int ix = 0; ix < nx; ++ix) {
|
||||
func(ix,iy,getGridRef(ix, iy));
|
||||
}
|
||||
os << "\n";
|
||||
}
|
||||
os.close();
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
private:
|
||||
|
||||
@@ -202,8 +194,15 @@ private:
|
||||
};
|
||||
|
||||
|
||||
struct DataMapNeighbors {
|
||||
|
||||
struct DataMapSignalEntry {
|
||||
/** reference to all neighbors */
|
||||
std::vector<int> neighbors;
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct DataMapSignalEntry : public DataMapNeighbors {
|
||||
|
||||
struct Entry {
|
||||
float rssi;
|
||||
@@ -213,6 +212,10 @@ struct DataMapSignalEntry {
|
||||
|
||||
std::vector<Entry> entries;
|
||||
|
||||
void add(const DataMapSignalEntry& o) {
|
||||
for (const Entry& e : o.entries) {entries.push_back(e);}
|
||||
}
|
||||
|
||||
void add(const float rssi, const float distanceToAP) {
|
||||
Entry e(rssi, distanceToAP);
|
||||
entries.push_back(e);
|
||||
@@ -225,9 +228,42 @@ struct DataMapSignalEntry {
|
||||
return it->rssi;
|
||||
}
|
||||
|
||||
float getFirstRSSI() const {
|
||||
auto comp = [] (const Entry& e1, const Entry& e2) {return e1.distanceToAP < e2.distanceToAP;};
|
||||
if (entries.empty()) {return -120;}
|
||||
auto it = std::min_element(entries.begin(), entries.end(), comp);
|
||||
return it->rssi;
|
||||
}
|
||||
|
||||
float getAvgFirst() const {
|
||||
if (entries.empty()) {return -120;}
|
||||
if (entries.size()==1) {return entries.front().rssi;}
|
||||
std::vector<Entry> copy = entries;
|
||||
auto comp = [] (const Entry& e1, const Entry& e2) {return e1.rssi > e2.rssi;};
|
||||
std::sort(copy.begin(), copy.end(), comp);
|
||||
|
||||
float sum = 0;
|
||||
int cnt = std::min((int)copy.size(), 15);
|
||||
for (int i = 0; i < cnt; ++i) {
|
||||
sum += copy[i].rssi;
|
||||
}
|
||||
return sum/cnt;
|
||||
|
||||
}
|
||||
|
||||
// float get2ndMaxRSSI() const {
|
||||
// if (entries.empty()) {return -120;}
|
||||
// if (entries.size()==1) {return entries.front().rssi;}
|
||||
// std::vector<Entry> copy = entries;
|
||||
// auto comp = [] (const Entry& e1, const Entry& e2) {return e1.rssi < e2.rssi;};
|
||||
// std::sort(copy.begin(), copy.end(), comp);
|
||||
// return copy[copy.size()-2].rssi;
|
||||
// }
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
class DataMapSignal : public DataMap<DataMapSignalEntry> {
|
||||
|
||||
public:
|
||||
@@ -242,4 +278,41 @@ public:
|
||||
|
||||
};
|
||||
|
||||
|
||||
class DataMap2Factory {
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/** combine neighboring nodes into one */
|
||||
template <typename T> static void combine(const DataMap<T>& map, DataMap<T>& dst) {
|
||||
|
||||
auto forEach = [&] (const float, const float, const T& n) {
|
||||
for (int idx : n.neighbors) {
|
||||
dst[idx].add(n);
|
||||
}
|
||||
};
|
||||
|
||||
map.forEach(forEach);
|
||||
|
||||
}
|
||||
|
||||
/** fill empty fields with the values of their immediate neighbors */
|
||||
template <typename T> static void fillGaps(const DataMap<T>& map, DataMap<T>& dst) {
|
||||
|
||||
auto forEach = [&] (const float, const float, const T& n) {
|
||||
if (n.entries.empty()) {
|
||||
for (int idx : n.neighbors) {
|
||||
dst[idx].add(n);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
map.forEach(forEach);
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // DATAMAP2_H
|
||||
|
||||
Reference in New Issue
Block a user