#ifndef KDTREE_H #define KDTREE_H #include #include "common/utils/Array.h" #include "common/math/Vector.h" #include "client/rendering/Lines.h" struct KDTree final { class Triangle { Array v; Vector3 mid; public: Triangle(const Vector3& a, const Vector3& b, const Vector3& c); const Array& data() const; const Vector3& operator[](int index) const; const Vector3& getMid() const; }; private: struct Node { std::vector data; int splitDim; float splitValue; Node* lessEqual; Node* greater; Node(); }; Node root; public: KDTree(); ~KDTree(); KDTree(const KDTree& other) = delete; KDTree(KDTree&& other) = delete; KDTree& operator=(const KDTree& other) = delete; KDTree& operator=(KDTree&& other) = delete; void build(std::vector& data); void fillLines(Lines& lines, const std::vector& data); private: void clean(Node* n); float median(std::vector& data, int dim) const; void build(Node* n, std::vector& data); void fillLines(Lines& lines, Node* n, const Vector3& min, const Vector3& max); }; #endif