generated from karl/cpp-template
Compare commits
No commits in common. "ab2adf41735c9e18257c7a3ffdd73e5bbb1aafa3" and "80d6a27eeff02439a557f62555a2dcd66d7f59e5" have entirely different histories.
ab2adf4173
...
80d6a27eef
6
Makefile
6
Makefile
@ -1,10 +1,10 @@
|
|||||||
CXX = g++
|
CXX = g++
|
||||||
CXXFLAGS = -Wall -O3
|
CXXFLAGS = -Wall -O3
|
||||||
|
|
||||||
kdtree: main.o
|
program: main.o
|
||||||
$(CXX) $(CXXFLAGS) -o kdtree.out main.o
|
$(CXX) $(CXXFLAGS) -o program.out main.o
|
||||||
|
|
||||||
main.o: main.cpp kdtree.h
|
main.o: main.cpp
|
||||||
$(CXX) $(CXXFLAGS) -c main.cpp
|
$(CXX) $(CXXFLAGS) -c main.cpp
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
|
7
kdtree.h
7
kdtree.h
@ -74,7 +74,7 @@ class KDTree {
|
|||||||
// Get extent along this axis
|
// Get extent along this axis
|
||||||
auto comparator = get_point_comparator(it_axis);
|
auto comparator = get_point_comparator(it_axis);
|
||||||
|
|
||||||
Point *min = *std::min_element(points.begin(), points.end(), comparator);
|
Point *min = *std::max_element(points.begin(), points.end(), comparator);
|
||||||
Point *max = *std::max_element(points.begin(), points.end(), comparator);
|
Point *max = *std::max_element(points.begin(), points.end(), comparator);
|
||||||
|
|
||||||
float extent = max->coordinates[it_axis] - min->coordinates[it_axis];
|
float extent = max->coordinates[it_axis] - min->coordinates[it_axis];
|
||||||
@ -98,7 +98,7 @@ class KDTree {
|
|||||||
|
|
||||||
// TODO: This copies. Can we split the vector into two without copying?
|
// TODO: This copies. Can we split the vector into two without copying?
|
||||||
std::vector<Point *> left_of_median(points.begin(), points.begin() + middle);
|
std::vector<Point *> left_of_median(points.begin(), points.begin() + middle);
|
||||||
std::vector<Point *> right_of_median(points.begin() + middle + 1, points.end());
|
std::vector<Point *> right_of_median(points.begin() + middle, points.end());
|
||||||
|
|
||||||
// Create node, recursively call to construct subtree
|
// Create node, recursively call to construct subtree
|
||||||
return new Node(axis, median, build(left_of_median, depth + 1),
|
return new Node(axis, median, build(left_of_median, depth + 1),
|
||||||
@ -112,8 +112,7 @@ class KDTree {
|
|||||||
|
|
||||||
str += std::string(depth, '-') + std::to_string(point->coordinates[0]) + ", " +
|
str += std::string(depth, '-') + std::to_string(point->coordinates[0]) + ", " +
|
||||||
std::to_string(point->coordinates[1]) + ", " +
|
std::to_string(point->coordinates[1]) + ", " +
|
||||||
std::to_string(point->coordinates[2]) + " with axis " + std::to_string(node->axis) +
|
std::to_string(point->coordinates[2]) + "\n";
|
||||||
"\n";
|
|
||||||
|
|
||||||
to_string_recurse(str, node->left, depth + 1);
|
to_string_recurse(str, node->left, depth + 1);
|
||||||
to_string_recurse(str, node->right, depth + 1);
|
to_string_recurse(str, node->right, depth + 1);
|
||||||
|
11
main.cpp
11
main.cpp
@ -1,18 +1,7 @@
|
|||||||
#include "kdtree.h"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << "Hello World!" << std::endl;
|
std::cout << "Hello World!" << std::endl;
|
||||||
|
|
||||||
// Test points
|
|
||||||
std::vector<Point *> points{new Point(new float[3]{0.0, 0.0, 0.0}, nullptr),
|
|
||||||
new Point(new float[3]{0.0, 1.0, 0.0}, nullptr),
|
|
||||||
new Point(new float[3]{0.0, 2.0, 3.0}, nullptr),
|
|
||||||
new Point(new float[3]{1.0, 0.0, 4.0}, nullptr)};
|
|
||||||
|
|
||||||
KDTree tree = KDTree(points);
|
|
||||||
|
|
||||||
std::cout << tree.to_string();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user