-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplify.go
More file actions
76 lines (62 loc) · 1.71 KB
/
simplify.go
File metadata and controls
76 lines (62 loc) · 1.71 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
70
71
72
73
74
75
76
package constdp
import (
"github.com/TopoSimplify/constrain"
"github.com/TopoSimplify/hdb"
"github.com/TopoSimplify/node"
"github.com/intdxdt/iter"
)
//Line simplification at a given threshold
func (self *ConstDP) Simplify(id *iter.Igen, constVertices ...[]int) *ConstDP {
var constVertexSet []int
var constVerts []int
if len(constVertices) > 0 {
constVerts = constVertices[0]
}
//state
self.State().MarkDirty()
self.SimpleSet.Empty()
self.Hulls = self.Decompose(id)
// constrain hulls to self intersects
self.Hulls, _, constVertexSet = constrain.ToSelfIntersects(
id, self.Hulls, self.Polyline(), self.Options(), constVerts,
)
var db = hdb.NewHdb()
var selections map[*node.Node]struct{}
var deformables = make([]node.Node, 0, len(self.Hulls))
for i := range self.Hulls {
deformables = append(deformables, self.Hulls[i])
}
// empty deque, this is for future splits
node.Clear(&self.Hulls)
db.Load(deformables)
for len(deformables) > 0 {
// 0. find deformable node
selections = findDeformableNodes(deformables, db)
// 1. deform selected nodes
if len(selections) > 0 {
deformables = deformNodes(id, selections)
// 2. remove selected nodes from db
cleanUpDB(db, selections)
// 3. add new deformations to db
db.Load(deformables)
} else {
deformables = deformables[:0]
}
// 4. repeat until there are no deformables
}
self.AggregateSimpleSegments(
id, db, constVertexSet, self.ValidateMerge,
)
node.Clear(&self.Hulls)
self.SimpleSet.Empty()
var hull *node.Node
var nodes = db.All()
for i := range nodes {
hull = nodes[i]
self.Hulls = append(self.Hulls, *hull)
self.SimpleSet.Extend(hull.Range.I, hull.Range.J)
}
//state
self.State().MarkClean()
return self
}