Revision 2215 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/provider/fusion/BufferListFusion.java

View differences:

BufferListFusion.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22 1
package org.gvsig.raster.impl.provider.fusion;
23 2

  
24 3
import java.awt.geom.Rectangle2D;
25 4
import java.util.List;
26 5

  
6
import org.gvsig.fmap.dal.coverage.RasterLocator;
27 7
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
28 8
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
9
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
29 10
import org.gvsig.raster.impl.DefaultRasterManager;
30 11
import org.gvsig.raster.impl.datastruct.ExtentImpl;
31 12

  
......
50 31
	
51 32
	private List<Buffer>         bufferList                = null;
52 33
	private List<Extent>         bboxList                  = null;
53
	private double               outputPixelSize           = 0;
54
	private int                  dataType                  = Buffer.TYPE_UNDEFINED;
55
	private int                  bandCount                 = 0;
56
	private Extent               bbox                      = null;
57
	private AbstractFusionMethod         fusion                    = null;
34
	private PixelSquareStructure pxSquare                  = null;
35
	private AbstractFusionMethod fusion                    = null;
58 36
	
37
	public class PixelSquareStructure {
38
		public double               pixelSize                 = 0;
39
		public int                  dataType                  = Buffer.TYPE_UNDEFINED;
40
		public int                  bandCount                 = 0;
41
		public int                  width                     = 0;
42
		public int                  height                    = 0;
43
		public Extent               bbox                      = null;
44
		public NoData               nodata                    = null;
45
		public Buffer               buffer                    = null;
46
		
47
		public PixelSquareStructure(
48
				Buffer buf,
49
				Extent bbox,
50
				double pixelSize) {
51
			this.pixelSize = pixelSize;
52
			this.dataType = buf.getDataType();
53
			this.bandCount = buf.getBandCount();
54
			this.width = buf.getWidth();
55
			this.height = buf.getHeight();
56
			nodata = buf.getNoDataValue() != null ? 
57
					buf.getNoDataValue() : 
58
					RasterLocator.getManager().getDataStructFactory().createDefaultNoData(bandCount, dataType);
59
			this.bbox = bbox;
60
			this.buffer = buf;
61
		}
62
		
63
		public PixelSquareStructure(
64
				double pixelSize,
65
				int bandCount,
66
				int datatype) {
67
			this.pixelSize = pixelSize;
68
			this.dataType = datatype;
69
			this.bandCount = bandCount;
70
			this.width = (int)Math.ceil(bbox.width() * pixelSize);
71
			this.height = (int)Math.ceil(bbox.height() * pixelSize);
72
			nodata = RasterLocator.getManager().getDataStructFactory().createDefaultNoData(bandCount, datatype);
73
		}
74
	}
75
	
76
	public static PixelSquareStructure buildPixelSquareStructure(
77
			Buffer buf,
78
			Extent bbox,
79
			double pixelSize) {
80
		return  new BufferListFusion().new PixelSquareStructure(buf, bbox, pixelSize);
81
	}
82
	
83
	public static PixelSquareStructure buildPixelSquareStructure(
84
			double pixelSize,
85
			int bandCount,
86
			int datatype) {
87
		return  new BufferListFusion().new PixelSquareStructure(pixelSize, bandCount, datatype);
88
	}
89
	
90
	public BufferListFusion() {}
91
	
59 92
	public BufferListFusion(
60 93
			List<Buffer> bufferList,
61
			int pixelSize,
62
			int ouputBandCount,
63
			int outputDatatype,
94
			PixelSquareStructure pxSquare,
64 95
			int fusionMethod) {
65
		this.outputPixelSize = pixelSize;
66
		this.dataType = outputDatatype;
67
		this.bandCount = ouputBandCount;
68 96
		this.bufferList = bufferList;
69
		bbox = getBoundingBox();
97
		if(pxSquare.bbox == null) {
98
			Extent bbox = getBoundingBox();
99
			pxSquare.bbox = bbox;
100
		}
101
		this.pxSquare = pxSquare;
70 102
		
71 103
		if(fusionMethod == FIRST) {
72
			fusion = new FirstFusionMethod();
104
			fusion = new FirstFusionMethod(bufferList, pxSquare);
73 105
		}
74 106
	}
75 107
	
......
80 112
	 * @return
81 113
	 */
82 114
	public Buffer getWindow() {
83
		int width = (int)Math.ceil(bbox.width() * outputPixelSize);
84
		int height = (int)Math.ceil(bbox.height() * outputPixelSize);
85
		Buffer buffer = DefaultRasterManager.getInstance().createBuffer(dataType, width, height, bandCount, true);
115
		if(pxSquare.buffer == null) {
116
			pxSquare.buffer = DefaultRasterManager.getInstance().createBuffer(
117
					pxSquare.dataType, pxSquare.width, pxSquare.height, pxSquare.bandCount, true);
118
		}
86 119
		
87
		if(dataType == Buffer.TYPE_BYTE) {
88
			for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
89
				for (int row = 0; row < buffer.getHeight(); row++) {
90
					for (int col = 0; col < buffer.getWidth(); col++) {
91
						buffer.setElem(row, col, iBand, fusion.getByteValue(row, col, iBand));
92
					}	
93
				}
120
		if(pxSquare.dataType == Buffer.TYPE_BYTE) {
121
			for (int row = 0; row < pxSquare.buffer.getHeight(); row++) {
122
				for (int col = 0; col < pxSquare.buffer.getWidth(); col++) {
123
					pxSquare.buffer.setElemByte(row, col, fusion.getByteValue(row, col));
124
				}	
94 125
			}
95 126
		}
96
		
97
		if(dataType == Buffer.TYPE_FLOAT) {
98
			for (int iBand = 0; iBand < buffer.getBandCount(); iBand++) {
99
				for (int row = 0; row < buffer.getHeight(); row++) {
100
					for (int col = 0; col < buffer.getWidth(); col++) {
101
						buffer.setElem(row, col, iBand, fusion.getFloatValue(row, col, iBand));
102
					}	
103
				}
127

  
128
		if(pxSquare.dataType == Buffer.TYPE_FLOAT) {
129
			for (int row = 0; row < pxSquare.buffer.getHeight(); row++) {
130
				for (int col = 0; col < pxSquare.buffer.getWidth(); col++) {
131
					pxSquare.buffer.setElemFloat(row, col, fusion.getFloatValue(row, col));
132
				}	
104 133
			}
105 134
		}
106
		return buffer;
135
		return pxSquare.buffer;
107 136
	}
108 137
	
109
	/*private Extent getIntersectionBoundingBox(Extent bbox) {
110
		Extent intersection = bbox;
111
		if(bboxList != null) {
112
			for (int i = 0; i < bboxList.size(); i++) {
113
				Extent e = bboxList.get(i);
114
				intersection = intersection.intersection(e);
138
	/**
139
	 * Sets a band to NODATA value 
140
	 * @param bufResult
141
	 * @param tileExtent
142
	 * @param buf
143
	 * @param ex
144
	 * @param pixelSize
145
	 */
146
	protected void clearMaskBuffer(Buffer buf) {
147
		if(buf.getDataType() == Buffer.TYPE_BYTE) {
148
			for (int i = 0; i < buf.getHeight(); i++) {
149
				for (int j = 0; j < buf.getWidth(); j++) {
150
					for (int iBand = 0; iBand < buf.getBandCount(); iBand++) {
151
						buf.setElem(i, j, iBand, pxSquare.nodata.getValue().byteValue());						
152
					}
153
				}
115 154
			}
116
		} else {
117
			for (int i = 0; i < bufferList.size(); i++) {
118
				Rectangle2D r = bufferList.get(i).getDataExtent();
119
				Extent e = new ExtentImpl(r.getMinX(), r.getMinY(), r.getMaxX(), r.getMaxY());
120
				intersection = intersection.intersection(e);
155
			return;
156
		}
157
		if(buf.getDataType() == Buffer.TYPE_SHORT) {
158
			for (int i = 0; i < buf.getHeight(); i++) {
159
				for (int j = 0; j < buf.getWidth(); j++) {
160
					for (int iBand = 0; iBand < buf.getBandCount(); iBand++) {
161
						buf.setElem(i, j, iBand, pxSquare.nodata.getValue().shortValue());						
162
					}
163
				}
121 164
			}
165
			return;
122 166
		}
123
		return intersection;
124
	}*/
167
		if(buf.getDataType() == Buffer.TYPE_INT) {
168
			for (int i = 0; i < buf.getHeight(); i++) {
169
				for (int j = 0; j < buf.getWidth(); j++) {
170
					for (int iBand = 0; iBand < buf.getBandCount(); iBand++) {
171
						buf.setElem(i, j, iBand, pxSquare.nodata.getValue().intValue());						
172
					}
173
				}
174
			}
175
			return;
176
		}
177
		if(buf.getDataType() == Buffer.TYPE_FLOAT) {
178
			for (int i = 0; i < buf.getHeight(); i++) {
179
				for (int j = 0; j < buf.getWidth(); j++) {
180
					for (int iBand = 0; iBand < buf.getBandCount(); iBand++) {
181
						buf.setElem(i, j, iBand, pxSquare.nodata.getValue().floatValue());						
182
					}
183
				}
184
			}
185
			return;
186
		}
187
		if(buf.getDataType() == Buffer.TYPE_DOUBLE) {
188
			for (int i = 0; i < buf.getHeight(); i++) {
189
				for (int j = 0; j < buf.getWidth(); j++) {
190
					for (int iBand = 0; iBand < buf.getBandCount(); iBand++) {
191
						buf.setElem(i, j, iBand, pxSquare.nodata.getValue().doubleValue());						
192
					}
193
				}
194
			}
195
			return;
196
		}
197
	}
125 198
	
126 199
	private Extent getBoundingBox() {
127 200
		double minX = Double.MAX_VALUE;
......
156 229
		return new ExtentImpl(minX, minY, maxX, maxY);
157 230
	}
158 231
	
232
	public void dispose() {
233
		for (int i = 0; i < bufferList.size(); i++) {
234
			bufferList.get(i).dispose();
235
		}
236
		bufferList.clear();
237
	}
238
	
239
	/*public void setNoDataValue(int datatype) {
240
		NoData noData = RasterLocator.getManager().getDataStructFactory().createDefaultNoData(bandCount, datatype);
241
		switch (datatype) {
242
		case Buffer.TYPE_BYTE:
243
			byteNoData = noData.getValue().byteValue();
244
			break;
245
		case Buffer.TYPE_SHORT:
246
			shortNoData = noData.getValue().shortValue();
247
			break;
248
		case Buffer.TYPE_INT:
249
			intNoData = noData.getValue().intValue();
250
			break;
251
		case Buffer.TYPE_FLOAT:
252
			floatNoData = noData.getValue().floatValue();
253
			break;
254
		case Buffer.TYPE_DOUBLE:
255
			doubleNoData = ((NoData)noData).getValue().doubleValue();
256
			break;
257
		}
258
	}
259
	
260
	private Extent getIntersectionBoundingBox(Extent bbox) {
261
		Extent intersection = bbox;
262
		if(bboxList != null) {
263
			for (int i = 0; i < bboxList.size(); i++) {
264
				Extent e = bboxList.get(i);
265
				intersection = intersection.intersection(e);
266
			}
267
		} else {
268
			for (int i = 0; i < bufferList.size(); i++) {
269
				Rectangle2D r = bufferList.get(i).getDataExtent();
270
				Extent e = new ExtentImpl(r.getMinX(), r.getMinY(), r.getMaxX(), r.getMaxY());
271
				intersection = intersection.intersection(e);
272
			}
273
		}
274
		return intersection;
275
	}*/
276
	
277
	
159 278
}

Also available in: Unified diff