gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / test / impl / stripecache / horizontal / TestCreateBand.java @ 1965
History | View | Annotate | Download (2.71 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import junit.framework.TestCase; |
6 |
|
7 |
import org.gvsig.jgdal.GdalException; |
8 |
import org.gvsig.raster.cache.buffer.Band; |
9 |
import org.gvsig.raster.cache.buffer.Buffer; |
10 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
11 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
12 |
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl; |
13 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
14 |
|
15 |
/**
|
16 |
* This test add a band in a raster of 3 bands. As a result of this test a raster
|
17 |
* of four bands is created and saved in the hard disk. The value of additional band
|
18 |
* is zero in all its elements. Finally it gets the band added and compare each values
|
19 |
* with 0.
|
20 |
*
|
21 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
22 |
*/
|
23 |
public class TestCreateBand extends TestCase { |
24 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
25 |
|
26 |
public void start() { |
27 |
this.setUp();
|
28 |
this.testStack();
|
29 |
} |
30 |
|
31 |
public void setUp() { |
32 |
System.err.println("StripeCache TestCreateBand running..."); |
33 |
} |
34 |
|
35 |
public void testStack() { |
36 |
long t1 = System.currentTimeMillis(); |
37 |
GdalRead input = null;
|
38 |
try {
|
39 |
//Reducimos el tama?o de la cache para una prueba con menos datos
|
40 |
BufferCacheManagerImpl.cacheSize = 2;
|
41 |
BufferCacheManagerImpl.pageSize = 0.2;
|
42 |
|
43 |
//Read input data
|
44 |
input = new GdalRead(rasterIn);
|
45 |
Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight()); |
46 |
|
47 |
//Create Buffer
|
48 |
Buffer buf = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
49 |
input.getWidth(), |
50 |
input.getHeight(), |
51 |
input.getBandCount()); |
52 |
|
53 |
//Set data to buffer
|
54 |
setLines(dataIn, buf); |
55 |
Band rb = buf.createBand((byte)100); |
56 |
|
57 |
for (int i = 0; i < rb.getHeight(); i++) { |
58 |
for (int j = 0; j < rb.getWidth(); j++) { |
59 |
byte b = rb.getElemByte(i, j);
|
60 |
assertEquals((byte)100, b); |
61 |
} |
62 |
} |
63 |
|
64 |
buf.free(); |
65 |
} catch (GdalException e) {
|
66 |
e.printStackTrace(); |
67 |
} catch (IOException e) { |
68 |
e.printStackTrace(); |
69 |
} catch (ProcessInterruptedException e) {
|
70 |
e.printStackTrace(); |
71 |
} catch (OperationNotSupportedException e) { |
72 |
e.printStackTrace(); |
73 |
} |
74 |
long t2 = System.currentTimeMillis(); |
75 |
System.out.println("Tiempo StripeCache TestCreateBand: " + (t2 - t1) + " milisegundos"); |
76 |
} |
77 |
|
78 |
private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
79 |
if(dataIn instanceof byte[][][]) { |
80 |
byte[][][] d = (byte[][][])dataIn; |
81 |
for (int iBand = 0; iBand < d.length; iBand++) { |
82 |
for (int row = 0; row < d[iBand].length; row++) { |
83 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
84 |
} |
85 |
} |
86 |
} |
87 |
} |
88 |
|
89 |
} |