Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / grid / TGEmptyBufferForWrite.java @ 21615

History | View | Annotate | Download (5.53 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.grid;
20

    
21
import junit.framework.TestCase;
22

    
23
import org.gvsig.raster.RasterLibrary;
24
import org.gvsig.raster.buffer.RasterBufferInvalidAccessException;
25
import org.gvsig.raster.buffer.RasterBufferInvalidException;
26
import org.gvsig.raster.dataset.IBuffer;
27
/**
28
 * Este test prueba el acceso a datos a traves de un grid.
29
 * 
30
 * 1-Crear? un buffer vacio para escritura con la extensi?n pasado por
31
 *   par?metro. El extent completo ser? igual que el extent de la vista asignada
32
 *   (SIN INTERPOLACI?N).
33
 * 2-Comprueba que se calcule bien el n?mero de pixels
34
 * 3-Asigna datos al grid
35
 * 4-Los recupera comprobando que est?n bien asignados
36
 * 
37
 * 1-Crear? un buffer vacio para escritura con la extensi?n pasado por
38
 *   par?metro. El extent completo ser? distinto que el extent de la vista
39
 *   asignada (CON INTERPOLACI?N).
40
 * 2-Comprueba que se calcule bien el n?mero de pixels
41
 * 3-Asigna datos al grid
42
 * 4-Los recupera con distintos m?todos de interpolaci?n comprobando que est?n
43
 *   bien asignados
44
 * 
45
 * @author Nacho Brodin (nachobrodin@gmail.com)
46
 *
47
 */
48
public class TGEmptyBufferForWrite extends TestCase {
49

    
50
        static {
51
                RasterLibrary.wakeUp();
52
        }
53

    
54
        public void setUp() {
55
                System.err.println("TGEmptyBufferForWrite running...");
56
        }
57

    
58
        public void start() {
59
                this.setUp();
60
                this.testStack();
61
        }
62

    
63
        public void testStack() {
64
                try {
65
                        // SIN INTERPOLACI?N
66
                        GridExtent layerExtent = new GridExtent(1000, 1000, 1500, 1500, 50);
67
                        Grid g = new Grid(layerExtent, layerExtent, IBuffer.TYPE_INT, new int[] { 0, 1, 2 });
68

    
69
                        // Tama?o en pixels
70
                        assertEquals(layerExtent.getNX(), 10);
71
                        assertEquals(layerExtent.getNY(), 10);
72
                        assertEquals(g.getNX(), 10);
73
                        assertEquals(g.getNY(), 10);
74

    
75
                        for (int i = 0; i < g.getNX(); i++) {
76
                                for (int j = 0; j < g.getNY(); j++)
77
                                        g.setCellValue(j, i, (int) (j * i));
78
                        }
79
                        // print(g);
80
                        for (int i = 0; i < g.getNX(); i++) {
81
                                for (int j = 0; j < g.getNY(); j++)
82
                                        assertEquals(g.getCellValueAsInt(j, i), (int) (j * i));
83
                        }
84

    
85
                        // CON INTERPOLACI?N
86
                        GridExtent windowExtent = new GridExtent(1125, 1125, 1375, 1375, 50);
87
                        layerExtent = new GridExtent(1000, 1000, 1500, 1500, 50);
88
                        g = new Grid(layerExtent, windowExtent, IBuffer.TYPE_INT, new int[] { 0, 1, 2 });
89

    
90
                        // Tama?o en pixels
91
                        assertEquals(layerExtent.getNX(), 10);
92
                        assertEquals(layerExtent.getNY(), 10);
93
                        assertEquals(g.getNX(), 5);
94
                        assertEquals(g.getNY(), 5);
95

    
96
                        for (int i = 0; i < g.getLayerNX(); i++) {
97
                                for (int j = 0; j < g.getLayerNY(); j++)
98
                                        g.setCellValue(j, i, (int) (j * i));
99
                        }
100
                        g.setInterpolationMethod(GridInterpolated.INTERPOLATION_BicubicSpline);
101
                        int[][] m1 = new int[][] { { 9, 12, 15, 18, 21 }, { 12, 16, 20, 24, 28 }, { 15, 20, 25, 30, 35 }, { 18, 24, 30, 36, 42 }, { 21, 28, 35, 42, 49 } };
102
                        // print(g);
103
                        compare(m1, g);
104

    
105
                        g.setInterpolationMethod(GridInterpolated.INTERPOLATION_NearestNeighbour);
106
                        // print(g);
107
                        int[][] m2 = new int[][] { { 9, 12, 15, 18, 21 }, { 12, 16, 20, 24, 28 }, { 15, 20, 25, 30, 35 }, { 18, 24, 30, 36, 42 }, { 21, 28, 35, 42, 49 } };
108
                        compare(m2, g);
109

    
110
                        g.setInterpolationMethod(GridInterpolated.INTERPOLATION_Bilinear);
111
                        // print(g);
112
                        int[][] m3 = new int[][] { { 9, 12, 15, 18, 21 }, { 12, 16, 20, 24, 28 }, { 15, 20, 25, 30, 35 }, { 18, 24, 30, 36, 42 }, { 21, 28, 35, 42, 49 } };
113
                        compare(m3, g);
114

    
115
                        g.setInterpolationMethod(GridInterpolated.INTERPOLATION_BSpline);
116
                        // print(g);
117
                        int[][] m4 = new int[][] { { 9, 11, 14, 18, 21 }, { 12, 15, 19, 23, 27 }, { 14, 20, 24, 29, 35 }, { 18, 23, 30, 36, 41 }, { 21, 27, 35, 42, 49 } };
118
                        compare(m4, g);
119

    
120
                        g.setInterpolationMethod(GridInterpolated.INTERPOLATION_InverseDistance);
121
                        // print(g);
122
                        int[][] m5 = new int[][] { { 9, 12, 15, 18, 21 }, { 12, 16, 20, 24, 28 }, { 15, 20, 25, 30, 35 }, { 18, 24, 30, 36, 42 }, { 21, 28, 35, 42, 49 } };
123
                        compare(m5, g);
124

    
125
                } catch (RasterBufferInvalidException e1) {
126
                        e1.printStackTrace();
127
                } catch (OutOfGridException e3) {
128
                        e3.printStackTrace();
129
                } catch (RasterBufferInvalidAccessException e) {
130
                        e.printStackTrace();
131
                } catch (GridException e) {
132
                        e.printStackTrace();
133
                }
134
        }
135
        
136
        private void compare(int[][] m, Grid g) throws RasterBufferInvalidAccessException, GridException {
137
                for (int line = 0; line < g.getNY(); line++) {
138
                        for (int col = 0; col < g.getNX(); col++)
139
                                assertEquals(g.getCellValueAsInt(col, line), m[line][col]);
140
                }
141
        }
142
        
143
        /**
144
         * Imprime todos los pixels de la fuente de datos en RGB
145
         * @throws RasterBufferInvalidAccessException 
146
         */
147
        /*private void print(Grid g) throws RasterBufferInvalidAccessException {
148
                for(int line = 0; line < g.getNY(); line++){
149
                        for(int col = 0; col < g.getNX(); col++)
150
                                System.out.print(g.getCellValueAsInt(col, line) + " ");
151
                        System.out.println();
152
                }
153
                System.out.println();
154
        }*/
155
}