From baeb8bef11f70108ed3bdde9414e50552184375d Mon Sep 17 00:00:00 2001 From: k-a-z-u Date: Wed, 25 Jul 2018 18:12:48 +0200 Subject: [PATCH] worked on windows --- floorplan/3D/WallsViaCuttedQuads.h | 59 ++++++++++++++++++++++++++---- floorplan/v2/Floorplan.h | 3 +- floorplan/v2/FloorplanReader.h | 22 ++++++++++- floorplan/v2/FloorplanWriter.h | 19 +++++++++- 4 files changed, 91 insertions(+), 12 deletions(-) diff --git a/floorplan/3D/WallsViaCuttedQuads.h b/floorplan/3D/WallsViaCuttedQuads.h index 227bad2..a8e119d 100644 --- a/floorplan/3D/WallsViaCuttedQuads.h +++ b/floorplan/3D/WallsViaCuttedQuads.h @@ -264,7 +264,6 @@ namespace Floorplan3D { strip.add(p4); for (const Floorplan::FloorObstacleWallDoor* door : doors) { - Polygon2 pDoor; const Point2 pds = door->getStart(wall.line); const Point2 pde = door->getEnd(wall.line); @@ -274,17 +273,17 @@ namespace Floorplan3D { const Point3 dp2u(pde.x, pde.y, z1+door->height); const Point3 dp1u(pds.x, pds.y, z1+door->height); - //auto flattenD1 = [dp1,a] (const Point3 p) {return (p - dp1).rotZ(-a).xz();}; - //auto unFlatten1 = [dp1,a] (const Point3 p) {return Point3(p.x, 0, p.y).rotZ(a)+dp1;}; - + Polygon2 pDoor; pDoor.add(flatten(dp1)); pDoor.add(flatten(dp2)); pDoor.add(flatten(dp2u)); pDoor.add(flatten(dp1u)); + // wall cutout (front/back) gpFront.remove(pDoor); gpBack.remove(pDoor); + // 3D framing strip.add(unFlattenFront2(pDoor[0])); strip.add(unFlattenBack2(pDoor[0])); @@ -313,11 +312,55 @@ namespace Floorplan3D { obs.triangles.push_back(t); } -// std::vector ptsToConnect3; -// for (const Point2 p2 : ptsToConnect) { -// const Point3 p3 = unf -// } + // process all windows within the wall + for (const Floorplan::FloorObstacleWallWindow* win : wall.line->windows) { + + const Point2 pws = win->getStart(wall.line); + const Point2 pwe = win->getEnd(wall.line); + + const float wz1 = z1 + win->startsAtHeight; + const float wz2 = z1 + win->startsAtHeight + win->height; + + const Point3 dp1(pws.x, pws.y, wz1); + const Point3 dp2(pwe.x, pwe.y, wz1); + const Point3 dp2u(pwe.x, pwe.y, wz2); + const Point3 dp1u(pws.x, pws.y, wz2); + + Polygon2 pWindow; + pWindow.add(flatten(dp1)); + pWindow.add(flatten(dp2)); + pWindow.add(flatten(dp2u)); + pWindow.add(flatten(dp1u)); + + // wall cutout (front/back) + gpFront.remove(pWindow); + gpBack.remove(pWindow); + + // 3D framing + TriangleStrip strip; + + strip.add(unFlattenFront2(pWindow[0])); + strip.add(unFlattenBack2(pWindow[0])); + + strip.add(unFlattenFront2(pWindow[3])); + strip.add(unFlattenBack2(pWindow[3])); + + strip.add(unFlattenFront2(pWindow[2])); + strip.add(unFlattenBack2(pWindow[2])); + + strip.add(unFlattenFront2(pWindow[1])); + strip.add(unFlattenBack2(pWindow[1])); + + strip.add(unFlattenFront2(pWindow[0])); + strip.add(unFlattenBack2(pWindow[0])); + + for (Triangle3 t : strip.toTriangles()) { + t.reverse(); + obs.triangles.push_back(t); + } + + } // Frontseite triangulieren std::vector triasFront = gpFront.getTriangles(); diff --git a/floorplan/v2/Floorplan.h b/floorplan/v2/Floorplan.h index d11dd0f..d0b6291 100644 --- a/floorplan/v2/Floorplan.h +++ b/floorplan/v2/Floorplan.h @@ -424,9 +424,8 @@ namespace Floorplan { 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) {;} + FloorObstacleWallWindow(const WindowType type, const Material material, const float atLinePos, const float startsAtHeight, const float width, const float height, const bool io = false) : FloorObstacle(material), type(type), atLinePos(atLinePos), startsAtHeight(startsAtHeight), width(width), height(height), inOut(io) {;} Point2 getStart(const FloorObstacleWall* wall) const { const Point2 dir = wall->to - wall->from; const Point2 cen = wall->from + dir * atLinePos; diff --git a/floorplan/v2/FloorplanReader.h b/floorplan/v2/FloorplanReader.h index e101961..8665530 100644 --- a/floorplan/v2/FloorplanReader.h +++ b/floorplan/v2/FloorplanReader.h @@ -415,7 +415,7 @@ namespace Floorplan { FloorObstacleWallDoor* door = new FloorObstacleWallDoor( parseDoorType(n->Attribute("type")), parseMaterial(n->Attribute("material")), - n->FloatAttribute("at"), + n->FloatAttribute("x01"), n->FloatAttribute("width"), n->FloatAttribute("height"), n->BoolAttribute("lr"), @@ -425,6 +425,22 @@ namespace Floorplan { } } + // windows + FOREACH_NODE(n, el) { + if (std::string("window") == n->Name()) { + FloorObstacleWallWindow* win = new FloorObstacleWallWindow( + parseWindowType(n->Attribute("type")), + parseMaterial(n->Attribute("material")), + n->FloatAttribute("x01"), + n->FloatAttribute("y"), + n->FloatAttribute("width"), + n->FloatAttribute("height"), + n->BoolAttribute("io") + ); + wall->windows.push_back(win); + } + } + return wall; } @@ -534,6 +550,10 @@ namespace Floorplan { try { return (DoorType) std::stoi(type); } catch (...) { return DoorType::UNKNOWN; } } + static WindowType parseWindowType(const std::string type) { + try { return (WindowType) std::stoi(type); } catch (...) { return WindowType::UNKNOWN; } + } + static Material parseMaterial(const std::string material) { try { return (Material) std::stoi(material); diff --git a/floorplan/v2/FloorplanWriter.h b/floorplan/v2/FloorplanWriter.h index 34bb14c..f98037b 100644 --- a/floorplan/v2/FloorplanWriter.h +++ b/floorplan/v2/FloorplanWriter.h @@ -38,6 +38,7 @@ namespace Floorplan { private: static std::string toString(const ObstacleType t) { return std::to_string((int)t); } + static std::string toString(const WindowType t) { return std::to_string((int)t); } static std::string toString(const DoorType t) { return std::to_string((int)t); } static std::string toString(const Material m) { return std::to_string((int)m); } static std::string toString(const OutlineMethod m) { return std::to_string((int)m); } @@ -349,7 +350,7 @@ namespace Floorplan { oDoor->SetAttribute("type", toString(door->type).c_str()); oDoor->SetAttribute("material", toString(door->material).c_str()); - oDoor->SetAttribute("at", door->atLinePos); + oDoor->SetAttribute("x01", door->atLinePos); oDoor->SetAttribute("width", door->width); oDoor->SetAttribute("height", door->height); oDoor->SetAttribute("io", door->inOut); @@ -357,6 +358,22 @@ namespace Floorplan { } + // windows? + for (const FloorObstacleWallWindow* win : wall->windows) { + + XMLElem* oDoor = doc.NewElement("window"); + oWall->InsertEndChild(oDoor); + + oDoor->SetAttribute("type", toString(win->type).c_str()); + oDoor->SetAttribute("material", toString(win->material).c_str()); + oDoor->SetAttribute("x01", win->atLinePos); + oDoor->SetAttribute("y", win->startsAtHeight); + oDoor->SetAttribute("width", win->width); + oDoor->SetAttribute("height", win->height); + oDoor->SetAttribute("io", win->inOut); + + } + } /** write a line obstacle (old walls, handrail, ..) */