gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib / org.gvsig.raster.cache.lib.impl / src / main / java / org / gvsig / raster / cache / tile / impl / buffer / RasterBuffer.java @ 454
History | View | Annotate | Download (5.9 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.raster.cache.tile.impl.buffer; |
23 |
|
24 |
import java.awt.geom.Rectangle2D; |
25 |
|
26 |
import org.gvsig.raster.cache.tile.buffer.TileBuffer; |
27 |
|
28 |
/**
|
29 |
* Rectangulo de pixeles. Para cada tipo de datos java hay un buffer distinto donde cada elemento es
|
30 |
* accedido de la siguiente forma: [banda][fila][columna]
|
31 |
* m[1][2][0] = cte;-> Sustituye el elemento de la fila 2 de la banda 1 columna 0
|
32 |
* m[1][0] = array; -> Sustituye la fila 0 de la banda 1
|
33 |
* m[0] = matriz cuadrada; -> Sustituye la banda entera.
|
34 |
*
|
35 |
*/
|
36 |
public abstract class RasterBuffer implements TileBuffer { |
37 |
public double noDataValue = -99999;//Double.NaN;// |
38 |
protected int width; |
39 |
protected int height; |
40 |
protected int nBands; |
41 |
protected int dataType; |
42 |
private Rectangle2D dataExtent = null; |
43 |
|
44 |
/**
|
45 |
* Valor con el que se rellena una banda no valida del buffer. Una banda no valida es la que
|
46 |
* no tiene datos asignados y tampoco puede ser null. Todas las bandas no validas de un buffer
|
47 |
* apuntan por referencia a la misma banda.
|
48 |
*/
|
49 |
protected double notValidValue = 0D; |
50 |
|
51 |
/**
|
52 |
* Reserva de memoria para el rasterbuf
|
53 |
* @param dataType Tipo de dato
|
54 |
* @param width Ancho
|
55 |
* @param height Alto
|
56 |
* @param bandNr Numero de bandas
|
57 |
* @param orig
|
58 |
*/
|
59 |
public abstract void malloc(int dataType, int width, int height, int bandNr); |
60 |
|
61 |
/*
|
62 |
* (non-Javadoc)
|
63 |
* @see org.gvsig.fmap.driver.Buffer#getWidth()
|
64 |
*/
|
65 |
public int getWidth() { |
66 |
return width;
|
67 |
} |
68 |
|
69 |
/**
|
70 |
* Gets a bouding box of this buffer
|
71 |
* @return
|
72 |
*/
|
73 |
public Rectangle2D getDataExtent() { |
74 |
return dataExtent;
|
75 |
} |
76 |
|
77 |
/**
|
78 |
* Sets a bounding box of this buffer
|
79 |
* @param r
|
80 |
*/
|
81 |
public void setDataExtent(Rectangle2D r) { |
82 |
this.dataExtent = r;
|
83 |
} |
84 |
|
85 |
/*
|
86 |
* (non-Javadoc)
|
87 |
* @see org.gvsig.fmap.driver.Buffer#getHeight()
|
88 |
*/
|
89 |
public int getHeight() { |
90 |
return height;
|
91 |
} |
92 |
|
93 |
/*
|
94 |
* (non-Javadoc)
|
95 |
* @see org.gvsig.fmap.driver.Buffer#getBandCount()
|
96 |
*/
|
97 |
public int getBandCount() { |
98 |
return nBands;
|
99 |
} |
100 |
|
101 |
/**
|
102 |
* Obtiene el tipo de dato. Los tipos de dato posibles est?n definidos en IRaster.
|
103 |
* @return tipo de datos
|
104 |
*/
|
105 |
public int getDataType() { |
106 |
return dataType;
|
107 |
} |
108 |
|
109 |
/**
|
110 |
* Asigna el tipo de dato. Los tipos de dato posibles est?n definidos en IRaster.
|
111 |
* @param dataType Tipo de dato del buffer
|
112 |
*/
|
113 |
public void setDataType(int dataType) { |
114 |
this.dataType = dataType;
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Obtiene el tama?o del tipo de dato en bytes
|
119 |
* @return Tipo de dato
|
120 |
*/
|
121 |
public int getDataSize() { |
122 |
if (dataType == TYPE_BYTE) {
|
123 |
return 1; |
124 |
} else if ((dataType == TYPE_SHORT) | (dataType == TYPE_USHORT)) { |
125 |
return 2; |
126 |
} else if (dataType == TYPE_INT) { |
127 |
return 4; |
128 |
}else if (dataType == TYPE_FLOAT) { |
129 |
return 8; |
130 |
}else if (dataType == TYPE_DOUBLE) { |
131 |
return 16; |
132 |
} |
133 |
|
134 |
return 0; |
135 |
} |
136 |
|
137 |
/**
|
138 |
* Obtiene el tama?o del buffer
|
139 |
* @return tama?o del buffer
|
140 |
*/
|
141 |
public long sizeof() { |
142 |
return getDataSize() * width * height * nBands;
|
143 |
} |
144 |
|
145 |
|
146 |
/**
|
147 |
* Convierte un tipo de dato a cadena
|
148 |
* @param type Tipo de dato
|
149 |
* @return cadena que representa el tipo de dato
|
150 |
*/
|
151 |
public static String typesToString(int type) { |
152 |
switch (type) {
|
153 |
case RasterBuffer.TYPE_IMAGE:
|
154 |
return new String("Image"); |
155 |
|
156 |
case RasterBuffer.TYPE_BYTE:
|
157 |
return new String("Byte"); |
158 |
|
159 |
case RasterBuffer.TYPE_DOUBLE:
|
160 |
return new String("Double"); |
161 |
|
162 |
case RasterBuffer.TYPE_FLOAT:
|
163 |
return new String("Float"); |
164 |
|
165 |
case RasterBuffer.TYPE_INT:
|
166 |
return new String("Integer"); |
167 |
|
168 |
case RasterBuffer.TYPE_USHORT:
|
169 |
case RasterBuffer.TYPE_SHORT:
|
170 |
return new String("Short"); |
171 |
} |
172 |
|
173 |
return null; |
174 |
} |
175 |
|
176 |
/*
|
177 |
* (non-Javadoc)
|
178 |
* @see org.gvsig.raster.dataset.Buffer#isInside(int, int)
|
179 |
*/
|
180 |
public boolean isInside(int x, int y) { |
181 |
if (x < 0 || y < 0 || x >= getWidth() || y >= getHeight()) |
182 |
return false; |
183 |
return true; |
184 |
} |
185 |
|
186 |
/*
|
187 |
* (non-Javadoc)
|
188 |
* @see org.gvsig.fmap.driver.Buffer#getNoDataValue()
|
189 |
*/
|
190 |
public double getNoDataValue() { |
191 |
return noDataValue;
|
192 |
} |
193 |
|
194 |
/*
|
195 |
* (non-Javadoc)
|
196 |
* @see org.gvsig.fmap.driver.Buffer#getByteNoDataValue()
|
197 |
*/
|
198 |
public byte getByteNoDataValue() { |
199 |
return (byte)noDataValue; |
200 |
} |
201 |
|
202 |
/*
|
203 |
* (non-Javadoc)
|
204 |
* @see org.gvsig.fmap.driver.Buffer#getShortNoDataValue()
|
205 |
*/
|
206 |
public short getShortNoDataValue(){ |
207 |
return (short)noDataValue; |
208 |
} |
209 |
|
210 |
/*
|
211 |
* (non-Javadoc)
|
212 |
* @see org.gvsig.fmap.driver.Buffer#getIntNoDataValue()
|
213 |
*/
|
214 |
public int getIntNoDataValue(){ |
215 |
return (int)noDataValue; |
216 |
} |
217 |
|
218 |
/*
|
219 |
* (non-Javadoc)
|
220 |
* @see org.gvsig.fmap.driver.Buffer#getFloatNoDataValue()
|
221 |
*/
|
222 |
public float getFloatNoDataValue(){ |
223 |
return (float)noDataValue; |
224 |
} |
225 |
|
226 |
/*
|
227 |
* (non-Javadoc)
|
228 |
* @see org.gvsig.fmap.driver.Buffer#setNoDataValue(double)
|
229 |
*/
|
230 |
public void setNoDataValue(double nd){ |
231 |
noDataValue = nd; |
232 |
} |
233 |
|
234 |
/*
|
235 |
* (non-Javadoc)
|
236 |
* @see org.gvsig.fmap.driver.Buffer#getNotValidValue()
|
237 |
*/
|
238 |
public double getNotValidValue(){ |
239 |
return notValidValue;
|
240 |
} |
241 |
|
242 |
/*
|
243 |
* (non-Javadoc)
|
244 |
* @see org.gvsig.fmap.driver.Buffer#setNotValidValue(java.lang.Object)
|
245 |
*/
|
246 |
public void setNotValidValue(double value){ |
247 |
this.notValidValue = value;
|
248 |
} |
249 |
|
250 |
} |