Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvisg.raster_proyeccion_al_vuelo / org.gvsig.raster.lib / org.gvsig.raster.lib.api / src / main / java / org / gvsig / fmap / dal / coverage / grid / render / Render.java @ 5461

History | View | Annotate | Download (11.8 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.coverage.grid.render;
23

    
24
import java.awt.Graphics2D;
25
import java.awt.geom.Dimension2D;
26

    
27
import org.cresques.cts.ICoordTrans;
28
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
29
import org.gvsig.fmap.dal.coverage.datastruct.ViewPortData;
30
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
31
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
32
import org.gvsig.fmap.dal.coverage.exception.QueryException;
33
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
34
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList;
35
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
36
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
37
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
38
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
39
import org.gvsig.fmap.dal.exception.ReadException;
40
import org.gvsig.tools.dispose.Disposable;
41
import org.gvsig.tools.task.TaskStatus;
42

    
43

    
44

    
45
/**
46
 * Renders a Grid object 
47
 * @author Nacho Brodin (nachobrodin@gmail.com)
48
 */
49
public interface Render extends Runnable, Disposable {
50
        
51
        /**
52
         * Obtiene las lista de filtros aplicados en la renderizaci?n
53
         * @return RasterFilterList
54
         */
55
        public RasterFilterList getFilterList();
56
        
57
        /**
58
         * Asigna la lista de filtros que se usar? en el renderizado
59
         * @param RasterFilterList
60
         */
61
        public void setFilterList(RasterFilterList filterList);
62
        
63
        /**
64
         * Asigna el ?ltimo estado de transparencia de la renderizaci?n.
65
         * @param lastTransparency
66
         */
67
        public void setLastTransparency(Transparency lastTransparency);
68
        
69
        /**
70
         * Obtiene el ?ltimo objeto transparencia aplicado en la renderizaci?n
71
         * @return Transparency
72
         */
73
        public Transparency getRenderingTransparency();
74
        
75
        /**
76
         * Gets the last alpha band number
77
         * @return
78
         */
79
        public int getLastAlphaBandNumber();
80
        
81
        /**
82
         * Informa de si el raster tiene tabla de color asociada o no.
83
         * @return true si tiene tabla de color y false si no la tiene.
84
         */
85
        public boolean existColorTable();
86
        
87
        /**
88
         * Gets a data store
89
         * @return
90
         */
91
        public RasterDataStore getDataStore();
92
        
93
        /**
94
         * Sets a data store
95
         * @param dataStore
96
         */
97
        public void setDataStore(RasterDataStore dataStore);
98
        
99
        /**
100
         * Gets the color table 
101
         * @return 
102
         */
103
        public ColorTable getColorTable();
104
        
105
        /**
106
         * Asigna un listener a la lista que ser? informado cuando cambie una
107
         * propiedad visual en la renderizaci?n.
108
         * @param listener VisualPropertyListener
109
         */
110
        public void addVisualPropertyListener(VisualPropertyListener listener);
111
        
112
        /**
113
         * Devuelve si la asignacion de las bandas a renderizar representa una capa
114
         * en escala de grises
115
         * @return
116
         */
117
        public boolean isRenderingAsGray();
118
        
119
        /**
120
         * Sets the color interpretation to renderize this layer
121
         * @param ci
122
         */
123
        public void setRenderColorInterpretation(ColorInterpretation ci);
124
        
125
        /**
126
         * Gets the color interpretation to renderize this layer
127
         * @return
128
         */
129
        public ColorInterpretation getRenderColorInterpretation();
130

    
131
        /**
132
         * Asigna el n?mero de bandas y el orden de renderizado. Cada posici?n del vector es una banda
133
         * del buffer y el contenido de esa posici?n es la banda de la imagen que se dibujar?
134
         * sobre ese buffer. A la hora de renderizar hay que tener en cuenta que solo se renderizan las
135
         * tres primeras bandas del buffer por lo que solo se tienen en cuenta los tres primeros
136
         * elementos. Por ejemplo, el array {1, 0, 3} dibujar? sobre el Graphics las bandas 1,0 y 3 de un
137
         * raster que tiene al menos 4 bandas. La notaci?n con -1 en alguna posici?n del vector solo tiene sentido
138
         * en la visualizaci?n pero no se puede as?gnar una banda del buffer a null.
139
         * Algunos ejemplos:
140
         * <P>
141
         * {-1, 0, -1} Dibuja la banda 0 del raster en la G de la visualizaci?n.
142
         * Si replicateBand es true R = G = B sino R = B = 0
143
         * {1, 0, 3} La R = banda 1 del raster, G = 0 y B = 3
144
         * {0} La R = banda 0 del raster. Si replicateBand es true R = G = B sino G = B = 0
145
         * </P>
146
         *
147
         *
148
         * @param renderBands: bandas y su posici?n
149
         */
150
        //public void setRenderBands(int[] renderBands);
151
        
152
        /**
153
         * Obtiene el n?mero de bandas y el orden de renderizado. Cada posici?n del
154
         * vector es una banda del buffer y el contenido de esa posici?n es la banda
155
         * de la imagen que se dibujar? sobre ese buffer. A la hora de renderizar hay
156
         * que tener en cuenta que solo se renderizan las tres primeras bandas del
157
         * buffer por lo que solo se tienen en cuenta los tres primeros elementos. Por
158
         * ejemplo, el array {1, 0, 3} dibujar? sobre el Graphics las bandas 1,0 y 3
159
         * de un raster de al menos 4 bandas. La notaci?n con -1 en alguna posici?n
160
         * del vector solo tiene sentido en la visualizaci?n pero no se puede as?gnar
161
         * una banda del buffer a null. Algunos ejemplos:
162
         * <P>
163
         * <UL>
164
         * <LI> {-1, 0, -1} Dibuja la banda 0 del raster en la G de la visualizaci?n. Si
165
         * replicateBand es true R = G = B sino R = B = 0 </LI>
166
         * <LI> {1, 0, 3} La R = banda 1 del raster, G = 0 y B = 3 </LI>
167
         * <LI> {0} La R = banda 0 del raster. Si replicateBand es true R = G = B
168
         * sino G = B = 0</LI>
169
         * </UL>
170
         * </P>
171
         *
172
         * @return bandas y su posici?n
173
         */
174
        //public int[] getRenderBands();
175
        
176
        /**
177
         * Dibuja el raster sobre el Graphics. Para ello debemos de pasar el viewPort que corresponde a la
178
         * vista. Este viewPort es ajustado a los tama?os m?ximos y m?nimos de la imagen por la funci?n
179
         * calculateNewView. Esta funci?n tambi?n asignar? la vista a los drivers. Posteriormente se calcula
180
         * el alto y ancho de la imagen a dibujar (wImg, hImg), as? como el punto donde se va a pintar dentro
181
         * del graphics (pt). Finalmente se llama a updateImage del driver para que pinte y una vez dibujado
182
         * se pasa a trav?s de la funci?n renderizeRaster que es la encargada de aplicar la pila de filtros
183
         * sobre el Image que ha devuelto el driver.
184
         *
185
         * Para calcular en que coordenada pixel (pt) se empezar? a pintar el BufferedImage con el raster le?do
186
         * se aplica sobre la esquina superior izquierda de esta la matriz de transformaci?n del ViewPortData
187
         * pasado vp.mat.transform(pt, pt). Si el raster no est? rotado este punto es el resultante de la
188
         * funci?n calculateNewView que devuelve la petici?n ajustada al extent de la imagen (sin rotar). Si
189
         * el raster est? rotado necesitaremos para la transformaci?n el resultado de la funci?n coordULRotateRaster.
190
         * Lo que hace esta ?ltima es colocar la petici?n que ha sido puesta en coordenadas de la imagen sin rotar
191
         * (para pedir al driver de forma correcta) otra vez en coordenadas de la imagen rotada (para calcular su
192
         * posici?n de dibujado).
193
         *
194
         * Para dibujar sobre el Graphics2D el raster rotado aplicaremos la matriz de transformaci?n con los
195
         * par?metros de Shear sobre este Graphics de forma inversa. Como hemos movido el fondo tendremos que
196
         * recalcular ahora el punto donde se comienza a dibujar aplicandole la transformaci?n sobre este
197
         * at.inverseTransform(pt, pt);. Finalmente volcamos el BufferedImage sobre el Graphics volviendo a dejar
198
         * el Graphics en su posici?n original al acabar.
199
         *
200
         * @param g Graphics sobre el que se pinta
201
         * @param vp ViewPort de la extensi?n a dibujar
202
         * @param taskStatus 
203
         * @throws ProcessInterruptedException 
204
         * @throws QueryException 
205
         */
206
        public Buffer draw(Graphics2D g, ViewPortData vp, TaskStatus taskStatus)
207
                throws QueryException, ProcessInterruptedException;
208
        
209
    /**
210
     * Dibuja la extensi?n del viewport sobre el graphics aplicando la
211
     * transformaci?n que recibe como par?metro.
212
     * 
213
     * @param g
214
     *            Graphics sobre el que se pinta
215
     * @param vp
216
     *            ViewPort de la extensi?n a dibujar
217
     * @param coordTrans
218
     *            Transformaci?n a aplicar sobre el buffer antes de ser
219
     *            dibujado. La transformaci?n ser? valida si tiene como
220
     *            proyecci?n fuente la proyecci?n de la extensi?n del ViewPort y
221
     *            como proyecci?n destino la proyecci?n de la fuente de datos.
222
     * @param taskStatus
223
     *            Objeto compartido para indicar el estado de la tarea
224
     * @return Si el graphics es null, el buffer proyectado justo antes de ser
225
     *         dibujado, en cualquier otro caso un buffer in?til sin datos.
226
     * @throws QueryException
227
     * @throws ProcessInterruptedException
228
     */
229
    public Buffer draw(Graphics2D g, ViewPortData vp, ICoordTrans coordTrans, TaskStatus taskStatus)
230
        throws QueryException, ProcessInterruptedException;
231
        
232
        /**
233
         * Este m?todo dibuja sobre el Graphics a partir de un Viewport sin ajustar. Los tiles que van llegando
234
         * no est?n en el tama?o ajustado sino que llegan en su tama?o origina, tipicamente 256x256 p?xeles. Estos
235
         * son reescalados al ir a dibujarlos sobre el Graphics.
236
         * 
237
         * @param g
238
         * @param vp
239
         * @throws RasterDriverException
240
         * @throws InvalidSetViewException
241
         * @throws ProcessInterruptedException
242
         */
243
        public void drawTiledService(Graphics2D g, ViewPortData vp, Dimension2D viewDimension, TaskStatus status)
244
                throws QueryException, ProcessInterruptedException;
245
        
246
    /**
247
     * Dibuja la extensi?n del viewport de forma teselada sobre el graphics
248
     * aplicando la
249
     * transformaci?n que recibe como par?metro.
250
     * 
251
     * @param g
252
     *            Graphics sobre el que se pinta
253
     * @param vp
254
     *            ViewPort de la extensi?n a dibujar
255
     * @param viewDimension
256
     *            Dimensi?n de la vista
257
     * @param coordTrans
258
     *            Transformaci?n a aplicar sobre el buffer antes de ser
259
     *            dibujado. La transformaci?n ser? valida si tiene como
260
     *            proyecci?n fuente la proyecci?n de la extensi?n del ViewPort y
261
     *            como proyecci?n destino la proyecci?n de la fuente de datos.
262
     * @param status
263
     *            Objeto compartido para indicar el estado de la tarea
264
     * @throws QueryException
265
     * @throws ProcessInterruptedException
266
     */
267
    public void drawTiledService(Graphics2D g, ViewPortData vp, Dimension2D viewDimension,
268
        ICoordTrans coordTrans, TaskStatus status) throws QueryException,
269
        ProcessInterruptedException;
270
        
271
        /**
272
         * <p>
273
         * This method throws the draw call in a Thread. This is useful to draw tiles.
274
         * </p>
275
         * <p>
276
         * Strategy:
277
         * <ul>
278
         * <li>If the image is out of the view the thread won't be thrown</li>
279
         * <li>Throw the thread to draw</li>
280
         * <li>The main thread waits until the secondary thread ends</li>
281
         * <li>When the buffer of a new tile has been received then nextBuffer is called from the store</li>
282
         * <li>When the last tile has been received then endReading is called from the store. This method unlocks the main
283
         * thread and will finish the process</li>
284
         * <li></li>
285
         * </ul> 
286
         * </p>
287
         * 
288
         * @see draw
289
         */
290
        public void drawThread(Graphics2D g, ViewPortData vp);
291
        
292
        /**
293
         * Draws the image with the parameters used in the last drawn. 
294
         * @return
295
         */
296
        public Buffer getLastRenderBuffer()
297
                throws QueryException, ProcessInterruptedException;
298
        
299
        /**
300
         * Sets the view structures to draw
301
         * @param g
302
         * @param vp
303
         */
304
        public void setGraphicInfo(Graphics2D g, ViewPortData vp);
305
        
306
        public void setReading(boolean reading);
307
}