Mercurial > gemma
annotate pkg/octree/vertex.go @ 727:41c8dc61f38f
Moved octree loading stuff to octree package.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sat, 22 Sep 2018 21:57:30 +0200 |
parents | cmd/octree2contour/vertex.go@5af9ab39e715 |
children | b0bd242ff821 |
rev | line source |
---|---|
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
1 package octree |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
3 import ( |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
4 "bytes" |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
5 "encoding/binary" |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
6 "io" |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
7 "math" |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
8 ) |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
10 type ( |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
11 Vertex struct { |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
12 X float64 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
13 Y float64 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
14 Z float64 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
15 } |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
16 |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
17 Triangle [3]Vertex |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
18 |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
19 Line [2]Vertex |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
20 |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
21 LineStringZ []Vertex |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
22 MultiLineStringZ []LineStringZ |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
23 ) |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
24 |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
25 const ( |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
26 wkbNDR byte = 1 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
27 wkbPointZ uint32 = 1000 + 1 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
28 wkbLineStringZ uint32 = 1000 + 2 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
29 wkbMultiLineStringZ uint32 = 1000 + 5 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
30 ) |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
31 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
32 func (v *Vertex) Minimize(w Vertex) { |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
33 if w.X < v.X { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
34 v.X = w.X |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
36 if w.Y < v.Y { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
37 v.Y = w.Y |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
39 if w.Z < v.Z { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
40 v.Z = w.Z |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
44 func (v *Vertex) Maximize(w Vertex) { |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
45 if w.X > v.X { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
46 v.X = w.X |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
48 if w.Y > v.Y { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
49 v.Y = w.Y |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
51 if w.Z > v.Z { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
52 v.Z = w.Z |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
56 func (v Vertex) Sub(w Vertex) Vertex { |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
57 return Vertex{ |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
58 v.X - w.X, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
59 v.Y - w.Y, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
60 v.Z - w.Z, |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 } |
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 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
64 func (v Vertex) Add(w Vertex) Vertex { |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
65 return Vertex{ |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
66 v.X + w.X, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
67 v.Y + w.Y, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
68 v.Z + w.Z, |
687
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
69 } |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
70 } |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
71 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
72 func (v Vertex) scale(s float64) Vertex { |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
73 return Vertex{ |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
74 s * v.X, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
75 s * v.Y, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
76 s * v.Z, |
687
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
77 } |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
78 } |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
79 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
80 func Interpolate(v1, v2 Vertex) func(Vertex) Vertex { |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
81 v2 = v2.Sub(v1) |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
82 return func(s Vertex) Vertex { |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
83 return Vertex{ |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
84 v2.X*s.X + v1.X, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
85 v2.Y*s.Y + v1.Y, |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
86 v2.Z*s.Z + v1.Z, |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 } |
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
91 func (a Vertex) Less(b Vertex) bool { |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
92 return a.X < b.X || a.Y < b.Y || a.Z < b.Z |
674
120a82bd9953
octree: Added loading frame for contour generation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 } |
687
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
94 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
95 func NewLine(p1, p2 Vertex) Line { |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
96 return Line{ |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
97 p2.Sub(p1), |
687
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
98 p1, |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
99 } |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
100 } |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
101 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
102 func (l Line) Eval(t float64) Vertex { |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
103 return l[0].scale(t).Add(l[1]) |
687
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
104 } |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
105 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
106 func (l Line) IntersectHorizontal(h float64) Vertex { |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
107 t := (h - l[1].Z) / l[0].Z |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
108 return l.Eval(t) |
687
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
109 } |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
110 |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
111 func side(z, h float64) int { |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
112 switch { |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
113 case z < h: |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
114 return -1 |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
115 case z > h: |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
116 return +1 |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
117 } |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
118 return 0 |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
119 } |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
120 |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
121 func (t *Triangle) IntersectHorizontal(h float64) LineStringZ { |
687
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
122 sides := [3]int{ |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
123 side(t[0].Z, h), |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
124 side(t[1].Z, h), |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
125 side(t[2].Z, h), |
687
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
126 } |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
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:
718
diff
changeset
|
128 var points LineStringZ |
689
614135d69823
octree: prepare storing the lines to file in contouring tool.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
687
diff
changeset
|
129 |
687
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
130 for i := 0; i < 3; i++ { |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
131 j := (i + 1) % 3 |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
132 si := sides[i] |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
133 sj := sides[j] |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
134 |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
135 switch { |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
136 case si == 0 && sj == 0: |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
137 // both on plane |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
138 points = append(points, t[i], t[j]) |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
139 case si == 0 && sj != 0: |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
140 // first on plane |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
141 points = append(points, t[i]) |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
142 case si != 0 && sj == 0: |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
143 // second on plane |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
144 points = append(points, t[j]) |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
145 case si == sj: |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
146 // both on same side |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
147 default: |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
148 // real intersection |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
149 v := NewLine(t[i], t[j]).IntersectHorizontal(h) |
687
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
150 points = append(points, v) |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
151 } |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
152 } |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
153 |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
154 return points |
be90ab542aa7
octree: contouring: Do the math to calculate the intersection points of the triangles and the planes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
674
diff
changeset
|
155 } |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
156 |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
157 func (v *Vertex) read(r io.Reader) error { |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
158 var buf [8]byte |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
159 b := buf[:] |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
160 if _, err := io.ReadFull(r, b); err != nil { |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
161 return nil |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
162 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
163 v.X = math.Float64frombits(binary.LittleEndian.Uint64(b)) |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
164 if _, err := io.ReadFull(r, b); err != nil { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
165 return nil |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
166 } |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
167 v.Y = math.Float64frombits(binary.LittleEndian.Uint64(b)) |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
168 if _, err := io.ReadFull(r, b); err != nil { |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
169 return nil |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
170 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
171 v.Z = math.Float64frombits(binary.LittleEndian.Uint64(b)) |
726
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
172 return nil |
5af9ab39e715
Renamed a few types to uppercase names to prepare the move to the octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
718
diff
changeset
|
173 } |
727
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
174 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
175 func (mls MultiLineStringZ) AsWKB() []byte { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
176 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
177 var buf bytes.Buffer |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
178 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
179 binary.Write(&buf, binary.LittleEndian, wkbNDR) |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
180 binary.Write(&buf, binary.LittleEndian, wkbMultiLineStringZ) |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
181 binary.Write(&buf, binary.LittleEndian, uint32(len(mls))) |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
182 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
183 for _, ml := range mls { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
184 binary.Write(&buf, binary.LittleEndian, wkbNDR) |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
185 binary.Write(&buf, binary.LittleEndian, wkbLineStringZ) |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
186 binary.Write(&buf, binary.LittleEndian, uint32(len(ml))) |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
187 for _, p := range ml { |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
188 binary.Write(&buf, binary.LittleEndian, math.Float64bits(p.X)) |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
189 binary.Write(&buf, binary.LittleEndian, math.Float64bits(p.Y)) |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
190 binary.Write(&buf, binary.LittleEndian, math.Float64bits(p.Z)) |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
191 } |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
192 } |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
193 |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
194 return buf.Bytes() |
41c8dc61f38f
Moved octree loading stuff to octree package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
726
diff
changeset
|
195 } |