-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathslice.go
More file actions
69 lines (56 loc) · 1.42 KB
/
Copy pathslice.go
File metadata and controls
69 lines (56 loc) · 1.42 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
// TODO: allow the client to slice, infill, e.g. independently
// Package slice provides types and functions for slicing and compiling STL format 3D models
// into G-code to be used for 3D printing.
package slice
import (
"fmt"
"os"
"sync"
"sigint.ca/slice/stl"
)
var debug bool
// A Config variable specifies a slicing configuration.
type Config struct {
DebugMode bool
LayerHeight float64
LineWidth float64
Infill Infiller
}
func dprintf(format string, args ...interface{}) {
if debug {
fmt.Fprintf(os.Stderr, "[ "+format+" ]\n", args...)
}
}
func wprintf(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "WARNING: "+format+"\n", args...)
}
// Slice slices and stl.Solid into layers.
func Slice(s *stl.Solid, cfg Config) ([]*Layer, error) {
debug = cfg.DebugMode
min, max := s.Bounds()
nLayers := int(0.5 + (max.Z-min.Z)/cfg.LayerHeight)
layers := make([]*Layer, nLayers)
h := cfg.LayerHeight
// slice in parallel if not in debug mode
if debug {
for i := range layers {
layers[i] = sliceLayer(i, min.Z+0.01+float64(i)*h, s, cfg)
for _, r := range layers[i].regions {
cfg.Infill.Fill(r)
}
}
} else {
var wg sync.WaitGroup
for i := range layers {
wg.Add(1)
go func(i int, z float64) {
layers[i] = sliceLayer(i, z, s, cfg)
//layers[i].genInfill(cfg)
wg.Done()
}(i, min.Z+0.01+float64(i)*h)
}
wg.Wait()
}
dprintf("sliced %d layers", nLayers)
return layers, nil
}