worked on 3D model creation
This commit is contained in:
@@ -191,17 +191,39 @@ namespace Floorplan {
|
|||||||
struct Elevator;
|
struct Elevator;
|
||||||
struct GroundTruthPoint;
|
struct GroundTruthPoint;
|
||||||
|
|
||||||
using FloorOutline = std::vector<FloorOutlinePolygon*>;
|
struct FloorOutline : public std::vector<FloorOutlinePolygon*> {
|
||||||
using FloorObstacles = std::vector<FloorObstacle*>;
|
bool enabled = true;
|
||||||
using FloorAccessPoints = std::vector<AccessPoint*>;
|
};
|
||||||
using FloorBeacons = std::vector<Beacon*>;
|
struct FloorObstacles : public std::vector<FloorObstacle*> {
|
||||||
using FloorFingerprintLocations = std::vector<FingerprintLocation*>;
|
bool enabled = true;
|
||||||
using FloorRegions = std::vector<FloorRegion*>;
|
};
|
||||||
using FloorUnderlays = std::vector<UnderlayImage*>;
|
struct FloorAccessPoints : public std::vector<AccessPoint*> {
|
||||||
using FloorPOIs = std::vector<POI*>;
|
bool enabled = true;
|
||||||
using FloorStairs = std::vector<Stair*>;
|
};
|
||||||
using FloorElevators = std::vector<Elevator*>;
|
struct FloorBeacons : public std::vector<Beacon*> {
|
||||||
using FloorGroundTruthPoints = std::vector<GroundTruthPoint*>;
|
bool enabled = true;
|
||||||
|
};
|
||||||
|
struct FloorFingerprintLocations : public std::vector<FingerprintLocation*> {
|
||||||
|
bool enabled = true;
|
||||||
|
};
|
||||||
|
struct FloorRegions : public std::vector<FloorRegion*> {
|
||||||
|
bool enabled = true;
|
||||||
|
};
|
||||||
|
struct FloorUnderlays : public std::vector<UnderlayImage*> {
|
||||||
|
bool enabled = true;
|
||||||
|
};
|
||||||
|
struct FloorPOIs : public std::vector<POI*> {
|
||||||
|
bool enabled = true;
|
||||||
|
};
|
||||||
|
struct FloorStairs : public std::vector<Stair*> {
|
||||||
|
bool enabled = true;
|
||||||
|
};
|
||||||
|
struct FloorElevators : public std::vector<Elevator*> {
|
||||||
|
bool enabled = true;
|
||||||
|
};
|
||||||
|
struct FloorGroundTruthPoints : public std::vector<GroundTruthPoint*> {
|
||||||
|
bool enabled = true;
|
||||||
|
};
|
||||||
|
|
||||||
/** describes one floor within the map, starting at a given height */
|
/** describes one floor within the map, starting at a given height */
|
||||||
struct Floor {
|
struct Floor {
|
||||||
@@ -567,6 +589,8 @@ namespace Floorplan {
|
|||||||
/** describe the floorplan's location on earth */
|
/** describe the floorplan's location on earth */
|
||||||
struct EarthRegistration {
|
struct EarthRegistration {
|
||||||
|
|
||||||
|
bool enabled = true;
|
||||||
|
|
||||||
/** all available correspondences: earth <-> map */
|
/** all available correspondences: earth <-> map */
|
||||||
std::vector<EarthPosMapPos*> correspondences;
|
std::vector<EarthPosMapPos*> correspondences;
|
||||||
|
|
||||||
|
|||||||
@@ -144,8 +144,8 @@ namespace Floorplan {
|
|||||||
|
|
||||||
|
|
||||||
/** parse the <elevators> tag */
|
/** parse the <elevators> tag */
|
||||||
static std::vector<Elevator*> parseFloorElevators(const XMLElem* el) {
|
static FloorElevators parseFloorElevators(const XMLElem* el) {
|
||||||
std::vector<Elevator*> vec;
|
FloorElevators vec;
|
||||||
FOREACH_NODE(n, el) {
|
FOREACH_NODE(n, el) {
|
||||||
if (std::string("elevator") == n->Name()) { vec.push_back(parseFloorElevator(n)); }
|
if (std::string("elevator") == n->Name()) { vec.push_back(parseFloorElevator(n)); }
|
||||||
}
|
}
|
||||||
@@ -153,8 +153,8 @@ namespace Floorplan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** parse the <stairs> tag */
|
/** parse the <stairs> tag */
|
||||||
static std::vector<Stair*> parseFloorStairs(const XMLElem* el) {
|
static FloorStairs parseFloorStairs(const XMLElem* el) {
|
||||||
std::vector<Stair*> vec;
|
FloorStairs vec;
|
||||||
FOREACH_NODE(n, el) {
|
FOREACH_NODE(n, el) {
|
||||||
if (std::string("stair") == n->Name()) { vec.push_back(parseFloorStair(n)); }
|
if (std::string("stair") == n->Name()) { vec.push_back(parseFloorStair(n)); }
|
||||||
}
|
}
|
||||||
@@ -207,8 +207,8 @@ namespace Floorplan {
|
|||||||
|
|
||||||
|
|
||||||
/** parse the <pois> tag */
|
/** parse the <pois> tag */
|
||||||
static std::vector<POI*> parseFloorPOIs(const XMLElem* el) {
|
static FloorPOIs parseFloorPOIs(const XMLElem* el) {
|
||||||
std::vector<POI*> vec;
|
FloorPOIs vec;
|
||||||
FOREACH_NODE(n, el) {
|
FOREACH_NODE(n, el) {
|
||||||
if (std::string("poi") == n->Name()) { vec.push_back(parseFloorPOI(n)); }
|
if (std::string("poi") == n->Name()) { vec.push_back(parseFloorPOI(n)); }
|
||||||
}
|
}
|
||||||
@@ -226,8 +226,8 @@ namespace Floorplan {
|
|||||||
|
|
||||||
|
|
||||||
/** parse the <gtpoints> tag */
|
/** parse the <gtpoints> tag */
|
||||||
static std::vector<GroundTruthPoint*> parseFloorGroundTruthPoints(const XMLElem* el) {
|
static FloorGroundTruthPoints parseFloorGroundTruthPoints(const XMLElem* el) {
|
||||||
std::vector<GroundTruthPoint*> vec;
|
FloorGroundTruthPoints vec;
|
||||||
FOREACH_NODE(n, el) {
|
FOREACH_NODE(n, el) {
|
||||||
if (std::string("gtpoint") == n->Name()) { vec.push_back(parseFloorGroundTruthPoint(n)); }
|
if (std::string("gtpoint") == n->Name()) { vec.push_back(parseFloorGroundTruthPoint(n)); }
|
||||||
}
|
}
|
||||||
@@ -242,10 +242,9 @@ namespace Floorplan {
|
|||||||
return gtp;
|
return gtp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** parse the <accesspoints> tag */
|
/** parse the <accesspoints> tag */
|
||||||
static std::vector<AccessPoint*> parseFloorAccessPoints(const XMLElem* el) {
|
static FloorAccessPoints parseFloorAccessPoints(const XMLElem* el) {
|
||||||
std::vector<AccessPoint*> vec;
|
FloorAccessPoints vec;
|
||||||
FOREACH_NODE(n, el) {
|
FOREACH_NODE(n, el) {
|
||||||
if (std::string("accesspoint") == n->Name()) { vec.push_back(parseAccessPoint(n)); }
|
if (std::string("accesspoint") == n->Name()) { vec.push_back(parseAccessPoint(n)); }
|
||||||
}
|
}
|
||||||
@@ -317,8 +316,8 @@ namespace Floorplan {
|
|||||||
|
|
||||||
|
|
||||||
/** parse the <beacons> tag */
|
/** parse the <beacons> tag */
|
||||||
static std::vector<Beacon*> parseFloorBeacons(const XMLElem* el) {
|
static FloorBeacons parseFloorBeacons(const XMLElem* el) {
|
||||||
std::vector<Beacon*> vec;
|
FloorBeacons vec;
|
||||||
FOREACH_NODE(n, el) {
|
FOREACH_NODE(n, el) {
|
||||||
if (std::string("beacon") == n->Name()) { vec.push_back(parseBeacon(n)); }
|
if (std::string("beacon") == n->Name()) { vec.push_back(parseBeacon(n)); }
|
||||||
}
|
}
|
||||||
@@ -341,9 +340,9 @@ namespace Floorplan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** parse <fingerprints> <location>s */
|
/** parse <fingerprints> <location>s */
|
||||||
static std::vector<FingerprintLocation*> parseFingerprintLocations(const XMLElem* el) {
|
static FloorFingerprintLocations parseFingerprintLocations(const XMLElem* el) {
|
||||||
assertNode("fingerprints", el);
|
assertNode("fingerprints", el);
|
||||||
std::vector<FingerprintLocation*> vec;
|
FloorFingerprintLocations vec;
|
||||||
FOREACH_NODE(n, el) {
|
FOREACH_NODE(n, el) {
|
||||||
if (std::string("location") == n->Name()) { vec.push_back(parseFingerprintLocation(n)); }
|
if (std::string("location") == n->Name()) { vec.push_back(parseFingerprintLocation(n)); }
|
||||||
}
|
}
|
||||||
@@ -363,8 +362,8 @@ namespace Floorplan {
|
|||||||
return fpl;
|
return fpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::vector<FloorRegion*> parseFloorRegions(const XMLElem* el) {
|
static FloorRegions parseFloorRegions(const XMLElem* el) {
|
||||||
std::vector<FloorRegion*> vec;
|
FloorRegions vec;
|
||||||
FOREACH_NODE(n, el) {
|
FOREACH_NODE(n, el) {
|
||||||
if (std::string("region") == n->Name()) { vec.push_back(parseFloorRegion(n)); }
|
if (std::string("region") == n->Name()) { vec.push_back(parseFloorRegion(n)); }
|
||||||
}
|
}
|
||||||
@@ -380,9 +379,9 @@ namespace Floorplan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** parse the <obstacles> tag */
|
/** parse the <obstacles> tag */
|
||||||
static std::vector<FloorObstacle*> parseFloorObstacles(const XMLElem* el) {
|
static FloorObstacles parseFloorObstacles(const XMLElem* el) {
|
||||||
assertNode("obstacles", el);
|
assertNode("obstacles", el);
|
||||||
std::vector<FloorObstacle*> obstacles;
|
FloorObstacles obstacles;
|
||||||
FOREACH_NODE(n, el) {
|
FOREACH_NODE(n, el) {
|
||||||
// if (std::string("wall") == n->Name()) {obstacles.push_back(parseFloorObstacleWall(n));}
|
// if (std::string("wall") == n->Name()) {obstacles.push_back(parseFloorObstacleWall(n));}
|
||||||
// if (std::string("door") == n->Name()) {obstacles.push_back(parseFloorObstacleDoor(n));}
|
// if (std::string("door") == n->Name()) {obstacles.push_back(parseFloorObstacleDoor(n));}
|
||||||
|
|||||||
2
main.cpp
2
main.cpp
@@ -111,7 +111,7 @@ int main(int argc, char** argv) {
|
|||||||
//::testing::GTEST_FLAG(filter) = "*Matrix4*";
|
//::testing::GTEST_FLAG(filter) = "*Matrix4*";
|
||||||
//::testing::GTEST_FLAG(filter) = "*Sphere3*";
|
//::testing::GTEST_FLAG(filter) = "*Sphere3*";
|
||||||
|
|
||||||
::testing::GTEST_FLAG(filter) = "FileReader*";
|
::testing::GTEST_FLAG(filter) = "Ray.ModelFac*";
|
||||||
//::testing::GTEST_FLAG(filter) = "Timestamp*";
|
//::testing::GTEST_FLAG(filter) = "Timestamp*";
|
||||||
|
|
||||||
//::testing::GTEST_FLAG(filter) = "*RayTrace3*";
|
//::testing::GTEST_FLAG(filter) = "*RayTrace3*";
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
#include "../../floorplan/v2/FloorplanReader.h"
|
#include "../../floorplan/v2/FloorplanReader.h"
|
||||||
#include "../../wifi/estimate/ray3/ModelFactory.h"
|
#include "../../wifi/estimate/ray3/ModelFactory.h"
|
||||||
|
|
||||||
|
using namespace Ray3D;
|
||||||
|
|
||||||
struct Wrapper {
|
struct Wrapper {
|
||||||
|
|
||||||
static std::vector<Point3> getVertices(const BBox3& bbox) {
|
static std::vector<Point3> getVertices(const BBox3& bbox) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "../Tests.h"
|
#include "../Tests.h"
|
||||||
#include "../../wifi/estimate/ray3/DataMap3.h"
|
#include "../../wifi/estimate/ray3/DataMap3.h"
|
||||||
|
using namespace Ray3D;
|
||||||
|
|
||||||
TEST(DataMap3, test) {
|
TEST(DataMap3, test) {
|
||||||
|
|
||||||
|
|||||||
@@ -4,17 +4,20 @@
|
|||||||
#include "../../wifi/estimate/ray3/ModelFactory.h"
|
#include "../../wifi/estimate/ray3/ModelFactory.h"
|
||||||
#include "../../floorplan/v2/FloorplanReader.h"
|
#include "../../floorplan/v2/FloorplanReader.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
using namespace Ray3D;
|
||||||
|
|
||||||
TEST(Ray, ModelFac) {
|
TEST(Ray, ModelFac) {
|
||||||
|
|
||||||
std::string file = "/mnt/data/workspaces/IndoorMap/maps/SHL39.xml";
|
std::string file = "/apps/paper/diss/data/maps/SHL41_nm.xml";
|
||||||
Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile(file);
|
Floorplan::IndoorMap* map = Floorplan::Reader::readFromFile(file);
|
||||||
|
|
||||||
ModelFactory fac(map);
|
ModelFactory fac(map);
|
||||||
fac.triangulize();
|
//fac.triangulize();
|
||||||
|
|
||||||
std::ofstream out("/mnt/vm/fhws.obj");
|
FloorplanMesh mesh = fac.getMesh();
|
||||||
out << fac.toOBJ() << std::endl;
|
|
||||||
|
std::ofstream out("/tmp/fhws.ply");
|
||||||
|
out << mesh.toPLY() << std::endl;
|
||||||
out.close();
|
out.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "../../wifi/estimate/ray3/WifiRayTrace3D.h"
|
#include "../../wifi/estimate/ray3/WifiRayTrace3D.h"
|
||||||
#include "../../floorplan/v2/FloorplanReader.h"
|
#include "../../floorplan/v2/FloorplanReader.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
using namespace Ray3D;
|
||||||
|
|
||||||
TEST(RayTrace3, test) {
|
TEST(RayTrace3, test) {
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ TEST(RayTrace3, test) {
|
|||||||
|
|
||||||
ModelFactory fac(map);
|
ModelFactory fac(map);
|
||||||
std::ofstream outOBJ("/tmp/vm/map.obj");
|
std::ofstream outOBJ("/tmp/vm/map.obj");
|
||||||
outOBJ << fac.toOBJ();
|
outOBJ << fac.getMesh().toOBJ();
|
||||||
outOBJ.close();
|
outOBJ.close();
|
||||||
|
|
||||||
const int gs_cm = 50;
|
const int gs_cm = 50;
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include "../../../geo/Triangle3.h"
|
#include "../../../geo/Triangle3.h"
|
||||||
#include "../../../math/Matrix4.h"
|
#include "../../../math/Matrix4.h"
|
||||||
|
|
||||||
|
namespace Ray3D {
|
||||||
|
|
||||||
class Cube {
|
class Cube {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -138,4 +140,6 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // QUBE_H
|
#endif // QUBE_H
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
namespace Ray3D {
|
||||||
|
|
||||||
template <typename T> class DataMap3 {
|
template <typename T> class DataMap3 {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -232,4 +234,6 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // DATAMAP3_H
|
#endif // DATAMAP3_H
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "Obstacle3.h"
|
#include "Obstacle3.h"
|
||||||
|
|
||||||
|
namespace Ray3D {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* meshed version of the floorplan
|
* meshed version of the floorplan
|
||||||
*/
|
*/
|
||||||
@@ -43,6 +45,112 @@ struct FloorplanMesh {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** convert to .ply file format */
|
||||||
|
std::string toPLY() const {
|
||||||
|
|
||||||
|
std::stringstream res;
|
||||||
|
res << "ply\n";
|
||||||
|
res << "format ascii 1.0\n";
|
||||||
|
|
||||||
|
int faces = 0;
|
||||||
|
int vertices = 0;
|
||||||
|
for (const Obstacle3D& obs : elements) {
|
||||||
|
vertices += obs.triangles.size() * 3;
|
||||||
|
faces += obs.triangles.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
// material
|
||||||
|
std::vector<Material> mats = {
|
||||||
|
|
||||||
|
Material(0,128,0,255), // ground outdoor
|
||||||
|
Material(64,64,64,255), // ground outdoor
|
||||||
|
Material(255,96,96,255), // stair
|
||||||
|
|
||||||
|
Material(128,128,128,255), // concrete
|
||||||
|
Material(64,128,255,64), // glass
|
||||||
|
Material(200,200,200,255), // default
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
res << "element material " << mats.size() << "\n";
|
||||||
|
res << "property uchar red\n";
|
||||||
|
res << "property uchar green\n";
|
||||||
|
res << "property uchar blue\n";
|
||||||
|
res << "property uchar alpha\n";
|
||||||
|
|
||||||
|
res << "element vertex " << vertices << "\n";
|
||||||
|
res << "property float x\n";
|
||||||
|
res << "property float y\n";
|
||||||
|
res << "property float z\n";
|
||||||
|
res << "property float nx\n";
|
||||||
|
res << "property float ny\n";
|
||||||
|
res << "property float nz\n";
|
||||||
|
res << "property int material_index\n";
|
||||||
|
res << "property uchar red\n";
|
||||||
|
res << "property uchar green\n";
|
||||||
|
res << "property uchar blue\n";
|
||||||
|
res << "property uchar alpha\n";
|
||||||
|
|
||||||
|
res << "element face " << faces << "\n";
|
||||||
|
res << "property list uchar int vertex_indices\n";
|
||||||
|
|
||||||
|
res << "end_header\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (const Material& mat : mats) {
|
||||||
|
res << mat.r << " " << mat.g << " " << mat.b << " " << mat.a << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const Obstacle3D& obs : elements) {
|
||||||
|
const int matIdx = getMaterial(obs);
|
||||||
|
const Material& mat = mats[matIdx];
|
||||||
|
for (const Triangle3& tria : obs.triangles) {
|
||||||
|
const Point3 n = cross(tria.p2-tria.p1, tria.p3-tria.p1).normalized();
|
||||||
|
res << tria.p1.x << " " << tria.p1.y << " " << tria.p1.z << " " << n.x << " " << n.y << " " << n.z << " " << matIdx << " " << mat.r << " " << mat.g << " " << mat.b << " " << mat.a << "\n";
|
||||||
|
res << tria.p2.x << " " << tria.p2.y << " " << tria.p2.z << " " << n.x << " " << n.y << " " << n.z << " " << matIdx << " " << mat.r << " " << mat.g << " " << mat.b << " " << mat.a <<"\n";
|
||||||
|
res << tria.p3.x << " " << tria.p3.y << " " << tria.p3.z << " " << n.x << " " << n.y << " " << n.z << " " << matIdx << " " << mat.r << " " << mat.g << " " << mat.b << " " << mat.a <<"\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int vidx = 0;
|
||||||
|
for (const Obstacle3D& obs : elements) {
|
||||||
|
for (const Triangle3& tria : obs.triangles) {
|
||||||
|
(void) tria;
|
||||||
|
res << "3 " << vidx++ << " " << vidx++ << " " << vidx++ << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// done
|
||||||
|
return res.str();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Material {
|
||||||
|
int r, g, b, a;
|
||||||
|
Material(int r, int g, int b, int a) : r(r), g(g), b(b), a(a) {;}
|
||||||
|
};
|
||||||
|
|
||||||
|
int getMaterial(const Obstacle3D& o) const {
|
||||||
|
if (o.type == Obstacle3D::Type::GROUND_OUTDOOR) {return 0;}
|
||||||
|
if (o.type == Obstacle3D::Type::GROUND_INDOOR) {return 1;}
|
||||||
|
if (o.type == Obstacle3D::Type::STAIR) {return 2;}
|
||||||
|
|
||||||
|
if (o.mat == Floorplan::Material::CONCRETE) {return 3;}
|
||||||
|
if (o.mat == Floorplan::Material::GLASS) {return 4;}
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Color getColor(const Obstacle3D& o) const {
|
||||||
|
// if (o.type == Obstacle3D::Type::GROUND_OUTDOOR) {return Color(0,128,0,255);}
|
||||||
|
// if (o.type == Obstacle3D::Type::GROUND_INDOOR) {return Color(64,64,64,255);}
|
||||||
|
// if (o.mat == Floorplan::Material::CONCRETE) {return Color(128,128,128,255);}
|
||||||
|
// if (o.mat == Floorplan::Material::GLASS) {return Color(128,128,255,64);}
|
||||||
|
// return Color(200,200,200,255);
|
||||||
|
// }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // FLOORPLANMESH_H
|
#endif // FLOORPLANMESH_H
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include "../../../floorplan/v2/Floorplan.h"
|
#include "../../../floorplan/v2/Floorplan.h"
|
||||||
#include "../../../Assertions.h"
|
#include "../../../Assertions.h"
|
||||||
|
|
||||||
|
namespace Ray3D {
|
||||||
|
|
||||||
/** raytracing attributes for one material */
|
/** raytracing attributes for one material */
|
||||||
struct MaterialAttributes {
|
struct MaterialAttributes {
|
||||||
|
|
||||||
@@ -61,4 +63,6 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // MATERIALOPTIONS_H
|
#endif // MATERIALOPTIONS_H
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#include "Cube.h"
|
#include "Cube.h"
|
||||||
#include "FloorplanMesh.h"
|
#include "FloorplanMesh.h"
|
||||||
|
|
||||||
|
namespace Ray3D {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* convert an indoor map into a 3D model based on triangles
|
* convert an indoor map into a 3D model based on triangles
|
||||||
*/
|
*/
|
||||||
@@ -17,9 +19,13 @@ private:
|
|||||||
|
|
||||||
bool exportCeilings = true;
|
bool exportCeilings = true;
|
||||||
bool exportObstacles = true;
|
bool exportObstacles = true;
|
||||||
|
bool exportStairs = true;
|
||||||
|
bool exportHandrails = true;
|
||||||
|
bool exportDoors = false;
|
||||||
bool exportWallTops = false;
|
bool exportWallTops = false;
|
||||||
std::vector<Floorplan::Floor*> exportFloors;
|
std::vector<Floorplan::Floor*> exportFloors;
|
||||||
|
|
||||||
|
/** the to-be-exported map */
|
||||||
const Floorplan::IndoorMap* map;
|
const Floorplan::IndoorMap* map;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -30,6 +36,7 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** whether or not to export ceilings */
|
||||||
void setExportCeilings(bool exp) {
|
void setExportCeilings(bool exp) {
|
||||||
this->exportCeilings = exp;
|
this->exportCeilings = exp;
|
||||||
}
|
}
|
||||||
@@ -62,6 +69,8 @@ private:
|
|||||||
// process each floor
|
// process each floor
|
||||||
for (const Floorplan::Floor* f : floors) {
|
for (const Floorplan::Floor* f : floors) {
|
||||||
|
|
||||||
|
if (!f->enabled) {continue;}
|
||||||
|
|
||||||
// triangulize the floor itself (floor/ceiling)
|
// triangulize the floor itself (floor/ceiling)
|
||||||
if (exportCeilings) {
|
if (exportCeilings) {
|
||||||
std::vector<Obstacle3D> tmp = getFloor(f);
|
std::vector<Obstacle3D> tmp = getFloor(f);
|
||||||
@@ -69,15 +78,20 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// process each obstacle within the floor
|
// process each obstacle within the floor
|
||||||
|
if (f->obstacles.enabled) {
|
||||||
for (const Floorplan::FloorObstacle* fo : f->obstacles) {
|
for (const Floorplan::FloorObstacle* fo : f->obstacles) {
|
||||||
|
std::vector<Obstacle3D> tmp = getObstacle(f, fo);
|
||||||
// handle line obstacles
|
res.insert(res.end(), tmp.begin(), tmp.end());
|
||||||
const Floorplan::FloorObstacleLine* fol = dynamic_cast<const Floorplan::FloorObstacleLine*>(fo);
|
}
|
||||||
if (fol) {
|
|
||||||
if (fol->type == Floorplan::ObstacleType::HANDRAIL) {continue;}
|
|
||||||
if (exportObstacles) {res.push_back(getTriangles(f, fol));}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stairs
|
||||||
|
if (f->stairs.enabled) {
|
||||||
|
for (const Floorplan::Stair* stair : f->stairs) {
|
||||||
|
|
||||||
|
if (exportStairs) {res.push_back(getStairs(f, stair));}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove
|
// TODO: remove
|
||||||
@@ -97,6 +111,10 @@ private:
|
|||||||
/** convert a floor (floor/ceiling) into triangles */
|
/** convert a floor (floor/ceiling) into triangles */
|
||||||
std::vector<Obstacle3D> getFloor(const Floorplan::Floor* f) {
|
std::vector<Obstacle3D> getFloor(const Floorplan::Floor* f) {
|
||||||
|
|
||||||
|
std::vector<Obstacle3D> res;
|
||||||
|
if (!f->enabled) {return res;}
|
||||||
|
if (!f->outline.enabled) {return res;}
|
||||||
|
|
||||||
// floor uses an outline based on "add" and "remove" areas
|
// floor uses an outline based on "add" and "remove" areas
|
||||||
// we need to create the apropriate triangles to model the polygon
|
// we need to create the apropriate triangles to model the polygon
|
||||||
// including all holes (remove-areas)
|
// including all holes (remove-areas)
|
||||||
@@ -123,8 +141,6 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Obstacle3D> res;
|
|
||||||
|
|
||||||
// create an obstacle for each type (indoor, outdoor)
|
// create an obstacle for each type (indoor, outdoor)
|
||||||
for (auto& it : types) {
|
for (auto& it : types) {
|
||||||
|
|
||||||
@@ -163,40 +179,82 @@ private:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** convert a line obstacle to 3D triangles */
|
/**
|
||||||
Obstacle3D getTriangles(const Floorplan::Floor* f, const Floorplan::FloorObstacleLine* fol) {
|
* @brief build the given obstacle
|
||||||
|
* @param f the floor
|
||||||
/*
|
* @param fo the obstacle
|
||||||
Obstacle3D res(fol->material);
|
* @param aboveDoor whether to place this obstacle ABOVE the given door (overwrite)
|
||||||
|
* @return
|
||||||
Point3 p1(fol->from.x, fol->from.y, f->getStartingZ());
|
|
||||||
Point3 p2(fol->to.x, fol->to.y, f->getStartingZ());
|
|
||||||
Point3 p3(fol->to.x, fol->to.y, f->getEndingZ());
|
|
||||||
Point3 p4(fol->from.x, fol->from.y, f->getEndingZ());
|
|
||||||
|
|
||||||
Triangle3 t1(p1,p2,p3);
|
|
||||||
Triangle3 t2(p1,p3,p4);
|
|
||||||
|
|
||||||
res.triangles.push_back(t1);
|
|
||||||
res.triangles.push_back(t2);
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
std::vector<Obstacle3D> getObstacle(const Floorplan::Floor* f, const Floorplan::FloorObstacle* fo, const Floorplan::FloorObstacleDoor* aboveDoor = nullptr) const {
|
||||||
|
|
||||||
|
std::vector<Obstacle3D> res;
|
||||||
|
|
||||||
|
// handle line obstacles
|
||||||
|
const Floorplan::FloorObstacleLine* fol = dynamic_cast<const Floorplan::FloorObstacleLine*>(fo);
|
||||||
|
if (fol) {
|
||||||
|
if (exportObstacles) {
|
||||||
|
if (fol->type != Floorplan::ObstacleType::HANDRAIL || exportHandrails) {
|
||||||
|
res.push_back(getObstacleLine(f, fol, aboveDoor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Floorplan::FloorObstacleDoor* door = dynamic_cast<const Floorplan::FloorObstacleDoor*>(fo);
|
||||||
|
if (door) {
|
||||||
|
if (exportObstacles) {
|
||||||
|
if (exportDoors) {
|
||||||
|
res.push_back(getDoor(f, door));
|
||||||
|
}
|
||||||
|
//std::vector<Obstacle3D> tmp = getDoorAbove(f, door);
|
||||||
|
//res.insert(res.end(), tmp.begin(), tmp.end());
|
||||||
|
res.push_back(getDoorAbove(f, door));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** convert a line obstacle to 3D triangles */
|
||||||
|
Obstacle3D getObstacleLine(const Floorplan::Floor* f, const Floorplan::FloorObstacleLine* fol, const Floorplan::FloorObstacleDoor* aboveDoor = nullptr) const {
|
||||||
|
|
||||||
|
switch (fol->type) {
|
||||||
|
case Floorplan::ObstacleType::HANDRAIL:
|
||||||
|
return getHandrail(f, fol);
|
||||||
|
case Floorplan::ObstacleType::WINDOW:
|
||||||
|
return getWindow(f, fol, aboveDoor);
|
||||||
|
case Floorplan::ObstacleType::WALL:
|
||||||
|
return getWall(f, fol, aboveDoor);
|
||||||
|
default:
|
||||||
|
throw Exception("invalid obstacle type");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Obstacle3D getWindow(const Floorplan::Floor* f, const Floorplan::FloorObstacleLine* fol, const Floorplan::FloorObstacleDoor* aboveDoor) const {
|
||||||
|
return getWall(f, fol, aboveDoor);
|
||||||
|
}
|
||||||
|
|
||||||
|
Obstacle3D getWall(const Floorplan::Floor* f, const Floorplan::FloorObstacleLine* fol, const Floorplan::FloorObstacleDoor* aboveDoor) const {
|
||||||
|
|
||||||
const float thickness_m = fol->thickness_m;
|
const float thickness_m = fol->thickness_m;
|
||||||
const Point2 from = fol->from;
|
const Point2 from = (!aboveDoor) ? (fol->from) : (aboveDoor->from);
|
||||||
const Point2 to = fol->to;
|
const Point2 to = (!aboveDoor) ? (fol->to) : (aboveDoor->to);
|
||||||
const Point2 cen2 = (from+to)/2;
|
const Point2 cen2 = (from+to)/2;
|
||||||
|
|
||||||
const float rad = std::atan2(to.y - from.y, to.x - from.x);
|
const float rad = std::atan2(to.y - from.y, to.x - from.x);
|
||||||
const float deg = rad * 180 / M_PI;
|
const float deg = rad * 180 / M_PI;
|
||||||
|
|
||||||
// cube's destination center
|
// cube's destination center
|
||||||
const Point3 pos(cen2.x, cen2.y, f->atHeight + f->height/2);
|
const float cenZ = (!aboveDoor) ? (f->atHeight + f->height/2) : (f->getEndingZ() - (f->height - aboveDoor->height) / 2);
|
||||||
|
const float height = (!aboveDoor) ? (f->height) : (f->height - aboveDoor->height);
|
||||||
|
const Point3 pos(cen2.x, cen2.y, cenZ);
|
||||||
|
|
||||||
// div by 2.01 to prevent overlapps and z-fi
|
// div by 2.01 to prevent overlapps and z-fighting
|
||||||
const float sx = from.getDistance(to) / 2.01f;
|
const float sx = from.getDistance(to) / 2;
|
||||||
const float sy = thickness_m / 2.01f;
|
const float sy = thickness_m / 2;
|
||||||
const float sz = f->height / 2.01f; // prevent overlaps
|
const float sz = height / 2.01f; // prevent overlaps
|
||||||
const Point3 size(sx, sy, sz);
|
const Point3 size(sx, sy, sz);
|
||||||
const Point3 rot(0,0,deg);
|
const Point3 rot(0,0,deg);
|
||||||
|
|
||||||
@@ -204,14 +262,147 @@ private:
|
|||||||
Cube cube(pos, size, rot);
|
Cube cube(pos, size, rot);
|
||||||
|
|
||||||
// done
|
// done
|
||||||
Obstacle3D res(Obstacle3D::Type::WALL, fol->material);
|
Obstacle3D res(getType(fol), fol->material);
|
||||||
res.triangles = cube.getTriangles();
|
res.triangles = cube.getTriangles();
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Obstacle3D getDoor(const Floorplan::Floor* f, const Floorplan::FloorObstacleDoor* door) const {
|
||||||
|
|
||||||
|
const float thickness_m = 0.10; // TODO??
|
||||||
|
const Point2 from = door->from;
|
||||||
|
const Point2 to = door->to;
|
||||||
|
const Point2 cen2 = (from+to)/2;
|
||||||
|
|
||||||
|
const float rad = std::atan2(to.y - from.y, to.x - from.x);
|
||||||
|
const float deg = rad * 180 / M_PI;
|
||||||
|
|
||||||
|
// cube's destination center
|
||||||
|
const Point3 pos(cen2.x, cen2.y, f->atHeight + door->height/2);
|
||||||
|
|
||||||
|
// div by 2.01 to prevent overlapps and z-fighting
|
||||||
|
const float sx = from.getDistance(to) / 2;
|
||||||
|
const float sy = thickness_m / 2;
|
||||||
|
const float sz = door->height / 2.01f; // prevent overlaps
|
||||||
|
const Point3 size(sx, sy, sz);
|
||||||
|
const Point3 rot(0,0,deg);
|
||||||
|
|
||||||
|
// build
|
||||||
|
Cube cube(pos, size, rot);
|
||||||
|
|
||||||
|
// done
|
||||||
|
Obstacle3D res(Obstacle3D::Type::DOOR, door->material);
|
||||||
|
res.triangles = cube.getTriangles();
|
||||||
|
return res;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** get the missing part/gap, above the given door */
|
||||||
|
Obstacle3D getDoorAbove(const Floorplan::Floor* f, const Floorplan::FloorObstacleDoor* door) const {
|
||||||
|
|
||||||
|
// find the element above the door (= a connected element)
|
||||||
|
auto comp = [door] (const Floorplan::FloorObstacle* obs) {
|
||||||
|
if (obs == door) {return false;}
|
||||||
|
const Floorplan::FloorObstacleLine* line = dynamic_cast<const Floorplan::FloorObstacleLine*>(obs);
|
||||||
|
if (!line) {return false;}
|
||||||
|
return (line->from == door->from || line->to == door->from || line->from == door->to || line->to == door->to);
|
||||||
|
};
|
||||||
|
auto it = std::find_if(f->obstacles.begin(), f->obstacles.end(), comp);
|
||||||
|
const Floorplan::FloorObstacleLine* line = dynamic_cast<const Floorplan::FloorObstacleLine*> (*it);
|
||||||
|
|
||||||
|
if (!line) {
|
||||||
|
throw Exception("did not find a matching element to place above the door");
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the obstacle to place above the door
|
||||||
|
return getObstacleLine(f, line, door);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Obstacle3D getHandrail(const Floorplan::Floor* f, const Floorplan::FloorObstacleLine* fol) const {
|
||||||
|
|
||||||
|
// target
|
||||||
|
Obstacle3D res(getType(fol), fol->material);
|
||||||
|
if (!exportHandrails) {return res;}
|
||||||
|
|
||||||
|
const float thickness_m = 0.05;
|
||||||
|
const Point2 from = fol->from;
|
||||||
|
const Point2 to = fol->to;
|
||||||
|
const Point2 cen2 = (from+to)/2;
|
||||||
|
|
||||||
|
// edges
|
||||||
|
const float z1 = f->atHeight;
|
||||||
|
const float z2 = f->atHeight + 1.0;
|
||||||
|
Point3 p1 = Point3(from.x, from.y, z1);
|
||||||
|
Point3 p2 = Point3(to.x, to.y, z1);
|
||||||
|
Point3 p3 = Point3(from.x, from.y, z2);
|
||||||
|
Point3 p4 = Point3(to.x, to.y, z2);
|
||||||
|
|
||||||
|
const float rad = std::atan2(to.y - from.y, to.x - from.x);
|
||||||
|
const float deg = rad * 180 / M_PI;
|
||||||
|
|
||||||
|
// cube's destination center
|
||||||
|
const Point3 pUp(cen2.x, cen2.y, z2);
|
||||||
|
|
||||||
|
const float sx = from.getDistance(to) / 2;
|
||||||
|
const float sy = thickness_m / 2;
|
||||||
|
const float sz = thickness_m / 2;
|
||||||
|
const Point3 size(sx, sy, sz);
|
||||||
|
const Point3 rot(0,0,deg);
|
||||||
|
|
||||||
|
// upper bar
|
||||||
|
const Cube cubeUpper(pUp, size, rot);
|
||||||
|
const std::vector<Triangle3> tmp = cubeUpper.getTriangles();
|
||||||
|
res.triangles.insert(res.triangles.end(), tmp.begin(), tmp.end());
|
||||||
|
|
||||||
|
const Point3 d1 = p2-p1;
|
||||||
|
const Point3 d2 = p4-p3;
|
||||||
|
const int numBars = d2.length() / 0.75f;
|
||||||
|
for (int i = 1; i < numBars; ++i) {
|
||||||
|
const Point3 s = p1 + d1 * i / numBars;
|
||||||
|
const Point3 e = p3 + d2 * i / numBars;
|
||||||
|
const Point3 c = (s+e)/2;
|
||||||
|
const Point3 size(thickness_m/2, thickness_m/2, s.getDistance(e)/2 - thickness_m);
|
||||||
|
const Cube cube(c, size, rot);
|
||||||
|
const std::vector<Triangle3> tmp = cube.getTriangles();
|
||||||
|
res.triangles.insert(res.triangles.end(), tmp.begin(), tmp.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
// done
|
||||||
|
return res;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** convert a line obstacle to 3D triangles */
|
||||||
|
Obstacle3D getStairs(const Floorplan::Floor* f, const Floorplan::Stair* s) {
|
||||||
|
|
||||||
|
Obstacle3D res(Obstacle3D::Type::STAIR, Floorplan::Material::CONCRETE);
|
||||||
|
|
||||||
|
std::vector<Floorplan::Quad3> quads = Floorplan::getQuads(s->getParts(), f);
|
||||||
|
for (const Floorplan::Quad3& quad : quads) {
|
||||||
|
const Triangle3 t1(quad.p1, quad.p2, quad.p3);
|
||||||
|
const Triangle3 t2(quad.p3, quad.p4, quad.p1);
|
||||||
|
res.triangles.push_back(t1);
|
||||||
|
res.triangles.push_back(t2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static Obstacle3D::Type getType(const Floorplan::FloorObstacleLine* l) {
|
||||||
|
switch (l->type) {
|
||||||
|
case Floorplan::ObstacleType::WALL: return Obstacle3D::Type::WALL;
|
||||||
|
case Floorplan::ObstacleType::WINDOW: return Obstacle3D::Type::WINDOW;
|
||||||
|
case Floorplan::ObstacleType::HANDRAIL: return Obstacle3D::Type::HANDRAIL;
|
||||||
|
default: return Obstacle3D::Type::UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // MODELFACTORY_H
|
#endif // MODELFACTORY_H
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||||
#include "../../../lib/gpc/gpc.h"
|
#include "../../../lib/gpc/gpc.h"
|
||||||
|
|
||||||
|
namespace Ray3D {
|
||||||
|
|
||||||
class Polygon {
|
class Polygon {
|
||||||
|
|
||||||
struct GPCPolygon : gpc_polygon {
|
struct GPCPolygon : gpc_polygon {
|
||||||
@@ -102,4 +104,6 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // MODELFACTORYHELPER_H
|
#endif // MODELFACTORYHELPER_H
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include "../../../floorplan/v2/Floorplan.h"
|
#include "../../../floorplan/v2/Floorplan.h"
|
||||||
|
|
||||||
|
namespace Ray3D {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 3D obstacle
|
* 3D obstacle
|
||||||
* based on multiple triangles
|
* based on multiple triangles
|
||||||
@@ -19,8 +21,10 @@ struct Obstacle3D {
|
|||||||
GROUND_INDOOR,
|
GROUND_INDOOR,
|
||||||
GROUND_OUTDOOR,
|
GROUND_OUTDOOR,
|
||||||
STAIR,
|
STAIR,
|
||||||
|
HANDRAIL,
|
||||||
DOOR,
|
DOOR,
|
||||||
WALL,
|
WALL,
|
||||||
|
WINDOW,
|
||||||
};
|
};
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
@@ -35,5 +39,6 @@ struct Obstacle3D {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // OBSTACLE3_H
|
#endif // OBSTACLE3_H
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
// http://graphics.stanford.edu/courses/cs148-10-summer/docs/2006--degreve--reflection_refraction.pdf
|
// http://graphics.stanford.edu/courses/cs148-10-summer/docs/2006--degreve--reflection_refraction.pdf
|
||||||
|
|
||||||
|
|
||||||
|
namespace Ray3D {
|
||||||
|
|
||||||
struct Intersection {
|
struct Intersection {
|
||||||
Point3 pos;
|
Point3 pos;
|
||||||
const Obstacle3D* obs;
|
const Obstacle3D* obs;
|
||||||
@@ -198,7 +200,7 @@ public:
|
|||||||
dm.resize(bbox, gs);
|
dm.resize(bbox, gs);
|
||||||
|
|
||||||
ModelFactory fac(map);
|
ModelFactory fac(map);
|
||||||
std::vector<Obstacle3D> obstacles = fac.triangulize();
|
std::vector<Obstacle3D> obstacles = fac.getMesh().elements;
|
||||||
|
|
||||||
// build bounding volumes
|
// build bounding volumes
|
||||||
for (Obstacle3D& obs : obstacles) {
|
for (Obstacle3D& obs : obstacles) {
|
||||||
@@ -503,9 +505,8 @@ private:
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // WIFIRAYTRACE3D_H
|
#endif // WIFIRAYTRACE3D_H
|
||||||
|
|||||||
Reference in New Issue
Block a user