Mercurial > gemma
annotate pkg/mesh/loader.go @ 4931:e41d42be0e13 fairway-marks-import
One more callback to avoid code duplication more consequently
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 14 Feb 2020 19:34:08 +0100 |
parents | f4abfd0ee8ad |
children | 5f47eeea988d |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
2 // without warranty, see README.md and license for details. |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
729
diff
changeset
|
13 |
4827
f4abfd0ee8ad
Renamed octree package to mesh as there is no octree any more.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4824
diff
changeset
|
14 package mesh |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "bufio" |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
18 "bytes" |
4656
a2f16987911b
Removed lz4 from loader, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4650
diff
changeset
|
19 "compress/gzip" |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "encoding/binary" |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "log" |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 ) |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
24 func (s *STRTree) deserializeIndex(r *bufio.Reader) error { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
25 var numIndex int32 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
26 if err := binary.Read(r, binary.LittleEndian, &numIndex); err != nil { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
27 return err |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
28 } |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
29 index := make([]int32, numIndex) |
4658
4bbfe3dd2ab5
Completed usage of STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4656
diff
changeset
|
30 s.index = index |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
31 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
32 var last int32 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
33 for i := range index { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
34 v, err := binary.ReadVarint(r) |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
35 if err != nil { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
36 return err |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
37 } |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
38 value := int32(v) + last |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
39 index[i] = value |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
40 last = value |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
41 } |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
43 return nil |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
44 } |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
45 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
46 func (s *STRTree) deserializeBBoxes(r *bufio.Reader) error { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
47 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
48 var numBBoxes int32 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
49 if err := binary.Read(r, binary.LittleEndian, &numBBoxes); err != nil { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
50 return err |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
51 } |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
52 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
53 bboxes := make([]Box2D, numBBoxes) |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
54 s.bboxes = bboxes |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
55 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
56 var err error |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
57 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
58 read := func(v *float64) { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
59 if err == nil { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
60 err = binary.Read(r, binary.LittleEndian, v) |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
61 } |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
64 for i := range bboxes { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
65 read(&bboxes[i].X1) |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
66 read(&bboxes[i].Y1) |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
67 read(&bboxes[i].X2) |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
68 read(&bboxes[i].Y2) |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
71 return err |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
72 } |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
73 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
74 func (s *STRTree) deserialize(r *bufio.Reader) error { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
75 s.tin = new(Tin) |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
76 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
77 if err := s.tin.Deserialize(r); err != nil { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
78 return err |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
79 } |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
80 var numEntries uint8 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
81 if err := binary.Read(r, binary.LittleEndian, &numEntries); err != nil { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
82 return err |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
83 } |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
84 s.Entries = int(numEntries) |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
85 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
86 if err := s.deserializeIndex(r); err != nil { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
87 return err |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
88 } |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
89 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
90 return s.deserializeBBoxes(r) |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
91 } |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
92 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
93 func (s *STRTree) FromBytes(data []byte) error { |
4656
a2f16987911b
Removed lz4 from loader, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4650
diff
changeset
|
94 r, err := gzip.NewReader(bytes.NewReader(data)) |
a2f16987911b
Removed lz4 from loader, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4650
diff
changeset
|
95 if err != nil { |
a2f16987911b
Removed lz4 from loader, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4650
diff
changeset
|
96 return err |
a2f16987911b
Removed lz4 from loader, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4650
diff
changeset
|
97 } |
a2f16987911b
Removed lz4 from loader, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4650
diff
changeset
|
98 return s.deserialize(bufio.NewReader(r)) |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
99 } |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
100 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
101 func (t *Tin) Deserialize(r *bufio.Reader) error { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
102 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
103 if err := binary.Read(r, binary.LittleEndian, &t.EPSG); err != nil { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
104 return err |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
105 } |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
106 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
107 log.Printf("info: EPSG: %d\n", t.EPSG) |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
108 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
109 if err := t.Min.Read(r); err != nil { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
110 return err |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
111 } |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
112 |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
113 if err := t.Max.Read(r); err != nil { |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
114 return err |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1017
diff
changeset
|
117 log.Printf("info: BBOX: [[%f, %f, %f], [%f, %f, %f]]\n", |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
118 t.Min.X, t.Min.Y, t.Min.Z, |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
119 t.Max.X, t.Max.Y, t.Max.Z) |
678
7bb961d750b6
octree: traverse horizontally over tree to find out which triangles to process.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
120 |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 var numVertices uint32 |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 if err := binary.Read(r, binary.LittleEndian, &numVertices); err != nil { |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
123 return err |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1017
diff
changeset
|
126 log.Printf("info: vertices: %d\n", numVertices) |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
707
diff
changeset
|
128 vertices := make([]Vertex, numVertices) |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
129 t.Vertices = vertices |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 for i := range vertices { |
729
b0bd242ff821
Removed vertex duplicate.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
727
diff
changeset
|
132 if err := vertices[i].Read(r); err != nil { |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
133 return err |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 var numTriangles uint32 |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 if err := binary.Read(r, binary.LittleEndian, &numTriangles); err != nil { |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
139 return err |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 |
1691
de09bd3b5c05
Octree: Fixed a few golint quirks and normalized logging a bit.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
1017
diff
changeset
|
142 log.Printf("info: triangles: %d\n", numTriangles) |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 indices := make([]int32, 3*numTriangles) |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 triangles := make([][]int32, numTriangles) |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
146 t.Triangles = triangles |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 var last int32 |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 for i := range triangles { |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 tri := indices[:3] |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 indices = indices[3:] |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 triangles[i] = tri |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 for j := range tri { |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 v, err := binary.ReadVarint(r) |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 if err != nil { |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
157 return err |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 value := int32(v) + last |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 tri[j] = value |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 last = value |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 |
4650
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
165 return nil |
f5fce22184da
Added a deserializer from STRTrees.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2465
diff
changeset
|
166 } |