refactored the new floorplan

new helper methods/operator toe geo classes
This commit is contained in:
kazu
2016-05-24 17:01:56 +02:00
parent d0801606b7
commit 51cab55d37
10 changed files with 937 additions and 9 deletions

188
floorplan/v2/Floorplan.h Normal file
View File

@@ -0,0 +1,188 @@
#ifndef FLOORPLAN_H
#define FLOORPLAN_H
#include <string>
#include <vector>
#include <initializer_list>
#include <unordered_map>
#include "../../geo/Point3.h"
#include "../../geo/Point2.h"
namespace Floorplan {
/** 3D polygon */
struct Polygon2 {
std::vector<Point2> points;
Polygon2() : points() {;}
Polygon2(const std::initializer_list<Point2> lst) : points(lst) {;}
bool operator == (const Polygon2& o) const {return std::equal(o.points.begin(), o.points.end(), this->points.begin());}
};
/** additional type-info for obstacles */
enum class ObstacleType {
UNKNOWN,
WALL,
DOOR,
WINDOW,
HANDRAIL,
PILLAR,
_END,
};
/** all supported material types */
enum class Material {
UNKNOWN,
CONCRETE,
WOOD,
DRYWALL,
GLASS,
_END,
};
/** types of outlines. either add or remove the selected region */
enum class OutlineMethod {
ADD,
REMOVE,
_END,
};
/** an AccessPoint located somewhere within the map */
struct AccessPoint {
std::string name;
std::string mac;
Point3 pos;
AccessPoint() : name(), mac(), pos() {;}
AccessPoint(const std::string& name, const std::string& mac, const Point3& pos) : name(name), mac(mac), pos(pos) {;}
bool operator == (const AccessPoint& o) const {return (o.name == name) && (o.mac == mac) && (o.pos == pos);}
};
/** a beacon located somewhere within the map */
struct Beacon {
std::string name;
std::string mac;
Point3 pos;
Beacon() : name(), mac(), pos() {;}
Beacon(const std::string& name, const std::string& mac, const Point3& pos) : name(name), mac(mac), pos(pos) {;}
bool operator == (const Beacon& o) const {return (o.name == name) && (o.mac == mac) && (o.pos == pos);}
};
/** a polygon denoting a floor's outline. is either added or removed */
struct FloorOutlinePolygon {
OutlineMethod method;
std::string name;
Polygon2 poly;
FloorOutlinePolygon() : method(OutlineMethod::ADD), name(), poly() {;}
FloorOutlinePolygon(const OutlineMethod method, const std::string& name, const Polygon2& poly) : method(method), name(name), poly(poly) {;}
bool operator == (const FloorOutlinePolygon& o) const {return (o.method == method) && (o.name == name) && (o.poly == poly);}
};
/** base-class for one obstacle (wall, door, window, pillar, ..) within a floor */
struct FloorObstacle {
ObstacleType type;
Material material;
FloorObstacle() : type(), material() {;}
FloorObstacle(const ObstacleType type, const Material material) : type(type), material(material) {;}
virtual ~FloorObstacle() {;}
};
/** line obstacle */
struct FloorObstacleLine : public FloorObstacle {
Point2 from;
Point2 to;
FloorObstacleLine(const ObstacleType type, const Material material, const Point2 from, const Point2 to) : FloorObstacle(type, material), from(from), to(to) {;}
FloorObstacleLine(const ObstacleType type, const Material material, const float x1, const float y1, const float x2, const float y2) : FloorObstacle(type, material), from(x1,y1), to(x2,y2) {;}
};
/** circle obstacle */
struct FloorObstacleCircle : public FloorObstacle {
Point2 center;
float radius;
FloorObstacleCircle(const ObstacleType type, const Material material, const Point2 center, const float radius) : FloorObstacle(type, material), center(center), radius(radius) {;}
FloorObstacleCircle(const ObstacleType type, const Material material, const float cx, const float cy, const float radius) : FloorObstacle(type, material), center(cx,cy), radius(radius) {;}
};
/** one region (e.g. a room) within the floor, described using a polygon */
struct FloorRegion {
std::string name;
Polygon2 poly;
FloorRegion() : name(), poly() {;}
FloorRegion(const std::string& name, const Polygon2& poly) : name(name), poly(poly) {;}
};
/** an image file that can be added to the map */
struct UnderlayImage {
std::string name;
std::string filename;
Point2 anchor;
float scaleX;
float scaleY;
};
/** a free key-value element */
struct KeyValueElement {
std::string empty;
std::unordered_map<std::string, std::string> params;
const std::string& getVal(const std::string& key) const {
auto it = params.find(key);
return (it == params.end()) ? (empty) : (it->second);
}
float getFloat(const std::string& key) const { return std::stof(getVal(key)); }
void setVal(const std::string& key, const std::string& val) {
params[key] = val;
}
void setFloat(const std::string& key, const float val) {
params[key] = std::to_string(val);
}
};
using FloorOutline = std::vector<FloorOutlinePolygon*>;
using FloorObstacles = std::vector<FloorObstacle*>;
using FloorAccessPoints = std::vector<AccessPoint*>;
using FloorBeacons = std::vector<Beacon*>;
using FloorRegions = std::vector<FloorRegion*>;
using FloorUnderlays = std::vector<UnderlayImage*>;
/** describes one floor within the map, starting at a given height */
struct Floor {
float atHeight; // the floor's starting height
float height; // the floor's total height (from start)
std::string name; // the floor's name
FloorOutline outline; // the floor's outline (ground)
FloorObstacles obstacles; // all obstacles (wall, door, window, ..) within the floor
FloorRegions regions; // all regions within the floor (rooms, ...)
FloorAccessPoints accesspoints;
FloorBeacons beacons;
FloorUnderlays underlays; // underlay images (used for map-building)
//FloorKeyValue other; // other, free elements
Floor() {;}
Floor(const Floor& o) = delete;
void operator = (const Floor& o) = delete;
};
/** describes the whole indoor map */
struct IndoorMap {
float width;
float depth;
std::vector<Floor*> floors;
IndoorMap() {;}
IndoorMap(const IndoorMap& o) = delete;
void operator = (const IndoorMap& o) = delete;
};
}
#endif // FLOORPLAN_H