-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
145 lines (133 loc) · 4.54 KB
/
main.cpp
File metadata and controls
145 lines (133 loc) · 4.54 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
#include "myclass.h"
#include "mySetPara.h"
#include <PointCloud.h>
#include <RansacShapeDetector.h>
#include <PlanePrimitiveShapeConstructor.h>
#include <iostream>
#include <vector>
#include <string>
#include <chrono>
#include <iomanip>
int main()
{
////////////////////////////
createDirectoryRecursively();
// Delete directory contents, the output directory must be created!!!
deleteDirectoryContents();
////////////////////////////
// Whether to perform quantitative experiments
if (isQuantitativeExperiment) {
// Current data type, can be "sphere" or "torus"
std::string dataType = "torus";
// Data path
std::string dataPath = "./data/" + dataType;
// Output file path
std::ofstream outfile("./output/quantitative_results.txt");
// Iterate through the dataset
for (int i = 0; i <= 80; i++) {
// Current iteration
number_of_Candidates = 0;
// Point cloud file path
std::string pointfilename = dataPath + "/" + std::to_string(i) + "/points.obj";
std::string linefilename = dataPath + "/" + std::to_string(i) + "/lines.obj";
// Point cloud and line cloud data
PointCloud pc; // Point cloud
PointCloud Line2pc; // Converted line cloud
LineCloud Lc; // Line cloud
// Initialize RANSAC parameters
RansacShapeDetector::Options ransacOptions;
setRansacOptions(ransacOptions, dataType);
// Get data
switch (INPUT_TYPE) {
case 0:
// Point cloud only
readPoints(pointfilename, pc);
break;
case 1:
// Line cloud only
readLines(linefilename, Lc, ransacOptions.m_bitmapEpsilon);
break;
case 2:
// Both point and line cloud
readPoints(pointfilename, pc);
readLines(linefilename, Lc, ransacOptions.m_bitmapEpsilon);
break;
default:
std::cerr << "ERROR: Unknown INPUT_TYPE = " << INPUT_TYPE << std::endl;
break;
}
// Perform preprocessing to convert line segments to point clouds and then merge them with the original point cloud
lc2pc(Lc, ransacOptions.m_bitmapEpsilon, Line2pc);
pc += Line2pc;
pc.calcNormals(30);
// Estimate line normals
estimateLineNormals(pc, Lc);
// Create RANSAC shape detector
RansacShapeDetector detector(ransacOptions);
// Add plane primitive shape constructor
detector.Add(new PlanePrimitiveShapeConstructor());
// Store plane primitive shapes
MiscLib::Vector< std::pair< MiscLib::RefCountPtr< PrimitiveShape >, size_t > > shapes;
// Initialize trial count
int trials = 30;
// Record successful plane detections
int num_plane = 0;
// Record average successful detection time
double timeSum = 0;
for (int j = 0; j < trials; j++) {
// Display current trial
std::cout << dataType << " " << i << " " << j << std::endl;
detector.Detect(pc, Lc, 0, pc.size(), &shapes);
num_plane += shapes.size();
std::string outPutPath = "./output/" + std::to_string(i) + "/" + std::to_string(j);
//writePointPlane(shapes, pc, Lc, ransacOptions.m_epsilon, ransacOptions.m_bitmapEpsilon, outPutPath);
for (int k = 0; k < Lc.size(); k++) {
Lc[k].tag = false;
}
shapes.clear();
}
}
}
else {
// Initialize data type
std::string dataType = "test";
// Data path
std::string pointfilename = "./data/" + dataType + "/points.obj";
std::string linefilename = "./data/" + dataType + "/lines.obj";
// Output path
PointCloud pc; // Point cloud
PointCloud line2pc; // Converted line cloud
// Merged point cloud
LineCloud Lc;
// RANSAC options
RansacShapeDetector::Options ransacOptions;
// Set RANSAC options
setRansacOptions(ransacOptions, dataType);
// Get data
if (INPUT_TYPE == 0) {
readPoints(pointfilename, pc);
}
else if (INPUT_TYPE == 1) {
readLines(linefilename, Lc, ransacOptions.m_bitmapEpsilon);
}
else {
readPoints(pointfilename, pc);
readLines(linefilename, Lc, ransacOptions.m_bitmapEpsilon);
}
lc2pc(Lc, ransacOptions.m_bitmapEpsilon, line2pc);
pc += line2pc;
pc.calcNormals(30);
estimateLineNormals(pc, Lc);
// Output the number of added points and lines
std::cout << "added " << pc.size() << " points" << std::endl;
std::cout << "added " << Lc.size() - 1 << " lines" << std::endl;
RansacShapeDetector detector(ransacOptions);
detector.Add(new PlanePrimitiveShapeConstructor());
MiscLib::Vector< std::pair< MiscLib::RefCountPtr< PrimitiveShape >, size_t > > shapes;
int remainpoint = 0;
remainpoint = detector.Detect(pc, Lc, 0, pc.size(), &shapes); // Perform detection
writePointPlane(shapes, pc, Lc, ransacOptions.m_epsilon, ransacOptions.m_bitmapEpsilon);
}
return 0;
}