Revision 11065 trunk/libraries/libRaster/src/org/gvsig/raster/dataaccess/buffer/RasterBuffer.java
RasterBuffer.java | ||
---|---|---|
47 | 47 |
public double noDataValue = -99999; |
48 | 48 |
protected int percent = 0; |
49 | 49 |
|
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;
|
|
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; |
|
78 | 78 |
|
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 |
|
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) |
|
128 | 120 |
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 |
} |
|
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 |
|
128 |
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 |
} |
|
148 | 148 |
|
149 |
/*
|
|
150 |
* (non-Javadoc)
|
|
151 |
* @see org.gvsig.fmap.driver.IBuffer#getHeight()
|
|
152 |
*/
|
|
153 |
public int getHeight() {
|
|
154 |
return height;
|
|
155 |
}
|
|
149 |
/* |
|
150 |
* (non-Javadoc) |
|
151 |
* @see org.gvsig.fmap.driver.IBuffer#getHeight() |
|
152 |
*/ |
|
153 |
public int getHeight() { |
|
154 |
return height; |
|
155 |
} |
|
156 | 156 |
|
157 |
/*
|
|
158 |
* (non-Javadoc)
|
|
159 |
* @see org.gvsig.fmap.driver.IBuffer#getBandCount()
|
|
160 |
*/
|
|
161 |
public int getBandCount() {
|
|
162 |
return nBands;
|
|
163 |
}
|
|
157 |
/* |
|
158 |
* (non-Javadoc) |
|
159 |
* @see org.gvsig.fmap.driver.IBuffer#getBandCount() |
|
160 |
*/ |
|
161 |
public int getBandCount() { |
|
162 |
return nBands; |
|
163 |
} |
|
164 | 164 |
|
165 |
/**
|
|
166 |
* Obtiene el tipo de dato. Los tipos de dato posibles est?n definidos en IRaster.
|
|
167 |
* @return tipo de datos
|
|
168 |
*/
|
|
165 |
/** |
|
166 |
* Obtiene el tipo de dato. Los tipos de dato posibles est?n definidos en IRaster. |
|
167 |
* @return tipo de datos |
|
168 |
*/ |
|
169 | 169 |
public int getDataType() { |
170 | 170 |
return dataType; |
171 | 171 |
} |
... | ... | |
414 | 414 |
} |
415 | 415 |
return hist; |
416 | 416 |
} |
417 |
|
|
417 |
|
|
418 |
/* |
|
419 |
* (non-Javadoc) |
|
420 |
* @see org.gvsig.raster.util.IHistogramable#resetPercent() |
|
421 |
*/ |
|
422 |
public void resetPercent() { |
|
423 |
percent = 0; |
|
424 |
} |
|
425 |
|
|
426 |
/* |
|
427 |
* (non-Javadoc) |
|
428 |
* @see org.gvsig.raster.util.IHistogramable#getPercent() |
|
429 |
*/ |
|
418 | 430 |
public int getPercent() { |
419 | 431 |
return percent; |
420 | 432 |
} |
Also available in: Unified diff