-
Notifications
You must be signed in to change notification settings - Fork 2
/
custom_handler.cpp
78 lines (64 loc) · 2 KB
/
custom_handler.cpp
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
#include <microstl.h>
#include <iostream>
struct CustomHandler : microstl::Reader::Handler
{
void onBegin(bool asciiMode) override
{
std::cout << "Begin parsing with " << (asciiMode ? "ASCII" : "binary") << " mode" << std::endl;
}
void onBinaryHeader(const uint8_t header[80]) override
{
std::cout << "Header: ";
for (size_t i = 0; i < 80; i++)
std::cout << int(header[i]) << ' ';
std::cout << std::endl;
}
void onName(const std::string& name) override
{
std::cout << "Name: " << name << std::endl;
}
void onFacetCount(uint32_t triangles) override
{
std::cout << "Triangles: " << triangles << std::endl;
}
void onError(size_t lineNumber) override
{
std::cerr << "Error detected on line: " << lineNumber << std::endl;
}
void onFacet(const float v1[3], const float v2[3], const float v3[3], const float n[3]) override
{
std::cout << "Facet: " << n[0] << "|" << n[1] << "|" << n[2] << ", "
<< v1[0] << "|" << v1[1] << "|" << v1[2] << ", "
<< v2[0] << "|" << v2[1] << "|" << v2[2] << ", "
<< v3[0] << "|" << v3[1] << "|" << v3[2] << std::endl;
}
void onFacetAttributes(const uint8_t attribute[2]) override
{
std::cout << "Attributes: " << int(attribute[0]) << ' ' << int(attribute[1]) << std::endl;
}
void onEnd(microstl::Result result) override
{
std::cout << "Finished parsing with return value " << microstl::getResultString(result) << std::endl;
}
};
int main(int argc, char** argv)
{
if (argc < 2)
{
// The recommended test file is simple_ascii.stl
std::cerr << "Missing argument for input file!" << std::endl;
return 1;
}
/// Create an instance of the custom handler that will receive the STL data
CustomHandler handler;
// Parse STL file with the custom handler as receiver
std::filesystem::path filePath(argv[1]);
microstl::Result result = microstl::Reader::readStlFile(filePath, handler);
// Error handling
if (result != microstl::Result::Success)
{
std::cerr << "Error: " << microstl::getResultString(result) << std::endl;
return 1;
}
return 0;
}