Revision 11930

View differences:

trunk/libraries/libRaster/src-test/org/gvsig/raster/dataset/TestStatistics.java
115 115
	private void dataTestB1(DatasetStatistics stats){
116 116
		assertEquals(new Double(stats.getMax()[0]), new Double(255.0));
117 117
		assertEquals(new Double(stats.getMin()[0]), new Double(0.0));
118
		assertEquals(new Double(stats.getSecondMax()[0]), new Double(253.0));
119
		assertEquals(new Double(stats.getSecondMin()[0]), new Double(7.0));
118
		assertEquals(new Double(stats.getSecondMax()[0]), new Double(254.0));
119
		assertEquals(new Double(stats.getSecondMin()[0]), new Double(1.0));
120 120
		assertEquals((int)stats.getMean()[0], 109);
121 121
		assertEquals((int)stats.getVariance()[0], 6125);
122 122
	}
......
133 133
	private void dataTestB3(DatasetStatistics stats){
134 134
		assertEquals(new Double(stats.getMax()[2]), new Double(255.0));
135 135
		assertEquals(new Double(stats.getMin()[2]), new Double(0.0));
136
		assertEquals(new Double(stats.getSecondMax()[2]), new Double(253.0));
137
		assertEquals(new Double(stats.getSecondMin()[2]), new Double(5.0));
136
		assertEquals(new Double(stats.getSecondMax()[2]), new Double(254.0));
137
		assertEquals(new Double(stats.getSecondMin()[2]), new Double(1.0));
138 138
		assertEquals((int)stats.getMean()[2], 98);
139 139
		assertEquals((int)stats.getVariance()[2], 5495);
140 140
	}
......
142 142
	private void dataTestB1_2(DatasetStatistics stats){
143 143
		assertEquals(new Double(stats.getMax()[0]), new Double(1269.0));
144 144
		assertEquals(new Double(stats.getMin()[0]), new Double(0.0));
145
		assertEquals(new Double(stats.getSecondMax()[0]), new Double(1233.0));
146
		assertEquals(new Double(stats.getSecondMin()[0]), new Double(27.0));
145
		assertEquals(new Double(stats.getSecondMax()[0]), new Double(1235.0));
146
		assertEquals(new Double(stats.getSecondMin()[0]), new Double(6.0));
147 147
		assertEquals((int)stats.getMean()[0], 71);
148 148
		assertEquals((int)stats.getVariance()[0], 22678);
149 149
	}
......
151 151
	private void dataTestB2_2(DatasetStatistics stats){
152 152
		assertEquals(new Double(stats.getMax()[1]), new Double(1525.0));
153 153
		assertEquals(new Double(stats.getMin()[1]), new Double(0.0));
154
		assertEquals(new Double(stats.getSecondMax()[1]), new Double(1498.0));
155
		assertEquals(new Double(stats.getSecondMin()[1]), new Double(35.0));
154
		assertEquals(new Double(stats.getSecondMax()[1]), new Double(1522.0));
155
		assertEquals(new Double(stats.getSecondMin()[1]), new Double(14.0));
156 156
		assertEquals((int)stats.getMean()[1], 104);
157 157
		assertEquals((int)stats.getVariance()[1], 37907);
158 158
	}
......
161 161
		assertEquals(new Double(stats.getMax()[2]), new Double(888.0));
162 162
		assertEquals(new Double(stats.getMin()[2]), new Double(0.0));
163 163
		assertEquals(new Double(stats.getSecondMax()[2]), new Double(884.0));
164
		assertEquals(new Double(stats.getSecondMin()[2]), new Double(24.0));
164
		assertEquals(new Double(stats.getSecondMin()[2]), new Double(13.0));
165 165
		assertEquals((int)stats.getMean()[2], 75);
166 166
		assertEquals((int)stats.getVariance()[2], 17437);
167 167
	}
trunk/libraries/libRaster/src-test/org/gvsig/raster/dataset/TestStatisticMultiFile.java
85 85
			dataTestB1(grmf.getStatistics());
86 86
			dataTestB2(grmf.getStatistics());
87 87
			dataTestB3(grmf.getStatistics());
88
			//print(grmf);
88
			print(grmf);
89 89
		} catch (FileNotFoundInListException e) {
90 90
			e.printStackTrace();
91 91
		}
......
94 94
	private void dataTestB1(DatasetStatistics stats){
95 95
		assertEquals(new Double(stats.getMax()[0]), new Double(249.0));
96 96
		assertEquals(new Double(stats.getMin()[0]), new Double(82.0));
97
		assertEquals(new Double(stats.getSecondMax()[0]), new Double(200.0));
97
		assertEquals(new Double(stats.getSecondMax()[0]), new Double(211.0));
98 98
		assertEquals(new Double(stats.getSecondMin()[0]), new Double(83.0));
99 99
		assertEquals((int)stats.getMean()[0], 119);
100
		assertEquals((int)stats.getVariance()[0], 583);
100
		assertEquals((int)stats.getVariance()[0], 584);
101 101
	}
102 102
	
103 103
	private void dataTestB2(DatasetStatistics stats){
104 104
		assertEquals(new Double(stats.getMax()[1]), new Double(234.0));
105 105
		assertEquals(new Double(stats.getMin()[1]), new Double(49.0));
106
		assertEquals(new Double(stats.getSecondMax()[1]), new Double(191.0));
106
		assertEquals(new Double(stats.getSecondMax()[1]), new Double(216.0));
107 107
		assertEquals(new Double(stats.getSecondMin()[1]), new Double(50.0));
108 108
		assertEquals((int)stats.getMean()[1], 102);
109 109
		assertEquals((int)stats.getVariance()[1], 1107);
......
112 112
	private void dataTestB3(DatasetStatistics stats){
113 113
		assertEquals(new Double(stats.getMax()[2]), new Double(255.0));
114 114
		assertEquals(new Double(stats.getMin()[2]), new Double(28.0));
115
		assertEquals(new Double(stats.getSecondMax()[2]), new Double(231.0));
115
		assertEquals(new Double(stats.getSecondMax()[2]), new Double(250.0));
116 116
		assertEquals(new Double(stats.getSecondMin()[2]), new Double(34.0));
117 117
		assertEquals((int)stats.getMean()[2], 115);
118 118
		assertEquals((int)stats.getVariance()[2], 2833);
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/properties/DatasetStatistics.java
216 216
	
217 217
		for (int iBand = 0; iBand < grf.getBandCount(); iBand ++) {
218 218
			max[iBand] = Double.NEGATIVE_INFINITY; 
219
			min[iBand] = Double.MAX_VALUE;
219
			min[iBand] = Double.POSITIVE_INFINITY;
220 220
			secondMax[iBand] = Double.NEGATIVE_INFINITY; 
221
			secondMin[iBand] = Double.MAX_VALUE;
221
			secondMin[iBand] = Double.POSITIVE_INFINITY;
222 222
			init[iBand] = true;
223 223
		}
224 224
		
......
242 242
			if((block + hB) > grf.getHeight())
243 243
				hB = Math.abs(grf.getHeight() - block);
244 244
			for (int iBand = 0; iBand < grf.getBandCount(); iBand ++) {
245
				for (int row = 0; row < hB; row++) {	
246
					for (int col = 0; col < grf.getWidth(); col ++) {
245
				for (int col = 0; col < grf.getWidth(); col ++) {
246
					for (int row = 0; row < hB; row++) {	
247 247
						double z = (b != null) ? (b[iBand][row][col] & 0xff) : ((s != null) ? (s[iBand][row][col] & 0xffff) : ((i != null) ? (i[iBand][row][col] & 0xffffff)  : (f != null) ? f[iBand][row][col] : d[iBand][row][col]));
248
						if (init[iBand]){
248
						
249
						if (init[iBand]) {
249 250
							min[iBand] = z;
250
							secondMin[iBand] = z;
251
							//secondMin[iBand] = z;
251 252
							max[iBand] = z;
252
							secondMax[iBand] = z;
253
							//secondMax[iBand] = z;
253 254
							init[iBand] = false;
254
							continue;
255
						} else {
256
							if ( min[iBand] > z ) {
257
								secondMin[iBand] = min[iBand];
258
								min[iBand] = z;
259
							}
260
							
261
							if ( max[iBand] < z ) {
262
								secondMax[iBand] = max[iBand];
263
								max[iBand] = z;
264
							}
265
							
266
							if(z < max[iBand]  && z > secondMax[iBand])
267
								secondMax[iBand] = z;
268

  
269
							if(z > min[iBand]  && z < secondMin[iBand])
270
								secondMin[iBand] = z;
255 271
						}
256
						if ( min[iBand] > z ){
257
							secondMin[iBand] = min[iBand];
258
							min[iBand] = z;
259
						}
260
						
261
						if ( secondMin[iBand] == min[iBand] && min[iBand] < z)
262
							secondMin[iBand] = z;
263
						
264
						if ( max[iBand] < z ){
265
							secondMax[iBand] = max[iBand];
266
							max[iBand] = z;
267
						}
268
						
269
						if ( secondMax[iBand] == max[iBand] && max[iBand] > z)
270
							secondMax[iBand] = z;
271
	
272 272
						mean[iBand] += z;
273 273
						variance[iBand] += z * z;
274 274
						iValues[iBand]++;
trunk/libraries/libRaster/src/org/gvsig/raster/grid/filter/RasterFilter.java
113 113
		
114 114
		percent = 0;
115 115
		if (exec) {
116
			for (int col = 0; col < width; col += 1) {
117
				for (int line = 0; line < height; line += 1)
118
					process(col, line);
119
				percent = (col * 100) / width;
116
			for (int row = 0; row < height; row ++) {
117
				for (int col = 0; col < width; col ++) 
118
					process(col, row);
119
				percent = (row * 100) / height;
120 120
			}
121 121
		}
122 122
		if (isCanceled())

Also available in: Unified diff