aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
diff options
context:
space:
mode:
authorMW2007-07-25 18:19:38 +0000
committerMW2007-07-25 18:19:38 +0000
commit2b42ea0a429c722bd7c5c67d3815c2ddc8399e78 (patch)
tree0a6338ff52efbdaadaa9a307bee618867460cfb6 /OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
parent* Terrain now uses the older slower method again until the fast version can b... (diff)
downloadopensim-SC-2b42ea0a429c722bd7c5c67d3815c2ddc8399e78.zip
opensim-SC-2b42ea0a429c722bd7c5c67d3815c2ddc8399e78.tar.gz
opensim-SC-2b42ea0a429c722bd7c5c67d3815c2ddc8399e78.tar.bz2
opensim-SC-2b42ea0a429c722bd7c5c67d3815c2ddc8399e78.tar.xz
Start of the OpenSim library , for now only contains a few textures.
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs700
1 files changed, 350 insertions, 350 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
index e6b18f4..18e40b5 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Grid.cs
@@ -1,350 +1,350 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 public Channel Normalise() 37 public Channel Normalise()
38 { 38 {
39 SetDiff(); 39 SetDiff();
40 40
41 double max = FindMax(); 41 double max = FindMax();
42 double min = FindMin(); 42 double min = FindMin();
43 43
44 int x, y; 44 int x, y;
45 45
46 if (max != min) 46 if (max != min)
47 { 47 {
48 for (x = 0; x < w; x++) 48 for (x = 0; x < w; x++)
49 { 49 {
50 for (y = 0; y < h; y++) 50 for (y = 0; y < h; y++)
51 { 51 {
52 map[x, y] = (map[x, y] - min) * (1.0 / (max - min)); 52 map[x, y] = (map[x, y] - min) * (1.0 / (max - min));
53 } 53 }
54 } 54 }
55 } 55 }
56 else 56 else
57 { 57 {
58 this.Fill(0.5); 58 this.Fill(0.5);
59 } 59 }
60 60
61 return this; 61 return this;
62 } 62 }
63 63
64 public Channel Normalise(double minv, double maxv) 64 public Channel Normalise(double minv, double maxv)
65 { 65 {
66 SetDiff(); 66 SetDiff();
67 67
68 double max = FindMax(); 68 double max = FindMax();
69 double min = FindMin(); 69 double min = FindMin();
70 70
71 int x, y; 71 int x, y;
72 72
73 for (x = 0; x < w; x++) 73 for (x = 0; x < w; x++)
74 { 74 {
75 for (y = 0; y < h; y++) 75 for (y = 0; y < h; y++)
76 { 76 {
77 double val = (map[x, y] - min) * (1.0 / max - min); 77 double val = (map[x, y] - min) * (1.0 / max - min);
78 val *= maxv - minv; 78 val *= maxv - minv;
79 val += minv; 79 val += minv;
80 80
81 map[x, y] = val; 81 map[x, y] = val;
82 } 82 }
83 } 83 }
84 84
85 return this; 85 return this;
86 } 86 }
87 87
88 public Channel Clip() 88 public Channel Clip()
89 { 89 {
90 int x, y; 90 int x, y;
91 91
92 for (x = 0; x < w; x++) 92 for (x = 0; x < w; x++)
93 { 93 {
94 for (y = 0; y < h; y++) 94 for (y = 0; y < h; y++)
95 { 95 {
96 SetClip(x, y, map[x, y]); 96 SetClip(x, y, map[x, y]);
97 } 97 }
98 } 98 }
99 99
100 return this; 100 return this;
101 } 101 }
102 102
103 public Channel Clip(double min, double max) 103 public Channel Clip(double min, double max)
104 { 104 {
105 int x, y; 105 int x, y;
106 for (x = 0; x < w; x++) 106 for (x = 0; x < w; x++)
107 { 107 {
108 for (y = 0; y < h; y++) 108 for (y = 0; y < h; y++)
109 { 109 {
110 double val = map[x, y]; 110 double val = map[x, y];
111 if (val > max) val = max; 111 if (val > max) val = max;
112 if (val < min) val = min; 112 if (val < min) val = min;
113 113
114 Set(x, y, val); 114 Set(x, y, val);
115 } 115 }
116 } 116 }
117 return this; 117 return this;
118 } 118 }
119 119
120 public Channel Crop(int x1, int y1, int x2, int y2) 120 public Channel Crop(int x1, int y1, int x2, int y2)
121 { 121 {
122 int width = x1 - x2 + 1; 122 int width = x1 - x2 + 1;
123 int height = y1 - y2 + 1; 123 int height = y1 - y2 + 1;
124 Channel chan = new Channel(width, height); 124 Channel chan = new Channel(width, height);
125 125
126 int x, y; 126 int x, y;
127 int nx, ny; 127 int nx, ny;
128 128
129 nx = 0; 129 nx = 0;
130 for (x = x1; x < x2; x++) 130 for (x = x1; x < x2; x++)
131 { 131 {
132 ny = 0; 132 ny = 0;
133 for (y = y1; y < y2; y++) 133 for (y = y1; y < y2; y++)
134 { 134 {
135 chan.map[nx, ny] = map[x, y]; 135 chan.map[nx, ny] = map[x, y];
136 136
137 ny++; 137 ny++;
138 } 138 }
139 nx++; 139 nx++;
140 } 140 }
141 141
142 return this; 142 return this;
143 } 143 }
144 144
145 public Channel AddClip(Channel other) 145 public Channel AddClip(Channel other)
146 { 146 {
147 SetDiff(); 147 SetDiff();
148 148
149 int x, y; 149 int x, y;
150 for (x = 0; x < w; x++) 150 for (x = 0; x < w; x++)
151 { 151 {
152 for (y = 0; y < h; y++) 152 for (y = 0; y < h; y++)
153 { 153 {
154 map[x, y] = other.map[x, y]; 154 map[x, y] = other.map[x, y];
155 if (map[x, y] > 1) 155 if (map[x, y] > 1)
156 map[x, y] = 1; 156 map[x, y] = 1;
157 if (map[x, y] < 0) 157 if (map[x, y] < 0)
158 map[x, y] = 0; 158 map[x, y] = 0;
159 } 159 }
160 } 160 }
161 return this; 161 return this;
162 } 162 }
163 163
164 public void Smooth(double amount) 164 public void Smooth(double amount)
165 { 165 {
166 SetDiff(); 166 SetDiff();
167 167
168 double area = amount; 168 double area = amount;
169 double step = amount / 4.0; 169 double step = amount / 4.0;
170 170
171 double[,] manipulate = new double[w, h]; 171 double[,] manipulate = new double[w, h];
172 int x, y; 172 int x, y;
173 double n, l; 173 double n, l;
174 for (x = 0; x < w; x++) 174 for (x = 0; x < w; x++)
175 { 175 {
176 for (y = 0; y < h; y++) 176 for (y = 0; y < h; y++)
177 { 177 {
178 double average = 0.0; 178 double average = 0.0;
179 int avgsteps = 0; 179 int avgsteps = 0;
180 180
181 for (n = 0.0 - area; n < area; n += step) 181 for (n = 0.0 - area; n < area; n += step)
182 { 182 {
183 for (l = 0.0 - area; l < area; l += step) 183 for (l = 0.0 - area; l < area; l += step)
184 { 184 {
185 avgsteps++; 185 avgsteps++;
186 average += GetBilinearInterpolate(x + n, y + l); 186 average += GetBilinearInterpolate(x + n, y + l);
187 } 187 }
188 } 188 }
189 189
190 manipulate[x, y] = average / avgsteps; 190 manipulate[x, y] = average / avgsteps;
191 } 191 }
192 } 192 }
193 map = manipulate; 193 map = manipulate;
194 } 194 }
195 195
196 public void Pertubation(double amount) 196 public void Pertubation(double amount)
197 { 197 {
198 SetDiff(); 198 SetDiff();
199 199
200 // Simple pertubation filter 200 // Simple pertubation filter
201 double[,] manipulated = new double[w, h]; 201 double[,] manipulated = new double[w, h];
202 Random generator = new Random(seed); // Seeds FTW! 202 Random generator = new Random(seed); // Seeds FTW!
203 //double amount = 8.0; 203 //double amount = 8.0;
204 204
205 int x, y; 205 int x, y;
206 for (x = 0; x < w; x++) 206 for (x = 0; x < w; x++)
207 { 207 {
208 for (y = 0; y < h; y++) 208 for (y = 0; y < h; y++)
209 { 209 {
210 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0); 210 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0);
211 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0); 211 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0);
212 double p = GetBilinearInterpolate(offset_x, offset_y); 212 double p = GetBilinearInterpolate(offset_x, offset_y);
213 manipulated[x, y] = p; 213 manipulated[x, y] = p;
214 } 214 }
215 } 215 }
216 map = manipulated; 216 map = manipulated;
217 } 217 }
218 218
219 public void PertubationMask(Channel mask) 219 public void PertubationMask(Channel mask)
220 { 220 {
221 // Simple pertubation filter 221 // Simple pertubation filter
222 double[,] manipulated = new double[w, h]; 222 double[,] manipulated = new double[w, h];
223 Random generator = new Random(seed); // Seeds FTW! 223 Random generator = new Random(seed); // Seeds FTW!
224 //double amount = 8.0; 224 //double amount = 8.0;
225 225
226 double amount; 226 double amount;
227 227
228 int x, y; 228 int x, y;
229 for (x = 0; x < w; x++) 229 for (x = 0; x < w; x++)
230 { 230 {
231 for (y = 0; y < h; y++) 231 for (y = 0; y < h; y++)
232 { 232 {
233 amount = mask.map[x, y]; 233 amount = mask.map[x, y];
234 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0); 234 double offset_x = (double)x + (generator.NextDouble() * amount) - (amount / 2.0);
235 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0); 235 double offset_y = (double)y + (generator.NextDouble() * amount) - (amount / 2.0);
236 236
237 if (offset_x > w) 237 if (offset_x > w)
238 offset_x = w - 1; 238 offset_x = w - 1;
239 if (offset_y > h) 239 if (offset_y > h)
240 offset_y = h - 1; 240 offset_y = h - 1;
241 if (offset_y < 0) 241 if (offset_y < 0)
242 offset_y = 0; 242 offset_y = 0;
243 if (offset_x < 0) 243 if (offset_x < 0)
244 offset_x = 0; 244 offset_x = 0;
245 245
246 double p = GetBilinearInterpolate(offset_x, offset_y); 246 double p = GetBilinearInterpolate(offset_x, offset_y);
247 manipulated[x, y] = p; 247 manipulated[x, y] = p;
248 SetDiff(x, y); 248 SetDiff(x, y);
249 } 249 }
250 } 250 }
251 map = manipulated; 251 map = manipulated;
252 } 252 }
253 253
254 public void Distort(Channel mask, double str) 254 public void Distort(Channel mask, double str)
255 { 255 {
256 // Simple pertubation filter 256 // Simple pertubation filter
257 double[,] manipulated = new double[w, h]; 257 double[,] manipulated = new double[w, h];
258 258
259 double amount; 259 double amount;
260 260
261 int x, y; 261 int x, y;
262 for (x = 0; x < w; x++) 262 for (x = 0; x < w; x++)
263 { 263 {
264 for (y = 0; y < h; y++) 264 for (y = 0; y < h; y++)
265 { 265 {
266 amount = mask.map[x, y]; 266 amount = mask.map[x, y];
267 double offset_x = (double)x + (amount * str) - (0.5 * str); 267 double offset_x = (double)x + (amount * str) - (0.5 * str);
268 double offset_y = (double)y + (amount * str) - (0.5 * str); 268 double offset_y = (double)y + (amount * str) - (0.5 * str);
269 269
270 if (offset_x > w) 270 if (offset_x > w)
271 offset_x = w - 1; 271 offset_x = w - 1;
272 if (offset_y > h) 272 if (offset_y > h)
273 offset_y = h - 1; 273 offset_y = h - 1;
274 if (offset_y < 0) 274 if (offset_y < 0)
275 offset_y = 0; 275 offset_y = 0;
276 if (offset_x < 0) 276 if (offset_x < 0)
277 offset_x = 0; 277 offset_x = 0;
278 278
279 double p = GetBilinearInterpolate(offset_x, offset_y); 279 double p = GetBilinearInterpolate(offset_x, offset_y);
280 manipulated[x, y] = p; 280 manipulated[x, y] = p;
281 SetDiff(x, y); 281 SetDiff(x, y);
282 } 282 }
283 } 283 }
284 map = manipulated; 284 map = manipulated;
285 285
286 } 286 }
287 287
288 public void Distort(Channel mask, Channel mask2, double str) 288 public void Distort(Channel mask, Channel mask2, double str)
289 { 289 {
290 // Simple pertubation filter 290 // Simple pertubation filter
291 double[,] manipulated = new double[w, h]; 291 double[,] manipulated = new double[w, h];
292 292
293 double amountX; 293 double amountX;
294 double amountY; 294 double amountY;
295 295
296 int x, y; 296 int x, y;
297 for (x = 0; x < w; x++) 297 for (x = 0; x < w; x++)
298 { 298 {
299 for (y = 0; y < h; y++) 299 for (y = 0; y < h; y++)
300 { 300 {
301 amountX = mask.map[x, y]; 301 amountX = mask.map[x, y];
302 amountY = mask2.map[x, y]; 302 amountY = mask2.map[x, y];
303 double offset_x = (double)x + (amountX * str) - (0.5 * str); 303 double offset_x = (double)x + (amountX * str) - (0.5 * str);
304 double offset_y = (double)y + (amountY * str) - (0.5 * str); 304 double offset_y = (double)y + (amountY * str) - (0.5 * str);
305 305
306 if (offset_x > w) 306 if (offset_x > w)
307 offset_x = w - 1; 307 offset_x = w - 1;
308 if (offset_y > h) 308 if (offset_y > h)
309 offset_y = h - 1; 309 offset_y = h - 1;
310 if (offset_y < 0) 310 if (offset_y < 0)
311 offset_y = 0; 311 offset_y = 0;
312 if (offset_x < 0) 312 if (offset_x < 0)
313 offset_x = 0; 313 offset_x = 0;
314 314
315 double p = GetBilinearInterpolate(offset_x, offset_y); 315 double p = GetBilinearInterpolate(offset_x, offset_y);
316 manipulated[x, y] = p; 316 manipulated[x, y] = p;
317 SetDiff(x, y); 317 SetDiff(x, y);
318 } 318 }
319 } 319 }
320 map = manipulated; 320 map = manipulated;
321 321
322 } 322 }
323 323
324 public Channel Blend(Channel other, double amount) 324 public Channel Blend(Channel other, double amount)
325 { 325 {
326 int x, y; 326 int x, y;
327 for (x = 0; x < w; x++) 327 for (x = 0; x < w; x++)
328 { 328 {
329 for (y = 0; y < h; y++) 329 for (y = 0; y < h; y++)
330 { 330 {
331 Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount)); 331 Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount));
332 } 332 }
333 } 333 }
334 return this; 334 return this;
335 } 335 }
336 336
337 public Channel Blend(Channel other, Channel amount) 337 public Channel Blend(Channel other, Channel amount)
338 { 338 {
339 int x, y; 339 int x, y;
340 for (x = 0; x < w; x++) 340 for (x = 0; x < w; x++)
341 { 341 {
342 for (y = 0; y < h; y++) 342 for (y = 0; y < h; y++)
343 { 343 {
344 Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount.map[x, y])); 344 Set(x, y, Tools.linearInterpolate(map[x, y], other.map[x, y], amount.map[x, y]));
345 } 345 }
346 } 346 }
347 return this; 347 return this;
348 } 348 }
349 } 349 }
350} 350}