From ff166e65e26c2c046044b08c609cc02c06dd09ee Mon Sep 17 00:00:00 2001 From: lveci Date: Wed, 16 Sep 2015 16:03:11 -0400 Subject: [PATCH 1/8] set all bands the same size --- .../org/esa/s1tbx/io/imageio/ImageIOFile.java | 20 ++++++++-------- .../esa/s1tbx/io/imageio/ImageIOReader.java | 8 +++---- .../io/radarsat2/Radarsat2ProductReader.java | 8 +++---- .../sentinel1/Sentinel1Level1Directory.java | 23 ++++++++++++++----- .../io/sentinel1/Sentinel1ProductReader.java | 17 ++++++++++---- .../io/terrasarx/TerraSarXProductReader.java | 4 ++-- 6 files changed, 50 insertions(+), 30 deletions(-) diff --git a/s1tbx-io/src/main/java/org/esa/s1tbx/io/imageio/ImageIOFile.java b/s1tbx-io/src/main/java/org/esa/s1tbx/io/imageio/ImageIOFile.java index 5e89492ff..fb4e5136b 100644 --- a/s1tbx-io/src/main/java/org/esa/s1tbx/io/imageio/ImageIOFile.java +++ b/s1tbx-io/src/main/java/org/esa/s1tbx/io/imageio/ImageIOFile.java @@ -47,8 +47,8 @@ public class ImageIOFile { private final String name; - private int sceneWidth = 0; - private int sceneHeight = 0; + private int imgWidth = 0; + private int imgHeight = 0; private int dataType; private int numImages = 1; private int numBands = 1; @@ -211,18 +211,18 @@ public void close() throws IOException { reader.dispose(); } - public int getSceneWidth() throws IOException { - if (sceneWidth == 0) { - sceneWidth = reader.getWidth(0); + public int getImageWidth() throws IOException { + if (imgWidth == 0) { + imgWidth = reader.getWidth(0); } - return sceneWidth; + return imgWidth; } - public int getSceneHeight() throws IOException { - if (sceneHeight == 0) { - sceneHeight = reader.getHeight(0); + public int getImageHeight() throws IOException { + if (imgHeight == 0) { + imgHeight = reader.getHeight(0); } - return sceneHeight; + return imgHeight; } public int getDataType() { diff --git a/s1tbx-io/src/main/java/org/esa/s1tbx/io/imageio/ImageIOReader.java b/s1tbx-io/src/main/java/org/esa/s1tbx/io/imageio/ImageIOReader.java index bbcac782c..6c8fb2547 100644 --- a/s1tbx-io/src/main/java/org/esa/s1tbx/io/imageio/ImageIOReader.java +++ b/s1tbx-io/src/main/java/org/esa/s1tbx/io/imageio/ImageIOReader.java @@ -69,7 +69,7 @@ protected Product readProductNodesImpl() throws IOException { final Product product = new Product(inputFile.getName(), productType, - imgIOFile.getSceneWidth(), imgIOFile.getSceneHeight()); + imgIOFile.getImageWidth(), imgIOFile.getImageHeight()); product.setFileLocation(inputFile); int bandCnt = 1; @@ -77,7 +77,7 @@ protected Product readProductNodesImpl() throws IOException { for (int b = 0; b < imgIOFile.getNumBands(); ++b) { final Band band = new Band("band" + bandCnt++, imgIOFile.getDataType(), - imgIOFile.getSceneWidth(), imgIOFile.getSceneHeight()); + imgIOFile.getImageWidth(), imgIOFile.getImageHeight()); product.addBand(band); bandMap.put(band, new ImageIOFile.BandInfo(band, imgIOFile, i, b)); @@ -116,8 +116,8 @@ private void addMetaData(final Product product, final File inputFile) throws IOE AbstractMetadata.setAttribute(absRoot, AbstractMetadata.PRODUCT, inputFile.getName()); AbstractMetadata.setAttribute(absRoot, AbstractMetadata.PRODUCT_TYPE, productType); - AbstractMetadata.setAttribute(absRoot, AbstractMetadata.num_samples_per_line, imgIOFile.getSceneWidth()); - AbstractMetadata.setAttribute(absRoot, AbstractMetadata.num_output_lines, imgIOFile.getSceneHeight()); + AbstractMetadata.setAttribute(absRoot, AbstractMetadata.num_samples_per_line, imgIOFile.getImageWidth()); + AbstractMetadata.setAttribute(absRoot, AbstractMetadata.num_output_lines, imgIOFile.getImageHeight()); AbstractMetadataIO.loadExternalMetadata(product, absRoot, inputFile); } diff --git a/s1tbx-io/src/main/java/org/esa/s1tbx/io/radarsat2/Radarsat2ProductReader.java b/s1tbx-io/src/main/java/org/esa/s1tbx/io/radarsat2/Radarsat2ProductReader.java index 105729323..51a367171 100644 --- a/s1tbx-io/src/main/java/org/esa/s1tbx/io/radarsat2/Radarsat2ProductReader.java +++ b/s1tbx-io/src/main/java/org/esa/s1tbx/io/radarsat2/Radarsat2ProductReader.java @@ -230,11 +230,11 @@ public void readAscendingRasterBand(final int sourceOffsetX, final int sourceOff if (flipToSARGeometry) { if (isAntennaPointingRight) { // flip the image up side down data = image.getData(new Rectangle(destOffsetX, - Math.max(0, img.getSceneHeight() - destOffsetY - destHeight), + Math.max(0, img.getImageHeight() - destOffsetY - destHeight), destWidth, destHeight)); } else { // flip the image upside down, then flip it left to right - data = image.getData(new Rectangle(Math.max(0, img.getSceneWidth() - destOffsetX - destWidth), - Math.max(0, img.getSceneHeight() - destOffsetY - destHeight), + data = image.getData(new Rectangle(Math.max(0, img.getImageWidth() - destOffsetX - destWidth), + Math.max(0, img.getImageHeight() - destOffsetY - destHeight), destWidth, destHeight)); } } else { @@ -295,7 +295,7 @@ public void readDescendingRasterBand(final int sourceOffsetX, final int sourceOf final RenderedImage image = reader.readAsRenderedImage(0, param); if (flipToSARGeometry && isAntennaPointingRight) { // flip the image left to right - data = image.getData(new Rectangle(Math.max(0, img.getSceneWidth() - destOffsetX - destWidth), + data = image.getData(new Rectangle(Math.max(0, img.getImageWidth() - destOffsetX - destWidth), destOffsetY, destWidth, destHeight)); } else { data = image.getData(new Rectangle(destOffsetX, destOffsetY, destWidth, destHeight)); diff --git a/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1Level1Directory.java b/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1Level1Directory.java index 93d0721d0..cdb0fe893 100644 --- a/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1Level1Directory.java +++ b/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1Level1Directory.java @@ -58,6 +58,8 @@ public class Sentinel1Level1Directory extends XMLProductDirectory implements Sen private final Map bandGeocodingMap = new HashMap<>(5); private final transient Map imgBandMetadataMap = new HashMap<>(4); private String acqMode = ""; + private int largestBandWidth; + private int largestBandHeight; private static final DateFormat standardDateFormat = ProductData.UTC.createDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -108,8 +110,12 @@ protected void addBands(final Product product) { final MetadataElement bandMetadata = absRoot.getElement(imgBandMetadataMap.get(imgName)); final String swath = bandMetadata.getAttributeString(AbstractMetadata.swath); final String pol = bandMetadata.getAttributeString(AbstractMetadata.polarization); - final int width = bandMetadata.getAttributeInt(AbstractMetadata.num_samples_per_line); - final int height = bandMetadata.getAttributeInt(AbstractMetadata.num_output_lines); + + //final int width = bandMetadata.getAttributeInt(AbstractMetadata.num_samples_per_line); + //final int height = bandMetadata.getAttributeInt(AbstractMetadata.num_output_lines); + // total scene width and height + final int width = largestBandWidth; + final int height = largestBandHeight; String tpgPrefix = ""; String suffix = pol; @@ -292,7 +298,9 @@ static void addManifestMetadata(final String productName, final MetadataElement } private void determineProductDimensions(final MetadataElement absRoot) throws IOException { - int totalWidth = 0, maxHeight = 0, k = 0; + int totalWidth = 0, k = 0; + largestBandWidth = 0; + largestBandHeight = 0; String pol = null; for (Map.Entry stringImageIOFileEntry : bandImageFileMap.entrySet()) { final ImageIOFile img = stringImageIOFileEntry.getValue(); @@ -313,14 +321,17 @@ private void determineProductDimensions(final MetadataElement absRoot) throws IO int width = bandMetadata.getAttributeInt(AbstractMetadata.num_samples_per_line); int height = bandMetadata.getAttributeInt(AbstractMetadata.num_output_lines); totalWidth += width; - if (height > maxHeight) { - maxHeight = height; + if (width > largestBandWidth) { + largestBandWidth = width; + } + if (height > largestBandHeight) { + largestBandHeight = height; } } if (isSLC() && isTOPSAR()) { // approximate does not account for overlap absRoot.setAttributeInt(AbstractMetadata.num_samples_per_line, totalWidth); - absRoot.setAttributeInt(AbstractMetadata.num_output_lines, maxHeight); + absRoot.setAttributeInt(AbstractMetadata.num_output_lines, largestBandHeight); } } diff --git a/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java b/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java index 048abe9d1..e84b48505 100644 --- a/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java +++ b/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java @@ -156,9 +156,16 @@ public void readSLCRasterBand(final int sourceOffsetX, final int sourceOffsetY, int length; int[] srcArray; - //System.out.println(cache.stats()+", size="+cache.size()); + System.out.println(cache.stats()+", size="+cache.size()); + + final int imgWidth = bandInfo.img.getImageWidth(); + final int imgheight = bandInfo.img.getImageHeight(); + final Rectangle destRect = new Rectangle(destOffsetX, destOffsetY, + Math.min(destWidth, imgWidth - destOffsetX), + Math.min(destHeight, imgheight - destOffsetY)); + if(destRect.width <= 0 || destRect.height <= 0) + return; - final Rectangle destRect = new Rectangle(destOffsetX, destOffsetY, destWidth, destHeight); final DataCache.DataKey datakey = new DataCache.DataKey(bandInfo.img, destRect); DataCache.Data cachedData = cache.get(datakey); if (cachedData != null && cachedData.valid) { @@ -179,7 +186,8 @@ public void readSLCRasterBand(final int sourceOffsetX, final int sourceOffsetY, //System.arraycopy(srcArray, 0, destArray, 0, length); int i = 0; for (int srcVal : srcArray) { - destArray[i++] = (short) srcVal; + if(i < destRect.width) + destArray[i++] = (short) srcVal; } } else { for (int i = 0; i < length; i += sourceStepX) { @@ -190,7 +198,8 @@ public void readSLCRasterBand(final int sourceOffsetX, final int sourceOffsetY, if (sourceStepX == 1) { int i = 0; for (int srcVal : srcArray) { - destArray[i++] = (short) (srcVal >> 16); + if(i < destRect.width) + destArray[i++] = (short) (srcVal >> 16); } } else { for (int i = 0; i < length; i += sourceStepX) { diff --git a/s1tbx-io/src/main/java/org/esa/s1tbx/io/terrasarx/TerraSarXProductReader.java b/s1tbx-io/src/main/java/org/esa/s1tbx/io/terrasarx/TerraSarXProductReader.java index 4b986705f..def3c8aee 100644 --- a/s1tbx-io/src/main/java/org/esa/s1tbx/io/terrasarx/TerraSarXProductReader.java +++ b/s1tbx-io/src/main/java/org/esa/s1tbx/io/terrasarx/TerraSarXProductReader.java @@ -180,7 +180,7 @@ public void readAscendingRasterBand(final int sourceOffsetX, final int sourceOff sourceOffsetY % sourceStepY); final RenderedImage image = reader.readAsRenderedImage(0, param); - Rectangle rect = new Rectangle(destOffsetX, Math.max(0, img.getSceneHeight() - destOffsetY - destHeight), + Rectangle rect = new Rectangle(destOffsetX, Math.max(0, img.getImageHeight() - destOffsetY - destHeight), destWidth, destHeight); data = image.getData(rect); } @@ -223,7 +223,7 @@ public void readDescendingRasterBand(final int sourceOffsetX, final int sourceOf sourceOffsetY % sourceStepY); final RenderedImage image = reader.readAsRenderedImage(0, param); - data = image.getData(new Rectangle(Math.max(0, img.getSceneWidth() - destOffsetX - destWidth), + data = image.getData(new Rectangle(Math.max(0, img.getImageWidth() - destOffsetX - destWidth), destOffsetY, destWidth, destHeight)); } From 058530a94292d4cc9e39b34fb976f1de8501de59 Mon Sep 17 00:00:00 2001 From: lveci Date: Wed, 16 Sep 2015 16:54:01 -0400 Subject: [PATCH 2/8] fix readSLCRasterBand --- .../io/sentinel1/Sentinel1ProductReader.java | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java b/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java index e84b48505..6125a0635 100644 --- a/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java +++ b/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java @@ -156,25 +156,25 @@ public void readSLCRasterBand(final int sourceOffsetX, final int sourceOffsetY, int length; int[] srcArray; - System.out.println(cache.stats()+", size="+cache.size()); + //System.out.println(cache.stats()+", size="+cache.size()); final int imgWidth = bandInfo.img.getImageWidth(); final int imgheight = bandInfo.img.getImageHeight(); - final Rectangle destRect = new Rectangle(destOffsetX, destOffsetY, + final Rectangle imgRect = new Rectangle(destOffsetX, destOffsetY, Math.min(destWidth, imgWidth - destOffsetX), Math.min(destHeight, imgheight - destOffsetY)); - if(destRect.width <= 0 || destRect.height <= 0) + if(imgRect.width <= 0 || imgRect.height <= 0) return; - final DataCache.DataKey datakey = new DataCache.DataKey(bandInfo.img, destRect); + final DataCache.DataKey datakey = new DataCache.DataKey(bandInfo.img, imgRect); DataCache.Data cachedData = cache.get(datakey); if (cachedData != null && cachedData.valid) { srcArray = cachedData.intArray; length = srcArray.length; } else { cachedData = readRect(datakey, bandInfo, - sourceOffsetX, sourceOffsetY, sourceStepX, sourceStepY, - destRect); + sourceOffsetX, sourceOffsetY, sourceStepX, sourceStepY, + imgRect); srcArray = cachedData.intArray; length = srcArray.length; @@ -183,27 +183,34 @@ public void readSLCRasterBand(final int sourceOffsetX, final int sourceOffsetY, final short[] destArray = (short[]) destBuffer.getElems(); if (!bandInfo.isImaginary) { if (sourceStepX == 1) { - //System.arraycopy(srcArray, 0, destArray, 0, length); - int i = 0; - for (int srcVal : srcArray) { - if(i < destRect.width) - destArray[i++] = (short) srcVal; + for(int y=0; y < imgRect.height; ++y) { + int stride = y*imgRect.width; + for(int x=0; x < imgRect.width; ++x) { + destArray[stride+x] = (short) srcArray[stride+x]; + } } } else { - for (int i = 0; i < length; i += sourceStepX) { - destArray[i] = (short) srcArray[i]; + for(int y=0; y < imgRect.height; ++y) { + int stride = y*imgRect.width; + for(int x=0; x < imgRect.width; x += sourceStepX) { + destArray[stride+x] = (short) srcArray[stride+x]; + } } } } else { if (sourceStepX == 1) { - int i = 0; - for (int srcVal : srcArray) { - if(i < destRect.width) - destArray[i++] = (short) (srcVal >> 16); + for(int y=0; y < imgRect.height; ++y) { + int stride = y*imgRect.width; + for(int x=0; x < imgRect.width; ++x) { + destArray[stride+x] = (short) (srcArray[stride+x] >> 16); + } } } else { - for (int i = 0; i < length; i += sourceStepX) { - destArray[i] = (short) (srcArray[i] >> 16); + for(int y=0; y < imgRect.height; ++y) { + int stride = y*imgRect.width; + for(int x=0; x < imgRect.width; x += sourceStepX) { + destArray[stride+x] = (short) (srcArray[stride+x] >> 16); + } } } } From 25cfe0c15468b33bc534b449cde21f9ccde72e77 Mon Sep 17 00:00:00 2001 From: lveci Date: Wed, 16 Sep 2015 17:13:35 -0400 Subject: [PATCH 3/8] remove unused variable --- .../org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java b/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java index 6125a0635..33220c5fb 100644 --- a/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java +++ b/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java @@ -152,8 +152,6 @@ public void readSLCRasterBand(final int sourceOffsetX, final int sourceOffsetY, final int destOffsetX, final int destOffsetY, int destWidth, int destHeight, final ImageIOFile.BandInfo bandInfo) throws IOException { - - int length; int[] srcArray; //System.out.println(cache.stats()+", size="+cache.size()); @@ -170,14 +168,11 @@ public void readSLCRasterBand(final int sourceOffsetX, final int sourceOffsetY, DataCache.Data cachedData = cache.get(datakey); if (cachedData != null && cachedData.valid) { srcArray = cachedData.intArray; - length = srcArray.length; } else { cachedData = readRect(datakey, bandInfo, sourceOffsetX, sourceOffsetY, sourceStepX, sourceStepY, imgRect); - srcArray = cachedData.intArray; - length = srcArray.length; } final short[] destArray = (short[]) destBuffer.getElems(); From 6cd9ecbd2588b407550426d770a605ca5ac611e9 Mon Sep 17 00:00:00 2001 From: jun--lu Date: Thu, 17 Sep 2015 16:09:02 -0400 Subject: [PATCH 4/8] modified to handle all swaths --- .../s1tbx/sentinel1/gpf/BackGeocodingOp.java | 292 ++++++++++-------- 1 file changed, 163 insertions(+), 129 deletions(-) diff --git a/s1tbx-op-sentinel1/src/main/java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java b/s1tbx-op-sentinel1/src/main/java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java index 8e02c8878..d065bfc05 100644 --- a/s1tbx-op-sentinel1/src/main/java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java +++ b/s1tbx-op-sentinel1/src/main/java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java @@ -65,9 +65,8 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Map; +import java.util.*; +import java.util.List; /** * "Backgeocoding" + "Coregistration" processing blocks in The Sentinel-1 TOPS InSAR processing chain. @@ -131,17 +130,18 @@ public final class BackGeocodingOp extends Operator { private double demNoDataValue = 0; // no data value for DEM private double noDataValue = 0.0; - private int subSwathIndex = 0; - private int burstOffset = 0; + private int[] burstOffset = null; private boolean burstOffsetComputed = false; - private String swathIndexStr = null; - private String subSwathName = null; - private String polarization = null; + private String[] mSubSwathNames = null; + private String[] sSubSwathNames = null; + private String[] mPolarizations = null; + private String[] sPolarizations = null; private SARGeocoding.Orbit mOrbit = null; private SARGeocoding.Orbit sOrbit = null; private final double invalidIndex = -9999.0; + private final HashMap sourceBandToTargetBandMap = new HashMap<>(); /** * Default constructor. The graph processing framework @@ -190,28 +190,28 @@ public void initialize() throws OperatorException { */ mSubSwath = mSU.getSubSwath(); sSubSwath = sSU.getSubSwath(); - - final String[] mSubSwathNames = mSU.getSubSwathNames(); - final String[] sSubSwathNames = sSU.getSubSwathNames(); - if (mSubSwathNames.length != 1 || sSubSwathNames.length != 1) { - throw new OperatorException("Split product is expected."); + numOfSubSwath = mSubSwath.length; + if (sSubSwath.length != numOfSubSwath) { + throw new OperatorException("Master and slave have different number of sub-swaths."); } - - if (!mSubSwathNames[0].equals(sSubSwathNames[0])) { - throw new OperatorException("Same sub-swath is expected."); - } - subSwathName = mSubSwathNames[0]; - subSwathIndex = 1; // subSwathIndex is always 1 because of split product - swathIndexStr = mSubSwathNames[0].substring(2); - final String[] mPolarizations = mSU.getPolarizations(); - final String[] sPolarizations = sSU.getPolarizations(); - if (!StringUtils.containsIgnoreCase(sPolarizations, mPolarizations[0])) { - throw new OperatorException("Same polarization is expected."); - } + mSubSwathNames = mSU.getSubSwathNames(); + sSubSwathNames = sSU.getSubSwathNames(); + for (String mSSName : mSubSwathNames) { + if (!StringUtils.containsIgnoreCase(sSubSwathNames, mSSName)) { + throw new OperatorException("Master and slave have different sub-swaths."); + } + } - polarization = mPolarizations[0]; + mPolarizations = mSU.getPolarizations(); + sPolarizations = sSU.getPolarizations(); + + for (String sPol : sPolarizations) { + if (!StringUtils.containsIgnoreCase(mPolarizations, sPol)) { + throw new OperatorException("Same polarization is expected."); + } + } if (externalDEMFile == null) { DEMFactory.checkIfDEMInstalled(demName); @@ -225,8 +225,9 @@ public void initialize() throws OperatorException { updateTargetProductMetadata(); - final Band masterBandI = getBand(masterProduct, "i_", swathIndexStr, polarization); - noDataValue = masterBandI.getNoDataValue(); + final String swathIndexStr = mSubSwathNames[0].substring(2); + noDataValue = getBand(masterProduct, "i_", swathIndexStr, "").getNoDataValue(); + } catch (Throwable e) { OperatorUtils.catchOperatorException(getId(), e); } @@ -302,18 +303,16 @@ private void createTargetProduct() { if (masterProduct.getBand(bandName) instanceof VirtualBand) { continue; } - final Band targetBand = ProductUtils.copyBand(bandName, masterProduct, bandName + mstSuffix, targetProduct, true); + final Band targetBand = ProductUtils.copyBand( + bandName, masterProduct, bandName + mstSuffix, targetProduct, true); if(targetBand.getUnit().equals(Unit.IMAGINARY)) { int idx = targetProduct.getBandIndex(targetBand.getName()); - ReaderUtils.createVirtualIntensityBand(targetProduct, targetProduct.getBandAt(idx-1), targetBand, mstSuffix); + ReaderUtils.createVirtualIntensityBand( + targetProduct, targetProduct.getBandAt(idx-1), targetBand, mstSuffix); } } - final Band masterBand = masterProduct.getBand(masterBandNames[0]); - final int masterBandWidth = masterBand.getSceneRasterWidth(); - final int masterBandHeight = masterBand.getSceneRasterHeight(); - final String[] slaveBandNames = slaveProduct.getBandNames(); final String slvSuffix = "_slv1" + StackUtils.getBandTimeStamp(slaveProduct); for (String bandName:slaveBandNames) { @@ -321,6 +320,12 @@ private void createTargetProduct() { if (srcBand instanceof VirtualBand) { continue; } + + final String subSwathName = getSubSwathName(bandName, sSubSwathNames); + final Band masterBand = getBand(masterProduct, "i_", subSwathName, ""); + final int masterBandWidth = masterBand.getSceneRasterWidth(); + final int masterBandHeight = masterBand.getSceneRasterHeight(); + final Band targetBand = new Band( bandName + slvSuffix, ProductData.TYPE_FLOAT32, @@ -330,6 +335,7 @@ private void createTargetProduct() { targetBand.setUnit(srcBand.getUnit()); targetBand.setDescription(srcBand.getDescription()); targetProduct.addBand(targetBand); + sourceBandToTargetBandMap.put(srcBand, targetBand); if(targetBand.getUnit().equals(Unit.IMAGINARY)) { int idx = targetProduct.getBandIndex(targetBand.getName()); @@ -345,38 +351,55 @@ private void createTargetProduct() { // } //} - copySlaveMetadata(); + for (String subSwathName : mSubSwathNames) { - if (outputRangeAzimuthOffset) { - final Band azOffsetBand = new Band( - "azOffset", - ProductData.TYPE_FLOAT32, - masterBandWidth, - masterBandHeight); + final Band masterBand = getBand(masterProduct, "i_", subSwathName, mPolarizations[0]); + final int masterBandWidth = masterBand.getSceneRasterWidth(); + final int masterBandHeight = masterBand.getSceneRasterHeight(); - azOffsetBand.setUnit("Index"); - targetProduct.addBand(azOffsetBand); + if (outputRangeAzimuthOffset) { + final Band azOffsetBand = new Band( + "azOffset_" + subSwathName, + ProductData.TYPE_FLOAT32, + masterBandWidth, + masterBandHeight); - final Band rgOffsetBand = new Band( - "rgOffset", - ProductData.TYPE_FLOAT32, - masterBandWidth, - masterBandHeight); + azOffsetBand.setUnit("Index"); + targetProduct.addBand(azOffsetBand); + + final Band rgOffsetBand = new Band( + "rgOffset_ " + subSwathName, + ProductData.TYPE_FLOAT32, + masterBandWidth, + masterBandHeight); - rgOffsetBand.setUnit("Index"); - targetProduct.addBand(rgOffsetBand); + rgOffsetBand.setUnit("Index"); + targetProduct.addBand(rgOffsetBand); + } + + if (outputDerampDemodPhase) { + final Band phaseBand = new Band( + "derampDemodPhase_ " + subSwathName, + ProductData.TYPE_FLOAT32, + masterBandWidth, + masterBandHeight); + + phaseBand.setUnit("radian"); + targetProduct.addBand(phaseBand); + } } - if (outputDerampDemodPhase) { - final Band phaseBand = new Band( - "derampDemodPhase", - ProductData.TYPE_FLOAT32, - masterBandWidth, - masterBandHeight); + copySlaveMetadata(); + } + + private String getSubSwathName(final String bandName, final String[] subSwathNames) { - phaseBand.setUnit("radian"); - targetProduct.addBand(phaseBand); + for (String subSwathName : subSwathNames) { + if (bandName.contains(subSwathName)) { + return subSwathName; + } } + return null; } private void copySlaveMetadata() { @@ -401,11 +424,11 @@ private void updateTargetProductMetadata() { final MetadataElement inputElem = ProductInformation.getInputProducts(targetProduct); final MetadataElement slvInputElem = ProductInformation.getInputProducts(slaveProduct); - final MetadataAttribute[] slvInputProductAttrbList = slvInputElem.getAttributes(); - for (MetadataAttribute attrib : slvInputProductAttrbList) { - final MetadataAttribute inputAttrb = AbstractMetadata.addAbstractedAttribute( + final MetadataAttribute[] slvInputProductAttributeList = slvInputElem.getAttributes(); + for (MetadataAttribute attribute : slvInputProductAttributeList) { + final MetadataAttribute inputAttribute = AbstractMetadata.addAbstractedAttribute( inputElem, "InputProduct", ProductData.TYPE_ASCII, "", ""); - inputAttrb.getData().setElems(attrib.getData().getElemString()); + inputAttribute.getData().setElems(attribute.getData().getElemString()); } } @@ -416,12 +439,12 @@ private void updateTargetProductMetadata() { * * @param targetTileMap The target tiles associated with all target bands to be computed. * @param targetRectangle The rectangle of target tile. - * @param pm A progress monitor which should be used to determine computation cancelation requests. + * @param pm A progress monitor which should be used to determine computation cancellation requests. * @throws org.esa.snap.framework.gpf.OperatorException * If an error occurs during computation of the target raster. */ @Override - public void computeTileStack(Map targetTileMap, Rectangle targetRectangle, ProgressMonitor pm) + public synchronized void computeTileStack(Map targetTileMap, Rectangle targetRectangle, ProgressMonitor pm) throws OperatorException { try { @@ -429,14 +452,11 @@ public void computeTileStack(Map targetTileMap, Rectangle targetRect final int ty0 = targetRectangle.y; final int tw = targetRectangle.width; final int th = targetRectangle.height; - final int tyMax = ty0 + th; - //System.out.println("tx0 = " + tx0 + ", ty0 = " + ty0 + ", tw = " + tw + ", th = " + th); + final int txMax = tx0 + tw - 1; + final int tyMax = ty0 + th - 1; + System.out.println("tx0 = " + tx0 + ", ty0 = " + ty0 + ", tw = " + tw + ", th = " + th); if (!isElevationModelAvailable) { - if (mSU.getPolarizations().length != 1 || sSU.getPolarizations().length != 1) { - throw new OperatorException("Split product with one polarization is expected."); - } - getElevationModel(); } @@ -444,26 +464,36 @@ public void computeTileStack(Map targetTileMap, Rectangle targetRect computeBurstOffset(); } - for (int burstIndex = 0; burstIndex < mSubSwath[subSwathIndex - 1].numOfBursts; burstIndex++) { - final int firstLineIdx = burstIndex*mSubSwath[subSwathIndex - 1].linesPerBurst; - final int lastLineIdx = firstLineIdx + mSubSwath[subSwathIndex - 1].linesPerBurst - 1; + for (int s = 0; s < numOfSubSwath; s++) { - if (tyMax <= firstLineIdx || ty0 > lastLineIdx) { + if (tx0 >= mSubSwath[s].samplesPerBurst - 1) { continue; } - final int ntx0 = tx0; - final int ntw = tw; - final int nty0 = Math.max(ty0, firstLineIdx); - final int ntyMax = Math.min(tyMax, lastLineIdx + 1); - final int nth = ntyMax - nty0; - //System.out.println("burstIndex = " + burstIndex + ": ntx0 = " + ntx0 + ", nty0 = " + nty0 + ", ntw = " + ntw + ", nth = " + nth); + final int subSwathIndex = s + 1; + for (int burstIndex = 0; burstIndex < mSubSwath[s].numOfBursts; burstIndex++) { + final int firstLineIdx = burstIndex*mSubSwath[s].linesPerBurst; + final int lastLineIdx = firstLineIdx + mSubSwath[s].linesPerBurst - 1; + + if (tyMax < firstLineIdx || ty0 > lastLineIdx) { + continue; + } + + final int ntx0 = tx0; + final int ntxMax = Math.min(txMax, mSubSwath[s].samplesPerBurst - 1); + final int ntw = ntxMax - ntx0 + 1; + final int nty0 = Math.max(ty0, firstLineIdx); + final int ntyMax = Math.min(tyMax, lastLineIdx); + final int nth = ntyMax - nty0 + 1; + System.out.println("subSwathIndex = " + subSwathIndex + ", burstIndex = " + burstIndex + + ": ntx0 = " + ntx0 + ", nty0 = " + nty0 + ", ntw = " + ntw + ", nth = " + nth); - double[] extendedAmount = {0.0, 0.0, 0.0, 0.0}; - computeExtendedAmount(ntx0, nty0, ntw, nth, extendedAmount); + double[] extendedAmount = {0.0, 0.0, 0.0, 0.0}; + computeExtendedAmount(ntx0, nty0, ntw, nth, subSwathIndex, extendedAmount); - computePartialTile(subSwathIndex, burstIndex, ntx0, nty0, ntw, nth, targetTileMap, - extendedAmount, pm); + computePartialTile(subSwathIndex, burstIndex, ntx0, nty0, ntw, nth, targetTileMap, + extendedAmount, pm); + } } } catch (Throwable e) { @@ -507,10 +537,21 @@ private synchronized void getElevationModel() throws Exception { private synchronized void computeBurstOffset() throws Exception { if (burstOffsetComputed) return; + + burstOffset = new int[numOfSubSwath]; + for (int i = 0; i < numOfSubSwath; i++) { + burstOffset[i] = computeBurstOffsetForOneSubSwath(i+1); + } + + burstOffsetComputed = true; + } + private int computeBurstOffsetForOneSubSwath(final int subSwathIndex) throws Exception { + try { final int h = mSubSwath[subSwathIndex - 1].latitude.length; final int w = mSubSwath[subSwathIndex - 1].latitude[0].length; final PosVector earthPoint = new PosVector(); + int burstOffset; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { final double lat = mSubSwath[subSwathIndex - 1].latitude[i][j]; @@ -543,13 +584,14 @@ private synchronized void computeBurstOffset() throws Exception { continue; } - burstOffsetComputed = true; - return; + return burstOffset; } } } catch (Throwable t) { t.printStackTrace(); } + + return -1; } private BurstIndices getBurstIndices(final int subSwathIndex, final Sentinel1Utils su, @@ -593,7 +635,7 @@ private BurstIndices getBurstIndices(final int subSwathIndex, final Sentinel1Uti return null; } - private void computeExtendedAmount(final int x0, final int y0, final int w, final int h, + private void computeExtendedAmount(final int x0, final int y0, final int w, final int h, final int subSwathIndex, final double[] extendedAmount) throws Exception { @@ -605,11 +647,11 @@ private void computeExtendedAmount(final int x0, final int y0, final int w, fina double rgExtendedAmountMin = Double.MAX_VALUE; for (int y = y0; y < y0 + h; y += 20) { - final int burstIndex = getBurstIndex(y); + final int burstIndex = getBurstIndex(y, subSwathIndex); for (int x = x0; x < x0 + w; x += 20) { - final double azTime = getAzimuthTime(y, burstIndex); - final double rgTime = getSlantRangeTime(x); + final double azTime = getAzimuthTime(y, burstIndex, subSwathIndex); + final double rgTime = getSlantRangeTime(x, subSwathIndex); final double lat = mSU.getLatitude(azTime, rgTime, subSwathIndex); final double lon = mSU.getLongitude(azTime, rgTime, subSwathIndex); geoPos.setLocation(lat, lon); @@ -664,7 +706,7 @@ private void computeExtendedAmount(final int x0, final int y0, final int w, fina } } - private int getBurstIndex(final int y) { + private int getBurstIndex(final int y, final int subSwathIndex) { for (int burstIndex = 0; burstIndex < mSubSwath[subSwathIndex - 1].numOfBursts; burstIndex++) { final int firstLineIdx = burstIndex*mSubSwath[subSwathIndex - 1].linesPerBurst; final int lastLineIdx = firstLineIdx + mSubSwath[subSwathIndex - 1].linesPerBurst - 1; @@ -675,13 +717,13 @@ private int getBurstIndex(final int y) { return -1; } - private double getAzimuthTime(final int y, final int burstIndex) { + private double getAzimuthTime(final int y, final int burstIndex, final int subSwathIndex) { final Sentinel1Utils.SubSwathInfo subSwath = mSubSwath[subSwathIndex - 1]; return subSwath.burstFirstLineTime[burstIndex] + (y - burstIndex * subSwath.linesPerBurst) * subSwath.azimuthTimeInterval; } - private double getSlantRangeTime(final int x) { + private double getSlantRangeTime(final int x, final int subSwathIndex) { return mSubSwath[subSwathIndex - 1].slrTimeToFirstPixel + x * mSU.rangeSpacing / Constants.lightSpeed; } @@ -692,7 +734,7 @@ private void computePartialTile(final int subSwathIndex, final int mBurstIndex, ProgressMonitor pm) throws Exception { - final int sBurstIndex = mBurstIndex + burstOffset; + final int sBurstIndex = mBurstIndex + burstOffset[subSwathIndex - 1]; if (sBurstIndex < 0 || sBurstIndex >= sSubSwath[subSwathIndex - 1].numOfBursts) { return; } @@ -721,22 +763,30 @@ private void computePartialTile(final int subSwathIndex, final int mBurstIndex, return; } - final Band slaveBandI = getBand(slaveProduct, "i_", swathIndexStr, polarization); - final Band slaveBandQ = getBand(slaveProduct, "q_", swathIndexStr, polarization); - final Tile slaveTileI = getSourceTile(slaveBandI, sourceRectangle); - final Tile slaveTileQ = getSourceTile(slaveBandQ, sourceRectangle); + final String sSubSwathName = acquisitionMode + sBurstIndex; + for (String sPol : sPolarizations) { - if (slaveTileI == null || slaveTileQ == null) { - return; - } + final Band slaveBandI = getBand(slaveProduct, "i_", sSubSwathName, sPol); + final Band slaveBandQ = getBand(slaveProduct, "q_", sSubSwathName, sPol); + final Tile slaveTileI = getSourceTile(slaveBandI, sourceRectangle); + final Tile slaveTileQ = getSourceTile(slaveBandQ, sourceRectangle); + if (slaveTileI == null || slaveTileQ == null) { + return; + } + + final Band targetBandI = sourceBandToTargetBandMap.get(slaveBandI); + final Band targetBandQ = sourceBandToTargetBandMap.get(slaveBandQ); - final double[][] derampDemodI = new double[sourceRectangle.height][sourceRectangle.width]; - final double[][] derampDemodQ = new double[sourceRectangle.height][sourceRectangle.width]; + final double[][] derampDemodI = new double[sourceRectangle.height][sourceRectangle.width]; + final double[][] derampDemodQ = new double[sourceRectangle.height][sourceRectangle.width]; - performDerampDemod(slaveTileI, slaveTileQ, sourceRectangle, derampDemodPhase, derampDemodI, derampDemodQ); + performDerampDemod( + slaveTileI, slaveTileQ, sourceRectangle, derampDemodPhase, derampDemodI, derampDemodQ); - performInterpolation(x0, y0, w, h, sourceRectangle, slaveTileI, slaveTileQ, targetTileMap, derampDemodPhase, - derampDemodI, derampDemodQ, slavePixPos, subSwathIndex, sBurstIndex); + performInterpolation(x0, y0, w, h, sourceRectangle, slaveTileI, slaveTileQ, targetBandI, targetBandQ, + targetTileMap, derampDemodPhase, derampDemodI, derampDemodQ, slavePixPos, subSwathIndex, + sBurstIndex); + } } private PixelPos[][] computeSlavePixPos(final int subSwathIndex, final int mBurstIndex, final int sBurstIndex, @@ -1111,6 +1161,7 @@ public static void performDerampDemod(final Tile slaveTileI, final Tile slaveTil private void performInterpolation(final int x0, final int y0, final int w, final int h, final Rectangle sourceRectangle, final Tile slaveTileI, final Tile slaveTileQ, + final Band targetBandI, final Band targetBandQ, final Map targetTileMap, final double[][] derampDemodPhase, final double[][] derampDemodI, final double[][] derampDemodQ, final PixelPos[][] slavePixPos, final int subswathIndex, final int sBurstIndex) { @@ -1120,34 +1171,17 @@ private void performInterpolation(final int x0, final int y0, final int w, final final ResamplingRaster resamplingRasterQ = new ResamplingRaster(slaveTileQ, derampDemodQ); final ResamplingRaster resamplingRasterPhase = new ResamplingRaster(slaveTileI, derampDemodPhase); - final Band[] targetBands = targetProduct.getBands(); - Band iBand = null; - Band qBand = null; - Band phaseBand = null; - for (Band band : targetBands) { - final String bandName = band.getName(); - if (bandName.contains("i_") && bandName.contains("_slv")) { - iBand = band; - } else if (bandName.contains("q_") && bandName.contains("_slv")) { - qBand = band; - } else if (bandName.contains("derampDemodPhase")) { - phaseBand = band; - } - } - - if (iBand == null || qBand == null) { - return; - } - - final Tile tgtTileI = targetTileMap.get(iBand); - final Tile tgtTileQ = targetTileMap.get(qBand); + final Tile tgtTileI = targetTileMap.get(targetBandI); + final Tile tgtTileQ = targetTileMap.get(targetBandQ); final ProductData tgtBufferI = tgtTileI.getDataBuffer(); final ProductData tgtBufferQ = tgtTileQ.getDataBuffer(); final TileIndex tgtIndex = new TileIndex(tgtTileI); + Band phaseBand; Tile tgtTilePhase; ProductData tgtBufferPhase = null; if (outputDerampDemodPhase) { + phaseBand = targetProduct.getBand("derampDemodPhase"); tgtTilePhase = targetTileMap.get(phaseBand); tgtBufferPhase = tgtTilePhase.getDataBuffer(); } @@ -1244,8 +1278,8 @@ private void outputRangeAzimuthOffsets(final int x0, final int y0, final int w, return; } - Sentinel1Utils.SubSwathInfo mSubSwath = mSU.getSubSwath()[subSwathIndex - 1]; - Sentinel1Utils.SubSwathInfo sSubSwath = sSU.getSubSwath()[subSwathIndex - 1]; + //Sentinel1Utils.SubSwathInfo mSubSwath = mSU.getSubSwath()[subSwathIndex - 1]; + //Sentinel1Utils.SubSwathInfo sSubSwath = sSU.getSubSwath()[subSwathIndex - 1]; final Tile tgtTileAzOffset = targetTileMap.get(azOffsetBand); final Tile tgtTileRgOffset = targetTileMap.get(rgOffsetBand); From 0312a512a3927954791b5c869970c07f350657be Mon Sep 17 00:00:00 2001 From: jun--lu Date: Fri, 18 Sep 2015 20:14:42 -0400 Subject: [PATCH 5/8] fixed a bug in computePartialTile --- .../main/java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s1tbx-op-sentinel1/src/main/java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java b/s1tbx-op-sentinel1/src/main/java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java index d065bfc05..8da6d9d1b 100644 --- a/s1tbx-op-sentinel1/src/main/java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java +++ b/s1tbx-op-sentinel1/src/main/java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java @@ -763,7 +763,7 @@ private void computePartialTile(final int subSwathIndex, final int mBurstIndex, return; } - final String sSubSwathName = acquisitionMode + sBurstIndex; + final String sSubSwathName = acquisitionMode + subSwathIndex; for (String sPol : sPolarizations) { final Band slaveBandI = getBand(slaveProduct, "i_", sSubSwathName, sPol); From eb7aa8eab209a47abf4510ebeaf5c51a2f6b8dd2 Mon Sep 17 00:00:00 2001 From: jun--lu Date: Mon, 21 Sep 2015 10:48:37 -0400 Subject: [PATCH 6/8] added a check on tile boundary --- .../java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/s1tbx-op-sentinel1/src/main/java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java b/s1tbx-op-sentinel1/src/main/java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java index 8da6d9d1b..c02ba0ec7 100644 --- a/s1tbx-op-sentinel1/src/main/java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java +++ b/s1tbx-op-sentinel1/src/main/java/org/esa/s1tbx/sentinel1/gpf/BackGeocodingOp.java @@ -444,7 +444,7 @@ private void updateTargetProductMetadata() { * If an error occurs during computation of the target raster. */ @Override - public synchronized void computeTileStack(Map targetTileMap, Rectangle targetRectangle, ProgressMonitor pm) + public void computeTileStack(Map targetTileMap, Rectangle targetRectangle, ProgressMonitor pm) throws OperatorException { try { @@ -478,6 +478,9 @@ public synchronized void computeTileStack(Map targetTileMap, Rectang if (tyMax < firstLineIdx || ty0 > lastLineIdx) { continue; } + if (tx0 >= mSubSwath[s].samplesPerBurst - 1) { + continue; + } final int ntx0 = tx0; final int ntxMax = Math.min(txMax, mSubSwath[s].samplesPerBurst - 1); From e29f9055b6404e829acf4cdf1e5b823f7c77fd2f Mon Sep 17 00:00:00 2001 From: jun--lu Date: Mon, 21 Sep 2015 10:51:18 -0400 Subject: [PATCH 7/8] modified readSLCRasterBand --- .../io/sentinel1/Sentinel1ProductReader.java | 100 +++++++++--------- 1 file changed, 52 insertions(+), 48 deletions(-) diff --git a/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java b/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java index 33220c5fb..4c203dedb 100644 --- a/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java +++ b/s1tbx-io/src/main/java/org/esa/s1tbx/io/sentinel1/Sentinel1ProductReader.java @@ -152,62 +152,66 @@ public void readSLCRasterBand(final int sourceOffsetX, final int sourceOffsetY, final int destOffsetX, final int destOffsetY, int destWidth, int destHeight, final ImageIOFile.BandInfo bandInfo) throws IOException { - int[] srcArray; - - //System.out.println(cache.stats()+", size="+cache.size()); - - final int imgWidth = bandInfo.img.getImageWidth(); - final int imgheight = bandInfo.img.getImageHeight(); - final Rectangle imgRect = new Rectangle(destOffsetX, destOffsetY, - Math.min(destWidth, imgWidth - destOffsetX), - Math.min(destHeight, imgheight - destOffsetY)); - if(imgRect.width <= 0 || imgRect.height <= 0) - return; - - final DataCache.DataKey datakey = new DataCache.DataKey(bandInfo.img, imgRect); - DataCache.Data cachedData = cache.get(datakey); - if (cachedData != null && cachedData.valid) { - srcArray = cachedData.intArray; - } else { - cachedData = readRect(datakey, bandInfo, - sourceOffsetX, sourceOffsetY, sourceStepX, sourceStepY, - imgRect); - srcArray = cachedData.intArray; - } - - final short[] destArray = (short[]) destBuffer.getElems(); - if (!bandInfo.isImaginary) { - if (sourceStepX == 1) { - for(int y=0; y < imgRect.height; ++y) { - int stride = y*imgRect.width; - for(int x=0; x < imgRect.width; ++x) { - destArray[stride+x] = (short) srcArray[stride+x]; - } - } + try { + int[] srcArray; + + //System.out.println(cache.stats()+", size="+cache.size()); + + final int imgWidth = bandInfo.img.getImageWidth(); + final int imgheight = bandInfo.img.getImageHeight(); + final Rectangle imgRect = new Rectangle(destOffsetX, destOffsetY, + Math.min(destWidth, imgWidth - destOffsetX), + Math.min(destHeight, imgheight - destOffsetY)); + if (imgRect.width <= 0 || imgRect.height <= 0) + return; + + final DataCache.DataKey datakey = new DataCache.DataKey(bandInfo.img, imgRect); + DataCache.Data cachedData = cache.get(datakey); + if (cachedData != null && cachedData.valid) { + srcArray = cachedData.intArray; } else { - for(int y=0; y < imgRect.height; ++y) { - int stride = y*imgRect.width; - for(int x=0; x < imgRect.width; x += sourceStepX) { - destArray[stride+x] = (short) srcArray[stride+x]; - } - } + cachedData = readRect(datakey, bandInfo, + sourceOffsetX, sourceOffsetY, sourceStepX, sourceStepY, + imgRect); + srcArray = cachedData.intArray; } - } else { - if (sourceStepX == 1) { - for(int y=0; y < imgRect.height; ++y) { - int stride = y*imgRect.width; - for(int x=0; x < imgRect.width; ++x) { - destArray[stride+x] = (short) (srcArray[stride+x] >> 16); + + final short[] destArray = (short[]) destBuffer.getElems(); + if (!bandInfo.isImaginary) { + if (sourceStepX == 1) { + for (int y = 0; y < imgRect.height; ++y) { + int stride = y * imgRect.width; + for (int x = 0; x < imgRect.width; ++x) { + destArray[stride + x] = (short) srcArray[stride + x]; + } + } + } else { + for (int y = 0; y < imgRect.height; ++y) { + int stride = y * imgRect.width; + for (int x = 0; x < imgRect.width; x += sourceStepX) { + destArray[stride + x] = (short) srcArray[stride + x]; + } } } } else { - for(int y=0; y < imgRect.height; ++y) { - int stride = y*imgRect.width; - for(int x=0; x < imgRect.width; x += sourceStepX) { - destArray[stride+x] = (short) (srcArray[stride+x] >> 16); + if (sourceStepX == 1) { + for (int y = 0; y < imgRect.height; ++y) { + int stride = y * imgRect.width; + for (int x = 0; x < imgRect.width; ++x) { + destArray[stride + x] = (short) (srcArray[stride + x] >> 16); + } + } + } else { + for (int y = 0; y < imgRect.height; ++y) { + int stride = y * imgRect.width; + for (int x = 0; x < imgRect.width; x += sourceStepX) { + destArray[stride + x] = (short) (srcArray[stride + x] >> 16); + } } } } + } catch(Exception t) { + t.printStackTrace(); } } From 40f19ffc0acc1f7a53bd8738dbbb7b6f1783247e Mon Sep 17 00:00:00 2001 From: jun--lu Date: Mon, 21 Sep 2015 10:52:42 -0400 Subject: [PATCH 8/8] modified to fix a multi-thread problem --- .../main/java/org/esa/s1tbx/io/imageio/ImageIOFile.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/s1tbx-io/src/main/java/org/esa/s1tbx/io/imageio/ImageIOFile.java b/s1tbx-io/src/main/java/org/esa/s1tbx/io/imageio/ImageIOFile.java index fb4e5136b..55b28c389 100644 --- a/s1tbx-io/src/main/java/org/esa/s1tbx/io/imageio/ImageIOFile.java +++ b/s1tbx-io/src/main/java/org/esa/s1tbx/io/imageio/ImageIOFile.java @@ -213,14 +213,18 @@ public void close() throws IOException { public int getImageWidth() throws IOException { if (imgWidth == 0) { - imgWidth = reader.getWidth(0); + synchronized(reader) { + imgWidth = reader.getWidth(0); + } } return imgWidth; } public int getImageHeight() throws IOException { if (imgHeight == 0) { - imgHeight = reader.getHeight(0); + synchronized(reader) { + imgHeight = reader.getHeight(0); + } } return imgHeight; }