Revision 349 2.0/trunk/org.gvsig.gvsig3d/org.gvsig.gvsig3d.lib/org.gvsig.gvsig3d.lib.impl/src/main/java/org/gvsig/gvsig3d/impl/map3d/MapContext3DImpl.java
MapContext3DImpl.java | ||
---|---|---|
1107 | 1107 |
private UpdateDataEvent loadRasterData(FLayer layer, Envelope envelope, |
1108 | 1108 |
RequestDataEvent rde) { |
1109 | 1109 |
|
1110 |
// System.out.println("PETICION DE TILE!!!!!!!!!!"); |
|
1111 | 1110 |
UpdateDataEvent ude = new UpdateDataEvent(); |
1112 | 1111 |
ude.copyDataFromRequest(rde); |
1113 | 1112 |
if (layer instanceof DefaultFLyrRaster) { |
... | ... | |
1117 | 1116 |
|
1118 | 1117 |
rLayer = (DefaultFLyrRaster) layer; |
1119 | 1118 |
|
1120 |
// boolean exists = _cachedLayers.containsKey(rLayer); |
|
1121 |
// |
|
1122 |
// if (!exists) { |
|
1123 |
// |
|
1124 |
// _cachedLayers.put(rLayer, getCacheStruct(rLayer)); |
|
1125 |
// |
|
1126 |
// } |
|
1127 |
// |
|
1128 |
// CacheStruct cacheStruct = _cachedLayers.get(rLayer); |
|
1129 |
|
|
1130 | 1119 |
RasterQuery query = RasterLocator.getManager().createQuery(); |
1131 | 1120 |
|
1132 | 1121 |
org.gvsig.fmap.dal.coverage.datastruct.Extent extent = RasterLocator |
... | ... | |
1140 | 1129 |
query.setTileParameters(rde.getTileLevel(), rde.getTileX(), |
1141 | 1130 |
rde.getTileY(), extent, null); |
1142 | 1131 |
|
1143 |
// query.setAreaOfInterest(extent, 512, 512); |
|
1144 |
|
|
1145 |
// System.out.println("Tile Parameters:"); |
|
1146 |
// System.out.println("TileLevel: " + rde.getTileLevel()); |
|
1147 |
// System.out.println("TileX = " + rde.getTileX()); |
|
1148 |
// System.out.println("TileY = " + rde.getTileY()); |
|
1149 |
// System.out.println("Extent = " + extent.getULX() + " " |
|
1150 |
// + extent.getULY() + " " + extent.getLRX() + " " |
|
1151 |
// + extent.getLRY()); |
|
1152 |
|
|
1153 | 1132 |
try { |
1154 | 1133 |
Object[] result = rLayer.getDataStore().queryArray(query); |
1155 | 1134 |
Buffer rBuff = (Buffer) result[0]; |
1156 |
System.out.println("Vectores en el queryarray: " |
|
1157 |
+ result.length); |
|
1158 |
System.out.println("Size of raster buffer" |
|
1159 |
+ rBuff.getBandCount()); |
|
1160 | 1135 |
|
1161 | 1136 |
Buffer transparencyBuffer = (result != null && result.length > 1) ? (Buffer) result[1] |
1162 | 1137 |
: null; |
... | ... | |
1176 | 1151 |
|
1177 | 1152 |
if (lastTransparency.getAlphaBand() != null) |
1178 | 1153 |
addAlpha = 1; |
1179 |
// int bufferBands = rBuff.getBandCount(); |
|
1154 |
|
|
1180 | 1155 |
// Si el numero de bandas es mayor que 3 (RGB) no se pueden |
1181 | 1156 |
// dibujar todas |
1182 | 1157 |
int numBands = rLayer.getDataStore().getBandCount(); |
... | ... | |
1187 | 1162 |
ColorInterpretation cInt = rLayer.getDataStore() |
1188 | 1163 |
.getColorInterpretation(); |
1189 | 1164 |
|
1165 |
ColorTable colorTable = rLayer.getDataStore() |
|
1166 |
.getColorTable(); |
|
1167 |
|
|
1190 | 1168 |
int rgba[] = { 0, 1, 2, 3 }; |
1191 | 1169 |
|
1192 | 1170 |
rgba = setBandsInColors(cInt); |
1193 | 1171 |
|
1194 | 1172 |
int pixelFormat = 0; |
1173 |
boolean isPalette = (cInt |
|
1174 |
.getBand(ColorInterpretation.PAL_BAND) != -1); |
|
1195 | 1175 |
|
1196 |
// Si es tipo paleta cambiamos el pixelformat |
|
1197 |
// if (cInt.getBand(ColorInterpretation.PAL_BAND) != -1) { |
|
1198 |
// |
|
1199 |
// ImageDrawer d = new ImageDrawer((DefaultRender) rLayer |
|
1200 |
// .getDataStore().getRender()); |
|
1201 |
// d.setBuffer(procBuffer); |
|
1202 |
// // d.setStep(null); |
|
1203 |
// // d.setBufferSize(procBuffer.getWidth(), |
|
1204 |
// // procBuffer.getHeight()); |
|
1205 |
// java.awt.Image geoImage; |
|
1206 |
// try { |
|
1207 |
// geoImage = d.drawBufferOverImageObject(); |
|
1208 |
// |
|
1209 |
// ImageIO.write((BufferedImage) geoImage, "png", |
|
1210 |
// new File("/home/jzarzoso/basura/prueba.png")); |
|
1211 |
// ude.setRasterData((BufferedImage) geoImage); |
|
1212 |
// return ude; |
|
1213 |
// } catch (ProcessInterruptedException e2) { |
|
1214 |
// return null; |
|
1215 |
// } catch (IOException e) { |
|
1216 |
// // TODO Auto-generated catch block |
|
1217 |
// e.printStackTrace(); |
|
1218 |
// } |
|
1219 |
// |
|
1220 |
// } |
|
1221 |
// |
|
1222 |
// else |
|
1223 |
pixelFormat = convertPixelFormat(numBands + addAlpha); |
|
1176 |
if (isPalette) { |
|
1224 | 1177 |
|
1225 |
// System.out.println("Tile ancho: " + rBuff.getWidth() |
|
1226 |
// + " alto: " + rBuff.getHeight() |
|
1227 |
// + " bandas totales incluyendo alpha (si tiene): " |
|
1228 |
// + numBands); |
|
1178 |
pixelFormat = org.gvsig.osgvp.core.osg.Image.PixelFormat.GL_RGBA; |
|
1229 | 1179 |
|
1180 |
} |
|
1181 |
|
|
1182 |
else |
|
1183 |
pixelFormat = convertPixelFormat(numBands + addAlpha); |
|
1184 |
|
|
1230 | 1185 |
switch (procBuffer.getDataType()) { |
1231 | 1186 |
case Buffer.TYPE_BYTE: |
1232 |
ude.setRasterData( |
|
1233 |
buildByteBuffer(ude, procBuffer, |
|
1234 |
lastTransparency.getAlphaBand(), |
|
1235 |
numBands, rgba), procBuffer.getWidth(), |
|
1236 |
procBuffer.getHeight(), numBands + addAlpha, |
|
1237 |
pixelFormat, Image.DataType.GL_UNSIGNED_BYTE); |
|
1187 |
|
|
1188 |
byte[] byteBuffer = null; |
|
1189 |
if (isPalette) { |
|
1190 |
byteBuffer = buildByteBufferPalette(ude, |
|
1191 |
rBuff, colorTable, transparencyBuffer); |
|
1192 |
ude.setRasterData(byteBuffer, |
|
1193 |
procBuffer.getWidth(), |
|
1194 |
procBuffer.getHeight(), |
|
1195 |
4, pixelFormat, |
|
1196 |
Image.DataType.GL_UNSIGNED_BYTE); |
|
1197 |
} else { |
|
1198 |
byteBuffer = buildByteBuffer(ude, procBuffer, |
|
1199 |
lastTransparency.getAlphaBand(), numBands, |
|
1200 |
rgba); |
|
1201 |
ude.setRasterData(byteBuffer, |
|
1202 |
procBuffer.getWidth(), |
|
1203 |
procBuffer.getHeight(), |
|
1204 |
numBands + addAlpha, pixelFormat, |
|
1205 |
Image.DataType.GL_UNSIGNED_BYTE); |
|
1206 |
} |
|
1238 | 1207 |
break; |
1239 | 1208 |
case Buffer.TYPE_SHORT: |
1240 | 1209 |
ude.setRasterData( |
... | ... | |
1666 | 1635 |
return data; |
1667 | 1636 |
} |
1668 | 1637 |
|
1638 |
protected byte[] buildByteBufferPalette(UpdateDataEvent ude, Buffer rBuff, |
|
1639 |
ColorTable colorTable, Buffer transparencyBuffer) { |
|
1640 |
|
|
1641 |
int cont = 0; |
|
1642 |
|
|
1643 |
byte[] data = new byte[rBuff.getWidth() * rBuff.getHeight() * 4]; |
|
1644 |
|
|
1645 |
for (int i = 0; i < rBuff.getWidth(); i++) { |
|
1646 |
|
|
1647 |
for (int j = 0; j < rBuff.getHeight(); j++) { |
|
1648 |
|
|
1649 |
byte index = rBuff.getElemByte(i, j, 0); |
|
1650 |
|
|
1651 |
byte[] rgba = colorTable.getRGBAByBand((double) (index & 0xff)); |
|
1652 |
|
|
1653 |
for (int k = 0; k < 4; k++) { |
|
1654 |
data[cont] = rgba[k]; |
|
1655 |
if(k==3 && transparencyBuffer != null) |
|
1656 |
data[cont] = transparencyBuffer.getElemByte(i, j, 0); |
|
1657 |
cont++; |
|
1658 |
} |
|
1659 |
} |
|
1660 |
} |
|
1661 |
|
|
1662 |
|
|
1663 |
|
|
1664 |
return data; |
|
1665 |
} |
|
1666 |
|
|
1669 | 1667 |
protected short[] buildShortBuffer(UpdateDataEvent ude, Buffer rBuff, |
1670 | 1668 |
Buffer transparencyBuffer, int numBands, int[] rgba) { |
1671 | 1669 |
int cont = 0; |
... | ... | |
2109 | 2107 |
// Getting envelope positions |
2110 | 2108 |
double minLat = geoEnvelope.getMinimum(0); |
2111 | 2109 |
double maxLat = geoEnvelope.getMaximum(0); |
2112 |
double minLon = geoEnvelope.getMinimum(1); |
|
2113 |
double maxLon = geoEnvelope.getMaximum(1); |
|
2114 | 2110 |
|
2115 |
//When we create a new OSG layer without setting an envelope, it comes as(0,90,0,90) |
|
2116 |
//We don't want to zoom |
|
2117 |
// if ((minLat == 0) && (maxLat == 90) && (minLon == 0) && (maxLon == 90)) |
|
2118 |
// |
|
2119 |
// return; |
|
2120 |
|
|
2121 | 2111 |
double cenLon = geoEnvelope.getCenter(0); |
2122 | 2112 |
double cenLat = geoEnvelope.getCenter(1); |
2123 | 2113 |
|
Also available in: Unified diff