moved from ray3 to floorplan/3D
worked on new wall models refactoring
This commit is contained in:
127
floorplan/3D/Obstacle3.h
Normal file
127
floorplan/3D/Obstacle3.h
Normal file
@@ -0,0 +1,127 @@
|
||||
#ifndef FLOORPLAN_3D_OBSTACLE3_H
|
||||
#define FLOORPLAN_3D_OBSTACLE3_H
|
||||
|
||||
#include <vector>
|
||||
#include "../../geo/Triangle3.h"
|
||||
#include "../../geo/Sphere3.h"
|
||||
|
||||
#include "../v2/Floorplan.h"
|
||||
|
||||
namespace Floorplan3D {
|
||||
|
||||
/**
|
||||
* 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,
|
||||
ERROR,
|
||||
};
|
||||
|
||||
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) {;}
|
||||
|
||||
|
||||
/** append a new triangle. REFERENCE ONLY VALID UNTIL NEXT ADD */
|
||||
Triangle3& addTriangle(const Point3 p1, const Point3 p2, const Point3 p3) {
|
||||
triangles.push_back(Triangle3(p1, p2, p3));
|
||||
return triangles.back();
|
||||
}
|
||||
|
||||
/** append a new quad by splitting into two triangles */
|
||||
void addQuad(const Point3 p1, const Point3 p2, const Point3 p3, const Point3 p4) {
|
||||
addTriangle(p1, p2, p3);
|
||||
addTriangle(p1, p3, p4);
|
||||
}
|
||||
|
||||
/** reverse all faces (CW<->CCW) */
|
||||
void reverseFaces() {
|
||||
for (Triangle3& t : triangles) {
|
||||
t.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 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);
|
||||
tria.rotate_deg(rot);
|
||||
}
|
||||
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 // FLOORPLAN_3D_OBSTACLE3_H
|
||||
Reference in New Issue
Block a user