modified lib GPC for header only
worked on 3d traytracing
This commit is contained in:
198
tests/geo/TestBVH.cpp
Normal file
198
tests/geo/TestBVH.cpp
Normal file
@@ -0,0 +1,198 @@
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
#include "../Tests.h"
|
||||
|
||||
#include "../../geo/volume/BVH.h"
|
||||
#include "../../geo/volume/BVHDebug.h"
|
||||
#include "../../geo/BBox3.h"
|
||||
|
||||
#include "../../floorplan/v2/Floorplan.h"
|
||||
#include "../../floorplan/v2/FloorplanReader.h"
|
||||
#include "../../wifi/estimate/ray3/ModelFactory.h"
|
||||
|
||||
struct Wrapper {
|
||||
|
||||
static std::vector<Point3> getVertices(const BBox3& bbox) {
|
||||
return {bbox.getMin(), bbox.getMax()};
|
||||
}
|
||||
|
||||
static std::vector<Point3> getDebugLines(const BBox3& bbox) {
|
||||
|
||||
Point3 p1(bbox.getMin().x, bbox.getMin().y, bbox.getMin().z);
|
||||
Point3 p2(bbox.getMax().x, bbox.getMin().y, bbox.getMin().z);
|
||||
Point3 p3(bbox.getMax().x, bbox.getMax().y, bbox.getMin().z);
|
||||
Point3 p4(bbox.getMin().x, bbox.getMax().y, bbox.getMin().z);
|
||||
|
||||
Point3 p5(bbox.getMin().x, bbox.getMin().y, bbox.getMax().z);
|
||||
Point3 p6(bbox.getMax().x, bbox.getMin().y, bbox.getMax().z);
|
||||
Point3 p7(bbox.getMax().x, bbox.getMax().y, bbox.getMax().z);
|
||||
Point3 p8(bbox.getMin().x, bbox.getMax().y, bbox.getMax().z);
|
||||
|
||||
std::vector<Point3> res;
|
||||
res.push_back(p1); res.push_back(p2);
|
||||
res.push_back(p2); res.push_back(p3);
|
||||
res.push_back(p3); res.push_back(p4);
|
||||
res.push_back(p4); res.push_back(p1);
|
||||
|
||||
res.push_back(p5); res.push_back(p6);
|
||||
res.push_back(p6); res.push_back(p7);
|
||||
res.push_back(p7); res.push_back(p8);
|
||||
res.push_back(p8); res.push_back(p5);
|
||||
|
||||
res.push_back(p1); res.push_back(p5);
|
||||
res.push_back(p2); res.push_back(p6);
|
||||
res.push_back(p3); res.push_back(p7);
|
||||
res.push_back(p4); res.push_back(p8);
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct WrapperObs3D {
|
||||
|
||||
static std::vector<Point3> getVertices(const Obstacle3D& o) {
|
||||
std::vector<Point3> pts;
|
||||
for (const Triangle3& tria : o.triangles) {
|
||||
pts.push_back(tria.p1);
|
||||
pts.push_back(tria.p2);
|
||||
pts.push_back(tria.p3);
|
||||
}
|
||||
return pts;
|
||||
}
|
||||
|
||||
static std::vector<Point3> getDebugLines(const Obstacle3D& o) {
|
||||
std::vector<Point3> pts;
|
||||
for (const Triangle3& tria : o.triangles) {
|
||||
pts.push_back(tria.p1); pts.push_back(tria.p2);
|
||||
pts.push_back(tria.p2); pts.push_back(tria.p3);
|
||||
pts.push_back(tria.p3); pts.push_back(tria.p1);
|
||||
}
|
||||
return pts;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
TEST(BVH, tree) {
|
||||
|
||||
BVHDebug<BBox3, BoundingVolumeSphere, Wrapper> tree;
|
||||
|
||||
BBox3 bb1(Point3(0,0,0), Point3(1,1,1));
|
||||
tree.add(bb1);
|
||||
|
||||
BBox3 bb2(Point3(-1,-1,-1), Point3(0,0,0));
|
||||
tree.add(bb2);
|
||||
|
||||
tree.optimize();
|
||||
tree.show();
|
||||
|
||||
int i = 0; (void) i;
|
||||
|
||||
}
|
||||
|
||||
TEST(BVH, tree2) {
|
||||
|
||||
BVHDebug<BBox3, BoundingVolumeSphere, Wrapper> tree;
|
||||
|
||||
BBox3 bb1(Point3(0,0,0), Point3(1,1,1));
|
||||
tree.add(bb1);
|
||||
|
||||
BBox3 bb2(Point3(-1,0,0), Point3(0,1,1));
|
||||
tree.add(bb2);
|
||||
|
||||
tree.optimize();
|
||||
tree.show();
|
||||
|
||||
int i = 0; (void) i;
|
||||
|
||||
}
|
||||
|
||||
TEST(BVH, tree3) {
|
||||
|
||||
BVHDebug<BBox3, BoundingVolumeSphere, Wrapper> tree;
|
||||
|
||||
BBox3 bb1 = BBox3::around(Point3(+0.5, +0.5, 0.0), Point3(0.25, 0.25, 0.25));
|
||||
tree.add(bb1);
|
||||
|
||||
BBox3 bb2 = BBox3::around(Point3(-0.5, +0.5, 0.0), Point3(0.25, 0.25, 0.25));
|
||||
tree.add(bb2);
|
||||
|
||||
BBox3 bb3 = BBox3::around(Point3(-0.0, +0.5, 0.0), Point3(0.36, 0.36, 0.36));
|
||||
tree.add(bb3);
|
||||
|
||||
BBox3 bb4 = BBox3::around(Point3(-0.0, +0.0, 0.0), Point3(0.5, 0.5, 0.5));
|
||||
tree.add(bb4);
|
||||
|
||||
tree.optimize(1);
|
||||
tree.show();
|
||||
|
||||
tree.optimize(1);
|
||||
tree.show();
|
||||
|
||||
tree.optimize(1);
|
||||
tree.show();
|
||||
|
||||
int i = 0; (void) i;
|
||||
|
||||
}
|
||||
|
||||
TEST(BVH, treeMap) {
|
||||
|
||||
std::string file = "/apps/SHL39.xml";
|
||||
Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile(file);
|
||||
|
||||
ModelFactory fac(map);
|
||||
fac.setExportCeilings(false);
|
||||
fac.setFloors({map->floors[3]});
|
||||
std::vector<Obstacle3D> obs = fac.triangulize();
|
||||
|
||||
BVHDebug<Obstacle3D, BoundingVolumeSphere, WrapperObs3D> tree;
|
||||
|
||||
for (const Obstacle3D& o : obs) {
|
||||
tree.add(o);
|
||||
}
|
||||
|
||||
//tree.show(150);
|
||||
|
||||
//int rounds = tree.optimize();
|
||||
|
||||
for (int i = 0; i < 200; ++i) {
|
||||
tree.optimize(1);
|
||||
//if (i%3==0) {
|
||||
tree.show(250, false);
|
||||
//}
|
||||
}
|
||||
|
||||
int i = 0; (void) i;
|
||||
|
||||
}
|
||||
|
||||
TEST(BVH, treeRandom) {
|
||||
|
||||
BVHDebug<BBox3, BoundingVolumeSphere, Wrapper> tree;
|
||||
|
||||
std::minstd_rand gen;
|
||||
std::uniform_real_distribution<float> dPos(-4.0, +4.0);
|
||||
std::uniform_real_distribution<float> dSize(+0.3, +1.0);
|
||||
|
||||
for (int i = 0; i < 50; ++i) {
|
||||
const Point3 pos(dPos(gen), dPos(gen), dPos(gen));
|
||||
const Point3 size(dSize(gen), dSize(gen), dSize(gen));
|
||||
BBox3 bb = BBox3::around(pos, size);
|
||||
tree.add(bb);
|
||||
}
|
||||
|
||||
tree.show();
|
||||
|
||||
// for (int i = 0; i < 25; ++i) {
|
||||
// tree.optimize(1);
|
||||
// tree.show();
|
||||
// }
|
||||
|
||||
int i = 0; (void) i;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -12,54 +12,87 @@ TEST(RayTrace3, test) {
|
||||
//Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile(file);
|
||||
//Floorplan::AccessPoint* ap = map->floors[0]->accesspoints[0];
|
||||
|
||||
std::string file = "/mnt/data/workspaces/IndoorMap/maps/SHL39.xml";
|
||||
std::string file = "/apps/SHL39.xml";
|
||||
Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile(file);
|
||||
Floorplan::AccessPoint* ap = map->floors[0]->accesspoints[4];
|
||||
|
||||
ModelFactory fac(map);
|
||||
std::ofstream outOBJ("/mnt/vm/map.obj");
|
||||
std::ofstream outOBJ("/tmp/vm/map.obj");
|
||||
outOBJ << fac.toOBJ();
|
||||
outOBJ.close();
|
||||
|
||||
const int gs_cm = 100;
|
||||
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;
|
||||
|
||||
const char sep = ';';
|
||||
if (1 == 1) {
|
||||
|
||||
std::ofstream out("/mnt/vm/rays.xyz.txt");
|
||||
auto lambda = [&] (const float x, const float y, const float z, const DataMap3SignalEntry& e) {
|
||||
const char sep = ' ';
|
||||
int lines = 0;
|
||||
|
||||
const float min = -120;
|
||||
const float max = -40;
|
||||
float rssi = e.getMaxRSSI();
|
||||
if (rssi > max) {rssi = max;}
|
||||
std::stringstream tmp;
|
||||
|
||||
if (rssi > -100) {
|
||||
const float v = ((rssi - min) / (max-min)) * 255;
|
||||
out
|
||||
<< x << sep << y << sep << z << sep
|
||||
<< v << sep << v << sep << v
|
||||
<< "\n";
|
||||
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();
|
||||
|
||||
|
||||
dms.forEach(lambda);
|
||||
out.close();
|
||||
|
||||
std::ofstream outHits("/mnt/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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user