-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfc_simplify.go
More file actions
106 lines (90 loc) · 2.31 KB
/
fc_simplify.go
File metadata and controls
106 lines (90 loc) · 2.31 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
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
package constdp
import (
"github.com/TopoSimplify/hdb"
"github.com/TopoSimplify/lnr"
"github.com/TopoSimplify/node"
"github.com/TopoSimplify/opts"
"github.com/intdxdt/iter"
"sync"
)
//Simplify a feature class of linear geometries
//optional callback for the number of deformables
func SimplifyFeatureClass(id *iter.Igen, selfs []*ConstDP, opts *opts.Opts, callback ...func(n int)) {
var deformableCallback = func(_ int) {}
if len(callback) > 0 {
deformableCallback = callback[0]
}
var junctions = make(map[int][]int)
if opts.PlanarSelf {
instances := make([]*lnr.FC, len(selfs))
for i, sf := range selfs {
instances[i] = lnr.NewFC(sf.Coordinates(), sf.Id())
}
junctions = lnr.FCPlanarSelfIntersection(instances)
}
SimplifyInstances(id, selfs, junctions)
var constrained = opts.AvoidNewSelfIntersects ||
opts.PlanarSelf ||
opts.GeomRelation ||
opts.DirRelation ||
opts.DistRelation
if constrained {
var selections map[*node.Node]struct{}
var hulldb = hdb.NewHdb()
var deformables []node.Node
for _, self := range selfs {
for i := range self.Hulls {
deformables = append(deformables, self.Hulls[i])
}
node.Clear(&self.Hulls) // empty deque, this is for future splits
}
hulldb.Load(deformables)
for len(deformables) > 0 {
deformableCallback(len(deformables))
// 0. find deformable node
selections = findDeformableNodes(deformables, hulldb)
// 1. deform selected nodes
if len(selections) > 0 {
deformables = deformNodes(id, selections)
// 2. remove selected nodes from db
cleanUpDB(hulldb, selections)
// 3. add new deformations to db
hulldb.Load(deformables)
// 4. repeat until there are no deformables
} else {
deformables = deformables[:0]
}
}
groupHullsByFC(hulldb)
}
}
func SimplifyInstances(id *iter.Igen, selfs []*ConstDP, junctions map[int][]int) {
var wg sync.WaitGroup
wg.Add(ConcurProcs)
var stream = make(chan *ConstDP)
var out = make(chan *ConstDP, 2*ConcurProcs)
go func() {
for s := range selfs {
stream <- selfs[s]
}
close(stream)
}()
var fn = func(idx int) {
defer wg.Done()
for self := range stream {
self.Simplify(id, junctions[self.Id()])
out <- self
}
}
go func() {
for i := 0; i < ConcurProcs; i++ {
go fn(i)
}
}()
go func() {
wg.Wait()
close(out)
}()
for range out {
}
}