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