gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.main / src / test / java / org / gvsig / fmap / dal / coverage / buffer / cache / TestAssignInterchangeBandsCache.java @ 2443
History | View | Annotate | Download (3.06 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 org.gvsig.fmap.dal.coverage.BaseTestCase; |
25 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
26 |
import org.gvsig.raster.impl.buffer.cache.RasterCache; |
27 |
/**
|
28 |
* Test para probar la operaci?n de asignar una constante a una banda de un buffer cacheado y
|
29 |
* el intercambio de 2 bandas para el mismo buffer. Con esto se prueban las operaciones de assign, getBand,
|
30 |
* assignBand, assignBandToNotValid, interchangeBands y getBandBuffer
|
31 |
*
|
32 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
33 |
*/
|
34 |
public class TestAssignInterchangeBandsCache extends BaseTestCase { |
35 |
|
36 |
private RasterCache rc = null; |
37 |
|
38 |
public void start() throws Exception { |
39 |
this.setUp();
|
40 |
this.testStack();
|
41 |
} |
42 |
|
43 |
@Override
|
44 |
protected void doSetUp() throws Exception { |
45 |
try {
|
46 |
super.doSetUp();
|
47 |
} catch (Exception e) { |
48 |
e.printStackTrace(); |
49 |
} |
50 |
System.err.println("TestBandOperationCache running..."); |
51 |
rc = new RasterCache(Buffer.TYPE_BYTE, 6000, 5000, 3); |
52 |
} |
53 |
|
54 |
public void testStack() { |
55 |
// long t2, t3, t4;
|
56 |
// long t1 = new Date().getTime();
|
57 |
rc.setNotValidValue(40);
|
58 |
rc.assign(0, (byte) 20); |
59 |
rc.assign(1, (byte) 30); |
60 |
rc.assignBandToNotValid(2);
|
61 |
// t2 = new Date().getTime();
|
62 |
// System.out.println("Time: asignar buffer a un valor cte: " + ((t2 - t1) / 1000D) + ", secs.");
|
63 |
|
64 |
rc.interchangeBands(0, 1); |
65 |
testValues(30, 20, 40); |
66 |
|
67 |
// t3 = new Date().getTime();
|
68 |
// System.out.println("Time: asserts del valor por banda cacheado: " + ((t3 - t2) / 1000D) + ", secs.");
|
69 |
|
70 |
Buffer buf = rc.getBandBuffer(2); |
71 |
testValue((int) rc.getNotValidValue(), buf);
|
72 |
|
73 |
// t4 = new Date().getTime();
|
74 |
// System.out.println("Time: getBandBuffer: " + ((t4 - t3) / 1000D) + ", secs.");
|
75 |
} |
76 |
|
77 |
private void testValues(int v1, int v2, int v3) { |
78 |
for (int row = 0; row < rc.getHeight(); row++) |
79 |
for (int col = 0; col < rc.getWidth(); col++) { |
80 |
assertEquals(v1, rc.getElemByte(row, col, 0));
|
81 |
assertEquals(v2, rc.getElemByte(row, col, 1));
|
82 |
assertEquals(v3, rc.getElemByte(row, col, 2));
|
83 |
} |
84 |
} |
85 |
|
86 |
private void testValue(int value, Buffer buf) { |
87 |
for (int row = 0; row < buf.getHeight(); row++) |
88 |
for (int col = 0; col < buf.getWidth(); col++) |
89 |
assertEquals(value, buf.getElemByte(row, col, 0));
|
90 |
} |
91 |
} |