Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / provider / fusion / FirstFusionMethod.java @ 2303

History | View | Annotate | Download (3.52 KB)

1
package org.gvsig.raster.impl.provider.fusion;
2

    
3
import java.awt.geom.Point2D;
4
import java.awt.geom.Rectangle2D;
5
import java.util.ArrayList;
6
import java.util.List;
7

    
8
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
9
import org.gvsig.raster.impl.datastruct.ExtentImpl;
10

    
11
public class FirstFusionMethod extends AbstractFusionMethod {
12
        protected SubSquareList     subSquareList    = null;
13
        private int                 bandCount        = 0;
14
        
15
        private int[]               lastPixelCoords  = new int[]{-1, -1};
16
        private byte[]              dataByte         = null;
17
        private short[]             dataShort        = null;
18
        private int[]               dataInt          = null;
19
        private float[]             dataFloat        = null;
20
        private double[]            dataDouble       = null;
21
        
22
        public class SubSquareList extends ArrayList<SubSquare> {
23
                private static final long serialVersionUID = 1L;
24
                private int               bandCount        = 0;
25
                
26
                public SubSquareList(int bandCount) {
27
                        this.bandCount = bandCount;
28
                }
29
                
30
                public byte[] getByteValue(int row, int col) {
31
                        byte[] value = new byte[bandCount];
32
                        for (int i = 0; i < size(); i++) {
33
                                Point2D coord = get(i).getLocalCoords(row, col);
34
                                if(coord != null) {
35
                                        get(i).getBuffer().getElemByte((int)coord.getY(), (int)coord.getX(), value);
36
                                        return value;
37
                                }
38
                        }
39
                        return null;
40
                }
41
                
42
                public float[] getFloatValue(int row, int col) {
43
                        float[] value = new float[bandCount];
44
                        for (int i = 0; i < size(); i++) {
45
                                Point2D coord = get(i).getLocalCoords(row, col);
46
                                if(coord != null) {
47
                                        get(i).getBuffer().getElemFloat((int)coord.getY(), (int)coord.getX(), value);
48
                                        return value;
49
                                }
50
                        }
51
                        return null;
52
                }
53
        }
54
        
55
        public FirstFusionMethod(
56
                        List<Buffer> bufferList, 
57
                        PixelSquareStructure pxSquare) {
58
                super(pxSquare);
59
                switch (pxSquare.dataType) {
60
                case Buffer.TYPE_BYTE:
61
                        dataByte = new byte[pxSquare.bandCount];
62
                        break;
63
                case Buffer.TYPE_SHORT:
64
                        dataShort = new short[pxSquare.bandCount];
65
                        break;
66
                case Buffer.TYPE_INT:
67
                        dataInt = new int[pxSquare.bandCount];
68
                        break;
69
                case Buffer.TYPE_FLOAT:
70
                        dataFloat = new float[pxSquare.bandCount];
71
                        break;
72
                case Buffer.TYPE_DOUBLE:
73
                        dataDouble = new double[pxSquare.bandCount];
74
                        break;
75
                }
76
                
77
                for (int i = 0; i < bufferList.size(); i++) {
78
                        bandCount = bufferList.get(i).getBandCount() > bandCount ? bufferList.get(i).getBandCount() : bandCount; 
79
                }
80
                
81
                subSquareList = new SubSquareList(bandCount);
82
                for (int i = 0; i < bufferList.size(); i++) {
83
                        SubSquare square = new SubSquare(
84
                                        pxSquare.bbox, 
85
                                        new Rectangle2D.Double(0, 0, pxSquare.width, pxSquare.height),
86
                                        new ExtentImpl(bufferList.get(i).getDataExtent()),
87
                                        new Rectangle2D.Double(0, 0, bufferList.get(i).getWidth(), bufferList.get(i).getHeight()),
88
                                        bufferList.get(i));
89
                        subSquareList.add(square);
90
                }
91
        }
92
        
93
        public Byte getByteValue(int row, int col, int band) {
94
                if(row != lastPixelCoords[0] || col != lastPixelCoords[1]) {
95
                        //Lee todas las bandas de una y devuelve la que corresponda al par?metro band
96
                        dataByte = subSquareList.getByteValue(row, col);
97
                        lastPixelCoords[0] = row;
98
                        lastPixelCoords[1] = col;
99
                }
100
                if(dataByte != null)
101
                        return dataByte[band];
102
                return null;
103
        }
104

    
105
        public Float getFloatValue(int row, int col, int band) {
106
                if(row == lastPixelCoords[0] && col == lastPixelCoords[1]) {
107
                        dataFloat = subSquareList.getFloatValue(row, col);
108
                        lastPixelCoords[0] = row;
109
                        lastPixelCoords[1] = col;
110
                }
111
                if(dataFloat != null)
112
                        return dataFloat[band];
113
                return null;
114
        }
115
        
116
        public int getBandCount() {
117
                return bandCount;
118
        }
119

    
120
}