comparison cmd/isoareas/main.go @ 4543:2a707732331f iso-areas

Look into cuts for finding real class borders.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 26 Sep 2019 18:34:54 +0200
parents 56f4e8cbfab7
children e5ae16f6d846
comparison
equal deleted inserted replaced
4542:56f4e8cbfab7 4543:2a707732331f
87 if err != nil { 87 if err != nil {
88 log.Fatalf("error: %v\n", err) 88 log.Fatalf("error: %v\n", err)
89 } 89 }
90 } 90 }
91 91
92 type indexedCut struct {
93 cut octree.LineStringZ
94 index int32
95 }
96
92 func intersectTriangles(tri *octree.Triangulation, heights []float64) [][]octree.LineStringZ { 97 func intersectTriangles(tri *octree.Triangulation, heights []float64) [][]octree.LineStringZ {
93
94 type indexedCut struct {
95 cut octree.LineStringZ
96 index int32
97 }
98 98
99 cuts := make([][]indexedCut, len(heights)) 99 cuts := make([][]indexedCut, len(heights))
100 100
101 classes := make([][]int32, len(heights)+1) 101 classes := make([][]int32, len(heights)+1)
102 102
169 for j := 0; j < 3; j++ { 169 for j := 0; j < 3; j++ {
170 if mask&(1<<j) == 0 { 170 if mask&(1<<j) == 0 {
171 171
172 // TODO: Look into cuts to see 172 // TODO: Look into cuts to see
173 // if there are real intersections 173 // if there are real intersections
174 k := (j + 1) % 3 174
175 front := tri.Points[ti[j]] 175 var curr octree.LineStringZ
176 back := tri.Points[ti[k]] 176
177 177 for l := i - 1; l <= i; l++ {
178 curr := octree.LineStringZ{front, back} 178 if l < 0 || l >= len(cuts) {
179 continue
180 }
181 if curr = findCut(ns[j], cuts[l]); curr != nil {
182 break
183 }
184 }
185
186 if curr == nil {
187 k := (j + 1) % 3
188 front := tri.Points[ti[j]]
189 back := tri.Points[ti[k]]
190 curr = octree.LineStringZ{front, back}
191 }
179 192
180 segment: 193 segment:
181 for e := pb.open.Front(); e != nil; e = e.Next() { 194 for e := pb.open.Front(); e != nil; e = e.Next() {
182 line := e.Value.(octree.LineStringZ) 195 line := e.Value.(octree.LineStringZ)
183 first, last := line[0], line[len(line)-1] 196 first, last := line[0], line[len(line)-1]
197
198 front, back := curr[0], curr[len(curr)-1]
184 199
185 if back.EpsEquals(first) { 200 if back.EpsEquals(first) {
186 curr = append(curr, line[1:]...) 201 curr = append(curr, line[1:]...)
187 pb.open.Remove(e) 202 pb.open.Remove(e)
188 goto segment 203 goto segment
252 } 267 }
253 268
254 func neighbors(t *octree.Triangulation, idx int32) []int32 { 269 func neighbors(t *octree.Triangulation, idx int32) []int32 {
255 idx *= 3 270 idx *= 3
256 return t.Halfedges[idx : idx+3] 271 return t.Halfedges[idx : idx+3]
272 }
273
274 func findCut(needle int32, haystack []indexedCut) octree.LineStringZ {
275 lo, hi := 0, len(haystack)-1
276 for lo <= hi {
277 mid := (hi-lo)/2 + lo
278 switch v := haystack[mid].index; {
279 case v < needle:
280 lo = mid + 1
281 case v > needle:
282 hi = mid - 1
283 default:
284 return haystack[mid].cut
285 }
286 }
287 return nil
257 } 288 }
258 289
259 func contains(needle int32, haystack []int32) bool { 290 func contains(needle int32, haystack []int32) bool {
260 lo, hi := 0, len(haystack)-1 291 lo, hi := 0, len(haystack)-1
261 for lo <= hi { 292 for lo <= hi {