Revision 9934

View differences:

org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/TestInterpolationBSplineIncrease.java
1
package org.gvsig.raster.cache.buffer.impl;
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.Buffer;
9
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
10
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
11
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
12
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
13
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
14

  
15
/**
16
 * Copy the band 0 from a buffer over the band 2 in the same buffer using the
17
 * method getBandCopy.  
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestInterpolationBSplineIncrease extends TestCase {
21
	private String         rasterIn  = "./src/test/resources/image/001m09_1_0.tif";
22
	private String         rasterOut = "/tmp/out-interpBSpline.tif";
23
	private static int     REL       = 2;
24
	
25
	public void start() {
26
		this.setUp();
27
		this.testStack();
28
	}
29

  
30
	public void setUp() {
31
		System.err.println("TestInterpolationBSpline running...");
32
	}
33
	
34
	public void testStack() {
35
		long t1 = System.currentTimeMillis();
36
		GdalRead input = null;
37
		GdalWrite out = null;
38
		try {
39
			//Read input data
40
			input = new GdalRead(rasterIn);
41
			int readSize = 10;
42
			Object dataIn = input.readBlock(0, 0, readSize, readSize);
43
			
44
			//Create Buffer
45
			Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
46
														readSize, 
47
														readSize,
48
														input.getBandCount(),
49
														true);
50
			
51
			//Set data to buffer
52
			setLines(dataIn, buf1);
53
			Buffer buf = buf1.getAdjustedWindow(readSize * REL, readSize * REL, BufferInterpolationImpl.INTERPOLATION_BSpline);
54
						
55
			//Write output file 
56
			out = new GdalWrite(rasterOut, 3, input.getDataType(), buf.getWidth(), buf.getHeight(), GdalWrite.COLOR_INTERP_RGB);
57
			out.writeBands(buf.getBands());
58
			out.close();	
59
			
60
			buf1.free();
61
		} catch (GdalException e) {
62
			e.printStackTrace();
63
		} catch (IOException e) {
64
			e.printStackTrace();
65
		} catch (ProcessInterruptedException e) {
66
			e.printStackTrace();
67
		} catch (OperationNotSupportedException e) {
68
			e.printStackTrace();
69
		}
70
		long t2 = System.currentTimeMillis();
71
		System.out.println("Tiempo TestInterpolationBSpline: " + (t2 - t1) + " milisegundos");
72
	}
73
	
74
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
75
		if(dataIn instanceof byte[][][]) {
76
    		byte[][][] d = (byte[][][])dataIn;
77
    		for (int iBand = 0; iBand < d.length; iBand++) {
78
				for (int row = 0; row < d[iBand].length; row++) {
79
					buf.setLineInBandByte(d[iBand][row], row, iBand);
80
				}
81
			}
82
    	}
83
	}
84
	
85
}
86

  
0 87

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/TestInterpolationBSplineReduction.java
1
package org.gvsig.raster.cache.buffer.impl;
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.Buffer;
9
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
10
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
11
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
12
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
13
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
14

  
15
/**
16
 * Copy the band 0 from a buffer over the band 2 in the same buffer using the
17
 * method getBandCopy.  
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestInterpolationBSplineReduction extends TestCase {
21
	private String         rasterIn  = "./src/test/resources/image/001m09_1_0.tif";
22
	private String         rasterOut = "/tmp/out-interpBSplineReduction.tif";
23
	private static int     REL       = 5;
24
	
25
	public void start() {
26
		this.setUp();
27
		this.testStack();
28
	}
29

  
30
	public void setUp() {
31
		System.err.println("TestInterpolationBSplineReduction running...");
32
	}
33
	
34
	public void testStack() {
35
		long t1 = System.currentTimeMillis();
36
		GdalRead input = null;
37
		GdalWrite out = null;
38
		try {
39
			//Read input data
40
			input = new GdalRead(rasterIn);
41
			Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
42
						
43
			//Create Buffer
44
			Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
45
														input.getWidth(), 
46
														input.getHeight(),
47
														input.getBandCount(),
48
														true);
49
			
50
			//Set data to buffer
51
			setLines(dataIn, buf1);
52
			Buffer buf = buf1.getAdjustedWindow(input.getWidth() / REL, input.getHeight() / REL, BufferInterpolationImpl.INTERPOLATION_BSpline);
53
						
54
			//Write output file 
55
			out = new GdalWrite(rasterOut, 3, input.getDataType(), buf.getWidth(), buf.getHeight(), GdalWrite.COLOR_INTERP_RGB);
56
			out.writeBands(buf.getBands());
57
			out.close();	
58
			
59
			buf1.free();
60
		} catch (GdalException e) {
61
			e.printStackTrace();
62
		} catch (IOException e) {
63
			e.printStackTrace();
64
		} catch (ProcessInterruptedException e) {
65
			e.printStackTrace();
66
		} catch (OperationNotSupportedException e) {
67
			e.printStackTrace();
68
		}
69
		long t2 = System.currentTimeMillis();
70
		System.out.println("Tiempo TestInterpolationBSplineReduction: " + (t2 - t1) + " milisegundos");
71
	}
72
	
73
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
74
		if(dataIn instanceof byte[][][]) {
75
    		byte[][][] d = (byte[][][])dataIn;
76
    		for (int iBand = 0; iBand < d.length; iBand++) {
77
				for (int row = 0; row < d[iBand].length; row++) {
78
					buf.setLineInBandByte(d[iBand][row], row, iBand);
79
				}
80
			}
81
    	}
82
	}
83
	
84
}
85

  
0 86

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/TestInterpolationBicubicIncrease.java
1
package org.gvsig.raster.cache.buffer.impl;
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.Buffer;
9
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
10
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
11
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
12
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
13
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
14

  
15
/**
16
 * Copy the band 0 from a buffer over the band 2 in the same buffer using the
17
 * method getBandCopy.  
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestInterpolationBicubicIncrease extends TestCase {
21
	private String         rasterIn  = "./src/test/resources/image/001m09_1_0.tif";
22
	private String         rasterOut = "/tmp/out-interpBicubic.tif";
23
	private static int     REL       = 2;
24
	
25
	public void start() {
26
		this.setUp();
27
		this.testStack();
28
	}
29

  
30
	public void setUp() {
31
		System.err.println("TestInterpolationBicubic running...");
32
	}
33
	
34
	public void testStack() {
35
		long t1 = System.currentTimeMillis();
36
		GdalRead input = null;
37
		GdalWrite out = null;
38
		try {
39
			//Read input data
40
			input = new GdalRead(rasterIn);
41
			int readSize = 10;
42
			Object dataIn = input.readBlock(0, 0, readSize, readSize);
43
			
44
			//Create Buffer
45
			Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
46
														readSize, 
47
														readSize,
48
														input.getBandCount(),
49
														true);
50
			
51
			//Set data to buffer
52
			setLines(dataIn, buf1);
53
			Buffer buf = buf1.getAdjustedWindow(readSize * REL, readSize * REL, BufferInterpolationImpl.INTERPOLATION_Bicubic);
54
						
55
			//Write output file 
56
			out = new GdalWrite(rasterOut, 3, input.getDataType(), buf.getWidth(), buf.getHeight(), GdalWrite.COLOR_INTERP_RGB);
57
			out.writeBands(buf.getBands());
58
			out.close();	
59
			
60
			buf1.free();
61
		} catch (GdalException e) {
62
			e.printStackTrace();
63
		} catch (IOException e) {
64
			e.printStackTrace();
65
		} catch (ProcessInterruptedException e) {
66
			e.printStackTrace();
67
		} catch (OperationNotSupportedException e) {
68
			e.printStackTrace();
69
		}
70
		long t2 = System.currentTimeMillis();
71
		System.out.println("Tiempo TestInterpolationBicubic: " + (t2 - t1) + " milisegundos");
72
	}
73
	
74
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
75
		if(dataIn instanceof byte[][][]) {
76
    		byte[][][] d = (byte[][][])dataIn;
77
    		for (int iBand = 0; iBand < d.length; iBand++) {
78
				for (int row = 0; row < d[iBand].length; row++) {
79
					buf.setLineInBandByte(d[iBand][row], row, iBand);
80
				}
81
			}
82
    	}
83
	}
84
	
85
}
86

  
0 87

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/TestInterpolationNearestIncrease.java
1
package org.gvsig.raster.cache.buffer.impl;
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.Buffer;
9
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
10
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
11
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
12
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
13
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
14

  
15
/**
16
 * Copy the band 0 from a buffer over the band 2 in the same buffer using the
17
 * method getBandCopy.  
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestInterpolationNearestIncrease extends TestCase {
21
	private String         rasterIn  = "./src/test/resources/image/001m09_1_0.tif";
22
	private String         rasterOut = "/tmp/out-interpNearest.tif";
23
	private static int     REL       = 2;
24
	
25
	public void start() {
26
		this.setUp();
27
		this.testStack();
28
	}
29

  
30
	public void setUp() {
31
		System.err.println("MemoryBuffer TestCopyBand running...");
32
	}
33
	
34
	public void testStack() {
35
		long t1 = System.currentTimeMillis();
36
		GdalRead input = null;
37
		GdalWrite out = null;
38
		try {
39
			//Read input data
40
			input = new GdalRead(rasterIn);
41
			int readSize = 10;
42
			Object dataIn = input.readBlock(0, 0, readSize, readSize);
43
						
44
			//Create Buffer
45
			Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
46
														readSize, 
47
														readSize,
48
														input.getBandCount(),
49
														true);
50
			
51
			//Set data to buffer
52
			setLines(dataIn, buf1);
53
			Buffer buf = buf1.getAdjustedWindow(readSize * REL, readSize * REL, BufferInterpolationImpl.INTERPOLATION_NearestNeighbour);
54
						
55
			//Write output file 
56
			out = new GdalWrite(rasterOut, 3, input.getDataType(), buf.getWidth(), buf.getHeight(), GdalWrite.COLOR_INTERP_RGB);
57
			out.writeBands(buf.getBands());
58
			out.close();	
59
			
60
			buf1.free();
61
		} catch (GdalException e) {
62
			e.printStackTrace();
63
		} catch (IOException e) {
64
			e.printStackTrace();
65
		} catch (ProcessInterruptedException e) {
66
			e.printStackTrace();
67
		} catch (OperationNotSupportedException e) {
68
			e.printStackTrace();
69
		}
70
		long t2 = System.currentTimeMillis();
71
		System.out.println("Tiempo MemoryBuffer TestCopyBand: " + (t2 - t1) + " milisegundos");
72
	}
73
	
74
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
75
		if(dataIn instanceof byte[][][]) {
76
    		byte[][][] d = (byte[][][])dataIn;
77
    		for (int iBand = 0; iBand < d.length; iBand++) {
78
				for (int row = 0; row < d[iBand].length; row++) {
79
					buf.setLineInBandByte(d[iBand][row], row, iBand);
80
				}
81
			}
82
    	}
83
	}
84
	
85
}
86

  
0 87

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/others/ArrayVsArrayList.java
1
package org.gvsig.raster.cache.buffer.impl.others;
2

  
3
import java.util.ArrayList;
4

  
5
import org.gvsig.raster.cache.buffer.PxTile;
6
import org.gvsig.raster.cache.buffer.impl.PxTileImpl;
7
import org.gvsig.raster.cache.buffer.impl.rocache.ByteBand;
8
import org.gvsig.raster.cache.buffer.impl.rocache.ReadOnlyCacheBand;
9

  
10
/**
11
 * This test compare the access time of an element in two cases. The first
12
 * case is the access to an element in a simple array of objects. The second
13
 * case is the access to an element in an ArrayList.
14
 *  
15
 * @author Nacho Brodin (nachobrodin@gmail.com)
16
 *
17
 */
18
public class ArrayVsArrayList {
19
	public static int N = 500000;
20
	/**
21
	 * @param args
22
	 */
23
	public static void main(String[] args) {
24
		ArrayVsArrayList p = new ArrayVsArrayList();
25
		p.array();
26
		p.arrayList();
27
	}
28
	
29
	private void array() {
30
		long t1 = System.currentTimeMillis();
31
		ArrayList<PxTile> stripeList = new ArrayList<PxTile>();
32
		for (int i = 0; i < 1; i++) 
33
			stripeList.add(new PxTileImpl(0, 0, 0, 0));
34
		
35
		ReadOnlyCacheBand[] l = new ReadOnlyCacheBand[N];
36
		for (int i = 0; i < N; i++) {
37
			ByteBand b =  new ByteBand(stripeList, null, 15, 15, 15, 2345, 3244);
38
			l[i] = b;
39
		}
40
		int z = 0;
41
		for (int i = 0; i < N; i++) {
42
			int y = l[i].getBandNumber();
43
			z += y;
44
		}
45
		long t2 = System.currentTimeMillis();
46
		System.out.println("Time Array with " + N + " elements: " + (t2 - t1) + " milisegundos" + z);
47
		
48
	}
49
	
50
	private void arrayList() {
51
		long t1 = System.currentTimeMillis();
52
		ArrayList<PxTile> stripeList = new ArrayList<PxTile>();
53
		for (int i = 0; i < 1; i++) 
54
			stripeList.add(new PxTileImpl(0, 0, 0, 0));
55
		
56
		ArrayList<ReadOnlyCacheBand> l = new ArrayList<ReadOnlyCacheBand>();
57
		for (int i = 0; i < N; i++) {
58
			ByteBand b =  new ByteBand(stripeList, null, 15, 15, 15, 2345, 3244);
59
			l.add(b);
60
		}
61
		int z = 0;
62
		for (int i = 0; i < N; i++) {
63
			int y = l.get(i).getBandNumber();
64
			z += y;
65
		}
66
		long t2 = System.currentTimeMillis();
67
		System.out.println("Time ArrayList with " + N + " elements: " + (t2 - t1) + " milisegundos" + z);
68
	}
69

  
70
}
0 71

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/others/TestCacheVsMemory.java
1
package org.gvsig.raster.cache.buffer.impl.others;
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.Buffer;
9
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
10
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
11
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl;
12
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
13
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
14
import org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.RasterCacheBuffer;
15

  
16
/**
17
 * Performance Test: It loads a complete image of 65MB in a cached buffer and after read the
18
 * same image in a memory buffer. For this test we use a small size of cache (2MB) and a size of
19
 * one page of 0.2MB
20
 *  
21
 * REPEAT = 1
22
 * Using setValues
23
 * Time cached: 1538 ms
24
 * Time memory: 1163 ms
25
 * 
26
 * REPEAT = 1
27
 * Using setLines
28
 * Time cached: 198 ms
29
 * Time memory: 171 ms
30
 *
31
 * REPEAT = 10
32
 * Using setValues
33
 * Time cached: 14317 ms
34
 * Time memory: 11168 ms
35
 * 
36
 * REPEAT = 10
37
 * Using setLines
38
 * Time cached: 1944 ms
39
 * Time memory: 1209 ms
40
 * 
41
 * Intel(R) Core(TM)2 CPU E8400  @ 3.00GHz
42
 * 2GB RAM DDR3 1066
43
 * HDD ATA 133
44
 * Linux Ubuntu 10.04 kernel 2.6.24
45
 * 
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 */
48
public class TestCacheVsMemory extends TestCase {
49
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
50
	private static int REPEAT = 10;
51
	
52
	public void start() {
53
		this.setUp();
54
		this.testStack();
55
	}
56

  
57
	public void setUp() {
58
		System.err.println("CacheVsMemory running...");
59
	}
60
	
61
	public void testStack() {
62
		
63
		try {
64
			GdalRead input = null;
65
			//Read input data
66
			input = new GdalRead(rasterIn);
67
			Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
68
			
69
			
70
			//Reducimos el tama?o de la cache para una prueba con menos datos
71
			BufferCacheManagerImpl.cacheSize = 25;
72
			BufferCacheManagerImpl.pageSize = 2;
73
		
74
			//****************CACHE**********************
75
			long t1 = System.currentTimeMillis();
76
			for (int iTimes = 0; iTimes < REPEAT; iTimes++) {
77

  
78
				//Create Buffer
79
				Buffer buf1 = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
80
						input.getWidth(), 
81
						input.getHeight(),
82
						input.getBandCount());
83

  
84
				//Set data to buffer
85
				setValues(dataIn, buf1);
86
				buf1.free();
87
			}
88
			
89
			long t2 = System.currentTimeMillis();
90
			System.out.println("Tiempo StripeCache : " + (t2 - t1) + " milisegundos");
91
			//****************FIN CACHE******************
92
			
93
			//****************MEMO***********************
94
			t1 = System.currentTimeMillis();
95
			for (int iTimes = 0; iTimes < REPEAT; iTimes++) {
96

  
97
				//Create Buffer
98
				Buffer buf2 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
99
						input.getWidth(), 
100
						input.getHeight(),
101
						input.getBandCount(),
102
						true);
103

  
104
				//Set data to buffer
105
				setValues(dataIn, buf2);
106
				buf2.free();
107
			}
108
			
109
			t2 = System.currentTimeMillis();
110
			System.out.println("Tiempo Memoria : " + (t2 - t1) + " milisegundos");
111
			//****************FIN MEMO******************
112
			
113
			input.close();
114
		} catch (GdalException e) {
115
			e.printStackTrace();
116
		} catch (IOException e) {
117
			e.printStackTrace();
118
		} catch (ProcessInterruptedException e) {
119
			e.printStackTrace();
120
		} catch (OperationNotSupportedException e) {
121
			e.printStackTrace();
122
		}
123
		
124
		
125
	}
126
	
127
	public void setValues(Object dataIn, Buffer buf) throws OperationNotSupportedException {
128
		if(dataIn instanceof byte[][][]) {
129
    		byte[][][] d = (byte[][][])dataIn;
130
    		for (int band = 0; band < d.length; band++) {
131
				for (int row = 0; row < d[band].length; row++) {
132
					for (int col = 0; col < d[band][row].length; col++) {
133
						buf.setElem(row, col, band, (byte)d[band][row][col]);
134
					}
135
				}
136
			}
137
    	}
138
	}
139
	
140
	public void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
141
		if(dataIn instanceof byte[][][]) {
142
    		byte[][][] d = (byte[][][])dataIn;
143
    		for (int iBand = 0; iBand < d.length; iBand++) {
144
				for (int row = 0; row < d[iBand].length; row++) {
145
					buf.setLineInBandByte(d[iBand][row], row, iBand);
146
				}
147
			}
148
    	}
149
	}
150
	
151
}
0 152

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestMultifile.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
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.Buffer;
9
import org.gvsig.raster.cache.buffer.BufferDataSource;
10
import org.gvsig.raster.cache.buffer.BufferParam;
11
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
12
import org.gvsig.raster.cache.buffer.impl.BufferParamImpl;
13
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
14
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
15
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
16

  
17
/**
18
 * This test gets bands from a raster with the method getBufferWithOneBand() and compare
19
 * each band from original source with obtained bands 
20
 * @author Nacho Brodin (nachobrodin@gmail.com)
21
 */
22
public class TestMultifile extends TestCase {
23
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
24
	private String rasterOut1 = "/tmp/out-b1.tif";
25
	private String rasterOut2 = "/tmp/out-b2.tif";
26
	private String rasterOut3 = "/tmp/out-b3.tif";
27
	private int    x      = 200;
28
	private int    y      = 200;
29
	private int    w      = 800;
30
	private int    h      = 800;
31
	
32
	public void start() {
33
		this.setUp();
34
		this.testStack();
35
	}
36

  
37
	public void setUp() {
38
		System.err.println("ROCache TestGetBufferWithOneBand running...");
39
	}
40
	
41
	public void testStack() {
42
		long t1 = System.currentTimeMillis();
43
		GdalRead input = null;
44
		try {
45
			//Read input data
46
			input = new GdalRead(rasterIn);
47
			
48
			BufferDataSource ds = null;
49
			try {
50
				ds = new BufferDataSourceImpl(rasterIn);
51
			} catch (IOException e) {
52
				e.printStackTrace();
53
			}
54
			Buffer buf = new RasterReadOnlyBuffer(ds);
55
						
56
			Buffer b0 = buf.getBufferWithOneBand(0);
57
			Buffer b1 = buf.getBufferWithOneBand(1);
58
			Buffer b2 = buf.getBufferWithOneBand(2);
59
			
60
			//Write output file 
61
			GdalWrite out1 = new GdalWrite(rasterOut1, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
62
			out1.writeBands(b0.getBands());
63
			out1.close();
64
			
65
			GdalWrite out2 = new GdalWrite(rasterOut2, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
66
			out2.writeBands(b1.getBands());
67
			out2.close();
68
			
69
			GdalWrite out3 = new GdalWrite(rasterOut3, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
70
			out3.writeBands(b2.getBands());
71
			out3.close();
72
			
73
			BufferParam params = new BufferParamImpl(
74
					new String[]{rasterOut1, rasterOut2, rasterOut3}, 
75
					x, y, w, h, null);
76
			RasterReadOnlyBuffer multiband = new RasterReadOnlyBuffer(params);
77
						
78
			for (int row = 0; row < multiband.getHeight(); row++) {
79
				for (int col = 0; col < multiband.getWidth(); col++) {
80
					byte b_0 = multiband.getElemByte(row, col, 0);
81
					byte b_1 = multiband.getElemByte(row, col, 1);
82
					byte b_2 = multiband.getElemByte(row, col, 2);
83
					assertEquals(b_0, b0.getElemByte(row + y, col + x, 0));
84
					assertEquals(b_1, b1.getElemByte(row + y, col + x, 0));
85
					assertEquals(b_2, b2.getElemByte(row + y, col + x, 0));
86
				}
87
			}
88
						
89
			b0.free();
90
			b1.free();
91
			b2.free();
92
			buf.free();
93
				
94
		} catch (GdalException e) {
95
			e.printStackTrace();
96
		} catch (IOException e) {
97
			e.printStackTrace();
98
		} catch (OperationNotSupportedException e) {
99
			e.printStackTrace();
100
		}
101
		long t2 = System.currentTimeMillis();
102
		System.out.println("Tiempo ROCache TestGetBufferWithOneBand: " + (t2 - t1) + " milisegundos");
103
	}
104
	
105
}
0 106

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/AllTests.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
2

  
3
import junit.framework.Test;
4
import junit.framework.TestSuite;
5

  
6
public class AllTests {
7

  
8
	public static Test suite() {
9
		TestSuite suite = new TestSuite("Test for org.fv.raster.buffer.rocache");
10
		//$JUnit-BEGIN$
11
		suite.addTestSuite(TestReplicateBand.class);
12
		suite.addTestSuite(TestSwapBands.class);
13
		suite.addTestSuite(TestReadTiffAndCompareData.class);
14
		suite.addTestSuite(TestSwapTwoBands.class);
15
		suite.addTestSuite(TestRemoveBand.class);
16
		suite.addTestSuite(TestGetBufferWithOneBand.class);
17
		suite.addTestSuite(TestReadWindowAndCompareData.class);
18
		suite.addTestSuite(TestAssignBand.class);
19
		suite.addTestSuite(TestCopyBand.class);
20
		suite.addTestSuite(TestAddBand.class);
21
		suite.addTestSuite(TestWindow.class);
22
		//$JUnit-END$
23
		return suite;
24
	}
25

  
26
}
0 27

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestGetBufferWithOneBand.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
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.Buffer;
9
import org.gvsig.raster.cache.buffer.BufferDataSource;
10
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
11
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
12
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
13
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
14

  
15
/**
16
 * This test gets bands from a raster with the method getBufferWithOneBand() and compare
17
 * each band from original source with obtained bands 
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestGetBufferWithOneBand extends TestCase {
21
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
22
	private String rasterOut1 = "/tmp/out-b1.tif";
23
	private String rasterOut2 = "/tmp/out-b2.tif";
24
	private String rasterOut3 = "/tmp/out-b3.tif";
25
	
26
	public void start() {
27
		this.setUp();
28
		this.testStack();
29
	}
30

  
31
	public void setUp() {
32
		System.err.println("ROCache TestGetBufferWithOneBand running...");
33
	}
34
	
35
	public void testStack() {
36
		long t1 = System.currentTimeMillis();
37
		GdalRead input = null;
38
		try {
39
			//Read input data
40
			input = new GdalRead(rasterIn);
41
			
42
			BufferDataSource ds = null;
43
			try {
44
				ds = new BufferDataSourceImpl(rasterIn);
45
			} catch (IOException e) {
46
				e.printStackTrace();
47
			}
48
			Buffer buf = new RasterReadOnlyBuffer(ds);
49
						
50
			Buffer b0 = buf.getBufferWithOneBand(0);
51
			Buffer b1 = buf.getBufferWithOneBand(1);
52
			Buffer b2 = buf.getBufferWithOneBand(2);
53
			
54
			//Write output file 
55
			GdalWrite out1 = new GdalWrite(rasterOut1, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
56
			out1.writeBands(b0.getBands());
57
			out1.close();
58
			
59
			GdalWrite out2 = new GdalWrite(rasterOut2, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
60
			out2.writeBands(b1.getBands());
61
			out2.close();
62
			
63
			GdalWrite out3 = new GdalWrite(rasterOut3, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
64
			out3.writeBands(b2.getBands());
65
			out3.close();
66
			
67
			for (int row = 0; row < buf.getHeight(); row++) {
68
				for (int col = 0; col < buf.getWidth(); col++) {
69
					byte b_0 = buf.getElemByte(row, col, 0);
70
					byte b_1 = buf.getElemByte(row, col, 1);
71
					byte b_2 = buf.getElemByte(row, col, 2);
72
					assertEquals(b_0, b0.getElemByte(row, col, 0));
73
					assertEquals(b_1, b1.getElemByte(row, col, 0));
74
					assertEquals(b_2, b2.getElemByte(row, col, 0));
75
				}
76
			}
77
			
78
			b0.free();
79
			b1.free();
80
			b2.free();
81
			buf.free();
82
				
83
		} catch (GdalException e) {
84
			e.printStackTrace();
85
		} catch (IOException e) {
86
			e.printStackTrace();
87
		} catch (OperationNotSupportedException e) {
88
			e.printStackTrace();
89
		}
90
		long t2 = System.currentTimeMillis();
91
		System.out.println("Tiempo ROCache TestGetBufferWithOneBand: " + (t2 - t1) + " milisegundos");
92
	}
93
	
94
}
0 95

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestSwapTwoBands.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.gvsig.raster.cache.buffer.Band;
8
import org.gvsig.raster.cache.buffer.Buffer;
9
import org.gvsig.raster.cache.buffer.BufferDataSource;
10
import org.gvsig.raster.cache.buffer.exception.WrongParameterException;
11
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl;
12
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
13

  
14
/**
15
 * This test swap two bands of a raster and save the result in other file.
16
 * Finally it compares the output bands with the input bands.
17
 * 
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestSwapTwoBands extends TestCase {
21
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
22
	
23
	public void start() {
24
		this.setUp();
25
		this.testStack();
26
	}
27

  
28
	public void setUp() {
29
		System.err.println("ROCache TestSwapTwoBands running...");
30
	}
31
	
32
	public void testStack() {
33
		long t1 = System.currentTimeMillis();
34
		try {
35
			//Reducimos el tama?o de la cache para una prueba con menos datos
36
			BufferCacheManagerImpl.cacheSize = 2;
37
			BufferCacheManagerImpl.pageSize = 0.2;
38
			
39
			BufferDataSource ds = null;
40
			try {
41
				ds = new BufferDataSourceImpl(rasterIn);
42
			} catch (IOException e) {
43
				e.printStackTrace();
44
			}
45
						
46
			//Create Buffer
47
			Buffer buf1 = new RasterReadOnlyBuffer(ds);
48

  
49
			Buffer buf2 = new RasterReadOnlyBuffer(ds);
50

  
51
			try {
52
				buf2.swapBands(0, 2);
53
			} catch (WrongParameterException e) {
54
				e.printStackTrace();
55
			}
56
			
57
			Band band1 = buf1.getBand(0);
58
			Band band2 = buf2.getBand(2);
59
			compareBands(band1, band2);
60
			
61
			band1 = buf1.getBand(2);
62
			band2 = buf2.getBand(0);
63
			compareBands(band1, band2);
64
			
65
			band1 = buf1.getBand(1);
66
			band2 = buf2.getBand(1);
67
			compareBands(band1, band2);
68
			
69
			buf1.free();
70
			buf2.free();
71
		} catch (IOException e) {
72
			e.printStackTrace();
73
		}
74
		long t2 = System.currentTimeMillis();
75
		System.out.println("Tiempo ROCache TestSwapTwoBands: " + (t2 - t1) + " milisegundos");
76
	}
77
	
78
	public void compareBands(Band band1, Band band2) {
79
		for (int i = 0; i < band1.getHeight(); i++) {
80
			for (int j = 0; j < band1.getWidth(); j++) {
81
				byte b1 = band1.getElemByte(i, j);
82
				byte b2 = band2.getElemByte(i, j);
83
				assertEquals(b1, b2);
84
			}
85
		}
86
	}
87
		
88
}
0 89

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestAddBand.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.gvsig.raster.cache.buffer.Band;
8
import org.gvsig.raster.cache.buffer.Buffer;
9
import org.gvsig.raster.cache.buffer.BufferDataSource;
10
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
11

  
12
/**
13
 * This test add a band in a raster of 3 bands. As a result of this test a raster
14
 * of four bands is created and saved in the hard disk. The value of additional band
15
 * is zero in all its elements. Finally it gets the band added and compare each values 
16
 * with 0. 
17
 *  
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestAddBand extends TestCase {
21
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
22
	
23
	public void start() {
24
		this.setUp();
25
		this.testStack();
26
	}
27

  
28
	public void setUp() {
29
		System.err.println("ROCache TestAddBand running...");
30
	}
31
	
32
	public void testStack() {
33
		long t1 = System.currentTimeMillis();
34
		try {
35
			//Read input data
36
			
37
			BufferDataSource ds = null;
38
			try {
39
				ds = new BufferDataSourceImpl(rasterIn);
40
			} catch (IOException e) {
41
				e.printStackTrace();
42
			}
43
			Buffer buf = new RasterReadOnlyBuffer(ds);
44
			buf.addBand(1);
45
						
46
			Band band = buf.getBand(1);
47
			for (int i = 0; i < band.getHeight(); i++) {
48
				for (int j = 0; j < band.getWidth(); j++) {
49
					byte b = band.getElemByte(i, j);
50
					assertEquals(0, b);
51
				}
52
			}
53
			
54
			buf.free();
55
		} catch (IOException e) {
56
			e.printStackTrace();
57
		}
58
		long t2 = System.currentTimeMillis();
59
		System.out.println("Tiempo ROCache TestAddBand: " + (t2 - t1) + " milisegundos");
60
	}	
61
}
0 62

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestReplicateBand.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
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.BufferDataSource;
11
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
12
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
13
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
14

  
15
/** 
16
 * This test insert one band at the end of the layer. The data of this new band is a copy 
17
 * of the band in position zero. Finally data of band zero and band three are compared
18
 * checking if both have the same values. 
19
 *  
20
 * @author Nacho Brodin (nachobrodin@gmail.com)
21
 */
22
public class TestReplicateBand extends TestCase {
23
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
24
	private String rasterOut = "/tmp/out-replicateBands.tif";
25
	
26
	public void start() {
27
		this.setUp();
28
		this.testStack();
29
	}
30

  
31
	public void setUp() {
32
		System.err.println("ROCache TestReplicateBand running...");
33
	}
34
	
35
	public void testStack() {
36
		long t1 = System.currentTimeMillis();
37
		GdalRead input1 = null;
38
		GdalWrite out = null;
39
		try {
40
						
41
			//Read input data
42
			input1 = new GdalRead(rasterIn);
43
			BufferDataSource ds = null;
44
			try {
45
				ds = new BufferDataSourceImpl(rasterIn);
46
			} catch (IOException e) {
47
				e.printStackTrace();
48
			}
49
			Buffer buf = new RasterReadOnlyBuffer(ds);
50
						
51
			buf.replicateBand(0, 3);
52
			
53
			//Write output file 
54
			out = new GdalWrite(rasterOut, 4, input1.getDataType(), input1.getWidth(), input1.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
55
			out.writeBands(buf.getBands());
56
			out.close();	
57
			
58
			Band band1 = buf.getBand(0);
59
			Band band2 = buf.getBand(3);
60
			for (int i = 0; i < band1.getHeight(); i++) {
61
				for (int j = 0; j < band1.getWidth(); j++) {
62
					byte b1 = band1.getElemByte(i, j);
63
					byte b2 = band2.getElemByte(i, j);
64
					assertEquals(b1, b2);
65
				}
66
			}
67
			
68
			buf.free();
69
		} catch (GdalException e) {
70
			e.printStackTrace();
71
		} catch (IOException e) {
72
			e.printStackTrace();
73
		}
74
		long t2 = System.currentTimeMillis();
75
		System.out.println("Tiempo ROCache TestReplicateBand: " + (t2 - t1) + " milisegundos");
76
	}
77
	
78
}
0 79

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestCopyBand.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6

  
7
import org.gvsig.raster.cache.buffer.Band;
8
import org.gvsig.raster.cache.buffer.Buffer;
9
import org.gvsig.raster.cache.buffer.BufferDataSource;
10
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
11

  
12
/**
13
 * Copy the band 0 from a buffer over the band 2 in the same buffer using the
14
 * method getBandCopy.  
15
 * @author Nacho Brodin (nachobrodin@gmail.com)
16
 */
17
public class TestCopyBand extends TestCase {
18
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
19
	
20
	public void start() {
21
		this.setUp();
22
		this.testStack();
23
	}
24

  
25
	public void setUp() {
26
		System.err.println("ROCache TestCopyBand running...");
27
	}
28
	
29
	public void testStack() {
30
		long t1 = System.currentTimeMillis();
31

  
32
		try {			
33
			BufferDataSource ds = null;
34
			try {
35
				ds = new BufferDataSourceImpl(rasterIn);
36
			} catch (IOException e) {
37
				e.printStackTrace();
38
			}
39
			Buffer buf = new RasterReadOnlyBuffer(ds);
40
			
41
			Band rb = buf.getBandCopy(0);
42
						
43
			Band band1 = buf.getBand(0);
44
			for (int i = 0; i < band1.getHeight(); i++) {
45
				for (int j = 0; j < band1.getWidth(); j++) {
46
					byte b1 = band1.getElemByte(i, j);
47
					byte b2 = rb.getElemByte(i, j);
48
					assertEquals(b1, b2);
49
				}
50
			}
51
			
52
			buf.free();
53
		} catch (IOException e) {
54
			e.printStackTrace();
55
		}
56
		long t2 = System.currentTimeMillis();
57
		System.out.println("Tiempo ROCache TestCopyBand: " + (t2 - t1) + " milisegundos");
58
	}
59
	
60
}
0 61

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestRemoveBand.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
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.Buffer;
9
import org.gvsig.raster.cache.buffer.BufferDataSource;
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.io.BufferDataSourceImpl;
13
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
14
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
15

  
16
/**
17
 * This test read a RGB image and remove one band from the read buffer. Then compare 
18
 * the bands that have not been removed with the source bands. As a result of this test a raster
19
 * of two bands is created and saved in the hard disk
20
 * 
21
 * @author Nacho Brodin (nachobrodin@gmail.com)
22
 */
23
public class TestRemoveBand 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("ROCache TestRemoveBand running...");
33
	}
34
	
35
	public void testStack() {
36
		long t1 = System.currentTimeMillis();
37
		GdalRead input = null;
38
		try {
39
			//Read input data
40
			input = new GdalRead(rasterIn);
41
			Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
42

  
43
			//Create Buffer
44
			Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
45
					input.getWidth(), 
46
					input.getHeight(),
47
					input.getBandCount(),
48
					true);
49

  
50
			//Set data to buffer
51
			setLines(dataIn, buf1);
52

  
53
			BufferDataSource ds = null;
54
			try {
55
				ds = new BufferDataSourceImpl(rasterIn);
56
			} catch (IOException e) {
57
				e.printStackTrace();
58
			}
59
			Buffer buf2 = new RasterReadOnlyBuffer(ds);
60

  
61
			//Remove bands
62
			buf2.removeBand(1);
63
			buf1.removeBand(1);
64
			compareIRasterBuffer(buf1, buf2);
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 ROCache TestRemoveBand: " + (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
	public void compareIRasterBuffer(Buffer b1, Buffer b2) {
90
		for (int iBand = 0; iBand < b1.getBandCount(); iBand++) {
91
			
92
		for (int i = 0; i < b1.getHeight(); i++) {
93
			for (int j = 0; j < b1.getWidth(); j++) {
94
				byte b = b1.getElemByte(i, j, iBand);
95
				byte c = b2.getElemByte(i, j, iBand);
96
				if(b != c)
97
					System.out.println("B:" + iBand + "" + i + " " + j);
98
				assertEquals(c, b);
99
			}
100
		}
101
		
102
		}
103
	}
104
	
105
}
0 106

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestSwapBands.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
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.BufferDataSource;
11
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
12
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
13
import org.gvsig.raster.cache.buffer.exception.WrongParameterException;
14
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
15
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
16
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
17

  
18
/**
19
 * This test swap several bands of a raster compare the result with a memory buffer
20
 * swaped.
21
 * <P>
22
 * The array to test is {2, 0, 1}. That means the band 0 goes to the position two, the
23
 * band one goes to the position zero and the band two goes to the position one. 
24
 * When the swap operation is executed, this test will check comparing the result 
25
 * bands with the input bands 
26
 * </P>
27
 * @author Nacho Brodin (nachobrodin@gmail.com)
28
 */
29
public class TestSwapBands extends TestCase {
30
	private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
31
	
32
	public void start() {
33
		this.setUp();
34
		this.testStack();
35
	}
36

  
37
	public void setUp() {
38
		System.err.println("ROCache TestSwapBands running...");
39
	}
40
	
41
	public void testStack() {
42
		long t1 = System.currentTimeMillis();
43
		GdalRead input1 = null;
44
		try {
45
			//Read input data
46
			input1 = new GdalRead(rasterIn);
47
			Object dataIn1 = input1.readBlock(0, 0, input1.getWidth(), input1.getHeight());
48

  
49
			//Create Buffer						
50
			Buffer buf2 = new RasterMemoryBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), 
51
					input1.getWidth(), 
52
					input1.getHeight(),
53
					input1.getBandCount(),
54
					true);
55

  
56
			//Set data to buffer
57
			setLines(dataIn1, buf2);
58

  
59
			BufferDataSource ds = null;
60
			try {
61
				ds = new BufferDataSourceImpl(rasterIn);
62
			} catch (IOException e) {
63
				e.printStackTrace();
64
			}
65
			RasterReadOnlyBuffer buf1 = new RasterReadOnlyBuffer(ds);
66
			try {
67
				buf2.swapBands(new int[]{2, 0, 1});
68
				buf1.swapBands(new int[]{2, 0, 1});
69
			} catch (WrongParameterException e) {
70
				e.printStackTrace();
71
			}
72
			
73
			//Write output file 
74
						
75
			Band band1 = buf1.getBand(0);
76
			Band band2 = buf2.getBand(0);
77
			compareBands(band1, band2);
78
			
79
			band1 = buf1.getBand(1);
80
			band2 = buf2.getBand(1);
81
			compareBands(band1, band2);
82
			
83
			band1 = buf1.getBand(2);
84
			band2 = buf2.getBand(2);
85
			compareBands(band1, band2);
86
			
87
			buf1.free();
88
			buf2.free();
89
		} catch (GdalException e) {
90
			e.printStackTrace();
91
		} catch (IOException e) {
92
			e.printStackTrace();
93
		} catch (ProcessInterruptedException e) {
94
			e.printStackTrace();
95
		} catch (OperationNotSupportedException e) {
96
			e.printStackTrace();
97
		}
98
		long t2 = System.currentTimeMillis();
99
		System.out.println("Tiempo ROCache TestSwapBands: " + (t2 - t1) + " milisegundos");
100
	}
101
	
102
	public void compareBands(Band band1, Band band2) {
103
		for (int i = 0; i < band1.getHeight(); i++) {
104
			for (int j = 0; j < band1.getWidth(); j++) {
105
				byte b1 = band1.getElemByte(i, j);
106
				byte b2 = band2.getElemByte(i, j);
107
				if(b1 != b2)
108
					System.out.println(i + " " + j);
109
				assertEquals(b1, b2);
110
			}
111
		}
112
	}
113
	
114
	private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
115
		if(dataIn instanceof byte[][][]) {
116
    		byte[][][] d = (byte[][][])dataIn;
117
    		for (int iBand = 0; iBand < d.length; iBand++) {
118
				for (int row = 0; row < d[iBand].length; row++) {
119
					buf.setLineInBandByte(d[iBand][row], row, iBand);
120
				}
121
			}
122
    	}
123
	}
124
	
125
}
0 126

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.36/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/impl/rocache/TestReadWindowAndCompareData.java
1
package org.gvsig.raster.cache.buffer.impl.rocache;
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.Buffer;
9
import org.gvsig.raster.cache.buffer.BufferParam;
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.BufferParamImpl;
14
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
15
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
16

  
17
/**
18
 * Read a number from cache
19
 * @author Nacho Brodin (nachobrodin@gmail.com)
20
 */
21
public class TestReadWindowAndCompareData extends TestCase {
22
	private String in = "./src/test/resources/image/001m09_1_0.tif";
23
	private int    initX  = 200;
24
	private int    initY  = 200;
25
	private int    w      = 400;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff