changes to Floorplan 3D
This commit is contained in:
@@ -137,16 +137,24 @@ namespace NM {
|
||||
// get all obstacles of this floor and remove them from the polygon as well (many will be outside of the added polygon)
|
||||
for (Floorplan::FloorObstacle* obs : floor->obstacles) {
|
||||
|
||||
// wall-obstacles
|
||||
Floorplan::FloorObstacleWall* wall = dynamic_cast<Floorplan::FloorObstacleWall*>(obs);
|
||||
if (wall != nullptr) {
|
||||
for (const Floorplan::Polygon2& poly : getPolygons(wall, false)) {
|
||||
nmPoly.remove(poly);
|
||||
}
|
||||
}
|
||||
|
||||
// line-obstacles
|
||||
Floorplan::FloorObstacleLine* line = dynamic_cast<Floorplan::FloorObstacleLine*>(obs);
|
||||
if (line != nullptr) {
|
||||
nmPoly.remove(getPolygon(line));
|
||||
nmPoly.remove(getPolygon(line));
|
||||
}
|
||||
|
||||
// object-obstacles
|
||||
Floorplan::FloorObstacleObject* obj = dynamic_cast<Floorplan::FloorObstacleObject*>(obs);
|
||||
if (obj != nullptr) {
|
||||
nmPoly.remove(getPolygon(obj));
|
||||
nmPoly.remove(getPolygon(obj));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -201,6 +209,15 @@ namespace NM {
|
||||
}
|
||||
}
|
||||
|
||||
for (Floorplan::FloorObstacle* obs : floor->obstacles) {
|
||||
Floorplan::FloorObstacleWall* wall = dynamic_cast<Floorplan::FloorObstacleWall*>(obs);
|
||||
if (wall != nullptr) {
|
||||
for (const Floorplan::Polygon2& poly : getPolygons(wall, true)) {
|
||||
nmDoors.add(poly);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// construct and add triangles
|
||||
std::vector<std::vector<Point3>> tmp = nmDoors.get();
|
||||
for (const std::vector<Point3>& tria : tmp) {
|
||||
@@ -626,6 +643,58 @@ namespace NM {
|
||||
return res;
|
||||
}
|
||||
|
||||
/** create all polygons describing the walls floor outline, excluding doors */
|
||||
std::vector<Floorplan::Polygon2> getPolygons(const Floorplan::FloorObstacleWall* wall, bool invert) const {
|
||||
|
||||
// invert = true -> door polygons
|
||||
// invert = false -> wall polygons
|
||||
|
||||
const float thickness_m = std::max(wall->thickness_m, settings.maxQuality_m); // wall's thickness (make thin walls big enough to be detected)
|
||||
|
||||
// get all points along the wall start, doorstart,doorend, doorstart,doorend, .., end
|
||||
std::vector<Point2> pts;
|
||||
pts.push_back(wall->from);
|
||||
pts.push_back(wall->to);
|
||||
for (const Floorplan::FloorObstacleWallDoor* door : wall->doors) {
|
||||
pts.push_back(door->getStart(wall));
|
||||
pts.push_back(door->getEnd(wall));
|
||||
}
|
||||
|
||||
// sort all points by distance from start (correct on-off-on-off-on order)
|
||||
auto comp = [wall] (const Point2 p1, const Point2 p2) {
|
||||
return wall->from.getDistance(p1) < wall->from.getDistance(p2);
|
||||
};
|
||||
std::sort(pts.begin(), pts.end(), comp);
|
||||
|
||||
std::vector<Floorplan::Polygon2> polys;
|
||||
|
||||
const size_t start = (invert) ? (1) : (0);
|
||||
|
||||
// from wall segment to wall segment, excluding doors
|
||||
for (size_t i = start; i < pts.size()-start; i += 2) {
|
||||
|
||||
const Point2 ps = pts[i+0];
|
||||
const Point2 pe = pts[i+1];
|
||||
|
||||
const Point2 dir = (pe - ps); // part's direction
|
||||
const Point2 perp = dir.perpendicular().normalized(); // perpendicular direction (90 degree)
|
||||
const Point2 p1 = ps + perp * thickness_m/2; // start-up
|
||||
const Point2 p2 = ps - perp * thickness_m/2; // start-down
|
||||
const Point2 p3 = pe + perp * thickness_m/2; // end-up
|
||||
const Point2 p4 = pe - perp * thickness_m/2; // end-down
|
||||
Floorplan::Polygon2 res;
|
||||
res.points.push_back(p1);
|
||||
res.points.push_back(p2);
|
||||
res.points.push_back(p4);
|
||||
res.points.push_back(p3);
|
||||
polys.push_back(res);
|
||||
|
||||
}
|
||||
|
||||
return polys;
|
||||
|
||||
}
|
||||
|
||||
/** convert the given 3D object to a polygon outline */
|
||||
Floorplan::Polygon2 getPolygon(const Floorplan::FloorObstacleObject* obj) const {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user