diff options
author | Jeff Ames | 2008-05-04 21:59:29 +0000 |
---|---|---|
committer | Jeff Ames | 2008-05-04 21:59:29 +0000 |
commit | 0e31eb831409c7f2f9f1ba88dec13dfef4dd3ac1 (patch) | |
tree | 964fa5d80d3910c3aa51cdd62f03e2779791abe2 /OpenSim/Region/Environment/Modules/World/WorldMap | |
parent | * Reformatted EstateManagementModule (diff) | |
download | opensim-SC-0e31eb831409c7f2f9f1ba88dec13dfef4dd3ac1.zip opensim-SC-0e31eb831409c7f2f9f1ba88dec13dfef4dd3ac1.tar.gz opensim-SC-0e31eb831409c7f2f9f1ba88dec13dfef4dd3ac1.tar.bz2 opensim-SC-0e31eb831409c7f2f9f1ba88dec13dfef4dd3ac1.tar.xz |
Update svn properties.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/WorldMap')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs | 332 |
1 files changed, 166 insertions, 166 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs b/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs index 8ebe33e..68c8046 100644 --- a/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs +++ b/OpenSim/Region/Environment/Modules/World/WorldMap/MapImageModule.cs | |||
@@ -1,167 +1,167 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.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 | using System; | 28 | using System; |
29 | using System.Drawing; | 29 | using System.Drawing; |
30 | using Nini.Config; | 30 | using Nini.Config; |
31 | using OpenJPEGNet; | 31 | using OpenJPEGNet; |
32 | using OpenSim.Region.Environment.Interfaces; | 32 | using OpenSim.Region.Environment.Interfaces; |
33 | using OpenSim.Region.Environment.Scenes; | 33 | using OpenSim.Region.Environment.Scenes; |
34 | 34 | ||
35 | namespace OpenSim.Region.Environment.Modules.World.WorldMap | 35 | namespace OpenSim.Region.Environment.Modules.World.WorldMap |
36 | { | 36 | { |
37 | internal class MapImageModule : IMapImageGenerator, IRegionModule | 37 | internal class MapImageModule : IMapImageGenerator, IRegionModule |
38 | { | 38 | { |
39 | private Scene m_scene; | 39 | private Scene m_scene; |
40 | 40 | ||
41 | #region IMapImageGenerator Members | 41 | #region IMapImageGenerator Members |
42 | 42 | ||
43 | public byte[] WriteJpeg2000Image(string gradientmap) | 43 | public byte[] WriteJpeg2000Image(string gradientmap) |
44 | { | 44 | { |
45 | byte[] imageData = null; | 45 | byte[] imageData = null; |
46 | 46 | ||
47 | Bitmap bmp = TerrainToBitmap(gradientmap); | 47 | Bitmap bmp = TerrainToBitmap(gradientmap); |
48 | 48 | ||
49 | try | 49 | try |
50 | { | 50 | { |
51 | imageData = OpenJPEG.EncodeFromImage(bmp, true); | 51 | imageData = OpenJPEG.EncodeFromImage(bmp, true); |
52 | } | 52 | } |
53 | catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke | 53 | catch (Exception e) // LEGIT: Catching problems caused by OpenJPEG p/invoke |
54 | { | 54 | { |
55 | Console.WriteLine("Failed generating terrain map: " + e); | 55 | Console.WriteLine("Failed generating terrain map: " + e); |
56 | } | 56 | } |
57 | 57 | ||
58 | return imageData; | 58 | return imageData; |
59 | } | 59 | } |
60 | 60 | ||
61 | #endregion | 61 | #endregion |
62 | 62 | ||
63 | #region IRegionModule Members | 63 | #region IRegionModule Members |
64 | 64 | ||
65 | public void Initialise(Scene scene, IConfigSource source) | 65 | public void Initialise(Scene scene, IConfigSource source) |
66 | { | 66 | { |
67 | m_scene = scene; | 67 | m_scene = scene; |
68 | m_scene.RegisterModuleInterface<IMapImageGenerator>(this); | 68 | m_scene.RegisterModuleInterface<IMapImageGenerator>(this); |
69 | } | 69 | } |
70 | 70 | ||
71 | public void PostInitialise() | 71 | public void PostInitialise() |
72 | { | 72 | { |
73 | } | 73 | } |
74 | 74 | ||
75 | public void Close() | 75 | public void Close() |
76 | { | 76 | { |
77 | } | 77 | } |
78 | 78 | ||
79 | public string Name | 79 | public string Name |
80 | { | 80 | { |
81 | get { return "MapImageModule"; } | 81 | get { return "MapImageModule"; } |
82 | } | 82 | } |
83 | 83 | ||
84 | public bool IsSharedModule | 84 | public bool IsSharedModule |
85 | { | 85 | { |
86 | get { return false; } | 86 | get { return false; } |
87 | } | 87 | } |
88 | 88 | ||
89 | #endregion | 89 | #endregion |
90 | 90 | ||
91 | private void ShadeBuildings(Bitmap map) | 91 | private void ShadeBuildings(Bitmap map) |
92 | { | 92 | { |
93 | lock (map) | 93 | lock (map) |
94 | { | 94 | { |
95 | lock (m_scene.Entities) | 95 | lock (m_scene.Entities) |
96 | { | 96 | { |
97 | foreach (EntityBase entity in m_scene.Entities.Values) | 97 | foreach (EntityBase entity in m_scene.Entities.Values) |
98 | { | 98 | { |
99 | if (entity is SceneObjectGroup) | 99 | if (entity is SceneObjectGroup) |
100 | { | 100 | { |
101 | SceneObjectGroup sog = (SceneObjectGroup) entity; | 101 | SceneObjectGroup sog = (SceneObjectGroup) entity; |
102 | 102 | ||
103 | foreach (SceneObjectPart primitive in sog.Children.Values) | 103 | foreach (SceneObjectPart primitive in sog.Children.Values) |
104 | { | 104 | { |
105 | int x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2)); | 105 | int x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2)); |
106 | int y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2)); | 106 | int y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2)); |
107 | int w = (int) primitive.Scale.X; | 107 | int w = (int) primitive.Scale.X; |
108 | int h = (int) primitive.Scale.Y; | 108 | int h = (int) primitive.Scale.Y; |
109 | 109 | ||
110 | int dx; | 110 | int dx; |
111 | for (dx = x; dx < x + w; dx++) | 111 | for (dx = x; dx < x + w; dx++) |
112 | { | 112 | { |
113 | int dy; | 113 | int dy; |
114 | for (dy = y; dy < y + h; dy++) | 114 | for (dy = y; dy < y + h; dy++) |
115 | { | 115 | { |
116 | if (x < 0 || y < 0) | 116 | if (x < 0 || y < 0) |
117 | continue; | 117 | continue; |
118 | if (x >= map.Width || y >= map.Height) | 118 | if (x >= map.Width || y >= map.Height) |
119 | continue; | 119 | continue; |
120 | 120 | ||
121 | map.SetPixel(dx, dy, Color.DarkGray); | 121 | map.SetPixel(dx, dy, Color.DarkGray); |
122 | } | 122 | } |
123 | } | 123 | } |
124 | } | 124 | } |
125 | } | 125 | } |
126 | } | 126 | } |
127 | } | 127 | } |
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
131 | private Bitmap TerrainToBitmap(string gradientmap) | 131 | private Bitmap TerrainToBitmap(string gradientmap) |
132 | { | 132 | { |
133 | Bitmap gradientmapLd = new Bitmap(gradientmap); | 133 | Bitmap gradientmapLd = new Bitmap(gradientmap); |
134 | 134 | ||
135 | int pallete = gradientmapLd.Height; | 135 | int pallete = gradientmapLd.Height; |
136 | 136 | ||
137 | Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height); | 137 | Bitmap bmp = new Bitmap(m_scene.Heightmap.Width, m_scene.Heightmap.Height); |
138 | Color[] colours = new Color[pallete]; | 138 | Color[] colours = new Color[pallete]; |
139 | 139 | ||
140 | for (int i = 0; i < pallete; i++) | 140 | for (int i = 0; i < pallete; i++) |
141 | { | 141 | { |
142 | colours[i] = gradientmapLd.GetPixel(0, i); | 142 | colours[i] = gradientmapLd.GetPixel(0, i); |
143 | } | 143 | } |
144 | 144 | ||
145 | lock (m_scene.Heightmap) | 145 | lock (m_scene.Heightmap) |
146 | { | 146 | { |
147 | ITerrainChannel copy = m_scene.Heightmap; | 147 | ITerrainChannel copy = m_scene.Heightmap; |
148 | for (int y = 0; y < copy.Height; y++) | 148 | for (int y = 0; y < copy.Height; y++) |
149 | { | 149 | { |
150 | for (int x = 0; x < copy.Width; x++) | 150 | for (int x = 0; x < copy.Width; x++) |
151 | { | 151 | { |
152 | // 512 is the largest possible height before colours clamp | 152 | // 512 is the largest possible height before colours clamp |
153 | int colorindex = (int) (Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1)); | 153 | int colorindex = (int) (Math.Max(Math.Min(1.0, copy[x, y] / 512.0), 0.0) * (pallete - 1)); |
154 | 154 | ||
155 | // Handle error conditions | 155 | // Handle error conditions |
156 | if (colorindex > pallete - 1 || colorindex < 0) | 156 | if (colorindex > pallete - 1 || colorindex < 0) |
157 | bmp.SetPixel(x, copy.Height - y - 1, Color.Red); | 157 | bmp.SetPixel(x, copy.Height - y - 1, Color.Red); |
158 | else | 158 | else |
159 | bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]); | 159 | bmp.SetPixel(x, copy.Height - y - 1, colours[colorindex]); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | ShadeBuildings(bmp); | 162 | ShadeBuildings(bmp); |
163 | return bmp; | 163 | return bmp; |
164 | } | 164 | } |
165 | } | 165 | } |
166 | } | 166 | } |
167 | } \ No newline at end of file | 167 | } \ No newline at end of file |