-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSlicer.cc
68 lines (64 loc) · 1.59 KB
/
Slicer.cc
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
#include "Slicer.hh"
#include <fstream>
#include "Slicing.hh"
#include "BufferWrite.hh"
using namespace std;
void Slicer::slicing() {
double zmax = stl.getZmax();
double zmin = stl.getZmin();
numLayer = (zmax - zmin - zStart) / zgap + 1;
layers.reserve(numLayer);
checkLayers = new bool[numLayer];
for (int i = 0; i < numLayer; i++)
checkLayers[i] = false;
for (double z = zmin + zStart; z < zmax; z += zgap) {
layers.push_back(Layer(z));
}
cout << finishedCount << "/" << numLayer;
for (int i = 0; i < NUM_THREADS; i++) {
threads[i] = thread(&Slicer::threadLayer, this);
}
for (int i = 0; i < NUM_THREADS; i++) {
threads[i].join();
}
/*
Support material part, not required for now,
it's also a big project
*/
/*
if (needSupportMaterial) {
cout << "\nAdding Support Material...";
//addSupportMaterial();
}
*/
cout << "\nWriting...";
#if 0 //Write to gcode file directly
ofstream f(gcode_target, ios_base::out | ios_base::app);
for (const auto& layer : layers)
layer.commandsOut(f);
#endif
#if 1 //Write to writing buffer
BufferWrite buffer(gcode_target);
for (const auto& layer : layers)
layer.commandsOut(buffer);
buffer.flush();
#endif
cout << "\nDone!\n";
}
//mult-threads management function
void Slicer::threadLayer() {
for (int index = 0; index < numLayer; index++) {
checkMutex.lock();
if (checkLayers[index]) {
checkMutex.unlock();
continue;
}
checkLayers[index] = true;
checkMutex.unlock();
Slicing cl(stl, layers[index]);
countMutex.lock();
finishedCount++;
cout << "\r" << finishedCount << "/" << numLayer;
countMutex.unlock();
}
}