Mercurial > gemma
comparison pkg/mesh/meshserialize_v2.go @ 5680:a87900c0fd11 sr-v2
Remove triangles that are not registered in the spatial index.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 11 Feb 2024 18:40:37 +0100 |
parents | |
children | 33499bd1b829 |
comparison
equal
deleted
inserted
replaced
5679:03dfbe675842 | 5680:a87900c0fd11 |
---|---|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 | |
2 // without warranty, see README.md and license for details. | |
3 // | |
4 // SPDX-License-Identifier: AGPL-3.0-or-later | |
5 // License-Filename: LICENSES/AGPL-3.0.txt | |
6 // | |
7 // Copyright (C) 2024 by via donau | |
8 // – Österreichische Wasserstraßen-Gesellschaft mbH | |
9 // Software engineering by Intevation GmbH | |
10 // | |
11 // Author(s): | |
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> | |
13 | |
14 package mesh | |
15 | |
16 func (s *STRTree) optimizeForSerializationV2() { | |
17 s.removeUnusedTriangles() | |
18 // TODO: Implement me! | |
19 } | |
20 | |
21 // removeUnusedTriangles removes all triangles from the | |
22 // TIN that are not registered in the spatial index. | |
23 func (s *STRTree) removeUnusedTriangles() { | |
24 used := make([]bool, len(s.tin.Triangles)) | |
25 unused := len(used) | |
26 s.allTriangleIndices(func(indices []int32) { | |
27 for _, idx := range indices { | |
28 used[idx] = true | |
29 unused-- // They only occur once in the spatial index. | |
30 } | |
31 }) | |
32 if unused <= 0 { | |
33 return | |
34 } | |
35 newTris := make([][]int32, 0, len(s.tin.Triangles)-unused) | |
36 remap := map[int32]int32{} | |
37 for idx, tri := range s.tin.Triangles { | |
38 if used[idx] { | |
39 remap[int32(idx)] = int32(len(newTris)) | |
40 newTris = append(newTris, tri) | |
41 } | |
42 } | |
43 s.tin.Triangles = newTris | |
44 // Update the spatial index as the gaps are now closed. | |
45 s.allTriangleIndices(func(indices []int32) { | |
46 for i, idx := range indices { | |
47 indices[i] = remap[idx] | |
48 } | |
49 }) | |
50 } |