This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/tests/ray/TestRayTrace3.cpp
2018-07-24 18:08:08 +02:00

102 lines
2.8 KiB
C++

#ifdef WITH_TESTS
#include "../Tests.h"
#include "../../wifi/estimate/ray3/WifiRayTrace3D.h"
#include "../../floorplan/v2/FloorplanReader.h"
#include <fstream>
using namespace Ray3D;
TEST(RayTrace3, test) {
//std::string file = "/mnt/data/workspaces/raytest2.xml";
//Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile(file);
//Floorplan::AccessPoint* ap = map->floors[0]->accesspoints[0];
//std::string file = "/apps/SHL39.xml";
std::string file = "/mnt/data/workspaces/IndoorMap/maps/SHL39.xml";
Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile(file);
Floorplan::AccessPoint* ap = map->floors[0]->accesspoints[4];
Builder fac(map);
std::ofstream outOBJ("/tmp/vm/map.obj");
outOBJ << fac.getMesh().toOBJ("obj").obj;
outOBJ.close();
const int gs_cm = 50;
WiFiRaytrace3D rt(map, gs_cm, ap->pos);
std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
const DataMap3Signal& dms = rt.estimate();
std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
auto result = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
std::cout << "it took: " << result << " msec" << std::endl;
if (1 == 1) {
const char sep = ' ';
int lines = 0;
std::stringstream tmp;
auto lambda = [&] (const float x, const float y, const float z, const DataMap3SignalEntry& e) {
const float min = -120;
const float max = -40;
float rssi = e.getMaxRSSI();
if (rssi > max) {rssi = max;}
if (z < 1.0 || z > 1.0) {return;}
if (rssi > -100) {
++lines;
const int v = ((rssi - min) / (max-min)) * 255; // color
tmp
<< x << sep << y << sep << z << sep
<< v << sep << v << sep << v
<< "\n";
}
};
dms.forEach(lambda);
std::ofstream out("/tmp/vm/grid.ply");
out << "ply\n";
out << "format ascii 1.0\n";
out << "comment VCGLIB generated\n";
out << "element vertex " << lines << "\n";
out << "property float x\n";
out << "property float y\n";
out << "property float z\n";
out << "property uchar red\n";
out << "property uchar green\n";
out << "property uchar blue\n";
out << "element face 0\n";
out << "property list uchar int vertex_indices\n";
out << "end_header\n";
out << tmp.str();
out.close();
std::cout << "lines: " << lines << std::endl;
std::ofstream outHits("/tmp/vm/hits.xyz.txt");
for (const Point3 hit : rt.getHitEnter()) {
outHits << hit.x << sep << hit.y << sep << hit.z << sep << 0 << sep << 255 << sep << 0 << "\n";
}
for (const Point3 hit : rt.getHitLeave()) {
outHits << hit.x << sep << hit.y << sep << hit.z << sep << 0 << sep << 0 << sep << 255 << "\n";
}
for (const Point3 hit : rt.getHitStop()) {
outHits << hit.x << sep << hit.y << sep << hit.z << sep << 0 << sep << 0 << sep << 0 << "\n";
}
outHits.close();
}
}
#endif