Revision 2438 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/grid/render/DefaultRender.java
DefaultRender.java | ||
---|---|---|
28 | 28 |
import java.awt.geom.NoninvertibleTransformException; |
29 | 29 |
import java.awt.geom.Point2D; |
30 | 30 |
import java.util.ArrayList; |
31 |
import java.util.List; |
|
31 | 32 |
|
32 | 33 |
import org.cresques.cts.ICoordTrans; |
33 | 34 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
... | ... | |
38 | 39 |
import org.gvsig.fmap.dal.coverage.datastruct.ViewPortData; |
39 | 40 |
import org.gvsig.fmap.dal.coverage.exception.FilterManagerException; |
40 | 41 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
41 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
42 | 42 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
43 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
43 |
import org.gvsig.fmap.dal.coverage.exception.QueryException; |
|
44 |
import org.gvsig.fmap.dal.coverage.exception.ROIException; |
|
45 |
import org.gvsig.fmap.dal.coverage.filter.FilterLoader; |
|
44 | 46 |
import org.gvsig.fmap.dal.coverage.grid.FilterListChangeEvent; |
45 | 47 |
import org.gvsig.fmap.dal.coverage.grid.FilterListChangeListener; |
46 |
import org.gvsig.fmap.dal.coverage.grid.Grid; |
|
47 | 48 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
48 | 49 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
49 | 50 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager; |
... | ... | |
54 | 55 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
55 | 56 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
56 | 57 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
58 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
|
57 | 59 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
58 | 60 |
import org.gvsig.fmap.dal.coverage.util.PropertyEvent; |
59 | 61 |
import org.gvsig.fmap.dal.coverage.util.PropertyListener; |
... | ... | |
61 | 63 |
import org.gvsig.raster.cache.tile.Tile; |
62 | 64 |
import org.gvsig.raster.cache.tile.exception.TileGettingException; |
63 | 65 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
64 |
import org.gvsig.raster.impl.buffer.DefaultRasterQuery; |
|
65 | 66 |
import org.gvsig.raster.impl.datastruct.DefaultViewPortData; |
66 | 67 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
67 |
import org.gvsig.raster.impl.grid.GridImpl; |
|
68 | 68 |
import org.gvsig.raster.impl.grid.filter.band.ColorTableFilter; |
69 | 69 |
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation; |
70 |
import org.gvsig.raster.roi.ROI; |
|
71 |
import org.gvsig.raster.util.persistence.PersistencyFilterParams; |
|
70 | 72 |
import org.gvsig.tools.ToolsLocator; |
71 | 73 |
import org.gvsig.tools.dynobject.DynStruct; |
72 | 74 |
import org.gvsig.tools.persistence.PersistenceManager; |
... | ... | |
97 | 99 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
98 | 100 |
*/ |
99 | 101 |
public class DefaultRender implements Render, PropertyListener, FilterListChangeListener, Persistent, TileListener { |
100 |
|
|
101 | 102 |
/** |
102 |
* Grid para la gesti?n del buffer |
|
103 |
*/ |
|
104 |
private Grid grid = null; |
|
105 |
/** |
|
106 | 103 |
* Fuente de datos para el renderizado |
107 | 104 |
*/ |
108 |
private RasterDataStore dataStore = null; |
|
105 |
private RasterDataStore dataStore = null;
|
|
109 | 106 |
/** |
110 | 107 |
* N?mero de bandas a renderizar y en el orden que se har?. Esto es asignado |
111 | 108 |
* por el usuario de la renderizaci?n. |
112 | 109 |
*/ |
113 |
private int[] renderBands = { 0, 1, 2 }; |
|
110 |
ColorInterpretation renderColorInterpretation = null; |
|
111 |
//private int[] renderBands = { 0, 1, 2, 3 }; |
|
114 | 112 |
|
115 |
private ImageDrawerImpl drawer = null; |
|
113 |
private ImageDrawerImpl drawer = null; |
|
114 |
|
|
116 | 115 |
/** |
117 |
* Ultima transparencia aplicada en la visualizaci?n que es obtenida desde el |
|
118 |
* grid |
|
116 |
* |
|
119 | 117 |
*/ |
120 |
private Transparency lastTransparency = null;
|
|
121 |
private int lastAlphaBand = -1; |
|
118 |
private Transparency renderingTransparency = null;
|
|
119 |
private int lastAlphaBand = -1;
|
|
122 | 120 |
|
123 | 121 |
/** |
124 | 122 |
* Lista de filtros aplicada en la renderizaci?n |
... | ... | |
182 | 180 |
return reprojectionOnTheFly != null; |
183 | 181 |
} |
184 | 182 |
|
185 |
/* |
|
186 |
* (non-Javadoc) |
|
187 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#getDataStore() |
|
188 |
*/ |
|
189 | 183 |
public RasterDataStore getDataStore() { |
190 | 184 |
return this.dataStore; |
191 | 185 |
} |
192 | 186 |
|
193 |
/* |
|
194 |
* (non-Javadoc) |
|
195 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#setDataStore(org.gvsig.fmap.dal.coverage.store.RasterDataStore) |
|
196 |
*/ |
|
197 | 187 |
public void setDataStore(RasterDataStore dataStore) { |
198 | 188 |
this.dataStore = dataStore; |
199 | 189 |
init(); |
... | ... | |
204 | 194 |
return; |
205 | 195 |
|
206 | 196 |
drawer = new ImageDrawerImpl(); |
207 |
|
|
208 |
if (dataStore == null) { |
|
209 |
setRenderBands(new int[] { 0, 1, 2 }); |
|
210 |
return; |
|
211 |
} |
|
212 |
|
|
213 |
//Bandas que se dibujan por defecto si la interpretaci?n de color no tiene valores |
|
214 |
switch (dataStore.getBandCount()) { |
|
215 |
case 1: |
|
216 |
setRenderBands(new int[] { 0, 0, 0 }); |
|
217 |
break; |
|
218 |
case 2: |
|
219 |
setRenderBands(new int[] { 0, 1, 1 }); |
|
220 |
break; |
|
221 |
default: |
|
222 |
setRenderBands(new int[] { 0, 1, 2 }); |
|
223 |
break; |
|
224 |
} |
|
225 |
|
|
226 |
//--------------------------------------------------- |
|
227 |
//INICIALIZACI?N DE LA INTERPRETACI?N DE COLOR |
|
228 |
|
|
229 |
//Inicializaci?n de la asignaci?n de bandas en el renderizado |
|
230 |
//Leemos el objeto metadata para obtener la interpretaci?n de color asociada al raster |
|
231 |
|
|
232 |
ColorInterpretation colorInterpr = dataStore.getColorInterpretation(); |
|
233 |
if (colorInterpr != null) |
|
234 |
if (colorInterpr.getBand(DataStoreColorInterpretation.PAL_BAND) == -1) { |
|
235 |
if (colorInterpr.isUndefined()) |
|
236 |
return; |
|
237 |
int[] result = new int[] { -1, -1, -1 }; |
|
238 |
int gray = colorInterpr.getBand(DataStoreColorInterpretation.GRAY_BAND); |
|
239 |
if (gray != -1) |
|
240 |
result[0] = result[1] = result[2] = gray; |
|
241 |
else { |
|
242 |
int r = colorInterpr.getBand(DataStoreColorInterpretation.RED_BAND); |
|
243 |
if (r != -1) |
|
244 |
result[0] = r; |
|
245 |
int g = colorInterpr.getBand(DataStoreColorInterpretation.GREEN_BAND); |
|
246 |
if (g != -1) |
|
247 |
result[1] = g; |
|
248 |
int b = colorInterpr.getBand(DataStoreColorInterpretation.BLUE_BAND); |
|
249 |
if (b != -1) |
|
250 |
result[2] = b; |
|
251 |
} |
|
252 |
setRenderBands(result); |
|
253 |
} |
|
197 |
getRenderColorInterpretation(); |
|
254 | 198 |
} |
255 | 199 |
|
256 | 200 |
/** |
... | ... | |
280 | 224 |
public void run() { |
281 | 225 |
try { |
282 | 226 |
draw(lastGraphics, lastViewPortData, null); |
283 |
} catch (RasterDriverException e) { |
|
284 |
LoggerFactory.getLogger(getClass()).debug("Error reading data", e); |
|
285 |
} catch (InvalidSetViewException e) { |
|
286 |
LoggerFactory.getLogger(getClass()).debug("Invalid view", e); |
|
227 |
} catch (QueryException e) { |
|
228 |
LoggerFactory.getLogger(getClass()).debug("Error in a query", e); |
|
287 | 229 |
} catch (ProcessInterruptedException e) { |
288 | 230 |
} |
289 | 231 |
} |
290 | 232 |
|
291 |
/* |
|
292 |
* (non-Javadoc) |
|
293 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#setGraphicInfo(java.awt.Graphics2D, org.gvsig.fmap.dal.coverage.datastruct.ViewPortData) |
|
294 |
*/ |
|
295 | 233 |
public void setGraphicInfo(Graphics2D g, ViewPortData vp) { |
296 | 234 |
this.lastGraphics = g; |
297 | 235 |
this.lastViewPortData = vp; |
298 | 236 |
} |
299 | 237 |
|
300 |
/* |
|
301 |
* (non-Javadoc) |
|
302 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#drawThread(java.awt.Graphics2D, org.gvsig.fmap.dal.coverage.datastruct.ViewPortData) |
|
303 |
*/ |
|
304 | 238 |
public void drawThread(Graphics2D g, ViewPortData vp) { |
305 | 239 |
//Se dibuja si cae dentro de la vista |
306 | 240 |
if(util.isOutside(vp.getExtent(), dataStore.getExtent())) |
... | ... | |
319 | 253 |
} |
320 | 254 |
} |
321 | 255 |
|
322 |
/* |
|
323 |
* (non-Javadoc) |
|
324 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#draw(java.awt.Graphics2D, org.cresques.geo.ViewPortData) |
|
325 |
*/ |
|
256 |
public synchronized Buffer getLastRenderBuffer() |
|
257 |
throws QueryException, ProcessInterruptedException { |
|
258 |
return draw(null, lastViewPortData, null); |
|
259 |
} |
|
260 |
|
|
326 | 261 |
public synchronized void drawTiledService(Graphics2D g, |
327 | 262 |
ViewPortData vp, |
328 | 263 |
Dimension2D viewDimension, |
329 | 264 |
TaskStatus taskStatus) |
330 |
throws RasterDriverException, InvalidSetViewException, ProcessInterruptedException {
|
|
265 |
throws QueryException, ProcessInterruptedException {
|
|
331 | 266 |
lastGraphics = g; |
332 | 267 |
lastViewPortData = vp; |
333 | 268 |
this.viewDimension = viewDimension; |
334 |
|
|
269 |
int[] renderBands = getRenderColorInterpretation().buildRenderBands(); |
|
270 |
|
|
335 | 271 |
if(util.isOutside(vp.getExtent(), dataStore.getExtent())) { |
336 | 272 |
endReading(); |
337 | 273 |
return; |
338 | 274 |
} |
339 | 275 |
|
340 | 276 |
if (dataStore != null) { |
341 |
if(getLastTransparency().getAlphaBandNumber() == -1) |
|
342 |
getLastTransparency().setTransparencyBand(dataStore.getTransparency().getAlphaBandNumber()); |
|
277 |
lastAlphaBand = getRenderingTransparency().getAlphaBandNumber(); |
|
343 | 278 |
|
344 |
lastAlphaBand = getLastTransparency().getAlphaBandNumber(); |
|
345 |
|
|
346 | 279 |
// Asignamos la banda de transparencia si existe esta |
347 | 280 |
RasterQuery query = getRasterManager().createQuery(); |
348 | 281 |
query.setTaskStatus(taskStatus); |
349 | 282 |
query.setTime(vp.getTime()); |
350 |
query.setSupersamplingLoadingBuffer(false); // Desactivamos el supersampleo en la carga del buffer. |
|
351 |
query.setDrawableBands(getRenderBands()); |
|
352 |
query.setFrameWidth(0); |
|
353 |
query.setAlphaBand(getLastTransparency().getAlphaBandNumber()); |
|
283 |
query.setSupersamplingOption(false); // Desactivamos el supersampleo en la carga del buffer. |
|
284 |
if(dataStore.getColorInterpretation().isRGB()) |
|
285 |
renderBands[3] = 3; |
|
286 |
query.setDrawableBands(renderBands); |
|
287 |
if(dataStore.getDataType()[0] == Buffer.TYPE_BYTE) { |
|
288 |
if(lastAlphaBand != -1) |
|
289 |
query.forceARGBRequest(); |
|
290 |
else if(renderBands.length == 3 || (renderBands.length == 4 && renderBands[3] == -1)) |
|
291 |
query.forceRGBRequest(); |
|
292 |
else |
|
293 |
query.forceARGBRequest(); |
|
294 |
} else |
|
295 |
query.forceRGBRequest(); |
|
354 | 296 |
query.setAreaOfInterest(vp.getExtent(), |
355 | 297 |
(int)Math.round(vp.getWidth()), |
356 | 298 |
(int)Math.round(vp.getHeight()), this); |
357 | 299 |
dataStore.query(query); |
358 |
query.setSupersamplingLoadingBuffer(true);
|
|
300 |
query.setSupersamplingOption(true);
|
|
359 | 301 |
} else |
360 | 302 |
return; |
361 | 303 |
} |
362 | 304 |
|
363 |
public synchronized Buffer getLastRenderBuffer() |
|
364 |
throws RasterDriverException, InvalidSetViewException, ProcessInterruptedException { |
|
365 |
return draw(null, lastViewPortData, null); |
|
305 |
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 |
buf.setDataExtent(e.toRectangle2D()); |
|
334 |
|
|
335 |
Transparency transparencyProcessed = null; |
|
336 |
if(tiling == null || tiling.booleanValue()) { |
|
337 |
try { |
|
338 |
FilterLoader filterLoader = bufferPreprocessing(buf); |
|
339 |
transparencyProcessed = filterLoader.getTransparency(); |
|
340 |
buf = filterLoader.getBufferResult(); |
|
341 |
} 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 |
geoImage.flush(); |
|
386 |
} 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 |
} |
|
366 | 402 |
} |
367 | 403 |
|
368 | 404 |
public synchronized Buffer draw(Graphics2D g, ViewPortData vp, TaskStatus taskStatus) |
369 |
throws RasterDriverException, InvalidSetViewException, ProcessInterruptedException {
|
|
405 |
throws QueryException, ProcessInterruptedException {
|
|
370 | 406 |
lastGraphics = g; |
371 | 407 |
lastViewPortData = vp; |
372 | 408 |
|
... | ... | |
387 | 423 |
|
388 | 424 |
Buffer buf = null; |
389 | 425 |
double[] step = null; |
426 |
int[] renderBands = getRenderColorInterpretation().buildRenderBands(); |
|
390 | 427 |
|
391 | 428 |
if(reprojectionOnTheFly != null) { |
392 | 429 |
buf = reprojectionOnTheFly.warp(adjustedRotedRequest, |
... | ... | |
394 | 431 |
(int)Math.round(heightImage), |
395 | 432 |
vp.getTime(), |
396 | 433 |
renderBands, |
397 |
getLastTransparency());
|
|
434 |
getRenderingTransparency());
|
|
398 | 435 |
} else { |
399 |
// Asignamos la banda de transparencia si existe esta |
|
436 |
lastAlphaBand = getRenderingTransparency().getAlphaBandNumber(); |
|
437 |
|
|
400 | 438 |
RasterQuery query = getRasterManager().createQuery(); |
401 |
//query.setReadOnly(true); |
|
402 |
//query.setMemoryBuffer(true); //Ojo! con buffers remotos |
|
403 | 439 |
query.setTaskStatus(taskStatus); |
404 | 440 |
query.setTime(vp.getTime()); |
405 |
query.setSupersamplingLoadingBuffer(false); // Desactivamos el supersampleo en la carga del buffer. |
|
406 | 441 |
query.setAreaOfInterest(adjustedRotedRequest, (int)Math.round(widthImage), (int)Math.round(heightImage)); |
407 |
|
|
408 |
if (getLastTransparency().getAlphaBandNumber() != -1) { |
|
409 |
query.setDrawableBands(new int[] { getLastTransparency().getAlphaBandNumber()}); |
|
410 |
getLastTransparency().setAlphaBand(dataStore.query(query)); |
|
442 |
query.setDrawableBands(renderBands); |
|
443 |
if(dataStore.getDataType()[0] == Buffer.TYPE_BYTE) { |
|
444 |
if(lastAlphaBand != -1) |
|
445 |
query.forceARGBRequest(); |
|
446 |
else if(renderBands.length == 3 || (renderBands.length == 4 && renderBands[3] == -1)) |
|
447 |
query.forceRGBRequest(); |
|
448 |
} else { |
|
449 |
if(renderBands.length == 4 && renderBands[3] != -1) |
|
450 |
query.forceARGBRequest(); |
|
451 |
else |
|
452 |
query.forceRGBRequest(); |
|
411 | 453 |
} |
412 |
lastAlphaBand = getLastTransparency().getAlphaBandNumber(); |
|
413 |
|
|
414 |
query.setAreaOfInterest(adjustedRotedRequest, (int)Math.round(widthImage), (int)Math.round(heightImage)); |
|
415 |
query.setDrawableBands(getRenderBands()); |
|
416 | 454 |
buf = dataStore.query(query); |
417 |
((DefaultRasterQuery)query).setBuffer(null); |
|
418 |
query.setSupersamplingLoadingBuffer(true); |
|
419 |
step = dataStore.getStep(); |
|
455 |
step = query.getStep(); |
|
420 | 456 |
} |
421 | 457 |
|
422 | 458 |
if(drawer == null) { |
... | ... | |
431 | 467 |
adjustedRotedRequest); |
432 | 468 |
} |
433 | 469 |
|
434 |
/* |
|
435 |
* (non-Javadoc) |
|
436 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#draw(java.awt.Graphics2D, org.cresques.geo.ViewPortData) |
|
437 |
*/ |
|
438 | 470 |
private synchronized Buffer drawBufferOnImage(Graphics2D g, ViewPortData vp, Buffer buf, double[] step, AffineTransform transf, Extent adjustedRotedRequest) |
439 |
throws RasterDriverException, InvalidSetViewException, ProcessInterruptedException { |
|
471 |
throws QueryException, ProcessInterruptedException { |
|
472 |
FilterLoader filterLoader = bufferPreprocessing(buf); |
|
473 |
Transparency transparencyProcessed = filterLoader.getTransparency(); |
|
474 |
buf = filterLoader.getBufferResult(); |
|
440 | 475 |
|
441 |
grid = bufferPreprocessing(buf, lastTransparency); |
|
442 |
|
|
443 |
//Buffer filtrado para renderizar |
|
444 |
buf = grid.getRasterBuf(); |
|
445 | 476 |
if(g == null) |
446 | 477 |
return buf; |
478 |
|
|
447 | 479 |
drawer.setBuffer(buf); // Buffer de datos a renderizar |
448 | 480 |
drawer.setSupersamplingOn(step); // Desplazamiento para supersampleo |
449 | 481 |
drawer.setOutputSize((int)Math.round(widthImage), (int)Math.round(heightImage)); // Ancho y alto del buffer |
450 |
drawer.setLastTransparency(getLastTransparency());
|
|
482 |
drawer.setLastTransparency(transparencyProcessed);
|
|
451 | 483 |
Image geoImage = drawer.drawBufferOverImageObject(); // Acci?n de renderizado |
452 | 484 |
drawer.dispose(); |
453 |
|
|
454 |
// Borramos el buffer de transparencia para que siempre se tenga que regenerar. |
|
455 |
getLastTransparency().setAlphaBand(null); |
|
456 |
|
|
485 |
|
|
457 | 486 |
//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 |
458 | 487 |
//transformaci?n. Esto no es necesario hacerlo, sin ello se visualiza igual. Unicamente se hace porque de esta |
459 | 488 |
//forma el raster resultante mejora un poco en calidad en ciertos niveles de zoom ya que al aplicar transformaciones |
... | ... | |
495 | 524 |
at.inverseTransform(pt, pt); |
496 | 525 |
g.drawImage(geoImage, (int) Math.round(pt.getX()), (int) Math.round(pt.getY()), null); |
497 | 526 |
g.transform(at.createInverse()); |
527 |
geoImage.flush(); |
|
498 | 528 |
} catch (NoninvertibleTransformException e) { |
499 | 529 |
LoggerFactory.getLogger(getClass()).debug("Transformation error", e); |
500 | 530 |
} |
... | ... | |
504 | 534 |
// System.out.println("Renderizando Raster: " + ((t2 - t1) / 1000D) + ", secs."); |
505 | 535 |
} |
506 | 536 |
|
507 |
/* |
|
508 |
* (non-Javadoc) |
|
509 |
* @see org.gvsig.raster.cache.tile.provider.TileListener#tileReady(org.gvsig.raster.cache.tile.Tile) |
|
510 |
*/ |
|
511 |
public synchronized void tileReady(Tile loadedTile) throws TileGettingException { |
|
512 |
boolean crash = false; |
|
513 |
Boolean tiling = (Boolean)loadedTile.getDownloaderParams("Tiling"); |
|
514 |
double[] step = (double[])loadedTile.getDownloaderParams("Step"); |
|
515 |
AffineTransform transf = (AffineTransform)loadedTile.getDownloaderParams("AffineTransform"); |
|
516 |
|
|
517 |
Extent e = getRasterManager().getDataStructFactory(). |
|
518 |
createExtent(loadedTile.getUl().getX(), |
|
519 |
loadedTile.getUl().getY(), |
|
520 |
loadedTile.getLr().getX(), |
|
521 |
loadedTile.getLr().getY()); |
|
522 |
|
|
523 |
Buffer buf = (loadedTile.getData() != null && loadedTile.getData().length > 0) ? (Buffer)loadedTile.getData()[0] : null; |
|
524 |
Buffer transparencyBuffer = (loadedTile.getData() != null && loadedTile.getData().length > 1) |
|
525 |
? (Buffer)loadedTile.getData()[1] : null; |
|
526 |
|
|
527 |
if(!loadedTile.dataIsLoaded()) { |
|
528 |
if(loadedTile.getCrashImage() == null) |
|
529 |
return; |
|
530 |
crash = true; |
|
531 |
buf = (Buffer)loadedTile.getCrashImage()[0]; |
|
532 |
transparencyBuffer = (Buffer)loadedTile.getCrashImage()[1]; |
|
533 |
transparencyBuffer.setDataExtent(e.toRectangle2D()); |
|
534 |
} else { |
|
535 |
if(buf == null) |
|
536 |
return; |
|
537 |
ColorTable tileColorTable = (loadedTile.getData() != null && loadedTile.getData().length > 2) ? (ColorTable)loadedTile.getData()[2] : null; |
|
538 |
if(tiling == null || tiling.booleanValue()) { |
|
539 |
if(filterList != null) |
|
540 |
addTileColorTable(tileColorTable); |
|
541 |
} |
|
542 |
} |
|
543 |
|
|
544 |
if(tiling == null || tiling.booleanValue()) { |
|
545 |
lastTransparency.setAlphaBand(transparencyBuffer); |
|
546 |
Grid grid = null; |
|
547 |
try { |
|
548 |
grid = bufferPreprocessing(buf, lastTransparency); |
|
549 |
} catch (ProcessInterruptedException e3) { |
|
550 |
return; |
|
551 |
} |
|
552 |
buf = grid.getRasterBuf(); |
|
553 |
} |
|
554 |
|
|
555 |
if(tiling == null || tiling.booleanValue()) { |
|
556 |
//Reescalado de los tiles. El tama?o en pixels de un tile no tiene pq coincidir con el de la vista. |
|
557 |
double w = lastViewPortData.getWidth(); |
|
558 |
double h = lastViewPortData.getHeight(); |
|
559 |
if(viewDimension != null) { |
|
560 |
w = viewDimension.getWidth(); |
|
561 |
h = viewDimension.getHeight(); |
|
562 |
} |
|
563 |
double viewScaleW = lastViewPortData.getExtent().width() / w; |
|
564 |
double tileScaleW = e.width() / (double)buf.getWidth(); |
|
565 |
double scaleW = viewScaleW / tileScaleW; |
|
566 |
double viewScaleH = lastViewPortData.getExtent().height() / h; |
|
567 |
double tileScaleH = e.height() / (double)buf.getHeight(); |
|
568 |
double scaleH = viewScaleH / tileScaleH; |
|
569 |
|
|
570 |
ImageDrawerImpl d = new ImageDrawerImpl(); |
|
571 |
d.setBuffer(buf); |
|
572 |
d.setSupersamplingOn(null); |
|
573 |
d.setOutputSize(buf.getWidth(), buf.getHeight()); |
|
574 |
d.setLastTransparency(getLastTransparency()); |
|
575 |
Image geoImage; |
|
576 |
try { |
|
577 |
geoImage = d.drawBufferOverImageObject(); |
|
578 |
} catch (ProcessInterruptedException e2) { |
|
579 |
return; |
|
580 |
} |
|
581 |
d.dispose(); |
|
582 |
|
|
583 |
lastTransparency.setAlphaBand(null); |
|
584 |
|
|
585 |
AffineTransform at = new AffineTransform(); |
|
586 |
at.scale(1/scaleW, 1/scaleH); |
|
587 |
|
|
588 |
try { |
|
589 |
Point2D pt = new Point2D.Double(e.getULX(), e.getULY()); |
|
590 |
((DefaultViewPortData)lastViewPortData).mat.transform(pt, pt); |
|
591 |
at.inverseTransform(pt, pt); |
|
592 |
|
|
593 |
lastGraphics.transform(at); |
|
594 |
lastGraphics.drawImage(geoImage, (int) Math.round(pt.getX()), (int) Math.round(pt.getY()), null); |
|
595 |
lastGraphics.transform(at.createInverse()); |
|
596 |
|
|
597 |
} catch (NoninvertibleTransformException e1) { |
|
598 |
e1.printStackTrace(); |
|
599 |
} |
|
600 |
} else { |
|
601 |
try { |
|
602 |
drawBufferOnImage(lastGraphics, lastViewPortData, buf, step, transf, e); |
|
603 |
} catch (RasterDriverException e1) { |
|
604 |
LoggerFactory.getLogger(getClass()).debug("Error loading data", e1); |
|
605 |
} catch (InvalidSetViewException e1) { |
|
606 |
LoggerFactory.getLogger(getClass()).debug("Invalid view", e1); |
|
607 |
} catch (ProcessInterruptedException e1) { |
|
608 |
} |
|
609 |
} |
|
610 |
|
|
611 |
if(!crash) { //Las im?genes de crash no se liberan ya que est?n en un hashmap global |
|
612 |
if(buf != null) |
|
613 |
buf.dispose(); |
|
614 |
if(transparencyBuffer != null) |
|
615 |
transparencyBuffer.dispose(); |
|
616 |
} |
|
617 |
} |
|
618 |
|
|
619 | 537 |
/** |
620 | 538 |
* Applies filters and transparency on the buffer and returns the grid with the modified buffer. |
621 | 539 |
* @param buf |
622 | 540 |
* @param transparency |
623 | 541 |
* @throws ProcessInterruptedException |
624 | 542 |
*/ |
625 |
private Grid bufferPreprocessing(Buffer buf, Transparency transparency) throws ProcessInterruptedException { |
|
626 |
if (dataStore != null) { |
|
627 |
//Asignamos los datos al objeto transparencia antes de aplicar la pila de filtros para que el valor NoData sea efectivo |
|
628 |
if (dataStore.getTransparency().getNoData().isNoDataTransparent() || transparency.existAlphaBand()) |
|
629 |
transparency.setDataBuffer(buf); |
|
630 |
else { |
|
631 |
transparency.setDataBuffer(null); |
|
632 |
} |
|
633 |
transparency.activeTransparency(); |
|
634 |
} else |
|
635 |
return null; |
|
636 |
|
|
637 |
//Aplicamos los filtros |
|
638 |
grid = new GridImpl(buf, dataStore, true); |
|
639 |
if(filterList != null) { |
|
640 |
filterList.addEnvParam("Transparency", transparency); |
|
641 |
grid.setFilterList(filterList); |
|
642 |
grid.applyFilters(); |
|
543 |
private FilterLoader bufferPreprocessing(Buffer buf) throws ProcessInterruptedException { |
|
544 |
//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); |
|
643 | 550 |
} |
644 |
|
|
645 |
//Si la lista de filtros genera bandas de transparencia se mezclan con la actual |
|
646 |
if(grid.getFilterList().getAlphaBand() != null) { |
|
647 |
Buffer t = grid.getFilterList().getAlphaBand(); |
|
648 |
if(transparency.getAlphaBand() != null) |
|
649 |
t = getRasterManager().getColorConversion().mergeTransparencyBuffers(t, transparency.getAlphaBand()); |
|
650 |
transparency.setAlphaBand(t); |
|
651 |
transparency.activeTransparency(); |
|
551 |
getRenderingTransparency().activeTransparency(); |
|
552 |
List<ROI> roi = null; |
|
553 |
try { |
|
554 |
roi = (List<ROI>)dataStore.getRois(lastViewPortData != null ? lastViewPortData.getProjection() : null); |
|
555 |
} catch (ROIException e) { |
|
652 | 556 |
} |
653 | 557 |
|
654 |
return grid; |
|
558 |
FilterLoader filterLoader = RasterLocator.getManager().createFilterLoader(filterList); |
|
559 |
filterLoader.addSrcBandCount(dataStore.getBandCount()); |
|
560 |
filterLoader.addSrcDataType(dataStore.getDataType()[0]); |
|
561 |
filterLoader.addSrcStatistics(dataStore.getStatistics()); |
|
562 |
filterLoader.addSrcROI(roi); |
|
563 |
filterLoader.addSrcHistogram(dataStore.getHistogramComputer()); |
|
564 |
filterLoader.addTransparency(getRenderingTransparency()); |
|
565 |
filterLoader.applyFilters(buf); |
|
566 |
|
|
567 |
return filterLoader; |
|
655 | 568 |
} |
656 |
|
|
569 |
|
|
657 | 570 |
/** |
658 | 571 |
* When tiles are renderized the color table in each tile could be diferent. |
659 | 572 |
* In this case the color table must be replaced |
... | ... | |
676 | 589 |
} |
677 | 590 |
} |
678 | 591 |
} |
679 |
/*ColorTable colorTable = null; |
|
680 |
if(tileColorTable == null) |
|
681 |
colorTable = dataStore.getColorTable(); |
|
682 |
else |
|
683 |
colorTable = tileColorTable; |
|
684 |
if(colorTable != null) { |
|
685 |
RasterFilterListManager colorTableManager; |
|
686 |
try { |
|
687 |
filterList.remove("enhanced_stretch"); |
|
688 |
colorTableManager = filterList.getManagerByID("ColorTable"); |
|
689 |
Params params = filterList.createEmptyFilterParams(); |
|
690 |
params.setParam("colorTable", colorTable); |
|
691 |
colorTableManager.addFilter(params); |
|
692 |
} catch (FilterManagerException e) { |
|
693 |
e.printStackTrace(); |
|
694 |
} catch (FilterTypeException e) { |
|
695 |
e.printStackTrace(); |
|
696 |
} |
|
697 |
}*/ |
|
698 | 592 |
} |
699 | 593 |
|
700 |
/* |
|
701 |
* (non-Javadoc) |
|
702 |
* @see org.gvsig.raster.impl.grid.render.TileListener#endReading() |
|
703 |
*/ |
|
704 | 594 |
public void endReading() { |
705 | 595 |
isDrawing = false; |
706 | 596 |
} |
707 | 597 |
|
708 |
/* |
|
709 |
* (non-Javadoc) |
|
710 |
* @see org.gvsig.raster.impl.grid.render.TileListener#isReading() |
|
711 |
*/ |
|
712 | 598 |
public boolean isReading() { |
713 | 599 |
return isDrawing; |
714 | 600 |
} |
715 | 601 |
|
716 |
/* |
|
717 |
* (non-Javadoc) |
|
718 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#setReading(boolean) |
|
719 |
*/ |
|
720 | 602 |
public void setReading(boolean reading) { |
721 | 603 |
isDrawing = reading; |
722 | 604 |
} |
... | ... | |
783 | 665 |
return adjustedRotedExtent; |
784 | 666 |
} |
785 | 667 |
|
786 |
/* |
|
787 |
* (non-Javadoc) |
|
788 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#getRenderBands() |
|
789 |
*/ |
|
790 |
public int[] getRenderBands() { |
|
791 |
return renderBands; |
|
792 |
} |
|
793 |
|
|
794 |
/* |
|
795 |
* (non-Javadoc) |
|
796 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#isRenderingAsGray() |
|
797 |
*/ |
|
798 | 668 |
public boolean isRenderingAsGray() { |
799 |
int[] renderBands = getRenderBands(); |
|
800 |
if ((renderBands != null) && (renderBands.length == 3) && (renderBands[0] >= 0) && |
|
669 |
int[] renderBands = getRenderColorInterpretation().buildRenderBands();
|
|
670 |
if ((renderBands != null) && (renderBands.length == 3 || renderBands.length == 4) && (renderBands[0] >= 0) &&
|
|
801 | 671 |
(renderBands[0] == renderBands[1]) && (renderBands[1] == renderBands[2])) |
802 | 672 |
return true; |
803 | 673 |
return false; |
804 | 674 |
} |
805 |
|
|
675 |
|
|
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 |
|
|
806 | 706 |
/** |
807 | 707 |
* Asigna el n?mero de bandas y el orden de renderizado. Cada posici?n del vector es una banda |
808 | 708 |
* del buffer y el contenido de esa posici?n es la banda de la imagen que se dibujar? |
... | ... | |
822 | 722 |
* |
823 | 723 |
* @param renderBands: bandas y su posici?n |
824 | 724 |
*/ |
825 |
public void setRenderBands(int[] renderBands) { |
|
725 |
/*public void setRenderBands(int[] renderBands) {
|
|
826 | 726 |
if( renderBands[0] != this.renderBands[0] || |
827 | 727 |
renderBands[1] != this.renderBands[1] || |
828 |
renderBands[2] != this.renderBands[2]) |
|
728 |
renderBands[2] != this.renderBands[2] || |
|
729 |
renderBands[3] != this.renderBands[3]) |
|
829 | 730 |
callVisualPropertyChanged(renderBands); |
731 |
|
|
830 | 732 |
this.renderBands = renderBands; |
831 | 733 |
if (filterList != null) |
832 | 734 |
for (int i = 0; i < filterList.lenght(); i++) |
833 | 735 |
(filterList.get(i)).addParam("renderBands", renderBands); |
834 | 736 |
} |
737 |
|
|
738 |
public int[] getRenderBands() { |
|
739 |
return renderBands; |
|
740 |
}*/ |
|
835 | 741 |
|
836 | 742 |
/** |
837 | 743 |
* Dado que la notaci?n de bandas para renderizado admite posiciones con -1 y la notaci?n del |
... | ... | |
858 | 764 |
return out; |
859 | 765 |
} |
860 | 766 |
|
861 |
public Transparency getLastTransparency() {
|
|
767 |
public Transparency getRenderingTransparency() {
|
|
862 | 768 |
//If the transparency hasn't been defined yet then we'll take that from the store |
863 |
if (lastTransparency == null) {
|
|
864 |
lastTransparency = dataStore.getTransparency().cloneTransparency();
|
|
865 |
lastTransparency.addPropertyListener(this);
|
|
769 |
if (renderingTransparency == null) {
|
|
770 |
renderingTransparency = dataStore.getTransparency().cloneTransparency();
|
|
771 |
renderingTransparency.addPropertyListener(this);
|
|
866 | 772 |
} |
867 |
return lastTransparency; |
|
773 |
renderingTransparency.setColorInterpretation(getRenderColorInterpretation()); |
|
774 |
return renderingTransparency; |
|
868 | 775 |
} |
869 | 776 |
|
870 |
/* |
|
871 |
* (non-Javadoc) |
|
872 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#getLastAlphaBandNumber() |
|
873 |
*/ |
|
874 | 777 |
public int getLastAlphaBandNumber() { |
875 | 778 |
return lastAlphaBand; |
876 | 779 |
} |
877 | 780 |
|
878 |
/* |
|
879 |
* (non-Javadoc) |
|
880 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#setLastTransparency(org.gvsig.fmap.dal.coverage.store.props.Transparency) |
|
881 |
*/ |
|
882 | 781 |
public void setLastTransparency(Transparency lastTransparency) { |
883 |
this.lastTransparency = lastTransparency;
|
|
884 |
if(this.lastTransparency != null)
|
|
885 |
this.lastTransparency.addPropertyListener(this);
|
|
782 |
this.renderingTransparency = lastTransparency;
|
|
783 |
if(this.renderingTransparency != null)
|
|
784 |
this.renderingTransparency.addPropertyListener(this);
|
|
886 | 785 |
} |
887 | 786 |
|
888 |
/* |
|
889 |
* (non-Javadoc) |
|
890 |
* @see org.gvsig.fmap.dal.coverage.grid.Render#getFilterList() |
|
891 |
*/ |
|
892 | 787 |
public RasterFilterList getFilterList() { |
893 | 788 |
return filterList; |
894 | 789 |
} |
895 | 790 |
|
896 |
/* |
|
897 |
* (non-Javadoc) |
|
898 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#setFilterList(org.gvsig.fmap.dal.coverage.grid.RasterFilterList) |
|
899 |
*/ |
|
900 | 791 |
public void setFilterList(RasterFilterList filterList) { |
901 | 792 |
this.filterList = filterList; |
902 | 793 |
this.filterList.addFilterListListener(this); |
903 | 794 |
} |
904 | 795 |
|
905 |
/* |
|
906 |
* (non-Javadoc) |
|
907 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#existColorTable() |
|
908 |
*/ |
|
909 | 796 |
public boolean existColorTable() { |
797 |
if(filterList != null) |
|
910 | 798 |
return (filterList.getFilterByBaseClass(ColorTableFilter.class) != null); |
799 |
else |
|
800 |
return false; |
|
911 | 801 |
} |
912 | 802 |
|
913 |
/* |
|
914 |
* (non-Javadoc) |
|
915 |
* @see org.gvsig.fmap.dal.coverage.grid.render.Render#getColorTable() |
|
916 |
*/ |
|
917 | 803 |
public ColorTable getColorTable() { |
918 | 804 |
if(existColorTable()) { |
919 | 805 |
RasterFilter f = filterList.getFilterByBaseClass(ColorTableFilter.class); |
... | ... | |
923 | 809 |
} |
924 | 810 |
|
925 | 811 |
/** |
926 |
* Obtiene el grid asociado al render |
|
927 |
* @return |
|
928 |
*/ |
|
929 |
public Grid getGrid() { |
|
930 |
return grid; |
|
931 |
} |
|
932 |
|
|
933 |
/** |
|
934 | 812 |
* Asigna la factoria de buffer del renderizador |
935 | 813 |
* @param bf |
936 | 814 |
*/ |
... | ... | |
951 | 829 |
public void filterListChanged(FilterListChangeEvent e) { |
952 | 830 |
callVisualPropertyChanged(new VisualPropertyEvent(e.getSource())); |
953 | 831 |
} |
954 |
|
|
955 |
/* |
|
956 |
* (non-Javadoc) |
|
957 |
* @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState) |
|
958 |
*/ |
|
959 |
public void loadFromState(PersistentState state) |
|
960 |
throws PersistenceException { |
|
961 |
lastTransparency = (Transparency)state.get("lastTransparency"); |
|
962 |
renderBands = (int[])state.getIntArray("renderBands"); |
|
963 |
//setFilterList((RasterFilterList)state.get("filterList")); |
|
964 |
} |
|
965 |
|
|
966 |
/* |
|
967 |
* (non-Javadoc) |
|
968 |
* @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState) |
|
969 |
*/ |
|
970 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
971 |
state.set("lastTransparency", lastTransparency); |
|
972 |
state.set("renderBands", renderBands); |
|
973 |
//state.set("filterList", filterList); |
|
974 |
} |
|
975 | 832 |
|
976 |
public static void registerPersistence() { |
|
977 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
978 |
DynStruct definition = manager.addDefinition( |
|
979 |
DefaultRender.class, |
|
980 |
"RasterRendering", |
|
981 |
"RasterRendering Persistent definition", |
|
982 |
null, |
|
983 |
null |
|
984 |
); |
|
985 |
definition.addDynFieldObject("lastTransparency").setClassOfValue(Transparency.class).setMandatory(false); |
|
986 |
definition.addDynFieldList("renderBands").setClassOfItems(int.class).setMandatory(false); |
|
987 |
//definition.addDynFieldObject("filterList").setClassOfValue(RasterFilterList.class).setMandatory(false); |
|
988 |
} |
|
989 |
|
|
990 | 833 |
/** |
991 | 834 |
* Sets buffers to null |
992 | 835 |
*/ |
993 | 836 |
public void dispose() { |
994 |
if (lastTransparency != null) |
|
995 |
lastTransparency.dispose(); |
|
996 |
if (grid != null) |
|
997 |
grid.dispose(); |
|
837 |
if (renderingTransparency != null) |
|
838 |
renderingTransparency.dispose(); |
|
998 | 839 |
if (getFilterList() != null) |
999 | 840 |
getFilterList().dispose(); |
1000 | 841 |
try { |
... | ... | |
1003 | 844 |
} |
1004 | 845 |
} |
1005 | 846 |
|
1006 |
/* |
|
1007 |
* (non-Javadoc) |
|
1008 |
* @see java.lang.Object#finalize() |
|
1009 |
*/ |
|
1010 | 847 |
protected void finalize() throws Throwable { |
1011 |
grid = null; |
|
1012 | 848 |
dataStore = null; |
1013 |
renderBands = null; |
|
1014 | 849 |
drawer = null; |
1015 |
lastTransparency = null;
|
|
850 |
renderingTransparency = null;
|
|
1016 | 851 |
filterList = null; |
1017 | 852 |
ulPxRequest = null; |
1018 | 853 |
lrPxRequest = null; |
... | ... | |
1027 | 862 |
super.finalize(); |
1028 | 863 |
} |
1029 | 864 |
|
865 |
//****************************** |
|
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 |
.setClassOfItems(PersistencyFilterParams.class) |
|
891 |
.setMandatory(false); |
|
892 |
} |
|
893 |
} |
|
894 |
|
|
895 |
private List<PersistencyFilterParams> listFilterParameters = null; |
|
896 |
|
|
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 |
private List<PersistencyFilterParams> buildPersistencyFilterParamFromFilters() throws PersistenceException { |
|
917 |
List<PersistencyFilterParams> filters = new ArrayList<PersistencyFilterParams>(); |
|
918 |
|
|
919 |
for (int i = 0; i < getFilterList().lenght(); i++) { |
|
920 |
RasterFilter f = getFilterList().get(i); |
|
921 |
Params uipar = f.getUIParams(f.getName()); |
|
922 |
PersistencyFilterParams param = new PersistencyFilterParams(); |
|
923 |
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 |
PersistencyFilterParams pfp = (PersistencyFilterParams) listFilterParameters.get(i); |
|
950 |
if(pfp != null && pfp.getFilterClass() != null && pfp.getFilterParams() != null) { |
|
951 |
RasterFilterListManager filterManager = filterList.getManagerByFilterClass(pfp.getFilterClass()); |
|
952 |
filterManager.setFilterList(filterList); |
|
953 |
if(filterManager != null) |
|
954 |
filterManager.addFilter(pfp.getFilterClass(), pfp.getFilterParams()); |
|
955 |
} |
|
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 |
|
|
1030 | 968 |
} |
Also available in: Unified diff