Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / buffer / TestGdalFloatHistogram.java @ 11183

History | View | Annotate | Download (4.38 KB)

1 11113 nacho
/* 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.buffer;
20
21
import junit.framework.TestCase;
22
23
import org.gvsig.raster.RasterLibrary;
24
import org.gvsig.raster.dataset.IBuffer;
25
import org.gvsig.raster.dataset.NotSupportedExtensionException;
26
import org.gvsig.raster.dataset.RasterDataset;
27
import org.gvsig.raster.dataset.RasterDriverException;
28
import org.gvsig.raster.dataset.RasterMultiDataset;
29
import org.gvsig.raster.util.Histogram;
30
31
/**
32
 * Test a un histograma usando clases. El test se realiza sobre un raster en
33
 * coma flotante de 28x25 pixels. Se crean clases de tres tipo de intervalos distintos y
34
 * se testean los valores obtenidos en el histograma resultante. El ?ltimo
35
 * test comprueba la generaci?n autom?tica de clases.
36
 *
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 */
39
public class TestGdalFloatHistogram extends TestCase {
40
41
        private String baseDir = "./test-images/";
42
        private String path = baseDir + "miniRaster28x25F32.tif";
43
        private RasterDataset f = null;
44
        private BufferFactory ds = null;
45
46
        public void start() {
47
                this.setUp();
48
                this.testStack();
49
        }
50
51
        public void setUp() {
52
                System.err.println("TestGdalFloatHistogram running...");
53
        }
54
55
        static{
56
                RasterLibrary.wakeUp();
57
        }
58
59
        public void testStack() {
60
                int[] drawableBands = {0, 1, 2};
61
                try {
62
                        f = RasterDataset.open(null, path);
63
                } catch (NotSupportedExtensionException e) {
64
                        return;
65
                } catch (RasterDriverException e) {
66
                        return;
67
                }
68
                ds = new BufferFactory(f);
69
                ds.addDrawableBands(drawableBands);
70
                ds.setAreaOfInterest(0, 0, 28, 25);
71
                //printData();
72
73
                Histogram histogram = null;
74
                RasterMultiDataset rmd = ds.getGeoRasterMultiFile();
75
76
                /*try {
77
                        histogram = rmd.getHistogram();
78
                } catch (HistogramException e) {
79
                        e.printStackTrace();
80
                }*/
81
                //testHist1(histogram);
82
83
        }
84
85
        private void testHist1(Histogram histogram) {
86
                assertEquals(histogram.getHistogramValue(0, 0), 0);
87
                assertEquals(histogram.getHistogramValue(0, 1), 700);
88
        }
89
90
        private void testHist2(Histogram histogram) {
91
                assertEquals(histogram.getHistogramValue(0, 0), 180);
92
                assertEquals(histogram.getHistogramValue(0, 1), 520);
93
        }
94
95
        private void testHist3(Histogram histogram) {
96
                assertEquals(histogram.getHistogramValue(0, 0), 4);
97
                assertEquals(histogram.getHistogramValue(0, 1), 38);
98
                assertEquals(histogram.getHistogramValue(0, 2), 138);
99
                assertEquals(histogram.getHistogramValue(0, 3), 100);
100
                assertEquals(histogram.getHistogramValue(0, 4), 420);
101
        }
102
103
        private void testHist4(Histogram histogram) {
104
                assertEquals(histogram.getHistogramValue(0, 0), 10);
105
                assertEquals(histogram.getHistogramValue(0, 1), 17);
106
                assertEquals(histogram.getHistogramValue(0, 2), 36);
107
                assertEquals(histogram.getHistogramValue(0, 3), 72);
108
                assertEquals(histogram.getHistogramValue(0, 4), 119);
109
                assertEquals(histogram.getHistogramValue(0, 5), 129);
110
                assertEquals(histogram.getHistogramValue(0, 6), 98);
111
                assertEquals(histogram.getHistogramValue(0, 7), 93);
112
                assertEquals(histogram.getHistogramValue(0, 8), 76);
113
                assertEquals(histogram.getHistogramValue(0, 9), 49);
114
        }
115
116
        private void print(Histogram histogram) {
117
                for (int i = 0; i < histogram.getNumBands(); i++) {
118
                        for (int j = 0; j < histogram.getBandLenght(i); j++) {
119
                                System.out.print(histogram.getHistogramValue(i, j) + " ");
120
                        }
121
                        System.out.println("");
122
                }
123
        }
124
125
        /**
126
         * Imprime todos los pixels de la fuente de datos en RGB
127
         */
128
        private void printData() {
129
                IBuffer raster = ds.getRasterBuf();
130
                for(int line = 0; line < raster.getHeight(); line++) {
131
                        for(int col = 0; col < raster.getWidth(); col++)
132
                                System.out.print("(" + raster.getElemFloat(line, col, 0) + ")");
133
                        System.out.println();
134
                }
135
        }
136
}