-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmeshcleaner.cpp
49 lines (43 loc) · 1.16 KB
/
meshcleaner.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
#include <iostream>
#include <sstream>
#include "mesh_definitions.hpp"
#include "meshcleanerworker.hpp"
std::string file_basename(const std::string & fn)
{
std::string::size_type index = fn.rfind('.');
if (index != std::string::npos)
return fn.substr(0, index);
else
return fn;
}
int main(int argc, char * argv[])
{
if (argc != 2)
{
std::cerr << "Usage: " << argv[0] << " file.stl" << std::endl;
return -1;
}
MeshcleanerWorker Worker;
Worker.LoadSTL(argv[1]);
if (!Worker.IsLoaded())
{
std::cerr << "Cannot open file " << argv[1] << std::endl;
return -1;
}
if (Worker.IsManifold())
{
std::cerr << "File is already manifold and doesn't need cleaning" << std::endl;
return 0;
}
Worker.Clean();
if (Worker.IsManifold())
{
std::cerr << "File cleaned successfully, writing result to " << file_basename(argv[1]) << "_fixed.stl" << std::endl;
std::stringstream fn;
fn << file_basename(argv[1]) << "_fixed.stl";
Worker.WriteSTL(fn.str());
return 0;
}
std::cout << "Cleaning failed" << std::endl;
return 1;
}