-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_kdtree.cpp
More file actions
61 lines (43 loc) · 2.11 KB
/
build_kdtree.cpp
File metadata and controls
61 lines (43 loc) · 2.11 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
#include <locale>
#include "Point.hpp"
#include "kdtree.hpp"
#include "DotFileWriter.hpp"
#include "PCDFile.hpp"
#include "SplitAxisStrategyFactory.hpp"
#include "SplitPointStrategyFactory.hpp"
#include <string>
using namespace rossb83;
/*
* quick script that builds a kdtree and stores it to a specified file
*/
int main(int argc, char* argv[]) {
static const std::string INPUT_FILE = "inputfile";
static const std::string OUTPUT_FILE = "outputfile";
static const std::string SPLIT_POINT = "splitpoint";
static const std::string SPLIT_AXIS = "splitaxis";
std::unordered_map<std::string,std::string> inputs;
inputs.insert({{INPUT_FILE,"sample_data.csv"},{OUTPUT_FILE,"sample_kdtree.dot"},{SPLIT_POINT,"sort"},{SPLIT_AXIS,"cycle"}});
for (size_t i = 1; i < argc; i++) {
std::string input = std::string(argv[i]);
int delimiter = input.find("=");
if ((argv[i][0] == '-') && (delimiter != std::string::npos)) {
inputs[input.substr(1,delimiter-1)] = input.substr(delimiter+1);
}
}
std::cout << "Reading point data input file: " << inputs[INPUT_FILE] << std::endl;
// read input file from disk
PCDFile<double> inputfile(inputs[INPUT_FILE]);
std::cout << "Building kdtree with: " << std::endl;
std::cout << "\tSplit Axis Strategy: " << inputs[SPLIT_AXIS] << std::endl;
std::cout << "\tSplit Point Strategy: " << inputs[SPLIT_POINT] << std::endl;
// generate strategies to create kdtree
std::shared_ptr<SplitAxisStrategy<double>> splitAxisStrategy = SplitAxisStrategyFactory<double>::createSplitAxisStrategy(inputs[SPLIT_AXIS]);
std::shared_ptr<SplitPointStrategy<double>> splitPointStrategy = SplitPointStrategyFactory<double>::createSplitPointStrategy(inputs[SPLIT_POINT]);
// generate kdtree from input file
KDTree<double> kdtree(inputfile, splitPointStrategy, splitAxisStrategy);
std::cout << "Serializing kdtree to output file: " << inputs[OUTPUT_FILE] << std::endl;
// serialize kdtree and store on disk
DotFileWriter<double> dotfile(inputs[OUTPUT_FILE]);
dotfile.writeFile(kdtree);
return 0;
}