diff options
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs')
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs | 141 |
1 files changed, 0 insertions, 141 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs deleted file mode 100644 index 7162758..0000000 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Editing/Flatten.cs +++ /dev/null | |||
@@ -1,141 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace libTerrain | ||
29 | { | ||
30 | partial class Channel | ||
31 | { | ||
32 | /// <summary> | ||
33 | /// Flattens the area underneath rx,ry by moving it to the average of the area. Uses a spherical mask provided by the raise() function. | ||
34 | /// </summary> | ||
35 | /// <param name="rx">The X coordinate of the terrain mask</param> | ||
36 | /// <param name="ry">The Y coordinate of the terrain mask</param> | ||
37 | /// <param name="size">The size of the terrain mask</param> | ||
38 | /// <param name="amount">The scale of the terrain mask</param> | ||
39 | public void Flatten(double rx, double ry, double size, double amount) | ||
40 | { | ||
41 | FlattenSlow(rx, ry, size, amount); | ||
42 | } | ||
43 | |||
44 | private void FlattenSlow(double rx, double ry, double size, double amount) | ||
45 | { | ||
46 | // Generate the mask | ||
47 | Channel temp = new Channel(w, h); | ||
48 | temp.Fill(0); | ||
49 | temp.Raise(rx, ry, size, amount); | ||
50 | temp.Normalise(); | ||
51 | double total_mod = temp.Sum(); | ||
52 | |||
53 | // Establish the average height under the area | ||
54 | Channel newmap = new Channel(w, h); | ||
55 | newmap.map = (double[,]) map.Clone(); | ||
56 | |||
57 | newmap *= temp; | ||
58 | |||
59 | double total_terrain = newmap.Sum(); | ||
60 | double avg_height = total_terrain/total_mod; | ||
61 | |||
62 | // Create a flat terrain using the average height | ||
63 | Channel flat = new Channel(w, h); | ||
64 | flat.Fill(avg_height); | ||
65 | |||
66 | // Blend the current terrain with the average height terrain | ||
67 | // using the "raised" empty terrain as a mask | ||
68 | Blend(flat, temp); | ||
69 | } | ||
70 | |||
71 | // TODO: unused | ||
72 | // private void FlattenFast(double rx, double ry, double size, double amount) | ||
73 | // { | ||
74 | // int x, y; | ||
75 | // double avg = 0; | ||
76 | // double div = 0; | ||
77 | |||
78 | // int minX = Math.Max(0, (int) (rx - (size + 1))); | ||
79 | // int maxX = Math.Min(w, (int) (rx + (size + 1))); | ||
80 | // int minY = Math.Max(0, (int) (ry - (size + 1))); | ||
81 | // int maxY = Math.Min(h, (int) (ry + (size + 1))); | ||
82 | |||
83 | // for (x = minX; x < maxX; x++) | ||
84 | // { | ||
85 | // for (y = minY; y < maxY; y++) | ||
86 | // { | ||
87 | // double z = size; | ||
88 | // z *= z; | ||
89 | // z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); | ||
90 | |||
91 | // if (z < 0) | ||
92 | // z = 0; | ||
93 | |||
94 | // avg += z*amount; | ||
95 | // div += z; | ||
96 | // } | ||
97 | // } | ||
98 | |||
99 | // double height = avg/div; | ||
100 | |||
101 | // for (x = minX; x < maxX; x++) | ||
102 | // { | ||
103 | // for (y = minY; y < maxY; y++) | ||
104 | // { | ||
105 | // double z = size; | ||
106 | // z *= z; | ||
107 | // z -= ((x - rx)*(x - rx)) + ((y - ry)*(y - ry)); | ||
108 | |||
109 | // if (z > 0.0) | ||
110 | // Set(x, y, Tools.LinearInterpolate(map[x, y], height, z)); | ||
111 | // } | ||
112 | // } | ||
113 | // } | ||
114 | |||
115 | public void Flatten(Channel mask, double amount) | ||
116 | { | ||
117 | // Generate the mask | ||
118 | Channel temp = mask*amount; | ||
119 | temp.Clip(0, 1); // Cut off out-of-bounds values | ||
120 | |||
121 | double total_mod = temp.Sum(); | ||
122 | |||
123 | // Establish the average height under the area | ||
124 | Channel map = new Channel(w, h); | ||
125 | map.map = (double[,]) this.map.Clone(); | ||
126 | |||
127 | map *= temp; | ||
128 | |||
129 | double total_terrain = map.Sum(); | ||
130 | double avg_height = total_terrain/total_mod; | ||
131 | |||
132 | // Create a flat terrain using the average height | ||
133 | Channel flat = new Channel(w, h); | ||
134 | flat.Fill(avg_height); | ||
135 | |||
136 | // Blend the current terrain with the average height terrain | ||
137 | // using the "raised" empty terrain as a mask | ||
138 | Blend(flat, temp); | ||
139 | } | ||
140 | } | ||
141 | } | ||