modified lib GPC for header only
worked on 3d traytracing
This commit is contained in:
@@ -5,6 +5,9 @@
|
||||
#include "../../../geo/Line2.h"
|
||||
#include "../../../geo/BBox2.h"
|
||||
|
||||
#include "../../../geo/volume/BVH.h"
|
||||
#include "../../../geo/volume/BVHDebug.h"
|
||||
|
||||
#include "../../../floorplan/v2/Floorplan.h"
|
||||
#include "../../../floorplan/v2/FloorplanHelper.h"
|
||||
|
||||
@@ -13,7 +16,9 @@
|
||||
#include "MaterialOptions.h"
|
||||
#include "Obstacle3.h"
|
||||
#include "ModelFactory.h"
|
||||
#include "ObstacleTree.h"
|
||||
//#include "ObstacleTree.h"
|
||||
|
||||
|
||||
|
||||
#include <random>
|
||||
|
||||
@@ -133,8 +138,29 @@ struct Hit3 {
|
||||
|
||||
|
||||
|
||||
struct Obstacle3DWrapper {
|
||||
|
||||
static std::vector<Point3> getVertices(const Obstacle3D& obs) {
|
||||
std::vector<Point3> pts;
|
||||
for (const Triangle3& tria : obs.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& obs) {
|
||||
std::vector<Point3> pts;
|
||||
for (const Triangle3& tria : obs.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;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -147,12 +173,11 @@ private:
|
||||
|
||||
DataMap3Signal dm;
|
||||
|
||||
//std::vector<Obstacle3D> obstacles;
|
||||
ObstacleTree tree;
|
||||
BVHDebug<Obstacle3D, BoundingVolumeSphere, Obstacle3DWrapper> tree;
|
||||
|
||||
struct Limit {
|
||||
static constexpr int RAYS = 1000;
|
||||
static constexpr int HITS = 16;
|
||||
static constexpr int RAYS = 15000;
|
||||
static constexpr int HITS = 25;
|
||||
static constexpr float RSSI = -110;
|
||||
};
|
||||
|
||||
@@ -174,19 +199,13 @@ public:
|
||||
ModelFactory fac(map);
|
||||
std::vector<Obstacle3D> obstacles = fac.triangulize();
|
||||
|
||||
|
||||
|
||||
// build bounding volumes
|
||||
for (Obstacle3D& obs : obstacles) {
|
||||
ObstacleLeaf* leaf = new ObstacleLeaf();
|
||||
leaf->obs = obs;
|
||||
leaf->boundSphere = getSphereAround(obs.triangles);
|
||||
if (leaf->boundSphere.radius == 0) {
|
||||
throw Exception("invalid item detected");
|
||||
}
|
||||
tree.add(leaf);
|
||||
tree.add(obs);
|
||||
}
|
||||
tree.optimize();
|
||||
|
||||
//tree.optimize();
|
||||
//tree.show(500, false);
|
||||
|
||||
int xxx = 0; (void) xxx;
|
||||
|
||||
@@ -209,6 +228,7 @@ public:
|
||||
std::uniform_real_distribution<float> dy(-1.0, +1.0);
|
||||
std::uniform_real_distribution<float> dz(-1.0, +1.0);
|
||||
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < Limit::RAYS; ++i) {
|
||||
|
||||
std::cout << "ray: " << i << std::endl;
|
||||
@@ -229,6 +249,8 @@ public:
|
||||
}
|
||||
|
||||
|
||||
//#define USE_DEBUG
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -239,7 +261,9 @@ private:
|
||||
|
||||
// stop?
|
||||
if (nextHit.invalid) {
|
||||
#ifdef USE_DEBUG
|
||||
hitStop.push_back(nextHit.pos);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -248,7 +272,9 @@ private:
|
||||
|
||||
// continue?
|
||||
if ((nextHit.stopHere) || (ray.getRSSI(nextHit.dist) < Limit::RSSI) || (ray.getDepth() > Limit::HITS)) {
|
||||
#ifdef USE_DEBUG
|
||||
hitStop.push_back(nextHit.pos);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -256,11 +282,15 @@ private:
|
||||
// apply effects
|
||||
if (ray.isWithin) {
|
||||
leave(ray, nextHit);
|
||||
#ifdef USE_DEBUG
|
||||
hitLeave.push_back(nextHit.pos);
|
||||
#endif
|
||||
} else {
|
||||
enter(ray, nextHit);
|
||||
reflectAt(ray, nextHit);
|
||||
#ifdef USE_DEBUG
|
||||
hitEnter.push_back(nextHit.pos);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -365,6 +395,7 @@ private:
|
||||
|
||||
Assert::isNear(1.0f, ray.dir.length(), 0.01f, "not normalized!");
|
||||
|
||||
int hits = 0;
|
||||
const float MAX = 999999;
|
||||
Hit3 nearest; nearest.dist = MAX;
|
||||
|
||||
@@ -387,10 +418,13 @@ private:
|
||||
|
||||
// }
|
||||
|
||||
std::vector<Obstacle3D*> obs = tree.getHits(ray);
|
||||
for (const Obstacle3D* o : obs) {
|
||||
hitTest(ray, *o, nearest);
|
||||
}
|
||||
|
||||
auto onHit = [&] (const Obstacle3D& obs) {
|
||||
++hits;
|
||||
hitTest(ray, obs, nearest);
|
||||
};
|
||||
|
||||
tree.getHits(ray, onHit);
|
||||
|
||||
}
|
||||
|
||||
@@ -399,6 +433,8 @@ private:
|
||||
nearest.invalid = true;
|
||||
}
|
||||
|
||||
//std::cout << hits << std::endl;
|
||||
|
||||
return nearest;
|
||||
|
||||
}
|
||||
@@ -445,6 +481,7 @@ private:
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Sphere3 getSphereAround(const std::vector<Triangle3>& trias) {
|
||||
|
||||
std::vector<Point3> pts;
|
||||
@@ -463,7 +500,7 @@ private:
|
||||
return sphere;
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user