Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / dataset / TestReadBlockMrSID.java @ 12522

History | View | Annotate | Download (3.22 KB)

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

    
27
import junit.framework.TestCase;
28

    
29
import org.gvsig.raster.RasterLibrary;
30
import org.gvsig.raster.buffer.BufferFactory;
31

    
32
/**
33
 * Test del uso de la funci?n readBlock de MrSID. Cargar? un dataset del formato mrsid y recorrer? todo
34
 * el raster con la llamada readBlock. El resultado de los datos leidos con esta llamada ser?n 
35
 * comparados a los leidos con setAreaOfInterest
36
 * 
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 *
39
 */
40
public class TestReadBlockMrSID extends TestCase {
41
        
42
        private String baseDir = "./test-images/";
43
        private String path1 = baseDir + "q101866.sid";
44
        private RasterDataset f1 = null;
45
        
46
        static {
47
                RasterLibrary.wakeUp();
48
        }
49
        
50
        public void start() {
51
                this.setUp();
52
                this.testStack();
53
        }
54
        
55
        public void setUp() {
56
                System.err.println("TestReadBlockMrSID running...");
57
                try {
58
                        f1 = RasterDataset.open(null, path1);
59
                } catch (NotSupportedExtensionException e1) {
60
                        e1.printStackTrace();
61
                } catch (RasterDriverException e1) {
62
                        e1.printStackTrace();
63
                }
64
        }
65
        
66
        public void testStack() {
67
                BufferFactory bf = new BufferFactory(f1);
68
                bf.setAllDrawableBands();
69
                bf.setAreaOfInterest(f1.getExtent().getMin().getX(), f1.getExtent().getMax().getY(), f1.getExtent().width(), f1.getExtent().height());
70
                IBuffer buf1 = bf.getRasterBuf();
71
                
72
                int block = 100;
73
                int nblocks = (int)Math.ceil(f1.getHeight() / block);
74
                try {
75
                        int line = 0;
76
                        int initBand = 0;
77
                        int column = 0;
78
                        for (int i = 0; i < nblocks; i++) {
79
                                byte[][][] buf = (byte[][][])f1.readBlock(i * block, block);
80
                                initBand = i * block;
81
                                for (int band = 0; band < buf.length; band++) {
82
                                        line = initBand;
83
                                        for (int row = 0; row < buf[band].length; row++) {
84
                                                column = 0;
85
                                                for (int col = 0; col < buf[band][row].length; col++) {
86
                                                        //try {
87
                                                        assertEquals(buf[band][row][col], buf1.getElemByte(line, column, band));
88
                                                        /*} catch (AssertionFailedError e) {
89
                                                                System.out.println(band + " " + line + " " + column);
90
                                                                
91
                                                        }*/
92
                                                        column ++;
93
                                                }
94
                                                line ++;
95
                                        }
96
                                        
97
                                }
98
                        }
99
                } catch (InvalidSetViewException e) {
100
                        e.printStackTrace();
101
                } catch (FileNotOpenException e) {
102
                        e.printStackTrace();
103
                } catch (RasterDriverException e) {
104
                        e.printStackTrace();
105
                }        
106
                
107
        }
108

    
109
}