gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.lib / org.gvsig.gvsig3d.lib.impl / src / main / java / org / gvsig / gvsig3d / impl / map3d / MapContext3DImpl.java @ 361
History | View | Annotate | Download (65.8 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 |
*/
|
22 |
package org.gvsig.gvsig3d.impl.map3d; |
23 |
|
24 |
import java.awt.Color; |
25 |
import java.awt.Dimension; |
26 |
import java.awt.Graphics2D; |
27 |
import java.awt.geom.AffineTransform; |
28 |
import java.awt.image.BufferedImage; |
29 |
import java.awt.image.ImagingOpException; |
30 |
import java.io.File; |
31 |
import java.io.IOException; |
32 |
import java.util.Hashtable; |
33 |
import java.util.Vector; |
34 |
|
35 |
import org.cresques.cts.IProjection; |
36 |
import org.gvsig.fmap.dal.DataStore; |
37 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
38 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
39 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
40 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
41 |
import org.gvsig.fmap.dal.coverage.exception.FilePaletteException; |
42 |
import org.gvsig.fmap.dal.coverage.exception.FilterManagerException; |
43 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
44 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
45 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
46 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
47 |
import org.gvsig.fmap.dal.coverage.grid.Grid; |
48 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
49 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager; |
50 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
51 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
52 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
53 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
54 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
55 |
import org.gvsig.fmap.dal.exception.ReadException; |
56 |
import org.gvsig.fmap.geom.Geometry; |
57 |
import org.gvsig.fmap.geom.GeometryLocator; |
58 |
import org.gvsig.fmap.geom.GeometryManager; |
59 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
60 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
61 |
import org.gvsig.fmap.geom.primitive.Envelope; |
62 |
import org.gvsig.fmap.mapcontext.MapContext; |
63 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
64 |
import org.gvsig.fmap.mapcontext.ViewPort; |
65 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
66 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
67 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
68 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
69 |
import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
70 |
import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
71 |
import org.gvsig.fmap.mapcontext.layers.LayerListener; |
72 |
import org.gvsig.fmap.mapcontext.layers.SelectionEvent; |
73 |
import org.gvsig.fmap.mapcontext.layers.SingleLayerIterator; |
74 |
import org.gvsig.fmap.mapcontext.layers.operations.Classifiable; |
75 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
76 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
77 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
78 |
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
79 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
80 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent; |
81 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent; |
82 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
83 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener; |
84 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
85 |
import org.gvsig.gvsig3d.impl.symbology3d.Symbol3DFactory; |
86 |
import org.gvsig.gvsig3d.impl.symbology3d.marker.impl.SimpleMarker3DSymbol; |
87 |
import org.gvsig.gvsig3d.map3d.Layer3DProps; |
88 |
import org.gvsig.gvsig3d.map3d.MapContext3D; |
89 |
import org.gvsig.gvsig3d.map3d.layers.FLayers3D; |
90 |
import org.gvsig.gvsig3d.symbology3d.I3DSymbol; |
91 |
import org.gvsig.gvsig3d.symbology3d.marker.ISimpleMarker3DSymbol; |
92 |
import org.gvsig.osgvp.core.osg.Group; |
93 |
import org.gvsig.osgvp.core.osg.Image; |
94 |
import org.gvsig.osgvp.core.osg.Matrix; |
95 |
import org.gvsig.osgvp.core.osg.Node; |
96 |
import org.gvsig.osgvp.core.osg.Vec2; |
97 |
import org.gvsig.osgvp.core.osg.Vec3; |
98 |
import org.gvsig.osgvp.core.osg.Vec4; |
99 |
import org.gvsig.osgvp.exceptions.image.ImageConversionException; |
100 |
import org.gvsig.osgvp.exceptions.node.ChildIndexOutOfBoundsExceptions; |
101 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
102 |
import org.gvsig.osgvp.manipulator.BasicInputHandler; |
103 |
import org.gvsig.osgvp.manipulator.EditionManager; |
104 |
import org.gvsig.osgvp.symbology.ISymbol3D; |
105 |
import org.gvsig.osgvp.terrain.Extent; |
106 |
import org.gvsig.osgvp.terrain.HeightfieldLayer; |
107 |
import org.gvsig.osgvp.terrain.JavaDataDriver; |
108 |
import org.gvsig.osgvp.terrain.Layer; |
109 |
import org.gvsig.osgvp.terrain.LayerManager; |
110 |
import org.gvsig.osgvp.terrain.RequestDataEvent; |
111 |
import org.gvsig.osgvp.terrain.Terrain; |
112 |
import org.gvsig.osgvp.terrain.Terrain.CoordinateSystemType; |
113 |
import org.gvsig.osgvp.terrain.TerrainViewer; |
114 |
import org.gvsig.osgvp.terrain.TextureLayer; |
115 |
import org.gvsig.osgvp.terrain.UpdateDataEvent; |
116 |
import org.gvsig.osgvp.terrain.VectorLayer; |
117 |
import org.gvsig.osgvp.terrain.exceptions.LayerManagementException; |
118 |
import org.gvsig.osgvp.viewer.Camera; |
119 |
import org.gvsig.osgvp.viewer.IViewerContainer; |
120 |
import org.gvsig.osgvp.viewer.OSGViewer; |
121 |
import org.gvsig.raster.cache.tile.TileCache; |
122 |
import org.gvsig.raster.cache.tile.TileCacheLibrary; |
123 |
import org.gvsig.raster.cache.tile.TileCacheLocator; |
124 |
import org.gvsig.raster.cache.tile.TileCacheManager; |
125 |
import org.gvsig.raster.cache.tile.provider.CacheStruct; |
126 |
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
127 |
import org.gvsig.raster.impl.grid.GridImpl; |
128 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
129 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractIntervalLegend; |
130 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend; |
131 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
132 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
133 |
import org.gvsig.tools.ToolsLocator; |
134 |
import org.gvsig.tools.dynobject.DynStruct; |
135 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
136 |
import org.gvsig.tools.locator.LocatorException; |
137 |
import org.gvsig.tools.persistence.PersistenceManager; |
138 |
import org.gvsig.tools.task.Cancellable; |
139 |
import org.gvsig.tools.util.Callable; |
140 |
|
141 |
/**
|
142 |
* @author gvSIG Team
|
143 |
* @version $Id$
|
144 |
*
|
145 |
*/
|
146 |
public class MapContext3DImpl extends MapContext3D { |
147 |
|
148 |
private Terrain _terrain;
|
149 |
private IViewerContainer _canvas3d;
|
150 |
private TerrainViewer _terrainViewer;
|
151 |
private LayerManager _terrainLayerManager;
|
152 |
private JavaDataDriver _terrainDataManager = null; |
153 |
|
154 |
private Hashtable<FLayer, Layer> _terrainFLayerMap = new Hashtable<FLayer, Layer>(); |
155 |
private Hashtable<String, FLayer> _terrainLayerMap = new Hashtable<String, FLayer>(); |
156 |
|
157 |
private Hashtable<FLayer, EditionManager> _layersEditionMap = new Hashtable<FLayer, EditionManager>(); |
158 |
private Hashtable<FLayer, BasicInputHandler> _layersHandlerMap = new Hashtable<FLayer, BasicInputHandler>(); |
159 |
|
160 |
private Hashtable<DefaultFLyrRaster, CacheStruct> _cachedLayers = new Hashtable<DefaultFLyrRaster, CacheStruct>(); |
161 |
|
162 |
private IProjection _viewProjection;
|
163 |
private float _verticalExaggeration; |
164 |
private boolean _bEmptyView = true; |
165 |
private boolean _bListenToLegend = true; |
166 |
private boolean _bLoading = false; |
167 |
private TerrainViewer _canvasoff = null; |
168 |
private boolean _renewCanvasOff = false; |
169 |
|
170 |
TerrainViewer _printViewer = null;
|
171 |
Layer _testRasterLayer = null;
|
172 |
|
173 |
private boolean visibilityChange = false; |
174 |
|
175 |
TileCacheManager tileMan = TileCacheLocator.getManager(); |
176 |
TileCache tileCache = tileMan.getTileCache(RasterLibrary.pathTileCache); |
177 |
|
178 |
int maxBands = 3; |
179 |
|
180 |
public MapContext3DImpl() {
|
181 |
|
182 |
} |
183 |
|
184 |
public MapContext3DImpl(ViewPort vp) {
|
185 |
super(vp);
|
186 |
|
187 |
} |
188 |
|
189 |
public MapContext3DImpl(FLayers fLayers, ViewPort vp) {
|
190 |
|
191 |
super(fLayers, vp);
|
192 |
} |
193 |
|
194 |
public void draw(BufferedImage image, Graphics2D g, Cancellable cancel, |
195 |
double scale) {
|
196 |
|
197 |
if (_canvas3d == null || _canvas3d.getOSGViewer() == null) |
198 |
return;
|
199 |
double x = getViewPort().getOffset().getX();
|
200 |
double y = getViewPort().getOffset().getY();
|
201 |
double w = image.getWidth();
|
202 |
double h = image.getHeight();
|
203 |
|
204 |
if (_canvasoff == null) { |
205 |
try {
|
206 |
_canvasoff = new TerrainViewer();
|
207 |
_canvasoff.setUpViewerInBackground(0, 0, 512, 512); |
208 |
|
209 |
Terrain planetView3D = ((TerrainViewer) _canvas3d |
210 |
.getOSGViewer()).getTerrain(0);
|
211 |
Terrain terrain = new Terrain();
|
212 |
terrain.setCoordinateSystemType(planetView3D |
213 |
.getCoordinateSystemType()); |
214 |
terrain.setCoordinateSystemName(planetView3D |
215 |
.getCoordinateSystemName()); |
216 |
terrain.setCoordinateSystemFormat(planetView3D |
217 |
.getCoordinateSystemFormat()); |
218 |
terrain.setExtent(planetView3D.xMin(), planetView3D.yMin(), |
219 |
planetView3D.xMax(), planetView3D.yMax()); |
220 |
terrain.setTerrainName(planetView3D.getTerrainName()); |
221 |
|
222 |
terrain.init(); |
223 |
terrain.setLayerManager(_terrainLayerManager); |
224 |
|
225 |
_canvasoff.addTerrain(terrain); |
226 |
_canvasoff.addFeature((((TerrainViewer) _canvas3d |
227 |
.getOSGViewer()).getFeatures())); |
228 |
Vec4 color = ((TerrainViewer) _canvas3d.getOSGViewer()) |
229 |
.getClearColor(); |
230 |
_canvasoff.setClearColor(color.x(), color.y(), color.z(), |
231 |
color.w()); |
232 |
this.setRenewCanvasOff(false); |
233 |
} catch (NodeException e) {
|
234 |
// TODO Auto-generated catch block
|
235 |
e.printStackTrace(); |
236 |
} |
237 |
|
238 |
} |
239 |
|
240 |
Camera refCam = _canvas3d.getOSGViewer().getCamera(); |
241 |
Matrix refView = refCam.getViewMatrix(); |
242 |
Matrix refProy = refCam.getProjectionMatrix(); |
243 |
Matrix.Perspective pers = refProy.getPerspective(); |
244 |
Camera viewCam = new Camera();
|
245 |
viewCam.setProjectionMatrixAsPerspective(pers.fovy, w / h, pers.zNear, |
246 |
pers.zFar); |
247 |
viewCam.setViewMatrix(refView); |
248 |
_canvasoff.setViewport(0, 0, (int) w, (int) h); |
249 |
_canvasoff.setCamera(viewCam); |
250 |
_canvasoff.takeScreenshotToMemory(); |
251 |
_canvasoff.frame(); |
252 |
|
253 |
org.gvsig.osgvp.core.osg.Image OSGimage = _canvasoff |
254 |
.getScreenshotImage(); |
255 |
|
256 |
BufferedImage img = null; |
257 |
try {
|
258 |
img = OSGimage.getBufferedImage(); |
259 |
} catch (ImageConversionException e1) {
|
260 |
// TODO Auto-generated catch block
|
261 |
e1.printStackTrace(); |
262 |
} catch (IOException e1) { |
263 |
// TODO Auto-generated catch block
|
264 |
e1.printStackTrace(); |
265 |
} |
266 |
|
267 |
double scalex = w / img.getWidth(null); |
268 |
double scaley = h / img.getHeight(null); |
269 |
try {
|
270 |
AffineTransform xform = AffineTransform.getScaleInstance(scalex, |
271 |
scaley); |
272 |
AffineTransform xpos = AffineTransform.getTranslateInstance(x, y); |
273 |
xpos.concatenate(xform); |
274 |
g.drawRenderedImage(img, xpos); |
275 |
} catch (ImagingOpException e) { |
276 |
|
277 |
} |
278 |
} |
279 |
|
280 |
public void CreateOSGLayer(FLayer layer, Layer3DProps props3d) { |
281 |
// if (_terrain == null || _viewProjection == null)
|
282 |
// return;
|
283 |
//
|
284 |
// OSGCacheService cacheService = (OSGCacheService) props3D
|
285 |
// .getCacheService();
|
286 |
// if (cacheService == null) {
|
287 |
// cacheService = new OSGCacheService(_canvas3d, _terrain, props3D
|
288 |
// .getCacheName(), layer, _viewProjection);
|
289 |
// cacheService.setCacheRootDir(Layer3DProps.m_cacheDir);
|
290 |
// props3D.setCacheService(cacheService);
|
291 |
// }
|
292 |
//
|
293 |
// // use VectorCacheService to add features to planet
|
294 |
// cacheService.AddFeaturesToTerrain();
|
295 |
|
296 |
} |
297 |
|
298 |
public void DeleteOSGLayer(FLayer layer, Layer3DProps props3d) { |
299 |
// if (_terrain == null || _viewProjection == null)
|
300 |
// return;
|
301 |
//
|
302 |
// OSGCacheService cacheService = (OSGCacheService) props3D
|
303 |
// .getCacheService();
|
304 |
// if (cacheService != null) {
|
305 |
// // use VectorCacheService to delete features to terrain
|
306 |
// cacheService.DeleteFeaturesToTerrain();
|
307 |
// }
|
308 |
|
309 |
} |
310 |
|
311 |
public void PrintDebugLayers() { |
312 |
if (_terrainLayerManager != null) { |
313 |
System.out.println("==========================="); |
314 |
System.out.println("Total terrain layers: " |
315 |
+ _terrainLayerManager.getNumLayers()); |
316 |
System.out.println("==========================="); |
317 |
} |
318 |
SingleLayerIterator lyrIterator = new SingleLayerIterator(layers);
|
319 |
int pos = 0; |
320 |
while (lyrIterator.hasNext()) {
|
321 |
FLayer layer = lyrIterator.next(); |
322 |
System.out.println(" Layer " + layer.getName()); |
323 |
Layer3DProps props3D = getLayer3DProps(layer); |
324 |
System.out.println(" Type " + props3D.getType()); |
325 |
System.out.println(" Order " + pos); |
326 |
pos++; |
327 |
} |
328 |
} |
329 |
|
330 |
public void activationChanged(LayerEvent e) { |
331 |
|
332 |
} |
333 |
|
334 |
public void addCurrentLayers() { |
335 |
|
336 |
SingleLayerIterator lyrIterator = new SingleLayerIterator(layers);
|
337 |
while (lyrIterator.hasNext()) {
|
338 |
FLayer layer = lyrIterator.next(); |
339 |
Layer3DProps props = getLayer3DProps(layer); |
340 |
layerAdded((FLayers3D) layer.getParentLayer(), layer); |
341 |
// addLayerToTerrain(layer, false);
|
342 |
|
343 |
} |
344 |
|
345 |
} |
346 |
|
347 |
public void addLayerToTerrain(FLayer layer, boolean bVerifyLegend) { |
348 |
|
349 |
System.out.println("ADD LAYER TO TERRAIN METHOD!"); |
350 |
Envelope layerEnvelope = null;
|
351 |
try {
|
352 |
layerEnvelope = layer.getFullEnvelope(); |
353 |
} catch (ReadException e1) {
|
354 |
// TODO Auto-generated catch block
|
355 |
e1.printStackTrace(); |
356 |
} |
357 |
|
358 |
Layer3DProps props = getLayer3DProps(layer); |
359 |
GeometryManager geoMan; |
360 |
|
361 |
geoMan = GeometryLocator.getGeometryManager(); |
362 |
|
363 |
if (layerEnvelope == null) { |
364 |
|
365 |
try {
|
366 |
layerEnvelope = geoMan.createEnvelope(Geometry.SUBTYPES.GEOM2D); |
367 |
if (_terrain.getCoordinateSystemType() == Terrain.CoordinateSystemType.GEOCENTRIC) {
|
368 |
layerEnvelope.setLowerCorner(geoMan.createPoint(-180.0,
|
369 |
-90.0, Geometry.SUBTYPES.GEOM2D));
|
370 |
layerEnvelope.setUpperCorner(geoMan.createPoint(360.0,
|
371 |
180.0, Geometry.SUBTYPES.GEOM2D));
|
372 |
} |
373 |
|
374 |
else {
|
375 |
|
376 |
layerEnvelope.setLowerCorner(geoMan |
377 |
.createPoint(-20000000.0, -10000000.00, |
378 |
Geometry.SUBTYPES.GEOM2D)); |
379 |
layerEnvelope.setUpperCorner(geoMan.createPoint(40000000.0,
|
380 |
20000000.0, Geometry.SUBTYPES.GEOM2D));
|
381 |
|
382 |
} |
383 |
} catch (CreateEnvelopeException e) {
|
384 |
// TODO Auto-generated catch block
|
385 |
e.printStackTrace(); |
386 |
} catch (CreateGeometryException e) {
|
387 |
// TODO Auto-generated catch block
|
388 |
e.printStackTrace(); |
389 |
} |
390 |
|
391 |
} |
392 |
|
393 |
Extent extent = null;
|
394 |
if (_terrain.getCoordinateSystemType() == CoordinateSystemType.PROJECTED) {
|
395 |
|
396 |
extent = new Extent(layerEnvelope.getLowerCorner().getX(),
|
397 |
layerEnvelope.getLowerCorner().getY(), layerEnvelope |
398 |
.getUpperCorner().getX(), layerEnvelope |
399 |
.getUpperCorner().getY()); |
400 |
|
401 |
} else {
|
402 |
extent = new Extent(Math.toRadians(layerEnvelope.getLowerCorner() |
403 |
.getX()), Math.toRadians(layerEnvelope.getLowerCorner()
|
404 |
.getY()), Math.toRadians(layerEnvelope.getUpperCorner()
|
405 |
.getX()), Math.toRadians(layerEnvelope.getUpperCorner()
|
406 |
.getY())); |
407 |
|
408 |
} |
409 |
|
410 |
// Raster Layers
|
411 |
if (props.getType() == Layer3DPropsImpl.layer3DImage)
|
412 |
// || props.reasterized()==true) {
|
413 |
{ |
414 |
TextureLayer rlayer = new TextureLayer();
|
415 |
rlayer.setEnabled(layer.isVisible()); |
416 |
// Here we use extent because the older osgvp version. The new will
|
417 |
// be
|
418 |
// named envelope
|
419 |
rlayer.setExtent(extent); |
420 |
rlayer.setOpacity(props.getOpacity()); |
421 |
rlayer.setDataDriver(_terrainDataManager); |
422 |
// rlayer.setMaxLevel(20);
|
423 |
// rlayer.setMaxResolution(16);
|
424 |
// _logger.warn("computed optimum level = "
|
425 |
// + computeOptimumLevel(layer, 20, 256));
|
426 |
// rlayer.setMaxResolution(computeOptimumLevel(layer, 21, 256));
|
427 |
try {
|
428 |
_terrainLayerManager.addLayer(rlayer); |
429 |
} catch (LayerManagementException e) {
|
430 |
// TODO Auto-generated catch block
|
431 |
e.printStackTrace(); |
432 |
} |
433 |
_terrainFLayerMap.put(layer, rlayer); |
434 |
_terrainLayerMap.put(rlayer.getLayerID(), layer); |
435 |
props.setTerrainLayer(rlayer); |
436 |
|
437 |
// if rasterizing layers set Default 2D symbology
|
438 |
if (layer instanceof FLyrVect) { |
439 |
// Create a 2D Legend for jess
|
440 |
if (((FLyrVect) (layer)).getLegend().getDefaultSymbol() instanceof I3DSymbol) |
441 |
try {
|
442 |
((FLyrVect) layer) |
443 |
.setLegend((IVectorLegend) MapContextLocator |
444 |
.getMapContextManager() |
445 |
.getLegend( |
446 |
((FLyrVect) layer) |
447 |
.getDataStore(), |
448 |
MapContextLocator |
449 |
.getMapContextManager() |
450 |
.getDefaultSymbologyDomain())); |
451 |
} catch (LegendLayerException e) {
|
452 |
// TODO Auto-generated catch block
|
453 |
e.printStackTrace(); |
454 |
} catch (LocatorException e) {
|
455 |
// TODO Auto-generated catch block
|
456 |
e.printStackTrace(); |
457 |
} |
458 |
} |
459 |
|
460 |
// Delete the cachestruct if it exists, and create a new one.
|
461 |
|
462 |
if (_cachedLayers.containsKey(layer)) {
|
463 |
|
464 |
_cachedLayers.remove(layer); |
465 |
|
466 |
} |
467 |
|
468 |
} |
469 |
// Vector layers
|
470 |
if (props.getType() == Layer3DProps.layer3DVector) {
|
471 |
// if (layer instanceof FLyrVect) {
|
472 |
// Set a 3D Legend
|
473 |
// TODO We don't need to create always a new Legend. We need to
|
474 |
if (((FLyrVect) layer).getLegend() instanceof ISingleSymbolLegend) |
475 |
if (!(((FLyrVect) layer).getLegend().getDefaultSymbol() instanceof I3DSymbol)) { |
476 |
try {
|
477 |
((FLyrVect) layer) |
478 |
.setLegend((IVectorLegend) MapContextLocator |
479 |
.getMapContextManager().getLegend( |
480 |
((FLyrVect) layer) |
481 |
.getDataStore(), |
482 |
"project.document.view3d"));
|
483 |
} catch (LegendLayerException e) {
|
484 |
// TODO Auto-generated catch block
|
485 |
e.printStackTrace(); |
486 |
} catch (LocatorException e) {
|
487 |
// TODO Auto-generated catch block
|
488 |
e.printStackTrace(); |
489 |
} |
490 |
} |
491 |
|
492 |
VectorLayer vlayer = new VectorLayer();
|
493 |
vlayer.setEnabled(layer.isVisible()); |
494 |
vlayer.setExtent(extent); |
495 |
vlayer.setDataDriver(_terrainDataManager); |
496 |
try {
|
497 |
_terrainLayerManager.addLayer(vlayer); |
498 |
} catch (LayerManagementException e) {
|
499 |
// TODO Auto-generated catch block
|
500 |
e.printStackTrace(); |
501 |
} |
502 |
_terrainFLayerMap.put(layer, vlayer); |
503 |
_terrainLayerMap.put(vlayer.getLayerID(), layer); |
504 |
props.setTerrainLayer(vlayer); |
505 |
} |
506 |
// OsgLayers
|
507 |
|
508 |
// Elevation layers
|
509 |
if (props.getType() == Layer3DPropsImpl.layer3DElevation) {
|
510 |
|
511 |
HeightfieldLayer hLayer = new HeightfieldLayer();
|
512 |
hLayer.setEnabled(layer.isVisible()); |
513 |
hLayer.setExtent(extent); |
514 |
hLayer.setDataDriver(_terrainDataManager); |
515 |
hLayer.setMaxLevel(20);
|
516 |
hLayer.setMaxResolution(18);
|
517 |
hLayer.setScaleFactor(props.getVerticalEx()); |
518 |
|
519 |
hLayer.setValidDataValues(new Vec2(-9999, 9999)); |
520 |
// _logger.warn("computed optimum level = "
|
521 |
// + computeOptimumLevel(layer, 20, 256));
|
522 |
// rlayer.setMaxResolution(computeOptimumLevel(layer, 21, 256));
|
523 |
try {
|
524 |
_terrainLayerManager.addLayer(hLayer); |
525 |
} catch (LayerManagementException e) {
|
526 |
// TODO Auto-generated catch block
|
527 |
e.printStackTrace(); |
528 |
} |
529 |
_terrainFLayerMap.put(layer, hLayer); |
530 |
_terrainLayerMap.put(hLayer.getLayerID(), layer); |
531 |
props.setTerrainLayer(hLayer); |
532 |
|
533 |
// Delete the cachestruct if it exists, and create a new one.
|
534 |
|
535 |
if (_cachedLayers.containsKey(layer)) {
|
536 |
|
537 |
_cachedLayers.remove(layer); |
538 |
|
539 |
} |
540 |
|
541 |
} |
542 |
|
543 |
// if (bVerifyLegend) {
|
544 |
// _bListenToLegend = false;
|
545 |
// props3D.VerifyLegend(_terrain.getTerrainName());
|
546 |
// _bListenToLegend = true;
|
547 |
// }
|
548 |
// }
|
549 |
|
550 |
} |
551 |
|
552 |
public int computeOptimumLevel(FLayer layer, int maxLevel, double tileSize) { |
553 |
int level = maxLevel;
|
554 |
// if (!(layer instanceof DefaultFLyrRaster))
|
555 |
// return level;
|
556 |
//
|
557 |
// Envelope enve = null;
|
558 |
//
|
559 |
// enve = layer.getFullEnvelope();
|
560 |
//
|
561 |
// ArrayList attr = ((DefaultFLyrRaster) layer).getAttributes();
|
562 |
// if (attr == null) {
|
563 |
// return level;
|
564 |
// }
|
565 |
// int width = 0, height = 0;
|
566 |
// for (int i = 0; i < attr.size(); i++) {
|
567 |
// Object[] a = (Object[]) attr.get(i);
|
568 |
// if (a[0].toString().equals("Width"))
|
569 |
// width = ((Integer) a[1]).intValue();
|
570 |
// if (a[0].toString().equals("Height"))
|
571 |
// height = ((Integer) a[1]).intValue();
|
572 |
// }
|
573 |
//
|
574 |
// if (ext != null && width != 0 && height != 0) {
|
575 |
//
|
576 |
// Extent destinationExtents = _terrain.getExtent();
|
577 |
// double xMax = destinationExtents.xMax();
|
578 |
// double xMin = destinationExtents.xMin();
|
579 |
// double yMax = destinationExtents.yMax();
|
580 |
// double yMin = destinationExtents.yMin();
|
581 |
// int terrainType = _terrain.getCoordinateSystemType();
|
582 |
// if (terrainType == Terrain.CoordinateSystemType.GEOCENTRIC) {
|
583 |
// xMax = Math.toDegrees(xMax);
|
584 |
// xMin = Math.toDegrees(xMin);
|
585 |
// yMax = Math.toDegrees(yMax);
|
586 |
// yMin = Math.toDegrees(yMin);
|
587 |
// }
|
588 |
//
|
589 |
// double destination_xRange = xMax - xMin;
|
590 |
// double destination_yRange = yMax - yMin;
|
591 |
// double AR = destination_xRange / destination_yRange;
|
592 |
// int C1 = 1;
|
593 |
// int R1 = 1;
|
594 |
//
|
595 |
// boolean swapAxis = AR < 1.0;
|
596 |
// if (swapAxis)
|
597 |
// AR = 1.0 / AR;
|
598 |
//
|
599 |
// double lower_AR = Math.floor(AR);
|
600 |
// double upper_AR = Math.ceil(AR);
|
601 |
//
|
602 |
// if (AR < Math.sqrt(lower_AR * upper_AR)) {
|
603 |
// C1 = (int) (lower_AR);
|
604 |
// R1 = 1;
|
605 |
// } else {
|
606 |
// C1 = (int) (upper_AR);
|
607 |
// R1 = 1;
|
608 |
// }
|
609 |
//
|
610 |
// if (swapAxis) {
|
611 |
// // std::swap(C1,R1);
|
612 |
// int t = C1;
|
613 |
// C1 = R1;
|
614 |
// R1 = t;
|
615 |
// }
|
616 |
//
|
617 |
// double source_xRange = enve.getMaxX() - enve.getMinX();
|
618 |
// double source_yRange = enve.getMaxY() - enve.getMinY();
|
619 |
//
|
620 |
// float sourceResolutionX = ((float) source_xRange) / (float) width;
|
621 |
// float sourceResolutionY = ((float) source_yRange) / (float) height;
|
622 |
//
|
623 |
// //
|
624 |
// log(osg::NOTICE,"Source %s resX %f resY %f",source->getFileName().c_str(),
|
625 |
// // sourceResolutionX, sourceResolutionX);
|
626 |
//
|
627 |
// int k_cols =
|
628 |
// (int) (Math.ceil(1.0
|
629 |
// + Math.log(destination_xRange
|
630 |
// / (C1 * sourceResolutionX * tileSize)) / Math.log(2.0)));
|
631 |
// int k_rows =
|
632 |
// (int) (Math.ceil(1.0
|
633 |
// + Math.log(destination_yRange
|
634 |
// / (R1 * sourceResolutionY * tileSize)) / Math.log(2.0)));
|
635 |
// level = Math.max(k_cols, k_rows);
|
636 |
// level = Math.min(level, maxLevel);
|
637 |
// level = Math.max(level, 0);
|
638 |
// }
|
639 |
return level;
|
640 |
} |
641 |
|
642 |
public IViewerContainer getCanvas3d() {
|
643 |
return _canvas3d;
|
644 |
} |
645 |
|
646 |
public JavaDataDriver getDataManager() {
|
647 |
return _terrainDataManager;
|
648 |
} |
649 |
|
650 |
public Layer3DProps getLayer3DProps(FLayer layer) {
|
651 |
Layer3DProps props3D = (Layer3DProps) layer |
652 |
.getProperty("3DLayerExtension");
|
653 |
//
|
654 |
// // Create instance of props for osg layers.
|
655 |
if (props3D == null) { |
656 |
props3D = new Layer3DPropsImpl(layer);
|
657 |
// if (layer instanceof FLyrVect) {
|
658 |
// FLyrVect nLayer = (FLyrVect) layer;
|
659 |
// Driver driver;
|
660 |
// try {
|
661 |
// driver = nLayer.getRecordset().getDriver();
|
662 |
// if (driver instanceof GvsigDriverOSG) {
|
663 |
// props3D.setChooseType(false);
|
664 |
// props3D.setType(Layer3DProps.layer3DOSG);
|
665 |
// }
|
666 |
// } catch (ReadDriverException e) {
|
667 |
// // TODO Auto-generated catch block
|
668 |
// e.printStackTrace();
|
669 |
// }
|
670 |
//
|
671 |
// }
|
672 |
// // Set the properties
|
673 |
props3D.setLayer(layer); |
674 |
//
|
675 |
// props3D.initCacheName(_terrain.getCoordinateSystemType(),
|
676 |
// _viewProjection, Terrain.CoordinateSystemType.GEOCENTRIC);
|
677 |
FLyrDefault baseLayer = (FLyrDefault) layer; |
678 |
baseLayer.setProperty("3DLayerExtension", props3D);
|
679 |
props3D.setVerticalEx(getVerticalExaggeration()); |
680 |
} else {
|
681 |
if (_bLoading)
|
682 |
props3D.setChooseType(false);
|
683 |
props3D.setLayer(layer); |
684 |
} |
685 |
//
|
686 |
return props3D;
|
687 |
|
688 |
// return null;
|
689 |
} |
690 |
|
691 |
public LayerManager getLayerManager() {
|
692 |
return _terrainLayerManager;
|
693 |
} |
694 |
|
695 |
public Node getSpecialNode() {
|
696 |
Node specialNode = null;
|
697 |
try {
|
698 |
specialNode = _terrainViewer.getFeature(0);
|
699 |
} catch (ChildIndexOutOfBoundsExceptions e) {
|
700 |
|
701 |
} |
702 |
return specialNode;
|
703 |
} |
704 |
|
705 |
public Terrain getTerrain() {
|
706 |
return _terrain;
|
707 |
} |
708 |
|
709 |
public float getVerticalExaggeration() { |
710 |
return _verticalExaggeration;
|
711 |
} |
712 |
|
713 |
public IProjection getViewProjection() {
|
714 |
return _viewProjection;
|
715 |
} |
716 |
|
717 |
public void invalidateVectorLayer(Layer3DProps props) { |
718 |
|
719 |
// TODO Auto-generated method stub
|
720 |
// if (_terrain == null || _viewProjection == null)
|
721 |
// return;
|
722 |
//
|
723 |
// VectorCacheService cacheService = (VectorCacheService) props
|
724 |
// .getCacheService();
|
725 |
// if (cacheService != null) {
|
726 |
// // use VectorCacheService to add features to terrain
|
727 |
// cacheService.refreshFeaturesToTerrain();
|
728 |
// }
|
729 |
|
730 |
} |
731 |
|
732 |
public boolean isRenewCanvasOff() { |
733 |
return _renewCanvasOff;
|
734 |
} |
735 |
|
736 |
public void layerAdded(FLayers3D parent, FLayer layer) { |
737 |
|
738 |
System.out.println("A?adida capa. Evento Capturado"); |
739 |
// to add group layers to 3D, just add recursively child data layers
|
740 |
if (layer instanceof FLayers) { |
741 |
FLayers group = (FLayers) layer; |
742 |
for (int iChild = 0; iChild < group.getLayersCount(); iChild++) { |
743 |
layerAdded((FLayers3D) group, group.getLayer(iChild)); |
744 |
} |
745 |
getLayer3DProps(layer).setHooked(true);
|
746 |
return;
|
747 |
} |
748 |
//
|
749 |
if (layer instanceof Classifiable) { |
750 |
Classifiable legendLyr = (Classifiable) layer; |
751 |
legendLyr.addLegendListener((LegendListener) this);
|
752 |
this.addLayerListener(this); |
753 |
} |
754 |
layer.addLayerListener((LayerListener) this);
|
755 |
|
756 |
// listener to manage the selection for the layers
|
757 |
// if (layer.getClass().equals(FLyrVect.class)) {
|
758 |
// FLyrVect lyr = (FLyrVect) layer;
|
759 |
// refreshLayerVectorsVisibility(lyr);
|
760 |
// try {
|
761 |
// SelectableDataSource recordSet = lyr.getRecordset();
|
762 |
// if (recordSet != null) {
|
763 |
// SelectionSupport selectionSupport = recordSet
|
764 |
// .getSelectionSupport();
|
765 |
// selectionSupport.addSelectionListener(this);
|
766 |
// }
|
767 |
// } catch (ReadDriverException e) {
|
768 |
// // TODO Auto-generated catch block
|
769 |
// e.printStackTrace();
|
770 |
// }
|
771 |
// }
|
772 |
|
773 |
// if (!_bLoading)
|
774 |
Layer3DProps props3D = getLayer3DProps(layer); |
775 |
|
776 |
if (layer instanceof DefaultFLyrRaster) { |
777 |
try {
|
778 |
// If DefaultFLayerRaster we must init the layer for the
|
779 |
// persistence to
|
780 |
// work
|
781 |
((DefaultFLyrRaster) layer).init(); |
782 |
props3D.setType(Layer3DProps.layer3DImage); |
783 |
} catch (LoadLayerException e) {
|
784 |
// TODO Auto-generated catch block
|
785 |
e.printStackTrace(); |
786 |
} catch (FilePaletteException e) {
|
787 |
// TODO Auto-generated catch block
|
788 |
e.printStackTrace(); |
789 |
} |
790 |
|
791 |
} |
792 |
|
793 |
// If it's a vectorial layer we load it as 3D by default
|
794 |
else if (layer instanceof FLyrVect) { |
795 |
|
796 |
props3D.setType(Layer3DProps.layer3DVector); |
797 |
} |
798 |
addLayerToTerrain(layer, true);
|
799 |
|
800 |
// Only do this the first time to add layer
|
801 |
// if (_bEmptyView && !_bLoading) {
|
802 |
// if (layers.getLayersCount() > 0) {
|
803 |
// try {
|
804 |
try {
|
805 |
zoomToEnvelope(layer.getFullEnvelope()); |
806 |
} catch (ReadException e) {
|
807 |
// TODO Auto-generated catch block
|
808 |
e.printStackTrace(); |
809 |
} |
810 |
// } catch (ExpansionFileReadException e) {
|
811 |
// e.printStackTrace();
|
812 |
// } catch (ReadDriverException e) {
|
813 |
// e.printStackTrace();
|
814 |
// }
|
815 |
// _bEmptyView = false;
|
816 |
// }
|
817 |
// }
|
818 |
//
|
819 |
// // PrintDebugLayers();
|
820 |
|
821 |
} |
822 |
|
823 |
private CacheStruct getCacheStruct(DefaultFLyrRaster layer) {
|
824 |
|
825 |
// System.out.println("Creando estructura de cache");
|
826 |
|
827 |
// Se obtiene el datastore de la capa
|
828 |
RasterDataStore dataStore = layer.getDataStore(); |
829 |
|
830 |
// Creais la estructura de cach?
|
831 |
TileCacheManager manager = TileCacheLocator.getManager(); |
832 |
|
833 |
int coordinates = CacheStruct.FLAT;
|
834 |
|
835 |
if (_terrain.getCoordinateSystemType() == Terrain.CoordinateSystemType.GEOGRAPHIC)
|
836 |
coordinates = CacheStruct.GEOGRAFIC; |
837 |
|
838 |
DefaultRasterProvider provider = (DefaultRasterProvider) dataStore |
839 |
.getProvider(); |
840 |
|
841 |
provider.setProjection(layer.getProjection()); |
842 |
|
843 |
// El epsg suele tener la forma EPSG:4326
|
844 |
String epsg = null; |
845 |
IProjection proj = provider.getProjection(); |
846 |
if (proj != null) |
847 |
epsg = proj.getAbrev(); |
848 |
|
849 |
// HACK
|
850 |
epsg = "EPSG:23030";
|
851 |
|
852 |
int resolution = 256; |
853 |
|
854 |
int type = getLayer3DProps(layer).getType();
|
855 |
|
856 |
// if elevation layer, lower the tile resolution
|
857 |
if (type == Layer3DProps.layer3DElevation)
|
858 |
|
859 |
resolution = 32;
|
860 |
|
861 |
CacheStruct struct = manager.createCacheStructure(coordinates, |
862 |
TileCacheLibrary.DEFAULT_LEVELS, provider.getExtent() |
863 |
.toRectangle2D(), provider.getCellSize(), resolution, |
864 |
resolution, provider.getFullName(), |
865 |
TileCacheLibrary.DEFAULT_STRUCTURE, |
866 |
|
867 |
RasterLibrary.pathTileCache, provider.getFileSuffix(), provider |
868 |
.getProjection().getAbrev(), provider.getFileSize()); |
869 |
|
870 |
return struct;
|
871 |
|
872 |
} |
873 |
|
874 |
private void refreshLayerVectorsVisibility(FLayer lyr) { |
875 |
// if (_terrain == null || _viewProjection == null)
|
876 |
// return;
|
877 |
//
|
878 |
// Layer3DProps props3D = getLayer3DProps(lyr);
|
879 |
//
|
880 |
// VectorCacheService cacheService = (VectorCacheService) props3D
|
881 |
// .getCacheService();
|
882 |
// if (cacheService != null) {
|
883 |
// // use VectorCacheService to add features to terrain
|
884 |
// cacheService.refreshFeaturesToTerrain(lyr.isVisible());
|
885 |
// props3D.drawVersion = lyr.getDrawVersion();
|
886 |
// }
|
887 |
|
888 |
} |
889 |
|
890 |
public void layerMoved(FLayers3D parent, FLayer layer, int oldPos, |
891 |
int newPos) {
|
892 |
if (layer instanceof FLayers) { |
893 |
FLayers group = (FLayers) layer; |
894 |
if (newPos > oldPos) {
|
895 |
for (int iChild = group.getLayersCount() - 1; iChild >= 0; iChild--) |
896 |
layerMoved((FLayers3D) group, group.getLayer(iChild), |
897 |
oldPos, newPos); |
898 |
} else {
|
899 |
for (int iChild = 0; iChild < group.getLayersCount(); iChild++) |
900 |
layerMoved((FLayers3D) group, group.getLayer(iChild), |
901 |
oldPos, newPos); |
902 |
} |
903 |
return;
|
904 |
} |
905 |
|
906 |
Layer3DProps props3D = getLayer3DProps(layer); |
907 |
refreshLayerInTerrain(layer, props3D, false);
|
908 |
|
909 |
int type = props3D.getType();
|
910 |
|
911 |
// Now reorder in layer manager only for terrain layer types
|
912 |
if ((type == Layer3DProps.layer3DOSG)
|
913 |
|| ((type == Layer3DProps.layer3DVector))) |
914 |
return;
|
915 |
|
916 |
// Obtain the old position in the layer
|
917 |
Layer terrainLayer = _terrainFLayerMap.get(layer); |
918 |
Vector<Integer> terrainOldPos = null; |
919 |
try {
|
920 |
terrainOldPos = _terrainLayerManager.getOrder(terrainLayer); |
921 |
} catch (LayerManagementException e) {
|
922 |
// TODO Auto-generated catch block
|
923 |
e.printStackTrace(); |
924 |
} |
925 |
|
926 |
int terrainNewPos = 0; |
927 |
// Compute the new position.
|
928 |
SingleLayerIterator lyrIterator = new SingleLayerIterator(layers);
|
929 |
while (lyrIterator.hasNext()) {
|
930 |
FLayer auxLayer = lyrIterator.next(); |
931 |
if (auxLayer == layer)
|
932 |
break;
|
933 |
Layer3DProps auxProps3D = getLayer3DProps(auxLayer); |
934 |
if ((auxProps3D.getType() != Layer3DProps.layer3DOSG)
|
935 |
&& (auxProps3D.getType() != Layer3DProps.layer3DVector)) { |
936 |
terrainNewPos++; |
937 |
} |
938 |
|
939 |
} |
940 |
|
941 |
if ((terrainOldPos == null) || (terrainOldPos.size() == 0)) |
942 |
return;
|
943 |
if (terrainOldPos.get(0) != terrainNewPos) |
944 |
try {
|
945 |
_terrainLayerManager.moveLayer(terrainOldPos.get(0),
|
946 |
terrainNewPos); |
947 |
} catch (LayerManagementException e) {
|
948 |
// TODO Auto-generated catch block
|
949 |
e.printStackTrace(); |
950 |
} |
951 |
//
|
952 |
// System.out.println("En el toc antes era el " + oldPos +
|
953 |
// " y ahora el "
|
954 |
// + newPos);
|
955 |
// System.out.println("En el terrain antes era el " + terrainOldPos
|
956 |
// + " y ahora el " + terrainNewPos);
|
957 |
|
958 |
// PrintDebugLayers();
|
959 |
|
960 |
} |
961 |
|
962 |
public void layerRemoved(FLayers3D parent, FLayer layer) { |
963 |
System.out.println("Removed layer"); |
964 |
|
965 |
// to remove group layers to 3D, just remove recursively child data
|
966 |
// layers
|
967 |
if (layer instanceof FLayers) { |
968 |
FLayers group = (FLayers) layer; |
969 |
for (int iChild = 0; iChild < group.getLayersCount(); iChild++) { |
970 |
layerRemoved((FLayers3D) group, group.getLayer(iChild)); |
971 |
} |
972 |
getLayer3DProps(layer).setHooked(false);
|
973 |
return;
|
974 |
} |
975 |
|
976 |
if (layer instanceof Classifiable) { |
977 |
Classifiable legendLyr = (Classifiable) layer; |
978 |
legendLyr.removeLegendListener((LegendListener) this);
|
979 |
} |
980 |
|
981 |
layer.removeLayerListener((LayerListener) this);
|
982 |
|
983 |
removeLayerToTerrain(layer); |
984 |
|
985 |
// All layers are removed
|
986 |
if (layers.getLayersCount() == 0) { |
987 |
_bEmptyView = true;
|
988 |
} |
989 |
|
990 |
if (getLayer3DProps(layer).getType() == Layer3DProps.layer3DOSG) {
|
991 |
|
992 |
try {
|
993 |
((TerrainViewer) _canvas3d.getOSGViewer()) |
994 |
.removeFeature(getEditionManager(layer)); |
995 |
} catch (NodeException e) {
|
996 |
// TODO Auto-generated catch block
|
997 |
e.printStackTrace(); |
998 |
} |
999 |
|
1000 |
} |
1001 |
|
1002 |
// PrintDebugLayers();
|
1003 |
|
1004 |
} |
1005 |
|
1006 |
public void legendChanged(LegendChangedEvent e) { |
1007 |
if (!_bListenToLegend)
|
1008 |
return;
|
1009 |
if ((e == null) && (!visibilityChange)) { |
1010 |
// find layer whose legend changed
|
1011 |
FLayer found = null;
|
1012 |
SingleLayerIterator lyrIterator = new SingleLayerIterator(layers);
|
1013 |
Layer3DProps props3D = getLayer3DProps(layers); |
1014 |
while (lyrIterator.hasNext()) {
|
1015 |
FLayer lyr = lyrIterator.next(); |
1016 |
if (lyr instanceof FLyrVect |
1017 |
&& props3D.getType() != Layer3DProps.layer3DOSG) { |
1018 |
FLyrVect lyrVect = (FLyrVect) lyr; |
1019 |
System.out
|
1020 |
.println("Changeando la simbologia de la capa vectorial: "
|
1021 |
+ lyrVect); |
1022 |
long newDrawVersion = layers.getDrawVersion();
|
1023 |
Layer3DProps vectProps = getLayer3DProps(lyrVect); |
1024 |
if ((newDrawVersion - props3D.getDrawVersion()) >= 1) { |
1025 |
props3D.setDrawVersion(lyrVect.getDrawVersion()); |
1026 |
// refreshLayerInTerrain(lyrVect, vectProps, true);
|
1027 |
// if layer is vectorized remove and add the layer
|
1028 |
if (vectProps.getType() == Layer3DProps.layer3DVector) {
|
1029 |
removeLayerToTerrain(lyr); |
1030 |
addLayerToTerrain(lyr, true);
|
1031 |
} |
1032 |
// refreshLayerVectorsVisibility(lyrVect);
|
1033 |
_bListenToLegend = false;
|
1034 |
// props3D.VerifyLegend(_terrain.getTerrainName());
|
1035 |
_bListenToLegend = true;
|
1036 |
|
1037 |
} |
1038 |
} |
1039 |
} |
1040 |
|
1041 |
// IWindow f = PluginServices.getMDIManager().getActiveWindow();
|
1042 |
// if (f instanceof BaseView) {
|
1043 |
// BaseView view3D = (BaseView) f;
|
1044 |
// view3D.getTOC().refresh();
|
1045 |
// }
|
1046 |
} |
1047 |
visibilityChange = false;
|
1048 |
|
1049 |
} |
1050 |
|
1051 |
public UpdateDataEvent loadData(RequestDataEvent rde) {
|
1052 |
|
1053 |
if (_terrainLayerMap.size() == 0) |
1054 |
return null; |
1055 |
if (rde == null) |
1056 |
return null; |
1057 |
if (rde.getExtent() == null || rde.getLayer() == null |
1058 |
|| rde.getLayerManager() == null)
|
1059 |
return null; |
1060 |
|
1061 |
String layerID = rde.getLayer().getLayerID();
|
1062 |
FLayer layer = (FLayer) _terrainLayerMap.get(layerID); |
1063 |
if (layer == null) |
1064 |
return null; |
1065 |
if (!layer.isVisible())
|
1066 |
return null; |
1067 |
double minX, minY, width, height;
|
1068 |
|
1069 |
if (_terrain.getCoordinateSystemType() == CoordinateSystemType.PROJECTED) {
|
1070 |
minX = rde.getExtent().xMin(); |
1071 |
minY = rde.getExtent().yMin(); |
1072 |
width = rde.getExtent().xMax() - rde.getExtent().xMin(); |
1073 |
height = rde.getExtent().yMax() - rde.getExtent().yMin(); |
1074 |
|
1075 |
} else {
|
1076 |
minX = Math.toDegrees(rde.getExtent().xMin());
|
1077 |
minY = Math.toDegrees(rde.getExtent().yMin());
|
1078 |
width = Math.toDegrees(rde.getExtent().xMax()
|
1079 |
- rde.getExtent().xMin()); |
1080 |
height = Math.toDegrees(rde.getExtent().yMax()
|
1081 |
- rde.getExtent().yMin()); |
1082 |
} |
1083 |
GeometryManager geoMan = GeometryLocator.getGeometryManager(); |
1084 |
Envelope envelope = null;
|
1085 |
try {
|
1086 |
envelope = geoMan.createEnvelope(Geometry.SUBTYPES.GEOM2D); |
1087 |
envelope.setLowerCorner(geoMan.createPoint(minX, minY, |
1088 |
Geometry.SUBTYPES.GEOM2D)); |
1089 |
envelope.setUpperCorner(geoMan.createPoint(minX + width, minY |
1090 |
+ height, Geometry.SUBTYPES.GEOM2D)); |
1091 |
} catch (CreateGeometryException e) {
|
1092 |
// TODO Auto-generated catch block
|
1093 |
e.printStackTrace(); |
1094 |
} catch (CreateEnvelopeException e) {
|
1095 |
// TODO Auto-generated catch block
|
1096 |
e.printStackTrace(); |
1097 |
} |
1098 |
|
1099 |
// Case of Raster data
|
1100 |
|
1101 |
UpdateDataEvent ude = null;
|
1102 |
|
1103 |
if (rde.getLayer().getLayerType() == Layer.LayerType.TEXTURELAYER)
|
1104 |
ude = loadRasterData(layer, envelope, rde); |
1105 |
|
1106 |
if (rde.getLayer().getLayerType() == Layer.LayerType.VECTORLAYER)
|
1107 |
ude = loadVectorData(layer, envelope, rde); |
1108 |
|
1109 |
if (rde.getLayer().getLayerType() == Layer.LayerType.HEIGHTFIELDLAYER)
|
1110 |
ude = loadElevationData(layer, envelope, rde); |
1111 |
|
1112 |
return ude;
|
1113 |
} |
1114 |
|
1115 |
private UpdateDataEvent loadRasterData(FLayer layer, Envelope envelope,
|
1116 |
RequestDataEvent rde) { |
1117 |
|
1118 |
UpdateDataEvent ude = new UpdateDataEvent();
|
1119 |
ude.copyDataFromRequest(rde); |
1120 |
if (layer instanceof DefaultFLyrRaster) { |
1121 |
DefaultFLyrRaster rLayer = (DefaultFLyrRaster) layer; |
1122 |
|
1123 |
if (rLayer.getDataStore().isTiled()) {
|
1124 |
|
1125 |
rLayer = (DefaultFLyrRaster) layer; |
1126 |
|
1127 |
RasterQuery query = RasterLocator.getManager().createQuery(); |
1128 |
|
1129 |
org.gvsig.fmap.dal.coverage.datastruct.Extent extent = RasterLocator |
1130 |
.getManager() |
1131 |
.getDataStructFactory() |
1132 |
.createExtent(envelope.getLowerCorner().getX(), |
1133 |
envelope.getUpperCorner().getY(), |
1134 |
envelope.getUpperCorner().getX(), |
1135 |
envelope.getLowerCorner().getY()); |
1136 |
|
1137 |
query.setTileParameters(rde.getTileLevel(), rde.getTileX(), |
1138 |
rde.getTileY(), extent, null);
|
1139 |
|
1140 |
try {
|
1141 |
Object[] result = rLayer.getDataStore().queryArray(query); |
1142 |
Buffer rBuff = (Buffer) result[0]; |
1143 |
|
1144 |
Buffer transparencyBuffer = (result != null && result.length > 1) ? (Buffer) result[1] |
1145 |
: null;
|
1146 |
|
1147 |
ColorTable tileColorTable = (result != null && result.length > 2) ? (ColorTable) result[2] |
1148 |
: null;
|
1149 |
int addAlpha = 0; |
1150 |
|
1151 |
Transparency lastTransparency = rLayer.getDataStore()
|
1152 |
.getRender().getLastTransparency(); |
1153 |
|
1154 |
lastTransparency.setAlphaBand(transparencyBuffer); |
1155 |
|
1156 |
addTileColorTable(tileColorTable, rLayer); |
1157 |
|
1158 |
Buffer procBuffer = processBufferFilters(rBuff, rLayer);
|
1159 |
|
1160 |
if (lastTransparency.getAlphaBand() != null) |
1161 |
addAlpha = 1;
|
1162 |
|
1163 |
// Si el numero de bandas es mayor que 3 (RGB) no se pueden
|
1164 |
// dibujar todas
|
1165 |
int numBands = rLayer.getDataStore().getBandCount();
|
1166 |
|
1167 |
if (numBands > (maxBands))
|
1168 |
numBands = maxBands; |
1169 |
|
1170 |
ColorInterpretation cInt = rLayer.getDataStore() |
1171 |
.getColorInterpretation(); |
1172 |
|
1173 |
ColorTable colorTable = rLayer.getDataStore() |
1174 |
.getColorTable(); |
1175 |
|
1176 |
int rgba[] = { 0, 1, 2, 3 }; |
1177 |
|
1178 |
rgba = setBandsInColors(cInt); |
1179 |
|
1180 |
int pixelFormat = 0; |
1181 |
boolean isPalette = (cInt
|
1182 |
.getBand(ColorInterpretation.PAL_BAND) != -1);
|
1183 |
|
1184 |
if (isPalette) {
|
1185 |
|
1186 |
pixelFormat = org.gvsig.osgvp.core.osg.Image.PixelFormat.GL_RGBA; |
1187 |
|
1188 |
} |
1189 |
|
1190 |
else
|
1191 |
pixelFormat = convertPixelFormat(numBands + addAlpha); |
1192 |
|
1193 |
switch (procBuffer.getDataType()) {
|
1194 |
case Buffer.TYPE_BYTE: |
1195 |
|
1196 |
byte[] byteBuffer = null; |
1197 |
if (isPalette) {
|
1198 |
byteBuffer = buildByteBufferPalette(ude, rBuff, |
1199 |
colorTable, transparencyBuffer); |
1200 |
ude.setRasterData(byteBuffer, |
1201 |
procBuffer.getWidth(), |
1202 |
procBuffer.getHeight(), 4, pixelFormat,
|
1203 |
Image.DataType.GL_UNSIGNED_BYTE);
|
1204 |
} else {
|
1205 |
byteBuffer = buildByteBuffer(ude, procBuffer, |
1206 |
lastTransparency.getAlphaBand(), numBands, |
1207 |
rgba); |
1208 |
ude.setRasterData(byteBuffer, |
1209 |
procBuffer.getWidth(), |
1210 |
procBuffer.getHeight(), |
1211 |
numBands + addAlpha, pixelFormat, |
1212 |
Image.DataType.GL_UNSIGNED_BYTE);
|
1213 |
} |
1214 |
break;
|
1215 |
case Buffer.TYPE_SHORT: |
1216 |
ude.setRasterData( |
1217 |
buildShortBuffer(ude, rBuff, |
1218 |
transparencyBuffer, numBands, rgba), |
1219 |
rBuff.getWidth(), rBuff.getHeight(), numBands, |
1220 |
pixelFormat, Image.DataType.GL_SHORT);
|
1221 |
break;
|
1222 |
case Buffer.TYPE_USHORT: |
1223 |
ude.setRasterData( |
1224 |
buildShortBuffer(ude, rBuff, |
1225 |
transparencyBuffer, numBands, rgba), |
1226 |
rBuff.getWidth(), rBuff.getHeight(), numBands, |
1227 |
pixelFormat, Image.DataType.GL_UNSIGNED_SHORT);
|
1228 |
break;
|
1229 |
case Buffer.TYPE_INT: |
1230 |
ude.setRasterData( |
1231 |
buildIntBuffer(ude, rBuff, transparencyBuffer, |
1232 |
numBands, rgba), rBuff.getWidth(), |
1233 |
rBuff.getHeight(), numBands, pixelFormat, |
1234 |
Image.DataType.GL_INT);
|
1235 |
break;
|
1236 |
case Buffer.TYPE_FLOAT: |
1237 |
ude.setRasterData( |
1238 |
buildFloatBuffer(ude, rBuff, |
1239 |
transparencyBuffer, numBands, rgba), |
1240 |
rBuff.getWidth(), rBuff.getHeight(), numBands |
1241 |
+ addAlpha, pixelFormat, |
1242 |
Image.DataType.GL_FLOAT);
|
1243 |
break;
|
1244 |
case Buffer.TYPE_DOUBLE: |
1245 |
ude.setRasterData( |
1246 |
buildDoubleBuffer(ude, rBuff, |
1247 |
transparencyBuffer, numBands, rgba), |
1248 |
rBuff.getWidth(), rBuff.getHeight(), numBands, |
1249 |
pixelFormat, Image.DataType.GL_DOUBLE);
|
1250 |
break;
|
1251 |
} |
1252 |
|
1253 |
// ude.setRasterData(getLayerDrawImage(layer, envelope));
|
1254 |
|
1255 |
} catch (ProcessInterruptedException e) {
|
1256 |
// TODO Auto-generated catch block
|
1257 |
e.printStackTrace(); |
1258 |
} catch (RasterDriverException e) {
|
1259 |
System.out.println("QueryArray failed"); |
1260 |
// e.printStackTrace();
|
1261 |
} catch (InvalidSetViewException e) {
|
1262 |
// TODO Auto-generated catch block
|
1263 |
e.printStackTrace(); |
1264 |
} catch (NullPointerException e) { |
1265 |
// ude.setFailData();
|
1266 |
System.out.println("Problem getting the tile. NullPointer"); |
1267 |
} |
1268 |
|
1269 |
} |
1270 |
// Not tiled raster
|
1271 |
else {
|
1272 |
ude.setRasterData(getLayerDrawImage(layer, envelope)); |
1273 |
} |
1274 |
|
1275 |
} |
1276 |
|
1277 |
// Vectorial rasterized
|
1278 |
else if (layer instanceof FLyrVect) { |
1279 |
ude.setRasterData(getLayerDrawImage(layer, envelope)); |
1280 |
} |
1281 |
// unrecognized layer type
|
1282 |
else {
|
1283 |
ude.setFailData(); |
1284 |
} |
1285 |
|
1286 |
// System.out.println("Returning UDE");
|
1287 |
|
1288 |
return ude;
|
1289 |
} |
1290 |
|
1291 |
private void addTileColorTable(ColorTable tileColorTable, |
1292 |
DefaultFLyrRaster rLayer) { |
1293 |
if (tileColorTable == null) |
1294 |
return;
|
1295 |
|
1296 |
else {
|
1297 |
RasterFilterList filterList = rLayer.getDataStore().getRender() |
1298 |
.getFilterList(); |
1299 |
if (filterList.getFilterClassByID("ColorTable") == null) { |
1300 |
try {
|
1301 |
RasterFilterListManager colorTableManager = filterList |
1302 |
.getManagerByID("ColorTable");
|
1303 |
Params params = filterList.createEmptyFilterParams(); |
1304 |
params.setParam("colorTable", tileColorTable);
|
1305 |
colorTableManager.addFilter(params); |
1306 |
} catch (FilterManagerException e) {
|
1307 |
e.printStackTrace(); |
1308 |
} catch (FilterTypeException e) {
|
1309 |
e.printStackTrace(); |
1310 |
} |
1311 |
} |
1312 |
} |
1313 |
} |
1314 |
|
1315 |
private Buffer processBufferFilters(Buffer rBuffer, DefaultFLyrRaster rLayer) { |
1316 |
|
1317 |
RasterDataStore store = rLayer.getDataStore(); |
1318 |
Transparency transparency = rLayer.getDataStore().getRender()
|
1319 |
.getLastTransparency(); |
1320 |
|
1321 |
if (rLayer.getDataStore() != null) { |
1322 |
// Asignamos los datos al objeto transparencia antes de aplicar la
|
1323 |
// pila de filtros para que el valor NoData sea efectivo
|
1324 |
if (store.getTransparency().getNoData().isNoDataTransparent()
|
1325 |
|| transparency.existAlphaBand()) |
1326 |
transparency.setDataBuffer(rBuffer); |
1327 |
else {
|
1328 |
transparency.setDataBuffer(null);
|
1329 |
} |
1330 |
transparency.activeTransparency(); |
1331 |
} else
|
1332 |
return null; |
1333 |
|
1334 |
// Aplicamos los filtros
|
1335 |
|
1336 |
Grid grid = new GridImpl(rBuffer, store, true); |
1337 |
RasterFilterList filterList = rLayer.getRender().getFilterList(); |
1338 |
if (filterList != null) { |
1339 |
filterList.addEnvParam("Transparency", transparency);
|
1340 |
grid.setFilterList(filterList); |
1341 |
ColorTable cTable = grid.getPalette(); |
1342 |
try {
|
1343 |
grid.applyFilters(); |
1344 |
} catch (ProcessInterruptedException e) {
|
1345 |
// TODO Auto-generated catch block
|
1346 |
e.printStackTrace(); |
1347 |
} |
1348 |
} |
1349 |
|
1350 |
// Si la lista de filtros genera bandas de transparencia se mezclan con
|
1351 |
// la actual
|
1352 |
if (grid.getFilterList().getAlphaBand() != null) { |
1353 |
Buffer t = grid.getFilterList().getAlphaBand();
|
1354 |
if (transparency.getAlphaBand() != null) |
1355 |
t = RasterLocator |
1356 |
.getManager() |
1357 |
.getColorConversion() |
1358 |
.mergeTransparencyBuffers(t, |
1359 |
transparency.getAlphaBand()); |
1360 |
transparency.setAlphaBand(t); |
1361 |
transparency.activeTransparency(); |
1362 |
} |
1363 |
|
1364 |
return grid.getRasterBuf();
|
1365 |
|
1366 |
} |
1367 |
|
1368 |
private UpdateDataEvent loadVectorData(FLayer layer, Envelope envelope,
|
1369 |
RequestDataEvent rde) { |
1370 |
|
1371 |
UpdateDataEvent ude = new UpdateDataEvent();
|
1372 |
ude.copyDataFromRequest(rde); |
1373 |
|
1374 |
Group g= new Group(); |
1375 |
Layer3DProps layerprops = getLayer3DProps(layer); |
1376 |
// Hack for polylines and polygons to only render them rasterized
|
1377 |
// till gvSIG architects solve geometries problem
|
1378 |
|
1379 |
|
1380 |
//
|
1381 |
// try {
|
1382 |
// if (((FLyrVect) layer).getShapeType()!=1 &&((FLyrVect) layer).getShapeType()!=7)
|
1383 |
// {
|
1384 |
// removeLayerToTerrain(layer);
|
1385 |
// layerprops.setType(Layer3DPropsImpl.layer3DImage);
|
1386 |
// addLayerToTerrain(layer, true);
|
1387 |
// return null;
|
1388 |
// }
|
1389 |
// } catch (ReadException e1) {
|
1390 |
// // TODO Auto-generated catch block
|
1391 |
// e1.printStackTrace();
|
1392 |
//
|
1393 |
//
|
1394 |
// }// End hack
|
1395 |
|
1396 |
|
1397 |
|
1398 |
// Set ViewPort
|
1399 |
ViewPort vp = getViewPort(); |
1400 |
vp.setEnvelope(envelope); // the real extent of the tile
|
1401 |
vp.setAdjustable(false);
|
1402 |
vp.setImageSize(new Dimension(256, 256)); |
1403 |
vp.setDist1pixel(0.000000001);
|
1404 |
ILegend legend = ((FLyrVect) layer).getLegend(); |
1405 |
ISymbol[] symbolList = fillSymbolList(legend);
|
1406 |
for (int i = 0; i < symbolList.length; i++) { |
1407 |
I3DSymbol sy = (I3DSymbol) symbolList[i]; |
1408 |
sy.setCoordinateSystemType(_terrain.getCoordinateSystemType()); |
1409 |
if (layerprops.isZEnable() == false) |
1410 |
sy.setFixedHeight(layerprops.getHeight()); |
1411 |
} |
1412 |
|
1413 |
double scale = 0.5 * (layer.getMaxScale() + layer.getMinScale()); |
1414 |
|
1415 |
DataStore ds = ((SingleLayer) layer).getDataStore(); |
1416 |
|
1417 |
if (((I3DSymbol) symbolList[0]).getGeometry().getSize() == 0 |
1418 |
|| ds.getProviderName() == "NetCDFVectorial"
|
1419 |
|| layerprops.isGeometryDirty() == true) {
|
1420 |
try {
|
1421 |
|
1422 |
for(int i=0;i<symbolList.length;i++) |
1423 |
{ |
1424 |
((I3DSymbol)(symbolList[i])).resetGeometry(); |
1425 |
|
1426 |
|
1427 |
|
1428 |
} |
1429 |
layer.draw(null, null, getViewPort(), new MyCancel(), scale); |
1430 |
// setGeometryDirty to false to avoid unnecessary repaints
|
1431 |
layerprops.setDirtyGeometry(false);
|
1432 |
} catch (ReadException e) {
|
1433 |
// TODO Auto-generated catch block
|
1434 |
e.printStackTrace(); |
1435 |
} |
1436 |
} |
1437 |
// OSG Layers
|
1438 |
Node n = null;
|
1439 |
|
1440 |
if (ds.getProviderName() == "OSG") { |
1441 |
try {
|
1442 |
n = (Node) ds.invokeDynMethod("getNode", null); |
1443 |
g.addChild(n); |
1444 |
} catch (DynMethodException e) {
|
1445 |
// TODO Auto-generated catch block
|
1446 |
e.printStackTrace(); |
1447 |
} catch (NodeException e) {
|
1448 |
// TODO Auto-generated catch block
|
1449 |
e.printStackTrace(); |
1450 |
} |
1451 |
System.out.println("OSG Layer added"); |
1452 |
// Change properties to OSG layer
|
1453 |
layerprops.setType(Layer3DProps.layer3DOSG); |
1454 |
} |
1455 |
// Vectorial layers
|
1456 |
else {
|
1457 |
|
1458 |
for(int i=0;i<symbolList.length;i++) |
1459 |
{ |
1460 |
n=((I3DSymbol) symbolList[i]).getRenderNode(); |
1461 |
|
1462 |
|
1463 |
try {
|
1464 |
g.addChild(n); |
1465 |
} catch (NodeException e) {
|
1466 |
// TODO Auto-generated catch block
|
1467 |
e.printStackTrace(); |
1468 |
} |
1469 |
} |
1470 |
|
1471 |
} |
1472 |
ude.setVectorData(g); |
1473 |
return ude;
|
1474 |
} |
1475 |
|
1476 |
|
1477 |
|
1478 |
private ISymbol[] fillSymbolList(ILegend legend) { |
1479 |
ISymbol[] symbolList = null; |
1480 |
if (legend instanceof ISingleSymbolLegend) { |
1481 |
symbolList = new ISymbol[1]; |
1482 |
I3DSymbol sy = (I3DSymbol) ((ISingleSymbolLegend) (legend)) |
1483 |
.getDefaultSymbol(); |
1484 |
|
1485 |
|
1486 |
symbolList[0] = sy;
|
1487 |
} |
1488 |
if (legend instanceof AbstractIntervalLegend) |
1489 |
symbolList = ((AbstractIntervalLegend) (legend)).getSymbols(); |
1490 |
if (legend instanceof VectorialUniqueValueLegend) { |
1491 |
((VectorialUniqueValueLegend) (legend)) |
1492 |
.setDomain("project.document.view3d");
|
1493 |
symbolList = ((VectorialUniqueValueLegend) (legend)).getSymbols(); |
1494 |
} |
1495 |
return symbolList;
|
1496 |
|
1497 |
} |
1498 |
|
1499 |
|
1500 |
// private Node buildVectors(I3DSymbol symbol) {
|
1501 |
// Node n = null;
|
1502 |
//
|
1503 |
// ISymbol3D sym = null;
|
1504 |
// try {
|
1505 |
// sym = Symbol3DFactory.getSymbol3D(symbol);
|
1506 |
// } catch (NodeException e) {
|
1507 |
// // TODO Auto-generated catch block
|
1508 |
// e.printStackTrace();
|
1509 |
// }
|
1510 |
// // sm.setPointSize((float) sy.getSize());
|
1511 |
// n = sym.buildSceneGraph(symbol.getGeometry());
|
1512 |
// return n;
|
1513 |
// }
|
1514 |
|
1515 |
private UpdateDataEvent loadElevationData(FLayer layer, Envelope envelope,
|
1516 |
RequestDataEvent rde) { |
1517 |
|
1518 |
UpdateDataEvent ude = new UpdateDataEvent();
|
1519 |
ude.copyDataFromRequest(rde); |
1520 |
|
1521 |
if (layer instanceof DefaultFLyrRaster) { |
1522 |
DefaultFLyrRaster rLayer = (DefaultFLyrRaster) layer; |
1523 |
if (rLayer.getDataStore().isTiled()) {
|
1524 |
|
1525 |
rLayer = (DefaultFLyrRaster) layer; |
1526 |
// boolean exists = _cachedLayers.containsKey(rLayer);
|
1527 |
//
|
1528 |
// if (!exists) {
|
1529 |
//
|
1530 |
// _cachedLayers.put(rLayer, getCacheStruct(rLayer));
|
1531 |
//
|
1532 |
// }
|
1533 |
//
|
1534 |
// CacheStruct cacheStruct = _cachedLayers.get(rLayer);
|
1535 |
|
1536 |
RasterQuery query = RasterLocator.getManager().createQuery(); |
1537 |
|
1538 |
org.gvsig.fmap.dal.coverage.datastruct.Extent extent = RasterLocator |
1539 |
.getManager() |
1540 |
.getDataStructFactory() |
1541 |
.createExtent(envelope.getLowerCorner().getX(), |
1542 |
envelope.getUpperCorner().getY(), |
1543 |
envelope.getUpperCorner().getX(), |
1544 |
envelope.getLowerCorner().getY()); |
1545 |
|
1546 |
query.setTileParameters(rde.getTileLevel(), rde.getTileX(), |
1547 |
rde.getTileY(), extent, null);
|
1548 |
|
1549 |
// query.setAreaOfInterest(extent, 512, 512);
|
1550 |
|
1551 |
// System.out.println("Tile Parameters:");
|
1552 |
// System.out.println("TileLevel: " + rde.getTileLevel());
|
1553 |
// System.out.println("TileX = " + rde.getTileX());
|
1554 |
// System.out.println("TileY = " + rde.getTileY());
|
1555 |
// System.out.println("Extent = " + extent.getULX() + " "
|
1556 |
// + extent.getULY() + " " + extent.getLRX() + " "
|
1557 |
// + extent.getLRY());
|
1558 |
|
1559 |
try {
|
1560 |
Object[] result = rLayer.getDataStore().queryArray(query); |
1561 |
Buffer rBuff = (Buffer) result[0]; |
1562 |
Buffer transparencyBuffer;
|
1563 |
|
1564 |
if (result.length < 2) |
1565 |
transparencyBuffer = null;
|
1566 |
else
|
1567 |
transparencyBuffer = (Buffer) result[1]; |
1568 |
|
1569 |
int numBands = rBuff.getBandCount();
|
1570 |
if (transparencyBuffer != null) { |
1571 |
|
1572 |
// System.out
|
1573 |
// .println("Tengo Transparency buffer con "
|
1574 |
// + transparencyBuffer.getBandCount()
|
1575 |
// + " bandas");
|
1576 |
numBands++; |
1577 |
|
1578 |
} |
1579 |
|
1580 |
// System.out.println("Tile ancho: " + rBuff.getWidth()
|
1581 |
// + " alto: " + rBuff.getHeight()
|
1582 |
// + " bandas totales incluyendo alpha (si tiene): "
|
1583 |
// + numBands);
|
1584 |
|
1585 |
float[] data = new float[(rBuff.getWidth() * rBuff |
1586 |
.getHeight())]; |
1587 |
|
1588 |
int pixelFormat = convertPixelFormat(numBands);
|
1589 |
|
1590 |
// K hay que setearlo en el dialogo
|
1591 |
int cont = 0; |
1592 |
|
1593 |
int k = getLayer3DProps(rLayer).getElevationBand();
|
1594 |
|
1595 |
for (int i = rBuff.getWidth() - 1; i >= 0; i--) { |
1596 |
// Vertical Flip needed
|
1597 |
for (int j = 0; j < rBuff.getHeight(); j++) { |
1598 |
|
1599 |
switch (rBuff.getDataType()) {
|
1600 |
case Buffer.TYPE_BYTE: |
1601 |
data[cont] = (float) (rBuff
|
1602 |
.getElemByte(i, j, k)); |
1603 |
cont++; |
1604 |
break;
|
1605 |
case Buffer.TYPE_DOUBLE: |
1606 |
data[cont] = (float) (Math.round(rBuff |
1607 |
.getElemDouble(i, j, k))); |
1608 |
cont++; |
1609 |
break;
|
1610 |
case Buffer.TYPE_FLOAT: |
1611 |
data[cont] = (float) (Math.round(rBuff |
1612 |
.getElemFloat(i, j, k))); |
1613 |
cont++; |
1614 |
break;
|
1615 |
case Buffer.TYPE_INT: |
1616 |
data[cont] = (float) (rBuff.getElemInt(i, j, k) & 0xffffffff); |
1617 |
cont++; |
1618 |
break;
|
1619 |
case Buffer.TYPE_SHORT: |
1620 |
case Buffer.TYPE_USHORT: |
1621 |
data[cont] = (float) (rBuff.getElemShort(i, j,
|
1622 |
k) & 0xffff);
|
1623 |
cont++; |
1624 |
break;
|
1625 |
} |
1626 |
|
1627 |
} |
1628 |
|
1629 |
} |
1630 |
ude.setHeightfieldData(data, rBuff.getWidth(), |
1631 |
rBuff.getHeight()); |
1632 |
|
1633 |
data = null;
|
1634 |
result = null;
|
1635 |
// ude.setRasterData(getLayerDrawImage(layer, envelope));
|
1636 |
|
1637 |
} catch (ProcessInterruptedException e) {
|
1638 |
// TODO Auto-generated catch block
|
1639 |
e.printStackTrace(); |
1640 |
} catch (RasterDriverException e) {
|
1641 |
e.printStackTrace(); |
1642 |
} catch (InvalidSetViewException e) {
|
1643 |
// TODO Auto-generated catch block
|
1644 |
e.printStackTrace(); |
1645 |
} catch (NullPointerException e) { |
1646 |
// ude.setFailData();
|
1647 |
System.out.println("Problem getting the tile"); |
1648 |
} |
1649 |
|
1650 |
} |
1651 |
// No cache
|
1652 |
else {
|
1653 |
ude.setHeightfieldData(getLayerDrawImage(layer, envelope)); |
1654 |
} |
1655 |
|
1656 |
} |
1657 |
// unrecognized layer type
|
1658 |
else {
|
1659 |
ude.setFailData(); |
1660 |
} |
1661 |
|
1662 |
return ude;
|
1663 |
|
1664 |
} |
1665 |
|
1666 |
protected byte[] buildByteBuffer(UpdateDataEvent ude, Buffer rBuff, |
1667 |
Buffer transparencyBuffer, int numBands, int[] rgba) { |
1668 |
|
1669 |
int cont = 0; |
1670 |
int colorBands = numBands;
|
1671 |
|
1672 |
if (transparencyBuffer != null) { |
1673 |
// colorBands--;
|
1674 |
numBands = numBands + 1;
|
1675 |
} |
1676 |
|
1677 |
byte[] data = new byte[rBuff.getWidth() * rBuff.getHeight() * numBands]; |
1678 |
|
1679 |
for (int i = 0; i < rBuff.getWidth(); i++) { |
1680 |
|
1681 |
for (int j = 0; j < rBuff.getHeight(); j++) { |
1682 |
|
1683 |
for (int k = 0; k < colorBands; k++) { |
1684 |
data[cont] = (byte) rBuff.getElemByte(i, j, rgba[k]);
|
1685 |
// if(data[cont]!=-1)
|
1686 |
// System.out.println("Banda: " + k + " " + data[cont]);
|
1687 |
cont++; |
1688 |
|
1689 |
} |
1690 |
if (transparencyBuffer != null) { |
1691 |
// if (transparencyBuffer.getElemByte(i, j, 0) == 0)
|
1692 |
// data[cont] = (byte) 0;
|
1693 |
// else
|
1694 |
// data[cont] = (byte) 255;
|
1695 |
data[cont] = transparencyBuffer.getElemByte(i, j, 0);
|
1696 |
cont++; |
1697 |
|
1698 |
} |
1699 |
|
1700 |
} |
1701 |
} |
1702 |
|
1703 |
return data;
|
1704 |
} |
1705 |
|
1706 |
protected byte[] buildByteBufferPalette(UpdateDataEvent ude, Buffer rBuff, |
1707 |
ColorTable colorTable, Buffer transparencyBuffer) {
|
1708 |
|
1709 |
int cont = 0; |
1710 |
|
1711 |
byte[] data = new byte[rBuff.getWidth() * rBuff.getHeight() * 4]; |
1712 |
|
1713 |
for (int i = 0; i < rBuff.getWidth(); i++) { |
1714 |
|
1715 |
for (int j = 0; j < rBuff.getHeight(); j++) { |
1716 |
|
1717 |
byte index = rBuff.getElemByte(i, j, 0); |
1718 |
|
1719 |
byte[] rgba = colorTable.getRGBAByBand((double) (index & 0xff)); |
1720 |
|
1721 |
for (int k = 0; k < 4; k++) { |
1722 |
data[cont] = rgba[k]; |
1723 |
if (k == 3 && transparencyBuffer != null) |
1724 |
data[cont] = transparencyBuffer.getElemByte(i, j, 0);
|
1725 |
cont++; |
1726 |
} |
1727 |
} |
1728 |
} |
1729 |
|
1730 |
return data;
|
1731 |
} |
1732 |
|
1733 |
protected short[] buildShortBuffer(UpdateDataEvent ude, Buffer rBuff, |
1734 |
Buffer transparencyBuffer, int numBands, int[] rgba) { |
1735 |
int cont = 0; |
1736 |
int colorBands = numBands;
|
1737 |
|
1738 |
if (transparencyBuffer != null) { |
1739 |
// colorBands--;
|
1740 |
numBands = numBands + 1;
|
1741 |
} |
1742 |
|
1743 |
short[] data = new short[rBuff.getWidth() * rBuff.getHeight() |
1744 |
* numBands]; |
1745 |
|
1746 |
for (int i = 0; i < rBuff.getWidth(); i++) { |
1747 |
|
1748 |
for (int j = 0; j < rBuff.getHeight(); j++) { |
1749 |
|
1750 |
for (int k = 0; k < colorBands; k++) { |
1751 |
// En lugar de k se deben usar las bandas asociadas al
|
1752 |
// componente
|
1753 |
data[cont] = (short) rBuff.getElemShort(i, j, rgba[k]);
|
1754 |
cont++; |
1755 |
|
1756 |
} |
1757 |
if (transparencyBuffer != null) { |
1758 |
// if (transparencyBuffer.getElemByte(i, j, 0) == 0)
|
1759 |
// data[cont] = (byte) 0;
|
1760 |
// else
|
1761 |
// data[cont] = (byte) 255;
|
1762 |
data[cont] = transparencyBuffer.getElemShort(i, j, 0);
|
1763 |
|
1764 |
cont++; |
1765 |
|
1766 |
} |
1767 |
} |
1768 |
} |
1769 |
|
1770 |
return data;
|
1771 |
} |
1772 |
|
1773 |
protected int[] buildIntBuffer(UpdateDataEvent ude, Buffer rBuff, |
1774 |
Buffer transparencyBuffer, int numBands, int[] rgba) { |
1775 |
int cont = 0; |
1776 |
int colorBands = numBands;
|
1777 |
|
1778 |
if (transparencyBuffer != null) { |
1779 |
// colorBands--;
|
1780 |
numBands = numBands + 1;
|
1781 |
} |
1782 |
|
1783 |
int[] data = new int[rBuff.getWidth() * rBuff.getHeight() * numBands]; |
1784 |
|
1785 |
for (int i = 0; i < rBuff.getWidth(); i++) { |
1786 |
|
1787 |
for (int j = 0; j < rBuff.getHeight(); j++) { |
1788 |
|
1789 |
for (int k = 0; k < colorBands; k++) { |
1790 |
// En lugar de k se deben usar las bandas asociadas al
|
1791 |
// componente
|
1792 |
data[cont] = rBuff.getElemInt(i, j, rgba[k]); |
1793 |
cont++; |
1794 |
|
1795 |
} |
1796 |
if (transparencyBuffer != null) { |
1797 |
// if (transparencyBuffer.getElemByte(i, j, 0) == 0)
|
1798 |
// data[cont] = (byte) 0;
|
1799 |
// else
|
1800 |
// data[cont] = (byte) 255;
|
1801 |
data[cont] = transparencyBuffer.getElemInt(i, j, 0);
|
1802 |
|
1803 |
cont++; |
1804 |
|
1805 |
} |
1806 |
} |
1807 |
} |
1808 |
|
1809 |
return data;
|
1810 |
} |
1811 |
|
1812 |
protected float[] buildFloatBuffer(UpdateDataEvent ude, Buffer rBuff, |
1813 |
Buffer transparencyBuffer, int numBands, int[] rgba) { |
1814 |
|
1815 |
int cont = 0; |
1816 |
int colorBands = numBands;
|
1817 |
|
1818 |
if (transparencyBuffer != null) { |
1819 |
// colorBands--;
|
1820 |
numBands = numBands + 1;
|
1821 |
} |
1822 |
|
1823 |
float[] data = new float[rBuff.getWidth() * rBuff.getHeight() |
1824 |
* numBands]; |
1825 |
|
1826 |
for (int i = 0; i < rBuff.getWidth(); i++) { |
1827 |
|
1828 |
for (int j = 0; j < rBuff.getHeight(); j++) { |
1829 |
|
1830 |
for (int k = 0; k < colorBands; k++) { |
1831 |
// En lugar de k se deben usar las bandas asociadas al
|
1832 |
// componente
|
1833 |
data[cont] = rBuff.getElemFloat(i, j, rgba[k]); |
1834 |
cont++; |
1835 |
|
1836 |
} |
1837 |
if (transparencyBuffer != null) { |
1838 |
// if (transparencyBuffer.getElemByte(i, j, 0) == 0)
|
1839 |
// data[cont] = (byte) 0;
|
1840 |
// else
|
1841 |
// data[cont] = (byte) 255;
|
1842 |
data[cont] = transparencyBuffer.getElemFloat(i, j, 0);
|
1843 |
|
1844 |
cont++; |
1845 |
|
1846 |
} |
1847 |
} |
1848 |
} |
1849 |
|
1850 |
return data;
|
1851 |
} |
1852 |
|
1853 |
protected double[] buildDoubleBuffer(UpdateDataEvent ude, Buffer rBuff, |
1854 |
Buffer transparencyBuffer, int numBands, int[] rgba) { |
1855 |
int cont = 0; |
1856 |
int colorBands = numBands;
|
1857 |
|
1858 |
if (transparencyBuffer != null) { |
1859 |
// colorBands--;
|
1860 |
numBands = numBands + 1;
|
1861 |
} |
1862 |
|
1863 |
double[] data = new double[rBuff.getWidth() * rBuff.getHeight() |
1864 |
* numBands]; |
1865 |
|
1866 |
for (int i = 0; i < rBuff.getWidth(); i++) { |
1867 |
|
1868 |
for (int j = 0; j < rBuff.getHeight(); j++) { |
1869 |
|
1870 |
for (int k = 0; k < colorBands; k++) { |
1871 |
// En lugar de k se deben usar las bandas asociadas al
|
1872 |
// componente
|
1873 |
data[cont] = rBuff.getElemDouble(i, j, rgba[k]); |
1874 |
cont++; |
1875 |
|
1876 |
} |
1877 |
if (transparencyBuffer != null) { |
1878 |
// if (transparencyBuffer.getElemByte(i, j, 0) == 0)
|
1879 |
// data[cont] = (byte) 0;
|
1880 |
// else
|
1881 |
// data[cont] = (byte) 255;
|
1882 |
data[cont] = transparencyBuffer.getElemDouble(i, j, 0);
|
1883 |
|
1884 |
cont++; |
1885 |
|
1886 |
} |
1887 |
} |
1888 |
} |
1889 |
|
1890 |
return data;
|
1891 |
} |
1892 |
|
1893 |
protected int convertPixelFormat(int type) { |
1894 |
|
1895 |
switch (type) {
|
1896 |
|
1897 |
case 1: |
1898 |
return org.gvsig.osgvp.core.osg.Image.PixelFormat.GL_LUMINANCE;
|
1899 |
|
1900 |
case 2: |
1901 |
return org.gvsig.osgvp.core.osg.Image.PixelFormat.GL_LUMINANCE_ALPHA;
|
1902 |
|
1903 |
case 3: |
1904 |
return org.gvsig.osgvp.core.osg.Image.PixelFormat.GL_RGB;
|
1905 |
|
1906 |
case 4: |
1907 |
return org.gvsig.osgvp.core.osg.Image.PixelFormat.GL_RGBA;
|
1908 |
|
1909 |
} |
1910 |
|
1911 |
return org.gvsig.osgvp.core.osg.Image.PixelFormat.GL_COLOR_INDEX;
|
1912 |
|
1913 |
} |
1914 |
|
1915 |
protected int[] setBandsInColors(ColorInterpretation cInt) { |
1916 |
|
1917 |
int rgba[] = new int[4]; |
1918 |
|
1919 |
rgba[0] = cInt.getBand(ColorInterpretation.RED_BAND);
|
1920 |
if (rgba[0] == -1) |
1921 |
rgba[0] = 0; |
1922 |
rgba[1] = cInt.getBand(ColorInterpretation.GREEN_BAND);
|
1923 |
if (rgba[1] == -1) |
1924 |
rgba[1] = 1; |
1925 |
rgba[2] = cInt.getBand(ColorInterpretation.BLUE_BAND);
|
1926 |
if (rgba[2] == -1) |
1927 |
rgba[2] = 2; |
1928 |
rgba[3] = cInt.getBand(ColorInterpretation.ALPHA_BAND);
|
1929 |
if (rgba[3] == -1) |
1930 |
rgba[3] = 3; |
1931 |
|
1932 |
return rgba;
|
1933 |
|
1934 |
} |
1935 |
|
1936 |
protected class MyCancel implements Cancellable { |
1937 |
private boolean cancel = false; |
1938 |
|
1939 |
public MyCancel() {
|
1940 |
} |
1941 |
|
1942 |
public void setCanceled(boolean canceled) { |
1943 |
cancel = canceled; |
1944 |
} |
1945 |
|
1946 |
public boolean isCanceled() { |
1947 |
return cancel;
|
1948 |
} |
1949 |
} |
1950 |
|
1951 |
private BufferedImage getLayerDrawImage(FLayer layer, Envelope envelope) { |
1952 |
|
1953 |
int size = 256; |
1954 |
BufferedImage image = new BufferedImage(size, size, |
1955 |
BufferedImage.TYPE_4BYTE_ABGR);
|
1956 |
|
1957 |
ViewPort vp = new ViewPort(_viewProjection);
|
1958 |
vp.setEnvelope(envelope); // the real extent of the tile
|
1959 |
|
1960 |
vp.setAdjustable(false);
|
1961 |
vp.setImageSize(new Dimension(size, size)); |
1962 |
vp.setDist1pixel(0.000000001);
|
1963 |
|
1964 |
Graphics2D graphics = image.createGraphics();
|
1965 |
Color backgColor = new Color(255, 255, 255, 0); // transparent |
1966 |
// background
|
1967 |
graphics.setColor(backgColor); |
1968 |
graphics.fillRect(0, 0, size, size); |
1969 |
|
1970 |
double scale = 0.5 * (layer.getMaxScale() + layer.getMinScale()); |
1971 |
|
1972 |
try {
|
1973 |
layer.draw(image, graphics, vp, new MyCancel(), scale);
|
1974 |
|
1975 |
} catch (Exception e) { |
1976 |
return null; |
1977 |
} |
1978 |
|
1979 |
return image;
|
1980 |
|
1981 |
} |
1982 |
|
1983 |
public void nameChanged(LayerEvent e) { |
1984 |
System.out.println("Name change"); |
1985 |
|
1986 |
} |
1987 |
|
1988 |
public void refreshLayerInTerrain(FLayer layer, Layer3DProps props, |
1989 |
boolean bRemoveCache) {
|
1990 |
|
1991 |
System.out.println("Refresh"); |
1992 |
if (props == null) |
1993 |
return;
|
1994 |
|
1995 |
if (_terrain == null) |
1996 |
return; // view not opened yet |
1997 |
|
1998 |
// clear cache
|
1999 |
|
2000 |
// refresh layer in terrain
|
2001 |
int type = props.getType();
|
2002 |
if ((type == Layer3DProps.layer3DImage)
|
2003 |
|| (type == Layer3DProps.layer3DElevation) |
2004 |
|| (type == Layer3DProps.layer3DVectorMR)) { |
2005 |
|
2006 |
try {
|
2007 |
_terrainLayerManager.invalidateLayer(props.getTerrainLayer()); |
2008 |
} catch (LayerManagementException e) {
|
2009 |
// TODO Auto-generated catch block
|
2010 |
e.printStackTrace(); |
2011 |
} |
2012 |
} else if (type == Layer3DProps.layer3DVector) { |
2013 |
// ILegend legend = ((FLyrVect) layer).getLegend();
|
2014 |
//
|
2015 |
// try {
|
2016 |
// RequestDataEvent rde = new RequestDataEvent();
|
2017 |
// loadVectorData(layer, layer.getFullEnvelope(),
|
2018 |
// new RequestDataEvent(), (I3DSymbol) legend.getDefaultSymbol());
|
2019 |
// } catch (ReadException e) {
|
2020 |
// // TODO Auto-generated catch block
|
2021 |
// e.printStackTrace();
|
2022 |
// }
|
2023 |
|
2024 |
} |
2025 |
|
2026 |
} |
2027 |
|
2028 |
public boolean removeCache(File path) { |
2029 |
if (path.exists()) {
|
2030 |
File[] files = path.listFiles(); |
2031 |
for (int i = 0; i < files.length; i++) { |
2032 |
if (files[i].isDirectory()) {
|
2033 |
removeCache(files[i]); |
2034 |
} else {
|
2035 |
files[i].delete(); |
2036 |
} |
2037 |
} |
2038 |
} |
2039 |
return (path.delete());
|
2040 |
} |
2041 |
|
2042 |
public void removeLayerToTerrain(FLayer layer) { |
2043 |
|
2044 |
Layer terrainLayer = _terrainFLayerMap.get(layer); |
2045 |
if (terrainLayer != null) { |
2046 |
|
2047 |
_terrainLayerMap.remove(terrainLayer.getLayerID()); |
2048 |
_terrainFLayerMap.remove(layer); |
2049 |
|
2050 |
try {
|
2051 |
_terrainLayerManager.removeLayer(terrainLayer); |
2052 |
} catch (LayerManagementException e) {
|
2053 |
// TODO Auto-generated catch block
|
2054 |
e.printStackTrace(); |
2055 |
} |
2056 |
} |
2057 |
|
2058 |
} |
2059 |
|
2060 |
public void selectionChanged(SelectionEvent e) { |
2061 |
// TODO Auto-generated method stub
|
2062 |
// SingleLayerIterator lyrIterator = new SingleLayerIterator(layers);
|
2063 |
// while (lyrIterator.hasNext()) {
|
2064 |
// FLayer layer = lyrIterator.next();
|
2065 |
// Layer3DProps props3D = getLayer3DProps(layer);
|
2066 |
// if (props3D.getType() != Layer3DProps.layer3DOSG) {
|
2067 |
// if (layer.getClass().equals(FLyrVect.class)) {
|
2068 |
// FLyrVect lyr = (FLyrVect) layer;
|
2069 |
//
|
2070 |
// FBitSet selection = null;
|
2071 |
// try {
|
2072 |
// selection = lyr.getRecordset().getSelectionSupport()
|
2073 |
// .getSelection();
|
2074 |
// } catch (ReadDriverException e1) {
|
2075 |
// // TODO Auto-generated catch block
|
2076 |
// e1.printStackTrace();
|
2077 |
// }
|
2078 |
//
|
2079 |
// if ((selection.cardinality() == 0)
|
2080 |
// || (!(selection.isEmpty()))) {
|
2081 |
// Layer3DProps props = Layer3DProps
|
2082 |
// .getLayer3DProps(layer);
|
2083 |
// refreshLayerInTerrain(props, true);
|
2084 |
// if (layer instanceof FLyrVect) {
|
2085 |
// FLyrVect fvect = (FLyrVect) layer;
|
2086 |
// props.drawVersion = fvect.getDrawVersion();
|
2087 |
// }
|
2088 |
// }
|
2089 |
// }
|
2090 |
// }
|
2091 |
// }
|
2092 |
|
2093 |
} |
2094 |
|
2095 |
public void setDataManager(JavaDataDriver manager) { |
2096 |
_terrainDataManager = manager; |
2097 |
_terrainDataManager.setDataLoader(this);
|
2098 |
|
2099 |
} |
2100 |
|
2101 |
public void setLayerManager(LayerManager manager) { |
2102 |
_terrainLayerManager = manager; |
2103 |
|
2104 |
} |
2105 |
|
2106 |
public void setLoading(boolean bLoading) { |
2107 |
_bLoading = bLoading; |
2108 |
|
2109 |
} |
2110 |
|
2111 |
public void setRenewCanvasOff(boolean renewCanvasOff) { |
2112 |
_renewCanvasOff = renewCanvasOff; |
2113 |
|
2114 |
} |
2115 |
|
2116 |
public void setTerrain(Terrain terrain) { |
2117 |
if (_terrain == terrain)
|
2118 |
return;
|
2119 |
|
2120 |
_terrain = terrain; |
2121 |
|
2122 |
// add layers to terrain necessary when we are loading
|
2123 |
addCurrentLayers(); |
2124 |
|
2125 |
} |
2126 |
|
2127 |
public void setVerticalExaggeration(float verticalExaggeration) { |
2128 |
_verticalExaggeration = verticalExaggeration; |
2129 |
|
2130 |
} |
2131 |
|
2132 |
public void setViewProjection(IProjection projection) { |
2133 |
_viewProjection = projection; |
2134 |
|
2135 |
} |
2136 |
|
2137 |
public void setViewer(IViewerContainer canvas) { |
2138 |
_canvas3d = canvas; |
2139 |
_terrainViewer = (TerrainViewer) _canvas3d.getOSGViewer(); |
2140 |
|
2141 |
} |
2142 |
|
2143 |
public void visibilityChanged(LayerEvent e) { |
2144 |
FLayer lyr = e.getSource(); |
2145 |
|
2146 |
// if (props3D.getType() == Layer3DProps.layer3DVector) {
|
2147 |
// refreshLayerVectorsVisibility(lyr);
|
2148 |
// } else if (props3D.getType() == Layer3DProps.layer3DOSG) {
|
2149 |
// refreshLayer3DOSGVisibility(lyr);
|
2150 |
// } else {
|
2151 |
refreshLayerVisibility(lyr); |
2152 |
// }
|
2153 |
visibilityChange = true;
|
2154 |
|
2155 |
} |
2156 |
|
2157 |
private void refreshLayerVisibility(FLayer layer) { |
2158 |
|
2159 |
Layer terrainLayer = _terrainFLayerMap.get(layer); |
2160 |
terrainLayer.setEnabled(layer.isVisible()); |
2161 |
getEditionManager(layer).setEnabledNode(layer.isVisible()); |
2162 |
// _terrainLayerManager.updateLayers();
|
2163 |
|
2164 |
} |
2165 |
|
2166 |
public void zoomToEnvelope(Envelope geoEnvelope) { |
2167 |
if (geoEnvelope == null) |
2168 |
return;
|
2169 |
if ((geoEnvelope.getLength(0) == 0) || (geoEnvelope.getLength(1) == 0)) |
2170 |
return;
|
2171 |
|
2172 |
double maxHeight = 0.0; |
2173 |
|
2174 |
// Getting envelope positions
|
2175 |
double minLat = geoEnvelope.getMinimum(0); |
2176 |
double maxLat = geoEnvelope.getMaximum(0); |
2177 |
|
2178 |
double cenLon = geoEnvelope.getCenter(0); |
2179 |
double cenLat = geoEnvelope.getCenter(1); |
2180 |
|
2181 |
double elevation = 0; |
2182 |
|
2183 |
// calculate altitude
|
2184 |
double avLat = 0; |
2185 |
if (minLat > 0.0 || maxLat < 0.0) |
2186 |
avLat = Math.min(Math.abs(minLat), Math.abs(maxLat)); |
2187 |
double avLon = Math.min(180.0, geoEnvelope.getLength(1)); |
2188 |
|
2189 |
double terrainRadius = _terrain.getRadiusEquatorial();
|
2190 |
double radiusLat = terrainRadius * Math.cos(Math.toRadians(avLat)); |
2191 |
double deltaLon = Math.sqrt(2 * radiusLat * radiusLat |
2192 |
* (1 - Math.cos(Math.toRadians(avLon)))); |
2193 |
double deltaLat = Math.sqrt(2 * terrainRadius * terrainRadius |
2194 |
* (1 - Math.cos(Math.toRadians(geoEnvelope.getLength(0))))); |
2195 |
|
2196 |
// Calculate XYZ positions for camera.
|
2197 |
|
2198 |
int terrainType = _terrain.getCoordinateSystemType();
|
2199 |
|
2200 |
double zoomFactor = 1.5; |
2201 |
if (terrainType == Terrain.CoordinateSystemType.PROJECTED)
|
2202 |
zoomFactor = 1.3;
|
2203 |
elevation = (Math.max(deltaLon, deltaLat) * zoomFactor) + maxHeight;
|
2204 |
|
2205 |
Vec3 eye = new Vec3();
|
2206 |
Vec3 center = new Vec3();
|
2207 |
Vec3 up = new Vec3();
|
2208 |
// Calculate positions for PLAIN MODE.
|
2209 |
if (terrainType == Terrain.CoordinateSystemType.PROJECTED) {
|
2210 |
|
2211 |
double difx = (geoEnvelope.getMaximum(1) - geoEnvelope |
2212 |
.getMinimum(1)) / 1.2d; |
2213 |
double dify = (geoEnvelope.getMaximum(0) - geoEnvelope |
2214 |
.getMinimum(0)) / 1.2d; |
2215 |
double height;
|
2216 |
|
2217 |
height = Math.sqrt(difx * difx + dify * dify);
|
2218 |
double fullWindowFactor = 1.7; |
2219 |
// EYE
|
2220 |
eye.setX(cenLon); |
2221 |
eye.setY(cenLat); |
2222 |
eye.setZ(height * fullWindowFactor); |
2223 |
// CENTER
|
2224 |
center.setX(cenLon); |
2225 |
center.setY(cenLat); |
2226 |
center.setZ(0.0);
|
2227 |
// UP
|
2228 |
up.setX(0.0);
|
2229 |
up.setY(1.0);
|
2230 |
up.setZ(0.0);
|
2231 |
} else
|
2232 |
// Calculate positions for SPHERICAL MODE.
|
2233 |
if (terrainType == Terrain.CoordinateSystemType.GEOCENTRIC) {
|
2234 |
// EYE
|
2235 |
Vec3 aux = new Vec3(cenLon, cenLat, elevation);
|
2236 |
eye = _terrain.convertLatLongHeightToXYZ(aux); |
2237 |
// CENTER
|
2238 |
center.setX(0.0);
|
2239 |
center.setY(0.0);
|
2240 |
center.setZ(0.0);
|
2241 |
// UP
|
2242 |
up.setX(0.0);
|
2243 |
up.setY(0.0);
|
2244 |
up.setZ(1.0);
|
2245 |
} |
2246 |
Camera cam = new Camera();
|
2247 |
cam.setViewByLookAt(eye, center, up); |
2248 |
|
2249 |
_terrainViewer.setCamera(cam); |
2250 |
|
2251 |
} |
2252 |
|
2253 |
public void editionChanged(LayerEvent e) { |
2254 |
// TODO Auto-generated method stub
|
2255 |
|
2256 |
} |
2257 |
|
2258 |
public void drawValueChanged(LayerEvent e) { |
2259 |
// TODO Auto-generated method stub
|
2260 |
|
2261 |
} |
2262 |
|
2263 |
public boolean symbolChanged(SymbolLegendEvent e) { |
2264 |
|
2265 |
System.out.println("Symbol changed"); |
2266 |
return false; |
2267 |
} |
2268 |
|
2269 |
public void legendCleared(LegendClearEvent event) { |
2270 |
// TODO Auto-generated method stub
|
2271 |
|
2272 |
} |
2273 |
|
2274 |
public static class RegisterPersistence implements Callable { |
2275 |
|
2276 |
public Object call() throws Exception { |
2277 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
2278 |
if (manager.getDefinition(MapContext.class) == null) { |
2279 |
MapContext.registerPersistent(); |
2280 |
} |
2281 |
DynStruct definition = manager.addDefinition( |
2282 |
MapContext3DImpl.class, "MapContext3DImpl",
|
2283 |
"MapContext3DImpl Persistence definition", null, null); |
2284 |
definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, |
2285 |
"MapContext");
|
2286 |
|
2287 |
return Boolean.TRUE; |
2288 |
} |
2289 |
} |
2290 |
|
2291 |
@Override
|
2292 |
public EditionManager getEditionManager(FLayer layer) {
|
2293 |
|
2294 |
EditionManager eManager = _layersEditionMap.get(layer); |
2295 |
|
2296 |
if (eManager == null) { |
2297 |
|
2298 |
try {
|
2299 |
DataStore ds = ((SingleLayer) layer).getDataStore(); |
2300 |
|
2301 |
Node n = null;
|
2302 |
|
2303 |
if (ds.getProviderName() == "OSG") { |
2304 |
|
2305 |
n = (Node) ds.invokeDynMethod("getNode", null); |
2306 |
|
2307 |
} else
|
2308 |
n = new Group(); |
2309 |
|
2310 |
eManager = new EditionManager();
|
2311 |
|
2312 |
Group loadedScene = new Group(n.getCPtr()); |
2313 |
|
2314 |
for (int i = 0; i < loadedScene.getNumChildren(); i++) { |
2315 |
|
2316 |
eManager.setScene(loadedScene.getChild(i)); |
2317 |
|
2318 |
} |
2319 |
|
2320 |
BasicInputHandler handler = new BasicInputHandler(eManager,
|
2321 |
(OSGViewer) _canvas3d.getOSGViewer()); |
2322 |
|
2323 |
_canvas3d.getOSGViewer().addEventHandler(handler); |
2324 |
((TerrainViewer) _canvas3d.getOSGViewer()).addFeature(eManager); |
2325 |
|
2326 |
_layersEditionMap.put(layer, eManager); |
2327 |
_layersHandlerMap.put(layer, handler); |
2328 |
|
2329 |
} catch (NodeException e2) {
|
2330 |
// TODO Auto-generated catch block
|
2331 |
e2.printStackTrace(); |
2332 |
} catch (DynMethodException e) {
|
2333 |
// TODO Auto-generated catch block
|
2334 |
e.printStackTrace(); |
2335 |
} |
2336 |
|
2337 |
} |
2338 |
|
2339 |
return eManager;
|
2340 |
} |
2341 |
|
2342 |
public BasicInputHandler getEditionHandler(FLayer layer) {
|
2343 |
|
2344 |
return _layersHandlerMap.get(layer);
|
2345 |
|
2346 |
} |
2347 |
} |