Revision 9523 branches/piloto3d/libraries/libCq CMS for java.old/src/org/cresques/io/data/Grid.java

View differences:

Grid.java
1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3 2
 *
4
 * Copyright (C) 2004-5.
3
 * Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
5 4
 *
6 5
 * This program is free software; you can redistribute it and/or
7 6
 * modify it under the terms of the GNU General Public License
......
16 15
 * You should have received a copy of the GNU General Public License
17 16
 * along with this program; if not, write to the Free Software
18 17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23 18
 */
24 19
package org.cresques.io.data;
25 20

  
26 21
import org.cresques.io.GeoRasterFile;
22
import org.cresques.io.datastruct.Histogram;
23
import org.cresques.io.datastruct.Statistic;
24
import org.cresques.io.exceptions.FileFoundInListException;
25
import org.cresques.px.Extent;
27 26
import org.cresques.px.PxRaster;
27
import org.cresques.util.Utilities;
28 28

  
29
public class Grid{
30
	public Grid(GeoRasterFile[] grf){}
31
	public Grid(GeoRasterFile grf){}
32
	public void addRenderizer(PxRaster pxR){}
33
	public void addFile(GeoRasterFile grf){}
34
	public void removeFile(GeoRasterFile grf){}
29
public class Grid implements IQueryableRaster, IWritableRaster  {
30
	
31
	private GeoRasterMultiFile 		grmf = new GeoRasterMultiFile(null);
32
	private RasterBuf				rasterBuf = null;
33
	private Histogram				histogram = null;
34
	private PxRaster				pxRaster = null;
35
	private Statistic				stats = null;
36
	private int						width = 0;
37
	private int						height = 0;
38
	
39
	private double m_dNoDataValue = -99999; //TODO:temporal
40
	
41
	/**
42
	 * Constructor
43
	 */
44
	public Grid(){}
45
	
46
	/**
47
	 * Constructor
48
	 * @param grf Lista de geoRasterFile
49
	 */
50
	public Grid(GeoRasterFile[] grf){
51
		for(int i = 0; i< grf.length; i++)
52
			addFile(grf[i]);
53
	}
54
	
55
	/**
56
	 * Constructor
57
	 * @param grf GeoRasterFile
58
	 */
59
	public Grid(GeoRasterFile grf){
60
		addFile(grf);
61
	}
62

  
63
	/**
64
	 * Asigna el renderizador para el calculo de histogramas a partir 
65
	 * de la visualizaci?n.
66
	 * @param pxR Renderizador.
67
	 */
68
	public void addRenderizer(PxRaster pxR){
69
		this.pxRaster = pxR;
70
		this.stats = pxR.stats;
71
		this.getHistogram().addRenderizer(pxR);
72
	}
73
	
74
	/**
75
	 * A?ade un GeoRasterFile al Grid
76
	 * @param grf GeoRasterFile a a?adir
77
	 */
78
	public void addFile(GeoRasterFile grf){
79
		try{
80
			grmf.addFile(grf);
81
			width = grf.getWidth();
82
			height = grf.getHeight();
83
		}catch(FileFoundInListException e){
84
			//El fichero est? en la lista por lo que no lo a?adimos
85
		}
86
	}
87
	
88
	/**
89
	 * Elimina un GeoRasterFile del Grid
90
	 * @param grf GeoRasterFile a eliminar
91
	 */
92
	public void removeFile(GeoRasterFile grf){
93
		grmf.removeFile(grf);
94
	}
95
	
96
	/**
97
	 * Obtiene la estructura que contiene la lista de ficheros del Grid
98
	 * @return GeoRasterMultiFile
99
	 */
100
	public GeoRasterMultiFile getGeoRasterMultiFile(){
101
		return grmf;
102
	}
103
	
104
	/**
105
	 * Libera el buffer de memoria
106
	 */
107
	public void free(){
108
		rasterBuf = null;
109
		System.gc();
110
	}
111
	
112
	/**
113
	 * Resetea la asignaci?n de dibujado de las bandas de la imagen
114
	 * sobre el DataImage cuando se hace un update para esta banda.
115
	 */
116
	public void clearDrawableBand(){
117
		for(int i = 0; i< grmf.getFileCount(); i++)
118
			grmf.getBands().clearDrawableBand();
119
	}
120
	
121
	/**
122
	 * Para este GeoRasterFile asigna que bandas se pintaran
123
	 * sobre el RasterBuf cuando se haga un update. Cada posici?n del vector es una banda
124
	 * del rasterBuf y el contenido de esa posici?n es la banda de la imagen que se dibujar?
125
	 * sobre ese RasterBuf.
126
	 * @param drawableBands	.
127
	 */
128
	public void addDrawableBands(int[] drawableBands){
129
		for(int i = 0; i< drawableBands.length; i++)
130
			grmf.getBands().addDrawableBand(i, drawableBands[i]);				
131
	}
132
	
133
	/**
134
	 * Asigna el ?rea de interes en coordenadas del mundo real. Si las coordenadas exceden del tama?o de la imagen
135
	 * estas coordenadas son ajustadas el extent.
136
	 * @param x Coordenada X, esquina superior izquierda
137
	 * @param y Coordenada Y, esquina superior izquierda
138
	 * @param w Ancho del ?rea 
139
	 * @param h Alto del ?rea
140
	 * @throws ArrayIndexOutOfBoundsException
141
	 */
142
	public void setAreaOfInterest(double x, double y, double w, double h) throws ArrayIndexOutOfBoundsException{
143
		Extent ext = new Extent(x, y, x + w, y + h);
144
		ext = Utilities.calculateAdjustedView(ext, grmf.getExtent());
145
		
146
		rasterBuf = grmf.getWindowRaster(x, y, w, h);
147
		//width = rasterBuf.getWidth();
148
		//height = rasterBuf.getHeight();
149
	}
150
	
151
	/**
152
	 * Asigna el ?rea de interes en coordenadas pixel. Si las coordenadas exceden del tama?o de la imagen
153
	 * lanza una excepci?n.
154
	 * @param x Coordenada X, esquina superior izquierda
155
	 * @param y Coordenada Y, esquina superior izquierda
156
	 * @param w Ancho del ?rea 
157
	 * @param h Alto del ?rea
158
	 * @throws ArrayIndexOutOfBoundsException
159
	 */
160
	public void setAreaOfInterest(int x, int y, int w, int h) throws ArrayIndexOutOfBoundsException{
161
		if((x + w) > getWidth() || (y + h) > getHeight())
162
			throw new ArrayIndexOutOfBoundsException("Out of Image");
163
		
164
		rasterBuf = grmf.getWindowRaster(x, y, w, h);
165
		//width = rasterBuf.getWidth();
166
		//height = rasterBuf.getHeight();
167
	}
168
		
169
	/**
170
	 * Ajusta el ?rea del grid a un ancho y un alto dado en pixeles. Este ajuste se har? 
171
	 * en relaci?n a un m?todo de interpolaci?n definido en el par?metro.
172
	 * @param w Ancho de la nueva imagen.
173
	 * @param h Alto de la nueva imagen.
174
	 * @param interpolation M?todo de interpolaci?n que se usar? en el ajuste.
175
	 * @param bands Bandas que se desea en el nuevo RasterBuf ajustado. Si este par?metro es null
176
	 * se usar?n todas las bandas de la imagen.
177
	 */
178
	public void setAdjustedWindow(int w, int h, int interpolationMethod, int[] bands){
179
		if(w == width && h == height)
180
			return;
181
		switch(interpolationMethod){
182
		case IQueryableRaster.INTERPOLATION_NearestNeighbour:
183
				rasterBuf = rasterBuf.adjustRasterNearestNeighbour(w, h, bands);
184
				break;
185
		case IQueryableRaster.INTERPOLATION_Bilinear:
186
				System.out.println("Method not implemented yet");
187
				break;
188
		case IQueryableRaster.INTERPOLATION_InverseDistance:
189
				System.out.println("Method not implemented yet");
190
				break;
191
		case IQueryableRaster.INTERPOLATION_BicubicSpline:
192
				System.out.println("Method not implemented yet");
193
				break;
194
		case IQueryableRaster.INTERPOLATION_BSpline:
195
				System.out.println("Method not implemented yet");
196
				break;
197
		}
198
		//width = rasterBuf.getWidth();
199
		//height = rasterBuf.getHeight();
200
	}
201
	
202
	public RasterBuf getData(int x, int y, int w, int h) {
203

  
204
		return null;
205
	}
206

  
207
	/**
208
	 * Obtiene el tipo de datos del grid.
209
	 * @return entero que representa el tipo de dato de las celdas del grid.
210
	 */
211
	public int getDataType() {
212
		return grmf.getDataType()[0];
213
	}
214

  
215
	/**
216
	 * Obtiene la altura del grid.
217
	 * @return altura en celdas del grid.
218
	 */
219
	public int getHeight() {
220
		return height;
221
	}
222

  
223
	/**
224
	 * Obtiene la anchura del grid.
225
	 * @return anchura en celdas del grid.
226
	 */
227
	public int getWidth() {
228
		return width;
229
	}
230

  
231
	public double getXCellSize() {
232

  
233
		//TODO:remove this
234
		Extent e = grmf.getExtent();
235
		double dCellsize = (e.getMax().getX() - e.getMin().getX() ) / (double) width;
236
		
237
		return dCellsize;
238
		
239
	}
240

  
241
	public double getYCellSize() {
242

  
243
		return 0;
244
	}
245

  
246
	public boolean isNoData(int x, int y, int band) {
247

  
248
		return false;
249
		
250
	}
251
	
252
	public void setNoDataValue(double dNoDataValue){
253
		
254
		//TODO:temporal
255
		m_dNoDataValue = dNoDataValue;
256
	}
257
	
258
	public double getNoDataValue(){
259
		
260
		return m_dNoDataValue;
261
		
262
	}
263

  
264
	public void setDataType(int dt) {
265
		
266
	}
267
	
268
	public int getBandCount(){
269
		if(rasterBuf != null)
270
			return rasterBuf.getBandCount();
271
		else
272
			return this.getGeoRasterMultiFile().getBandCount();
273
	}
274

  
275
	/**
276
	 * Obtiene el buffer de datos del grid
277
	 * @return RasterBuf
278
	 */
279
	public RasterBuf getRasterBuf() {
280
		return rasterBuf;
281
	}
282
	
283
	/**
284
	 * Obtiene el objeto histograma asociado al grid
285
	 * @return
286
	 */
287
	public Histogram getHistogram() {
288
		if(histogram == null)
289
			histogram = new Histogram(this);
290
		
291
		return histogram;
292
	}
293

  
294
	/**
295
	 * Obtiene la clase para estadisticas
296
	 * @return
297
	 */
298
	public Statistic getStatistic() {
299
		return stats;
300
	}
301
	
302
	/**
303
	 * Evalua si una coordenada pixel cae dentro de la imagen.
304
	 * @param x coordenada pixel X
305
	 * @param y coordenada pixel Y
306
	 */
307
	public boolean isPixelInGrid(int x, int y){
308
		return (x >= 0 && y >= 0 && x <= getWidth() && y <= getHeight());
309
	}
310
	
311
	/**
312
	 * Extent del grid
313
	 */
314
	public Extent getExtent(){
315
		return grmf.getExtent();
316
	}
35 317
}
318

  

Also available in: Unified diff