root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / render / Rendering.java @ 15778
History | View | Annotate | Download (20.7 KB)
1 | 10740 | nacho | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | */
|
||
19 | package org.gvsig.raster.grid.render; |
||
20 | |||
21 | 12700 | nacho | import java.awt.Dimension; |
22 | 10740 | nacho | import java.awt.Graphics2D; |
23 | import java.awt.Image; |
||
24 | import java.awt.geom.AffineTransform; |
||
25 | import java.awt.geom.NoninvertibleTransformException; |
||
26 | import java.awt.geom.Point2D; |
||
27 | |||
28 | 11076 | nacho | import org.gvsig.raster.buffer.BufferFactory; |
29 | 10939 | nacho | import org.gvsig.raster.dataset.IBuffer; |
30 | 13328 | nacho | import org.gvsig.raster.dataset.IRasterDataSource; |
31 | 13353 | nacho | import org.gvsig.raster.dataset.InvalidSetViewException; |
32 | 10939 | nacho | import org.gvsig.raster.dataset.properties.DatasetColorInterpretation; |
33 | 12383 | nacho | import org.gvsig.raster.datastruct.Extent; |
34 | import org.gvsig.raster.datastruct.ViewPortData; |
||
35 | 10740 | nacho | import org.gvsig.raster.grid.Grid; |
36 | import org.gvsig.raster.grid.GridTransparency; |
||
37 | 12474 | nacho | import org.gvsig.raster.grid.filter.RasterFilter; |
38 | 10740 | nacho | import org.gvsig.raster.grid.filter.RasterFilterList; |
39 | 12700 | nacho | import org.gvsig.raster.util.RasterUtilities; |
40 | 10740 | nacho | /**
|
41 | * Esta clase se encarga de la gesti?n del dibujado de datos le?dos desde la capa
|
||
42 | * "dataaccess" sobre objetos java. Para ello necesita una fuente de datos que tipicamente
|
||
43 | * es un buffer (RasterBuffer) y un objeto que realice la funci?n de escritura de datos a
|
||
44 | 12325 | bsanchez | * partir de un estado inicial.
|
45 | * Esta capa del renderizado gestiona Extents, rotaciones, tama?os de vista pero la escritura
|
||
46 | 10740 | nacho | * de datos desde el buffer al objeto image es llevada a cabo por ImageDrawer.
|
47 | 12325 | bsanchez | *
|
48 | 10740 | nacho | * Par?metros de control de la visualizaci?n:
|
49 | * <UL>
|
||
50 | * <LI>renderBands: Orden de visualizado de las bands.</LI>
|
||
51 | 12325 | bsanchez | * <LI>replicateBands: Para visualizaci?n de raster de una banda. Dice si se replica sobre las otras dos bandas
|
52 | 10740 | nacho | * de visualizaci?n o se ponen a 0.</LI>
|
53 | * <LI>enhanced: aplicaci?n de filtro de realce</LI>
|
||
54 | * <LI>removeEnds: Eliminar extremos en el filtro de realce. Uso del segundo m?ximo y m?nimo</LI>
|
||
55 | * <LI>tailTrim: Aplicacion de recorte de colas en el realce. Es un valor decimal que representa el porcentaje del recorte entre 100.
|
||
56 | * Es decir, 0.1 significa que el recorte es de un 10%</LI>
|
||
57 | * </UL>
|
||
58 | 12325 | bsanchez | *
|
59 | 10740 | nacho | * @author Nacho Brodin (nachobrodin@gmail.com)
|
60 | */
|
||
61 | public class Rendering { |
||
62 | 11942 | bsanchez | |
63 | 10740 | nacho | /**
|
64 | * Grid para la gesti?n del buffer
|
||
65 | */
|
||
66 | private Grid grid = null; |
||
67 | /**
|
||
68 | * Fuente de datos para el renderizado
|
||
69 | */
|
||
70 | 11711 | nacho | private BufferFactory bufferFactory = null; |
71 | 10740 | nacho | /**
|
72 | 12088 | nacho | * Objeto sobre el cual se hace el renderizado
|
73 | */
|
||
74 | private Image geoImage = null; |
||
75 | /**
|
||
76 | * N?mero de bandas a renderizar y en el orden que se har?. Esto es asignado por el
|
||
77 | * usuario de la renderizaci?n.
|
||
78 | */
|
||
79 | private int[] renderBands = {0, 1, 2}; |
||
80 | /**
|
||
81 | * Tiene el comportamiento cuando se tiene un raster con una. Dice si en las otras
|
||
82 | * bandas a renderizar se replica la banda existente o se ponen a 0.
|
||
83 | */
|
||
84 | private boolean replicateBand = false; |
||
85 | 11827 | nacho | |
86 | 12088 | nacho | private ImageDrawer drawer = null; |
87 | /**
|
||
88 | * Ultima transparencia aplicada en la visualizaci?n que es obtenida desde el grid
|
||
89 | */
|
||
90 | private GridTransparency lastTransparency = null; |
||
91 | /**
|
||
92 | * Lista de filtros aplicada en la renderizaci?n
|
||
93 | */
|
||
94 | private RasterFilterList filterList = null; |
||
95 | 11942 | bsanchez | |
96 | |||
97 | 12722 | nacho | private IBuffer lastRenderBuffer = null; |
98 | 12899 | bsanchez | |
99 | 12722 | nacho | /**
|
100 | * Ancho y alto del objeto Image en una petici?n de dibujado a un raster raster
|
||
101 | */
|
||
102 | private double widthImage, heightImage; |
||
103 | 12899 | bsanchez | |
104 | 12723 | nacho | private Point2D ulPxRequest, lrPxRequest; |
105 | 11942 | bsanchez | |
106 | 12088 | nacho | /**
|
107 | * Constructor
|
||
108 | */
|
||
109 | public Rendering() {
|
||
110 | init(); |
||
111 | } |
||
112 | 11942 | bsanchez | |
113 | 10740 | nacho | /**
|
114 | 12325 | bsanchez | * Constructor
|
115 | 10740 | nacho | * @param grid
|
116 | */
|
||
117 | public Rendering(Grid grid) {
|
||
118 | this.grid = grid;
|
||
119 | init(); |
||
120 | } |
||
121 | 11942 | bsanchez | |
122 | 10740 | nacho | /**
|
123 | 12325 | bsanchez | * Constructor
|
124 | 10740 | nacho | * @param grid
|
125 | */
|
||
126 | 11076 | nacho | public Rendering(BufferFactory ds) {
|
127 | 11166 | nacho | this.bufferFactory = ds;
|
128 | 10740 | nacho | init(); |
129 | } |
||
130 | 11942 | bsanchez | |
131 | 10740 | nacho | private void init(){ |
132 | drawer = new ImageDrawer();
|
||
133 | 11942 | bsanchez | |
134 | 10740 | nacho | //---------------------------------------------------
|
135 | //INICIALIZACI?N DE LA INTERPRETACI?N DE COLOR
|
||
136 | 11942 | bsanchez | |
137 | 10740 | nacho | //Inicializaci?n de la asignaci?n de bandas en el renderizado
|
138 | //Leemos el objeto metadata para obtener la interpretaci?n de color asociada al raster
|
||
139 | 13328 | nacho | if (bufferFactory != null && bufferFactory.getDataSource().getDatasetCount() == 1) { |
140 | DatasetColorInterpretation colorInterpr = bufferFactory.getDataSource().getDataset(0)[0].getColorInterpretation(); |
||
141 | 12166 | bsanchez | if (colorInterpr != null) { |
142 | 10740 | nacho | int red = 0, green = 0, blue = 0; |
143 | 12166 | bsanchez | if (colorInterpr.getBand(DatasetColorInterpretation.PAL_BAND) == -1) { |
144 | if (bufferFactory.getBandCount() >= 3) { |
||
145 | 10740 | nacho | green = 1;
|
146 | blue = 2;
|
||
147 | } |
||
148 | 11942 | bsanchez | |
149 | 12166 | bsanchez | if (bufferFactory.getBandCount() == 2) |
150 | 10740 | nacho | green = blue = 1;
|
151 | 11942 | bsanchez | |
152 | 12166 | bsanchez | if (colorInterpr.getBand(DatasetColorInterpretation.RED_BAND) != -1) |
153 | 10740 | nacho | red = colorInterpr.getBand(DatasetColorInterpretation.RED_BAND); |
154 | 12166 | bsanchez | if (colorInterpr.getBand(DatasetColorInterpretation.GREEN_BAND) != -1) |
155 | 10740 | nacho | green = colorInterpr.getBand(DatasetColorInterpretation.GREEN_BAND); |
156 | 12166 | bsanchez | if (colorInterpr.getBand(DatasetColorInterpretation.BLUE_BAND) != -1) |
157 | 10740 | nacho | blue = colorInterpr.getBand(DatasetColorInterpretation.BLUE_BAND); |
158 | 11942 | bsanchez | |
159 | 13616 | nacho | setRenderBands(new int[] { red, green, blue }); |
160 | 10740 | nacho | } |
161 | } |
||
162 | } |
||
163 | } |
||
164 | 11942 | bsanchez | |
165 | 12166 | bsanchez | /**
|
166 | * Dibuja el raster sobre el Graphics. Para ello debemos de pasar el viewPort que corresponde a la
|
||
167 | * vista. Este viewPort es ajustado a los tama?os m?ximos y m?nimos de la imagen por la funci?n
|
||
168 | * calculateNewView. Esta funci?n tambi?n asignar? la vista a los drivers. Posteriormente se calcula
|
||
169 | * el alto y ancho de la imagen a dibujar (wImg, hImg), as? como el punto donde se va a pintar dentro
|
||
170 | * del graphics (pt). Finalmente se llama a updateImage del driver para que pinte y una vez dibujado
|
||
171 | * se pasa a trav?s de la funci?n renderizeRaster que es la encargada de aplicar la pila de filtros
|
||
172 | * sobre el Image que ha devuelto el driver.
|
||
173 | *
|
||
174 | * Para calcular en que coordenada pixel (pt) se empezar? a pintar el BufferedImage con el raster le?do
|
||
175 | * se aplica sobre la esquina superior izquierda de esta la matriz de transformaci?n del ViewPortData
|
||
176 | * pasado vp.mat.transform(pt, pt). Si el raster no est? rotado este punto es el resultante de la
|
||
177 | * funci?n calculateNewView que devuelve la petici?n ajustada al extent de la imagen (sin rotar). Si
|
||
178 | * el raster est? rotado necesitaremos para la transformaci?n el resultado de la funci?n coordULRotateRaster.
|
||
179 | * Lo que hace esta ?ltima es colocar la petici?n que ha sido puesta en coordenadas de la imagen sin rotar
|
||
180 | * (para pedir al driver de forma correcta) otra vez en coordenadas de la imagen rotada (para calcular su
|
||
181 | * posici?n de dibujado).
|
||
182 | *
|
||
183 | * Para dibujar sobre el Graphics2D el raster rotado aplicaremos la matriz de transformaci?n con los
|
||
184 | * par?metros de Shear sobre este Graphics de forma inversa. Como hemos movido el fondo tendremos que
|
||
185 | * recalcular ahora el punto donde se comienza a dibujar aplicandole la transformaci?n sobre este
|
||
186 | * at.inverseTransform(pt, pt);. Finalmente volcamos el BufferedImage sobre el Graphics volviendo a dejar
|
||
187 | * el Graphics en su posici?n original al acabar.
|
||
188 | *
|
||
189 | * @param g Graphics sobre el que se pinta
|
||
190 | * @param vp ViewPort de la extensi?n a dibujar
|
||
191 | 13353 | nacho | * @throws InvalidSetViewException
|
192 | * @throws ArrayIndexOutOfBoundsException
|
||
193 | 12166 | bsanchez | */
|
194 | 13409 | nacho | public synchronized void draw(Graphics2D g, ViewPortData vp) |
195 | throws ArrayIndexOutOfBoundsException, InvalidSetViewException, InterruptedException { |
||
196 | 12166 | bsanchez | geoImage = null;
|
197 | 13328 | nacho | IRasterDataSource dataset = bufferFactory.getDataSource(); |
198 | 12721 | nacho | AffineTransform transf = dataset.getAffineTransform();
|
199 | 12899 | bsanchez | |
200 | 12767 | nacho | if(RasterUtilities.isOutside(vp.getExtent(), dataset.getExtent()))
|
201 | return;
|
||
202 | 12899 | bsanchez | |
203 | 12767 | nacho | Extent adjustedRotedRequest = request(vp, dataset); |
204 | 10740 | nacho | |
205 | 12722 | nacho | if ((widthImage <= 0) || (heightImage <= 0)) |
206 | 12700 | nacho | return;
|
207 | 12899 | bsanchez | |
208 | 12166 | bsanchez | int[] step = null; |
209 | 11942 | bsanchez | |
210 | 12166 | bsanchez | if (bufferFactory != null) { |
211 | if (lastTransparency == null) |
||
212 | 13328 | nacho | lastTransparency = new GridTransparency(bufferFactory.getDataSource().getTransparencyFilesStatus());
|
213 | 12166 | bsanchez | // Asignamos la banda de transparencia si existe esta
|
214 | 13328 | nacho | if (bufferFactory.getDataSource().getTransparencyFilesStatus().existAlphaBand()) {
|
215 | 12166 | bsanchez | // BufferFactory bufferFactoryAlphaBand = new BufferFactory(bufferFactory.getMultiRasterDataset());
|
216 | bufferFactory.setSupersamplingLoadingBuffer(false); // Desactivamos el supersampleo en la carga del buffer. |
||
217 | bufferFactory.setDrawableBands(new int[] { lastTransparency.getAlphaBandNumber(), -1, -1 }); |
||
218 | 12723 | nacho | bufferFactory.setAreaOfInterest(adjustedRotedRequest.getULX(), adjustedRotedRequest.getULY(), adjustedRotedRequest.getLRX(), adjustedRotedRequest.getLRY(), (int)Math.round(widthImage), (int)Math.round(heightImage)); |
219 | 12166 | bsanchez | bufferFactory.setSupersamplingLoadingBuffer(true);
|
220 | lastTransparency.setAlphaBand(bufferFactory.getRasterBuf()); |
||
221 | lastTransparency.activeTransparency(); |
||
222 | } |
||
223 | bufferFactory.setSupersamplingLoadingBuffer(false); // Desactivamos el supersampleo en la carga del buffer. |
||
224 | // En el renderizado ser? ImageDrawer el que se encargue de esta funci?n
|
||
225 | bufferFactory.setDrawableBands(getRenderBands()); |
||
226 | 12723 | nacho | step = bufferFactory.setAreaOfInterest(adjustedRotedRequest.getULX(), adjustedRotedRequest.getULY(), adjustedRotedRequest.getLRX(), adjustedRotedRequest.getLRY(), (int)Math.round(widthImage), (int)Math.round(heightImage)); |
227 | 12166 | bsanchez | bufferFactory.setSupersamplingLoadingBuffer(true);
|
228 | 11942 | bsanchez | |
229 | 12166 | bsanchez | } else
|
230 | return;
|
||
231 | 11942 | bsanchez | |
232 | 12166 | bsanchez | grid = new Grid(bufferFactory, true); |
233 | grid.setTransparency(lastTransparency); |
||
234 | 15778 | nbrodin | filterList.addEnvParam("Transparency", grid.getTransparency());
|
235 | 12166 | bsanchez | if (filterList == null) |
236 | filterList = grid.getFilterList(); |
||
237 | else
|
||
238 | grid.setFilterList(filterList); |
||
239 | 13409 | nacho | |
240 | grid.applyFilters(); |
||
241 | |||
242 | 12721 | nacho | // Objeto con la info de paleta
|
243 | lastRenderBuffer = grid.getRasterBuf(); |
||
244 | drawer.setBuffer(lastRenderBuffer); // Buffer de datos a renderizar
|
||
245 | lastTransparency = grid.getTransparency(); |
||
246 | drawer.setTransparency(lastTransparency); // Objeto con la info de transparencia
|
||
247 | drawer.setStep(step); // Desplazamiento para supersampleo
|
||
248 | 12722 | nacho | drawer.setBufferSize((int)Math.round(widthImage), (int)Math.round(heightImage)); // Ancho y alto del buffer |
249 | 12721 | nacho | drawer.setPixelsToDrawSize(bufferFactory.getNWidth(), bufferFactory.getNHeight()); // Ancho y alto del buffer
|
250 | geoImage = drawer.drawBufferOverImageObject(replicateBand, getRenderBands()); // Acci?n de renderizado
|
||
251 | 12899 | bsanchez | |
252 | //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
|
||
253 | //transformaci?n. Esto no es necesario hacerlo, sin ello se visualiza igual. Unicamente se hace porque de esta
|
||
254 | 12749 | nacho | //forma el raster resultante mejora un poco en calidad en ciertos niveles de zoom ya que al aplicar transformaciones
|
255 | //sobre el Graphics parece que pierde algo de calidad.
|
||
256 | if(transf.getScaleX() > 0 && transf.getScaleY() < 0 && transf.getShearX() == 0 && transf.getShearY() == 0) { |
||
257 | Point2D pt = new Point2D.Double(adjustedRotedRequest.getULX(), adjustedRotedRequest.getULY()); |
||
258 | vp.mat.transform(pt, pt); |
||
259 | g.drawImage(geoImage, (int) Math.round(pt.getX()), (int) Math.round(pt.getY()), null); |
||
260 | return;
|
||
261 | } |
||
262 | 12899 | bsanchez | |
263 | 12721 | nacho | /*
|
264 | * Tenemos una matriz con la transformaci?n de la coordenadas de la vista a coordenadas reales vp.mat, adem?s tenemos
|
||
265 | * la transformaci?n de coordenadas reales a coordenadas pixel (transf). Con ambas podemos obtener una matriz de trasformacion
|
||
266 | * entre coordenadas de la vista a coordenadas pixel (transf X vp.mat). As? obtenemos la transformaci?n entre coordenadas
|
||
267 | * de la vista y coordenadas pixel del raster. El problemas es que cada zoom la escala de la petici?n del raster varia
|
||
268 | 12899 | bsanchez | * por lo que habr? que calcular una matriz con la escala (escale). escale X transf X vp.mat
|
269 | 12721 | nacho | */
|
270 | 12722 | nacho | double sX = Math.abs(ulPxRequest.getX() - lrPxRequest.getX()) / widthImage; |
271 | double sY = Math.abs(ulPxRequest.getY() - lrPxRequest.getY()) / heightImage; |
||
272 | 12721 | nacho | AffineTransform escale = new AffineTransform(sX, 0, 0, sY, 0, 0); |
273 | 12899 | bsanchez | |
274 | 12166 | bsanchez | try {
|
275 | 12721 | nacho | AffineTransform at = (AffineTransform)escale.clone(); |
276 | at.preConcatenate(transf); |
||
277 | 12722 | nacho | at.preConcatenate(vp.getMat()); |
278 | 12721 | nacho | g.transform(at); |
279 | 12722 | nacho | Point2D.Double pt = null; |
280 | //El punto sobre el que rota la imagen depende del signo de los tama?os del pixel
|
||
281 | 12899 | bsanchez | if(transf.getScaleX() < 0 && transf.getScaleY() < 0) |
282 | 12722 | nacho | pt = new Point2D.Double(adjustedRotedRequest.maxX(), adjustedRotedRequest.maxY()); |
283 | 12899 | bsanchez | else if(transf.getScaleX() > 0 && transf.getScaleY() > 0) |
284 | 12722 | nacho | pt = new Point2D.Double(adjustedRotedRequest.minX(), adjustedRotedRequest.minY()); |
285 | 12899 | bsanchez | else if(transf.getScaleX() < 0 && transf.getScaleY() > 0) |
286 | 12722 | nacho | pt = new Point2D.Double(adjustedRotedRequest.maxX(), adjustedRotedRequest.minY()); |
287 | 12749 | nacho | else
|
288 | 12736 | nacho | pt = new Point2D.Double(adjustedRotedRequest.getULX(), adjustedRotedRequest.getULY()); |
289 | 12722 | nacho | vp.getMat().transform(pt, pt); |
290 | 12899 | bsanchez | at.inverseTransform(pt, pt); |
291 | 12722 | nacho | g.drawImage(geoImage, (int) Math.round(pt.getX()), (int) Math.round(pt.getY()), null); |
292 | 12721 | nacho | g.transform(at.createInverse()); |
293 | } catch (NoninvertibleTransformException e) { |
||
294 | e.printStackTrace(); |
||
295 | } |
||
296 | 12899 | bsanchez | |
297 | 12721 | nacho | // long t2 = new Date().getTime();
|
298 | // System.out.println("Renderizando Raster: " + ((t2 - t1) / 1000D) + ", secs.");
|
||
299 | } |
||
300 | 12899 | bsanchez | |
301 | 12166 | bsanchez | /**
|
302 | 12700 | nacho | * Calculamos la petici?n en coordenadas del mundo real con la transformaci?n del raster. Esto
|
303 | * permite obtener las coordenadas de la petici?n con la rotaci?n, si la tiene.
|
||
304 | * @param vp
|
||
305 | * @param dataset
|
||
306 | * @return
|
||
307 | */
|
||
308 | 13328 | nacho | private Extent request(ViewPortData vp, IRasterDataSource dataset) {
|
309 | 12700 | nacho | if (dataset.isRotated()) {
|
310 | 12899 | bsanchez | //Obtenemos las cuatro esquinas de la selecci?n que hemos hecho en la vista
|
311 | 12700 | nacho | Point2D ul = new Point2D.Double(vp.getExtent().minX(), vp.getExtent().maxY()); |
312 | Point2D ur = new Point2D.Double(vp.getExtent().maxX(), vp.getExtent().maxY()); |
||
313 | Point2D ll = new Point2D.Double(vp.getExtent().minX(), vp.getExtent().minY()); |
||
314 | Point2D lr = new Point2D.Double(vp.getExtent().maxX(), vp.getExtent().minY()); |
||
315 | |||
316 | //Las pasamos a coordenadas pixel del raster
|
||
317 | ul = dataset.worldToRaster(ul); |
||
318 | ur = dataset.worldToRaster(ur); |
||
319 | ll = dataset.worldToRaster(ll); |
||
320 | lr = dataset.worldToRaster(lr); |
||
321 | |||
322 | //Obtenemos los valores pixel m?ximos y m?nimos para X e Y
|
||
323 | double pxMaxX = Math.max(Math.max(ul.getX(), ur.getX()), Math.max(ll.getX(), lr.getX())); |
||
324 | double pxMaxY = Math.max(Math.max(ul.getY(), ur.getY()), Math.max(ll.getY(), lr.getY())); |
||
325 | double pxMinX = Math.min(Math.min(ul.getX(), ur.getX()), Math.min(ll.getX(), lr.getX())); |
||
326 | double pxMinY = Math.min(Math.min(ul.getY(), ur.getY()), Math.min(ll.getY(), lr.getY())); |
||
327 | 12899 | bsanchez | |
328 | 12722 | nacho | //Ajustamos las coordenadas pixel al ?rea m?xima del raster
|
329 | pxMinX = Math.max(pxMinX, 0); |
||
330 | pxMinY = Math.max(pxMinY, 0); |
||
331 | 13377 | nacho | pxMaxX = Math.min(pxMaxX, dataset.getWidth());
|
332 | pxMaxY = Math.min(pxMaxY, dataset.getHeight());
|
||
333 | 12899 | bsanchez | |
334 | 12700 | nacho | //Petici?n en coordenadas pixel
|
335 | 12722 | nacho | ulPxRequest = new Point2D.Double(pxMinX, pxMinY); |
336 | lrPxRequest = new Point2D.Double(pxMaxX, pxMaxY); |
||
337 | 12899 | bsanchez | |
338 | 12722 | nacho | //Calculamos el ancho y alto del buffer sobre el que se escribe la petici?n
|
339 | widthImage = ((Math.abs(lrPxRequest.getX() - ulPxRequest.getX()) * vp.getWidth()) / Math.abs(ul.getX() - ur.getX())); |
||
340 | heightImage = ((Math.abs(lrPxRequest.getY() - ulPxRequest.getY()) * vp.getHeight()) / Math.abs(ur.getY() - lr.getY())); |
||
341 | 12700 | nacho | |
342 | //Convertimos la petici?n en coordenadas pixel a petici?n en coordenadas reales.
|
||
343 | 12722 | nacho | Point2D ulWC = dataset.rasterToWorld(ulPxRequest);
|
344 | Point2D lrWC = dataset.rasterToWorld(lrPxRequest);
|
||
345 | 12767 | nacho | |
346 | 12700 | nacho | //Ajustamos la petici?n a los limites del raster, teniendo en cuenta la rotaci?n de este.
|
347 | 12722 | nacho | return new Extent(ulWC, lrWC); |
348 | 12700 | nacho | } |
349 | 13377 | nacho | Extent adjustedRotedExtent = RasterUtilities.calculateAdjustedView(vp.getExtent(), dataset.getAffineTransform(), new Dimension((int)dataset.getWidth(), (int)dataset.getHeight())); |
350 | 12749 | nacho | widthImage = (int)Math.abs(adjustedRotedExtent.width() * vp.getMat().getScaleX()); |
351 | heightImage = (int)Math.abs(adjustedRotedExtent.height() * vp.getMat().getScaleY()); |
||
352 | Point2D ul = new Point2D.Double(adjustedRotedExtent.getULX(), adjustedRotedExtent.getULY()); |
||
353 | Point2D lr = new Point2D.Double(adjustedRotedExtent.getLRX(), adjustedRotedExtent.getLRY()); |
||
354 | 12722 | nacho | ul = dataset.worldToRaster(ul); |
355 | lr = dataset.worldToRaster(lr); |
||
356 | ulPxRequest = new Point2D.Double(ul.getX(), ul.getY()); |
||
357 | lrPxRequest = new Point2D.Double(lr.getX(), lr.getY()); |
||
358 | 12749 | nacho | return adjustedRotedExtent;
|
359 | 12700 | nacho | } |
360 | 12899 | bsanchez | |
361 | 12166 | bsanchez | /**
|
362 | * Obtiene el n?mero de bandas y el orden de renderizado. Cada posici?n del
|
||
363 | * vector es una banda del buffer y el contenido de esa posici?n es la banda
|
||
364 | * de la imagen que se dibujar? sobre ese buffer. A la hora de renderizar hay
|
||
365 | * que tener en cuenta que solo se renderizan las tres primeras bandas del
|
||
366 | * buffer por lo que solo se tienen en cuenta los tres primeros elementos. Por
|
||
367 | * ejemplo, el array {1, 0, 3} dibujar? sobre el Graphics las bandas 1,0 y 3
|
||
368 | * de un raster de al menos 4 bandas. La notaci?n con -1 en alguna posici?n
|
||
369 | * del vector solo tiene sentido en la visualizaci?n pero no se puede as?gnar
|
||
370 | * una banda del buffer a null. Algunos ejemplos:
|
||
371 | * <P>
|
||
372 | * {-1, 0, -1} Dibuja la banda 0 del raster en la G de la visualizaci?n. Si
|
||
373 | * replicateBand es true R = G = B sino R = B = 0 {1, 0, 3} La R = banda 1 del
|
||
374 | * raster, G = 0 y B = 3 {0} La R = banda 0 del raster. Si replicateBand es
|
||
375 | * true R = G = B sino G = B = 0
|
||
376 | 10740 | nacho | * </P>
|
377 | 12166 | bsanchez | *
|
378 | * @return bandas y su posici?n
|
||
379 | */
|
||
380 | 10740 | nacho | public int[] getRenderBands() { |
381 | return renderBands;
|
||
382 | } |
||
383 | |||
384 | /**
|
||
385 | 11942 | bsanchez | * Asigna el n?mero de bandas y el orden de renderizado. Cada posici?n del vector es una banda
|
386 | 10740 | nacho | * del buffer y el contenido de esa posici?n es la banda de la imagen que se dibujar?
|
387 | 12325 | bsanchez | * sobre ese buffer. A la hora de renderizar hay que tener en cuenta que solo se renderizan las
|
388 | 10740 | nacho | * tres primeras bandas del buffer por lo que solo se tienen en cuenta los tres primeros
|
389 | * elementos. Por ejemplo, el array {1, 0, 3} dibujar? sobre el Graphics las bandas 1,0 y 3 de un
|
||
390 | * raster que tiene al menos 4 bandas. La notaci?n con -1 en alguna posici?n del vector solo tiene sentido
|
||
391 | * en la visualizaci?n pero no se puede as?gnar una banda del buffer a null.
|
||
392 | * Algunos ejemplos:
|
||
393 | 12325 | bsanchez | * <P>
|
394 | 10740 | nacho | * {-1, 0, -1} Dibuja la banda 0 del raster en la G de la visualizaci?n.
|
395 | * Si replicateBand es true R = G = B sino R = B = 0
|
||
396 | * {1, 0, 3} La R = banda 1 del raster, G = 0 y B = 3
|
||
397 | * {0} La R = banda 0 del raster. Si replicateBand es true R = G = B sino G = B = 0
|
||
398 | * </P>
|
||
399 | 12325 | bsanchez | *
|
400 | *
|
||
401 | 11942 | bsanchez | * @param renderBands: bandas y su posici?n
|
402 | */
|
||
403 | 10740 | nacho | public void setRenderBands(int[] renderBands) { |
404 | this.renderBands = renderBands;
|
||
405 | 13616 | nacho | if(filterList != null) { |
406 | for (int i = 0; i < filterList.lenght(); i++) |
||
407 | ((RasterFilter)filterList.get(i)).addParam("renderBands", renderBands);
|
||
408 | } |
||
409 | 10740 | nacho | } |
410 | |||
411 | /**
|
||
412 | * Dado que la notaci?n de bandas para renderizado admite posiciones con -1 y la notaci?n del
|
||
413 | * buffer no ya que no tendria sentido. Esta funci?n adapta la primera notaci?n a la segunda
|
||
414 | * para realizar la petici?n setAreaOfInterest y cargar el buffer.
|
||
415 | * @param b Array que indica la posici?n de bandas para el renderizado
|
||
416 | * @return Array que indica la posici?n de bandas para la petici?n
|
||
417 | */
|
||
418 | 11711 | nacho | public int[] formatArrayRenderBand(int[] b) { |
419 | 10740 | nacho | int cont = 0; |
420 | for(int i = 0; i < b.length; i++) |
||
421 | if(b[i] >= 0) |
||
422 | cont ++; |
||
423 | if(cont <= 0) |
||
424 | return null; |
||
425 | int[] out = new int[cont]; |
||
426 | int pos = 0; |
||
427 | 11711 | nacho | for(int i = 0; i < cont; i++) { |
428 | 10740 | nacho | while(b[pos] == -1) |
429 | pos ++; |
||
430 | out[i] = b[pos]; |
||
431 | pos ++; |
||
432 | } |
||
433 | return out;
|
||
434 | } |
||
435 | 11942 | bsanchez | |
436 | 10740 | nacho | /**
|
437 | * Obtiene el ?ltimo objeto transparencia aplicado en la renderizaci?n
|
||
438 | * @return GridTransparency
|
||
439 | */
|
||
440 | 11711 | nacho | public GridTransparency getLastTransparency() {
|
441 | 10740 | nacho | return lastTransparency;
|
442 | } |
||
443 | 11942 | bsanchez | |
444 | 12567 | bsanchez | public void setLastTransparency(GridTransparency lastTransparency) { |
445 | this.lastTransparency = lastTransparency;
|
||
446 | } |
||
447 | |||
448 | 10740 | nacho | /**
|
449 | * Obtiene las lista de filtros aplicados en la renderizaci?n
|
||
450 | * @return RasterFilterList
|
||
451 | */
|
||
452 | 11711 | nacho | public RasterFilterList getFilterList() {
|
453 | 10740 | nacho | return filterList;
|
454 | } |
||
455 | 11942 | bsanchez | |
456 | 10930 | nacho | /**
|
457 | * Obtiene el ?ltimo buffer renderizado.
|
||
458 | * @return IBuffer
|
||
459 | */
|
||
460 | public IBuffer getLastRenderBuffer() {
|
||
461 | return this.lastRenderBuffer; |
||
462 | } |
||
463 | 13590 | nacho | |
464 | /**
|
||
465 | * Asigna el ?ltimo renderizado.
|
||
466 | * @param buf
|
||
467 | */
|
||
468 | public void setLastRenderBuffer(IBuffer buf) { |
||
469 | this.lastRenderBuffer = buf;
|
||
470 | } |
||
471 | 11711 | nacho | |
472 | /**
|
||
473 | 11827 | nacho | * Asigna la lista de filtros que se usar? en el renderizado
|
474 | 12325 | bsanchez | * @param RasterFilterList
|
475 | 11711 | nacho | */
|
476 | 11827 | nacho | public void setFilterList(RasterFilterList filterList) { |
477 | this.filterList = filterList;
|
||
478 | 11711 | nacho | } |
479 | 12166 | bsanchez | |
480 | 12035 | nacho | /**
|
481 | * Informa de si el raster tiene tabla de color asociada o no.
|
||
482 | * @return true si tiene tabla de color y false si no la tiene.
|
||
483 | */
|
||
484 | 12166 | bsanchez | public boolean existColorTable() { |
485 | 12899 | bsanchez | return (grid != null && grid.getPalettes() != null && grid.getPalettes()[0] != null); |
486 | 12035 | nacho | } |
487 | 12899 | bsanchez | |
488 | 13243 | jaume | /**
|
489 | * Obtiene el grid asociado al render
|
||
490 | * @return
|
||
491 | */
|
||
492 | 12899 | bsanchez | public Grid getGrid() {
|
493 | return grid;
|
||
494 | } |
||
495 | 13243 | jaume | |
496 | /**
|
||
497 | * Asigna la factoria de buffer del renderizador
|
||
498 | * @param bf
|
||
499 | */
|
||
500 | public void setBufferFactory(BufferFactory bf) { |
||
501 | this.bufferFactory = bf;
|
||
502 | } |
||
503 | 12166 | bsanchez | } |