Revision 1032
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalNative.java | ||
---|---|---|
817 | 817 |
x = 0; |
818 | 818 |
if(y < 0) |
819 | 819 |
y = 0; |
820 |
readData(buf, bandList, x, y, wh[0], wh[1], wh[0], wh[1], 0, 0, stpBuffer);
|
|
820 |
readDataCachedBuffer(buf, bandList, new int[]{x, y, wh[0], wh[1]}, wh[0], wh[1], 0, 0, stpBuffer);
|
|
821 | 821 |
return; |
822 | 822 |
} |
823 | 823 |
|
824 |
readData(buf, bandList, x, y, nWidth, nHeight, nWidth, nHeight, 0, 0, stpBuffer);
|
|
824 |
readDataCachedBuffer(buf, bandList, new int[]{x, y, nWidth, nHeight}, nWidth, nHeight, 0, 0, stpBuffer);
|
|
825 | 825 |
} |
826 | 826 |
|
827 | 827 |
/** |
... | ... | |
917 | 917 |
stpBuffer[3] = (int)((stpBuffer[3] * bufHeight) / nHeight); |
918 | 918 |
bufWidth = (int)Math.abs(stpBuffer[2] - stpBuffer[0]); |
919 | 919 |
bufHeight = (int)Math.abs(stpBuffer[3] - stpBuffer[1]); |
920 |
readData(buf, bandList, x, y, wh[0], wh[1], bufWidth, bufHeight, 0, 0, stpBuffer);
|
|
920 |
readDataCachedBuffer(buf, bandList, new int[]{x, y, wh[0], wh[1]}, bufWidth, bufHeight, 0, 0, stpBuffer);
|
|
921 | 921 |
return; |
922 | 922 |
} |
923 | 923 |
|
... | ... | |
927 | 927 |
if ((y + nHeight) > gdalBands[0].getRasterBandYSize()) |
928 | 928 |
nHeight = gdalBands[0].getRasterBandYSize() - y; |
929 | 929 |
|
930 |
readData(buf, bandList, x, y, (int)nWidth, (int)nHeight, bufWidth, bufHeight, stpX, stpY, stpBuffer);
|
|
930 |
readDataCachedBuffer(buf, bandList, new int[]{x, y, (int)nWidth, (int)nHeight}, bufWidth, bufHeight, stpX, stpY, stpBuffer);
|
|
931 | 931 |
} |
932 | 932 |
|
933 | 933 |
private void adjustPoints(Point2D ul, Point2D lr) { |
... | ... | |
961 | 961 |
|
962 | 962 |
for(int iBand = 1; iBand < gdalBands.length; iBand++) |
963 | 963 |
gdalBands[iBand] = getRasterBand(iBand + 1); |
964 |
|
|
964 |
|
|
965 | 965 |
assignDataTypeFromGdalRasterBands(gdalBands); |
966 |
|
|
966 |
|
|
967 | 967 |
int[] stepBuffer = new int[]{0, 0, w, h}; |
968 |
readData(buf, bandList, x, y, w, h, w, h, 0, 0, stepBuffer); |
|
969 |
//int yMax = y + h; |
|
970 |
//readDataByLine(buf, bandList, x, y, w, yMax); |
|
968 |
readDataCachedBuffer(buf, bandList, new int[]{x, y, w, h}, w, h, 0, 0, stepBuffer); |
|
971 | 969 |
} |
970 |
|
|
972 | 971 |
|
972 |
|
|
973 | 973 |
/** |
974 | 974 |
* Lee una ventana de datos con resampleo a partir de coordenadas en pixeles. Este m�todo lee la |
975 | 975 |
* ventana de una vez cargando los datos de un golpe en el buffer. |
... | ... | |
998 | 998 |
assignDataTypeFromGdalRasterBands(gdalBands); |
999 | 999 |
|
1000 | 1000 |
int[] stpBuffer = new int[]{0, 0 , buf.getWidth(), buf.getHeight()}; |
1001 |
readData(buf, bandList, x, y, w, h, bufWidth, bufHeight, 0, 0, stpBuffer);
|
|
1001 |
readDataCachedBuffer(buf, bandList, new int[]{x, y, w, h}, bufWidth, bufHeight, 0, 0, stpBuffer);
|
|
1002 | 1002 |
} |
1003 | 1003 |
|
1004 | 1004 |
/** |
... | ... | |
1014 | 1014 |
} |
1015 | 1015 |
setDataType(dt); |
1016 | 1016 |
} |
1017 |
|
|
1018 |
/** |
|
1019 |
* Lee una ventana de datos. Esta funci?n es usuada por |
|
1020 |
* readWindow para coordenadas reales y readWindow en coordenadas pixel. Esta es una versi?n de readData pero |
|
1021 |
* comprueba si el buffer es cacheado y si lo es pide por trozos para no intentar cargar desde gdal demasiados |
|
1022 |
* datos. |
|
1023 |
* @param buf Buffer donde se almacenan los datos |
|
1024 |
* @param bandList Lista de bandas que queremos leer y sobre que bandas del buffer de destino queremos escribirlas |
|
1025 |
* @param inputWindow |
|
1026 |
* <UL> |
|
1027 |
* <LI>inputWindow[0]:Posici?n X en pixeles de la imagen de entrada</LI> |
|
1028 |
* <LI>inputWindow[1]:Posici?n Y en pixeles de la imagen de entrada</LI> |
|
1029 |
* <LI>inputWindow[2]:Ancho en p?xeles a leer de la imagen de entrada</LI> |
|
1030 |
* <LI>inputWindow[3]:Alto en p?xeles a leer de la imagen de entrada</LI> |
|
1031 |
* </UL> |
|
1032 |
* @param bufWidth Ancho del buffer de la imagen de entrada. Si no coincide con inputWindow[2] el propio gdal resamplea |
|
1033 |
* @param bufHeight Alto del buffer de la imagen de entrada. Si no coincide con inputWindow[3] el propio gdal resamplea |
|
1034 |
* @param stepX Desplazamiento en p?xeles en X a partir de la posici?n x. Este desplazamiento es util cuando hay un |
|
1035 |
* supersampleo ya que puede ser que de los pixeles que est?n en el borde izquierdo de la petici?n solo queramos una |
|
1036 |
* parte de ellos. |
|
1037 |
* @param stepY Desplazamiento en p?xeles en Y a partir de la posici?n y. Este desplazamiento es util cuando hay un |
|
1038 |
* supersampleo ya que puede ser que de los p?xeles que est?n en el borde superior de la petici?n solo queramos una |
|
1039 |
* parte de ellos. |
|
1040 |
* @param stepBuffer El buffer puede empezar a escribirse a partir de un pixel determinado y acabar de escribir antes |
|
1041 |
* de fin de buffer. Este par?metro indica el desplazamiento desde el inicio del buffer y la posici?n final. |
|
1042 |
* <UL> |
|
1043 |
* <LI>stepBuffer[0]:Desplazamiento en X desde el inicio</LI> |
|
1044 |
* <LI>stepBuffer[1]:Desplazamiento en Y desde el inicio</LI> |
|
1045 |
* <LI>stepBuffer[2]:Posici?n X final m?s uno</LI> |
|
1046 |
* <LI>stepBuffer[3]:Posici?n Y final m?s uno</LI> |
|
1047 |
* </UL> |
|
1048 |
* @throws GdalException |
|
1049 |
*/ |
|
1050 |
private void readDataCachedBuffer(Buffer buf, |
|
1051 |
BandList bandList, |
|
1052 |
int[] inputWindow, |
|
1053 |
int bufWidth, |
|
1054 |
int bufHeight, |
|
1055 |
int stpX, |
|
1056 |
int stpY, |
|
1057 |
int[] stepBuffer) throws GdalException, ProcessInterruptedException { |
|
1058 |
if(buf.isCached()) { |
|
1059 |
int nBlocks = (int)(buf.getHeight() / buf.getBlockHeight()); |
|
1060 |
int lastblock = buf.getHeight() - (nBlocks * buf.getBlockHeight()); |
|
1061 |
if(lastblock > 0) |
|
1062 |
nBlocks ++; |
|
1063 |
int init = 0; |
|
1064 |
for (int i = 0; i < nBlocks; i++) { |
|
1065 |
if(lastblock > 0 && i == (nBlocks - 1)) { |
|
1066 |
int[] newStepBuffer = new int[]{0, init, stepBuffer[2], init + lastblock}; |
|
1067 |
readData(buf, |
|
1068 |
bandList, |
|
1069 |
new int[]{inputWindow[0], init, inputWindow[2], lastblock}, |
|
1070 |
bufWidth, lastblock, 0, 0, newStepBuffer); |
|
1071 |
} else { |
|
1072 |
int[] newStepBuffer = new int[]{0, init, stepBuffer[2], init + buf.getBlockHeight()}; |
|
1073 |
readData(buf, |
|
1074 |
bandList, |
|
1075 |
new int[]{inputWindow[0], init, inputWindow[2], buf.getBlockHeight()}, |
|
1076 |
bufWidth, buf.getBlockHeight(), 0, 0, newStepBuffer); |
|
1077 |
init += buf.getBlockHeight(); |
|
1078 |
} |
|
1079 |
} |
|
1080 |
} else { |
|
1081 |
readData(buf, bandList, inputWindow, bufWidth, bufHeight, 0, 0, stepBuffer); |
|
1082 |
} |
|
1083 |
} |
|
1017 | 1084 |
|
1018 | 1085 |
/** |
1019 |
* Lee una ventana de datos sin resampleo a partir de coordenadas en pixeles. Esta funci�n es usuada por
|
|
1086 |
* Lee una ventana de datos. Esta funci?n es usuada por
|
|
1020 | 1087 |
* readWindow para coordenadas reales y readWindow en coordenadas pixel. |
1021 | 1088 |
* @param buf Buffer donde se almacenan los datos |
1022 | 1089 |
* @param bandList Lista de bandas que queremos leer y sobre que bandas del buffer de destino queremos escribirlas |
1023 |
* @param x Posici�n X en pixeles |
|
1024 |
* @param y Posici�n Y en pixeles |
|
1025 |
* @param w Ancho en pixeles |
|
1026 |
* @param h Alto en pixeles |
|
1027 |
* @param bufWidth Ancho del buffer |
|
1028 |
* @param bufHeight Alto del buffer |
|
1029 |
* @param stepX Desplazamiento en pixeles en X a partir de la posici�n x. Este desplazamiento es util cuando hay un |
|
1030 |
* supersampleo ya que puede ser que de los pixeles que est�n en el borde izquierdo de la petici�n solo queramos una |
|
1090 |
* @param inputWindow |
|
1091 |
* <UL> |
|
1092 |
* <LI>inputWindow[0]:Posici?n X en pixeles de la imagen de entrada</LI> |
|
1093 |
* <LI>inputWindow[1]:Posici?n Y en pixeles de la imagen de entrada</LI> |
|
1094 |
* <LI>inputWindow[2]:Ancho en p?xeles a leer de la imagen de entrada</LI> |
|
1095 |
* <LI>inputWindow[3]:Alto en p?xeles a leer de la imagen de entrada</LI> |
|
1096 |
* </UL> |
|
1097 |
* @param bufWidth Ancho del buffer de la imagen de entrada. Si no coincide con inputWindow[2] el propio gdal resamplea |
|
1098 |
* @param bufHeight Alto del buffer de la imagen de entrada. Si no coincide con inputWindow[3] el propio gdal resamplea |
|
1099 |
* @param stepX Desplazamiento en p?xeles en X a partir de la posici?n x. Este desplazamiento es util cuando hay un |
|
1100 |
* supersampleo ya que puede ser que de los pixeles que est?n en el borde izquierdo de la petici?n solo queramos una |
|
1031 | 1101 |
* parte de ellos. |
1032 |
* @param stepY Desplazamiento en pixeles en Y a partir de la posici�n y. Este desplazamiento es util cuando hay un
|
|
1033 |
* supersampleo ya que puede ser que de los pixeles que est�n en el borde superior de la petici�n solo queramos una
|
|
1102 |
* @param stepY Desplazamiento en p?xeles en Y a partir de la posici?n y. Este desplazamiento es util cuando hay un
|
|
1103 |
* supersampleo ya que puede ser que de los p?xeles que est?n en el borde superior de la petici?n solo queramos una
|
|
1034 | 1104 |
* parte de ellos. |
1035 | 1105 |
* @param stepBuffer El buffer puede empezar a escribirse a partir de un pixel determinado y acabar de escribir antes |
1036 |
* de fin de buffer. Este par�metro indica el desplazamiento desde el inicio del buffer y la posici�n final.
|
|
1106 |
* de fin de buffer. Este par?metro indica el desplazamiento desde el inicio del buffer y la posici?n final.
|
|
1037 | 1107 |
* <UL> |
1038 | 1108 |
* <LI>stepBuffer[0]:Desplazamiento en X desde el inicio</LI> |
1039 | 1109 |
* <LI>stepBuffer[1]:Desplazamiento en Y desde el inicio</LI> |
1040 |
* <LI>stepBuffer[2]:Posici�n X final</LI>
|
|
1041 |
* <LI>stepBuffer[3]:Posici�n Y final</LI>
|
|
1110 |
* <LI>stepBuffer[2]:Posici?n X final m?s uno</LI>
|
|
1111 |
* <LI>stepBuffer[3]:Posici?n Y final m?s uno</LI>
|
|
1042 | 1112 |
* </UL> |
1043 | 1113 |
* @throws GdalException |
1044 | 1114 |
*/ |
1045 |
private void readData(Buffer buf, BandList bandList, int x, int y, int w, int h, |
|
1046 |
int bufWidth, int bufHeight, int stpX, int stpY, int[] stepBuffer) throws GdalException, ProcessInterruptedException { |
|
1115 |
private void readData(Buffer buf, |
|
1116 |
BandList bandList, |
|
1117 |
int[] inputWindow, |
|
1118 |
int bufWidth, |
|
1119 |
int bufHeight, |
|
1120 |
int stpX, |
|
1121 |
int stpY, |
|
1122 |
int[] stepBuffer) throws GdalException, ProcessInterruptedException { |
|
1047 | 1123 |
|
1048 | 1124 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString()); |
1049 | 1125 |
FileUtils fUtil = RasterLocator.getManager().getFileUtils(); |
... | ... | |
1055 | 1131 |
continue; |
1056 | 1132 |
int init = (int)((bufWidth * stpY) + stpX); //Pos inicial. Desplazamos stpX pixels hacia la derecha y bajamos stpY lineas |
1057 | 1133 |
int pos = init; |
1058 |
gdalBuf = gdalBands[iBand].readRaster(x, y, w, h, bufWidth, bufHeight, dataType[iBand]); |
|
1134 |
gdalBuf = gdalBands[iBand].readRaster( inputWindow[0], |
|
1135 |
inputWindow[1], |
|
1136 |
inputWindow[2], |
|
1137 |
inputWindow[3], |
|
1138 |
bufWidth, |
|
1139 |
bufHeight, |
|
1140 |
dataType[iBand]); |
|
1141 |
int lineInputWindow = 0; |
|
1059 | 1142 |
if(dataType[iBand] == Gdal.GDT_Byte) { |
1060 | 1143 |
for (int line = stepBuffer[1]; line < stepBuffer[3]/*buf.getHeight()*/; line++) { |
1061 |
pos = (int)((bufWidth * (line - stepBuffer[0])) + init); |
|
1144 |
pos = (int)((bufWidth * (lineInputWindow - stepBuffer[0])) + init);
|
|
1062 | 1145 |
for (int col = stepBuffer[0]; col < stepBuffer[2]/*buf.getWidth()*/; col ++) { |
1063 | 1146 |
for (int i = 0; i < drawableBands.length; i++) |
1064 | 1147 |
buf.setElem(line, col, drawableBands[i], gdalBuf.buffByte[pos]); |
1065 | 1148 |
pos ++; |
1066 | 1149 |
} |
1150 |
lineInputWindow ++; |
|
1067 | 1151 |
if(task.getEvent() != null) |
1068 | 1152 |
task.manageEvent(task.getEvent()); |
1069 | 1153 |
} |
1070 | 1154 |
} else if((dataType[iBand] == Gdal.GDT_UInt16) || (dataType[iBand] == Gdal.GDT_Int16) || (dataType[iBand] == Gdal.GDT_CInt16)) { |
1071 | 1155 |
for (int line = stepBuffer[1]; line < stepBuffer[3]; line++) { |
1072 |
pos = (int)((bufWidth * (line - stepBuffer[0])) + init); |
|
1156 |
pos = (int)((bufWidth * (lineInputWindow - stepBuffer[0])) + init);
|
|
1073 | 1157 |
for (int col = stepBuffer[0]; col < stepBuffer[2]; col ++) { |
1074 | 1158 |
for (int i = 0; i < drawableBands.length; i++) |
1075 | 1159 |
buf.setElem(line, col, drawableBands[i], gdalBuf.buffShort[pos]); |
1076 | 1160 |
pos ++; |
1077 | 1161 |
} |
1162 |
lineInputWindow ++; |
|
1078 | 1163 |
if(task.getEvent() != null) |
1079 | 1164 |
task.manageEvent(task.getEvent()); |
1080 | 1165 |
} |
1081 | 1166 |
} else if((dataType[iBand] == Gdal.GDT_UInt32) || (dataType[iBand] == Gdal.GDT_Int32) || (dataType[iBand] == Gdal.GDT_CInt32)) { |
1082 | 1167 |
for (int line = stepBuffer[1]; line < stepBuffer[3]; line++) { |
1083 |
pos = (int)((bufWidth * (line - stepBuffer[0])) + init); |
|
1168 |
pos = (int)((bufWidth * (lineInputWindow - stepBuffer[0])) + init);
|
|
1084 | 1169 |
for (int col = stepBuffer[0]; col < stepBuffer[2]; col ++) { |
1085 | 1170 |
for (int i = 0; i < drawableBands.length; i++) |
1086 | 1171 |
buf.setElem(line, col, drawableBands[i], gdalBuf.buffInt[pos]); |
1087 | 1172 |
pos ++; |
1088 | 1173 |
} |
1174 |
lineInputWindow ++; |
|
1089 | 1175 |
if(task.getEvent() != null) |
1090 | 1176 |
task.manageEvent(task.getEvent()); |
1091 | 1177 |
} |
1092 | 1178 |
} else if(dataType[iBand] == Gdal.GDT_Float32) { |
1093 | 1179 |
for (int line = stepBuffer[1]; line < stepBuffer[3]; line++) { |
1094 |
pos = (int)((bufWidth * (line - stepBuffer[0])) + init); |
|
1180 |
pos = (int)((bufWidth * (lineInputWindow - stepBuffer[0])) + init);
|
|
1095 | 1181 |
for (int col = stepBuffer[0]; col < stepBuffer[2]; col ++) { |
1096 | 1182 |
for (int i = 0; i < drawableBands.length; i++) |
1097 | 1183 |
buf.setElem(line, col, drawableBands[i], gdalBuf.buffFloat[pos]); |
1098 | 1184 |
pos ++; |
1099 | 1185 |
} |
1186 |
lineInputWindow ++; |
|
1100 | 1187 |
if(task.getEvent() != null) |
1101 | 1188 |
task.manageEvent(task.getEvent()); |
1102 | 1189 |
} |
1103 | 1190 |
} else if(dataType[iBand] == Gdal.GDT_Float64) { |
1104 | 1191 |
for (int line = stepBuffer[1]; line < stepBuffer[3]; line++) { |
1105 |
pos = (int)((bufWidth * (line - stepBuffer[0])) + init); |
|
1192 |
pos = (int)((bufWidth * (lineInputWindow - stepBuffer[0])) + init);
|
|
1106 | 1193 |
for (int col = stepBuffer[0]; col < stepBuffer[2]; col ++) { |
1107 | 1194 |
for (int i = 0; i < drawableBands.length; i++) |
1108 | 1195 |
buf.setElem(line, col, drawableBands[i], gdalBuf.buffDouble[pos]); |
1109 | 1196 |
pos ++; |
1110 | 1197 |
} |
1198 |
lineInputWindow ++; |
|
1111 | 1199 |
if(task.getEvent() != null) |
1112 | 1200 |
task.manageEvent(task.getEvent()); |
1113 | 1201 |
} |
Also available in: Unified diff