aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
diff options
context:
space:
mode:
authorAdam Frisby2007-07-21 22:25:42 +0000
committerAdam Frisby2007-07-21 22:25:42 +0000
commitf84937367f7180140bd17444d507977f9b7e3d2e (patch)
tree944f2824669e42b5df3b6655bd09999c89b50376 /OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
parent* Renamed terrain functions to match OpenSim naming styles. (diff)
downloadopensim-SC_OLD-f84937367f7180140bd17444d507977f9b7e3d2e.zip
opensim-SC_OLD-f84937367f7180140bd17444d507977f9b7e3d2e.tar.gz
opensim-SC_OLD-f84937367f7180140bd17444d507977f9b7e3d2e.tar.bz2
opensim-SC_OLD-f84937367f7180140bd17444d507977f9b7e3d2e.tar.xz
* Deleted libTerrain-BSD.dll
* Added libTerrain to BasicTerrain directly as a subfolder
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs264
1 files changed, 264 insertions, 0 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
new file mode 100644
index 0000000..41d20f6
--- /dev/null
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
@@ -0,0 +1,264 @@
1/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions are
4met:
5
6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8
9 * Redistributions in binary form must reproduce the above
10 copyright notice, this list of conditions and the following
11 disclaimer in the documentation and/or other materials provided
12 with the distribution.
13
14 * Neither the name of libTerrain nor the names of
15 its contributors may be used to endorse or promote products
16 derived from this software without specific prior written
17 permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32using System;
33using System.Collections.Generic;
34using System.Text;
35
36namespace libTerrain
37{
38 partial class Channel
39 {
40 public Channel normalise()
41 {
42 double max = findMax();
43 double min = findMin();
44
45 int x, y;
46
47 for (x = 0; x < w; x++)
48 {
49 for (y = 0; y < h; y++)
50 {
51 map[x, y] = (map[x, y] - min) * (1.0 / (max - min));
52 }
53 }
54
55 return this;
56 }
57
58 public Channel normalise(double minv, double maxv)
59 {
60 double max = findMax();
61 double min = findMin();
62
63 int x, y;
64
65 for (x = 0; x < w; x++)
66 {
67 for (y = 0; y < h; y++)
68 {
69 double val = (map[x, y] - min) * (1.0 / max - min);
70 val *= maxv - minv;
71 val += minv;
72
73 map[x, y] = val;
74 }
75 }
76
77 return this;
78 }
79
80 public Channel clip()
81 {
82 int x, y;
83
84 for (x = 0; x < w; x++)
85 {
86 for (y = 0; y < h; y++)
87 {
88 setClip(x, y, map[x, y]);
89 }
90 }
91
92 return this;
93 }
94
95 public Channel clip(double min, double max)
96 {
97 int x, y;
98 for (x = 0; x < w; x++)
99 {
100 for (y = 0; y < h; y++)
101 {
102 double val = map[x, y];
103 if (val > max) val = max;
104 if (val < min) val = min;
105 map[x, y] = val;
106 }
107 }
108 return this;
109 }
110
111 public Channel crop(int x1, int y1, int x2, int y2)
112 {
113 int width = x1 - x2 + 1;
114 int height = y1 - y2 + 1;
115 Channel chan = new Channel(width, height);
116
117 int x, y;
118 int nx, ny;
119
120 nx = 0;
121 for (x = x1; x < x2; x++)
122 {
123 ny = 0;
124 for (y = y1; y < y2; y++)
125 {
126 chan.map[nx, ny] = map[x, y];
127
128 ny++;
129 }
130 nx++;
131 }
132
133 return this;
134 }
135
136 public Channel addClip(Channel other)
137 {
138 int x, y;
139 for (x = 0; x < w; x++)
140 {
141 for (y = 0; y < h; y++)
142 {
143 map[x, y] = other.map[x, y];
144 if (map[x, y] > 1)
145 map[x, y] = 1;
146 if (map[x, y] < 0)
147 map[x, y] = 0;
148 }
149 }
150 return this;
151 }
152
153 public void smooth(double amount)
154 {
155 double area = amount;
156 double step = amount / 4.0;
157
158 double[,] manipulate = new double[w, h];
159 int x, y;
160 double n, l;
161 for (x = 0; x < w; x++)
162 {
163 for (y = 0; y < h; y++)
164 {
165 double average = 0.0;
166 int avgsteps = 0;
167
168 for (n = 0.0 - area; n < area; n += step)
169 {
170 for (l = 0.0 - area; l < area; l += step)
171 {
172 avgsteps++;
173 average += getBilinearInterpolate(x + n, y + l);
174 }
175 }
176
177 manipulate[x, y] = average / avgsteps;
178 }
179 }
180 map = manipulate;
181 }
182
183 public void pertubation(double amount)
184 {
185 // Simple pertubation filter
186 double[,] manipulated = new double[w, h];
187 Random generator = new Random(seed); // Seeds FTW!
188 //double amount = 8.0;
189
190 int x, y;
191 for (x = 0; x < w; x++)
192 {
193 for (y = 0; y < h; y++)
194 {
195 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0);
196 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0);
197 double p = getBilinearInterpolate(offset_x, offset_y);
198 manipulated[x, y] = p;
199 }
200 }
201 map = manipulated;
202 }
203
204 public void pertubationMask(Channel mask)
205 {
206 // Simple pertubation filter
207 double[,] manipulated = new double[w, h];
208 Random generator = new Random(seed); // Seeds FTW!
209 //double amount = 8.0;
210
211 double amount;
212
213 int x, y;
214 for (x = 0; x < w; x++)
215 {
216 for (y = 0; y < h; y++)
217 {
218 amount = mask.map[x, y];
219 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0);
220 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0);
221
222 if (offset_x > w)
223 offset_x = w - 1;
224 if (offset_y > h)
225 offset_y = h - 1;
226 if (offset_y < 0)
227 offset_y = 0;
228 if (offset_x < 0)
229 offset_x = 0;
230
231 double p = getBilinearInterpolate(offset_x, offset_y);
232 manipulated[x, y] = p;
233 }
234 }
235 map = manipulated;
236 }
237
238 public Channel blend(Channel other, double amount)
239 {
240 int x, y;
241 for (x = 0; x < w; x++)
242 {
243 for (y = 0; y < h; y++)
244 {
245 map[x, y] = Tools.linearInterpolate(map[x,y],other.map[x,y],amount);
246 }
247 }
248 return this;
249 }
250
251 public Channel blend(Channel other, Channel amount)
252 {
253 int x, y;
254 for (x = 0; x < w; x++)
255 {
256 for (y = 0; y < h; y++)
257 {
258 map[x, y] = Tools.linearInterpolate(map[x, y], other.map[x, y], amount.map[x,y]);
259 }
260 }
261 return this;
262 }
263 }
264}