Revision 11975
trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/saveraster/operations/RasterizerLayer.java | ||
---|---|---|
34 | 34 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
35 | 35 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
36 | 36 |
import com.iver.utiles.swing.threads.Cancellable; |
37 |
|
|
38 | 37 |
/** |
39 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
|
40 |
* |
|
41 |
* Sirve datos solicitados por los drivers que salvan a raster.
|
|
42 |
* Hereda de Rasterizer y reescribe el m?todo readData que es el que
|
|
43 |
* ser? llamado desde el driver cada vez que vacie el buffer y
|
|
44 |
* necesite m?s datos.
|
|
38 |
* Sirve datos solicitados por los drivers que salvan a raster. Hereda de
|
|
39 |
* Rasterizer y reescribe el m?todo readData que es el que ser? llamado desde el
|
|
40 |
* driver cada vez que vacie el buffer y necesite m?s datos.
|
|
41 |
* |
|
42 |
* @version 04/06/2007
|
|
43 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
|
45 | 44 |
*/ |
46 |
public class RasterizerLayer implements IDataWriter, IIncrementable{ |
|
45 |
public class RasterizerLayer implements IDataWriter, IIncrementable {
|
|
47 | 46 |
|
48 | 47 |
private ViewPort viewPort = null; |
49 | 48 |
private ViewPort viewPortBlock = null; |
50 | 49 |
private FLayers flayers = null; |
51 | 50 |
private Color backgroundColor = null; |
52 | 51 |
private boolean firstRead = true; |
53 |
private int nBlocks = 0;
|
|
54 |
private double percentMax = 100.0D;
|
|
55 |
protected double wcIntervalo = 0;
|
|
56 |
protected Dimension dimension = null;
|
|
57 |
protected int blockSize = 0;
|
|
58 |
protected double wcAlto = 0;
|
|
59 |
protected int lastBlock = 0;
|
|
60 |
protected BufferedImage image = null;
|
|
61 |
protected int[] rasterData = null;
|
|
62 |
protected int contBlocks = 1;
|
|
63 |
protected int percent = 0;
|
|
64 |
protected int imgHeight = 0;
|
|
65 |
|
|
52 |
private int nBlocks = 0;
|
|
53 |
private double percentMax = 100.0D;
|
|
54 |
protected double wcIntervalo = 0;
|
|
55 |
protected Dimension dimension = null;
|
|
56 |
protected int blockSize = 0;
|
|
57 |
protected double wcAlto = 0;
|
|
58 |
protected int lastBlock = 0;
|
|
59 |
protected BufferedImage image = null;
|
|
60 |
protected int[] rasterData = null;
|
|
61 |
protected int contBlocks = 1;
|
|
62 |
protected int percent = 0;
|
|
63 |
protected int imgHeight = 0;
|
|
64 |
|
|
66 | 65 |
/** |
67 | 66 |
* Calculo del viewPort |
68 | 67 |
* @param vp |
69 | 68 |
*/ |
70 |
private void calcViewPort(ViewPort vp){ |
|
69 |
private void calcViewPort(ViewPort vp) {
|
|
71 | 70 |
Rectangle2D ext = null; |
72 | 71 |
|
73 |
if(viewPortBlock == null){
|
|
72 |
if (viewPortBlock == null) {
|
|
74 | 73 |
ext = new Rectangle2D.Double( vp.getExtent().getMinX(), |
75 | 74 |
vp.getExtent().getMaxY() - wcIntervalo, |
76 | 75 |
vp.getExtent().getWidth(), |
77 | 76 |
wcIntervalo |
78 | 77 |
); |
79 |
}else{
|
|
78 |
} else {
|
|
80 | 79 |
ext = new Rectangle2D.Double( vp.getExtent().getMinX(), |
81 | 80 |
vp.getExtent().getMinY() - wcIntervalo, |
82 | 81 |
vp.getExtent().getWidth(), |
... | ... | |
104 | 103 |
viewPort.setImageSize(vp.getImageSize()); |
105 | 104 |
viewPort.setExtent(vp.getExtent()); |
106 | 105 |
|
107 |
//Calculo del viewPort del primer bloque |
|
106 |
// Calculo del viewPort del primer bloque
|
|
108 | 107 |
|
109 | 108 |
wcAlto = viewPort.getExtent().getMaxY() - viewPort.getExtent().getMinY(); |
110 | 109 |
wcIntervalo = (blockSize * wcAlto) / viewPort.getImageHeight(); |
111 | 110 |
dimension = new Dimension(viewPort.getImageWidth(), blockSize); |
112 | 111 |
|
113 | 112 |
imgHeight = vp.getImageHeight(); |
114 |
nBlocks = (int)(vp.getImageHeight() / blockSize); |
|
115 |
|
|
116 |
//Tama?o de ?ltimo bloque en pixeles |
|
113 |
nBlocks = (int) (vp.getImageHeight() / blockSize);
|
|
114 |
|
|
115 |
// Tama?o de ?ltimo bloque en pixeles
|
|
117 | 116 |
lastBlock = vp.getImageHeight() - (nBlocks * blockSize); |
118 | 117 |
|
119 | 118 |
calcViewPort(viewPort); |
... | ... | |
128 | 127 |
public int[] readARGBData(int sX, int sY, int nBand){ |
129 | 128 |
return readData( sX, sY, nBand); |
130 | 129 |
} |
131 |
|
|
132 |
/* (non-Javadoc) |
|
133 |
* @see org.cresques.io.IDataWriter#readData(int, int, int) |
|
134 |
*/ |
|
130 |
|
|
135 | 131 |
public int[] readData(int sX, int sY, int nBand) { |
136 |
if(nBand == 0) { //Con nBand==0 se devuelven las 3 bandas
|
|
137 |
nBlocks = (int)Math.ceil(imgHeight / (double)blockSize);
|
|
132 |
if (nBand == 0) { // Con nBand==0 se devuelven las 3 bandas
|
|
133 |
nBlocks = (int) Math.ceil(imgHeight / (double) blockSize);
|
|
138 | 134 |
image = new BufferedImage(sX, sY, BufferedImage.TYPE_INT_RGB); |
139 | 135 |
Graphics2D g = (Graphics2D) image.getGraphics(); |
140 |
BufferedImage img = new BufferedImage( viewPortBlock.getImageWidth(), |
|
141 |
viewPortBlock.getImageHeight(), |
|
142 |
BufferedImage.TYPE_INT_ARGB); |
|
136 |
BufferedImage img = new BufferedImage(viewPortBlock.getImageWidth(), viewPortBlock.getImageHeight(), BufferedImage.TYPE_INT_ARGB); |
|
143 | 137 |
g.setColor(backgroundColor); |
144 | 138 |
g.fillRect(0, 0, viewPortBlock.getImageWidth(), viewPortBlock.getImageHeight()); |
145 |
try{ |
|
146 |
//TODO: FUNCIONALIDAD: Salvar los m?ximos y m?nimos para salvar 16 bits |
|
147 |
|
|
148 |
//Si es la primera lectura salvamos los valores de m?ximo y m?nimo para la aplicaci?n |
|
149 |
//de realce si la imagen es de 16 bits. |
|
150 |
if(firstRead){ |
|
151 |
for(int i=0;i<flayers.getLayersCount();i++) { |
|
152 |
if(flayers.getLayer(i) instanceof FLyrRaster) { |
|
153 |
FLyrRaster raster = (FLyrRaster)flayers.getLayer(i); |
|
154 |
if( raster.getSource().getDataType() == RasterBuf.TYPE_SHORT || |
|
155 |
raster.getSource().getDataType() == RasterBuf.TYPE_USHORT) { |
|
139 |
try { |
|
140 |
// TODO: FUNCIONALIDAD: Salvar los m?ximos y m?nimos para salvar 16 bits |
|
141 |
|
|
142 |
// Si es la primera lectura salvamos los valores de m?ximo y m?nimo para la aplicaci?n |
|
143 |
// de realce si la imagen es de 16 bits. |
|
144 |
if (firstRead) { |
|
145 |
for (int i = 0; i < flayers.getLayersCount(); i++) { |
|
146 |
if (flayers.getLayer(i) instanceof FLyrRaster) { |
|
147 |
FLyrRaster raster = (FLyrRaster) flayers.getLayer(i); |
|
148 |
if (raster.getSource().getDataType() == RasterBuf.TYPE_SHORT || raster.getSource().getDataType() == RasterBuf.TYPE_USHORT) { |
|
156 | 149 |
//Statistic stats = raster.getSource().getFilterStack().getStats(); |
157 | 150 |
//stats.history.add(stats.new History(raster.getName(), stats.minBandValue, stats.maxBandValue, stats.secondMinBandValue, stats.secondMaxBandValue)); |
158 | 151 |
} |
... | ... | |
172 | 165 |
flayers.setDirty(true); |
173 | 166 |
flayers.draw(image, g, viewPortBlock, cancel, flayers.getMapContext().getScaleView()); |
174 | 167 |
|
175 |
//Si es el ?ltimo bloque vaciamos el historial de m?ximos y m?nimos |
|
176 |
if((contBlocks + 1) == nBlocks) { |
|
177 |
for(int i=0;i<flayers.getLayersCount();i++) { |
|
178 |
if(flayers.getLayer(i) instanceof FLyrRaster) { |
|
179 |
FLyrRaster raster = (FLyrRaster)flayers.getLayer(i); |
|
180 |
if( raster.getSource().getDataType() == RasterBuf.TYPE_SHORT || |
|
181 |
raster.getSource().getDataType() == RasterBuf.TYPE_USHORT){ |
|
168 |
// Si es el ?ltimo bloque vaciamos el historial de m?ximos y m?nimos |
|
169 |
if ((contBlocks + 1) == nBlocks) { |
|
170 |
for (int i = 0; i < flayers.getLayersCount(); i++) { |
|
171 |
if (flayers.getLayer(i) instanceof FLyrRaster) { |
|
172 |
FLyrRaster raster = (FLyrRaster) flayers.getLayer(i); |
|
173 |
if (raster.getSource().getDataType() == RasterBuf.TYPE_SHORT || raster.getSource().getDataType() == RasterBuf.TYPE_USHORT) { |
|
182 | 174 |
raster.getSource().getFilterStack().getStats().history.clear(); |
183 | 175 |
//Statistic stats = raster.getSource().getFilterStack().getStats(); |
184 | 176 |
} |
... | ... | |
191 | 183 |
} |
192 | 184 |
rasterData = image.getRGB(0, 0, sX, sY, rasterData, 0, sX); |
193 | 185 |
|
194 |
//Calculamos el viewPort del sgte bloque |
|
186 |
// Calculamos el viewPort del sgte bloque
|
|
195 | 187 |
|
196 |
if(((contBlocks+1) * blockSize) <= viewPort.getImageHeight())
|
|
188 |
if (((contBlocks + 1) * blockSize) <= viewPort.getImageHeight())
|
|
197 | 189 |
dimension = new Dimension(sX, sY); |
198 |
else { //Calculo de la altura del ?ltimo bloque |
|
199 |
dimension = new Dimension(sX, (int)(viewPort.getImageHeight() - (contBlocks * blockSize))); |
|
200 |
wcIntervalo = (lastBlock*wcAlto) / viewPort.getImageHeight();
|
|
190 |
else { // Calculo de la altura del ?ltimo bloque
|
|
191 |
dimension = new Dimension(sX, (int) (viewPort.getImageHeight() - (contBlocks * blockSize)));
|
|
192 |
wcIntervalo = (lastBlock * wcAlto) / viewPort.getImageHeight();
|
|
201 | 193 |
} |
202 | 194 |
|
203 | 195 |
calcViewPort(viewPortBlock); |
204 | 196 |
|
205 |
percent = (int)((100 * (contBlocks)) / nBlocks); |
|
206 |
contBlocks ++;
|
|
207 |
|
|
197 |
percent = (int) ((100 * (contBlocks)) / nBlocks);
|
|
198 |
contBlocks++; |
|
199 |
|
|
208 | 200 |
return rasterData; |
209 | 201 |
} |
210 | 202 |
|
211 | 203 |
return null; |
212 | 204 |
} |
213 |
|
|
205 |
|
|
214 | 206 |
/** |
215 |
* Asigna el ancho del bloque
|
|
216 |
* @param sizeBlock Ancho del bloque en pixeles
|
|
217 |
*/
|
|
207 |
* Asigna el ancho del bloque
|
|
208 |
* @param sizeBlock Ancho del bloque en pixeles
|
|
209 |
*/
|
|
218 | 210 |
public void setBlockSize(int blockSize) { |
219 | 211 |
this.blockSize = blockSize; |
220 | 212 |
} |
... | ... | |
253 | 245 |
public short[][] readShortData(int sizeX, int sizeY) { |
254 | 246 |
return null; |
255 | 247 |
} |
256 |
|
|
248 |
|
|
257 | 249 |
/* |
258 |
* (non-Javadoc)
|
|
250 |
* (non-Javadoc) |
|
259 | 251 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getTitle() |
260 | 252 |
*/ |
261 | 253 |
public String getTitle() { |
... | ... | |
263 | 255 |
} |
264 | 256 |
|
265 | 257 |
/* |
266 |
* (non-Javadoc)
|
|
258 |
* (non-Javadoc) |
|
267 | 259 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getLog() |
268 | 260 |
*/ |
269 | 261 |
public String getLog() { |
... | ... | |
271 | 263 |
} |
272 | 264 |
|
273 | 265 |
/* |
274 |
* (non-Javadoc)
|
|
266 |
* (non-Javadoc) |
|
275 | 267 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getLabel() |
276 | 268 |
*/ |
277 | 269 |
public String getLabel() { |
... | ... | |
279 | 271 |
} |
280 | 272 |
|
281 | 273 |
/* |
282 |
* (non-Javadoc)
|
|
274 |
* (non-Javadoc) |
|
283 | 275 |
* @see org.gvsig.gui.beans.incrementabletask.IIncrementable#getPercent() |
284 | 276 |
*/ |
285 | 277 |
public int getPercent() { |
286 | 278 |
return percent; |
287 | 279 |
} |
288 |
|
|
289 | 280 |
} |
Also available in: Unified diff