diff options
Diffstat (limited to 'OpenSim.Terrain.BasicTerrain/Normalise.cs')
-rw-r--r-- | OpenSim.Terrain.BasicTerrain/Normalise.cs | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/OpenSim.Terrain.BasicTerrain/Normalise.cs b/OpenSim.Terrain.BasicTerrain/Normalise.cs deleted file mode 100644 index 0d37f44..0000000 --- a/OpenSim.Terrain.BasicTerrain/Normalise.cs +++ /dev/null | |||
@@ -1,102 +0,0 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Terrain.BasicTerrain | ||
6 | { | ||
7 | static class Normalise | ||
8 | { | ||
9 | /// <summary> | ||
10 | /// Converts the heightmap to values ranging from 0..1 | ||
11 | /// </summary> | ||
12 | /// <param name="map">The heightmap to be normalised</param> | ||
13 | public static void normalise(float[,] map) | ||
14 | { | ||
15 | double max = findMax(map); | ||
16 | double min = findMin(map); | ||
17 | int w = map.GetLength(0); | ||
18 | int h = map.GetLength(1); | ||
19 | |||
20 | int x, y; | ||
21 | |||
22 | for (x = 0; x < w; x++) | ||
23 | { | ||
24 | for (y = 0; y < h; y++) | ||
25 | { | ||
26 | map[x, y] = (float)((map[x, y] - min) * (1.0 / (max - min))); | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | |||
31 | /// <summary> | ||
32 | /// Converts the heightmap to values ranging from 0..<newmax> | ||
33 | /// </summary> | ||
34 | /// <param name="map">The heightmap to be normalised</param> | ||
35 | /// <param name="newmax">The new maximum height value of the map</param> | ||
36 | public static void normalise(float[,] map, double newmax) | ||
37 | { | ||
38 | double max = findMax(map); | ||
39 | double min = findMin(map); | ||
40 | int w = map.GetLength(0); | ||
41 | int h = map.GetLength(1); | ||
42 | |||
43 | int x, y; | ||
44 | |||
45 | for (x = 0; x < w; x++) | ||
46 | { | ||
47 | for (y = 0; y < h; y++) | ||
48 | { | ||
49 | map[x, y] = (float)((map[x, y] - min) * (1.0 / (max - min)) * newmax); | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | |||
54 | /// <summary> | ||
55 | /// Finds the largest value in the heightmap | ||
56 | /// </summary> | ||
57 | /// <param name="map">The heightmap</param> | ||
58 | /// <returns>The highest value</returns> | ||
59 | public static double findMax(float[,] map) | ||
60 | { | ||
61 | int x, y; | ||
62 | int w = map.GetLength(0); | ||
63 | int h = map.GetLength(1); | ||
64 | double max = double.MinValue; | ||
65 | |||
66 | for (x = 0; x < w; x++) | ||
67 | { | ||
68 | for (y = 0; y < h; y++) | ||
69 | { | ||
70 | if (map[x, y] > max) | ||
71 | max = map[x, y]; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | return max; | ||
76 | } | ||
77 | |||
78 | /// <summary> | ||
79 | /// Finds the lowest value in a heightmap | ||
80 | /// </summary> | ||
81 | /// <param name="map">The heightmap</param> | ||
82 | /// <returns>The minimum value</returns> | ||
83 | public static double findMin(float[,] map) | ||
84 | { | ||
85 | int x, y; | ||
86 | int w = map.GetLength(0); | ||
87 | int h = map.GetLength(1); | ||
88 | double min = double.MaxValue; | ||
89 | |||
90 | for (x = 0; x < w; x++) | ||
91 | { | ||
92 | for (y = 0; y < h; y++) | ||
93 | { | ||
94 | if (map[x, y] < min) | ||
95 | min = map[x, y]; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | return min; | ||
100 | } | ||
101 | } | ||
102 | } | ||