This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/floorplan/3D/Builder.h
2018-10-25 11:50:12 +02:00

199 lines
4.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2014 Urheberrechtshinweis
* Alle Rechte vorbehalten / All Rights Reserved
*
* Programmcode ist urheberrechtlich geschuetzt.
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
* Keine Verwendung ohne explizite Genehmigung.
* (vgl. § 106 ff UrhG / § 97 UrhG)
*/
#ifndef FLOORPLAN_3D_BUILDER_H
#define FLOORPLAN_3D_BUILDER_H
#include "../v2/Floorplan.h"
#include "FloorplanMesh.h"
#include "Obstacle3.h"
#include "Outline.h"
#include "Stairs.h"
#include "Handrails.h"
#include "Objects.h"
#include "Pillars.h"
#include "Doors.h"
#include "Walls.h"
#include "WallsViaCubes.h"
#include "WallsViaCuttedQuads.h"
namespace Floorplan3D {
class Builder {
/** the to-be-exported map */
const Floorplan::IndoorMap* map;
public:
bool exportCeilings = true;
bool exportObstacles = true;
bool exportStairs = true;
bool fancyStairs = true;
bool exportHandrails = true;
bool exportDoors = true;
// bool exportAboveDoors = true;
bool doorsOpen = false;
bool exportObjects = true;
bool exportPillars = true;
bool exportWallTops = false;
bool center = false;
//Walls* walls = new WallsViaCubes();
//Walls* walls = new WallsViaCuttedQuads();
public:
/** ctor */
Builder(const Floorplan::IndoorMap* map) : map(map) {
}
/** get the created mesh */
FloorplanMesh getMesh() {
FloorplanMesh mesh;
mesh.elements = triangulize();
if (center) {
BBox3 bb = mesh.getBBox();
mesh -= Point3(bb.getCenter().x, bb.getCenter().y, 0);
}
return mesh;
}
private:
/** get all triangles grouped by obstacle */
std::vector<Obstacle3D> triangulize() {
// TODO: filtering??
std::vector<Floorplan::Floor*> floors = map->floors;
std::vector<Obstacle3D> res;
// get the to-be-exported floors (either "all" or "user defined")
//const std::vector<Floorplan::Floor*>& floors = (exportFloors.empty()) ? (map->floors) : (exportFloors);
// process each floor
for (const Floorplan::Floor* f : floors) {
if (!f->enabled) {continue;}
// triangulize the floor itself (floor/ceiling)
if (exportCeilings) {
Outline out;
const std::vector<Obstacle3D> tmp = out.get(f);
res.insert(res.end(), tmp.begin(), tmp.end());
}
// process each obstacle within the floor
if (f->obstacles.enabled) {
if (1 == 1) {
const std::vector<Obstacle3D> tmp = getLines(f);
res.insert(res.end(), tmp.begin(), tmp.end());
}
if (1 == 1) {
const std::vector<Obstacle3D> tmp = getWalls(f);
res.insert(res.end(), tmp.begin(), tmp.end());
}
if (exportHandrails) {
Handrails rails;
const std::vector<Obstacle3D> tmp = rails.getHandrails(f);
res.insert(res.end(), tmp.begin(), tmp.end());
}
if (exportObjects) {
Objects objs;
const std::vector<Obstacle3D> tmp = objs.getObjects(f);
res.insert(res.end(), tmp.begin(), tmp.end());
}
if (exportPillars) {
Pillars pillars;
const std::vector<Obstacle3D> tmp = pillars.getPillars(f);
res.insert(res.end(), tmp.begin(), tmp.end());
}
if (exportDoors) {
Doors doors;
const std::vector<Obstacle3D> tmp = doors.getDoors(f);
res.insert(res.end(), tmp.begin(), tmp.end());
}
// for (const Floorplan::FloorObstacle* fo : f->obstacles) {
// std::vector<Obstacle3D> tmp = getWalls(f);
// res.insert(res.end(), tmp.begin(), tmp.end());
// }
}
// // stairs
if (f->stairs.enabled && exportStairs) {
Stairs stairs;
const std::vector<Obstacle3D> tmp = stairs.getStairs(f);
res.insert(res.end(), tmp.begin(), tmp.end());
}
}
return res;
}
/** just get all walls */
std::vector<Obstacle3D> getWalls(const Floorplan::Floor* f) {
WallsViaCuttedQuads walls;
for (const Floorplan::FloorObstacle* obs : f->obstacles) {
const Floorplan::FloorObstacleWall* wall = dynamic_cast<const Floorplan::FloorObstacleWall*>(obs);
if (wall) {walls.add(f, wall);}
}
return walls.get();
}
/** get all old walls (lines) */
std::vector<Obstacle3D> getLines(const Floorplan::Floor* f) {
WallsViaCubes walls;
for (const Floorplan::FloorObstacle* obs : f->obstacles) {
const Floorplan::FloorObstacleLine* line = dynamic_cast<const Floorplan::FloorObstacleLine*>(obs);
if (line) {
if (line->type == Floorplan::ObstacleType::WALL) {
walls.add(f, line, nullptr);
}
}
}
return walls.get();
}
};
}
#endif // FLOORPLAN_3D_BUILDER_H