-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
104 lines (93 loc) · 3.27 KB
/
main.cpp
File metadata and controls
104 lines (93 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "Octree.h"
#include "KDTree.h"
// Variables that are used for tree comparisons
float KD_TOLERANCE = 0.1; // Tolerance for point distance
float OCT_TOLERANCE = 0.1; // Results with lower than tolerance mean similar points
float OCT_THRESHOLD = 0.65; // Similarity threshold percentage, results with higher percentage are more similar
bool KDTreeComparison(KDTree& treeA, KDTree& treeB) {
// distance from A to B
float max_dist_A_to_B = 0.0;
vector<Point> dataA = treeA.traverse();
for (const auto& pA : dataA) {
Point nearest_pB = treeB.nearestNeighbor(pA);
float dist = distance(pA, nearest_pB);
if (dist > max_dist_A_to_B) {
max_dist_A_to_B = dist;
}
}
// distance from B to A
float max_dist_B_to_A = 0.0;
vector<Point> dataB = treeB.traverse();
for (const auto& pB : dataB) {
Point nearest_pA = treeA.nearestNeighbor(pB);
float dist = distance(pB, nearest_pA);
if (dist > max_dist_B_to_A) {
max_dist_B_to_A = dist;
}
}
if (std::max(max_dist_A_to_B, max_dist_B_to_A) <= KD_TOLERANCE) {
return true;
}
return false;
}
bool OctTreeComparison(Octree& treeA, Octree& treeB) {
return Octree::compareOctree(treeA.getRoot(), treeB.getRoot(), OCT_TOLERANCE, OCT_THRESHOLD);
}
KDTree fillKD(const std::vector<Point>& vertices) {
KDTree tree;
for (Point p : vertices) {
tree.insert(p);
}
return tree;
}
Octree fillOct(const std::vector<Point>& vertices) {
Octree tree;
for (Point p : vertices) {
tree.insert(p);
}
return tree;
}
/**
* ./executable <source_dir> <tree_toggle_boolean> <count>
*/
int main(int argc, char* argv[]) {
string source_dir = argv[1];
string tree_toggle = argv[2];
int count = stoi(argv[3]);
vector<Point> source_vertices; // vector of 3d points
vector<Face> source_faces; // vector of face vectors
KDTree source_KDTree;
Octree source_Octree;
if (tree_toggle == "kdtree") {
source_KDTree = fillKD(source_vertices);
}
else if (tree_toggle == "octree") {
source_Octree = fillOct(source_vertices);
}
if (!loadOFF(source_dir, source_vertices, source_faces)) return -1;
string directory = "path/to/ModelNet10/class_name/"; // path to the directory containing the off files you want to load (by class here)
// make a directory iterator out of the path - iterate over the "entries"
int iteration = 0;
vector<string> filenames;
for (const auto& entry : std::filesystem::directory_iterator(directory)) {
vector<Point> vertices; // vector of 3d points
vector<Face> faces; // vector of face vectors
if (!loadOFF(entry.path().string(), vertices, faces)) continue;
if (tree_toggle == "kdtree") {
KDTree KDTree = fillKD(vertices);
KDTreeComparison(source_KDTree, KDTree);
filenames.push_back(entry.path().string());
}
else if (tree_toggle == "octree") {
Octree Octree = fillOct(vertices);
if (OctTreeComparison(source_Octree, Octree)) {
filenames.push_back(entry.path().string());
}
}
iteration++;
if (iteration == count) {
break;
}
}
return 0;
}