Revision 472
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/RasterTiledImageLayer.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2015 gvSIG Association |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.view3d.swing.impl.data; |
|
26 |
|
|
27 |
import gov.nasa.worldwind.avlist.AVKey; |
|
28 |
import gov.nasa.worldwind.avlist.AVList; |
|
29 |
import gov.nasa.worldwind.data.RasterServer; |
|
30 |
import gov.nasa.worldwind.geom.Angle; |
|
31 |
import gov.nasa.worldwind.geom.Extent; |
|
32 |
import gov.nasa.worldwind.geom.Sector; |
|
33 |
import gov.nasa.worldwind.layers.BasicTiledImageLayer; |
|
34 |
import gov.nasa.worldwind.layers.TextureTile; |
|
35 |
import gov.nasa.worldwind.render.DrawContext; |
|
36 |
import gov.nasa.worldwind.retrieve.RetrievalPostProcessor; |
|
37 |
import gov.nasa.worldwind.retrieve.Retriever; |
|
38 |
import gov.nasa.worldwind.retrieve.RetrieverFactory; |
|
39 |
import gov.nasa.worldwind.util.Logging; |
|
40 |
import gov.nasa.worldwind.util.WWUtil; |
|
41 |
|
|
42 |
import org.slf4j.Logger; |
|
43 |
import org.slf4j.LoggerFactory; |
|
44 |
import org.w3c.dom.Element; |
|
45 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
46 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
47 |
import org.gvsig.view3d.swing.impl.DefaultMapControl3D; |
|
48 |
|
|
49 |
/** |
|
50 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
51 |
* |
|
52 |
*/ |
|
53 |
public class RasterTiledImageLayer extends BasicTiledImageLayer { |
|
54 |
|
|
55 |
private static final Logger LOG = LoggerFactory |
|
56 |
.getLogger(RasterTiledImageLayer.class); |
|
57 |
|
|
58 |
/** |
|
59 |
* @param params |
|
60 |
*/ |
|
61 |
public RasterTiledImageLayer(AVList params) { |
|
62 |
|
|
63 |
super(params); |
|
64 |
|
|
65 |
this.createRasterServer(params); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* @param domElement |
|
70 |
* @param params |
|
71 |
*/ |
|
72 |
public RasterTiledImageLayer(Element domElement, AVList params) { |
|
73 |
super(domElement, params); |
|
74 |
|
|
75 |
this.createRasterServer(params != null ? params : (AVList) this |
|
76 |
.getValue(AVKey.CONSTRUCTION_PARAMETERS)); |
|
77 |
} |
|
78 |
|
|
79 |
private void createRasterServer(AVList params) { |
|
80 |
|
|
81 |
if (params == null) { |
|
82 |
LOG.error("Can not create raster server, parameters is null"); |
|
83 |
throw new IllegalArgumentException(); |
|
84 |
} |
|
85 |
|
|
86 |
if (this.getDataFileStore() == null) { |
|
87 |
LOG.error("Can not create raster server, file store is null"); |
|
88 |
throw new IllegalArgumentException(); |
|
89 |
} |
|
90 |
|
|
91 |
String datasetName = params.getStringValue(AVKey.DATASET_NAME); |
|
92 |
if (WWUtil.isEmpty(datasetName)) { |
|
93 |
LOG.error( |
|
94 |
"Can not create raster server, missing required parameter: {}", |
|
95 |
AVKey.DATASET_NAME); |
|
96 |
throw new IllegalArgumentException(); |
|
97 |
} |
|
98 |
|
|
99 |
String dataCacheName = params.getStringValue(AVKey.DATA_CACHE_NAME); |
|
100 |
if (WWUtil.isEmpty(dataCacheName)) { |
|
101 |
LOG.error( |
|
102 |
"Can not create raster server, missing required parameter: {}", |
|
103 |
AVKey.DATA_CACHE_NAME); |
|
104 |
throw new IllegalArgumentException(); |
|
105 |
} |
|
106 |
|
|
107 |
MapContext mapContext = |
|
108 |
(MapContext) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTEXT); |
|
109 |
|
|
110 |
if (mapContext == null) { |
|
111 |
LOG.error( |
|
112 |
"Can not create raster server, missing required parameter: {}", |
|
113 |
DefaultMapControl3D.GVSIG_MAPCONTEXT); |
|
114 |
throw new IllegalArgumentException(); |
|
115 |
} |
|
116 |
|
|
117 |
FLayer layer = (FLayer) params.getValue(DefaultMapControl3D.GVSIG_LAYER); |
|
118 |
|
|
119 |
if (layer == null) { |
|
120 |
LOG.error( |
|
121 |
"Can not create raster server, missing required parameter: {}", |
|
122 |
"GVSIG_LAYER"); |
|
123 |
throw new IllegalArgumentException(); |
|
124 |
} |
|
125 |
|
|
126 |
final AVList rasterServerParams = params.copy(); |
|
127 |
|
|
128 |
rasterServerParams.setValue(AVKey.FILE_STORE, this.getDataFileStore()); |
|
129 |
|
|
130 |
RetrieverFactory retrieverFactory = new RetrieverFactory() { |
|
131 |
|
|
132 |
final protected RasterServer rasterServer = |
|
133 |
new DefaultRasterServer(rasterServerParams); |
|
134 |
|
|
135 |
public Retriever createRetriever(AVList tileParams, |
|
136 |
RetrievalPostProcessor postProcessor) { |
|
137 |
|
|
138 |
DefaultRasterServerRetriever retriever = |
|
139 |
new DefaultRasterServerRetriever(tileParams, |
|
140 |
this.rasterServer, postProcessor); |
|
141 |
|
|
142 |
// copy only values that do not exist in destination AVList |
|
143 |
// from rasterServerParams (source) to retriever (destination) |
|
144 |
|
|
145 |
String[] keysToCopy = |
|
146 |
new String[] { AVKey.DATASET_NAME, AVKey.DISPLAY_NAME, |
|
147 |
AVKey.FILE_STORE, AVKey.IMAGE_FORMAT, |
|
148 |
AVKey.FORMAT_SUFFIX }; |
|
149 |
|
|
150 |
WWUtil.copyValues(rasterServerParams, retriever, keysToCopy, |
|
151 |
false); |
|
152 |
|
|
153 |
return retriever; |
|
154 |
} |
|
155 |
}; |
|
156 |
|
|
157 |
params.setValue(AVKey.RETRIEVER_FACTORY_LOCAL, retrieverFactory); |
|
158 |
this.setValue(AVKey.RETRIEVER_FACTORY_LOCAL, retrieverFactory); |
|
159 |
|
|
160 |
} |
|
161 |
|
|
162 |
protected boolean isTileVisible(DrawContext dc, TextureTile tile) { |
|
163 |
|
|
164 |
if(tile.getSector().isWithinLatLonLimits()){ |
|
165 |
return tile.getExtent(dc).intersects( |
|
166 |
dc.getView().getFrustumInModelCoordinates()) |
|
167 |
&& (dc.getVisibleSector() == null || dc.getVisibleSector() |
|
168 |
.intersects(tile.getSector())); |
|
169 |
} else { |
|
170 |
|
|
171 |
// Try to fix extend. This is necessary to avoid problems getting if |
|
172 |
// some tile is visible or not when the tile has corrupt sector like |
|
173 |
// 180.0000001 or -90.000000004561 |
|
174 |
Extent extend = this.fixExtend(tile, dc); |
|
175 |
return extend.intersects(dc.getView() |
|
176 |
.getFrustumInModelCoordinates()) |
|
177 |
&& (dc.getVisibleSector() == null || dc.getVisibleSector() |
|
178 |
.intersects(tile.getSector())); |
|
179 |
} |
|
180 |
} |
|
181 |
|
|
182 |
private Extent fixExtend(TextureTile tile, DrawContext dc) { |
|
183 |
|
|
184 |
if (dc == null) { |
|
185 |
String msg = Logging.getMessage("nullValue.DrawContextIsNull"); |
|
186 |
Logging.logger().severe(msg); |
|
187 |
throw new IllegalArgumentException(msg); |
|
188 |
} |
|
189 |
|
|
190 |
if ( tile.getSector().isWithinLatLonLimits()){ |
|
191 |
return Sector.computeBoundingBox(dc.getGlobe(), |
|
192 |
dc.getVerticalExaggeration(), tile.getSector()); |
|
193 |
} else { |
|
194 |
|
|
195 |
double[] degreesArray = tile.getSector().asDegreesArray(); |
|
196 |
|
|
197 |
double minLatitude = |
|
198 |
degreesArray[0] < Angle.NEG90.degrees ? Angle.NEG90.degrees |
|
199 |
: degreesArray[0]; |
|
200 |
double maxLatitude = |
|
201 |
degreesArray[1] > Angle.POS90.degrees ? Angle.POS90.degrees |
|
202 |
: degreesArray[1]; |
|
203 |
double minLongitude = |
|
204 |
degreesArray[2] < Angle.NEG180.degrees ? Angle.NEG180.degrees |
|
205 |
: degreesArray[2]; |
|
206 |
double maxLongitude = |
|
207 |
degreesArray[3] > Angle.POS180.degrees ? Angle.POS180.degrees |
|
208 |
: degreesArray[3]; |
|
209 |
|
|
210 |
Sector adjustedSector = |
|
211 |
new Sector(Angle.fromDegrees(minLatitude), |
|
212 |
Angle.fromDegrees(maxLatitude), |
|
213 |
Angle.fromDegrees(minLongitude), |
|
214 |
Angle.fromDegrees(maxLongitude)); |
|
215 |
|
|
216 |
return Sector.computeBoundingBox(dc.getGlobe(), |
|
217 |
dc.getVerticalExaggeration(), adjustedSector); |
|
218 |
} |
|
219 |
} |
|
220 |
} |
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/LayerConverter.java | ||
---|---|---|
28 | 28 |
import gov.nasa.worldwind.layers.Layer; |
29 | 29 |
|
30 | 30 |
import org.gvsig.fmap.dal.exception.DataException; |
31 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
32 | 31 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
32 |
import org.gvsig.view3d.swing.api.MapControl3D; |
|
33 | 33 |
|
34 | 34 |
|
35 | 35 |
/** |
... | ... | |
40 | 40 |
|
41 | 41 |
/** |
42 | 42 |
* |
43 |
* @param mapContext
|
|
43 |
* @param mapControl
|
|
44 | 44 |
* @param layer |
45 | 45 |
* @return |
46 |
* @throws DataException
|
|
46 |
* @throws DataException |
|
47 | 47 |
*/ |
48 |
public Layer convertToLayer(MapContext mapContext, FLayer layer) throws DataException;
|
|
48 |
public Layer convertToLayer(MapControl3D mapControl, FLayer layer) throws DataException;
|
|
49 | 49 |
|
50 | 50 |
/** |
51 | 51 |
* |
52 |
* @param mapContext
|
|
52 |
* @param mapControl
|
|
53 | 53 |
* @param layer |
54 | 54 |
* @return |
55 | 55 |
*/ |
56 |
public ElevationModel convertToElevationModel(MapContext mapContext, FLayer layer);
|
|
56 |
public ElevationModel convertToElevationModel(MapControl3D mapControl, FLayer layer);
|
|
57 | 57 |
} |
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/DefaultTiledImageLayer.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2015 gvSIG Association |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.view3d.swing.impl.data; |
|
26 |
|
|
27 |
import gov.nasa.worldwind.avlist.AVKey; |
|
28 |
import gov.nasa.worldwind.avlist.AVList; |
|
29 |
import gov.nasa.worldwind.data.RasterServer; |
|
30 |
import gov.nasa.worldwind.geom.Angle; |
|
31 |
import gov.nasa.worldwind.geom.Extent; |
|
32 |
import gov.nasa.worldwind.geom.Sector; |
|
33 |
import gov.nasa.worldwind.layers.BasicTiledImageLayer; |
|
34 |
import gov.nasa.worldwind.layers.TextureTile; |
|
35 |
import gov.nasa.worldwind.render.DrawContext; |
|
36 |
import gov.nasa.worldwind.retrieve.RetrievalPostProcessor; |
|
37 |
import gov.nasa.worldwind.retrieve.Retriever; |
|
38 |
import gov.nasa.worldwind.retrieve.RetrieverFactory; |
|
39 |
import gov.nasa.worldwind.util.Logging; |
|
40 |
import gov.nasa.worldwind.util.WWUtil; |
|
41 |
|
|
42 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
43 |
import org.gvsig.view3d.swing.api.MapControl3D; |
|
44 |
import org.gvsig.view3d.swing.impl.DefaultMapControl3D; |
|
45 |
import org.slf4j.Logger; |
|
46 |
import org.slf4j.LoggerFactory; |
|
47 |
import org.w3c.dom.Element; |
|
48 |
|
|
49 |
/** |
|
50 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
|
51 |
* |
|
52 |
*/ |
|
53 |
public class DefaultTiledImageLayer extends BasicTiledImageLayer { |
|
54 |
|
|
55 |
private static final Logger LOG = LoggerFactory |
|
56 |
.getLogger(DefaultTiledImageLayer.class); |
|
57 |
|
|
58 |
/** |
|
59 |
* @param params |
|
60 |
*/ |
|
61 |
public DefaultTiledImageLayer(AVList params) { |
|
62 |
|
|
63 |
super(params); |
|
64 |
|
|
65 |
this.createRasterServer(params); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* @param domElement |
|
70 |
* @param params |
|
71 |
*/ |
|
72 |
public DefaultTiledImageLayer(Element domElement, AVList params) { |
|
73 |
super(domElement, params); |
|
74 |
|
|
75 |
this.createRasterServer(params != null ? params : (AVList) this |
|
76 |
.getValue(AVKey.CONSTRUCTION_PARAMETERS)); |
|
77 |
} |
|
78 |
|
|
79 |
private void createRasterServer(AVList params) { |
|
80 |
|
|
81 |
if (params == null) { |
|
82 |
LOG.error("Can not create raster server, parameters is null"); |
|
83 |
throw new IllegalArgumentException(); |
|
84 |
} |
|
85 |
|
|
86 |
if (this.getDataFileStore() == null) { |
|
87 |
LOG.error("Can not create raster server, file store is null"); |
|
88 |
throw new IllegalArgumentException(); |
|
89 |
} |
|
90 |
|
|
91 |
String datasetName = params.getStringValue(AVKey.DATASET_NAME); |
|
92 |
if (WWUtil.isEmpty(datasetName)) { |
|
93 |
LOG.error( |
|
94 |
"Can not create raster server, missing required parameter: {}", |
|
95 |
AVKey.DATASET_NAME); |
|
96 |
throw new IllegalArgumentException(); |
|
97 |
} |
|
98 |
|
|
99 |
String dataCacheName = params.getStringValue(AVKey.DATA_CACHE_NAME); |
|
100 |
if (WWUtil.isEmpty(dataCacheName)) { |
|
101 |
LOG.error( |
|
102 |
"Can not create raster server, missing required parameter: {}", |
|
103 |
AVKey.DATA_CACHE_NAME); |
|
104 |
throw new IllegalArgumentException(); |
|
105 |
} |
|
106 |
|
|
107 |
MapControl3D mapControl3D = |
|
108 |
(MapControl3D) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTROL3D); |
|
109 |
|
|
110 |
if (mapControl3D == null) { |
|
111 |
LOG.error( |
|
112 |
"Can not create raster server, missing required parameter: {}", |
|
113 |
DefaultMapControl3D.GVSIG_MAPCONTROL3D); |
|
114 |
throw new IllegalArgumentException(); |
|
115 |
} |
|
116 |
|
|
117 |
FLayer layer = (FLayer) params.getValue(DefaultMapControl3D.GVSIG_LAYER); |
|
118 |
|
|
119 |
if (layer == null) { |
|
120 |
LOG.error( |
|
121 |
"Can not create raster server, missing required parameter: {}", |
|
122 |
"GVSIG_LAYER"); |
|
123 |
throw new IllegalArgumentException(); |
|
124 |
} |
|
125 |
|
|
126 |
final AVList rasterServerParams = params.copy(); |
|
127 |
|
|
128 |
rasterServerParams.setValue(AVKey.FILE_STORE, this.getDataFileStore()); |
|
129 |
|
|
130 |
RetrieverFactory retrieverFactory = new RetrieverFactory() { |
|
131 |
|
|
132 |
final protected RasterServer rasterServer = |
|
133 |
new DefaultRasterServer(rasterServerParams); |
|
134 |
|
|
135 |
public Retriever createRetriever(AVList tileParams, |
|
136 |
RetrievalPostProcessor postProcessor) { |
|
137 |
|
|
138 |
DefaultRasterServerRetriever retriever = |
|
139 |
new DefaultRasterServerRetriever(tileParams, |
|
140 |
this.rasterServer, postProcessor); |
|
141 |
|
|
142 |
// copy only values that do not exist in destination AVList |
|
143 |
// from rasterServerParams (source) to retriever (destination) |
|
144 |
|
|
145 |
String[] keysToCopy = |
|
146 |
new String[] { AVKey.DATASET_NAME, AVKey.DISPLAY_NAME, |
|
147 |
AVKey.FILE_STORE, AVKey.IMAGE_FORMAT, |
|
148 |
AVKey.FORMAT_SUFFIX }; |
|
149 |
|
|
150 |
WWUtil.copyValues(rasterServerParams, retriever, keysToCopy, |
|
151 |
false); |
|
152 |
|
|
153 |
return retriever; |
|
154 |
} |
|
155 |
}; |
|
156 |
|
|
157 |
params.setValue(AVKey.RETRIEVER_FACTORY_LOCAL, retrieverFactory); |
|
158 |
this.setValue(AVKey.RETRIEVER_FACTORY_LOCAL, retrieverFactory); |
|
159 |
|
|
160 |
} |
|
161 |
|
|
162 |
protected boolean isTileVisible(DrawContext dc, TextureTile tile) { |
|
163 |
|
|
164 |
if(tile.getSector().isWithinLatLonLimits()){ |
|
165 |
return tile.getExtent(dc).intersects( |
|
166 |
dc.getView().getFrustumInModelCoordinates()) |
|
167 |
&& (dc.getVisibleSector() == null || dc.getVisibleSector() |
|
168 |
.intersects(tile.getSector())); |
|
169 |
} else { |
|
170 |
|
|
171 |
// Try to fix extend. This is necessary to avoid problems getting if |
|
172 |
// some tile is visible or not when the tile has corrupt sector like |
|
173 |
// 180.0000001 or -90.000000004561 |
|
174 |
Extent extend = this.fixExtend(tile, dc); |
|
175 |
return extend.intersects(dc.getView() |
|
176 |
.getFrustumInModelCoordinates()) |
|
177 |
&& (dc.getVisibleSector() == null || dc.getVisibleSector() |
|
178 |
.intersects(tile.getSector())); |
|
179 |
} |
|
180 |
} |
|
181 |
|
|
182 |
private Extent fixExtend(TextureTile tile, DrawContext dc) { |
|
183 |
|
|
184 |
if (dc == null) { |
|
185 |
String msg = Logging.getMessage("nullValue.DrawContextIsNull"); |
|
186 |
Logging.logger().severe(msg); |
|
187 |
throw new IllegalArgumentException(msg); |
|
188 |
} |
|
189 |
|
|
190 |
if ( tile.getSector().isWithinLatLonLimits()){ |
|
191 |
return Sector.computeBoundingBox(dc.getGlobe(), |
|
192 |
dc.getVerticalExaggeration(), tile.getSector()); |
|
193 |
} else { |
|
194 |
|
|
195 |
double[] degreesArray = tile.getSector().asDegreesArray(); |
|
196 |
|
|
197 |
double minLatitude = |
|
198 |
degreesArray[0] < Angle.NEG90.degrees ? Angle.NEG90.degrees |
|
199 |
: degreesArray[0]; |
|
200 |
double maxLatitude = |
|
201 |
degreesArray[1] > Angle.POS90.degrees ? Angle.POS90.degrees |
|
202 |
: degreesArray[1]; |
|
203 |
double minLongitude = |
|
204 |
degreesArray[2] < Angle.NEG180.degrees ? Angle.NEG180.degrees |
|
205 |
: degreesArray[2]; |
|
206 |
double maxLongitude = |
|
207 |
degreesArray[3] > Angle.POS180.degrees ? Angle.POS180.degrees |
|
208 |
: degreesArray[3]; |
|
209 |
|
|
210 |
Sector adjustedSector = |
|
211 |
new Sector(Angle.fromDegrees(minLatitude), |
|
212 |
Angle.fromDegrees(maxLatitude), |
|
213 |
Angle.fromDegrees(minLongitude), |
|
214 |
Angle.fromDegrees(maxLongitude)); |
|
215 |
|
|
216 |
return Sector.computeBoundingBox(dc.getGlobe(), |
|
217 |
dc.getVerticalExaggeration(), adjustedSector); |
|
218 |
} |
|
219 |
} |
|
220 |
} |
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/GvSIGLayerDataRaster.java | ||
---|---|---|
28 | 28 |
import gov.nasa.worldwind.avlist.AVKey; |
29 | 29 |
import gov.nasa.worldwind.avlist.AVList; |
30 | 30 |
import gov.nasa.worldwind.data.BufferedImageRaster; |
31 |
import gov.nasa.worldwind.data.ByteBufferRaster; |
|
31 | 32 |
import gov.nasa.worldwind.data.DataRaster; |
32 | 33 |
import gov.nasa.worldwind.geom.Sector; |
34 |
import gov.nasa.worldwind.util.BufferWrapper; |
|
33 | 35 |
|
34 | 36 |
import java.awt.Dimension; |
35 | 37 |
import java.awt.Graphics2D; |
... | ... | |
37 | 39 |
import java.awt.geom.AffineTransform; |
38 | 40 |
import java.awt.geom.Point2D; |
39 | 41 |
import java.awt.image.BufferedImage; |
42 |
import java.awt.image.DataBufferByte; |
|
43 |
import java.awt.image.WritableRaster; |
|
44 |
import java.nio.ByteBuffer; |
|
40 | 45 |
|
41 | 46 |
import org.cresques.cts.ICoordTrans; |
42 | 47 |
import org.cresques.cts.IProjection; |
43 |
import org.slf4j.Logger; |
|
44 |
import org.slf4j.LoggerFactory; |
|
45 | 48 |
import org.gvsig.fmap.crs.CRSFactory; |
46 | 49 |
import org.gvsig.fmap.dal.exception.ReadException; |
47 | 50 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
... | ... | |
54 | 57 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
55 | 58 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
56 | 59 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelable; |
57 |
import org.gvsig.tools.task.Cancellable; |
|
60 |
import org.gvsig.view3d.swing.api.MapControl3D; |
|
61 |
import org.slf4j.Logger; |
|
62 |
import org.slf4j.LoggerFactory; |
|
58 | 63 |
|
59 | 64 |
/** |
60 | 65 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
... | ... | |
65 | 70 |
|
66 | 71 |
private static final Logger LOG = LoggerFactory |
67 | 72 |
.getLogger(GvSIGLayerDataRaster.class); |
68 |
|
|
69 |
private MapContext mapContext;
|
|
73 |
|
|
74 |
private MapControl3D mapControl3D;
|
|
70 | 75 |
private FLayer layer; |
71 | 76 |
|
72 | 77 |
/** |
73 | 78 |
* |
74 | 79 |
*/ |
75 |
public GvSIGLayerDataRaster(MapContext mapContext, FLayer theLayer,
|
|
80 |
public GvSIGLayerDataRaster(MapControl3D mapControl3D, FLayer theLayer,
|
|
76 | 81 |
AVList params) { |
77 | 82 |
|
78 |
if (params == null || mapContext == null || theLayer == null) {
|
|
83 |
if (params == null || mapControl3D == null || theLayer == null) {
|
|
79 | 84 |
throw new IllegalArgumentException(); |
80 | 85 |
} |
81 | 86 |
|
82 | 87 |
this.layer = theLayer; |
83 |
this.mapContext = mapContext;
|
|
88 |
this.mapControl3D = mapControl3D;
|
|
84 | 89 |
this.setValues(params.copy()); |
85 | 90 |
} |
86 | 91 |
|
87 | 92 |
public void dispose() { |
88 |
//TODO |
|
89 | 93 |
} |
90 | 94 |
|
91 | 95 |
public int getWidth() { |
... | ... | |
103 | 107 |
} |
104 | 108 |
|
105 | 109 |
public void drawOnTo(DataRaster canvas) { |
106 |
|
|
110 |
// TODO Check load mode of layer |
|
111 |
this.drawImageOnTo(canvas); |
|
112 |
} |
|
113 |
|
|
114 |
private void drawImageOnTo(DataRaster canvas) { |
|
107 | 115 |
if (canvas == null) { |
108 | 116 |
throw new IllegalArgumentException(); |
109 | 117 |
} |
... | ... | |
114 | 122 |
|
115 | 123 |
Sector overlap = this.getSector().intersection(canvas.getSector()); |
116 | 124 |
|
117 |
ViewPort viewPort = new ViewPort(mapContext.getProjection());
|
|
125 |
ViewPort viewPort = new ViewPort(mapControl3D.getMapContext().getProjection());
|
|
118 | 126 |
|
119 | 127 |
// Set adjustable to false to avoid problems with adjusted envelope |
120 | 128 |
viewPort.setAdjustable(false); |
... | ... | |
126 | 134 |
|
127 | 135 |
try { |
128 | 136 |
|
129 |
IProjection projection = mapContext.getProjection();
|
|
137 |
IProjection projection = mapControl3D.getMapContext().getProjection();
|
|
130 | 138 |
|
131 | 139 |
ICoordTrans ct = CRSFactory.getCRS("EPSG:4326").getCT(projection); |
132 | 140 |
Point2D p1 = convert(ct, new Point2D.Double(degrees[2], degrees[0])); |
... | ... | |
137 | 145 |
Math.min(p1.getY(), p2.getY()), |
138 | 146 |
Math.max(p1.getX(), p2.getX()), |
139 | 147 |
Math.max(p1.getY(), p2.getY()), SUBTYPES.GEOM2D); |
140 |
|
|
148 |
|
|
141 | 149 |
/** |
142 |
* Check if request tile intersect with layer envelope to avoid
|
|
143 |
* the creation of useless tiles.
|
|
150 |
* Check if request tile intersect with layer envelope to avoid |
|
151 |
* the creation of useless tiles.
|
|
144 | 152 |
*/ |
145 | 153 |
if (!envelope.intersects(layer.getFullEnvelope())) { |
146 | 154 |
return; |
... | ... | |
196 | 204 |
viewPort.refreshExtent(); |
197 | 205 |
|
198 | 206 |
try { |
199 |
|
|
207 |
|
|
200 | 208 |
layer.draw(image, (Graphics2D) image.getGraphics(), viewPort, |
201 |
getCancel(), getScale(viewPort));
|
|
202 |
|
|
209 |
mapControl3D.getCancellable(), getScale(viewPort));
|
|
210 |
|
|
203 | 211 |
if (layer instanceof FLyrVect && layer instanceof ILabelable) { |
204 |
|
|
212 |
|
|
205 | 213 |
ILabelable labelable = (ILabelable) layer; |
206 |
|
|
207 |
if (labelable.isLabeled()
|
|
214 |
|
|
215 |
if (labelable.isLabeled() |
|
208 | 216 |
&& labelable.getLabelingStrategy() != null |
209 | 217 |
&& labelable.getLabelingStrategy().shouldDrawLabels( |
210 | 218 |
getScale(viewPort))) { |
211 |
|
|
219 |
|
|
212 | 220 |
labelable.drawLabels(image, (Graphics2D) image |
213 |
.getGraphics(), viewPort, getCancel(),
|
|
214 |
getScale(viewPort), mapContext.getViewPort().getDPI());
|
|
221 |
.getGraphics(), viewPort, mapControl3D.getCancellable(),
|
|
222 |
getScale(viewPort), mapControl3D.getMapContext().getViewPort().getDPI());
|
|
215 | 223 |
} |
216 | 224 |
} |
217 | 225 |
|
218 | 226 |
} catch (ReadException e) { |
219 |
LOG.warn( |
|
220 |
"Can't draw required zone of layer {}, can't read legend", |
|
221 |
layer.getInfoString()); |
|
227 |
LOG.warn("Can't draw required zone of layer {}, can't read legend", |
|
228 |
layer.getName()); |
|
222 | 229 |
return; |
230 |
} finally { |
|
231 |
if(mapControl3D.getCancellable().isCanceled()){ |
|
232 |
return; |
|
233 |
} |
|
223 | 234 |
} |
224 | 235 |
BufferedImageRaster bufferedImageRaster = |
225 | 236 |
new BufferedImageRaster(overlap, image); |
... | ... | |
270 | 281 |
|
271 | 282 |
private double getScale(ViewPort viewPort) { |
272 | 283 |
|
273 |
MapContext mapContextCloned = mapContext.cloneFMap();
|
|
284 |
MapContext mapContextCloned = mapControl3D.getMapContext().cloneFMap();
|
|
274 | 285 |
mapContextCloned.setViewPort(viewPort); |
275 | 286 |
double scale = mapContextCloned.getScaleView(); |
276 | 287 |
mapContextCloned.dispose(); |
... | ... | |
340 | 351 |
params.setValue(AVKey.SECTOR, sector); |
341 | 352 |
|
342 | 353 |
GvSIGLayerDataRaster subRaster = |
343 |
new GvSIGLayerDataRaster(mapContext, layer, params);
|
|
354 |
new GvSIGLayerDataRaster(mapControl3D, layer, params);
|
|
344 | 355 |
return subRaster; |
345 | 356 |
} |
346 |
|
|
347 |
private Cancellable getCancel(){ |
|
348 |
Cancellable cancel = new Cancellable() { |
|
349 |
|
|
350 |
private boolean canceled = false; |
|
351 |
|
|
352 |
public void setCanceled(boolean flag) { |
|
353 |
canceled = flag; |
|
354 |
} |
|
355 |
|
|
356 |
public boolean isCanceled() { |
|
357 |
return canceled; |
|
358 |
} |
|
359 |
}; |
|
360 |
|
|
361 |
return cancel; |
|
362 |
} |
|
363 | 357 |
} |
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/DefaultLayerConverter.java | ||
---|---|---|
48 | 48 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
49 | 49 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
50 | 50 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
51 |
import org.gvsig.view3d.swing.api.MapControl3D; |
|
51 | 52 |
import org.gvsig.view3d.swing.impl.DefaultMapControl3D; |
52 | 53 |
import org.slf4j.Logger; |
53 | 54 |
import org.slf4j.LoggerFactory; |
... | ... | |
62 | 63 |
private static final Logger LOG = LoggerFactory |
63 | 64 |
.getLogger(DefaultLayerConverter.class); |
64 | 65 |
|
65 |
public Layer convertToLayer(MapContext mapContext, FLayer layer)
|
|
66 |
public Layer convertToLayer(MapControl3D mapControl, FLayer layer)
|
|
66 | 67 |
throws DataException { |
67 | 68 |
|
68 | 69 |
AVList params = new AVListImpl(); |
69 | 70 |
|
70 | 71 |
// Add Layer and MapContext to parameters. |
71 |
params.setValue(DefaultMapControl3D.GVSIG_MAPCONTEXT, mapContext);
|
|
72 |
params.setValue(DefaultMapControl3D.GVSIG_MAPCONTROL3D, mapControl);
|
|
72 | 73 |
params.setValue(DefaultMapControl3D.GVSIG_LAYER, layer); |
73 | 74 |
|
74 | 75 |
createRasterTiledImageLayerParams(layer, params); |
... | ... | |
80 | 81 |
// Copy parameters to avoid problems |
81 | 82 |
AVList paramsLayer = params.copy(); |
82 | 83 |
|
83 |
RasterTiledImageLayer rasterLayer =
|
|
84 |
new RasterTiledImageLayer(doc.getDocumentElement(), paramsLayer);
|
|
84 |
DefaultTiledImageLayer rasterLayer =
|
|
85 |
new DefaultTiledImageLayer(doc.getDocumentElement(), paramsLayer);
|
|
85 | 86 |
return rasterLayer; |
86 | 87 |
} |
87 | 88 |
|
88 |
public ElevationModel convertToElevationModel(MapContext mapContext,
|
|
89 |
public ElevationModel convertToElevationModel(MapControl3D mapControl,
|
|
89 | 90 |
FLayer layer) { |
90 | 91 |
// TODO Auto-generated method stub |
91 | 92 |
return null; |
... | ... | |
175 | 176 |
params.setValue(AVKey.DISPLAY_NAME, layer.getName()); |
176 | 177 |
params.setValue(AVKey.SERVICE_NAME, "Offline"); |
177 | 178 |
|
178 |
MapContext mapContext =
|
|
179 |
(MapContext) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTEXT);
|
|
179 |
MapControl3D mapControl3D =
|
|
180 |
(MapControl3D) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTROL3D);
|
|
180 | 181 |
|
181 | 182 |
Sector sector = null; |
182 | 183 |
try { |
183 |
sector = getSector(layer, mapContext.getProjection());
|
|
184 |
sector = getSector(layer, mapControl3D.getMapContext().getProjection());
|
|
184 | 185 |
} catch (DataException e) { |
185 | 186 |
LOG.info("Can't create sector from layer and projection", e); |
186 | 187 |
return; |
... | ... | |
228 | 229 |
params.setValue(AVKey.NETWORK_RETRIEVAL_ENABLED, false); |
229 | 230 |
params.setValue(AVKey.USE_MIP_MAPS, true); |
230 | 231 |
params.setValue(AVKey.USE_TRANSPARENT_TEXTURES, true); |
231 |
|
|
232 |
|
|
232 | 233 |
} |
233 | 234 |
|
234 | 235 |
private Sector getSector(FLayer layer, IProjection projection) |
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/DefaultRasterServer.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
package org.gvsig.view3d.swing.impl.data; |
26 | 26 |
|
27 |
import gov.nasa.worldwind.WWObjectImpl; |
|
27 | 28 |
import gov.nasa.worldwind.WorldWind; |
28 | 29 |
import gov.nasa.worldwind.avlist.AVKey; |
29 | 30 |
import gov.nasa.worldwind.avlist.AVList; |
... | ... | |
44 | 45 |
import java.io.IOException; |
45 | 46 |
import java.nio.ByteBuffer; |
46 | 47 |
|
48 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
49 |
import org.gvsig.view3d.swing.api.MapControl3D; |
|
50 |
import org.gvsig.view3d.swing.impl.DefaultMapControl3D; |
|
47 | 51 |
import org.slf4j.Logger; |
48 | 52 |
import org.slf4j.LoggerFactory; |
49 | 53 |
|
50 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
51 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
52 |
import org.gvsig.view3d.swing.impl.DefaultMapControl3D; |
|
53 |
|
|
54 | 54 |
/** |
55 | 55 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a> |
56 | 56 |
* |
57 | 57 |
*/ |
58 |
public class DefaultRasterServer implements RasterServer { |
|
58 |
public class DefaultRasterServer extends WWObjectImpl implements RasterServer {
|
|
59 | 59 |
|
60 | 60 |
private static final Logger LOG = LoggerFactory |
61 | 61 |
.getLogger(DefaultRasterServer.class); |
62 | 62 |
|
63 | 63 |
protected static final MemoryCache cache = new BasicRasterServerCache(); |
64 | 64 |
|
65 |
private AVList rasterServerParams; |
|
66 |
|
|
67 | 65 |
private DataRaster dataRaster; |
68 | 66 |
|
69 | 67 |
/** |
... | ... | |
76 | 74 |
throw new IllegalArgumentException(); |
77 | 75 |
} |
78 | 76 |
|
79 |
MapContext mapContext =
|
|
80 |
(MapContext) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTEXT);
|
|
77 |
MapControl3D mapControl3D =
|
|
78 |
(MapControl3D) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTROL3D);
|
|
81 | 79 |
|
82 |
if (mapContext == null) {
|
|
80 |
if (mapControl3D == null) {
|
|
83 | 81 |
LOG.error( |
84 | 82 |
"Can not create raster server, missing required parameter: {}", |
85 |
DefaultMapControl3D.GVSIG_MAPCONTEXT);
|
|
83 |
DefaultMapControl3D.GVSIG_MAPCONTROL3D);
|
|
86 | 84 |
throw new IllegalArgumentException(); |
87 | 85 |
} |
88 | 86 |
|
... | ... | |
95 | 93 |
throw new IllegalArgumentException(); |
96 | 94 |
} |
97 | 95 |
|
98 |
this.rasterServerParams = params;
|
|
96 |
this.setValues(params);
|
|
99 | 97 |
|
100 | 98 |
DataRasterReaderFactory readerFactory = |
101 | 99 |
(DataRasterReaderFactory) WorldWind |
... | ... | |
126 | 124 |
if (raster instanceof BufferedImageRaster) { |
127 | 125 |
|
128 | 126 |
if ("image/png".equalsIgnoreCase(format)) { |
129 |
|
|
127 |
|
|
130 | 128 |
return ImageUtil.asPNG(raster); |
131 |
|
|
129 |
|
|
132 | 130 |
} else if ("image/jpg".equalsIgnoreCase(format) |
133 | 131 |
|| "image/jpeg".equalsIgnoreCase(format)) { |
134 |
|
|
132 |
|
|
135 | 133 |
return ImageUtil.asJPEG(raster); |
136 |
|
|
134 |
|
|
137 | 135 |
} else if ("image/dds".equalsIgnoreCase(format)) { |
138 |
|
|
136 |
|
|
139 | 137 |
return DDSCompressor |
140 | 138 |
.compressImage(((BufferedImageRaster) raster) |
141 | 139 |
.getBufferedImage()); |
142 |
|
|
140 |
|
|
143 | 141 |
} |
144 | 142 |
} else if (raster instanceof ByteBufferRaster) { |
145 | 143 |
// Elevations as BIL16 or as BIL32 are stored in the simple |
... | ... | |
154 | 152 |
} |
155 | 153 |
|
156 | 154 |
public Sector getSector() { |
157 |
return (Sector) this.rasterServerParams.getValue(AVKey.SECTOR);
|
|
155 |
return (Sector) this.getValue(AVKey.SECTOR); |
|
158 | 156 |
} |
159 | 157 |
|
160 | 158 |
private DataRaster composeRaster(AVList reqParams) { |
... | ... | |
196 | 194 |
reqParams.setValue(AVKey.BYTE_ORDER, AVKey.BIG_ENDIAN); |
197 | 195 |
} |
198 | 196 |
|
199 |
reqParams.setValue(AVKey.PIXEL_FORMAT, AVKey.IMAGE); |
|
200 |
reqRaster = |
|
201 |
new BufferedImageRaster(reqWidth, reqHeight, |
|
202 |
Transparency.TRANSLUCENT, reqSector); |
|
197 |
if (AVKey.ELEVATION.equals(this.getValue(AVKey.PIXEL_FORMAT))) { |
|
203 | 198 |
|
199 |
reqParams.setValue(AVKey.PIXEL_FORMAT, AVKey.ELEVATION); |
|
200 |
|
|
201 |
if (!reqParams.hasKey(AVKey.DATA_TYPE)) { |
|
202 |
reqParams.setValue(AVKey.DATA_TYPE, AVKey.INT16); |
|
203 |
} |
|
204 |
|
|
205 |
reqRaster = |
|
206 |
new ByteBufferRaster(reqWidth, reqHeight, reqSector, reqParams); |
|
207 |
|
|
208 |
} else if (AVKey.IMAGE.equals(this.getValue(AVKey.PIXEL_FORMAT))) { |
|
209 |
|
|
210 |
reqParams.setValue(AVKey.PIXEL_FORMAT, AVKey.IMAGE); |
|
211 |
reqRaster = |
|
212 |
new BufferedImageRaster(reqWidth, reqHeight, |
|
213 |
Transparency.TRANSLUCENT, reqSector); |
|
214 |
|
|
215 |
} else { |
|
216 |
LOG.error("Unrecognized type of pixel format: {}", |
|
217 |
this.getValue(AVKey.PIXEL_FORMAT)); |
|
218 |
throw new IllegalArgumentException(); |
|
219 |
} |
|
220 |
|
|
204 | 221 |
this.dataRaster.drawOnTo(reqRaster); |
205 | 222 |
|
206 | 223 |
return reqRaster; |
2.1/trunk/org.gvsig.view3d/org.gvsig.view3d.swing/org.gvsig.view3d.swing.impl/src/main/java/org/gvsig/view3d/swing/impl/data/DefaultDataRasterReader.java | ||
---|---|---|
33 | 33 |
|
34 | 34 |
import java.io.IOException; |
35 | 35 |
|
36 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
37 | 36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 |
import org.gvsig.view3d.swing.api.MapControl3D; |
|
38 | 38 |
import org.gvsig.view3d.swing.impl.DefaultMapControl3D; |
39 | 39 |
|
40 | 40 |
/** |
... | ... | |
79 | 79 |
|
80 | 80 |
try { |
81 | 81 |
FLayer layer = (FLayer) source; |
82 |
MapContext mapContext =
|
|
83 |
(MapContext) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTEXT);
|
|
82 |
MapControl3D mapControl3D =
|
|
83 |
(MapControl3D) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTROL3D);
|
|
84 | 84 |
dataRaster = |
85 |
new GvSIGLayerDataRaster(mapContext, layer, params);
|
|
85 |
new GvSIGLayerDataRaster(mapControl3D, layer, params);
|
|
86 | 86 |
canRead = true; |
87 | 87 |
} catch (Throwable e) { |
88 | 88 |
canRead = false; |
... | ... | |
109 | 109 |
if (source instanceof FLayer) { |
110 | 110 |
|
111 | 111 |
FLayer layer = (FLayer) source; |
112 |
MapContext mapContext =
|
|
113 |
(MapContext) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTEXT);
|
|
112 |
MapControl3D mapControl3D =
|
|
113 |
(MapControl3D) params.getValue(DefaultMapControl3D.GVSIG_MAPCONTROL3D);
|
|
114 | 114 |
GvSIGLayerDataRaster dataRaster = |
115 |
new GvSIGLayerDataRaster(mapContext, layer, params);
|
|
115 |
new GvSIGLayerDataRaster(mapControl3D, layer, params);
|
|
116 | 116 |
return new DataRaster[] { dataRaster }; |
117 | 117 |
|
118 | 118 |
} |
Also available in: Unified diff