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