Revision 10740
trunk/libraries/libRaster/.cvsignore | ||
---|---|---|
1 |
fmap-raster.jar |
|
2 |
gvRaster.jar |
|
3 |
dist |
|
4 |
bin |
|
5 |
*.tgz |
|
0 | 6 |
trunk/libraries/libRaster/build.xml | ||
---|---|---|
1 |
<project name="Parte raster de FMap" default="generate-without-source" basedir="."> |
|
2 |
<description> |
|
3 |
Instala el plugin en Andami |
|
4 |
</description> |
|
5 |
<!-- set global properties for this build --> |
|
6 |
<property name="src" location="src"/> |
|
7 |
<property name="build" location="bin"/> |
|
8 |
<property name="dist" location="dist"/> |
|
9 |
<property name="lib" location="lib" /> |
|
10 |
<property name="mainplugin" value="com.iver.cit.gvsig"/> |
|
11 |
<property name="andami" location="../_fwAndami"/> |
|
12 |
<property name="extensionsDir" location="${andami}/gvSIG/extensiones"/> |
|
13 |
<property name="drivers-dir" location="${extensionsDir}/${mainplugin}/drivers" /> |
|
14 |
<property name="lib-dir" location="${extensionsDir}/${mainplugin}/lib"/> |
|
15 |
<property name="jarName" location="gvRaster" /> |
|
16 |
<property name="andamiLibs" location="${andami}/lib" /> |
|
17 |
<property name="andamiJar" location="${andami}/andami.jar"/> |
|
18 |
<property name="fmapLibs" location="../libFMap/lib" /> |
|
19 |
<property name="gvsigJar" location="${extensionsDir}/${mainplugin}/lib/${mainplugin}.jar"/> |
|
20 |
<property name="compile-classpath" value="${andamiJar}:${gvsigJar}:${andamiLibs}/beans.jar:${andamiLibs}/castor-0.9.5.3-xml.jar:${fmapLibs}/cms.jar:${fmapLibs}/driver-manager-1.1.jar:${fmapLibs}/fmap.jar:${fmapLibs}/gdbms-0.8-SNAPSHOT.jar:${lib}/gt2-wms.jar:${andamiLibs}/iver-utiles.jar:${fmapLibs}/jts-1.7.jar:${fmapLibs}/kxml2.jar:${andamiLibs}/log4j-1.2.8.jar:${fmapLibs}/remote-clients.jar:${andamiLibs}/tempFileManager.jar" /> |
|
21 |
<!-- ${fmapLibs}/geoapi-2.0.jar:${fmapLibs}/gt2-main.jar --> |
|
22 |
|
|
23 |
<target name="init"> |
|
24 |
<!-- Create the time stamp --> |
|
25 |
<tstamp/> |
|
26 |
<!-- Create the build directory structure used by compile --> |
|
27 |
<mkdir dir="${build}"/> |
|
28 |
<mkdir dir="${dist}"/> |
|
29 |
|
|
30 |
</target> |
|
31 |
|
|
32 |
<target name="generate-without-source" |
|
33 |
description="generate the distribution without the source file" |
|
34 |
depends="gdal"> |
|
35 |
<!-- Create the distribution directory --> |
|
36 |
<mkdir dir="${dist}"/> |
|
37 |
|
|
38 |
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> |
|
39 |
<jar jarfile="${jarName}.jar" basedir="${build}" includes="org/gvsig/raster/**"/> |
|
40 |
|
|
41 |
<copy file="${jarName}.jar" todir="${lib-dir}"/> |
|
42 |
<copy file="${jarName}.jar" todir="${fmapLibs}"/> |
|
43 |
|
|
44 |
<copy todir="${lib-dir}"> |
|
45 |
<fileset dir="./lib" includes="*.jar"/> |
|
46 |
<fileset dir="." includes=".keystore"/> |
|
47 |
</copy> |
|
48 |
<copy todir="${fmapLibs}/"> |
|
49 |
<fileset dir="." includes="${jarName}.jar"/> |
|
50 |
</copy> |
|
51 |
|
|
52 |
</target> |
|
53 |
|
|
54 |
<target name="gdal" depends="" description="Genera el jar del driver de gdal"> |
|
55 |
<mkdir dir="${drivers-dir}/gdal" /> |
|
56 |
<jar jarfile="${drivers-dir}/gdal/gdal.jar" basedir="./bin" includes="org/gvsig/raster/driver/gdal/**" /> |
|
57 |
</target> |
|
58 |
|
|
59 |
<target name="clean" description="clean up" > |
|
60 |
<delete dir="${dist}"/> |
|
61 |
<delete dir="${build}"/> |
|
62 |
</target> |
|
63 |
</project> |
|
64 |
|
|
0 | 65 |
trunk/libraries/libRaster/.classpath | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="src" path="src"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
|
5 |
<classpathentry kind="src" path="src-test"/> |
|
6 |
<classpathentry kind="lib" path="lib/gvsig-i18n.jar"/> |
|
7 |
<classpathentry kind="lib" path="lib/kxml2.jar"/> |
|
8 |
<classpathentry kind="lib" path="lib/jgdal-0.6.0.jar" sourcepath="/libjni-gdal/src"/> |
|
9 |
<classpathentry kind="lib" path="lib/log4j-1.2.8.jar"/> |
|
10 |
<classpathentry kind="lib" path="lib/cms.jar"/> |
|
11 |
<classpathentry kind="lib" path="lib/jecw-0.0.2.jar"/> |
|
12 |
<classpathentry combineaccessrules="false" kind="src" path="/libFMap"/> |
|
13 |
<classpathentry kind="lib" path="lib/driver-manager-1.1.jar"/> |
|
14 |
<classpathentry kind="var" path="JUNIT_HOME/junit.jar" sourcepath="ECLIPSE_HOME/plugins/org.eclipse.jdt.source_3.1.1/src/org.junit_3.8.1/junitsrc.zip"/> |
|
15 |
<classpathentry kind="output" path="bin"/> |
|
16 |
</classpath> |
|
0 | 17 |
trunk/libraries/libRaster/tmp/cache/CacheStruct.java | ||
---|---|---|
1 |
|
|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 |
* |
|
4 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana. |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
*/ |
|
20 |
package org.gvsig.raster.dataaccess.cache; |
|
21 |
|
|
22 |
import org.gvsig.raster.driver.IBuffer; |
|
23 |
import org.gvsig.raster.shared.RasterLibrary; |
|
24 |
|
|
25 |
/** |
|
26 |
* Esta clase representa la estructura en memoria de la cache. Contiene el n?mero de p?ginas |
|
27 |
* as? como los subconjuntos en las que se divide. Tendr? tambi?n datos como en ancho y alto de |
|
28 |
* cada p?gina y tama?o en memoria de esta. |
|
29 |
* |
|
30 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
31 |
* |
|
32 |
*/ |
|
33 |
public class CacheStruct{ |
|
34 |
//******************* PARAMETERS *************************** |
|
35 |
/** |
|
36 |
* Tama?o aproximado de cach? en Megas. Si este valor es alto cabr?n muchas p?ginas en memoria |
|
37 |
* a la vez y si es bajo cabr?n pocas. Hay que tener en cuenta que al instanciar se convertira en bytes |
|
38 |
* para su mejor tratamiento. Al llamar al constructor esta variable contendr? el tama?o exacto |
|
39 |
* de la cache en bytes. El tama?o aqu? especificado es aproximado. Este variar? dependiendo de los |
|
40 |
* par?metros del raster a cachear ya que las p?ginas deben tener una altura potencia de 2. |
|
41 |
*/ |
|
42 |
private long cacheSize = RasterLibrary.cacheSize; |
|
43 |
/** |
|
44 |
* Tama?o m?ximo de la p?gina en Megas. Hay que tener en cuenta que al instanciar se convertira en bytes |
|
45 |
* para su mejor tratamiento. Al llamar al constructor esta variable contendr? el tama?o exacto |
|
46 |
* de la p?gina en bytes |
|
47 |
*/ |
|
48 |
private double pagSize = RasterLibrary.pageSize; |
|
49 |
/** |
|
50 |
* N?mero de p?ginas que tiene cada conjunto |
|
51 |
*/ |
|
52 |
private int pagsPerGroup = RasterLibrary.pagsPerGroup; |
|
53 |
//****************** END PARAMETERS ************************ |
|
54 |
|
|
55 |
private int[] possibleHeights = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536}; |
|
56 |
|
|
57 |
/** |
|
58 |
* Altura de la p?gina en l?neas |
|
59 |
*/ |
|
60 |
private int hPag = 1; |
|
61 |
/** |
|
62 |
* Para extraer el desplazamiento de una direcci?n (l?nea de raster) hay que hacer una operaci?n And con |
|
63 |
* con la altura de la p?gina -1. Por ejemplo, una p?gina de 16 l?neas de altura el desplazamiento ser? |
|
64 |
* 16 - 1 = 15 porque 15 en binario es 1111. |
|
65 |
* |
|
66 |
* Si queremos acceder a la linea del raster n?mero 83 (1010011) realizando la operaci?n And con el valor del |
|
67 |
* desplazamiento obtenemos (0001111 & 1010011 = 0000011), es decir el valor 3 en decimal. Esto quiere decir |
|
68 |
* que la l?nea 83 del raster es la 3 de su p?gina. |
|
69 |
*/ |
|
70 |
private int offset = 1; |
|
71 |
/** |
|
72 |
* N?mero de p?ginas en cach? |
|
73 |
*/ |
|
74 |
private int nPags = 0; |
|
75 |
private int nBands = 0; |
|
76 |
private int nGroups = 0; |
|
77 |
private int bitsPag = 0; |
|
78 |
/** |
|
79 |
* N?mero total de p?ginas en las que se divide el raster |
|
80 |
*/ |
|
81 |
private int nTotalPags = 0; |
|
82 |
|
|
83 |
/** |
|
84 |
* Calcula los par?metros del tama?o de cach? y de p?gina, asi como la altura de las mismas y el n?mero |
|
85 |
* de grupos que salen en cach?. |
|
86 |
* @param nBands N?mero de bandas del raster |
|
87 |
* @param dataType Tipo de dato de la imagen |
|
88 |
* @param dataSourceWidth ancho de cada l?nea completa del raster. |
|
89 |
*/ |
|
90 |
public CacheStruct(int nBands, int dataType, int dataSourceWidth, int dataSourceHeight){ |
|
91 |
this.nBands = nBands; |
|
92 |
cacheSize = cacheSize * 1048576; |
|
93 |
pagSize = pagSize * 1048576; |
|
94 |
|
|
95 |
int dataSize = 0; |
|
96 |
if (dataType == IBuffer.TYPE_BYTE){ |
|
97 |
dataSize = 1; |
|
98 |
} else if ((dataType == IBuffer.TYPE_SHORT) | (dataType == IBuffer.TYPE_USHORT)) { |
|
99 |
dataSize = 2; |
|
100 |
} else if (dataType == IBuffer.TYPE_INT) { |
|
101 |
dataSize = 4; |
|
102 |
} else if (dataType == IBuffer.TYPE_FLOAT) { |
|
103 |
dataSize = 4; |
|
104 |
} else if (dataType == IBuffer.TYPE_DOUBLE) { |
|
105 |
dataSize = 8; |
|
106 |
} |
|
107 |
dataSize *= nBands; |
|
108 |
|
|
109 |
//La altura de la p?gina depende del ancho de esta |
|
110 |
for(int i = (possibleHeights.length - 1); i >= 0; i --){ |
|
111 |
long size = (long)dataSourceWidth * (long)possibleHeights[i] * (long)dataSize; |
|
112 |
if(size <= pagSize){ |
|
113 |
hPag = possibleHeights[i]; |
|
114 |
break; |
|
115 |
} |
|
116 |
} |
|
117 |
//Calculamos el tama?o de p?gina en bytes |
|
118 |
pagSize = dataSourceWidth * hPag * dataSize; |
|
119 |
|
|
120 |
//Calculamos el n?mero de p?ginas que tendr? el buffer completo |
|
121 |
nPags = (int)(cacheSize / pagSize); |
|
122 |
|
|
123 |
while((nPags % pagsPerGroup) != 0) |
|
124 |
nPags ++; |
|
125 |
|
|
126 |
//Recalculamos el tama?o de la cach? |
|
127 |
cacheSize = (long)(pagSize * nPags); |
|
128 |
|
|
129 |
//Calculamos el n?mero de grupos de cach? |
|
130 |
nGroups = (int)(nPags / pagsPerGroup); |
|
131 |
|
|
132 |
int h = hPag; |
|
133 |
while(h > 1){ |
|
134 |
h >>= 1; |
|
135 |
bitsPag ++; |
|
136 |
} |
|
137 |
|
|
138 |
//Calculamos el n?mero total de p?ginas en cach? |
|
139 |
nTotalPags = (int)(dataSourceHeight / hPag); |
|
140 |
if((dataSourceHeight % hPag) != 0) |
|
141 |
nTotalPags ++; |
|
142 |
|
|
143 |
offset = hPag - 1; |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* Obtiene el tama?o de cach? en Bytes |
|
148 |
* @return Tama?o de cach? en Bytes |
|
149 |
*/ |
|
150 |
public long getCacheSize() { |
|
151 |
return cacheSize; |
|
152 |
} |
|
153 |
|
|
154 |
/** |
|
155 |
* Obtiene la altura de la p?gina de cache en l?neas. |
|
156 |
* @return N?mero de l?neas de altura de p?gina. |
|
157 |
*/ |
|
158 |
public int getHPag() { |
|
159 |
return hPag; |
|
160 |
} |
|
161 |
|
|
162 |
/** |
|
163 |
* Obtiene el n?mero de bandas |
|
164 |
* @return N?mero de bandas |
|
165 |
*/ |
|
166 |
public int getNBands() { |
|
167 |
return nBands; |
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* Obtiene el n?mero de p?ginas de la cach? |
|
172 |
* @return N?mero total de p?ginas de la cach? |
|
173 |
*/ |
|
174 |
public int getNPags() { |
|
175 |
return nPags; |
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* Obtiene el tama?o de p?gina en bytes |
|
180 |
* @return Tama?o de p?gina en bytes |
|
181 |
*/ |
|
182 |
public long getPagSize() { |
|
183 |
return (long)pagSize; |
|
184 |
} |
|
185 |
|
|
186 |
/** |
|
187 |
* Obtiene el n?mero de p?ginas que contiene cada grupo. |
|
188 |
* @return N?mero de p?ginas de un grupo. |
|
189 |
*/ |
|
190 |
public int getPagsPerGroup() { |
|
191 |
return pagsPerGroup; |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Obtiene el n?mero de grupos de cach? |
|
196 |
* @return N?mero de grupos |
|
197 |
*/ |
|
198 |
public int getNGroups() { |
|
199 |
return nGroups; |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* Obtiene el n?mero total de p?ginas del raster |
|
204 |
* @return N?mero total de p?ginas |
|
205 |
*/ |
|
206 |
public int getNTotalPags() { |
|
207 |
return nTotalPags; |
|
208 |
} |
|
209 |
|
|
210 |
/** |
|
211 |
* Obtiene el n?mero de bits por p?gina para poder calcular el desplazamiento binario |
|
212 |
* de la direcci?n de acceso de la petici?n. Es decir si se solicita un dato en la l?nea |
|
213 |
* 36 (en decimal) del raster 100100(en binario) y el desplazamiento es 4 bits el n?mero de |
|
214 |
* p?gina resultante ser? 10(en binario) 2 (en decimal) |
|
215 |
* @return |
|
216 |
*/ |
|
217 |
public int getBitsPag() { |
|
218 |
return bitsPag; |
|
219 |
} |
|
220 |
|
|
221 |
/** |
|
222 |
* Imprime la informaci?n de estructura de cach? |
|
223 |
*/ |
|
224 |
public void show(){ |
|
225 |
System.out.println("Cache size:" + cacheSize); |
|
226 |
System.out.println("Pag size:" + pagSize); |
|
227 |
System.out.println("Number of Pags del raster:" + nTotalPags); |
|
228 |
System.out.println("Number of Pags de cache:" + nPags); |
|
229 |
System.out.println("Number of Bands:" + nBands); |
|
230 |
System.out.println("Number of Groups:" + nGroups); |
|
231 |
System.out.println("bits per pag:" + bitsPag); |
|
232 |
System.out.println("Page Height:" + hPag); |
|
233 |
} |
|
234 |
|
|
235 |
/** |
|
236 |
* Para extraer el desplazamiento de una direcci?n (l?nea de raster) hay que hacer una operaci?n And con |
|
237 |
* con la altura de la p?gina -1. Por ejemplo, una p?gina de 16 l?neas de altura el desplazamiento ser? |
|
238 |
* 16 - 1 = 15 porque 15 en binario es 1111. |
|
239 |
* |
|
240 |
* Si queremos acceder a la linea del raster n?mero 83 (1010011) realizando la operaci?n And con el valor del |
|
241 |
* desplazamiento obtenemos (0001111 & 1010011 = 0000011), es decir el valor 3 en decimal. Esto quiere decir |
|
242 |
* que la l?nea 83 del raster es la 3 de su p?gina. |
|
243 |
* @return valor del desplazamiento |
|
244 |
*/ |
|
245 |
public int getOffset() { |
|
246 |
return offset; |
|
247 |
} |
|
248 |
|
|
249 |
} |
|
0 | 250 |
trunk/libraries/libRaster/tmp/cache/InvalidPageNumberException.java | ||
---|---|---|
1 |
package org.gvsig.raster.dataaccess.cache; |
|
2 |
|
|
3 |
/** |
|
4 |
* Excepci?n lanzada cuando el n?mero de p?gina al que se intenta acceder no es valido. |
|
5 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
6 |
* |
|
7 |
*/ |
|
8 |
public class InvalidPageNumberException extends Exception{ |
|
9 |
public InvalidPageNumberException(String msg){ |
|
10 |
super(msg); |
|
11 |
} |
|
12 |
} |
|
0 | 13 |
trunk/libraries/libRaster/tmp/cache/RasterMultiPageCache.java | ||
---|---|---|
1 |
package org.gvsig.raster.dataaccess.cache; |
|
2 |
|
|
3 |
import org.gvsig.raster.dataaccess.buffer.IBand; |
|
4 |
import org.gvsig.raster.dataaccess.buffer.RasterBuffer; |
|
5 |
import org.gvsig.raster.dataaccess.buffer.RasterMemoryBuffer; |
|
6 |
import org.gvsig.raster.driver.IBuffer; |
|
7 |
|
|
8 |
public class RasterMultiPageCache extends RasterBuffer implements IBuffer { |
|
9 |
|
|
10 |
/** |
|
11 |
* Constructor. Asigna las variables de inicializaci?n. |
|
12 |
* @param dataType Tipo de dato |
|
13 |
* @param width Ancho |
|
14 |
* @param height Alto |
|
15 |
* @param bandNr Banda |
|
16 |
* @param orig |
|
17 |
*/ |
|
18 |
public RasterMultiPageCache(int dataType, int width, int height, int nBand){ |
|
19 |
this.dataType = dataType; |
|
20 |
this.width = width; |
|
21 |
this.height = height; |
|
22 |
this.nBands = nBand; |
|
23 |
} |
|
24 |
|
|
25 |
public void malloc(int dataType, int width, int height, int bandNr) { |
|
26 |
} |
|
27 |
|
|
28 |
public void replicateBand(int orig, int dest) { |
|
29 |
} |
|
30 |
|
|
31 |
public void switchBands(int[] bandPosition) { |
|
32 |
} |
|
33 |
|
|
34 |
public RasterBuffer adjustRasterNearestNeighbourInterpolation(int w, int h, int[] bands) { |
|
35 |
return null; |
|
36 |
} |
|
37 |
|
|
38 |
public RasterBuffer adjustRasterBilinearInterpolation(int w, int h, int[] bands) { |
|
39 |
return null; |
|
40 |
} |
|
41 |
|
|
42 |
public RasterBuffer adjustRasterInverseDistanceInterpolation(int w, int h, int[] bands) { |
|
43 |
return null; |
|
44 |
} |
|
45 |
|
|
46 |
public RasterBuffer adjustRasterBicubicSplineInterpolation(int w, int h, int[] bands) { |
|
47 |
return null; |
|
48 |
} |
|
49 |
|
|
50 |
public RasterBuffer adjustRasterBSplineInterpolation(int w, int h, int[] bands) { |
|
51 |
return null; |
|
52 |
} |
|
53 |
|
|
54 |
public IBuffer cloneBuffer() { |
|
55 |
return null; |
|
56 |
} |
|
57 |
|
|
58 |
public void mallocOneBand(int dataType, int width, int height, int band) { |
|
59 |
} |
|
60 |
|
|
61 |
public byte[][] getLineByte(int line) { |
|
62 |
return null; |
|
63 |
} |
|
64 |
|
|
65 |
public short[][] getLineShort(int line) { |
|
66 |
return null; |
|
67 |
} |
|
68 |
|
|
69 |
public int[][] getLineInt(int line) { |
|
70 |
return null; |
|
71 |
} |
|
72 |
|
|
73 |
public float[][] getLineFloat(int line) { |
|
74 |
return null; |
|
75 |
} |
|
76 |
|
|
77 |
public double[][] getLineDouble(int line) { |
|
78 |
return null; |
|
79 |
} |
|
80 |
|
|
81 |
public byte[] getLineFromBandByte(int line, int band) { |
|
82 |
return null; |
|
83 |
} |
|
84 |
|
|
85 |
public short[] getLineFromBandShort(int line, int band) { |
|
86 |
return null; |
|
87 |
} |
|
88 |
|
|
89 |
public int[] getLineFromBandInt(int line, int band) { |
|
90 |
return null; |
|
91 |
} |
|
92 |
|
|
93 |
public float[] getLineFromBandFloat(int line, int band) { |
|
94 |
return null; |
|
95 |
} |
|
96 |
|
|
97 |
public double[] getLineFromBandDouble(int line, int band) { |
|
98 |
return null; |
|
99 |
} |
|
100 |
|
|
101 |
public byte getElemByte(int line, int col, int band) { |
|
102 |
return 0; |
|
103 |
} |
|
104 |
|
|
105 |
public short getElemShort(int line, int col, int band) { |
|
106 |
return 0; |
|
107 |
} |
|
108 |
|
|
109 |
public int getElemInt(int line, int col, int band) { |
|
110 |
return 0; |
|
111 |
} |
|
112 |
|
|
113 |
public float getElemFloat(int line, int col, int band) { |
|
114 |
return 0; |
|
115 |
} |
|
116 |
|
|
117 |
public double getElemDouble(int line, int col, int band) { |
|
118 |
return 0; |
|
119 |
} |
|
120 |
|
|
121 |
public void getElemByte(int line, int col, byte[] data) { |
|
122 |
} |
|
123 |
|
|
124 |
public void getElemShort(int line, int col, short[] data) { |
|
125 |
} |
|
126 |
|
|
127 |
public void getElemInt(int line, int col, int[] data) { |
|
128 |
} |
|
129 |
|
|
130 |
public void getElemFloat(int line, int col, float[] data) { |
|
131 |
} |
|
132 |
|
|
133 |
public void getElemDouble(int line, int col, double[] data) { |
|
134 |
} |
|
135 |
|
|
136 |
public void copyBand(int nBand, IBand band) { |
|
137 |
} |
|
138 |
|
|
139 |
public void assignBand(int nBand, IBand band) { |
|
140 |
} |
|
141 |
|
|
142 |
public IBand getBand(int nBand) { |
|
143 |
return null; |
|
144 |
} |
|
145 |
|
|
146 |
public void setLineInBandByte(byte[] data, int line, int band) { |
|
147 |
} |
|
148 |
|
|
149 |
public void setLineInBandShort(short[] data, int line, int band) { |
|
150 |
} |
|
151 |
|
|
152 |
public void setLineInBandInt(int[] data, int line, int band) { |
|
153 |
} |
|
154 |
|
|
155 |
public void setLineInBandFloat(float[] data, int line, int band) { |
|
156 |
} |
|
157 |
|
|
158 |
public void setLineInBandDouble(double[] data, int line, int band) { |
|
159 |
} |
|
160 |
|
|
161 |
public void setLineByte(byte[][] data, int line) { |
|
162 |
} |
|
163 |
|
|
164 |
public void setLineShort(short[][] data, int line) { |
|
165 |
} |
|
166 |
|
|
167 |
public void setLineInt(int[][] data, int line) { |
|
168 |
} |
|
169 |
|
|
170 |
public void setLineFloat(float[][] data, int line) { |
|
171 |
} |
|
172 |
|
|
173 |
public void setLineDouble(double[][] data, int line) { |
|
174 |
} |
|
175 |
|
|
176 |
public void setElem(int line, int col, int band, byte data) { |
|
177 |
} |
|
178 |
|
|
179 |
public void setElem(int line, int col, int band, short data) { |
|
180 |
} |
|
181 |
|
|
182 |
public void setElem(int line, int col, int band, int data) { |
|
183 |
} |
|
184 |
|
|
185 |
public void setElem(int line, int col, int band, float data) { |
|
186 |
} |
|
187 |
|
|
188 |
public void setElem(int line, int col, int band, double data) { |
|
189 |
} |
|
190 |
|
|
191 |
public void setElemByte(int line, int col, byte[] data) { |
|
192 |
} |
|
193 |
|
|
194 |
public void setElemShort(int line, int col, short[] data) { |
|
195 |
} |
|
196 |
|
|
197 |
public void setElemInt(int line, int col, int[] data) { |
|
198 |
} |
|
199 |
|
|
200 |
public void setElemFloat(int line, int col, float[] data) { |
|
201 |
} |
|
202 |
|
|
203 |
public void setElemDouble(int line, int col, double[] data) { |
|
204 |
} |
|
205 |
|
|
206 |
public void assign(int band, byte value) { |
|
207 |
} |
|
208 |
|
|
209 |
public void assign(int band, short value) { |
|
210 |
} |
|
211 |
|
|
212 |
public void assign(int band, int value) { |
|
213 |
} |
|
214 |
|
|
215 |
public void assign(int band, float value) { |
|
216 |
} |
|
217 |
|
|
218 |
public void assign(int band, double value) { |
|
219 |
} |
|
220 |
|
|
221 |
public IBand createBand(byte defaultValue) { |
|
222 |
return null; |
|
223 |
} |
|
224 |
|
|
225 |
public void interchangeBands(int band1, int band2) { |
|
226 |
} |
|
227 |
|
|
228 |
public void assignBandToNotValid(int iBand) { |
|
229 |
} |
|
230 |
|
|
231 |
public IBuffer getBandBuffer(int nBand) { |
|
232 |
return null; |
|
233 |
} |
|
234 |
|
|
235 |
|
|
236 |
} |
|
0 | 237 |
trunk/libraries/libRaster/tmp/cache/WriterBufferServer.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 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.dataaccess.cache; |
|
20 |
|
|
21 |
import org.gvsig.raster.driver.IBuffer; |
|
22 |
import org.gvsig.raster.driver.IDataWriter; |
|
23 |
|
|
24 |
/** |
|
25 |
* Sirve los datos desde un IBuffer para el driver de escritura de bloques de |
|
26 |
* cach?. La altura servida ser? igual a la del bloque de cache. |
|
27 |
* |
|
28 |
* @deprecated Esta clase fue creada para que CacheDataServer salvara sus datos a tif. |
|
29 |
* Se ha cambiado por la escritura de los bytes en disco porque era m?s ?ptimo. |
|
30 |
* |
|
31 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
32 |
*/ |
|
33 |
public class WriterBufferServer implements IDataWriter{ |
|
34 |
private IBuffer buffer = null; |
|
35 |
|
|
36 |
public WriterBufferServer(IBuffer buffer){ |
|
37 |
this.buffer = buffer; |
|
38 |
} |
|
39 |
|
|
40 |
public int[] readARGBData(int sizeX, int sizeY, int nBand) { |
|
41 |
return null; |
|
42 |
} |
|
43 |
|
|
44 |
public byte[][] readByteData(int sizeX, int sizeY) { |
|
45 |
int len = buffer.getWidth() * buffer.getHeight(); |
|
46 |
byte[][] b = new byte[buffer.getBandCount()][len]; |
|
47 |
for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++) |
|
48 |
for(int j = 0; j < buffer.getHeight(); j ++) |
|
49 |
for(int i = 0; i < buffer.getWidth(); i ++) |
|
50 |
b[iBand][j * buffer.getWidth() + i] = buffer.getElemByte(j, i, iBand); |
|
51 |
return b; |
|
52 |
} |
|
53 |
|
|
54 |
public short[][] readShortData(int sizeX, int sizeY) { |
|
55 |
int len = buffer.getWidth() * buffer.getHeight(); |
|
56 |
short[][] b = new short[buffer.getBandCount()][len]; |
|
57 |
for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++) |
|
58 |
for(int j = 0; j < buffer.getHeight(); j ++) |
|
59 |
for(int i = 0; i < buffer.getWidth(); i ++) |
|
60 |
b[iBand][j * buffer.getWidth() + i] = buffer.getElemShort(j, i, iBand); |
|
61 |
return b; |
|
62 |
} |
|
63 |
|
|
64 |
public int[][] readIntData(int sizeX, int sizeY) { |
|
65 |
int len = buffer.getWidth() * buffer.getHeight(); |
|
66 |
int[][] b = new int[buffer.getBandCount()][len]; |
|
67 |
for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++) |
|
68 |
for(int j = 0; j < buffer.getHeight(); j ++) |
|
69 |
for(int i = 0; i < buffer.getWidth(); i ++) |
|
70 |
b[iBand][j * buffer.getWidth() + i] = buffer.getElemInt(j, i, iBand); |
|
71 |
return b; |
|
72 |
} |
|
73 |
|
|
74 |
public float[][] readFloatData(int sizeX, int sizeY) { |
|
75 |
int len = buffer.getWidth() * buffer.getHeight(); |
|
76 |
float[][] b = new float[buffer.getBandCount()][len]; |
|
77 |
for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++) |
|
78 |
for(int j = 0; j < buffer.getHeight(); j ++) |
|
79 |
for(int i = 0; i < buffer.getWidth(); i ++) |
|
80 |
b[iBand][j * buffer.getWidth() + i] = buffer.getElemFloat(j, i, iBand); |
|
81 |
return b; |
|
82 |
} |
|
83 |
|
|
84 |
public double[][] readDoubleData(int sizeX, int sizeY) { |
|
85 |
int len = buffer.getWidth() * buffer.getHeight(); |
|
86 |
double[][] b = new double[buffer.getBandCount()][len]; |
|
87 |
for(int iBand = 0; iBand < buffer.getBandCount(); iBand ++) |
|
88 |
for(int j = 0; j < buffer.getHeight(); j ++) |
|
89 |
for(int i = 0; i < buffer.getWidth(); i ++) |
|
90 |
b[iBand][j * buffer.getWidth() + i] = buffer.getElemDouble(j, i, iBand); |
|
91 |
return b; |
|
92 |
} |
|
93 |
} |
|
0 | 94 |
trunk/libraries/libRaster/tmp/cache/package.html | ||
---|---|---|
1 |
<html> |
|
2 |
<body>Clases para la gesti?n del cacheado de datos. |
|
3 |
</body> |
|
4 |
</html> |
|
0 | 5 |
trunk/libraries/libRaster/tmp/cache/Cache.java | ||
---|---|---|
1 |
|
|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 |
* |
|
4 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana. |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
*/ |
|
20 |
package org.gvsig.raster.dataaccess.cache; |
|
21 |
|
|
22 |
/** |
|
23 |
* <P> |
|
24 |
* Esta clase representa a la cache raster. Consta de una ser?e de p?ginas (CachePages) |
|
25 |
* que son buffers con los bloques de datos cacheados en un instante dado. Esta cache tiene |
|
26 |
* una estructura en forma de array donde cada elemento es una p?gina de cach?. Las p?ginas |
|
27 |
* se agrupan en bloques de N p?ginas denominados grupos. La variable nelemsGroup contiene |
|
28 |
* el n?mero de p?ginas de cada grupo. |
|
29 |
* </P> |
|
30 |
* <P> |
|
31 |
* La politica de reemplazo es que una p?gina siempre va a un conjunto determinado por el calculo |
|
32 |
* cto = pag % nelemsGroup. Si hay hueco vac?o en el grupo se a?adir? en el siguiente hueco pero |
|
33 |
* si hay que reeplazar se reeplazar? la p?gina que m?s tiempo haga su ?ltimo acceso. |
|
34 |
* </P> |
|
35 |
* <P> |
|
36 |
* Esta cach? lleva el control de que p?ginas est?n cargadas a trav?s de un array de de booleanos |
|
37 |
* donde cada elemento representa a una p?gina de datos del raster. Si el elemento en la posici?n |
|
38 |
* N de dicho array es true significa que la p?gina est? cacheada. Si es false no lo estar?. |
|
39 |
* </P> |
|
40 |
* <P> |
|
41 |
* La p?gina de datos actualmente accedida debe estar cacheada por lo que est? clase debe llevar |
|
42 |
* el control de que p?gina se est? accediendo o a sido accedida por ?ltima vez. La variable que |
|
43 |
* nos dice que p?gina est? siendo accedida es loadPage y pageBuffer ser? la variable que apunta |
|
44 |
* al buffer de esta p?gina. Cuando se cambia de p?gina en un acceso estas dos variables deben |
|
45 |
* cambiar a sus nuevos valores. |
|
46 |
* </P> |
|
47 |
* <P> |
|
48 |
* Otro par?metro que controla esta clase es que p?gina de cada grupo ha sido accedido con mayor |
|
49 |
* frecuencia. Esto es ?til porque siempre se reemplaza la p?gina de un grupo que haga m?s tiempo |
|
50 |
* que haya sido accedida bajo la premisa de que "las p?ginas con accesos recientes tienen mayor |
|
51 |
* probabilidad de volver a ser usadas". Esto es controlado por la variable lastAccess que es |
|
52 |
* usada para implementar el algoritmo LRU. Cada vez que una p?gina de un grupo es accedida su |
|
53 |
* contador de lastAccess se pone a 0. El resto de contadores de las p?ginas del grupo se incrementa |
|
54 |
* en uno. Siempre se sustituye la p?gina del grupo con valor m?s grande en el contador. |
|
55 |
* </P> |
|
56 |
* |
|
57 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
58 |
* |
|
59 |
*/ |
|
60 |
public class Cache{ |
|
61 |
/** |
|
62 |
* Objeto que guarda y recupera trozos de cache de disco. |
|
63 |
*/ |
|
64 |
private ICacheDataSource dataSource = null; |
|
65 |
/** |
|
66 |
* Cada elemento es una p?gina del raster y dice si est? cacheada o no. |
|
67 |
*/ |
|
68 |
private boolean[] cacheada = null; |
|
69 |
/** |
|
70 |
* N?mero de p?gina cargada en accessPage. |
|
71 |
*/ |
|
72 |
private int numberInAccessPage = -1; |
|
73 |
/** |
|
74 |
* Buffer de datos de la p?gina actualmente accedida. |
|
75 |
*/ |
|
76 |
private PageBuffer accessPage = null; |
|
77 |
/** |
|
78 |
* P?ginas de cach? |
|
79 |
*/ |
|
80 |
private PageBuffer[] page = null; |
|
81 |
/** |
|
82 |
* Cada elemento del array es una p?gina de cach? y contiene el n?mero de p?gina cargada en |
|
83 |
* esa posici?n. |
|
84 |
*/ |
|
85 |
private int[] pageNumberInCache = null; |
|
86 |
/** |
|
87 |
* P?ginas de la cach?. |
|
88 |
*/ |
|
89 |
private CacheStruct cacheStruct = null; |
|
90 |
/** |
|
91 |
* ?ltimo acceso a las p?ginas de cada grupo. |
|
92 |
*/ |
|
93 |
private int[][] lastAccess = null; |
|
94 |
/** |
|
95 |
* Cada elemento representa una p?gina de cach? y dice si esta ha sido modificada desde que |
|
96 |
* fu? cargada en cach? o no. |
|
97 |
*/ |
|
98 |
private boolean[] modified = null; |
|
99 |
|
|
100 |
/** |
|
101 |
* Inicializamos la variables. Para ello creamos el objeto Cache que contendr? todos los |
|
102 |
* par?metros necesarios para crear el array que controla los accesos m?s recientes y el |
|
103 |
* array que dice si una p?gina est? en memoria o no. |
|
104 |
* @param nBands N?mero de bandas |
|
105 |
* @param dataType Tipo de dato de la p?gina |
|
106 |
* @param dataSourceWidth ancho de la fuente de datos |
|
107 |
*/ |
|
108 |
public Cache(int nBands, int dataType, int dataSourceWidth, int dataSourceHeight){ |
|
109 |
//Creamos la estructura de la cach? |
|
110 |
cacheStruct = new CacheStruct(nBands, dataType, dataSourceWidth, dataSourceHeight); |
|
111 |
|
|
112 |
//Inicializamos la antig?edad de acceso |
|
113 |
lastAccess = new int[cacheStruct.getNGroups()][cacheStruct.getPagsPerGroup()]; |
|
114 |
for(int i = 0; i < cacheStruct.getNGroups(); i ++) |
|
115 |
for(int j = 0; j < cacheStruct.getPagsPerGroup(); j ++) |
|
116 |
lastAccess[i][j] = -1; |
|
117 |
|
|
118 |
//Creamos el buffer de la cach? |
|
119 |
page = new PageBuffer[cacheStruct.getNPags()]; |
|
120 |
pageNumberInCache = new int[cacheStruct.getNPags()]; |
|
121 |
modified = new boolean[cacheStruct.getNPags()]; |
|
122 |
|
|
123 |
cacheada = new boolean[cacheStruct.getNTotalPags()]; |
|
124 |
for(int i = 0; i < cacheada.length; i++) |
|
125 |
cacheada[i] = false; |
|
126 |
|
|
127 |
for(int i = 0; i < cacheStruct.getNPags(); i++){ |
|
128 |
page[i] = new PageBuffer(dataType, dataSourceWidth, cacheStruct.getHPag(), nBands, true); |
|
129 |
pageNumberInCache[i] = -1; |
|
130 |
modified[i] = false; |
|
131 |
} |
|
132 |
|
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* Obtiene el n?mero de bits por p?gina para poder calcular el desplazamiento binario |
|
137 |
* de la direcci?n de acceso de la petici?n. Es decir si se solicita un dato en la l?nea |
|
138 |
* 36 (en decimal) del raster 100100(en binario) y el desplazamiento es 4 bits el n?mero de |
|
139 |
* p?gina resultante ser? 10(en binario) 2 (en decimal) |
|
140 |
* @return |
|
141 |
*/ |
|
142 |
public int getBitsPag() { |
|
143 |
return cacheStruct.getBitsPag(); |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* Obtiene la altura de la p?gina de cache en l?neas. |
|
148 |
* @return N?mero de l?neas de altura de p?gina. |
|
149 |
*/ |
|
150 |
public int getHPag() { |
|
151 |
return cacheStruct.getHPag(); |
|
152 |
} |
|
153 |
|
|
154 |
/** |
|
155 |
* Array de booleanos donde cada elemento es una p?gina del raster y dice si la p?gina |
|
156 |
* est? cacheada o no. |
|
157 |
* @return true si la p?gina est? en cach? y false si no lo est? |
|
158 |
*/ |
|
159 |
public boolean isInCache(int nPag) { |
|
160 |
if(nPag < 0 || nPag >= cacheada.length) |
|
161 |
return false; |
|
162 |
return cacheada[nPag]; |
|
163 |
} |
|
164 |
|
|
165 |
/** |
|
166 |
* Marca una p?gina como cargada en cach?. |
|
167 |
* @param nPag N?mero de p?gina a marcar. |
|
168 |
*/ |
|
169 |
public void setPageAsLoadInCache(int nPag){ |
|
170 |
if(nPag < 0 || nPag >= cacheada.length) |
|
171 |
return; |
|
172 |
cacheada[nPag] = true; |
|
173 |
} |
|
174 |
|
|
175 |
/** |
|
176 |
* Desmarca una p?gina como cargada en cach?. |
|
177 |
* @param nPag N?mero de p?gina a desmarcar. |
|
178 |
*/ |
|
179 |
public void setPageAsNotLoadInCache(int nPag){ |
|
180 |
if(nPag < 0 || nPag >= cacheada.length) |
|
181 |
return; |
|
182 |
cacheada[nPag] = false; |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* Obtiene el n?mero de p?gina del raster cargada en una p?gina de cach? especificada |
|
187 |
* en el par?metro. |
|
188 |
* @param nCachePage N?mero de p?gina de cach? de la que se quiere saber que p?gina del |
|
189 |
* raster hay cargada. |
|
190 |
* @return N?mero de p?gina del raster |
|
191 |
*/ |
|
192 |
public int getRasterPageNumberInPosition(int nCachePage){ |
|
193 |
return pageNumberInCache[nCachePage]; |
|
194 |
} |
|
195 |
|
|
196 |
/** |
|
197 |
* Obtiene el n?mero de p?gina del raster cargada en una p?gina de cach? especificada |
|
198 |
* en el par?metro. |
|
199 |
* @param group Grupo en el que se encuentra la p?gina |
|
200 |
* @param posInGroup Posici?n dentro del grupo en el que est? la p?gina |
|
201 |
* @return N?mero de p?gina del raster |
|
202 |
*/ |
|
203 |
public int getRasterPageNumberInPosition(int group, int posInGroup){ |
|
204 |
return pageNumberInCache[group * getPagsPerGroup() + posInGroup]; |
|
205 |
} |
|
206 |
|
|
207 |
/** |
|
208 |
* Asigna el n?mero de p?gina del raster cargada en una p?gina de cach? especificada. |
|
209 |
* @param nCachePage N?mero de p?gina de cach? |
|
210 |
* @param nRasterPage N?mero de p?gina de raster a asignar |
|
211 |
*/ |
|
212 |
public void setRasterPageNumberInPosition(int nCachePage, int nRasterPage){ |
|
213 |
pageNumberInCache[nCachePage] = nRasterPage; |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* Asigna el n?mero de p?gina del raster cargada en una p?gina de cach? especificada. |
|
218 |
* @param nCachePage N?mero de p?gina de cach? |
|
219 |
* @param nRasterPage N?mero de p?gina de raster a asignar |
|
220 |
*/ |
|
221 |
public void setRasterPageNumberInPosition(int group, int posInGroup, int nRasterPage){ |
|
222 |
pageNumberInCache[group * getPagsPerGroup() + posInGroup] = nRasterPage; |
|
223 |
} |
|
224 |
|
|
225 |
/** |
|
226 |
* Obtiene el n?mero de p?gina de cach? donde est? cargada la p?gina del raster |
|
227 |
* que se ha pasado por par?metro. |
|
228 |
* @param pag P?gina del raster |
|
229 |
* @return N?mero de p?gina del raster |
|
230 |
*/ |
|
231 |
public int getNumberCachePageFromNumberRasterPage(int pag){ |
|
232 |
int group = pag % getNGroups(); |
|
233 |
for(int i = 0; i < getPagsPerGroup(); i++) |
|
234 |
if(pageNumberInCache[group + i] == pag) |
|
235 |
return (group * getPagsPerGroup() + i); |
|
236 |
return -1; |
|
237 |
} |
|
238 |
|
|
239 |
/** |
|
240 |
* Obtiene el n?mero de p?gina de cach? (en formato grupo/p?gina dentro del grupo) |
|
241 |
* donde est? cargada la p?gina del raster que se ha pasado por par?metro. |
|
242 |
* @param pag P?gina del raster |
|
243 |
* @return N?mero de p?gina del raster |
|
244 |
*/ |
|
245 |
public int[] getNumberGroupFromNumberRasterPage(int pag){ |
|
246 |
int group = pag % getNGroups(); |
|
247 |
for(int i = 0; i < getPagsPerGroup(); i++) |
|
248 |
if(pageNumberInCache[(group * getPagsPerGroup()) + i] == pag) |
|
249 |
return new int[]{group, i}; |
|
250 |
return null; |
|
251 |
} |
|
252 |
|
|
253 |
/** |
|
254 |
* Obtiene el array que contiene los valores de la antig?edad del acceso dentro del |
|
255 |
* grupo. La primera dimensi?n del array corresponde al n?mero de grupo y la segunda |
|
256 |
* a los elementos del grupo. El elemento del grupo con un acceso m?s reciente tendr? |
|
257 |
* un n?mero menor y el de mayor valor ser? el candidato para la sustituci?n en el pr?ximo |
|
258 |
* remplazamiento. |
|
259 |
* @return Array bidimensional con los valores de antig?edad. |
|
260 |
*/ |
|
261 |
public int[][] getLastAccess() { |
|
262 |
return lastAccess; |
|
263 |
} |
|
264 |
|
|
265 |
/** |
|
266 |
* Asigna un cero en la posici?n del array que contiene la antig?edad de acceso dentro |
|
267 |
* del grupo. Esta operaci?n se realiza cada vez que se accede a un dato del la p?gina |
|
268 |
* cacheada y significa que es la p?gina m?s recientemente accedida. |
|
269 |
* @param group N?mero de grupo |
|
270 |
* @param posInGroup Posici?n de la p?gina dentro del grupo. |
|
271 |
*/ |
|
272 |
public void setZeroInLastAccess(int group, int posInGroup){ |
|
273 |
lastAccess[group][posInGroup] = 0; |
|
274 |
} |
|
275 |
|
|
276 |
/** |
|
277 |
* Obtiene el n?mero de p?gina cargada en el buffer |
|
278 |
* @return Entero con el n?mero de p?gina |
|
279 |
*/ |
|
280 |
public int getNumberInAccessPage() { |
|
281 |
return numberInAccessPage; |
|
282 |
} |
|
283 |
|
|
284 |
/** |
|
285 |
* Obtiene el n?mero de p?ginas que tiene cada grupo |
|
286 |
* @return Entero con el n?mero de p?ginas por grupo |
|
287 |
*/ |
|
288 |
public int getPagsPerGroup() { |
|
289 |
return cacheStruct.getPagsPerGroup(); |
|
290 |
} |
|
291 |
|
|
292 |
/** |
|
293 |
* Obtiene la p?gina de datos de la posici?n pag |
|
294 |
* @param pag N?mero de p?gina de cach? a recuperar |
|
295 |
* @return PageBuffer correspondiente a la p?gina recuperada |
|
296 |
*/ |
|
297 |
public PageBuffer getPageBufferFromNumberCachePage(int pag) { |
|
298 |
return page[pag]; |
|
299 |
} |
|
300 |
|
|
301 |
/** |
|
302 |
* Obtiene la p?gina de datos a partir del n?mero de p?gina de raster |
|
303 |
* @param pag N?mero de p?gina raster a recuperar |
|
304 |
* @return PageBuffer correspondiente a la p?gina recuperada o null si no est? en cach? |
|
305 |
*/ |
|
306 |
public PageBuffer getPageBufferFromNumberRasterPage(int pag) { |
|
307 |
int group = pag % getNGroups(); |
|
308 |
for(int i = 0; i < getPagsPerGroup(); i++) |
|
309 |
if(pageNumberInCache[group * getPagsPerGroup() + i] == pag) |
|
310 |
return page[group * getPagsPerGroup() + i]; |
|
311 |
return null; |
|
312 |
} |
|
313 |
|
|
314 |
/** |
|
315 |
* Obtiene la p?gina de datos del grupo definido en el par?metro group y de la |
|
316 |
* posici?n pag dentro de ese grupo. |
|
317 |
* @param group Grupo de la p?gina requerida |
|
318 |
* @param pag N?mero de p?gina dentro del grupo |
|
319 |
* @return PageBuffer correspondiente a la p?gina recuperada |
|
320 |
*/ |
|
321 |
public PageBuffer getPageBuffer(int group, int posInGroup) { |
|
322 |
return page[group * getPagsPerGroup() + posInGroup]; |
|
323 |
} |
|
324 |
|
|
325 |
/** |
|
326 |
* Obtiene la p?gina de datos actualmente accedida |
|
327 |
* @return PageBuffer correspondiente a la p?gina que se est? accediendo |
|
328 |
*/ |
|
329 |
public PageBuffer getAccessPage() { |
|
330 |
return accessPage; |
|
331 |
} |
|
332 |
|
|
333 |
/** |
|
334 |
* Asigna el buffer de la p?gina accedida por referencia |
|
335 |
* @param pb |
|
336 |
*/ |
|
337 |
public void setAccessPage(PageBuffer pb, int pagNumber){ |
|
338 |
accessPage = pb; |
|
339 |
numberInAccessPage = pagNumber; |
|
340 |
} |
|
341 |
|
|
342 |
/** |
|
343 |
* Consulta si una p?gina de cach? ha sido modificada desde que se carg? en cach? o no. |
|
344 |
* @param nCachePag N?mero de p?gina de cach? (posici?n de esta) |
|
345 |
* @return true si ha sido modificada y false si no lo ha sido. |
|
346 |
*/ |
|
347 |
public boolean isModified(int nCachePag){ |
|
348 |
return modified[nCachePag]; |
|
349 |
} |
|
350 |
|
|
351 |
/** |
|
352 |
* Consulta si una p?gina de cach? ha sido modificada desde que se carg? en cach? o no. |
|
353 |
* @param group Grupo en el que se encuentra la p?gina |
|
354 |
* @param posInGroup Posici?n dentro del grupo en el que est? la p?gina |
|
355 |
* @return true si ha sido modificada y false si no lo ha sido. |
|
356 |
*/ |
|
357 |
public boolean isModified(int group, int posInGroup){ |
|
358 |
return modified[group * getPagsPerGroup() + posInGroup]; |
|
359 |
} |
|
360 |
|
|
361 |
/** |
|
362 |
* Pone como modificada una p?gina de cach? |
|
363 |
* @param nCachePag N?mero de p?gina de cach? (posici?n de esta) |
|
364 |
*/ |
|
365 |
public void setModify(int nCachePag){ |
|
366 |
modified[nCachePag] = true; |
|
367 |
} |
|
368 |
|
|
369 |
/** |
|
370 |
* Pone como modificada una p?gina de cach? |
|
371 |
* @param group Grupo en el que se encuentra la p?gina |
|
372 |
* @param posInGroup Posici?n dentro del grupo en el que est? la p?gina |
|
373 |
*/ |
|
374 |
public void setModify(int group, int posInGroup){ |
|
375 |
modified[group * getPagsPerGroup() + posInGroup] = true; |
|
376 |
} |
|
377 |
|
|
378 |
/** |
|
379 |
* Pone como no modificada una p?gina de cach? |
|
380 |
* @param nCachePag N?mero de p?gina de cach? (posici?n de esta) |
|
381 |
*/ |
|
382 |
public void unsetModify(int nCachePag){ |
|
383 |
modified[nCachePag] = false; |
|
384 |
} |
|
385 |
|
|
386 |
/** |
|
387 |
* Pone como no modificada una p?gina de cach? |
|
388 |
* @param group Grupo en el que se encuentra la p?gina |
|
389 |
* @param posInGroup Posici?n dentro del grupo en el que est? la p?gina |
|
390 |
*/ |
|
391 |
public void unsetModify(int group, int posInGroup){ |
|
392 |
modified[group * getPagsPerGroup() + posInGroup] = false; |
|
393 |
} |
|
394 |
|
|
395 |
/** |
|
396 |
* Obtiene el n?mero de p?ginas de la cach? |
|
397 |
* @return N?mero total de p?ginas de la cach? |
|
398 |
*/ |
|
399 |
public int getNPags() { |
|
400 |
return cacheStruct.getNPags(); |
|
401 |
} |
|
402 |
|
|
403 |
/** |
|
404 |
* Obtiene el n?mero de bandas |
|
405 |
* @return N?mero de bandas |
|
406 |
*/ |
|
407 |
public int getNBands() { |
|
408 |
return cacheStruct.getNBands(); |
|
409 |
} |
|
410 |
|
|
411 |
/** |
|
412 |
* Obtiene la estructura de ca cach? |
|
413 |
* @return CacheStruct |
|
414 |
*/ |
|
415 |
public CacheStruct getCacheStruct() { |
|
416 |
return cacheStruct; |
|
417 |
} |
|
418 |
|
|
419 |
/** |
|
420 |
* Obtiene el n?mero de grupos de cach? |
|
421 |
* @return N?mero de grupos |
|
422 |
*/ |
|
423 |
public int getNGroups() { |
|
424 |
return cacheStruct.getNGroups(); |
|
425 |
} |
|
426 |
|
|
427 |
/** |
|
428 |
* Obtiene el n?mero total de p?ginas del raster |
|
429 |
* @return N?mero total de p?ginas |
|
430 |
*/ |
|
431 |
public int getNTotalPags() { |
|
432 |
return cacheStruct.getNTotalPags(); |
|
433 |
} |
|
434 |
|
|
435 |
/** |
|
436 |
* Obtiene el array con los n?meros de p?gina que hay cargados |
|
437 |
* en cada bloque de cache |
|
438 |
* @return array con los n?mero de p?gina |
|
439 |
*/ |
|
440 |
public int[] getPageNumberInCache(){ |
|
441 |
return this.pageNumberInCache; |
|
442 |
} |
|
443 |
|
|
444 |
/** |
|
445 |
* Para extraer el desplazamiento de una direcci?n (l?nea de raster) hay que hacer una operaci?n And con |
|
446 |
* con la altura de la p?gina -1. Por ejemplo, una p?gina de 16 l?neas de altura el desplazamiento ser? |
|
447 |
* 16 - 1 = 15 porque 15 en binario es 1111. |
|
448 |
* |
|
449 |
* Si queremos acceder a la linea del raster n?mero 83 (1010011) realizando la operaci?n And con el valor del |
|
450 |
* desplazamiento obtenemos (0001111 & 1010011 = 0000011), es decir el valor 3 en decimal. Esto quiere decir |
|
451 |
* que la l?nea 83 del raster es la 3 de su p?gina. |
|
452 |
* @return valor del desplazamiento |
|
453 |
*/ |
|
454 |
public int getOffset() { |
|
455 |
return cacheStruct.getOffset(); |
|
456 |
} |
|
457 |
|
|
458 |
/** |
|
459 |
* Convierte una p?gina dentro de un grupo de la cach? en un n?mero de |
|
460 |
* p?gina de cach?. Por ejemplo, en una cach? de 10 grupos y 5 p?ginas por grupo |
|
461 |
* la p?gina 2 del grupo 4 devolver? el 23 (5 * 4 + 3 = 23) teniendo en cuenta que |
|
462 |
* la p?gina y el grupo cero tambi?n cuentan. |
|
463 |
* @param group |
|
464 |
* @param pageInGroup |
|
465 |
* @return |
|
466 |
*/ |
|
467 |
public int convertPageInGroupToPageInCache(int group, int pageInGroup){ |
|
468 |
return (group * cacheStruct.getPagsPerGroup() + pageInGroup); |
|
469 |
} |
|
470 |
|
|
471 |
/** |
|
472 |
* Actualiza los ?ltimos accesos del grupo pasado por par?metro. Se incrementar? |
|
473 |
* uno en todas las p?ginas del conjunto a excepci?n de las que valen -1 ya que |
|
474 |
* esto significa que no hay p?gina cargada en dicha posici?n. |
|
475 |
* @param group N?mero de grupo a actualizar sus accesos |
|
476 |
* @return La posici?n del elemento del grupo con valor m?ximo. Este elemento |
|
477 |
* es el candidato para el reemplazo. |
|
478 |
*/ |
|
479 |
public int updateLastAccess(int group){ |
|
480 |
int max = Integer.MIN_VALUE; |
|
481 |
int posMax = 0; |
|
482 |
for(int i = 0; i < getPagsPerGroup(); i++){ |
|
483 |
if(getLastAccess()[group][i] >= 0) |
|
484 |
getLastAccess()[group][i] ++; |
|
485 |
|
|
486 |
if(getLastAccess()[group][i] > max){ |
|
487 |
max = getLastAccess()[group][i]; |
|
488 |
posMax = i; |
|
489 |
} |
|
490 |
} |
|
491 |
return posMax; |
|
492 |
} |
|
493 |
|
|
494 |
/** |
|
495 |
* Obtiene la posici?n del grupo de la p?gina a reemplazar, es decir la de m?ximo valor |
|
496 |
* en el vector lastAccess. |
|
497 |
* @param group N?mero de grupo a obtener la p?gina de reemplazo |
|
498 |
* @return La posici?n del elemento del grupo con valor m?ximo. Este elemento |
|
499 |
* es el candidato para el reemplazo. |
|
500 |
*/ |
|
501 |
public int posInGroupPagToReplace(int group){ |
|
502 |
int max = Integer.MIN_VALUE; |
|
503 |
int posMax = 0; |
|
504 |
for(int i = 0; i < getPagsPerGroup(); i++){ |
|
505 |
if(getLastAccess()[group][i] > max){ |
|
506 |
max = getLastAccess()[group][i]; |
|
507 |
posMax = i; |
|
508 |
} |
|
509 |
} |
|
510 |
return posMax; |
|
511 |
} |
|
512 |
|
|
513 |
/** |
|
514 |
* Asigna el objeto que guarda y recupera trozos de cache de disco. |
|
515 |
* @param dataSource |
|
516 |
*/ |
|
517 |
public void setDataSource(ICacheDataSource dataSource){ |
|
518 |
this.dataSource = dataSource; |
|
519 |
} |
|
520 |
|
|
521 |
/** |
|
522 |
* Recupera el objeto que guarda y recupera trozos de cache de disco. |
|
523 |
* @return dataSource |
|
524 |
*/ |
|
525 |
public ICacheDataSource getDataSource(){ |
|
526 |
return dataSource; |
|
527 |
} |
|
528 |
|
|
529 |
/** |
|
530 |
* Imprime la informaci?n de estructura de cach? |
|
531 |
*/ |
|
532 |
public void show(){ |
|
533 |
cacheStruct.show(); |
|
534 |
System.out.println("Cacheada:"); |
|
535 |
for(int i = 0; i < cacheada.length; i++) |
|
536 |
System.out.print(i + "=" + cacheada[i]+" "); |
|
537 |
System.out.println(); |
|
538 |
System.out.println("LastAccess:"); |
|
539 |
for(int i = 0; i < cacheStruct.getNGroups(); i++){ |
|
540 |
System.out.println("Grupo " + i +":"); |
|
541 |
for(int j = 0; j < cacheStruct.getPagsPerGroup(); j++) |
|
542 |
System.out.println("elem " + j + " : " + "Page " + pageNumberInCache[i * cacheStruct.getPagsPerGroup() + j] + " : " + lastAccess[i][j]); |
|
543 |
|
|
544 |
} |
|
545 |
} |
|
546 |
|
|
547 |
} |
|
0 | 548 |
trunk/libraries/libRaster/tmp/cache/CacheDataServer.java | ||
---|---|---|
1 |
|
|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
3 |
* |
|
4 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana. |
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
*/ |
|
20 |
package org.gvsig.raster.dataaccess.cache; |
|
21 |
|
|
22 |
import java.io.BufferedInputStream; |
|
23 |
import java.io.BufferedOutputStream; |
|
24 |
import java.io.DataInputStream; |
|
25 |
import java.io.DataOutputStream; |
|
26 |
import java.io.File; |
|
27 |
import java.io.FileInputStream; |
|
28 |
import java.io.FileNotFoundException; |
|
29 |
import java.io.FileOutputStream; |
|
30 |
import java.io.IOException; |
|
31 |
|
|
32 |
import org.gvsig.raster.driver.Band; |
|
33 |
import org.gvsig.raster.driver.BandFoundInListException; |
|
34 |
import org.gvsig.raster.driver.BandList; |
|
35 |
import org.gvsig.raster.driver.GeoRasterWriter; |
|
36 |
import org.gvsig.raster.driver.IBuffer; |
|
37 |
import org.gvsig.raster.driver.IDataWriter; |
|
38 |
import org.gvsig.raster.driver.NotSupportedExtensionException; |
|
39 |
import org.gvsig.raster.driver.RasterDataset; |
|
40 |
import org.gvsig.raster.driver.RasterDriverException; |
|
41 |
import org.gvsig.raster.shared.Extent; |
|
42 |
import org.gvsig.raster.shared.RasterLibrary; |
|
43 |
|
|
44 |
|
|
45 |
/** |
|
46 |
* Servidor de datos de cach?. Esta clase es la encargada de volcar a disco las p?ginas de cach? y recuperar |
|
47 |
* las cuando le son solicitadas. Por ello debe implementar el interfaz ICacheDataSource con dos m?todos |
|
48 |
* loadPage y savePage. Ambos a partir del n?mero de p?gina recuperaran o salvaran de/a disco una p?gina. |
|
49 |
* |
|
50 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
51 |
* |
|
52 |
*/ |
|
53 |
public class CacheDataServer implements ICacheDataSource{ |
|
54 |
|
|
55 |
/** |
|
56 |
* Directorio temporal para la cach?. Si gastamos el mismo que andami este se ocupar? de gestionar su |
|
57 |
* destrucci?n al cerrar gvSIG. |
|
58 |
*/ |
|
59 |
private String tempDirectoryPath = RasterLibrary.tempCacheDirectoryPath; |
|
60 |
private String id = null; //Identificador de fichero. |
|
61 |
|
|
62 |
/** |
|
63 |
* Constructor. |
|
64 |
* Crea el identificador para todos los trozos de cach? que se guardar?n en disco. |
|
65 |
* |
|
66 |
*/ |
|
67 |
public CacheDataServer() { |
|
68 |
if(id == null) |
|
69 |
id = Long.toString(System.currentTimeMillis()); |
|
70 |
} |
|
71 |
|
|
72 |
/* (non-Javadoc) |
|
73 |
* @see org.gvsig.fmap.dataaccess.cache.ICacheDataSource#loadPage(int, org.gvsig.fmap.dataaccess.cache.PageBuffer) |
|
74 |
*/ |
|
75 |
public void loadPage(int nPag, PageBuffer pageBuffer) { |
|
76 |
String inFileName = tempDirectoryPath + File.separator + id + "-" + nPag; |
|
77 |
|
|
78 |
File file = new File(inFileName); |
|
79 |
if(!file.exists()) |
|
80 |
return; |
|
81 |
|
|
82 |
DataInputStream dis; |
|
83 |
try { |
|
84 |
dis = new DataInputStream( new BufferedInputStream(new FileInputStream(file))); |
|
85 |
read(dis, pageBuffer); |
|
86 |
dis.close(); |
|
87 |
}catch (FileNotFoundException e) { |
|
88 |
return; |
|
89 |
}catch(IOException ex){ |
|
90 |
return; |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
/* (non-Javadoc) |
|
95 |
* @see org.gvsig.fmap.dataaccess.cache.ICacheDataSource#savePage(int, org.gvsig.fmap.dataaccess.cache.PageBuffer) |
|
96 |
*/ |
|
97 |
public void savePage(int nPag, PageBuffer pageBuffer) throws IOException { |
|
98 |
createTempDirectory(); |
|
99 |
String fileName = tempDirectoryPath + File.separator + id + "-" + nPag; |
|
100 |
|
|
101 |
File f = new File(fileName); |
|
102 |
DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(f))); |
|
103 |
save(dos, pageBuffer); |
|
104 |
dos.close(); |
|
105 |
} |
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
/** |
|
110 |
* Esta funci?n crea el directorio para temporales y devuelve el nombre de este. |
|
111 |
* @return |
|
112 |
*/ |
|
113 |
private String createTempDirectory(){ |
|
114 |
File tempDirectory = new File(tempDirectoryPath); |
|
115 |
if (!tempDirectory.exists()) |
|
116 |
tempDirectory.mkdir(); |
|
117 |
return tempDirectoryPath; |
|
118 |
} |
|
119 |
|
|
120 |
//TODO: TEST: Implementar y probar el cacheado para tipos de datos != de byte |
|
121 |
/** |
|
122 |
* Tilea un raster en disco para que sea accesible por la cach?. |
|
123 |
* @param fileName Nombre del fichero a tilear |
|
124 |
* @param pageLines N?mero de l?neas de cada tile |
|
125 |
* @throws IOException |
|
126 |
* @throws RasterDriverException |
|
127 |
* @throws NotSupportedExtensionException |
|
128 |
*/ |
|
129 |
public void cachear(String fileName, int pageLines)throws IOException, NotSupportedExtensionException, RasterDriverException{ |
|
130 |
if(id == null) |
|
131 |
id = Long.toString(System.currentTimeMillis()); |
|
132 |
|
|
133 |
RasterDataset grf = RasterDataset.openFile(null, fileName); |
|
134 |
|
|
135 |
//Creamos un BandList con todas las bandas del fichero |
|
136 |
BandList bandList = new BandList(); |
|
137 |
for(int i = 0; i < grf.getBandCount();i++){ |
|
138 |
try{ |
|
139 |
Band band = new Band(grf.getFName(), i, grf.getDataType()); |
|
140 |
bandList.addBand(band, i); |
|
141 |
bandList.addDrawableBand(i, i); |
|
142 |
}catch(BandFoundInListException ex){ |
|
143 |
//No a?adimos la banda |
|
144 |
} |
|
145 |
} |
|
146 |
|
|
147 |
int pages = (int)Math.ceil(grf.getHeight() / pageLines); |
|
148 |
|
|
149 |
createTempDirectory(); |
Also available in: Unified diff