gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / impl / RasterBase.java @ 1939
History | View | Annotate | Download (4.32 KB)
1 |
package org.gvsig.raster.cache.buffer.impl; |
---|---|
2 |
|
3 |
import org.gvsig.raster.cache.buffer.BufferNoData; |
4 |
|
5 |
|
6 |
|
7 |
/**
|
8 |
* Base class for raster elements. This class contains methos for
|
9 |
* reading width, height, number of bands and other raster parameters
|
10 |
*
|
11 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
12 |
*/
|
13 |
public abstract class RasterBase { |
14 |
private static final long serialVersionUID = 1L; |
15 |
private int dataType = RasterBuffer.TYPE_UNDEFINED; |
16 |
private int bandCount = 0; |
17 |
private int width = 0; |
18 |
private int height = 0; |
19 |
private int x = 0; |
20 |
private int y = 0; |
21 |
public BufferNoData noDataValue = null; |
22 |
|
23 |
/**
|
24 |
* Sets size and position values
|
25 |
* @param x
|
26 |
* Upper left X position
|
27 |
* @param y
|
28 |
* Upper left X position
|
29 |
* @param w
|
30 |
* Width
|
31 |
* @param h
|
32 |
* Height
|
33 |
*/
|
34 |
public RasterBase(int x, int y, int w, int h) { |
35 |
this.x = x;
|
36 |
this.y = y;
|
37 |
this.width = w;
|
38 |
this.height = h;
|
39 |
} |
40 |
|
41 |
/**
|
42 |
* Sets size and position values
|
43 |
* @param x
|
44 |
* Upper left X position
|
45 |
* @param y
|
46 |
* Upper left X position
|
47 |
* @param w
|
48 |
* Width
|
49 |
* @param h
|
50 |
* Height
|
51 |
* @param datatype
|
52 |
* Data type of this raster
|
53 |
* @param nBands
|
54 |
* Number of bands of this raster
|
55 |
*/
|
56 |
public RasterBase(int x, int y, int w, int h, int dataType, int nBands) { |
57 |
this.x = x;
|
58 |
this.y = y;
|
59 |
this.width = w;
|
60 |
this.height = h;
|
61 |
this.dataType = dataType;
|
62 |
this.bandCount = nBands;
|
63 |
} |
64 |
|
65 |
/**
|
66 |
* Returns the width in pixels
|
67 |
* @return Width in pixels of this raster
|
68 |
*/
|
69 |
public int getWidth() { |
70 |
return width;
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* Sets the width in pixels
|
75 |
* @param width
|
76 |
* Width in pixels of this raster
|
77 |
*/
|
78 |
public void setWidth(int width) { |
79 |
this.width = width;
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* Returns the height in pixels
|
84 |
* @return Height in pixels of this raster
|
85 |
*/
|
86 |
public int getHeight() { |
87 |
return height;
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* Sets the height in pixels
|
92 |
* @param height
|
93 |
* Height in pixels of this raster
|
94 |
*/
|
95 |
public void setHeight(int height) { |
96 |
this.height = height;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Returns the X upper left coordinate
|
101 |
* @return X upper left coordinate in pixels
|
102 |
*/
|
103 |
public int getX() { |
104 |
return x;
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* Sets the X upper left coordinate
|
109 |
* @params x
|
110 |
* X upper left coordinate in pixels
|
111 |
*/
|
112 |
public void setX(int x) { |
113 |
this.x = x;
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* Returns the Y upper left coordinate
|
118 |
* @return Y upper left coordinate in pixels
|
119 |
*/
|
120 |
public int getY() { |
121 |
return y;
|
122 |
} |
123 |
|
124 |
/**
|
125 |
* Sets the Y upper left coordinate
|
126 |
* @params y
|
127 |
* Y upper left coordinate in pixels
|
128 |
*/
|
129 |
public void setY(int y) { |
130 |
this.y = y;
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* Gets the data type
|
135 |
* @return
|
136 |
*/
|
137 |
public int getDataType() { |
138 |
return dataType;
|
139 |
} |
140 |
|
141 |
/**
|
142 |
* Sets the data type
|
143 |
* @param dataType
|
144 |
*/
|
145 |
public void setDataType(int dataType) { |
146 |
this.dataType = dataType;
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Gets number of bands
|
151 |
* @return
|
152 |
*/
|
153 |
public int getBandCount() { |
154 |
return bandCount;
|
155 |
} |
156 |
|
157 |
/**
|
158 |
* Sets number of bands
|
159 |
* @param bandCount
|
160 |
*/
|
161 |
public void setBandCount(int bandCount) { |
162 |
this.bandCount = bandCount;
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* Adds one to the band counter
|
167 |
*/
|
168 |
public void bandPlusPlus() { |
169 |
this.bandCount ++;
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* Substracts one to the band counter
|
174 |
*/
|
175 |
public void bandLessLess() { |
176 |
this.bandCount --;
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* Gets no data value
|
181 |
* @return double
|
182 |
*/
|
183 |
public BufferNoData getNoDataValue() {
|
184 |
return noDataValue;
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* Sets no data value
|
189 |
* @return double
|
190 |
*/
|
191 |
public void setNoDataValue(BufferNoData nd){ |
192 |
noDataValue = nd; |
193 |
} |
194 |
|
195 |
/**
|
196 |
* Gets the size of the data type in bytes
|
197 |
* @return Size of the data type that is used
|
198 |
*/
|
199 |
public int getDataSize() { |
200 |
if (getDataType() == RasterBuffer.TYPE_BYTE) {
|
201 |
return 1; |
202 |
} else if ((getDataType() == RasterBuffer.TYPE_SHORT) | (getDataType() == RasterBuffer.TYPE_USHORT)) { |
203 |
return 2; |
204 |
} else if (getDataType() == RasterBuffer.TYPE_INT) { |
205 |
return 4; |
206 |
}else if (getDataType() == RasterBuffer.TYPE_FLOAT) { |
207 |
return 8; |
208 |
}else if (getDataType() == RasterBuffer.TYPE_DOUBLE) { |
209 |
return 16; |
210 |
} |
211 |
|
212 |
return 0; |
213 |
} |
214 |
|
215 |
/**
|
216 |
* Gets the buffer size
|
217 |
* @return buffer size
|
218 |
*/
|
219 |
public long sizeof() { |
220 |
return (long)(getDataSize() * getWidth() * getHeight() * getBandCount()); |
221 |
} |
222 |
|
223 |
} |