work on raytracing

This commit is contained in:
2017-09-06 08:34:20 +02:00
parent c21925e86f
commit e4cd9c6b8d
32 changed files with 2790 additions and 3 deletions

63
tests/geo/TestSphere3.cpp Normal file
View File

@@ -0,0 +1,63 @@
#ifdef WITH_TESTS
#include "../Tests.h"
#include "../../geo/Sphere3.h"
TEST(Sphere3, contains) {
Sphere3 a(Point3(0,0,0), 10);
Sphere3 b1(Point3(8,0,0), 1);
Sphere3 b2(Point3(0,8,0), 1);
Sphere3 b3(Point3(0,0,8), 1);
ASSERT_TRUE(a.contains(b1));
ASSERT_TRUE(a.contains(b2));
ASSERT_TRUE(a.contains(b3));
ASSERT_FALSE(b1.contains(a));
ASSERT_FALSE(b2.contains(a));
ASSERT_FALSE(b3.contains(a));
Sphere3 c1(Point3(8,0,0), 2.01);
Sphere3 c2(Point3(0,8,0), 2.01);
Sphere3 c3(Point3(0,0,8), 2.01);
ASSERT_FALSE(a.contains(c1));
ASSERT_FALSE(a.contains(c2));
ASSERT_FALSE(a.contains(c3));
ASSERT_FALSE(c1.contains(a));
ASSERT_FALSE(c2.contains(a));
ASSERT_FALSE(c3.contains(a));
}
TEST(Sphere3, join) {
// no overlap
Sphere3 a1(Point3(-1,0,0), 1);
Sphere3 a2(Point3(+1,0,0), 1);
Sphere3 a3 = Sphere3::join(a1, a2);
ASSERT_EQ(Point3(0,0,0), a3.center);
ASSERT_EQ(2, a3.radius);
// overlap
Sphere3 b1(Point3(-1,0,0), 1.5);
Sphere3 b2(Point3(+1,0,0), 1.5);
Sphere3 b3 = Sphere3::join(b1, b2);
ASSERT_EQ(Point3(0,0,0), b3.center);
ASSERT_EQ(2.5, b3.radius);
// fully within
Sphere3 c1(Point3(-1,0,0), 3.6);
Sphere3 c2(Point3(+1,0,0), 1.5);
Sphere3 c3 = Sphere3::join(c1, c2);
ASSERT_EQ(c1.center, c3.center);
ASSERT_EQ(c1.radius, c3.radius);
Sphere3 c4 = Sphere3::join(c2, c1);
ASSERT_EQ(c1.center, c4.center);
ASSERT_EQ(c1.radius, c4.radius);
}
#endif

View File

@@ -0,0 +1,36 @@
#ifdef WITH_TESTS
#include "../Tests.h"
#include "../../geo/Triangle3.h"
// https://stackoverflow.com/questions/17458562/efficient-aabb-triangle-intersection-in-c-sharp
// http://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/code/tribox3.txt
TEST(Triangle3, intersect) {
Point3 dst;
{
Triangle3 tria(Point3(-1,0,0), Point3(+1,0,0), Point3(0,1,0));
Ray3 ray(Point3(0,0.5,-1), Point3(0,0,1));
ASSERT_TRUE(tria.intersects(ray, dst));
ASSERT_EQ(Point3(0, 0.5, 0), dst);
}
{
Triangle3 tria(Point3(-1,0,0), Point3(+1,0,0), Point3(0,1,1));
Ray3 ray(Point3(0,0.5,-1), Point3(0,0,1));
ASSERT_TRUE(tria.intersects(ray, dst));
ASSERT_EQ(Point3(0, 0.5, 0.5), dst);
}
{
Triangle3 tria(Point3(10.4253730774, 49.0029830933, 0.00995028018951), Point3(10.4253730774, 49.0029830933, 3.99004983902), Point3(10.4253730774, 50.197013855, 3.99004983902));
Ray3 ray(Point3(67.2000045776, 36.0, 3.5), Point3(0.154123231769, -0.631025910378, -0.76029753685));
ASSERT_FALSE(tria.intersects(ray, dst));
}
}
#endif

View File

@@ -0,0 +1,37 @@
#ifdef WITH_TESTS
#include "../Tests.h"
#include "../../math/Matrix4.h"
TEST(Matrix4, mul) {
Matrix4 mat1 = Matrix4::identity();
Matrix4 mat2 = Matrix4::identity();
ASSERT_EQ(mat1, mat2);
}
TEST(Matrix4, vecMul) {
Matrix4 mat = Matrix4::identity();
Vector4 vec(1,1,1,1);
Vector4 v2 = mat*vec;
int i = 0; (void) i;
}
TEST(Matrix4, rot) {
Matrix4 mat = Matrix4::getRotationDeg(0,0,0);
Vector4 vec(1,0,0,1);
Vector4 v2 = mat*vec;
ASSERT_EQ(v2, vec);
}
#endif

View File

@@ -0,0 +1,27 @@
#ifdef WITH_TESTS
#include "../Tests.h"
#include "../../wifi/estimate/ray3/DataMap3.h"
TEST(DataMap3, test) {
BBox3 bbox(Point3(0,0,0), Point3(10,10,10));
DataMap3<float> dm;
dm.resize(bbox, 10);
dm.set(0,0,0, 10);
ASSERT_EQ(10, dm.get(0,0,0));
dm.set(0,5,0, 11);
ASSERT_EQ(11, dm.get(0,5,0));
dm.set(5,0,0, 12);
ASSERT_EQ(12, dm.get(5,0,0));
dm.set(0,0,5, 13);
ASSERT_EQ(13, dm.get(0,0,5));
}
#endif

View File

@@ -0,0 +1,22 @@
#ifdef WITH_TESTS
#include "../Tests.h"
#include "../../wifi/estimate/ray3/ModelFactory.h"
#include "../../floorplan/v2/FloorplanReader.h"
#include <fstream>
TEST(Ray, ModelFac) {
std::string file = "/mnt/data/workspaces/IndoorMap/maps/SHL39.xml";
Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile(file);
ModelFactory fac(map);
fac.triangulize();
std::ofstream out("/mnt/vm/fhws.obj");
out << fac.toOBJ() << std::endl;
out.close();
}
#endif

View File

@@ -0,0 +1,66 @@
#ifdef WITH_TESTS
#include "../Tests.h"
#include "../../wifi/estimate/ray3/WifiRayTrace3D.h"
#include "../../floorplan/v2/FloorplanReader.h"
#include <fstream>
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 = "/mnt/data/workspaces/IndoorMap/maps/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");
outOBJ << fac.toOBJ();
outOBJ.close();
const int gs_cm = 100;
WiFiRaytrace3D rt(map, gs_cm, ap->pos);
const DataMap3Signal& dms = rt.estimate();
const char sep = ';';
std::ofstream out("/mnt/vm/rays.xyz.txt");
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 (rssi > -100) {
const float v = ((rssi - min) / (max-min)) * 255;
out
<< x << sep << y << sep << z << sep
<< v << sep << v << sep << v
<< "\n";
}
};
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();
}
#endif