Revision 17429

View differences:

trunk/libraries/libRaster/src-test/org/gvsig/raster/grid/roi/TestRasterROI.java
1
package org.gvsig.raster.grid.roi;
2

  
3
import junit.framework.TestCase;
4

  
5
import org.gvsig.raster.buffer.RasterBufferInvalidException;
6
import org.gvsig.raster.dataset.IBuffer;
7
import org.gvsig.raster.grid.Grid;
8
import org.gvsig.raster.grid.GridException;
9
import org.gvsig.raster.grid.GridExtent;
10
import org.gvsig.raster.grid.OutOfGridException;
11

  
12
public class TestRasterROI extends TestCase {
13
	
14
	Grid grid = null;
15
	GridExtent extent = null;
16
	int cellSize = 1;
17
	double xMin = 0;
18
	double xMax = 10;
19
	double yMin = 0;
20
	double yMax = 10;
21
	RasterROI rasterROI = null;
22
	
23
	public void setUp() {
24
		int bands[] = {0};
25
		extent = new GridExtent();
26
		extent.setCellSize(cellSize);
27
		extent.setXRange(xMin, xMax);
28
		extent.setYRange(yMin, yMax);
29
		try {
30
			grid = new Grid(extent, extent, IBuffer.TYPE_DOUBLE, bands);
31
			for (int x = 0; x<5; x++)
32
				for (int y = 0; y<5; y++){
33
					grid.setCellValue(x, y, 0.0);
34
				}
35
			for (int x = 5; x<xMax; x++)
36
				for (int y = 0; y<5; y++){
37
					grid.setCellValue(x, y, 1.0);
38
				}
39
			for (int x = 0; x<5; x++)
40
				for (int y = 5; y<10; y++){
41
					grid.setCellValue(x, y, 2.0);
42
				}
43
			for (int x = 5; x<10; x++)
44
				for (int y = 5; y<10; y++){
45
					grid.setCellValue(x, y, 3.0);
46
				}
47
		} catch (RasterBufferInvalidException e) {
48
			// TODO Auto-generated catch block
49
			e.printStackTrace();
50
		} catch (OutOfGridException e) {
51
			// TODO Auto-generated catch block
52
			e.printStackTrace();
53
		}
54
		
55
	}
56
	
57
	public void start() {
58
		this.setUp();
59
		this.testStack();
60
	}
61
	
62
	public void testStack() {
63
		
64
		rasterROI = new RasterROI(grid);
65
		rasterROI.addPoint(0,0);
66
		rasterROI.addPoint(0,1);
67
		rasterROI.addPoint(1,0);
68
		rasterROI.addPoint(1,1);
69
		
70

  
71
		try {
72
			assertEquals(0.0,rasterROI.getMaxValue(),0.0);
73
			assertEquals(0.0,rasterROI.getMeanValue(),0.0);
74
			assertEquals(0.0,rasterROI.getMinValue(),0.0);
75
		} catch (GridException e) {
76
			e.printStackTrace();
77
		}
78
		
79
		rasterROI.clear();
80
		rasterROI.addPoint(8,8);
81
		rasterROI.addPoint(9,8);
82
		rasterROI.addPoint(8,9);
83
		rasterROI.addPoint(9,9);
84
		
85
		try {
86
			assertEquals(3.0,rasterROI.getMaxValue(),0.0);
87
			assertEquals(3.0,rasterROI.getMeanValue(),0.0);
88
			assertEquals(3.0,rasterROI.getMinValue(),0.0);
89
		} catch (GridException e) {
90
			e.printStackTrace();
91
		}
92
		
93
		rasterROI.clear();
94
		rasterROI.addPoint(4,4);
95
		rasterROI.addPoint(5,4);
96
		rasterROI.addPoint(4,5);
97
		rasterROI.addPoint(5,5);
98
		
99
		try {
100
			assertEquals(3.0,rasterROI.getMaxValue(),0.0);
101
			assertEquals(1.5,rasterROI.getMeanValue(),0.0);
102
			assertEquals(0.0,rasterROI.getMinValue(),0.0);	
103
		} catch (GridException e) {
104
			e.printStackTrace();
105
		}
106
	}
107

  
108
}

Also available in: Unified diff