Revision 2301

View differences:

org.gvsig.raster/branches/org.gvsig.raster_dataaccess_refactoring/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/provider/AbstractRasterProvider.java
212 212
	}
213 213
	
214 214
	/**
215
	 * Acciones de inicilizacin comunes a todos los drivers.
216
	 * Este mtodo debe ser llamado explicitamente por el constructor de cada driver.
217
	 * Estas son acciones de inicializaci�n que se ejecutan despu�s del constructor de cada driver.
215
	 * Acciones de inicilizaci?n comunes a todos los drivers.
216
	 * Este m?todo debe ser llamado explicitamente por el constructor de cada driver.
217
	 * Estas son acciones de inicializaci?n que se ejecutan despu?s del constructor de cada driver.
218 218
	 * Las acciones que hayan de ser realizadas antes se definen en el constructor de RasterDataset.
219 219
	 */
220 220
	protected void init() {
221 221
	}
222 222
	
223
	public boolean isRGB() {
224
		if(getDataType()[0] == Buffer.TYPE_BYTE) {
225
			ColorInterpretation ci = getColorInterpretation();
226
			return ci.isRGB();
227
		}
228
		return false;
229
	}
230
	
231
	public boolean isARGB() {
232
		if(getDataType()[0] == Buffer.TYPE_BYTE) {
233
			ColorInterpretation ci = getColorInterpretation();
234
			return ci.isARGB();
235
		}
236
		return false;
237
	}
238
	
223 239
	public boolean isTiled() {
224 240
		return false;
225 241
	}
......
465 481

  
466 482
	public NoData getNoDataValue() {
467 483
		if(noData == null) {
468
			noData = RasterLocator.getManager().getDataStructFactory().createNoData(null, null, getRMFFile(), getBandCount());
469
			noData.setDataType(getDataType()[0]);
484
			noData = RasterLocator.getManager().getDataStructFactory().createDefaultNoData(getBandCount(), getDataType()[0]);
485
			noData.setFileName(getRMFFile());
470 486
		}
471 487
		return noData;
472 488
	}
org.gvsig.raster/branches/org.gvsig.raster_dataaccess_refactoring/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/provider/fusion/AbstractFusionMethod.java
1 1
package org.gvsig.raster.impl.provider.fusion;
2 2

  
3
import java.awt.geom.AffineTransform;
4
import java.awt.geom.NoninvertibleTransformException;
5
import java.awt.geom.Point2D;
3 6
import java.awt.geom.Rectangle2D;
4 7

  
5 8
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
......
10 13
	protected PixelSquareStructure     pxSquare  = null;
11 14
	
12 15
	public class SubSquare {
13
		private int    ulxPxDistance = 0;
14
		private int    ulyPxDistance = 0;
15
		private int    lrxPxDistance = 0;
16
		private int    lryPxDistance = 0;
17 16
		private Buffer buffer        = null;
17
		private AffineTransform    parentTransform  = null;
18
		private AffineTransform    squareTransform  = null;
19
		private Extent             squareExtent     = null;
18 20
		
19 21
		public SubSquare(
20 22
				Extent parentExtent,
......
23 25
				Rectangle2D squareSize,
24 26
				Buffer buf) {
25 27
			this.buffer = buf;
26
			double xDistWc = Math.abs(squareExtent.getULX() - parentExtent.getULX());
27
			double yDistWc = Math.abs(squareExtent.getULY() - parentExtent.getULY());
28
			double pixelSize = parentExtent.width() / parentSize.getWidth();
29
			ulxPxDistance = (int)Math.floor(xDistWc * pixelSize);
30
			ulyPxDistance = (int)Math.ceil(yDistWc * pixelSize);
31
			lrxPxDistance = (int)(ulxPxDistance + squareSize.getWidth() - 1);
32
			lryPxDistance = (int)(ulyPxDistance + squareSize.getHeight() - 1);
28
			this.squareExtent = squareExtent;
29
			parentTransform = new AffineTransform(
30
					parentExtent.width() /  parentSize.getWidth(), 
31
					0, 0, 
32
					-(parentExtent.height() /  parentSize.getHeight()), 
33
					parentExtent.getULX(), 
34
					parentExtent.getULY());
35
			
36
			squareTransform = new AffineTransform(
37
					squareExtent.width() /  squareSize.getWidth(), 
38
					0, 0, 
39
					-(squareExtent.height() /  squareSize.getHeight()), 
40
					squareExtent.getULX(), 
41
					squareExtent.getULY());
33 42
		}
34 43
		
44
		private Point2D parentRasterToWorld(Point2D pt) {
45
			return parentTransform.transform(pt, pt);
46
		}
47

  
48
		private Point2D squareWorldToRaster(Point2D pt) {
49
			try {
50
				return squareTransform.inverseTransform(pt, pt);
51
			} catch (NoninvertibleTransformException e) {
52
				return pt;
53
			}
54
		}
55
		
35 56
		/**
36 57
		 * Returns true if the pixel coordinates relative to the parent buffer is inside of this square
37 58
		 * @param row
38 59
		 * @param col
39 60
		 * @return
40 61
		 */
41
		public boolean isInside(int row, int col) {
42
			return (col >= ulxPxDistance && col <= lrxPxDistance && row >= ulyPxDistance && row <= lryPxDistance);
62
		public Point2D getLocalCoords(int row, int col) {
63
			Point2D p = parentRasterToWorld(new Point2D.Double(col, row));
64
			if (p.getX() >= squareExtent.getULX() && p.getX() <= squareExtent.getLRX() && p.getY() <= squareExtent.getULY()  && p.getY() >= squareExtent.getLRY()) {
65
				return squareWorldToRaster(p);
66
			}
67
			return null;
43 68
		}
44 69
		
45
		public void loadLocalCoords(int row, int col, int[] coords) {
46
			coords[0] = row - ulyPxDistance;
47
			coords[1] = col - ulxPxDistance;
48
		}
49
		
50 70
		public Buffer getBuffer() {
51 71
			return buffer;
52 72
		}
org.gvsig.raster/branches/org.gvsig.raster_dataaccess_refactoring/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/provider/fusion/FirstFusionMethod.java
1 1
package org.gvsig.raster.impl.provider.fusion;
2 2

  
3
import java.awt.geom.Point2D;
3 4
import java.awt.geom.Rectangle2D;
4 5
import java.util.ArrayList;
5 6
import java.util.List;
......
18 19
	
19 20
	public class SubSquareList extends ArrayList<SubSquare> {
20 21
		private static final long serialVersionUID = 1L;
21
		private int[]             coords           = new int[2];
22 22
		
23 23
		public void getByteValue(int row, int col, byte[] data) {
24 24
			for (int i = 0; i < size(); i++) {
25
				if(get(i).isInside(row, col)) {
26
					get(i).loadLocalCoords(row, col, coords);
27
					get(i).getBuffer().getElemByte(coords[0], coords[1], data);
25
				Point2D coord = get(i).getLocalCoords(row, col);
26
				if(coord != null) {
27
					get(i).getBuffer().getElemByte((int)coord.getY(), (int)coord.getX(), data);
28 28
					return;
29 29
				}
30 30
			}
......
32 32
		
33 33
		public void getFloatValue(int row, int col, float[] data) {
34 34
			for (int i = 0; i < size(); i++) {
35
				if(get(i).isInside(row, col)) {
36
					get(i).loadLocalCoords(row, col, coords);
37
					get(i).getBuffer().getElemFloat(coords[0], coords[1], data);
35
				Point2D coord = get(i).getLocalCoords(row, col);
36
				if(coord != null) {
37
					get(i).getBuffer().getElemFloat((int)coord.getY(), (int)coord.getX(), data);
38 38
					return;
39 39
				}
40 40
			}
org.gvsig.raster/branches/org.gvsig.raster_dataaccess_refactoring/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/AbstractRasterDataStore.java
182 182
		Buffer buf = null;
183 183
		
184 184
		if(q.isSupersamplingOptionActive() && q.isSupersamplingTheRequest()) {
185
			//TODO: Sin probar
185
			//TODO: Sin probar. Quiz?s sea mejor aplicar BufferInterpolation
186 186
			Supersampling supersampling = new Supersampling(q, this);
187 187
			buf = supersampling.query(provider);
188 188
		} else if(q.requestHasShift()) {
org.gvsig.raster/branches/org.gvsig.raster_dataaccess_refactoring/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/properties/DataStoreColorInterpretation.java
22 22
package org.gvsig.raster.impl.store.properties;
23 23

  
24 24
import java.util.ArrayList;
25
import java.util.List;
25 26

  
26 27
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
27 28
/**
......
55 56
	public DataStoreColorInterpretation(String[] colorInterp) {
56 57
		this.colorInterpretation = colorInterp;
57 58
	}
59
	
60
	public static DataStoreColorInterpretation createDefaultInterpretation(int nBands) {
61
		if(nBands <= 0)
62
			return null;
63
		if(nBands == 1)
64
			return new DataStoreColorInterpretation(new String[]{GRAY_BAND});
65
		if(nBands == 2)
66
			return new DataStoreColorInterpretation(new String[]{GRAY_BAND, ALPHA_BAND});
67
		if(nBands == 3)
68
			return new DataStoreColorInterpretation(new String[]{RED_BAND, GREEN_BAND, BLUE_BAND});
69
		return new DataStoreColorInterpretation(new String[]{RED_BAND, GREEN_BAND, BLUE_BAND, ALPHA_BAND});
70
	}
71
	
72
	public static DataStoreColorInterpretation createPaletteInterpretation() {
73
		return new DataStoreColorInterpretation(new String[]{PAL_BAND});
74
	}
58 75

  
59 76
	/**
60 77
	 * Obtiene una interpretaci?n de color GRAY
......
69 86
	 * @return DatasetColorInterpretation
70 87
	 */
71 88
	public static DataStoreColorInterpretation createARGBInterpretation() {
72
		return new DataStoreColorInterpretation(new String[]{ALPHA_BAND, RED_BAND, GREEN_BAND, BLUE_BAND});
89
		return new DataStoreColorInterpretation(new String[]{RED_BAND, GREEN_BAND, BLUE_BAND, ALPHA_BAND});
73 90
	}
74 91
	
75 92
	/**
......
97 114
		colorInterpretation = new String[values];
98 115
	}
99 116
	
100
	/**
101
	 * Obtiene los valores de la interpretaci?n de color
102
	 * @return String[]
103
	 */
117
	public boolean isRGB() {
118
		if(colorInterpretation != null) {
119
			if (colorInterpretation.length == 3 && 
120
				colorInterpretation[0] == RED_BAND && 
121
				colorInterpretation[1] == BLUE_BAND && 
122
				colorInterpretation[2] == BLUE_BAND)
123
				return true;
124
		}
125
		return false;
126
	}
127
	
128
	public boolean isARGB() {
129
		if(colorInterpretation != null) {
130
			if (colorInterpretation.length == 4 && 
131
				colorInterpretation[0] == RED_BAND && 
132
				colorInterpretation[1] == BLUE_BAND && 
133
				colorInterpretation[2] == BLUE_BAND &&
134
				colorInterpretation[3] == ALPHA_BAND)
135
				return true;
136
		}
137
		return false;
138
	}
139
	
104 140
	public String[] getValues() {
105 141
		return colorInterpretation;
106 142
	}
......
113 149
		colorInterpretation = colorInterp;
114 150
	}
115 151
	
116
	/**
117
	 * Asigna un valor para la interpretaci?n de color de una banda
118
	 * @param band Banda 
119
	 * @param value valor
120
	 */
121 152
	public void setColorInterpValue(int band, String value) {
122 153
		try{
123 154
			colorInterpretation[band] = value;
......
126 157
		}
127 158
	}
128 159
	
129
	/**
130
	 * Obtiene la posici?n de la banda que contiene el identificador pasado por par?metro 
131
	 * o -1 si no tiene dicho identificador.
132
	 * @return Posici?n de la banda que contiene el identificador o -1 si no lo tiene.
133
	 */
134 160
	public int getBand(String id) {
135 161
		if(colorInterpretation != null) {
136 162
			for(int i = 0; i < colorInterpretation.length; i++)
......
145 171
	 * o null si no tiene dicho identificador.
146 172
	 * @return Lista con las posiciones de las bandas que contienen el identificador o null si no lo tiene.
147 173
	 */
148
	@SuppressWarnings("unchecked")
149 174
	public int[] getBands(String id) {
150 175
		if(colorInterpretation != null){
151
			ArrayList array = new ArrayList();
176
			List<Integer> array = new ArrayList<Integer>();
152 177
			for(int i = 0; i < colorInterpretation.length; i++)
153 178
				if(colorInterpretation[i].equals(id))
154 179
					array.add(new Integer(i));
......
160 185
		return null;
161 186
	}
162 187

  
163
	/*
164
	 * (non-Javadoc)
165
	 * @see org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation#hasAlphaBand()
166
	 */
167 188
	public boolean hasAlphaBand() {
168 189
		String[] values = getValues();
169 190
		for (int i = 0; i < values.length; i++) {
......
173 194
		return false;
174 195
	}	
175 196
	
176
	/**
177
	 * Obtiene el n?mero de entradas de interpretaci?n de color por
178
	 * banda en la lista.
179
	 * @return
180
	 */
181 197
	public int length() {
182 198
		return colorInterpretation.length;
183 199
	}
184 200
	
185
	/**
186
	 * Obtiene el valor de interpretaci?n de color de la entrada i. 
187
	 * @param i N?mero de entrada
188
	 * @return interpretaci?n de color para la entrada solicitada
189
	 */
190 201
	public String get(int i) {
191 202
		if (i >= colorInterpretation.length)
192 203
			return null;
193 204
		return colorInterpretation[i];
194 205
	}
195 206
	
196
	/*
197
	 * (non-Javadoc)
198
	 * @see org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation#addColorInterpretation(org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation)
199
	 */
200 207
	public void addColorInterpretation(ColorInterpretation ci) {
201 208
		String[] newCI = new String[colorInterpretation.length + ci.length()];
202 209
		for (int i = 0; i < colorInterpretation.length; i++)
......
207 214
		this.colorInterpretation = newCI;
208 215
	}
209 216
	
210
	/**
211
	 * Consulta si la interpretaci?n de color est? por definir en la imagen.
212
	 * @return true si no hay interpretaci?n de color definida y false si la hay
213
	 */
214 217
	public boolean isUndefined() {
215 218
		for (int i = 0; i < colorInterpretation.length; i++) {
216 219
			if (colorInterpretation[i] != null) {
......
222 225
		return true;
223 226
	}
224 227
	
225
	/*
226
	 * (non-Javadoc)
227
	 * @see org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation#cloneColorInterpretation()
228
	 */
229 228
	public ColorInterpretation cloneColorInterpretation() {
230 229
		DataStoreColorInterpretation ci = new DataStoreColorInterpretation();
231 230
		String[] l = new String[colorInterpretation.length];
org.gvsig.raster/branches/org.gvsig.raster_dataaccess_refactoring/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/store/props/ColorInterpretation.java
53 53
	public int length();
54 54
	
55 55
	/**
56
	 * Returns true if the color interpretation is RGB
57
	 * @return
58
	 */
59
	public boolean isRGB();
60
	
61
	/**
62
	 * Returns true if the color interpretation is ARGB
63
	 * @return
64
	 */
65
	public boolean isARGB();
66
	
67
	/**
56 68
	 * Obtiene el valor de interpretaci?n de color de la entrada i. 
57 69
	 * @param i N?mero de entrada
58 70
	 * @return interpretaci?n de color para la entrada solicitada
org.gvsig.raster.mosaic/trunk/org.gvsig.raster.mosaic/org.gvsig.raster.mosaic.io/src/main/java/org/gvsig/raster/mosaic/io/MosaicProvider.java
127 127
	private HashMap<String, MosaicTileServer>
128 128
	                                         tileServerMap            = new HashMap<String, MosaicTileServer>();
129 129
	private ArrayList<RasterProvider>        selectedProviders        = new ArrayList<RasterProvider>();
130
	private boolean                          bandCountCalculated      = false;
130 131
    
131 132
	public static void register() {
132 133
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
......
238 239
		uri = getParameters().getURI();
239 240
		providerList = getParameters().getProviders();
240 241
		pixelSize = getParameters().getPixelSize();
241
		ColorInterpretation ci = null;
242
		if(getBandCount() == 4)
243
			ci = DataStoreColorInterpretation.createARGBInterpretation();
244
		if(getBandCount() == 3)
245
			ci = DataStoreColorInterpretation.createRGBInterpretation();
246
		if(getBandCount() == 1)
247
			ci = DataStoreColorInterpretation.createGrayInterpretation();
248 242
		
249
		setColorInterpretation(ci);
250
		
251 243
		//Se le pone banda de transparencia siempre
252 244
		if(providerList.get(0).getDataType()[0] == Buffer.TYPE_BYTE) {
253 245
			transparency = new DataStoreTransparency();
......
278 270
		
279 271
		((MosaicDataParametersImpl)getParameters()).resetParamsChanged();
280 272
	}
273

  
274
	public ColorInterpretation getColorInterpretation() {
275
		if(super.getColorInterpretation() == null) {
276
			ColorInterpretation ci = null;
277
			for (int i = 0; i < providerList.size(); i++) {
278
				RasterProvider prv = providerList.get(i);
279
				if(prv.getBandCount() == getBandCount() && prv.getColorInterpretation() != null) {
280
					ci = prv.getColorInterpretation().cloneColorInterpretation();
281
				}
282
			}
283

  
284
			if(ci == null) {
285
				if(getDataType()[0] == Buffer.TYPE_BYTE) {
286
					if(getBandCount() == 4)
287
						ci = DataStoreColorInterpretation.createARGBInterpretation();
288
					if(getBandCount() == 3)
289
						ci = DataStoreColorInterpretation.createRGBInterpretation();
290
					if(getBandCount() == 1)
291
						ci = DataStoreColorInterpretation.createPaletteInterpretation();
292
				} else {
293
					if(getBandCount() == 1)
294
						ci = DataStoreColorInterpretation.createGrayInterpretation();
295
					else 
296
						ci = DataStoreColorInterpretation.createDefaultInterpretation();
297
				}
298
			}
299

  
300
			setColorInterpretation(ci);
301
		}
302
		return super.getColorInterpretation();
303
	}
281 304
	
282 305
	/**
283 306
	 * Loads the specific provider
......
408 431
	 * @return 
409 432
	 */
410 433
	public int getBandCount() {
411
		if(providerList.get(0).getDataType()[0] == Buffer.TYPE_BYTE)
412
			return providerList.get(0).getBandCount() + 1;
413
		return providerList.get(0).getBandCount();
434
		if(!bandCountCalculated) {
435
			bandCount = providerList.get(0).getBandCount();
436
			for (int i = 1; i < providerList.size(); i++) {
437
				if(providerList.get(i).getBandCount() > bandCount)
438
					bandCount = providerList.get(i).getBandCount();
439
			}
440
		}
441
		return bandCount;
414 442
	}
415 443
	
416 444
	public String[] getURIByProvider() {
......
681 709
			q.setDrawableBands(bandList.getDrawableBands());
682 710
			DefaultRasterStore store = new DefaultRasterStore();
683 711
			store.setProvider(provider);
684
			Buffer buf;
712
			Buffer buf = null;
685 713
			try {
686 714
				buf = store.query(q);
687 715
				buf.setDataExtent(extIntersection.toRectangle2D());

Also available in: Unified diff