45 |
45 |
private static int multicacheMemorySize = 100;
|
46 |
46 |
|
47 |
47 |
public double noDataValue = -99999;
|
48 |
|
protected int percent = 0;
|
|
48 |
|
|
49 |
protected int percent = 0;
|
|
50 |
protected boolean canceled = false;
|
49 |
51 |
|
50 |
|
protected int width;
|
51 |
|
protected int height;
|
52 |
|
protected int nBands;
|
53 |
|
protected int dataType;
|
54 |
|
|
55 |
|
/**
|
56 |
|
* Variable est?tica que si est? a false desactiva el uso de cach?. Puede ser usada por un cliente
|
57 |
|
* para cargar siempre los datos en memoria. independientemente de su tama?o.
|
58 |
|
*/
|
59 |
|
public static boolean cacheOn = true;
|
60 |
|
/**
|
61 |
|
* Fuerza la carga de los datos en cach? independientemente de su tama?o. Su
|
62 |
|
* uso suele ser util solo para depuraci?n. Su valor por defecto y recomendado
|
63 |
|
* es siempre false.
|
64 |
|
*/
|
65 |
|
public static boolean forceToLoadInCache = false;
|
66 |
|
/**
|
67 |
|
* Fuerza la carga de los datos en cach? de solo lectura independientemente de su tama?o. Su
|
68 |
|
* uso suele ser util solo para depuraci?n. Su valor por defecto y recomendado
|
69 |
|
* es siempre false.
|
70 |
|
*/
|
71 |
|
public static boolean forceToLoadInReadOnlyCache = false;
|
72 |
|
/**
|
73 |
|
* Valor con el que se rellena una banda no valida del buffer. Una banda no valida es la que
|
74 |
|
* no tiene datos asignados y tampoco puede ser null. Todas las bandas no validas de un buffer
|
75 |
|
* apuntan por referencia a la misma banda.
|
76 |
|
*/
|
77 |
|
protected double notValidValue = 0D;
|
|
52 |
protected int width;
|
|
53 |
protected int height;
|
|
54 |
protected int nBands;
|
|
55 |
protected int dataType;
|
|
56 |
|
|
57 |
/**
|
|
58 |
* Variable est?tica que si est? a false desactiva el uso de cach?. Puede ser usada por un cliente
|
|
59 |
* para cargar siempre los datos en memoria. independientemente de su tama?o.
|
|
60 |
*/
|
|
61 |
public static boolean cacheOn = true;
|
|
62 |
/**
|
|
63 |
* Fuerza la carga de los datos en cach? independientemente de su tama?o. Su
|
|
64 |
* uso suele ser util solo para depuraci?n. Su valor por defecto y recomendado
|
|
65 |
* es siempre false.
|
|
66 |
*/
|
|
67 |
public static boolean forceToLoadInCache = false;
|
|
68 |
/**
|
|
69 |
* Fuerza la carga de los datos en cach? de solo lectura independientemente de su tama?o. Su
|
|
70 |
* uso suele ser util solo para depuraci?n. Su valor por defecto y recomendado
|
|
71 |
* es siempre false.
|
|
72 |
*/
|
|
73 |
public static boolean forceToLoadInReadOnlyCache = false;
|
|
74 |
/**
|
|
75 |
* Valor con el que se rellena una banda no valida del buffer. Una banda no valida es la que
|
|
76 |
* no tiene datos asignados y tampoco puede ser null. Todas las bandas no validas de un buffer
|
|
77 |
* apuntan por referencia a la misma banda.
|
|
78 |
*/
|
|
79 |
protected double notValidValue = 0D;
|
78 |
80 |
|
79 |
|
/**
|
80 |
|
* Genera instancias del buffer de datos adecuado al tama?o del raster. Si no hay muchos datos
|
81 |
|
* (menos de cacheMemorySize) crear? un buffer en memoria. Si hay m?s de esta cantidad
|
82 |
|
* entonces crearemos un buffer cacheado (RasterCache). A partir de la cantidad se?alada
|
83 |
|
* por multicacheMemorySize haremos un buffer cacheado donde cada p?gina no ocupa todo
|
84 |
|
* el ancho del raster ya que este ser? muy grande. La gesti?n de una cache donde cada
|
85 |
|
* pagina ha de partir una l?nea lleva una complejidad a?adida.
|
86 |
|
*
|
87 |
|
* @param dataType Tipo de dato
|
88 |
|
* @param width Ancho
|
89 |
|
* @param height Alto
|
90 |
|
* @param bandNr Banda
|
91 |
|
* @param malloc
|
92 |
|
* @return
|
93 |
|
* @throws RasterDriverException
|
94 |
|
* @throws NotSupportedExtensionException
|
95 |
|
* @throws FileNotFoundException
|
96 |
|
*/
|
97 |
|
public static RasterBuffer getBuffer(int dataType, int width, int height, int bandNr, boolean malloc, String filePath)
|
98 |
|
/*throws FileNotFoundException, NotSupportedExtensionException, RasterDriverException*/{
|
99 |
|
//Opci?n de cachear siempre activada (Solo DEBUG)
|
100 |
|
if(forceToLoadInCache)
|
101 |
|
return new RasterCache(dataType, width, height, bandNr);
|
102 |
|
if(forceToLoadInReadOnlyCache && filePath != null){
|
103 |
|
try {
|
104 |
|
return new RasterReadOnlyHugeBuffer(dataType, width, height, bandNr, filePath);
|
105 |
|
} catch (FileNotFoundException e) {
|
106 |
|
//TODO: EXCEPTION: Modificar el lanzamiento de excepciones del RasterBuffer
|
107 |
|
e.printStackTrace();
|
108 |
|
} catch (NotSupportedExtensionException e) {
|
109 |
|
e.printStackTrace();
|
110 |
|
} catch (RasterDriverException e) {
|
111 |
|
e.printStackTrace();
|
112 |
|
}
|
113 |
|
}
|
114 |
|
|
115 |
|
if(cacheOn){
|
116 |
|
long size = (RasterUtilities.getBytesFromRasterBufType(dataType) * width * height * bandNr) / 1024;
|
117 |
|
long ms1 = cacheMemorySize * 1024;
|
118 |
|
long ms2 = multicacheMemorySize * 1024;
|
119 |
|
if(size <= ms1)
|
120 |
|
return new RasterMemoryBuffer(dataType, width, height, bandNr, malloc);
|
121 |
|
else{
|
122 |
|
//if(filePath == null)
|
123 |
|
return new RasterCache(dataType, width, height, bandNr);
|
124 |
|
/*else
|
125 |
|
return new RasterReadOnlyHugeBuffer(dataType, width, height, bandNr, filePath);*/
|
126 |
|
}
|
127 |
|
}else
|
|
81 |
/**
|
|
82 |
* Genera instancias del buffer de datos adecuado al tama?o del raster. Si no hay muchos datos
|
|
83 |
* (menos de cacheMemorySize) crear? un buffer en memoria. Si hay m?s de esta cantidad
|
|
84 |
* entonces crearemos un buffer cacheado (RasterCache). A partir de la cantidad se?alada
|
|
85 |
* por multicacheMemorySize haremos un buffer cacheado donde cada p?gina no ocupa todo
|
|
86 |
* el ancho del raster ya que este ser? muy grande. La gesti?n de una cache donde cada
|
|
87 |
* pagina ha de partir una l?nea lleva una complejidad a?adida.
|
|
88 |
*
|
|
89 |
* @param dataType Tipo de dato
|
|
90 |
* @param width Ancho
|
|
91 |
* @param height Alto
|
|
92 |
* @param bandNr Banda
|
|
93 |
* @param malloc
|
|
94 |
* @return
|
|
95 |
* @throws RasterDriverException
|
|
96 |
* @throws NotSupportedExtensionException
|
|
97 |
* @throws FileNotFoundException
|
|
98 |
*/
|
|
99 |
public static RasterBuffer getBuffer(int dataType, int width, int height, int bandNr, boolean malloc, String filePath)
|
|
100 |
/*throws FileNotFoundException, NotSupportedExtensionException, RasterDriverException*/{
|
|
101 |
//Opci?n de cachear siempre activada (Solo DEBUG)
|
|
102 |
if(forceToLoadInCache)
|
|
103 |
return new RasterCache(dataType, width, height, bandNr);
|
|
104 |
if(forceToLoadInReadOnlyCache && filePath != null){
|
|
105 |
try {
|
|
106 |
return new RasterReadOnlyHugeBuffer(dataType, width, height, bandNr, filePath);
|
|
107 |
} catch (FileNotFoundException e) {
|
|
108 |
//TODO: EXCEPTION: Modificar el lanzamiento de excepciones del RasterBuffer
|
|
109 |
e.printStackTrace();
|
|
110 |
} catch (NotSupportedExtensionException e) {
|
|
111 |
e.printStackTrace();
|
|
112 |
} catch (RasterDriverException e) {
|
|
113 |
e.printStackTrace();
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
if(cacheOn){
|
|
118 |
long size = (RasterUtilities.getBytesFromRasterBufType(dataType) * width * height * bandNr) / 1024;
|
|
119 |
long ms1 = cacheMemorySize * 1024;
|
|
120 |
long ms2 = multicacheMemorySize * 1024;
|
|
121 |
if(size <= ms1)
|
128 |
122 |
return new RasterMemoryBuffer(dataType, width, height, bandNr, malloc);
|
129 |
|
}
|
130 |
|
|
131 |
|
/**
|
132 |
|
* Reserva de memoria para el rasterbuf
|
133 |
|
* @param dataType Tipo de dato
|
134 |
|
* @param width Ancho
|
135 |
|
* @param height Alto
|
136 |
|
* @param bandNr Numero de bandas
|
137 |
|
* @param orig
|
138 |
|
*/
|
139 |
|
public abstract void malloc(int dataType, int width, int height, int bandNr);
|
140 |
|
|
141 |
|
/*
|
142 |
|
* (non-Javadoc)
|
143 |
|
* @see org.gvsig.fmap.driver.IBuffer#getWidth()
|
144 |
|
*/
|
145 |
|
public int getWidth() {
|
146 |
|
return width;
|
147 |
|
}
|
|
123 |
else{
|
|
124 |
//if(filePath == null)
|
|
125 |
return new RasterCache(dataType, width, height, bandNr);
|
|
126 |
/*else
|
|
127 |
return new RasterReadOnlyHugeBuffer(dataType, width, height, bandNr, filePath);*/
|
|
128 |
}
|
|
129 |
}else
|
|
130 |
return new RasterMemoryBuffer(dataType, width, height, bandNr, malloc);
|
|
131 |
}
|
|
132 |
|
|
133 |
/**
|
|
134 |
* Reserva de memoria para el rasterbuf
|
|
135 |
* @param dataType Tipo de dato
|
|
136 |
* @param width Ancho
|
|
137 |
* @param height Alto
|
|
138 |
* @param bandNr Numero de bandas
|
|
139 |
* @param orig
|
|
140 |
*/
|
|
141 |
public abstract void malloc(int dataType, int width, int height, int bandNr);
|
|
142 |
|
|
143 |
/*
|
|
144 |
* (non-Javadoc)
|
|
145 |
* @see org.gvsig.fmap.driver.IBuffer#getWidth()
|
|
146 |
*/
|
|
147 |
public int getWidth() {
|
|
148 |
return width;
|
|
149 |
}
|
148 |
150 |
|
149 |
|
/*
|
150 |
|
* (non-Javadoc)
|
151 |
|
* @see org.gvsig.fmap.driver.IBuffer#getHeight()
|
152 |
|
*/
|
153 |
|
public int getHeight() {
|
154 |
|
return height;
|
155 |
|
}
|
|
151 |
/*
|
|
152 |
* (non-Javadoc)
|
|
153 |
* @see org.gvsig.fmap.driver.IBuffer#getHeight()
|
|
154 |
*/
|
|
155 |
public int getHeight() {
|
|
156 |
return height;
|
|
157 |
}
|
156 |
158 |
|
157 |
|
/*
|
158 |
|
* (non-Javadoc)
|
159 |
|
* @see org.gvsig.fmap.driver.IBuffer#getBandCount()
|
160 |
|
*/
|
161 |
|
public int getBandCount() {
|
162 |
|
return nBands;
|
163 |
|
}
|
|
159 |
/*
|
|
160 |
* (non-Javadoc)
|
|
161 |
* @see org.gvsig.fmap.driver.IBuffer#getBandCount()
|
|
162 |
*/
|
|
163 |
public int getBandCount() {
|
|
164 |
return nBands;
|
|
165 |
}
|
164 |
166 |
|
165 |
|
/**
|
166 |
|
* Obtiene el tipo de dato. Los tipos de dato posibles est?n definidos en IRaster.
|
167 |
|
* @return tipo de datos
|
168 |
|
*/
|
|
167 |
/**
|
|
168 |
* Obtiene el tipo de dato. Los tipos de dato posibles est?n definidos en IRaster.
|
|
169 |
* @return tipo de datos
|
|
170 |
*/
|
169 |
171 |
public int getDataType() {
|
170 |
172 |
return dataType;
|
171 |
173 |
}
|
... | ... | |
381 |
383 |
return null;
|
382 |
384 |
Histogram hist = new Histogram(getBandCount(), 256);
|
383 |
385 |
for (int iBand = 0; iBand < getBandCount(); iBand++)
|
384 |
|
for (int row = 0; row < getHeight(); row++)
|
|
386 |
for (int row = 0; row < getHeight(); row++) {
|
385 |
387 |
for (int col = 0; col < getWidth(); col++)
|
386 |
388 |
hist.incrementPxValue(iBand, (getElemByte(row, col, iBand) & 0xff));
|
|
389 |
if (isCanceled()) return null;
|
|
390 |
percent = ((iBand*getHeight() + row) * 100) /(getHeight() * getBandCount());
|
|
391 |
}
|
387 |
392 |
percent = 100;
|
388 |
393 |
return hist;
|
389 |
394 |
}
|
... | ... | |
393 |
398 |
* @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getHistogramUsingClasses(org.gvsig.raster.shared.DataClassList)
|
394 |
399 |
*/
|
395 |
400 |
public Histogram getHistogramUsingClasses(DataClassList classes) throws HistogramException {
|
|
401 |
percent = 0;
|
396 |
402 |
Histogram hist = new Histogram(getBandCount(), classes.length());
|
397 |
403 |
for (int iBand = 0; iBand < getBandCount(); iBand++) {
|
398 |
404 |
for (int col = 0; col < getHeight(); col++) {
|
... | ... | |
407 |
413 |
}
|
408 |
414 |
if(pixelValue >= 0)
|
409 |
415 |
hist.incrementPxValue(iBand, pixelValue);
|
410 |
|
}
|
|
416 |
}
|
|
417 |
if (isCanceled()) return null;
|
|
418 |
percent = ((iBand*getHeight() + col) * 100) / (getHeight() * getBandCount());
|
411 |
419 |
}
|
412 |
420 |
}
|
|
421 |
percent = 100;
|
413 |
422 |
return hist;
|
414 |
423 |
}
|
|
424 |
|
|
425 |
/*
|
|
426 |
* (non-Javadoc)
|
|
427 |
* @see org.gvsig.raster.util.IHistogramable#resetPercent()
|
|
428 |
*/
|
|
429 |
public void resetPercent() {
|
|
430 |
percent = 0;
|
|
431 |
}
|
|
432 |
|
|
433 |
/*
|
|
434 |
* (non-Javadoc)
|
|
435 |
* @see org.gvsig.raster.util.IHistogramable#getPercent()
|
|
436 |
*/
|
|
437 |
public int getPercent() {
|
|
438 |
return percent;
|
|
439 |
}
|
|
440 |
|
|
441 |
/*
|
|
442 |
* (non-Javadoc)
|
|
443 |
* @see org.gvsig.raster.util.ICancellable#isCanceled()
|
|
444 |
*/
|
|
445 |
public boolean isCanceled() {
|
|
446 |
return canceled;
|
|
447 |
}
|
|
448 |
|
|
449 |
/*
|
|
450 |
* (non-Javadoc)
|
|
451 |
* @see org.gvsig.raster.util.ICancellable#setCanceled(boolean)
|
|
452 |
*/
|
|
453 |
public void setCanceled(boolean value) {
|
|
454 |
canceled = value;
|
|
455 |
}
|
415 |
456 |
}
|