Terrain Rasterizer
Conversion of GPS data into 2.5D topographic maps
Loading...
Searching...
No Matches
quadtree.hpp
1#ifndef QUADTREE_HPP
2#define QUADTREE_HPP
3
4#include "triangulation.hpp"
5#include <memory>
6#include <optional>
7#include <vector>
8
14 double minX, minY, maxX, maxY;
15
22 bool contains(double x, double y) const;
23
29 bool intersects(const BoundingBox &other) const;
30};
31
39class QuadTree {
40public:
46 QuadTree(const BoundingBox &bounds, int depth = 0);
47
54 void insert(const Triangle &triangle, const std::vector<Point> &points);
55
64 std::optional<Triangle> find(double x, double y,
65 const std::vector<Point> &points) const;
66
67private:
68 BoundingBox bounds;
69 int depth;
70 static const int MAX_DEPTH = 10;
71 static const int MAX_TRIANGLES = 1500; // Leaf capacity
72
73 std::vector<Triangle> triangles;
74 std::unique_ptr<QuadTree> children[4]; // NW, NE, SW, SE
75
76 bool isLeaf() const;
77 void subdivide();
78};
79
80#endif // QUADTREE_HPP
A recursive QuadTree structure for spatial indexing of triangles.
Definition quadtree.hpp:39
std::optional< Triangle > find(double x, double y, const std::vector< Point > &points) const
Finds the triangle containing a specific point.
Definition quadtree.cpp:107
void insert(const Triangle &triangle, const std::vector< Point > &points)
Inserts a triangle into the QuadTree.
Definition quadtree.cpp:78
Represents a 2D axis-aligned bounding box.
Definition quadtree.hpp:13
bool intersects(const BoundingBox &other) const
Checks if this bounding box intersects with another.
Definition quadtree.cpp:14
bool contains(double x, double y) const
Checks if a point is within the bounding box.
Definition quadtree.cpp:10
Represents a triangle defined by three indices into a point list.
Definition triangulation.hpp:12