added support for pillars

some new helper methods/classes
This commit is contained in:
2018-05-22 11:45:35 +02:00
parent a22290415e
commit 9e6d9f4ce7
13 changed files with 185 additions and 9 deletions

View File

@@ -165,6 +165,7 @@ namespace Floorplan {
DRYWALL,
GLASS,
METAL,
METALLIZED_GLAS,
_END,
};
@@ -356,8 +357,10 @@ namespace Floorplan {
struct FloorObstacleCircle : public FloorObstacle {
Point2 center;
float radius;
FloorObstacleCircle(const Material material, const Point2 center, const float radius) : FloorObstacle(material), center(center), radius(radius) {;}
FloorObstacleCircle(const Material material, const float cx, const float cy, const float radius) : FloorObstacle(material), center(cx,cy), radius(radius) {;}
float height = 0; // 0 = floor's height
FloorObstacleCircle(const Material material, const Point2 center, const float radius, const float height=0) : FloorObstacle(material), center(center), radius(radius), height(height) {;}
FloorObstacleCircle(const Material material, const float cx, const float cy, const float radius, const float height=0) : FloorObstacle(material), center(cx,cy), radius(radius), height(height) {;}
//float getHeight(const Floor* f) const {return (height > 0) ? (height) : (f->height);}
};
/** door obstacle */

View File

@@ -29,6 +29,18 @@ public:
return std::make_pair(nullptr, nullptr);
}
/** get the AP for the given Name [if available] */
static std::pair<Floorplan::AccessPoint*, Floorplan::Floor*> getAPByName(const Floorplan::IndoorMap* map, const std::string& name) {
for (Floorplan::Floor* f : map->floors) {
for (Floorplan::AccessPoint* ap : f->accesspoints) {
if (name == ap->name) {
return std::make_pair(ap, f);
}
}
}
return std::make_pair(nullptr, nullptr);
}
/** get all APs within the map */
static std::vector<std::pair<Floorplan::AccessPoint*, Floorplan::Floor*>> getAPs(const Floorplan::IndoorMap* map) {
std::vector<std::pair<Floorplan::AccessPoint*, Floorplan::Floor*>> res;
@@ -40,6 +52,18 @@ public:
return res;
}
/** get the Fingerprint-Loation for the given Name [if available] */
static std::pair<Floorplan::FingerprintLocation*, Floorplan::Floor*> getFingerprintLocationByName(const Floorplan::IndoorMap* map, const std::string& name) {
for (Floorplan::Floor* f : map->floors) {
for (Floorplan::FingerprintLocation* fpl : f->fpLocations) {
if (name == fpl->name) {
return std::make_pair(fpl, f);
}
}
}
return std::make_pair(nullptr, nullptr);
}
/** get all ground-truth points within the map as hash-map: id->pos */
static std::unordered_map<int, Point3> getGroundTruthPoints(const Floorplan::IndoorMap* map) {
std::unordered_map<int, Point3> res;

View File

@@ -412,7 +412,8 @@ namespace Floorplan {
return new FloorObstacleCircle(
parseMaterial(el->Attribute("material")),
el->FloatAttribute("cx"), el->FloatAttribute("cy"),
el->FloatAttribute("radius")
el->FloatAttribute("radius"),
el->FloatAttribute("height")
);
}

View File

@@ -344,6 +344,7 @@ namespace Floorplan {
obstacle->SetAttribute("cx", circle->center.x);
obstacle->SetAttribute("cy", circle->center.y);
obstacle->SetAttribute("radius", circle->radius);
obstacle->SetAttribute("height", circle->height);
obstacles->InsertEndChild(obstacle);
}

View File

@@ -2,6 +2,7 @@
#define WIFIMEASUREMENTS_H
#include <vector>
#include <algorithm>
#include "WiFiMeasurement.h"
@@ -42,6 +43,14 @@ struct WiFiMeasurements {
}
}
/** get the oldest timestamp among all contained measurements */
Timestamp getOldestTS() const {
auto comp = [] (const WiFiMeasurement& m1, const WiFiMeasurement& m2) {return m1.getTimestamp() < m2.getTimestamp();};
auto it = std::max_element(entries.begin(), entries.end(), comp);
if (it == entries.end()) {throw Exception("no element found");}
return it->getTimestamp();
}
/** create a combination */
static WiFiMeasurements mix(const WiFiMeasurements& a, const WiFiMeasurements& b, float sec = 3) {

View File

@@ -12,6 +12,8 @@ class WiFiModelFactory {
private:
static constexpr const char* name = "WifiModelFac";
Floorplan::IndoorMap* map;
public:

View File

@@ -7,6 +7,7 @@
#include "WiFiModelPerFloor.h"
#include "WiFiModelPerBBox.h"
WiFiModel* WiFiModelFactory::loadXML(const std::string& file) {
XMLDoc doc;
@@ -25,10 +26,10 @@ WiFiModel* WiFiModelFactory::readFromXML(XMLDoc* doc, XMLElem* src) {
WiFiModel* mdl = nullptr;
// create an instance for the model
if (type == "WiFiModelLogDist") {mdl = new WiFiModelLogDist();}
else if (type == "WiFiModelLogDistCeiling") {mdl = new WiFiModelLogDistCeiling(map);}
else if (type == "WiFiModelPerFloor") {mdl = new WiFiModelPerFloor(map);}
else if (type == "WiFiModelPerBBox") {mdl = new WiFiModelPerBBox(map);}
if (type == "WiFiModelLogDist") {Log::add(name, "loading WiFiModelLogDist"); mdl = new WiFiModelLogDist();}
else if (type == "WiFiModelLogDistCeiling") {Log::add(name, "loading WiFiModelLogDistCeiling"); mdl = new WiFiModelLogDistCeiling(map);}
else if (type == "WiFiModelPerFloor") {Log::add(name, "loading WiFiModelPerFloor"); mdl = new WiFiModelPerFloor(map);}
else if (type == "WiFiModelPerBBox") {Log::add(name, "loading WiFiModelPerBBox"); mdl = new WiFiModelPerBBox(map);}
else {throw Exception("invalid model type given: " + type);}
// load the model from XML

View File

@@ -18,6 +18,8 @@
*/
class WiFiModelLogDistCeiling : public WiFiModel {
static constexpr const char* name = "WifiModelLDC";
public:
/** parameters describing one AP to the model */
@@ -224,6 +226,8 @@ public:
ceilings.addCeiling(atHeight_m);
}
Log::add(name, "loaded " + std::to_string(accessPoints.size()) + " APs");
}
};

View File

@@ -14,6 +14,8 @@
*/
class WiFiModelPerFloor : public WiFiModel {
static constexpr const char* name = "WiFiModelFlo";
public:
struct ModelForFloor {
@@ -173,6 +175,8 @@ public:
}
Log::add(name, "loaded " + std::to_string(models.size()) + " floor models");
}
void writeToXML(XMLDoc* doc, XMLElem* dst) override {

View File

@@ -74,14 +74,14 @@ namespace WiFiOptimizer {
float exp;
float waf;
Point3 getPos() const {return Point3(x,y,z);}
/** ctor */
APParams() {;}
/** ctor */
APParams(float x, float y, float z, float txp, float exp, float waf) : x(x), y(y), z(z), txp(txp), exp(exp), waf(waf) {;}
Point3 getPos() const {return Point3(x,y,z);}
std::string asString() const {
std::stringstream ss;
ss << "Pos:" << getPos().asString() << " TXP:" << txp << " EXP:" << exp << " WAF:" << waf;

View File

@@ -0,0 +1,82 @@
#ifndef CYLINDER_H
#define CYLINDER_H
#include "../../../math/Matrix4.h"
#include "Mesh.h"
namespace Ray3D {
/** walled cylinder */
class Cylinder : public Mesh {
public:
/** ctor */
Cylinder() {
;
}
/** get a transformed version */
Cylinder transformed(const Matrix4& mat) const {
Cylinder res = *this;
res.transform(mat);
return res;
}
/** build */
void add(const float rOuter, const float h, bool topAndBottom) {
const int tiles = 8;
const float deg_per_tile = 360.0f / tiles;
const float rad_per_tile = deg_per_tile / 180.0f * M_PI;
for (int i = 0; i < tiles; ++i) {
const float startRad = (i+0) * rad_per_tile;
const float endRad = (i+1) * rad_per_tile;
const float xo0 = std::cos(startRad) * rOuter;
const float yo0 = std::sin(startRad) * rOuter;
const float xo1 = std::cos(endRad) * rOuter;
const float yo1 = std::sin(endRad) * rOuter;
const float cx = 0;
const float cy = 0;
// outer
addQuad(
Point3(xo0, yo0, -h),
Point3(xo1, yo1, -h),
Point3(xo1, yo1, +h),
Point3(xo0, yo0, +h)
);
if (topAndBottom) {
// top
addTriangle(
Point3(cx, cy, h),
Point3(xo0, yo0, h),
Point3(xo1, yo1, h)
);
// bottom
addTriangle(
Point3(cx, cy, -h),
Point3(xo1, yo1, -h),
Point3(xo0, yo0, -h)
);
}
}
}
};
}
#endif // CYLINDER_H

View File

@@ -28,6 +28,11 @@ namespace Ray3D {
transform(mat);
}
void translate(const Point3 pos) {
const Matrix4 mPos = Matrix4::getTranslation(pos.x, pos.y, pos.z);
transform(mPos);
}
void transform(const Matrix4& mat) {
for (Triangle3& tria : trias) {
@@ -53,6 +58,10 @@ namespace Ray3D {
trias.push_back( Triangle3(p1,p3,p4) );
}
void addTriangle(Point3 p1, Point3 p2, Point3 p3) {
trias.push_back( Triangle3(p1,p2,p3) );
}
};
}

View File

@@ -8,6 +8,7 @@
#include "Obstacle3.h"
#include "Cube.h"
#include "Tube.h"
#include "Cylinder.h"
#include "FloorplanMesh.h"
#include "OBJPool.h"
@@ -219,6 +220,14 @@ namespace Ray3D {
}
}
// handle circle obstacles
const Floorplan::FloorObstacleCircle* foc = dynamic_cast<const Floorplan::FloorObstacleCircle*>(fo);
if (foc) {
if (exportObstacles) {
res.push_back(getPillar(f, foc));
}
}
// handle object obstacles
const Floorplan::FloorObstacleObject* foo = dynamic_cast<const Floorplan::FloorObstacleObject*>(fo);
if (foo) {
@@ -267,6 +276,27 @@ namespace Ray3D {
return getWall(f, fol, aboveDoor);
}
Obstacle3D getPillar(const Floorplan::Floor* f, const Floorplan::FloorObstacleCircle* foc) const {
FloorPos fpos(f);
// attributes
const float r = foc->radius;
const float h = (foc->height > 0) ? (foc->height) : (fpos.height);
const Point3 pos(foc->center.x, foc->center.y, fpos.z1 + h/2);
// build
Cylinder cyl;
cyl.add(r, h/2, true);
cyl.translate(pos);
// done
Obstacle3D res(getType(foc), foc->material);
res.triangles = cyl.getTriangles();
return res;
}
Obstacle3D getWall(const Floorplan::Floor* f, const Floorplan::FloorObstacleLine* fol, const Floorplan::FloorObstacleDoor* aboveDoor) const {
FloorPos fpos(f);
@@ -310,6 +340,7 @@ namespace Ray3D {
Obstacle3D obs = OBJPool::get().getObject(name);
obs = obs.rotated_deg( Point3(foo->rot.x, foo->rot.y, foo->rot.z) );
obs = obs.translated(foo->pos + Point3(0,0,fpos.z1));
obs.type = Obstacle3D::Type::OBJECT;
// std::vector<Triangle3> trias;
// for (const OBJReader::Face& face : reader.getData().faces) {
@@ -642,6 +673,11 @@ namespace Ray3D {
}
}
static Obstacle3D::Type getType(const Floorplan::FloorObstacleCircle* c) {
(void) c;
return Obstacle3D::Type::WALL;
}
/** used to model ceiling thickness */
struct FloorPos {
float fh;