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/AbstractFusionMethod.java
AbstractFusionMethod.java | ||
---|---|---|
1 | 1 |
package org.gvsig.raster.impl.provider.fusion; |
2 | 2 |
|
3 |
import java.awt.geom.AffineTransform; |
|
4 |
import java.awt.geom.NoninvertibleTransformException; |
|
5 |
import java.awt.geom.Point2D; |
|
3 | 6 |
import java.awt.geom.Rectangle2D; |
4 | 7 |
|
5 | 8 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
6 | 9 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
7 |
import org.gvsig.raster.impl.provider.fusion.BufferListFusion.PixelSquareStructure; |
|
8 | 10 |
|
9 | 11 |
public abstract class AbstractFusionMethod { |
10 | 12 |
protected PixelSquareStructure pxSquare = null; |
11 | 13 |
|
12 | 14 |
public class SubSquare { |
13 |
private int ulxPxDistance = 0; |
|
14 |
private int ulyPxDistance = 0; |
|
15 |
private int lrxPxDistance = 0; |
|
16 |
private int lryPxDistance = 0; |
|
17 | 15 |
private Buffer buffer = null; |
16 |
private AffineTransform parentTransform = null; |
|
17 |
private AffineTransform squareTransform = null; |
|
18 |
private Extent squareExtent = null; |
|
18 | 19 |
|
19 | 20 |
public SubSquare( |
20 | 21 |
Extent parentExtent, |
... | ... | |
23 | 24 |
Rectangle2D squareSize, |
24 | 25 |
Buffer buf) { |
25 | 26 |
this.buffer = buf; |
26 |
double xDistWc = Math.abs(squareExtent.getULX() - parentExtent.getULX()); |
|
27 |
double yDistWc = Math.abs(squareExtent.getULY() - parentExtent.getULY()); |
|
28 |
double pixelSize = parentExtent.width() / parentSize.getWidth(); |
|
29 |
ulxPxDistance = (int)Math.floor(xDistWc * pixelSize); |
|
30 |
ulyPxDistance = (int)Math.ceil(yDistWc * pixelSize); |
|
31 |
lrxPxDistance = (int)(ulxPxDistance + squareSize.getWidth() - 1); |
|
32 |
lryPxDistance = (int)(ulyPxDistance + squareSize.getHeight() - 1); |
|
27 |
this.squareExtent = squareExtent; |
|
28 |
parentTransform = new AffineTransform( |
|
29 |
parentExtent.width() / parentSize.getWidth(), |
|
30 |
0, 0, |
|
31 |
-(parentExtent.height() / parentSize.getHeight()), |
|
32 |
parentExtent.getULX(), |
|
33 |
parentExtent.getULY()); |
|
34 |
|
|
35 |
squareTransform = new AffineTransform( |
|
36 |
squareExtent.width() / squareSize.getWidth(), |
|
37 |
0, 0, |
|
38 |
-(squareExtent.height() / squareSize.getHeight()), |
|
39 |
squareExtent.getULX(), |
|
40 |
squareExtent.getULY()); |
|
33 | 41 |
} |
34 | 42 |
|
43 |
private Point2D parentRasterToWorld(Point2D pt) { |
|
44 |
return parentTransform.transform(pt, pt); |
|
45 |
} |
|
46 |
|
|
47 |
private Point2D squareWorldToRaster(Point2D pt) { |
|
48 |
try { |
|
49 |
return squareTransform.inverseTransform(pt, pt); |
|
50 |
} catch (NoninvertibleTransformException e) { |
|
51 |
return pt; |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
35 | 55 |
/** |
36 | 56 |
* Returns true if the pixel coordinates relative to the parent buffer is inside of this square |
37 | 57 |
* @param row |
38 | 58 |
* @param col |
39 | 59 |
* @return |
40 | 60 |
*/ |
41 |
public boolean isInside(int row, int col) { |
|
42 |
return (col >= ulxPxDistance && col <= lrxPxDistance && row >= ulyPxDistance && row <= lryPxDistance); |
|
61 |
public Point2D getLocalCoords(int row, int col) { |
|
62 |
Point2D p = parentRasterToWorld(new Point2D.Double(col, row)); |
|
63 |
if (p.getX() >= squareExtent.getULX() && p.getX() <= squareExtent.getLRX() && p.getY() <= squareExtent.getULY() && p.getY() >= squareExtent.getLRY()) { |
|
64 |
return squareWorldToRaster(p); |
|
65 |
} |
|
66 |
return null; |
|
43 | 67 |
} |
44 | 68 |
|
45 |
public void loadLocalCoords(int row, int col, int[] coords) { |
|
46 |
coords[0] = row - ulyPxDistance; |
|
47 |
coords[1] = col - ulxPxDistance; |
|
48 |
} |
|
49 |
|
|
50 | 69 |
public Buffer getBuffer() { |
51 | 70 |
return buffer; |
52 | 71 |
} |
... | ... | |
56 | 75 |
this.pxSquare = pxSquare; |
57 | 76 |
} |
58 | 77 |
|
59 |
public abstract byte[] getByteValue(int row, int col);
|
|
78 |
public abstract Byte getByteValue(int row, int col, int band);
|
|
60 | 79 |
|
61 |
public abstract float[] getFloatValue(int row, int col); |
|
80 |
public abstract Float getFloatValue(int row, int col, int band); |
|
81 |
|
|
82 |
public abstract int getBandCount(); |
|
62 | 83 |
|
63 | 84 |
} |
Also available in: Unified diff