gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / render / DefaultRender.java @ 2424
History | View | Annotate | Download (34.5 KB)
1 | 30 | nbrodin | /* 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.raster.impl.grid.render; |
||
23 | |||
24 | import java.awt.Graphics2D; |
||
25 | import java.awt.Image; |
||
26 | import java.awt.geom.AffineTransform; |
||
27 | 657 | nbrodin | import java.awt.geom.Dimension2D; |
28 | 30 | nbrodin | import java.awt.geom.NoninvertibleTransformException; |
29 | import java.awt.geom.Point2D; |
||
30 | import java.util.ArrayList; |
||
31 | 2328 | nbrodin | import java.util.List; |
32 | 30 | nbrodin | |
33 | 1277 | nbrodin | import org.cresques.cts.ICoordTrans; |
34 | 132 | nbrodin | import org.gvsig.fmap.dal.coverage.RasterLocator; |
35 | 1869 | nbrodin | import org.gvsig.fmap.dal.coverage.RasterManager; |
36 | 55 | nbrodin | import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
37 | 30 | nbrodin | import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
38 | 242 | nbrodin | import org.gvsig.fmap.dal.coverage.datastruct.Params; |
39 | 112 | nbrodin | import org.gvsig.fmap.dal.coverage.datastruct.ViewPortData; |
40 | 242 | nbrodin | import org.gvsig.fmap.dal.coverage.exception.FilterManagerException; |
41 | import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
||
42 | 90 | nbrodin | import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
43 | 2232 | nbrodin | import org.gvsig.fmap.dal.coverage.exception.QueryException; |
44 | 2328 | nbrodin | import org.gvsig.fmap.dal.coverage.exception.ROIException; |
45 | 2308 | nbrodin | import org.gvsig.fmap.dal.coverage.filter.FilterLoader; |
46 | 30 | nbrodin | import org.gvsig.fmap.dal.coverage.grid.FilterListChangeEvent; |
47 | import org.gvsig.fmap.dal.coverage.grid.FilterListChangeListener; |
||
48 | 127 | nbrodin | import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
49 | 30 | nbrodin | import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
50 | 242 | nbrodin | import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager; |
51 | 112 | nbrodin | import org.gvsig.fmap.dal.coverage.grid.render.Render; |
52 | import org.gvsig.fmap.dal.coverage.grid.render.VisualPropertyEvent; |
||
53 | import org.gvsig.fmap.dal.coverage.grid.render.VisualPropertyListener; |
||
54 | 55 | nbrodin | import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
55 | import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
||
56 | import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
||
57 | 127 | nbrodin | import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
58 | 2328 | nbrodin | import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
59 | 723 | nbrodin | import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
60 | 111 | nbrodin | import org.gvsig.fmap.dal.coverage.util.PropertyEvent; |
61 | import org.gvsig.fmap.dal.coverage.util.PropertyListener; |
||
62 | 130 | nbrodin | import org.gvsig.fmap.dal.coverage.util.RasterUtils; |
63 | 296 | nbrodin | import org.gvsig.raster.cache.tile.Tile; |
64 | import org.gvsig.raster.cache.tile.exception.TileGettingException; |
||
65 | import org.gvsig.raster.cache.tile.provider.TileListener; |
||
66 | 112 | nbrodin | import org.gvsig.raster.impl.datastruct.DefaultViewPortData; |
67 | 30 | nbrodin | import org.gvsig.raster.impl.datastruct.ExtentImpl; |
68 | import org.gvsig.raster.impl.grid.filter.band.ColorTableFilter; |
||
69 | 162 | nbrodin | import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation; |
70 | 2328 | nbrodin | import org.gvsig.raster.roi.ROI; |
71 | 2341 | nbrodin | import org.gvsig.raster.util.persistence.PersistencyFilterParams; |
72 | 30 | nbrodin | import org.gvsig.tools.ToolsLocator; |
73 | import org.gvsig.tools.dynobject.DynStruct; |
||
74 | import org.gvsig.tools.persistence.PersistenceManager; |
||
75 | import org.gvsig.tools.persistence.Persistent; |
||
76 | import org.gvsig.tools.persistence.PersistentState; |
||
77 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
78 | 1040 | nbrodin | import org.gvsig.tools.task.TaskStatus; |
79 | 210 | nbrodin | import org.slf4j.LoggerFactory; |
80 | 30 | nbrodin | /**
|
81 | * Esta clase se encarga de la gesti?n del dibujado de datos le?dos desde la capa
|
||
82 | * "dataaccess" sobre objetos java. Para ello necesita una fuente de datos que tipicamente
|
||
83 | * es un buffer (RasterBuffer) y un objeto que realice la funci?n de escritura de datos a
|
||
84 | * partir de un estado inicial.
|
||
85 | * Esta capa del renderizado gestiona Extents, rotaciones, tama?os de vista pero la escritura
|
||
86 | * de datos desde el buffer al objeto image es llevada a cabo por ImageDrawer.
|
||
87 | *
|
||
88 | * Par?metros de control de la visualizaci?n:
|
||
89 | * <UL>
|
||
90 | * <LI>renderBands: Orden de visualizado de las bands.</LI>
|
||
91 | * <LI>replicateBands: Para visualizaci?n de raster de una banda. Dice si se replica sobre las otras dos bandas
|
||
92 | * de visualizaci?n o se ponen a 0.</LI>
|
||
93 | * <LI>enhanced: aplicaci?n de filtro de realce</LI>
|
||
94 | * <LI>removeEnds: Eliminar extremos en el filtro de realce. Uso del segundo m?ximo y m?nimo</LI>
|
||
95 | * <LI>tailTrim: Aplicacion de recorte de colas en el realce. Es un valor decimal que representa el porcentaje del recorte entre 100.
|
||
96 | * Es decir, 0.1 significa que el recorte es de un 10%</LI>
|
||
97 | * </UL>
|
||
98 | *
|
||
99 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
100 | */
|
||
101 | 210 | nbrodin | public class DefaultRender implements Render, PropertyListener, FilterListChangeListener, Persistent, TileListener { |
102 | 30 | nbrodin | /**
|
103 | * Fuente de datos para el renderizado
|
||
104 | */
|
||
105 | 2311 | nbrodin | private RasterDataStore dataStore = null; |
106 | 30 | nbrodin | /**
|
107 | * N?mero de bandas a renderizar y en el orden que se har?. Esto es asignado
|
||
108 | * por el usuario de la renderizaci?n.
|
||
109 | */
|
||
110 | 2311 | nbrodin | ColorInterpretation renderColorInterpretation = null;
|
111 | //private int[] renderBands = { 0, 1, 2, 3 };
|
||
112 | 30 | nbrodin | |
113 | 2311 | nbrodin | private ImageDrawerImpl drawer = null; |
114 | 2308 | nbrodin | |
115 | 30 | nbrodin | /**
|
116 | 2308 | nbrodin | *
|
117 | 30 | nbrodin | */
|
118 | 2311 | nbrodin | private Transparency renderingTransparency = null; |
119 | private int lastAlphaBand = -1; |
||
120 | 722 | nbrodin | |
121 | 30 | nbrodin | /**
|
122 | * Lista de filtros aplicada en la renderizaci?n
|
||
123 | */
|
||
124 | private RasterFilterList filterList = null; |
||
125 | |||
126 | /**
|
||
127 | * Ancho y alto del objeto Image en una petici?n de dibujado a un raster
|
||
128 | * raster
|
||
129 | */
|
||
130 | private double widthImage, heightImage; |
||
131 | |||
132 | private Point2D ulPxRequest, lrPxRequest; |
||
133 | |||
134 | /**
|
||
135 | * Array de listeners que ser?n informados cuando cambia una propiedad en la visualizaci?n
|
||
136 | */
|
||
137 | private ArrayList<VisualPropertyListener> |
||
138 | visualPropertyListener = new ArrayList<VisualPropertyListener>(); |
||
139 | 132 | nbrodin | private RasterUtils util = RasterLocator.getManager().getRasterUtils();
|
140 | 210 | nbrodin | private boolean isDrawing = false; |
141 | 132 | nbrodin | |
142 | 210 | nbrodin | private Graphics2D lastGraphics = null; |
143 | private ViewPortData lastViewPortData = null; |
||
144 | 657 | nbrodin | private Dimension2D viewDimension = null; |
145 | 1277 | nbrodin | private RasterRenderReprojection
|
146 | reprojectionOnTheFly = null;
|
||
147 | 1869 | nbrodin | private RasterManager rManager = null; |
148 | 1277 | nbrodin | |
149 | 30 | nbrodin | /**
|
150 | * Constructor
|
||
151 | * @param grid
|
||
152 | */
|
||
153 | 758 | nbrodin | public DefaultRender() {
|
154 | } |
||
155 | |||
156 | /**
|
||
157 | * Constructor
|
||
158 | * @param grid
|
||
159 | */
|
||
160 | 109 | nbrodin | public DefaultRender(RasterDataStore ds) {
|
161 | 55 | nbrodin | this.dataStore = ds;
|
162 | 30 | nbrodin | init(); |
163 | } |
||
164 | 186 | nbrodin | |
165 | 1869 | nbrodin | private RasterManager getRasterManager() {
|
166 | if(rManager == null) |
||
167 | rManager = RasterLocator.getManager(); |
||
168 | return rManager;
|
||
169 | } |
||
170 | |||
171 | 1277 | nbrodin | public void createReprojectionOnTheFly( |
172 | RasterDataStore store, |
||
173 | ICoordTrans coordTrans, |
||
174 | TaskStatus status) { |
||
175 | reprojectionOnTheFly = new RasterRenderReprojection(
|
||
176 | store, coordTrans, status); |
||
177 | } |
||
178 | |||
179 | public boolean isReprojectingOnTheFly() { |
||
180 | return reprojectionOnTheFly != null; |
||
181 | } |
||
182 | |||
183 | 186 | nbrodin | public RasterDataStore getDataStore() {
|
184 | return this.dataStore; |
||
185 | } |
||
186 | |||
187 | public void setDataStore(RasterDataStore dataStore) { |
||
188 | this.dataStore = dataStore;
|
||
189 | init(); |
||
190 | } |
||
191 | 30 | nbrodin | |
192 | private void init() { |
||
193 | 1977 | nbrodin | if(dataStore == null || dataStore.getDataType() == null) |
194 | 373 | nbrodin | return;
|
195 | 1277 | nbrodin | |
196 | 1315 | nbrodin | drawer = new ImageDrawerImpl();
|
197 | 2311 | nbrodin | getRenderColorInterpretation(); |
198 | 30 | nbrodin | } |
199 | |||
200 | /**
|
||
201 | * Asigna un listener a la lista que ser? informado cuando cambie una
|
||
202 | * propiedad visual en la renderizaci?n.
|
||
203 | * @param listener VisualPropertyListener
|
||
204 | */
|
||
205 | public void addVisualPropertyListener(VisualPropertyListener listener) { |
||
206 | visualPropertyListener.add(listener); |
||
207 | } |
||
208 | |||
209 | /**
|
||
210 | * M?todo llamado cuando hay un cambio en una propiedad de visualizaci?n
|
||
211 | */
|
||
212 | private void callVisualPropertyChanged(Object obj) { |
||
213 | 1735 | nbrodin | if(visualPropertyListener != null) { |
214 | for (int i = 0; i < visualPropertyListener.size(); i++) { |
||
215 | VisualPropertyEvent ev = new VisualPropertyEvent(obj);
|
||
216 | ((VisualPropertyListener)visualPropertyListener.get(i)).visualPropertyValueChanged(ev); |
||
217 | } |
||
218 | 30 | nbrodin | } |
219 | } |
||
220 | 210 | nbrodin | |
221 | /**
|
||
222 | * Thread de dibujado
|
||
223 | */
|
||
224 | public void run() { |
||
225 | try {
|
||
226 | 1040 | nbrodin | draw(lastGraphics, lastViewPortData, null);
|
227 | 2232 | nbrodin | } catch (QueryException e) {
|
228 | LoggerFactory.getLogger(getClass()).debug("Error in a query", e);
|
||
229 | 210 | nbrodin | } catch (ProcessInterruptedException e) {
|
230 | } |
||
231 | } |
||
232 | |||
233 | public void setGraphicInfo(Graphics2D g, ViewPortData vp) { |
||
234 | this.lastGraphics = g;
|
||
235 | this.lastViewPortData = vp;
|
||
236 | } |
||
237 | 30 | nbrodin | |
238 | 210 | nbrodin | public void drawThread(Graphics2D g, ViewPortData vp) { |
239 | //Se dibuja si cae dentro de la vista
|
||
240 | if(util.isOutside(vp.getExtent(), dataStore.getExtent()))
|
||
241 | return;
|
||
242 | |||
243 | setReading(true);
|
||
244 | setGraphicInfo(g, vp); |
||
245 | new Thread(this).start(); |
||
246 | |||
247 | while(isReading()) {
|
||
248 | try {
|
||
249 | Thread.sleep(50); |
||
250 | } catch (InterruptedException e) { |
||
251 | break;
|
||
252 | } |
||
253 | } |
||
254 | } |
||
255 | |||
256 | 2308 | nbrodin | public synchronized Buffer getLastRenderBuffer() |
257 | throws QueryException, ProcessInterruptedException {
|
||
258 | return draw(null, lastViewPortData, null); |
||
259 | } |
||
260 | |||
261 | 1040 | nbrodin | public synchronized void drawTiledService(Graphics2D g, |
262 | ViewPortData vp, |
||
263 | Dimension2D viewDimension,
|
||
264 | TaskStatus taskStatus) |
||
265 | 2232 | nbrodin | throws QueryException, ProcessInterruptedException {
|
266 | 224 | nbrodin | lastGraphics = g; |
267 | lastViewPortData = vp; |
||
268 | 1040 | nbrodin | this.viewDimension = viewDimension;
|
269 | 2311 | nbrodin | int[] renderBands = getRenderColorInterpretation().buildRenderBands(); |
270 | |||
271 | 224 | nbrodin | if(util.isOutside(vp.getExtent(), dataStore.getExtent())) {
|
272 | endReading(); |
||
273 | return;
|
||
274 | } |
||
275 | |||
276 | if (dataStore != null) { |
||
277 | 2308 | nbrodin | lastAlphaBand = getRenderingTransparency().getAlphaBandNumber(); |
278 | 724 | nbrodin | |
279 | 224 | nbrodin | // Asignamos la banda de transparencia si existe esta
|
280 | 1869 | nbrodin | RasterQuery query = getRasterManager().createQuery(); |
281 | 1040 | nbrodin | query.setTaskStatus(taskStatus); |
282 | 621 | nbrodin | query.setTime(vp.getTime()); |
283 | 2233 | nbrodin | query.setSupersamplingOption(false); // Desactivamos el supersampleo en la carga del buffer. |
284 | 2308 | nbrodin | if(dataStore.getColorInterpretation().isRGB())
|
285 | renderBands[3] = 3; |
||
286 | 2311 | nbrodin | query.setDrawableBands(renderBands); |
287 | 2308 | nbrodin | if(dataStore.getDataType()[0] == Buffer.TYPE_BYTE) { |
288 | if(lastAlphaBand != -1) |
||
289 | query.forceARGBRequest(); |
||
290 | 2311 | nbrodin | else if(renderBands.length == 3 || (renderBands.length == 4 && renderBands[3] == -1)) |
291 | 2308 | nbrodin | query.forceRGBRequest(); |
292 | else
|
||
293 | query.forceARGBRequest(); |
||
294 | } else
|
||
295 | query.forceRGBRequest(); |
||
296 | 642 | nbrodin | query.setAreaOfInterest(vp.getExtent(), |
297 | 224 | nbrodin | (int)Math.round(vp.getWidth()), |
298 | 234 | nbrodin | (int)Math.round(vp.getHeight()), this); |
299 | 224 | nbrodin | dataStore.query(query); |
300 | 2233 | nbrodin | query.setSupersamplingOption(true);
|
301 | 224 | nbrodin | } else
|
302 | return;
|
||
303 | } |
||
304 | |||
305 | 2308 | nbrodin | public synchronized void tileReady(Tile loadedTile) throws TileGettingException { |
306 | boolean crash = false; |
||
307 | Boolean tiling = (Boolean)loadedTile.getDownloaderParams("Tiling"); |
||
308 | double[] step = (double[])loadedTile.getDownloaderParams("Step"); |
||
309 | AffineTransform transf = (AffineTransform)loadedTile.getDownloaderParams("AffineTransform"); |
||
310 | |||
311 | Extent e = getRasterManager().getDataStructFactory(). |
||
312 | createExtent(loadedTile.getUl().getX(), |
||
313 | loadedTile.getUl().getY(), |
||
314 | loadedTile.getLr().getX(), |
||
315 | loadedTile.getLr().getY()); |
||
316 | |||
317 | Buffer buf = (loadedTile.getData() != null && loadedTile.getData().length > 0) ? (Buffer)loadedTile.getData()[0] : null; |
||
318 | |||
319 | if(!loadedTile.dataIsLoaded()) {
|
||
320 | if(loadedTile.getCrashARGB() == null) |
||
321 | return;
|
||
322 | crash = true;
|
||
323 | buf = (Buffer)loadedTile.getCrashARGB();
|
||
324 | } else {
|
||
325 | if(buf == null) |
||
326 | return;
|
||
327 | ColorTable tileColorTable = (loadedTile.getData() != null && loadedTile.getData().length > 2) ? (ColorTable)loadedTile.getData()[2] : null; |
||
328 | if(tiling == null || tiling.booleanValue()) { |
||
329 | if(filterList != null) |
||
330 | addTileColorTable(tileColorTable); |
||
331 | } |
||
332 | } |
||
333 | 2314 | nbrodin | buf.setDataExtent(e.toRectangle2D()); |
334 | 2308 | nbrodin | |
335 | Transparency transparencyProcessed = null; |
||
336 | if(tiling == null || tiling.booleanValue()) { |
||
337 | try {
|
||
338 | 2315 | nbrodin | FilterLoader filterLoader = bufferPreprocessing(buf); |
339 | transparencyProcessed = filterLoader.getTransparency(); |
||
340 | buf = filterLoader.getBufferResult(); |
||
341 | 2308 | nbrodin | } catch (ProcessInterruptedException e3) {
|
342 | return;
|
||
343 | } |
||
344 | } |
||
345 | |||
346 | if(tiling == null || tiling.booleanValue()) { |
||
347 | //Reescalado de los tiles. El tama?o en pixels de un tile no tiene pq coincidir con el de la vista.
|
||
348 | double w = lastViewPortData.getWidth();
|
||
349 | double h = lastViewPortData.getHeight();
|
||
350 | if(viewDimension != null) { |
||
351 | w = viewDimension.getWidth(); |
||
352 | h = viewDimension.getHeight(); |
||
353 | } |
||
354 | double viewScaleW = lastViewPortData.getExtent().width() / w;
|
||
355 | double tileScaleW = e.width() / (double)buf.getWidth(); |
||
356 | double scaleW = viewScaleW / tileScaleW;
|
||
357 | double viewScaleH = lastViewPortData.getExtent().height() / h;
|
||
358 | double tileScaleH = e.height() / (double)buf.getHeight(); |
||
359 | double scaleH = viewScaleH / tileScaleH;
|
||
360 | |||
361 | ImageDrawerImpl d = new ImageDrawerImpl();
|
||
362 | d.setBuffer(buf); |
||
363 | d.setSupersamplingOn(null);
|
||
364 | d.setOutputSize(buf.getWidth(), buf.getHeight()); |
||
365 | d.setLastTransparency(transparencyProcessed); |
||
366 | Image geoImage;
|
||
367 | try {
|
||
368 | geoImage = d.drawBufferOverImageObject(); |
||
369 | } catch (ProcessInterruptedException e2) {
|
||
370 | return;
|
||
371 | } |
||
372 | d.dispose(); |
||
373 | |||
374 | AffineTransform at = new AffineTransform(); |
||
375 | at.scale(1 / scaleW, 1 / scaleH); |
||
376 | |||
377 | try {
|
||
378 | Point2D pt = new Point2D.Double(e.getULX(), e.getULY()); |
||
379 | ((DefaultViewPortData)lastViewPortData).mat.transform(pt, pt); |
||
380 | at.inverseTransform(pt, pt); |
||
381 | |||
382 | lastGraphics.transform(at); |
||
383 | lastGraphics.drawImage(geoImage, (int) Math.round(pt.getX()), (int) Math.round(pt.getY()), null); |
||
384 | lastGraphics.transform(at.createInverse()); |
||
385 | 2393 | nbrodin | geoImage.flush(); |
386 | 2308 | nbrodin | } catch (NoninvertibleTransformException e1) { |
387 | e1.printStackTrace(); |
||
388 | } |
||
389 | } else {
|
||
390 | try {
|
||
391 | drawBufferOnImage(lastGraphics, lastViewPortData, buf, step, transf, e); |
||
392 | } catch (QueryException e1) {
|
||
393 | LoggerFactory.getLogger(getClass()).debug("Error loading data", e1);
|
||
394 | } catch (ProcessInterruptedException e1) {
|
||
395 | } |
||
396 | } |
||
397 | |||
398 | if(!crash) { //Las im?genes de crash no se liberan ya que est?n en un hashmap global |
||
399 | if(buf != null) |
||
400 | buf.dispose(); |
||
401 | } |
||
402 | 1676 | nbrodin | } |
403 | |||
404 | public synchronized Buffer draw(Graphics2D g, ViewPortData vp, TaskStatus taskStatus) |
||
405 | 2232 | nbrodin | throws QueryException, ProcessInterruptedException {
|
406 | 210 | nbrodin | lastGraphics = g; |
407 | lastViewPortData = vp; |
||
408 | 30 | nbrodin | |
409 | 210 | nbrodin | if(util.isOutside(vp.getExtent(), dataStore.getExtent())) {
|
410 | endReading(); |
||
411 | 1676 | nbrodin | return null; |
412 | 210 | nbrodin | } |
413 | 30 | nbrodin | |
414 | 55 | nbrodin | Extent adjustedRotedRequest = request(vp, dataStore); |
415 | 30 | nbrodin | |
416 | 210 | nbrodin | if ((widthImage <= 0) || (heightImage <= 0)) { |
417 | endReading(); |
||
418 | 1676 | nbrodin | return null; |
419 | 210 | nbrodin | } |
420 | 233 | nbrodin | |
421 | if (dataStore == null) |
||
422 | 1676 | nbrodin | return null; |
423 | 723 | nbrodin | |
424 | 1277 | nbrodin | Buffer buf = null; |
425 | double[] step = null; |
||
426 | 2311 | nbrodin | int[] renderBands = getRenderColorInterpretation().buildRenderBands(); |
427 | 1277 | nbrodin | |
428 | if(reprojectionOnTheFly != null) { |
||
429 | buf = reprojectionOnTheFly.warp(adjustedRotedRequest, |
||
430 | (int)Math.round(widthImage), |
||
431 | (int)Math.round(heightImage), |
||
432 | vp.getTime(), |
||
433 | renderBands, |
||
434 | 2308 | nbrodin | getRenderingTransparency()); |
435 | 1277 | nbrodin | } else {
|
436 | 2308 | nbrodin | lastAlphaBand = getRenderingTransparency().getAlphaBandNumber(); |
437 | 1277 | nbrodin | |
438 | 2236 | nbrodin | RasterQuery query = getRasterManager().createQuery(); |
439 | query.setTaskStatus(taskStatus); |
||
440 | query.setTime(vp.getTime()); |
||
441 | 1277 | nbrodin | query.setAreaOfInterest(adjustedRotedRequest, (int)Math.round(widthImage), (int)Math.round(heightImage)); |
442 | 2311 | nbrodin | query.setDrawableBands(renderBands); |
443 | 2308 | nbrodin | if(dataStore.getDataType()[0] == Buffer.TYPE_BYTE) { |
444 | if(lastAlphaBand != -1) |
||
445 | query.forceARGBRequest(); |
||
446 | 2311 | nbrodin | else if(renderBands.length == 3 || (renderBands.length == 4 && renderBands[3] == -1)) |
447 | 2308 | nbrodin | query.forceRGBRequest(); |
448 | 2315 | nbrodin | } else {
|
449 | if(renderBands.length == 4 && renderBands[3] != -1) |
||
450 | query.forceARGBRequest(); |
||
451 | else
|
||
452 | query.forceRGBRequest(); |
||
453 | } |
||
454 | 1277 | nbrodin | buf = dataStore.query(query); |
455 | 2234 | nbrodin | step = query.getStep(); |
456 | 233 | nbrodin | } |
457 | 1277 | nbrodin | |
458 | 373 | nbrodin | if(drawer == null) { |
459 | init(); |
||
460 | } |
||
461 | |||
462 | 1676 | nbrodin | return drawBufferOnImage(lastGraphics,
|
463 | lastViewPortData, |
||
464 | buf, |
||
465 | step, |
||
466 | dataStore.getAffineTransform(), |
||
467 | adjustedRotedRequest); |
||
468 | 210 | nbrodin | } |
469 | |||
470 | 1676 | nbrodin | private synchronized Buffer drawBufferOnImage(Graphics2D g, ViewPortData vp, Buffer buf, double[] step, AffineTransform transf, Extent adjustedRotedRequest) |
471 | 2232 | nbrodin | throws QueryException, ProcessInterruptedException {
|
472 | 2315 | nbrodin | FilterLoader filterLoader = bufferPreprocessing(buf); |
473 | Transparency transparencyProcessed = filterLoader.getTransparency();
|
||
474 | buf = filterLoader.getBufferResult(); |
||
475 | 210 | nbrodin | |
476 | 1676 | nbrodin | if(g == null) |
477 | return buf;
|
||
478 | 2308 | nbrodin | |
479 | 1674 | nbrodin | drawer.setBuffer(buf); // Buffer de datos a renderizar
|
480 | 1315 | nbrodin | drawer.setSupersamplingOn(step); // Desplazamiento para supersampleo
|
481 | drawer.setOutputSize((int)Math.round(widthImage), (int)Math.round(heightImage)); // Ancho y alto del buffer |
||
482 | 2308 | nbrodin | drawer.setLastTransparency(transparencyProcessed); |
483 | 237 | nbrodin | Image geoImage = drawer.drawBufferOverImageObject(); // Acci?n de renderizado |
484 | 1674 | nbrodin | drawer.dispose(); |
485 | 2308 | nbrodin | |
486 | 30 | nbrodin | //En el caso de no tenga rotaci?n y el tama?o de pixel sea positivo en X y negativo en Y no aplicamos ninguna
|
487 | //transformaci?n. Esto no es necesario hacerlo, sin ello se visualiza igual. Unicamente se hace porque de esta
|
||
488 | //forma el raster resultante mejora un poco en calidad en ciertos niveles de zoom ya que al aplicar transformaciones
|
||
489 | //sobre el Graphics parece que pierde algo de calidad.
|
||
490 | if(transf.getScaleX() > 0 && transf.getScaleY() < 0 && transf.getShearX() == 0 && transf.getShearY() == 0) { |
||
491 | Point2D lastGraphicOffset = new Point2D.Double(adjustedRotedRequest.getULX(), adjustedRotedRequest.getULY()); |
||
492 | 112 | nbrodin | ((DefaultViewPortData)vp).mat.transform(lastGraphicOffset, lastGraphicOffset); |
493 | 30 | nbrodin | g.drawImage(geoImage, (int) Math.round(lastGraphicOffset.getX()), (int) Math.round(lastGraphicOffset.getY()), null); |
494 | 1676 | nbrodin | return buf;
|
495 | 30 | nbrodin | } |
496 | |||
497 | /*
|
||
498 | * Tenemos una matriz con la transformaci?n de la coordenadas de la vista a coordenadas reales vp.mat, adem?s tenemos
|
||
499 | * la transformaci?n de coordenadas reales a coordenadas pixel (transf). Con ambas podemos obtener una matriz de trasformacion
|
||
500 | * entre coordenadas de la vista a coordenadas pixel (transf X vp.mat). As? obtenemos la transformaci?n entre coordenadas
|
||
501 | 224 | nbrodin | * de la vista y coordenadas pixel del raster. El problema es que a cada zoom la escala de la petici?n del raster varia
|
502 | 30 | nbrodin | * por lo que habr? que calcular una matriz con la escala (escale). escale X transf X vp.mat
|
503 | */
|
||
504 | double sX = Math.abs(ulPxRequest.getX() - lrPxRequest.getX()) / widthImage; |
||
505 | double sY = Math.abs(ulPxRequest.getY() - lrPxRequest.getY()) / heightImage; |
||
506 | 224 | nbrodin | AffineTransform scale = new AffineTransform(sX, 0, 0, sY, 0, 0); |
507 | 30 | nbrodin | |
508 | try {
|
||
509 | 224 | nbrodin | AffineTransform at = (AffineTransform)scale.clone(); |
510 | 30 | nbrodin | at.preConcatenate(transf); |
511 | at.preConcatenate(vp.getMat()); |
||
512 | g.transform(at); |
||
513 | Point2D.Double pt = null; |
||
514 | //El punto sobre el que rota la imagen depende del signo de los tama?os del pixel
|
||
515 | if(transf.getScaleX() < 0 && transf.getScaleY() < 0) |
||
516 | pt = new Point2D.Double(adjustedRotedRequest.maxX(), adjustedRotedRequest.maxY()); |
||
517 | else if(transf.getScaleX() > 0 && transf.getScaleY() > 0) |
||
518 | pt = new Point2D.Double(adjustedRotedRequest.minX(), adjustedRotedRequest.minY()); |
||
519 | else if(transf.getScaleX() < 0 && transf.getScaleY() > 0) |
||
520 | pt = new Point2D.Double(adjustedRotedRequest.maxX(), adjustedRotedRequest.minY()); |
||
521 | else
|
||
522 | pt = new Point2D.Double(adjustedRotedRequest.getULX(), adjustedRotedRequest.getULY()); |
||
523 | vp.getMat().transform(pt, pt); |
||
524 | at.inverseTransform(pt, pt); |
||
525 | g.drawImage(geoImage, (int) Math.round(pt.getX()), (int) Math.round(pt.getY()), null); |
||
526 | g.transform(at.createInverse()); |
||
527 | 2393 | nbrodin | geoImage.flush(); |
528 | 30 | nbrodin | } catch (NoninvertibleTransformException e) { |
529 | 210 | nbrodin | LoggerFactory.getLogger(getClass()).debug("Transformation error", e);
|
530 | 30 | nbrodin | } |
531 | 1055 | nbrodin | |
532 | 1676 | nbrodin | return buf;
|
533 | 30 | nbrodin | // long t2 = new Date().getTime();
|
534 | // System.out.println("Renderizando Raster: " + ((t2 - t1) / 1000D) + ", secs.");
|
||
535 | } |
||
536 | 210 | nbrodin | |
537 | 234 | nbrodin | /**
|
538 | * Applies filters and transparency on the buffer and returns the grid with the modified buffer.
|
||
539 | * @param buf
|
||
540 | * @param transparency
|
||
541 | * @throws ProcessInterruptedException
|
||
542 | */
|
||
543 | 2315 | nbrodin | private FilterLoader bufferPreprocessing(Buffer buf) throws ProcessInterruptedException { |
544 | 2308 | nbrodin | //Asignamos los datos al objeto transparencia antes de aplicar la pila de filtros para que el valor NoData sea efectivo
|
545 | if (getRenderingTransparency().getNoData().isNoDataTransparent() ||
|
||
546 | getRenderingTransparency().existAlphaBand()) |
||
547 | getRenderingTransparency().setDataBuffer(buf); |
||
548 | else {
|
||
549 | getRenderingTransparency().setDataBuffer(null);
|
||
550 | 234 | nbrodin | } |
551 | 2308 | nbrodin | getRenderingTransparency().activeTransparency(); |
552 | 2328 | nbrodin | List<ROI> roi = null; |
553 | try {
|
||
554 | 2331 | nbrodin | roi = (List<ROI>)dataStore.getRois(lastViewPortData != null ? lastViewPortData.getProjection() : null); |
555 | 2328 | nbrodin | } catch (ROIException e) {
|
556 | } |
||
557 | 234 | nbrodin | |
558 | 2308 | nbrodin | FilterLoader filterLoader = RasterLocator.getManager().createFilterLoader(filterList); |
559 | filterLoader.addSrcBandCount(dataStore.getBandCount()); |
||
560 | filterLoader.addSrcDataType(dataStore.getDataType()[0]);
|
||
561 | filterLoader.addSrcStatistics(dataStore.getStatistics()); |
||
562 | 2328 | nbrodin | filterLoader.addSrcROI(roi); |
563 | 2338 | nbrodin | filterLoader.addSrcHistogram(dataStore.getHistogramComputer()); |
564 | 2308 | nbrodin | filterLoader.addTransparency(getRenderingTransparency()); |
565 | 2315 | nbrodin | filterLoader.applyFilters(buf); |
566 | 2308 | nbrodin | |
567 | 2315 | nbrodin | return filterLoader;
|
568 | 234 | nbrodin | } |
569 | 2308 | nbrodin | |
570 | 242 | nbrodin | /**
|
571 | * When tiles are renderized the color table in each tile could be diferent.
|
||
572 | * In this case the color table must be replaced
|
||
573 | */
|
||
574 | 972 | nbrodin | //@deprecated one color table by tiled layer
|
575 | private void addTileColorTable(ColorTable tileColorTable) { |
||
576 | if(tileColorTable == null) |
||
577 | return;
|
||
578 | else {
|
||
579 | if(filterList.getFilterClassByID("ColorTable") == null) { |
||
580 | try {
|
||
581 | RasterFilterListManager colorTableManager = filterList.getManagerByID("ColorTable");
|
||
582 | Params params = filterList.createEmptyFilterParams(); |
||
583 | params.setParam("colorTable", tileColorTable);
|
||
584 | colorTableManager.addFilter(params); |
||
585 | } catch (FilterManagerException e) {
|
||
586 | e.printStackTrace(); |
||
587 | } catch (FilterTypeException e) {
|
||
588 | e.printStackTrace(); |
||
589 | } |
||
590 | } |
||
591 | } |
||
592 | 242 | nbrodin | } |
593 | |||
594 | 210 | nbrodin | public void endReading() { |
595 | isDrawing = false;
|
||
596 | } |
||
597 | |||
598 | public boolean isReading() { |
||
599 | return isDrawing;
|
||
600 | } |
||
601 | |||
602 | public void setReading(boolean reading) { |
||
603 | isDrawing = reading; |
||
604 | } |
||
605 | |||
606 | 30 | nbrodin | /**
|
607 | * Calculamos la petici?n en coordenadas del mundo real con la transformaci?n del raster. Esto
|
||
608 | * permite obtener las coordenadas de la petici?n con la rotaci?n, si la tiene.
|
||
609 | * @param vp
|
||
610 | 55 | nbrodin | * @param ldatastore
|
611 | 30 | nbrodin | * @return
|
612 | */
|
||
613 | 55 | nbrodin | private Extent request(ViewPortData vp, RasterDataStore ldatastore) {
|
614 | if (ldatastore.isRotated()) {
|
||
615 | 30 | nbrodin | //Obtenemos las cuatro esquinas de la selecci?n que hemos hecho en la vista
|
616 | Point2D ul = new Point2D.Double(vp.getExtent().minX(), vp.getExtent().maxY()); |
||
617 | Point2D ur = new Point2D.Double(vp.getExtent().maxX(), vp.getExtent().maxY()); |
||
618 | Point2D ll = new Point2D.Double(vp.getExtent().minX(), vp.getExtent().minY()); |
||
619 | Point2D lr = new Point2D.Double(vp.getExtent().maxX(), vp.getExtent().minY()); |
||
620 | |||
621 | //Las pasamos a coordenadas pixel del raster
|
||
622 | 55 | nbrodin | ul = ldatastore.worldToRaster(ul); |
623 | ur = ldatastore.worldToRaster(ur); |
||
624 | ll = ldatastore.worldToRaster(ll); |
||
625 | lr = ldatastore.worldToRaster(lr); |
||
626 | 30 | nbrodin | |
627 | //Obtenemos los valores pixel m?ximos y m?nimos para X e Y
|
||
628 | double pxMaxX = Math.max(Math.max(ul.getX(), ur.getX()), Math.max(ll.getX(), lr.getX())); |
||
629 | double pxMaxY = Math.max(Math.max(ul.getY(), ur.getY()), Math.max(ll.getY(), lr.getY())); |
||
630 | double pxMinX = Math.min(Math.min(ul.getX(), ur.getX()), Math.min(ll.getX(), lr.getX())); |
||
631 | double pxMinY = Math.min(Math.min(ul.getY(), ur.getY()), Math.min(ll.getY(), lr.getY())); |
||
632 | |||
633 | //Ajustamos las coordenadas pixel al ?rea m?xima del raster
|
||
634 | pxMinX = Math.max(pxMinX, 0); |
||
635 | pxMinY = Math.max(pxMinY, 0); |
||
636 | 55 | nbrodin | pxMaxX = Math.min(pxMaxX, ldatastore.getWidth());
|
637 | pxMaxY = Math.min(pxMaxY, ldatastore.getHeight());
|
||
638 | 30 | nbrodin | |
639 | //Petici?n en coordenadas pixel
|
||
640 | ulPxRequest = new Point2D.Double(pxMinX, pxMinY); |
||
641 | lrPxRequest = new Point2D.Double(pxMaxX, pxMaxY); |
||
642 | |||
643 | //Calculamos el ancho y alto del buffer sobre el que se escribe la petici?n
|
||
644 | widthImage = ((Math.abs(lrPxRequest.getX() - ulPxRequest.getX()) * vp
|
||
645 | .getWidth()) / Math.abs(pxMaxX - pxMinX));
|
||
646 | heightImage = ((Math.abs(lrPxRequest.getY() - ulPxRequest.getY()) * vp
|
||
647 | .getHeight()) / Math.abs(pxMaxY - pxMinY));
|
||
648 | |||
649 | //Convertimos la petici?n en coordenadas pixel a petici?n en coordenadas reales.
|
||
650 | 55 | nbrodin | Point2D ulWC = ldatastore.rasterToWorld(ulPxRequest);
|
651 | Point2D lrWC = ldatastore.rasterToWorld(lrPxRequest);
|
||
652 | 30 | nbrodin | |
653 | //Ajustamos la petici?n a los limites del raster, teniendo en cuenta la rotaci?n de este.
|
||
654 | return new ExtentImpl(ulWC, lrWC); |
||
655 | } |
||
656 | 374 | nbrodin | Extent adjustedRotedExtent = util.calculateAdjustedView(vp.getExtent(), ldatastore.getAffineTransform(), ldatastore.getWidth(), ldatastore.getHeight()); |
657 | 30 | nbrodin | widthImage = (int)Math.round(Math.abs(adjustedRotedExtent.width() * vp.getMat().getScaleX())); |
658 | heightImage = (int)Math.round(Math.abs(adjustedRotedExtent.height() * vp.getMat().getScaleY())); |
||
659 | Point2D ul = new Point2D.Double(adjustedRotedExtent.getULX(), adjustedRotedExtent.getULY()); |
||
660 | Point2D lr = new Point2D.Double(adjustedRotedExtent.getLRX(), adjustedRotedExtent.getLRY()); |
||
661 | 55 | nbrodin | ul = ldatastore.worldToRaster(ul); |
662 | lr = ldatastore.worldToRaster(lr); |
||
663 | 30 | nbrodin | ulPxRequest = new Point2D.Double(ul.getX(), ul.getY()); |
664 | lrPxRequest = new Point2D.Double(lr.getX(), lr.getY()); |
||
665 | return adjustedRotedExtent;
|
||
666 | } |
||
667 | |||
668 | 164 | nbrodin | public boolean isRenderingAsGray() { |
669 | 2311 | nbrodin | int[] renderBands = getRenderColorInterpretation().buildRenderBands(); |
670 | 2308 | nbrodin | if ((renderBands != null) && (renderBands.length == 3 || renderBands.length == 4) && (renderBands[0] >= 0) && |
671 | 164 | nbrodin | (renderBands[0] == renderBands[1]) && (renderBands[1] == renderBands[2])) |
672 | return true; |
||
673 | return false; |
||
674 | } |
||
675 | 2311 | nbrodin | |
676 | public void setRenderColorInterpretation(ColorInterpretation ci) { |
||
677 | this.renderColorInterpretation = ci;
|
||
678 | } |
||
679 | |||
680 | public ColorInterpretation getRenderColorInterpretation() {
|
||
681 | if(renderColorInterpretation == null) { |
||
682 | //Initializes the color interpretation using the source but if the source does not have
|
||
683 | //it will be figure out depending on the number of bands
|
||
684 | renderColorInterpretation = dataStore.getColorInterpretation(); |
||
685 | if(renderColorInterpretation == null || !renderColorInterpretation.hasInterpretation()) { |
||
686 | switch (dataStore.getBandCount()) {
|
||
687 | case 1: |
||
688 | case 2: |
||
689 | renderColorInterpretation = DataStoreColorInterpretation.createGrayInterpretation(); |
||
690 | break;
|
||
691 | case 3: |
||
692 | renderColorInterpretation = DataStoreColorInterpretation.createRGBInterpretation(); |
||
693 | break;
|
||
694 | case 4: |
||
695 | renderColorInterpretation = DataStoreColorInterpretation.createRGBAInterpretation(); |
||
696 | default:
|
||
697 | renderColorInterpretation = DataStoreColorInterpretation.createRGBInterpretation(); |
||
698 | break;
|
||
699 | } |
||
700 | } else
|
||
701 | renderColorInterpretation = dataStore.getColorInterpretation().cloneColorInterpretation(); |
||
702 | } |
||
703 | return renderColorInterpretation;
|
||
704 | } |
||
705 | |||
706 | 30 | nbrodin | /**
|
707 | * Asigna el n?mero de bandas y el orden de renderizado. Cada posici?n del vector es una banda
|
||
708 | * del buffer y el contenido de esa posici?n es la banda de la imagen que se dibujar?
|
||
709 | * sobre ese buffer. A la hora de renderizar hay que tener en cuenta que solo se renderizan las
|
||
710 | * tres primeras bandas del buffer por lo que solo se tienen en cuenta los tres primeros
|
||
711 | * elementos. Por ejemplo, el array {1, 0, 3} dibujar? sobre el Graphics las bandas 1,0 y 3 de un
|
||
712 | * raster que tiene al menos 4 bandas. La notaci?n con -1 en alguna posici?n del vector solo tiene sentido
|
||
713 | * en la visualizaci?n pero no se puede as?gnar una banda del buffer a null.
|
||
714 | * Algunos ejemplos:
|
||
715 | * <P>
|
||
716 | * {-1, 0, -1} Dibuja la banda 0 del raster en la G de la visualizaci?n.
|
||
717 | * Si replicateBand es true R = G = B sino R = B = 0
|
||
718 | * {1, 0, 3} La R = banda 1 del raster, G = 0 y B = 3
|
||
719 | * {0} La R = banda 0 del raster. Si replicateBand es true R = G = B sino G = B = 0
|
||
720 | * </P>
|
||
721 | *
|
||
722 | *
|
||
723 | * @param renderBands: bandas y su posici?n
|
||
724 | */
|
||
725 | 2311 | nbrodin | /*public void setRenderBands(int[] renderBands) {
|
726 | 30 | nbrodin | if( renderBands[0] != this.renderBands[0] ||
|
727 | renderBands[1] != this.renderBands[1] ||
|
||
728 | 2308 | nbrodin | renderBands[2] != this.renderBands[2] ||
|
729 | renderBands[3] != this.renderBands[3])
|
||
730 | 30 | nbrodin | callVisualPropertyChanged(renderBands);
|
731 | 2308 | nbrodin | |
732 | 30 | nbrodin | this.renderBands = renderBands;
|
733 | if (filterList != null)
|
||
734 | for (int i = 0; i < filterList.lenght(); i++)
|
||
735 | (filterList.get(i)).addParam("renderBands", renderBands);
|
||
736 | }
|
||
737 | 2311 | nbrodin | |
738 | public int[] getRenderBands() {
|
||
739 | return renderBands;
|
||
740 | }*/
|
||
741 | 30 | nbrodin | |
742 | /**
|
||
743 | * Dado que la notaci?n de bandas para renderizado admite posiciones con -1 y la notaci?n del
|
||
744 | * buffer no ya que no tendria sentido. Esta funci?n adapta la primera notaci?n a la segunda
|
||
745 | * para realizar la petici?n setAreaOfInterest y cargar el buffer.
|
||
746 | * @param b Array que indica la posici?n de bandas para el renderizado
|
||
747 | * @return Array que indica la posici?n de bandas para la petici?n
|
||
748 | */
|
||
749 | public int[] formatArrayRenderBand(int[] b) { |
||
750 | int cont = 0; |
||
751 | for(int i = 0; i < b.length; i++) |
||
752 | if(b[i] >= 0) |
||
753 | cont ++; |
||
754 | if(cont <= 0) |
||
755 | return null; |
||
756 | int[] out = new int[cont]; |
||
757 | int pos = 0; |
||
758 | for(int i = 0; i < cont; i++) { |
||
759 | while(b[pos] == -1) |
||
760 | pos ++; |
||
761 | out[i] = b[pos]; |
||
762 | pos ++; |
||
763 | } |
||
764 | return out;
|
||
765 | } |
||
766 | |||
767 | 2308 | nbrodin | public Transparency getRenderingTransparency() { |
768 | 1674 | nbrodin | //If the transparency hasn't been defined yet then we'll take that from the store
|
769 | 2308 | nbrodin | if (renderingTransparency == null) { |
770 | renderingTransparency = dataStore.getTransparency().cloneTransparency(); |
||
771 | renderingTransparency.addPropertyListener(this);
|
||
772 | 1674 | nbrodin | } |
773 | 2311 | nbrodin | renderingTransparency.setColorInterpretation(getRenderColorInterpretation()); |
774 | 2308 | nbrodin | return renderingTransparency;
|
775 | 30 | nbrodin | } |
776 | 722 | nbrodin | |
777 | public int getLastAlphaBandNumber() { |
||
778 | return lastAlphaBand;
|
||
779 | } |
||
780 | 30 | nbrodin | |
781 | 723 | nbrodin | public void setLastTransparency(Transparency lastTransparency) { |
782 | 2308 | nbrodin | this.renderingTransparency = lastTransparency;
|
783 | if(this.renderingTransparency != null) |
||
784 | this.renderingTransparency.addPropertyListener(this); |
||
785 | 30 | nbrodin | } |
786 | |||
787 | public RasterFilterList getFilterList() {
|
||
788 | return filterList;
|
||
789 | } |
||
790 | |||
791 | public void setFilterList(RasterFilterList filterList) { |
||
792 | this.filterList = filterList;
|
||
793 | this.filterList.addFilterListListener(this); |
||
794 | } |
||
795 | |||
796 | public boolean existColorTable() { |
||
797 | 2424 | nbrodin | if(filterList != null) |
798 | 30 | nbrodin | return (filterList.getFilterByBaseClass(ColorTableFilter.class) != null); |
799 | 2424 | nbrodin | else
|
800 | return false; |
||
801 | 30 | nbrodin | } |
802 | 127 | nbrodin | |
803 | public ColorTable getColorTable() {
|
||
804 | if(existColorTable()) {
|
||
805 | RasterFilter f = filterList.getFilterByBaseClass(ColorTableFilter.class); |
||
806 | return ((ColorTableFilter)f).getColorTable();
|
||
807 | } |
||
808 | return null; |
||
809 | } |
||
810 | 30 | nbrodin | |
811 | /**
|
||
812 | * Asigna la factoria de buffer del renderizador
|
||
813 | * @param bf
|
||
814 | */
|
||
815 | 49 | nbrodin | public void setDataSource(RasterDataStore ds) { |
816 | 55 | nbrodin | this.dataStore = ds;
|
817 | 30 | nbrodin | } |
818 | |||
819 | /**
|
||
820 | * Evento activado cuando cambia una propiedad de transparencia.
|
||
821 | */
|
||
822 | public void actionValueChanged(PropertyEvent e) { |
||
823 | callVisualPropertyChanged(new VisualPropertyEvent(e.getSource()));
|
||
824 | } |
||
825 | |||
826 | /**
|
||
827 | * Evento activado cuando cambia la lista de filtros.
|
||
828 | */
|
||
829 | public void filterListChanged(FilterListChangeEvent e) { |
||
830 | callVisualPropertyChanged(new VisualPropertyEvent(e.getSource()));
|
||
831 | } |
||
832 | |||
833 | 1055 | nbrodin | /**
|
834 | * Sets buffers to null
|
||
835 | */
|
||
836 | public void dispose() { |
||
837 | 2308 | nbrodin | if (renderingTransparency != null) |
838 | renderingTransparency.dispose(); |
||
839 | 1055 | nbrodin | if (getFilterList() != null) |
840 | getFilterList().dispose(); |
||
841 | try {
|
||
842 | finalize(); |
||
843 | } catch (Throwable e) { |
||
844 | } |
||
845 | } |
||
846 | |||
847 | protected void finalize() throws Throwable { |
||
848 | dataStore = null;
|
||
849 | drawer = null;
|
||
850 | 2314 | nbrodin | renderingTransparency = null;
|
851 | 1055 | nbrodin | filterList = null;
|
852 | ulPxRequest = null;
|
||
853 | lrPxRequest = null;
|
||
854 | lastGraphics = null;
|
||
855 | lastViewPortData = null;
|
||
856 | viewDimension = null;
|
||
857 | |||
858 | if(visualPropertyListener != null) { |
||
859 | visualPropertyListener.clear(); |
||
860 | visualPropertyListener = null;
|
||
861 | } |
||
862 | super.finalize();
|
||
863 | } |
||
864 | 30 | nbrodin | |
865 | 2328 | nbrodin | //******************************
|
866 | //Persistence
|
||
867 | //******************************
|
||
868 | |||
869 | public static void registerPersistence() { |
||
870 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
871 | DynStruct definition = manager.getDefinition("DefaultRender_Persistent");
|
||
872 | if( definition == null ) { |
||
873 | definition = manager.addDefinition( |
||
874 | DefaultRender.class, |
||
875 | "DefaultRender_Persistent",
|
||
876 | "RasterRendering Persistent definition",
|
||
877 | null,
|
||
878 | null
|
||
879 | ); |
||
880 | |||
881 | definition.addDynFieldObject("lastTransparency")
|
||
882 | .setClassOfValue(Transparency.class)
|
||
883 | .setMandatory(false);
|
||
884 | |||
885 | definition.addDynFieldObject("filterList")
|
||
886 | .setClassOfValue(RasterFilterList.class) |
||
887 | .setMandatory(false);
|
||
888 | |||
889 | definition.addDynFieldList("paramlist")
|
||
890 | 2341 | nbrodin | .setClassOfItems(PersistencyFilterParams.class) |
891 | 2328 | nbrodin | .setMandatory(false);
|
892 | } |
||
893 | } |
||
894 | |||
895 | 2341 | nbrodin | private List<PersistencyFilterParams> listFilterParameters = null; |
896 | 2328 | nbrodin | |
897 | @SuppressWarnings("unchecked") |
||
898 | public void loadFromState(PersistentState state) |
||
899 | throws PersistenceException {
|
||
900 | renderingTransparency = (Transparency)state.get("lastTransparency"); |
||
901 | renderColorInterpretation = renderingTransparency.getColorInterpretation(); |
||
902 | filterList = (RasterFilterList)state.get("filterList");
|
||
903 | listFilterParameters = state.getList("paramlist");
|
||
904 | } |
||
905 | |||
906 | public void saveToState(PersistentState state) throws PersistenceException { |
||
907 | state.set("lastTransparency", getRenderingTransparency());
|
||
908 | state.set("filterList", getFilterList());
|
||
909 | state.set("paramlist", buildPersistencyFilterParamFromFilters());
|
||
910 | } |
||
911 | |||
912 | /**
|
||
913 | * Builds the list of filter parameters to persist
|
||
914 | * @return
|
||
915 | */
|
||
916 | 2341 | nbrodin | private List<PersistencyFilterParams> buildPersistencyFilterParamFromFilters() throws PersistenceException { |
917 | List<PersistencyFilterParams> filters = new ArrayList<PersistencyFilterParams>(); |
||
918 | 2328 | nbrodin | |
919 | for (int i = 0; i < getFilterList().lenght(); i++) { |
||
920 | RasterFilter f = getFilterList().get(i); |
||
921 | Params uipar = f.getUIParams(f.getName()); |
||
922 | 2341 | nbrodin | PersistencyFilterParams param = new PersistencyFilterParams();
|
923 | 2328 | nbrodin | param.setFilterParam(uipar); |
924 | param.setFilterName(f.getName()); |
||
925 | try {
|
||
926 | RasterFilterListManager manager = getFilterList().getManagerByFilterClass(f.getClass()); |
||
927 | param.setManagerExtensionName(manager.getManagerID()); |
||
928 | } catch (FilterManagerException e) {
|
||
929 | throw new PersistenceException("Error getting filter manager ID", e); |
||
930 | } |
||
931 | filters.add(param); |
||
932 | } |
||
933 | return filters;
|
||
934 | } |
||
935 | |||
936 | /**
|
||
937 | * Builds the filters from the list of classes <code>PersistencyFilterParam</code> recovered from a project
|
||
938 | * @param fList
|
||
939 | * @param listFilterUsed
|
||
940 | * @throws PersistenceException
|
||
941 | */
|
||
942 | public void buildFiltersFromPersistencyFilterParam(Statistics stats) throws PersistenceException { |
||
943 | filterList.addEnvParam("SrcStatistics", stats);
|
||
944 | setFilterList(filterList); |
||
945 | |||
946 | ArrayList<Exception> exc = new ArrayList<Exception>(); |
||
947 | for (int i = 0; i < listFilterParameters.size(); i++) { |
||
948 | try {
|
||
949 | 2341 | nbrodin | PersistencyFilterParams pfp = (PersistencyFilterParams) listFilterParameters.get(i); |
950 | if(pfp != null && pfp.getFilterClass() != null && pfp.getFilterParams() != null) { |
||
951 | 2328 | nbrodin | RasterFilterListManager filterManager = filterList.getManagerByFilterClass(pfp.getFilterClass()); |
952 | filterManager.setFilterList(filterList); |
||
953 | if(filterManager != null) |
||
954 | 2341 | nbrodin | filterManager.addFilter(pfp.getFilterClass(), pfp.getFilterParams()); |
955 | 2328 | nbrodin | } |
956 | } catch (FilterTypeException e) {
|
||
957 | exc.add(e); |
||
958 | } catch (FilterManagerException e) {
|
||
959 | exc.add(e); |
||
960 | } |
||
961 | } |
||
962 | |||
963 | if(exc.size() != 0) { |
||
964 | throw new PersistenceException("error_adding_filters", exc.get(0)); |
||
965 | } |
||
966 | } |
||
967 | |||
968 | 30 | nbrodin | } |