Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.main / src / test / java / org / gvsig / fmap / dal / coverage / buffer / cache / TestSaveAndLoadPages.java @ 2443

History | View | Annotate | Download (4.65 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.coverage.buffer.cache;
23

    
24
import java.io.IOException;
25
import java.util.Date;
26

    
27
import org.gvsig.fmap.dal.coverage.BaseTestCase;
28
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
29
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
30
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
31
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
32
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
33
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
34
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
35
import org.gvsig.raster.impl.buffer.cache.CacheDataServer;
36
import org.gvsig.raster.impl.buffer.cache.PageBandBuffer;
37
/**
38
 * @author Nacho Brodin (nachobrodin@gmail.com)
39
 */
40
public class TestSaveAndLoadPages extends BaseTestCase {
41
        private boolean            show    = false;
42
        private String             path    = baseDir + "03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg";
43
        private RasterDataStore   f       = null;        
44
        private RasterQuery        query   = null;
45
        protected Buffer           raster  = null;
46
        private int                pages   = 10;
47
        
48
    public void start() throws Exception {
49
                this.setUp();
50
                this.testStack();
51
        }
52
        
53
    @Override
54
    protected void doSetUp() throws Exception {
55
                System.err.println("TestSaveAndLoadPages running...");
56
                
57
                try {
58
                        super.doSetUp();
59
                } catch (Exception e) {
60
                        e.printStackTrace();
61
                }
62
                
63
                try {
64
                        f = manager.open(path);
65
                } catch (NotSupportedExtensionException e) {
66
                        e.printStackTrace();
67
                } catch (RasterDriverException e) {
68
                        e.printStackTrace();
69
                }
70
        }
71
        
72
        public void testStack() {
73
                int[] drawableBands = {0, 1, 2};
74
                
75
                query = manager.createQuery();
76
                query.setDrawableBands(drawableBands);
77
                try {
78
                        query.setAreaOfInterest(0, 0, (int)f.getWidth(), (int)f.getHeight());
79
                        raster = f.query(query);
80
                } catch (InvalidSetViewException e1) {
81
                        e1.printStackTrace();
82
                } catch (ProcessInterruptedException e) {
83
                        e.printStackTrace();
84
                } catch (RasterDriverException e) {
85
                        e.printStackTrace();
86
                }
87
                
88
                int h =  (int)f.getHeight() / pages;
89
                PageBandBuffer[] pbWriterList = new PageBandBuffer[h];
90
                CacheDataServer[] cds = new CacheDataServer[h];
91
                                
92
                long t2, t3, t4;
93
                                long t1 = new Date().getTime();
94
                                
95
                //Salvamos los PageBuffer
96
                byte[] data = new byte[3];
97
                for (int i = 0; i < pages; i++) {
98
                        pbWriterList[i] = new PageBandBuffer((int)f.getDataType()[0], (int)f.getWidth(), h, 3, true, i);
99
                        cds[i] = new CacheDataServer(null, 0, i);
100
                        for (int k = 0; k < f.getWidth(); k++) {
101
                                for (int j = 0; j < h; j++) {
102
                                        raster.getElemByte((i * h) + j, k, data);
103
                                        pbWriterList[i].setElemByte(j, k, data);
104
                                }        
105
                        }
106
                        try {
107
                                cds[i].savePage(pbWriterList[i]);
108
                        } catch (IOException e) {
109
                                e.printStackTrace();
110
                        }
111
                }
112
                
113
                t2 = new Date().getTime();
114
                if (show)
115
                        System.out.println("Time: Cargar PageBuffers y salvar a disco: " + ((t2 - t1) / 1000D) + ", secs.");
116
                
117
                //Recuperamos las p?ginas
118
                PageBandBuffer[] pbReaderList = new PageBandBuffer[h];
119
                for (int i = 0; i < pages; i++) {
120
                        pbReaderList[i] = new PageBandBuffer((int)f.getDataType()[0], (int)f.getWidth(), h, 3, true, i);
121
                        cds[i].loadPage(pbReaderList[i]);
122
                }
123
                
124
                t3 = new Date().getTime();
125
                if (show)
126
                        System.out.println("Time: Recuperar p?ginas de disco: " + ((t3 - t2) / 1000D) + ", secs.");
127
                
128
                //Comparamos
129
                byte[] a = new byte[3];
130
                byte[] b = new byte[3];
131
                for (int i = 0; i < pages; i++) {
132
                        for (int k = 0; k < f.getWidth(); k++) {
133
                                for (int j = 0; j < h; j++) {
134
                                        pbReaderList[i].getElemByte(j, k, a);
135
                                        pbWriterList[i].getElemByte(j, k, b);
136
                                        for (int t = 0; t < 3; t++) 
137
                                                assertEquals(a[t], b[t]);
138
                                }
139
                        }
140
                }
141

    
142
                t4 = new Date().getTime();
143
                if (show)
144
                        System.out.println("Time: Comparaciones: " + ((t4 - t3) / 1000D) + ", secs.");
145
        }
146
}