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/wifi/estimate/ray3/Obstacle3.h
2018-07-10 17:27:18 +02:00

105 lines
2.2 KiB
C++

#ifndef OBSTACLE3_H
#define OBSTACLE3_H
#include <vector>
#include "../../../geo/Triangle3.h"
#include "../../../geo/Sphere3.h"
#include "../../../floorplan/v2/Floorplan.h"
namespace Ray3D {
/**
* 3D obstacle
* based on multiple triangles
* has a material and a type
*/
struct Obstacle3D {
enum class Type {
UNKNOWN,
GROUND_INDOOR,
GROUND_OUTDOOR,
STAIR,
HANDRAIL,
DOOR,
WALL,
WINDOW,
OBJECT,
};
Type type;
Floorplan::Material mat;
std::vector<Triangle3> triangles;
/** empty ctor */
Obstacle3D() : type(Type::UNKNOWN), mat() {;}
/** ctor */
Obstacle3D(Type type, Floorplan::Material mat) : type(type), mat(mat) {;}
/** scaled copy */
Obstacle3D scaled(const Point3 scale) const {
Obstacle3D copy = *this;
for (Triangle3& tria : copy.triangles) {
tria *= scale;
}
return copy;
}
/** translated copy */
Obstacle3D translated(const Point3 pos) const {
Obstacle3D copy = *this;
for (Triangle3& tria : copy.triangles) {
tria += pos;
}
return copy;
}
/** rotated [around (0,0,0)] copy */
Obstacle3D rotated_deg(const Point3 rot) const {
Obstacle3D copy = *this;
for (Triangle3& tria : copy.triangles) {
tria.p1 = tria.p1.rot(rot.x/180.0f*M_PI, rot.y/180.0f*M_PI, rot.z/180.0f*M_PI);
tria.p2 = tria.p2.rot(rot.x/180.0f*M_PI, rot.y/180.0f*M_PI, rot.z/180.0f*M_PI);
tria.p3 = tria.p3.rot(rot.x/180.0f*M_PI, rot.y/180.0f*M_PI, rot.z/180.0f*M_PI);
}
return copy;
}
/** get all triangle-edge-points (x,y) within the obstacle */
std::vector<Point2> getPoints2D() const {
std::vector<Point2> res;
for (const Triangle3& tria : triangles) {
res.push_back(tria.p1.xy());
res.push_back(tria.p2.xy());
res.push_back(tria.p3.xy());
}
return res;
}
/** get all triangle-edge-points (x,y,z) within the obstacle */
std::vector<Point3> getPoints3D() const {
std::vector<Point3> res;
for (const Triangle3& tria : triangles) {
res.push_back(tria.p1);
res.push_back(tria.p2);
res.push_back(tria.p3);
}
return res;
}
/** perform sanity checks */
bool isValid() const {
for (const Triangle3& t : triangles) {
if (!t.isValid()) {return false;}
}
return true;
}
};
}
#endif // OBSTACLE3_H