-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·128 lines (101 loc) · 4.33 KB
/
main.cpp
File metadata and controls
executable file
·128 lines (101 loc) · 4.33 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
#include <iostream>
#include <FindSurface.hpp>
#include "pointcloud.hpp"
#include "helper.hpp"
namespace Test {
using namespace FindSurface;
struct Cpp {
static void run();
private:
static void runTest(
std::shared_ptr<Context> context,
FeatureType type,
unsigned int seedIndex,
float seedRadius
);
static const char* getTypeName(FeatureType type, bool capitalized = false);
static void printResult(const Result& result);
};
};
int main()
{
Test::Cpp::run();
return 0;
}
void Test::Cpp::run() {
const float measurementAccuracy = 0.01f;
const float meanDistance = 0.01f;
const float seedRadius = 0.025f;
auto context = Context::getInstance();
context->setMeasurementAccuracy(measurementAccuracy);
context->setMeanDistance(meanDistance);
try {
context->setPointCloudDataFloat(POINTS.data(), POINTS.size(), sizeof(Point));
} catch (Exception::InvalidOperation e) {
printf("Error! POINT_COUNT exceeds the limitation on input point clouds. Refer to the GitHub documentation (github.com/CurvSurf/FindSurface-x86_64) for details.");
return;
} catch (Exception::InvalidArgument e) {
printf("Error! It might be one of the following error cases: the pointer is nullptr, the count is zero, or the stride is neither zero nor at least three times the size of a float or double.");
return;
} catch(...) {
printf("Unknown Error!");
return;
}
std::cout << "Normal cases: " << std::endl;
int trial = 1;
for (auto preset : Preset::normalList) {
std::cout << trial++ << ". ";
runTest(context, preset.featureType, preset.seedIndex, seedRadius);
}
std::cout << "Smart cases: " << std::endl;
int smartOptions = FS_SCO_CONE_TO_CYLINDER
| FS_SCO_TORUS_TO_SPHERE
| FS_SCO_TORUS_TO_CYLINDER;
context->setSmartConversionOptions(smartOptions);
trial = 1;
for (auto preset : Preset::smartList) {
std::cout << trial++ << ". ";
runTest(context, preset.featureType, preset.seedIndex, seedRadius);
}
}
void Test::Cpp::runTest(std::shared_ptr<Context> context, FeatureType type, unsigned int seedIndex, float seedRadius) {
std::cout << "FindSurface searched for a " << getTypeName(type) << std::endl;
std::cout << "around the point of which index is " << seedIndex << std::endl;
try {
auto result = context->findSurface(type, seedIndex, seedRadius);
if (result.type != FeatureType::none) {
printResult(result);
}
else {
std::cout << "Not found." << std::endl;
}
}
catch (std::logic_error& error) {
std::cout << "Couldn't run FindSurface due to the following error: " << std::endl;
std::cout << error.what() << std::endl;
}
std::cout << std::endl;
}
const char* Test::Cpp::getTypeName(const FeatureType type, bool capitalized) {
switch (type) {
case FeatureType::plane: return capitalized ? "Plane" : "plane";
case FeatureType::sphere: return capitalized ? "Sphere" : "sphere";
case FeatureType::cylinder: return capitalized ? "Cylinder" : "cylinder";
case FeatureType::cone: return capitalized ? "Cone" : "cone";
case FeatureType::torus: return capitalized ? " Torus" : "torus";
case FeatureType::any: return capitalized ? "Any shape" : "any shape";
case FeatureType::none: return capitalized ? "Nothing" : "nothing";
default: return capitalized ? "Unknown" : "unknown";
}
}
void Test::Cpp::printResult(const Result& result) {
const float rmsError = result.rmsError;
std::cout << getTypeName(result.type, true) << " (rms error: " << rmsError << ")" << std::endl;
switch (result.type) {
case FeatureType::plane: std::cout << result.param.plane << std::endl; break;
case FeatureType::sphere: std::cout << result.param.sphere << std::endl; break;
case FeatureType::cylinder: std::cout << result.param.cylinder << std::endl; break;
case FeatureType::cone: std::cout << result.param.cone << std::endl; break;
case FeatureType::torus: std::cout << result.param.torus << std::endl; break;
}
}