aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.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/Generators/Voronoi.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/Generators/Voronoi.cs')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs428
1 files changed, 214 insertions, 214 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs
index eb8f7ba..3411ccf 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Generators/Voronoi.cs
@@ -1,214 +1,214 @@
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 /// <summary> 37 /// <summary>
38 /// Generates a Voronoi diagram (sort of a stained glass effect) which will fill the entire channel 38 /// Generates a Voronoi diagram (sort of a stained glass effect) which will fill the entire channel
39 /// </summary> 39 /// </summary>
40 /// <remarks>3-Clause BSD Licensed</remarks> 40 /// <remarks>3-Clause BSD Licensed</remarks>
41 /// <param name="pointsPerBlock">The number of generator points in each block</param> 41 /// <param name="pointsPerBlock">The number of generator points in each block</param>
42 /// <param name="blockSize">A multiple of the channel width and height which will have voronoi points generated in it. 42 /// <param name="blockSize">A multiple of the channel width and height which will have voronoi points generated in it.
43 /// <para>This is to ensure a more even distribution of the points than pure random allocation.</para></param> 43 /// <para>This is to ensure a more even distribution of the points than pure random allocation.</para></param>
44 /// <param name="c">The Voronoi diagram type. Usually an array with values consisting of [-1,1]. Experiment with the chain, you can have as many values as you like.</param> 44 /// <param name="c">The Voronoi diagram type. Usually an array with values consisting of [-1,1]. Experiment with the chain, you can have as many values as you like.</param>
45 public void VoronoiDiagram(int pointsPerBlock, int blockSize, double[] c) 45 public void VoronoiDiagram(int pointsPerBlock, int blockSize, double[] c)
46 { 46 {
47 SetDiff(); 47 SetDiff();
48 48
49 List<Point2D> points = new List<Point2D>(); 49 List<Point2D> points = new List<Point2D>();
50 Random generator = new Random(seed); 50 Random generator = new Random(seed);
51 51
52 // Generate the emitter points 52 // Generate the emitter points
53 int x, y, i; 53 int x, y, i;
54 for (x = -blockSize; x < w + blockSize; x += blockSize) 54 for (x = -blockSize; x < w + blockSize; x += blockSize)
55 { 55 {
56 for (y = -blockSize; y < h + blockSize; y += blockSize) 56 for (y = -blockSize; y < h + blockSize; y += blockSize)
57 { 57 {
58 for (i = 0; i < pointsPerBlock; i++) 58 for (i = 0; i < pointsPerBlock; i++)
59 { 59 {
60 double pX = x + (generator.NextDouble() * (double)blockSize); 60 double pX = x + (generator.NextDouble() * (double)blockSize);
61 double pY = y + (generator.NextDouble() * (double)blockSize); 61 double pY = y + (generator.NextDouble() * (double)blockSize);
62 62
63 points.Add(new Point2D(pX, pY)); 63 points.Add(new Point2D(pX, pY));
64 } 64 }
65 } 65 }
66 } 66 }
67 67
68 double[] distances = new double[points.Count]; 68 double[] distances = new double[points.Count];
69 69
70 // Calculate the distance each pixel is from an emitter 70 // Calculate the distance each pixel is from an emitter
71 for (x = 0; x < w; x++) 71 for (x = 0; x < w; x++)
72 { 72 {
73 for (y = 0; y < h; y++) 73 for (y = 0; y < h; y++)
74 { 74 {
75 for (i = 0; i < points.Count; i++) 75 for (i = 0; i < points.Count; i++)
76 { 76 {
77 double dx, dy; 77 double dx, dy;
78 dx = Math.Abs((double)x - points[i].x); 78 dx = Math.Abs((double)x - points[i].x);
79 dy = Math.Abs((double)y - points[i].y); 79 dy = Math.Abs((double)y - points[i].y);
80 80
81 distances[i] = (dx * dx + dy * dy); 81 distances[i] = (dx * dx + dy * dy);
82 } 82 }
83 83
84 Array.Sort(distances); 84 Array.Sort(distances);
85 85
86 double f = 0.0; 86 double f = 0.0;
87 87
88 // Multiply the distances with their 'c' counterpart 88 // Multiply the distances with their 'c' counterpart
89 // ordering the distances descending 89 // ordering the distances descending
90 for (i = 0; i < c.Length; i++) 90 for (i = 0; i < c.Length; i++)
91 { 91 {
92 if (i >= points.Count) 92 if (i >= points.Count)
93 break; 93 break;
94 94
95 f += c[i] * distances[i]; 95 f += c[i] * distances[i];
96 } 96 }
97 97
98 map[x, y] = f; 98 map[x, y] = f;
99 } 99 }
100 } 100 }
101 101
102 // Normalise the result 102 // Normalise the result
103 Normalise(); 103 Normalise();
104 } 104 }
105 105
106 public void VoronoiDiagram(List<Point2D> points, double[] c) 106 public void VoronoiDiagram(List<Point2D> points, double[] c)
107 { 107 {
108 SetDiff(); 108 SetDiff();
109 109
110 Random generator = new Random(seed); 110 Random generator = new Random(seed);
111 int x, y, i; 111 int x, y, i;
112 double[] distances = new double[points.Count]; 112 double[] distances = new double[points.Count];
113 113
114 // Calculate the distance each pixel is from an emitter 114 // Calculate the distance each pixel is from an emitter
115 for (x = 0; x < w; x++) 115 for (x = 0; x < w; x++)
116 { 116 {
117 for (y = 0; y < h; y++) 117 for (y = 0; y < h; y++)
118 { 118 {
119 for (i = 0; i < points.Count; i++) 119 for (i = 0; i < points.Count; i++)
120 { 120 {
121 double dx, dy; 121 double dx, dy;
122 dx = Math.Abs((double)x - points[i].x); 122 dx = Math.Abs((double)x - points[i].x);
123 dy = Math.Abs((double)y - points[i].y); 123 dy = Math.Abs((double)y - points[i].y);
124 124
125 distances[i] = (dx * dx + dy * dy); 125 distances[i] = (dx * dx + dy * dy);
126 } 126 }
127 127
128 Array.Sort(distances); 128 Array.Sort(distances);
129 129
130 double f = 0.0; 130 double f = 0.0;
131 131
132 // Multiply the distances with their 'c' counterpart 132 // Multiply the distances with their 'c' counterpart
133 // ordering the distances descending 133 // ordering the distances descending
134 for (i = 0; i < c.Length; i++) 134 for (i = 0; i < c.Length; i++)
135 { 135 {
136 if (i >= points.Count) 136 if (i >= points.Count)
137 break; 137 break;
138 138
139 f += c[i] * distances[i]; 139 f += c[i] * distances[i];
140 } 140 }
141 141
142 map[x, y] = f; 142 map[x, y] = f;
143 } 143 }
144 } 144 }
145 145
146 // Normalise the result 146 // Normalise the result
147 Normalise(); 147 Normalise();
148 } 148 }
149 149
150 public void VoroflatDiagram(int pointsPerBlock, int blockSize) 150 public void VoroflatDiagram(int pointsPerBlock, int blockSize)
151 { 151 {
152 SetDiff(); 152 SetDiff();
153 153
154 List<Point2D> points = new List<Point2D>(); 154 List<Point2D> points = new List<Point2D>();
155 Random generator = new Random(seed); 155 Random generator = new Random(seed);
156 156
157 // Generate the emitter points 157 // Generate the emitter points
158 int x, y, i; 158 int x, y, i;
159 for (x = -blockSize; x < w + blockSize; x += blockSize) 159 for (x = -blockSize; x < w + blockSize; x += blockSize)
160 { 160 {
161 for (y = -blockSize; y < h + blockSize; y += blockSize) 161 for (y = -blockSize; y < h + blockSize; y += blockSize)
162 { 162 {
163 for (i = 0; i < pointsPerBlock; i++) 163 for (i = 0; i < pointsPerBlock; i++)
164 { 164 {
165 double pX = x + (generator.NextDouble() * (double)blockSize); 165 double pX = x + (generator.NextDouble() * (double)blockSize);
166 double pY = y + (generator.NextDouble() * (double)blockSize); 166 double pY = y + (generator.NextDouble() * (double)blockSize);
167 167
168 points.Add(new Point2D(pX, pY)); 168 points.Add(new Point2D(pX, pY));
169 } 169 }
170 } 170 }
171 } 171 }
172 172
173 double[] distances = new double[points.Count]; 173 double[] distances = new double[points.Count];
174 174
175 // Calculate the distance each pixel is from an emitter 175 // Calculate the distance each pixel is from an emitter
176 for (x = 0; x < w; x++) 176 for (x = 0; x < w; x++)
177 { 177 {
178 for (y = 0; y < h; y++) 178 for (y = 0; y < h; y++)
179 { 179 {
180 for (i = 0; i < points.Count; i++) 180 for (i = 0; i < points.Count; i++)
181 { 181 {
182 double dx, dy; 182 double dx, dy;
183 dx = Math.Abs((double)x - points[i].x); 183 dx = Math.Abs((double)x - points[i].x);
184 dy = Math.Abs((double)y - points[i].y); 184 dy = Math.Abs((double)y - points[i].y);
185 185
186 distances[i] = (dx * dx + dy * dy); 186 distances[i] = (dx * dx + dy * dy);
187 } 187 }
188 188
189 //Array.Sort(distances); 189 //Array.Sort(distances);
190 190
191 double f = 0.0; 191 double f = 0.0;
192 192
193 double min = double.MaxValue; 193 double min = double.MaxValue;
194 for (int j = 0; j < distances.Length;j++ ) 194 for (int j = 0; j < distances.Length;j++ )
195 { 195 {
196 if (distances[j] < min) 196 if (distances[j] < min)
197 { 197 {
198 min = distances[j]; 198 min = distances[j];
199 f = j; 199 f = j;
200 } 200 }
201 } 201 }
202 202
203 // Multiply the distances with their 'c' counterpart 203 // Multiply the distances with their 'c' counterpart
204 // ordering the distances descending 204 // ordering the distances descending
205 205
206 map[x, y] = f; 206 map[x, y] = f;
207 } 207 }
208 } 208 }
209 209
210 // Normalise the result 210 // Normalise the result
211 Normalise(); 211 Normalise();
212 } 212 }
213 } 213 }
214} 214}