Revision 2438 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/provider/fusion/BufferListFusion.java
BufferListFusion.java | ||
---|---|---|
3 | 3 |
import java.awt.geom.Rectangle2D; |
4 | 4 |
import java.util.List; |
5 | 5 |
|
6 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
7 | 6 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
8 | 7 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
9 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
|
10 |
import org.gvsig.raster.impl.DefaultRasterManager; |
|
11 | 8 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
12 | 9 |
|
13 | 10 |
/** |
... | ... | |
33 | 30 |
private List<Extent> bboxList = null; |
34 | 31 |
private PixelSquareStructure pxSquare = null; |
35 | 32 |
private AbstractFusionMethod fusion = null; |
33 |
private int alphaBandNumber = -1; |
|
36 | 34 |
|
37 |
public class PixelSquareStructure { |
|
38 |
public double pixelSize = 0; |
|
39 |
public int dataType = Buffer.TYPE_UNDEFINED; |
|
40 |
public int bandCount = 0; |
|
41 |
public int width = 0; |
|
42 |
public int height = 0; |
|
43 |
public Extent bbox = null; |
|
44 |
public NoData nodata = null; |
|
45 |
public Buffer buffer = null; |
|
46 |
|
|
47 |
public PixelSquareStructure( |
|
48 |
Buffer buf, |
|
49 |
Extent bbox, |
|
50 |
double pixelSize) { |
|
51 |
this.pixelSize = pixelSize; |
|
52 |
this.dataType = buf.getDataType(); |
|
53 |
this.bandCount = buf.getBandCount(); |
|
54 |
this.width = buf.getWidth(); |
|
55 |
this.height = buf.getHeight(); |
|
56 |
nodata = buf.getNoDataValue() != null ? |
|
57 |
buf.getNoDataValue() : |
|
58 |
RasterLocator.getManager().getDataStructFactory().createDefaultNoData(bandCount, dataType); |
|
59 |
this.bbox = bbox; |
|
60 |
this.buffer = buf; |
|
61 |
} |
|
62 |
|
|
63 |
public PixelSquareStructure( |
|
64 |
double pixelSize, |
|
65 |
int bandCount, |
|
66 |
int datatype) { |
|
67 |
this.pixelSize = pixelSize; |
|
68 |
this.dataType = datatype; |
|
69 |
this.bandCount = bandCount; |
|
70 |
this.width = (int)Math.ceil(bbox.width() * pixelSize); |
|
71 |
this.height = (int)Math.ceil(bbox.height() * pixelSize); |
|
72 |
nodata = RasterLocator.getManager().getDataStructFactory().createDefaultNoData(bandCount, datatype); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
public static PixelSquareStructure buildPixelSquareStructure( |
|
77 |
Buffer buf, |
|
78 |
Extent bbox, |
|
79 |
double pixelSize) { |
|
80 |
return new BufferListFusion().new PixelSquareStructure(buf, bbox, pixelSize); |
|
81 |
} |
|
82 |
|
|
83 |
public static PixelSquareStructure buildPixelSquareStructure( |
|
84 |
double pixelSize, |
|
85 |
int bandCount, |
|
86 |
int datatype) { |
|
87 |
return new BufferListFusion().new PixelSquareStructure(pixelSize, bandCount, datatype); |
|
88 |
} |
|
89 |
|
|
90 |
public BufferListFusion() {} |
|
91 |
|
|
92 | 35 |
public BufferListFusion( |
93 | 36 |
List<Buffer> bufferList, |
94 | 37 |
PixelSquareStructure pxSquare, |
... | ... | |
112 | 55 |
* @return |
113 | 56 |
*/ |
114 | 57 |
public Buffer getWindow() { |
115 |
if(pxSquare.buffer == null) { |
|
116 |
pxSquare.buffer = DefaultRasterManager.getInstance().createBuffer( |
|
117 |
pxSquare.dataType, pxSquare.width, pxSquare.height, pxSquare.bandCount, true); |
|
118 |
} |
|
119 |
|
|
120 | 58 |
if(pxSquare.dataType == Buffer.TYPE_BYTE) { |
121 | 59 |
for (int row = 0; row < pxSquare.buffer.getHeight(); row++) { |
122 | 60 |
for (int col = 0; col < pxSquare.buffer.getWidth(); col++) { |
123 |
pxSquare.buffer.setElemByte(row, col, fusion.getByteValue(row, col)); |
|
61 |
boolean hasData = false; |
|
62 |
|
|
63 |
for (int band = 0; band < fusion.getBandCount(); band++) { |
|
64 |
Byte value = fusion.getByteValue(row, col, band); |
|
65 |
if(value != null) { |
|
66 |
pxSquare.buffer.setElem(row, col, band, value.byteValue()); |
|
67 |
hasData = true; |
|
68 |
value = null; |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
for (int band = fusion.getBandCount(); band < pxSquare.buffer.getBandCount(); band++) { |
|
73 |
pxSquare.buffer.setElem(row, col, band, (byte)255); |
|
74 |
} |
|
75 |
|
|
76 |
if(alphaBandNumber != -1 && alphaBandNumber < pxSquare.buffer.getBandCount()) |
|
77 |
if(hasData) //No data has been written |
|
78 |
pxSquare.buffer.setElem(row, col, alphaBandNumber, (byte)255); |
|
79 |
else |
|
80 |
pxSquare.buffer.setElem(row, col, alphaBandNumber, (byte)0); |
|
124 | 81 |
} |
125 | 82 |
} |
126 | 83 |
} |
... | ... | |
128 | 85 |
if(pxSquare.dataType == Buffer.TYPE_FLOAT) { |
129 | 86 |
for (int row = 0; row < pxSquare.buffer.getHeight(); row++) { |
130 | 87 |
for (int col = 0; col < pxSquare.buffer.getWidth(); col++) { |
131 |
pxSquare.buffer.setElemFloat(row, col, fusion.getFloatValue(row, col)); |
|
88 |
for (int band = 0; band < fusion.getBandCount(); band++) { |
|
89 |
pxSquare.buffer.setElem(row, col, band, fusion.getFloatValue(row, col, band)); |
|
90 |
} |
|
91 |
for (int band = fusion.getBandCount(); band < pxSquare.buffer.getBandCount(); band++) { |
|
92 |
pxSquare.buffer.setElem(row, col, band, 0F); |
|
93 |
} |
|
132 | 94 |
} |
133 | 95 |
} |
134 | 96 |
} |
... | ... | |
235 | 197 |
} |
236 | 198 |
bufferList.clear(); |
237 | 199 |
} |
200 |
|
|
201 |
public void setAlphaBand(int alphaBandNumber) { |
|
202 |
this.alphaBandNumber = alphaBandNumber; |
|
203 |
} |
|
238 | 204 |
|
239 | 205 |
/*public void setNoDataValue(int datatype) { |
240 | 206 |
NoData noData = RasterLocator.getManager().getDataStructFactory().createDefaultNoData(bandCount, datatype); |
Also available in: Unified diff