Revision 20489 trunk/extensions/extRasterTools-SE/src-test/org/gvsig/rastertools/clipping/ClippingProcessTest.java

View differences:

ClippingProcessTest.java
28 28
import org.gvsig.raster.dataset.FileNotOpenException;
29 29
import org.gvsig.raster.dataset.IBuffer;
30 30
import org.gvsig.raster.dataset.InvalidSetViewException;
31
import org.gvsig.raster.dataset.properties.DatasetColorInterpretation;
31 32
import org.gvsig.raster.grid.GridException;
32 33
import org.gvsig.raster.util.process.ClippingProcess;
33 34
import org.gvsig.rastertools.BaseTest;
......
41 42
 */
42 43
public class ClippingProcessTest extends BaseTest {
43 44

  
44
		private int[]                ecwCoords     = new int[]{100, 100, 200, 200};
45
		//ulx, lrx, lry, uly
46
		private int[]                coords     = new int[]{100, 200, 200, 100};
45 47
		
46 48
		static {
47 49
			RasterLibrary.wakeUp();
......
61 63
		}
62 64
		
63 65
		public void testStack() {
66
			//ECW
64 67
			openLayer(ecw);
68
			clipping(new int[]{0, 1, 2}, false, BufferInterpolation.INTERPOLATION_NearestNeighbour, getColorInterpretation(3));
69
			dataset = open(out + ".tif");
70
			compareDatasets(lyr.getDataSource(), dataset, new Point2D.Double(coords[0], coords[3]), 1, new int[]{0, 1, 2}, IBuffer.TYPE_BYTE);
71
			
72
			//MRSID
73
			openLayer(mrsid);
74
			clipping(new int[]{0, 1, 2}, false, BufferInterpolation.INTERPOLATION_NearestNeighbour, getColorInterpretation(3));
75
			dataset = open(out + ".tif");
76
			compareDatasets(lyr.getDataSource(), dataset, new Point2D.Double(coords[0], coords[3]), 1, new int[]{0, 1, 2}, IBuffer.TYPE_BYTE);
77
			
78
			//TIF BYTE
79
			openLayer(byteImg);
80
			clipping(new int[]{0}, false, BufferInterpolation.INTERPOLATION_NearestNeighbour, getColorInterpretation(1));
81
			dataset = open(out + ".tif");
82
			compareDatasets(lyr.getDataSource(), dataset, new Point2D.Double(coords[0], coords[3]), 1, new int[]{0}, IBuffer.TYPE_BYTE);
83
			
84
			//TIF FLOAT
85
			openLayer(floatImg);
86
			clipping(new int[]{0}, false, BufferInterpolation.INTERPOLATION_NearestNeighbour, getColorInterpretation(1));
87
			dataset = open(out + ".tif");
88
			compareDatasets(lyr.getDataSource(), dataset, new Point2D.Double(coords[0], coords[3]), 1, new int[]{0}, IBuffer.TYPE_FLOAT);
89
			
90
		}
91
		
92
		/**
93
		 * Proceso de recorte de la imagen en secuencial.
94
		 * @param drawBands
95
		 * @param onePerBand
96
		 * @param interp
97
		 */
98
		private void clipping(int[] drawBands, boolean onePerBand, int interp, DatasetColorInterpretation ci) {
65 99
			RasterProcess clippingProcess = new ClippingProcess();
66 100
			clippingProcess.addParam("viewname", null);
67
			clippingProcess.addParam("pixelcoordinates", ecwCoords);
101
			clippingProcess.addParam("pixelcoordinates", coords);
68 102
			clippingProcess.addParam("filename", getFileTemp());
69 103
			clippingProcess.addParam("datawriter", new WriterBufferServer());
70 104
			clippingProcess.addParam("layer", lyr);
71
			clippingProcess.addParam("drawablebands", new int[]{0, 1, 2});
72
			clippingProcess.addParam("onelayerperband", new Boolean(false));
73
			clippingProcess.addParam("interpolationmethod", new Integer(BufferInterpolation.INTERPOLATION_NearestNeighbour));
105
			clippingProcess.addParam("drawablebands", drawBands);
106
			clippingProcess.addParam("onelayerperband", new Boolean(onePerBand));
107
			clippingProcess.addParam("interpolationmethod", new Integer(interp));
74 108
			clippingProcess.addParam("affinetransform", new AffineTransform());
75
			clippingProcess.addParam("colorInterpretation", getColorInterpretation(3));
76
			clippingProcess.addParam("resolution", new int[]{ecwCoords[2] - ecwCoords[0], ecwCoords[3] - ecwCoords[1]});
109
			clippingProcess.addParam("colorInterpretation", ci);
110
			clippingProcess.addParam("resolution", new int[]{coords[2] - coords[0], coords[1] - coords[3]});
77 111
			try {
78 112
				clippingProcess.execute();
79 113
			} catch (InterruptedException e) {
80 114
				e.printStackTrace();
81 115
			}
82
			dataset = open(out + ".tif");
83
			compareDatasets(lyr.getDataSource(), dataset, new Point2D.Double(ecwCoords[0], ecwCoords[1]), 1, new int[]{0, 1, 2}, IBuffer.TYPE_BYTE);
84
			dataset.close();
85 116
		}
86
		
87
		/*private void printByteLine(byte[] line, int nLine){
88
			System.out.print("L?nea: " + nLine + "| ");
89
			for (int i = 0; i < line.length; i++)
90
				System.out.print((int)(line[i] & 0x000000ff) + " ");
91
			System.out.println();
92
		}*/
93
		
94
		public void testLine0_Banda0(byte[] line)throws InvalidSetViewException, FileNotOpenException, GridException{
95
			assertEquals((int)(line[0] & 0x000000ff), 43);
96
			assertEquals((int)(line[9] & 0x000000ff), 83);
97
			assertEquals((int)(line[19] & 0x000000ff), 75);
98
			assertEquals((int)(line[29] & 0x000000ff), 255);
99
		}
100
		
101
		public void testLine9_Banda0(byte[] line)throws InvalidSetViewException, FileNotOpenException, GridException{
102
			assertEquals((int)(line[0] & 0x000000ff), 118);
103
			assertEquals((int)(line[9] & 0x000000ff), 81);
104
			assertEquals((int)(line[19] & 0x000000ff), 105);
105
			assertEquals((int)(line[29] & 0x000000ff), 114);
106
		}
107
		
108
		public void testLine19_Banda0(byte[] line)throws InvalidSetViewException, FileNotOpenException, GridException{
109
			assertEquals((int)(line[0] & 0x000000ff), 70);
110
			assertEquals((int)(line[9] & 0x000000ff), 49);
111
			assertEquals((int)(line[19] & 0x000000ff), 63);
112
			assertEquals((int)(line[29] & 0x000000ff), 147);
113
		}
114
		
115
		public void testLine29_Banda0(byte[] line)throws InvalidSetViewException, FileNotOpenException, GridException{
116
			assertEquals((int)(line[0] & 0x000000ff), 175);
117
			assertEquals((int)(line[9] & 0x000000ff), 129);
118
			assertEquals((int)(line[19] & 0x000000ff), 15);
119
			assertEquals((int)(line[29] & 0x000000ff), 126);
120
		}
121
		
122
		public void testLine0_Banda2(byte[] line)throws InvalidSetViewException, FileNotOpenException, GridException{
123
			assertEquals((int)(line[0] & 0x000000ff), 26);
124
			assertEquals((int)(line[9] & 0x000000ff), 68);
125
			assertEquals((int)(line[19] & 0x000000ff), 70);
126
			assertEquals((int)(line[29] & 0x000000ff), 246);
127
		}
128
		
129
		public void testLine9_Banda2(byte[] line)throws InvalidSetViewException, FileNotOpenException, GridException{
130
			assertEquals((int)(line[0] & 0x000000ff), 96);
131
			assertEquals((int)(line[9] & 0x000000ff), 93);
132
			assertEquals((int)(line[19] & 0x000000ff), 93);
133
			assertEquals((int)(line[29] & 0x000000ff), 102);
134
		}
135
		
136
		public void testLine19_Banda2(byte[] line)throws InvalidSetViewException, FileNotOpenException, GridException{
137
			assertEquals((int)(line[0] & 0x000000ff), 81);
138
			assertEquals((int)(line[9] & 0x000000ff), 46);
139
			assertEquals((int)(line[19] & 0x000000ff), 63);
140
			assertEquals((int)(line[29] & 0x000000ff), 123);
141
		}
142
		
143
		public void testLine29_Banda2(byte[] line)throws InvalidSetViewException, FileNotOpenException, GridException{
144
			assertEquals((int)(line[0] & 0x000000ff), 147);
145
			assertEquals((int)(line[9] & 0x000000ff), 110);
146
			assertEquals((int)(line[19] & 0x000000ff), 14);
147
			assertEquals((int)(line[29] & 0x000000ff), 111);
148
		}
149 117

  
150
	
151

  
152 118
}

Also available in: Unified diff