started working on walling, dooring and windowing

refactoring
This commit is contained in:
k-a-z-u
2018-07-25 16:21:47 +02:00
parent f7e4323d58
commit 0d22d91470
9 changed files with 368 additions and 48 deletions

View File

@@ -157,6 +157,12 @@ namespace Floorplan {
_END,
};
/** available window types */
enum class WindowType {
UNKNOWN,
_END,
};
/** all supported material types */
enum class Material {
UNKNOWN,
@@ -193,6 +199,7 @@ namespace Floorplan {
struct Elevator;
struct GroundTruthPoint;
struct FloorObstacleWallDoor;
struct FloorObstacleWallWindow;
struct FloorOutline : public std::vector<FloorOutlinePolygon*> {
bool enabled = true;
@@ -351,7 +358,6 @@ namespace Floorplan {
Point2 to;
float thickness_m;
float height_m = 0; // 0 = floor's height
std::vector<FloorObstacleWallDoor*> doors;
FloorObstacleLine(const ObstacleType type, const Material material, const Point2 from, const Point2 to, const float thickness_m = 0.2f, const float height_m = 0) : FloorObstacle(material), type(type), from(from), to(to), thickness_m(thickness_m), height_m(height_m) {;}
FloorObstacleLine(const ObstacleType type, const Material material, const float x1, const float y1, const float x2, const float y2, const float thickness_m = 0.2f, const float height_m = 0) : FloorObstacle(material), type(type), from(x1,y1), to(x2,y2), thickness_m(thickness_m), height_m(height_m) {;}
};
@@ -378,7 +384,21 @@ namespace Floorplan {
float getSize() const {return (to-from).length();}
};
/** door obstacle */
/** wall obstacle */
struct FloorObstacleWall: public FloorObstacle {
ObstacleType type;
Point2 from;
Point2 to;
float thickness_m;
float height_m = 0; // 0 = floor's height
std::vector<FloorObstacleWallDoor*> doors;
std::vector<FloorObstacleWallWindow*> windows;
FloorObstacleWall(const ObstacleType type, const Material material, const Point2 from, const Point2 to, const float thickness_m = 0.2f, const float height_m = 0) : FloorObstacle(material), type(type), from(from), to(to), thickness_m(thickness_m), height_m(height_m) {;}
FloorObstacleWall(const ObstacleType type, const Material material, const float x1, const float y1, const float x2, const float y2, const float thickness_m = 0.2f, const float height_m = 0) : FloorObstacle(material), type(type), from(x1,y1), to(x2,y2), thickness_m(thickness_m), height_m(height_m) {;}
};
/** wall->door obstacle */
struct FloorObstacleWallDoor : public FloorObstacle {
DoorType type;
float atLinePos;
@@ -386,17 +406,40 @@ namespace Floorplan {
float height;
bool leftRight = false;
bool inOut = false;
FloorObstacleWallDoor(const DoorType type, const Material material, const float atLinePos, const float width, const float height) : FloorObstacle(material), type(type), atLinePos(atLinePos), width(width), height(height) {;}
Point2 getStart(const FloorObstacleLine* wall) const {
FloorObstacleWallDoor(const DoorType type, const Material material, const float atLinePos, const float width, const float height, const bool lr = false, const bool io = false) : FloorObstacle(material), type(type), atLinePos(atLinePos), width(width), height(height), leftRight(lr), inOut(io) {;}
Point2 getStart(const FloorObstacleWall* wall) const {
const Point2 dir = wall->to - wall->from;
return wall->from + dir * atLinePos;
}
Point2 getEnd(const FloorObstacleLine* wall) const {
Point2 getEnd(const FloorObstacleWall* wall) const {
const Point2 dir = wall->to - wall->from;
return getStart(wall) + dir.normalized() * (leftRight ? -width : +width);
}
};
/** wall->window obstacle */
struct FloorObstacleWallWindow : public FloorObstacle {
WindowType type;
float atLinePos;
float startsAtHeight;
float width;
float height;
bool leftRight = false;
bool inOut = false;
FloorObstacleWallWindow(const WindowType type, const Material material, const float atLinePos, const float startsAtHeight, const float width, const float height, const bool lr = false, const bool io = false) : FloorObstacle(material), type(type), atLinePos(atLinePos), startsAtHeight(startsAtHeight), width(width), height(height), leftRight(lr), inOut(io) {;}
Point2 getStart(const FloorObstacleWall* wall) const {
const Point2 dir = wall->to - wall->from;
const Point2 cen = wall->from + dir * atLinePos;
return cen - dir.normalized() * width/2;
}
Point2 getEnd(const FloorObstacleWall* wall) const {
const Point2 dir = wall->to - wall->from;
const Point2 cen = wall->from + dir * atLinePos;
return cen + dir.normalized() * width/2;
}
};
/** 3D obstacle */
struct FloorObstacleObject : public FloorObstacle {
std::string file;

View File

@@ -388,6 +388,7 @@ namespace Floorplan {
// if (std::string("window") == n->Name()) {obstacles.push_back(parseFloorObstacleWindow(n));}
// if (std::string("pillar") == n->Name()) {obstacles.push_back(parseFloorObstaclePillar(n));}
//if (std::string("obstacle") == n->Name()) {obstacles.push_back(parseFloorObstacleLine(n));} // OLD
if (std::string("wall") == n->Name()) {obstacles.push_back(parseFloorObstacleWall(n));}
if (std::string("line") == n->Name()) {obstacles.push_back(parseFloorObstacleLine(n));}
if (std::string("circle") == n->Name()) {obstacles.push_back(parseFloorObstacleCircle(n));}
if (std::string("door") == n->Name()) {obstacles.push_back(parseFloorObstacleDoor(n));}
@@ -396,6 +397,38 @@ namespace Floorplan {
return obstacles;
}
/** parse one wall */
static FloorObstacleWall* parseFloorObstacleWall(const XMLElem* el) {
FloorObstacleWall* wall = new FloorObstacleWall(
parseObstacleType(el->Attribute("type")),
parseMaterial(el->Attribute("material")),
el->FloatAttribute("x1"), el->FloatAttribute("y1"),
el->FloatAttribute("x2"), el->FloatAttribute("y2"),
(el->FloatAttribute("thickness") > 0) ? (el->FloatAttribute("thickness")) : (0.15), // default wall thickness in m
el->FloatAttribute("height")
);
// doors
FOREACH_NODE(n, el) {
if (std::string("door") == n->Name()) {
FloorObstacleWallDoor* door = new FloorObstacleWallDoor(
parseDoorType(n->Attribute("type")),
parseMaterial(n->Attribute("material")),
n->FloatAttribute("at"),
n->FloatAttribute("width"),
n->FloatAttribute("height"),
n->BoolAttribute("lr"),
n->BoolAttribute("io")
);
wall->doors.push_back(door);
}
}
return wall;
}
/** parse one line */
static FloorObstacleLine* parseFloorObstacleLine(const XMLElem* el) {
return new FloorObstacleLine(

View File

@@ -311,6 +311,8 @@ namespace Floorplan {
for (FloorObstacle* fo : mf->obstacles) {
if (dynamic_cast<FloorObstacleLine*>(fo)) {
addFloorObstacleLine(doc, obstacles, (FloorObstacleLine*)fo);
} else if (dynamic_cast<FloorObstacleWall*>(fo)) {
addFloorObstacleWall(doc, obstacles, (FloorObstacleWall*)fo);
} else if (dynamic_cast<FloorObstacleCircle*>(fo)) {
addFloorObstacleCircle(doc, obstacles, (FloorObstacleCircle*)fo);
} else if (dynamic_cast<FloorObstacleDoor*>(fo)) {
@@ -324,7 +326,40 @@ namespace Floorplan {
}
/** write a line obstacle (wall, handrail, ..) */
/** write a wall obstacle (wall) */
static void addFloorObstacleWall(XMLDoc& doc, XMLElem* obstacles, FloorObstacleWall* wall) {
XMLElem* oWall = doc.NewElement("wall");
obstacles->InsertEndChild(oWall);
oWall->SetAttribute("material", toString(wall->material).c_str());
oWall->SetAttribute("type", toString(wall->type).c_str());
oWall->SetAttribute("x1", wall->from.x);
oWall->SetAttribute("y1", wall->from.y);
oWall->SetAttribute("x2", wall->to.x);
oWall->SetAttribute("y2", wall->to.y);
oWall->SetAttribute("thickness", wall->thickness_m);
if (wall->height_m != 0) {oWall->SetAttribute("height", wall->height_m);}
// doors?
for (const FloorObstacleWallDoor* door : wall->doors) {
XMLElem* oDoor = doc.NewElement("door");
oWall->InsertEndChild(oDoor);
oDoor->SetAttribute("type", toString(door->type).c_str());
oDoor->SetAttribute("material", toString(door->material).c_str());
oDoor->SetAttribute("at", door->atLinePos);
oDoor->SetAttribute("width", door->width);
oDoor->SetAttribute("height", door->height);
oDoor->SetAttribute("io", door->inOut);
oDoor->SetAttribute("lr", door->leftRight);
}
}
/** write a line obstacle (old walls, handrail, ..) */
static void addFloorObstacleLine(XMLDoc& doc, XMLElem* obstacles, FloorObstacleLine* line) {
XMLElem* obstacle = doc.NewElement("line");
obstacle->SetAttribute("material", toString(line->material).c_str());