worked on 3D walls
This commit is contained in:
@@ -3,9 +3,12 @@
|
||||
|
||||
#include "../../geo/Line2.h"
|
||||
#include "../../geo/Polygon2.h"
|
||||
#include "../../geo/GPCPolygon2.h"
|
||||
|
||||
#include "Walls.h"
|
||||
#include "misc.h"
|
||||
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
namespace Floorplan3D {
|
||||
@@ -174,32 +177,133 @@ namespace Floorplan3D {
|
||||
Obstacle3D obs(type, wall.line->material);
|
||||
|
||||
const float z1 = fp.z1;
|
||||
const float z2 = fp.z2;
|
||||
const float z2 = (wall.line->height_m > 0) ? (fp.z1 + wall.line->height_m) : (fp.z2);
|
||||
|
||||
const Point3 p1 = Point3(wall.getP1().x, wall.getP1().y, z1);
|
||||
const Point3 p2 = Point3(wall.getP2().x, wall.getP2().y, z1);
|
||||
const Point3 p3 = Point3(wall.getP3().x, wall.getP3().y, z1);
|
||||
const Point3 p4 = Point3(wall.getP4().x, wall.getP4().y, z1);
|
||||
// const Point3 p1 = Point3(wall.getP1().x, wall.getP1().y, z1);
|
||||
// const Point3 p2 = Point3(wall.getP2().x, wall.getP2().y, z1);
|
||||
// const Point3 p3 = Point3(wall.getP3().x, wall.getP3().y, z1);
|
||||
// const Point3 p4 = Point3(wall.getP4().x, wall.getP4().y, z1);
|
||||
|
||||
const Point3 p1u = Point3(wall.getP1().x, wall.getP1().y, z2);
|
||||
const Point3 p2u = Point3(wall.getP2().x, wall.getP2().y, z2);
|
||||
const Point3 p3u = Point3(wall.getP3().x, wall.getP3().y, z2);
|
||||
const Point3 p4u = Point3(wall.getP4().x, wall.getP4().y, z2);
|
||||
// const Point3 p1u = Point3(wall.getP1().x, wall.getP1().y, z2);
|
||||
// const Point3 p2u = Point3(wall.getP2().x, wall.getP2().y, z2);
|
||||
// const Point3 p3u = Point3(wall.getP3().x, wall.getP3().y, z2);
|
||||
// const Point3 p4u = Point3(wall.getP4().x, wall.getP4().y, z2);
|
||||
|
||||
obs.addQuad(p1, p2, p2u, p1u);
|
||||
obs.addQuad(p2, p3, p3u, p2u);
|
||||
obs.addQuad(p3, p4, p4u, p3u);
|
||||
obs.addQuad(p4, p1, p1u, p4u);
|
||||
// obs.addQuad(p1, p2, p2u, p1u);
|
||||
// obs.addQuad(p2, p3, p3u, p2u);
|
||||
// obs.addQuad(p3, p4, p4u, p3u);
|
||||
// obs.addQuad(p4, p1, p1u, p4u);
|
||||
|
||||
obs.addQuad(p1u, p2u, p3u, p4u);
|
||||
obs.addQuad(p4, p3, p2, p1);
|
||||
// obs.addQuad(p1u, p2u, p3u, p4u);
|
||||
// obs.addQuad(p4, p3, p2, p1);
|
||||
|
||||
obs.reverseFaces();
|
||||
// obs.reverseFaces();
|
||||
|
||||
// return obs;
|
||||
|
||||
Point3 p0 = Point3(wall.line->from.x, wall.line->from.y, z1);
|
||||
|
||||
Point3 p1 = Point3(wall.getP1().x, wall.getP1().y, z1);
|
||||
Point3 p2 = Point3(wall.getP2().x, wall.getP2().y, z1);
|
||||
Point3 p3 = Point3(wall.getP3().x, wall.getP3().y, z1);
|
||||
Point3 p4 = Point3(wall.getP4().x, wall.getP4().y, z1);
|
||||
|
||||
Point3 p1u = Point3(wall.getP1().x, wall.getP1().y, z2);
|
||||
Point3 p2u = Point3(wall.getP2().x, wall.getP2().y, z2);
|
||||
Point3 p3u = Point3(wall.getP3().x, wall.getP3().y, z2);
|
||||
Point3 p4u = Point3(wall.getP4().x, wall.getP4().y, z2);
|
||||
|
||||
Point3 o = p0;
|
||||
float t = wall.line->thickness_m / 2;
|
||||
|
||||
const Point3 o1;// = p1;
|
||||
const Point3 o2;// = p4;
|
||||
const float a = std::atan2(wall.getP2().y - wall.getP1().y, wall.getP2().x - wall.getP1().x);
|
||||
|
||||
auto flatten = [a,o] (const Point3 p) {return (p - o).rotZ(-a).xz();};
|
||||
//auto flatten2 = [a,o] (const Point3 p) {return (p - o).rotZ(-a).xz();};
|
||||
|
||||
auto unFlattenFront = [o,t,a] (const Point3 p) {return Point3(p.x, +t, p.y).rotZ(a)+o;};
|
||||
auto unFlattenBack = [o,t,a] (const Point3 p) {return Point3(p.x, -t, p.y).rotZ(a)+o;};
|
||||
|
||||
const Point2 fp1 = flatten(p1);
|
||||
const Point2 fp2 = flatten(p2);
|
||||
const Point2 fp3 = flatten(p3);
|
||||
const Point2 fp4 = flatten(p4);
|
||||
const Point2 fp1u = flatten(p1u);
|
||||
const Point2 fp2u = flatten(p2u);
|
||||
const Point2 fp3u = flatten(p3u);
|
||||
const Point2 fp4u = flatten(p4u);
|
||||
|
||||
|
||||
Polygon2 front;
|
||||
front.add({fp1, fp2, fp2u, fp1u});
|
||||
|
||||
GPCPolygon2 gpFront;
|
||||
gpFront.add(front);
|
||||
|
||||
Polygon2 back;
|
||||
back.add({fp3, fp4, fp4u, fp3u});
|
||||
|
||||
GPCPolygon2 gpBack;
|
||||
gpBack.add(back);
|
||||
|
||||
for (const Floorplan::FloorObstacleWallDoor* door : wall.line->doors) {
|
||||
Polygon2 pDoor;
|
||||
|
||||
const Point2 pds = door->getStart(wall.line);
|
||||
const Point2 pde = door->getEnd(wall.line);
|
||||
|
||||
const Point3 dp1(pds.x, pds.y, z1);
|
||||
const Point3 dp2(pde.x, pde.y, z1);
|
||||
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;};
|
||||
|
||||
pDoor.add(flatten(dp1));
|
||||
pDoor.add(flatten(dp2));
|
||||
pDoor.add(flatten(dp2u));
|
||||
pDoor.add(flatten(dp1u));
|
||||
|
||||
gpFront.remove(pDoor);
|
||||
gpBack.remove(pDoor);
|
||||
|
||||
}
|
||||
|
||||
std::vector<Triangle3> triasFront = gpFront.getTriangles();
|
||||
|
||||
for (Triangle3 tria : triasFront) {
|
||||
fixTria(tria, unFlattenFront);
|
||||
tria.reverse();
|
||||
obs.triangles.push_back(tria);
|
||||
}
|
||||
|
||||
std::vector<Triangle3> triasBack = gpBack.getTriangles();
|
||||
|
||||
for (Triangle3 tria : triasBack) {
|
||||
fixTria(tria, unFlattenBack);
|
||||
obs.triangles.push_back(tria);
|
||||
}
|
||||
|
||||
|
||||
// for (const Floorplan::FloorObstacleWallDoor* door : wall.line->doors) {
|
||||
// const Point2 p1 = door->getStart(wall.line);
|
||||
// const Point2 p2 = door->getEnd(wall.line);
|
||||
|
||||
// }
|
||||
|
||||
return obs;
|
||||
|
||||
}
|
||||
|
||||
void fixTria(Triangle3& t, std::function<Point3(Point3)> func) {
|
||||
t.p1 = func(t.p1);
|
||||
t.p2 = func(t.p2);
|
||||
t.p3 = func(t.p3);
|
||||
}
|
||||
|
||||
/** cut off walls ending within another wall */
|
||||
std::vector<Wall> cutProtruding(std::vector<Wall> walls) {
|
||||
|
||||
|
||||
@@ -192,6 +192,7 @@ namespace Floorplan {
|
||||
struct Stair;
|
||||
struct Elevator;
|
||||
struct GroundTruthPoint;
|
||||
struct FloorObstacleWallDoor;
|
||||
|
||||
struct FloorOutline : public std::vector<FloorOutlinePolygon*> {
|
||||
bool enabled = true;
|
||||
@@ -350,6 +351,7 @@ 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) {;}
|
||||
};
|
||||
@@ -376,6 +378,25 @@ namespace Floorplan {
|
||||
float getSize() const {return (to-from).length();}
|
||||
};
|
||||
|
||||
/** door obstacle */
|
||||
struct FloorObstacleWallDoor : public FloorObstacle {
|
||||
DoorType type;
|
||||
float atLinePos;
|
||||
float width;
|
||||
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 {
|
||||
const Point2 dir = wall->to - wall->from;
|
||||
return wall->from + dir * atLinePos;
|
||||
}
|
||||
Point2 getEnd(const FloorObstacleLine* wall) const {
|
||||
const Point2 dir = wall->to - wall->from;
|
||||
return getStart(wall) + dir.normalized() * (leftRight ? -width : +width);
|
||||
}
|
||||
};
|
||||
|
||||
/** 3D obstacle */
|
||||
struct FloorObstacleObject : public FloorObstacle {
|
||||
std::string file;
|
||||
|
||||
Reference in New Issue
Block a user