wow
This commit is contained in:
parent
73b432d0c8
commit
2425729a72
@ -1,5 +1,6 @@
|
||||
#include "kd_tree.h"
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
KdTree::Point::Point(): x{0}, y{0}, z{0} {}
|
||||
KdTree::Point::Point(double x, double y, double z): x{x}, y{y}, z{z} {}
|
||||
@ -19,7 +20,7 @@ double KdTree::Point::dist2(Point const &other) const {
|
||||
return x_ * x_ + y_ * y_ + z_ * z_;
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream& os, KdTree::Point const & point) {
|
||||
ostream& operator<<(ostream &os, KdTree::Point const &point) {
|
||||
os << "[" << point.x << ", " << point.y << ", " << point.z << "]";
|
||||
return os;
|
||||
}
|
||||
@ -40,7 +41,7 @@ void KdTree::fill(std::vector<Tuple> &points) {
|
||||
KdTree::Node *KdTree::fillRec(std::size_t begin, std::size_t end, int axis) {
|
||||
if(end <= begin) return nullptr;
|
||||
|
||||
size_t n = begin + (end - begin) / 2;
|
||||
std::size_t n = begin + (end - begin) / 2;
|
||||
auto i = nodes.begin();
|
||||
std::nth_element(i + begin, i + n, i + end, [&](Node &p1, Node &p2) {
|
||||
return p1.position[axis] < p2.position[axis];
|
||||
@ -54,7 +55,7 @@ KdTree::Node *KdTree::fillRec(std::size_t begin, std::size_t end, int axis) {
|
||||
}
|
||||
|
||||
KdTree::Point KdTree::query(Point const &point) {
|
||||
bestDist = 99999.;
|
||||
bestDist = std::numeric_limits<double>::max();
|
||||
bestNode = nullptr;
|
||||
queryRec(root, point, 0);
|
||||
return bestNode->position;
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
double operator[] (std::size_t i) const;
|
||||
double dist2(Point const &other) const;
|
||||
|
||||
friend ostream& operator<<(ostream& os, Point const & point);
|
||||
friend ostream& operator<<(ostream &os, Point const &point);
|
||||
};
|
||||
|
||||
using Tuple = std::pair<Point, vtkIdType>;
|
||||
|
Loading…
Reference in New Issue
Block a user