From: <aa...@sv...> - 2007-01-30 18:20:53
|
Author: aaime Date: 2007-01-30 11:19:41 -0800 (Tue, 30 Jan 2007) New Revision: 24101 Modified: geotools/branches/2.3.x/module/coverage/src/org/geotools/coverage/proc= essing/operation/Resampler2D.java Log: Small optimizations, and a fix for cases when a grid needs to be rescaled= to a different grid geometry Modified: geotools/branches/2.3.x/module/coverage/src/org/geotools/covera= ge/processing/operation/Resampler2D.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/branches/2.3.x/module/coverage/src/org/geotools/coverage/pro= cessing/operation/Resampler2D.java 2007-01-30 17:12:35 UTC (rev 24100) +++ geotools/branches/2.3.x/module/coverage/src/org/geotools/coverage/pro= cessing/operation/Resampler2D.java 2007-01-30 19:19:41 UTC (rev 24101) @@ -56,6 +56,7 @@ import org.geotools.image.ImageWorker; import org.geotools.referencing.CRS; import org.geotools.referencing.FactoryFinder; +import org.geotools.referencing.operation.matrix.XAffineTransform; import org.geotools.referencing.operation.transform.DimensionFilter; import org.geotools.referencing.operation.transform.WarpTransform2D; import org.geotools.referencing.operation.transform.IdentityTransform; @@ -138,8 +139,9 @@ CoordinateReferenceSystem targetCRS, GridGeometry2D targetGG, final Interpolation interpolation, final Hints hints) throws FactoryException, TransformException { - int actionTaken =3D 0;// 0=3D=3Dnothing changes, 1=3D=3Dindex color ex= panded, + // 0=3D=3Dnothing changes, 1=3D=3Dindex color expanded, // 2=3D=3Dtaken geophysics, 3=3D=3Dtaken non-geophysics + int actionTaken =3D 0; /* * Grid range and "grid to CRS" transform are the only grid geometry * informations used by this method. If they are not available, this i= s @@ -379,7 +381,6 @@ * layout. The xmin, xmax, ymin and ymax bounds are relative to the * target image. */ - final GridRange sourceGR =3D sourceGG.getGridRange(); final GridRange targetGR =3D targetGG.getGridRange(); final int xAxis =3D targetGG.gridDimensionX; final int yAxis =3D targetGG.gridDimensionY; @@ -387,6 +388,11 @@ final int xmax =3D targetGR.getUpper(xAxis); final int ymin =3D targetGR.getLower(yAxis); final int ymax =3D targetGR.getUpper(yAxis); + final GridRange sourceGR =3D sourceGG.getGridRange(); + final int xminS =3D sourceGR.getLower(xAxis); + final int xmaxS =3D sourceGR.getUpper(xAxis); + final int yminS =3D sourceGR.getLower(yAxis); + final int ymaxS =3D sourceGR.getUpper(yAxis); ImageLayout layout =3D (ImageLayout) targetHints .get(JAI.KEY_IMAGE_LAYOUT); if (layout !=3D null) { @@ -440,15 +446,35 @@ * operation. */ String operation =3D null; - if (allSteps.isIdentity()) { - if (xmin >=3D sourceGR.getLower(sourceGG.gridDimensionX) - && xmax <=3D sourceGR.getUpper(sourceGG.gridDimensionX) - && ymin >=3D sourceGR.getLower(sourceGG.gridDimensionY) - && ymax <=3D sourceGR.getUpper(sourceGG.gridDimensionY)) { + if ((allSteps instanceof AffineTransform) && ((AffineTransform) allSte= ps).isIdentity()) { + if (xmin > xminS + && xmax < xmaxS + && ymin >yminS + && ymax <ymaxS) { operation =3D "Crop"; paramBlk =3D paramBlk.add((float) (xmin)).add((float) (ymin)) .add((float) (xmax - xmin)).add((float) (ymax - ymin)); } + else + if(xmin =3D=3DxminS + && xmax =3D=3D xmaxS + && ymin =3D=3DyminS + && ymax =3D=3DymaxS) + { + //// + // + // Optimization in case we have nothing to do, not even a crop. + // + //// + GridCoverage2D targetCoverage =3D new Resampler2D(sourceCoverage, + sourceImage, targetGG, actionTaken =3D=3D 1 ? null + : sourceCoverage.getSampleDimensions()); + if (actionTaken =3D=3D 3) { + targetCoverage =3D targetCoverage.geophysics(true); + } else if (actionTaken =3D=3D 2) + targetCoverage =3D targetCoverage.geophysics(false); + return targetCoverage; + } } =20 /* @@ -495,7 +521,7 @@ return targetCoverage; } // More general approach: apply the affine transform. - if (automaticGR) { +// if (automaticGR) { operation =3D "Affine"; // prepare the values for the background background =3D CoverageUtilities.getBackgroundValues(sourceCoverage= ); @@ -503,7 +529,17 @@ .inverse(); paramBlk =3D paramBlk.add(affine).add(interpolation).add( background); - } +// } +// else +// { +// /////////////////////////////////////////////////////////// +// // +// // Let's now check the situation where a simple change of=20 +// // envelope is require, that is when the allSteps transfor_ +// // mations is the identity but the two CRS are not the same. +// // +// /////////////////////////////////////////////////////////// +// } } else { /* * General case: construct the warp transform. |