forked from mfbonfigli/gocesiumtiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
132 lines (114 loc) · 3.56 KB
/
options.go
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
129
130
131
132
package tiler
import (
"runtime"
"github.com/mfbonfigli/gocesiumtiler/v2/version"
)
type TilerEvent int
const (
EventReadLasHeaderStarted TilerEvent = iota
EventReadLasHeaderCompleted
EventReadLasHeaderError
EventPointLoadingStarted
EventPointLoadingCompleted
EventPointLoadingError
EventBuildStarted
EventBuildCompleted
EventBuildError
EventExportStarted
EventExportCompleted
EventExportError
)
type TilerOptions struct {
gridSize float64
maxDepth int
elevationOffset float64
eightBitColors bool
geoidElevation bool
numWorkers int
minPointsPerTile int
callback TilerCallback
version version.TilesetVersion
}
type tilerOptionsFn func(*TilerOptions)
type TilerCallback func(event TilerEvent, inputDesc string, elapsed int64, msg string)
// NewDefaultTilerOptions returns sensible defaults for tiling options
func NewDefaultTilerOptions() *TilerOptions {
return &TilerOptions{
gridSize: 20,
maxDepth: 10,
elevationOffset: 0,
numWorkers: runtime.NumCPU(),
minPointsPerTile: 5000,
eightBitColors: false,
geoidElevation: false,
callback: nil,
version: version.TilesetVersion_1_0,
}
}
// NewTilerOptions returns default tiler options modified using the
// provided manipulating functions
func NewTilerOptions(optFn ...tilerOptionsFn) *TilerOptions {
opts := NewDefaultTilerOptions()
for _, fn := range optFn {
fn(opts)
}
return opts
}
// WithGridSize sets the max grid size, i.e. the approximate max allowed spacing between
// any two points at the coarser level of detail. Expressed in meters.
func WithGridSize(size float64) tilerOptionsFn {
return func(opt *TilerOptions) {
opt.gridSize = size
}
}
// WithMaxDepth sets the max depth, i.e. the maximum number of levels the tree can reach.
func WithMaxDepth(maxDepth int) tilerOptionsFn {
return func(opt *TilerOptions) {
opt.maxDepth = maxDepth
}
}
// WithElevationOffset sets the Z offset to force on points, in meters. Only use this
// if the input coordinates are expressed as elevation above the geoid or ellipsoid.
func WithElevationOffset(offset float64) tilerOptionsFn {
return func(opt *TilerOptions) {
opt.elevationOffset = offset
}
}
// WithWorkerNumber sets the number of workers to use to read the las files or to
// run the export jobs
func WithWorkerNumber(numWorkers int) tilerOptionsFn {
return func(opt *TilerOptions) {
opt.numWorkers = numWorkers
}
}
// WithMinPointsPerTile returns the minimum number of points a tile must store to exist.
// Used to avoid almost empty tiles that could be consolidated with their parent.
func WithMinPointsPerTile(minPointsPerTile int) tilerOptionsFn {
return func(opt *TilerOptions) {
opt.minPointsPerTile = minPointsPerTile
}
}
// WithCallback sets a function that should be invoked as the tiler job runs
func WithCallback(callback TilerCallback) tilerOptionsFn {
return func(opt *TilerOptions) {
opt.callback = callback
}
}
// WithEightBitColors true forces the tiler to interpret the color info on the file as eight bit colors
func WithEightBitColors(eightBit bool) tilerOptionsFn {
return func(opt *TilerOptions) {
opt.eightBitColors = eightBit
}
}
// WithGeoidElevation true tells the tiler to interpret the Z elevation as elevation over the geoid
func WithGeoidElevation(geoid bool) tilerOptionsFn {
return func(opt *TilerOptions) {
opt.geoidElevation = geoid
}
}
// WithTilesetVersion sets the version of the tilsets to generate
func WithTilesetVersion(v version.TilesetVersion) tilerOptionsFn {
return func(opt *TilerOptions) {
opt.version = v
}
}