Revision 5488 org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/DefaultBuffer.java
DefaultBuffer.java | ||
---|---|---|
6 | 6 |
|
7 | 7 |
import org.cresques.cts.ICoordTrans; |
8 | 8 |
import org.cresques.cts.IProjection; |
9 |
import org.slf4j.Logger; |
|
10 |
import org.slf4j.LoggerFactory; |
|
11 |
|
|
12 | 9 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
13 | 10 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
14 | 11 |
import org.gvsig.fmap.geom.primitive.Envelope; |
... | ... | |
23 | 20 |
import org.gvsig.raster.lib.buffer.api.Buffer; |
24 | 21 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
25 | 22 |
import org.gvsig.raster.lib.buffer.api.FilterList; |
23 |
import org.gvsig.raster.lib.buffer.api.NoData; |
|
26 | 24 |
import org.gvsig.raster.lib.buffer.api.RasterLocator; |
27 | 25 |
import org.gvsig.raster.lib.buffer.api.exceptions.BandException; |
28 | 26 |
import org.gvsig.raster.lib.buffer.api.statistics.Histogram; |
... | ... | |
30 | 28 |
import org.gvsig.raster.lib.buffer.impl.exceptions.CreateBufferException; |
31 | 29 |
import org.gvsig.raster.lib.buffer.impl.statistics.DefaultStatistics; |
32 | 30 |
import org.gvsig.tools.task.SimpleTaskStatus; |
31 |
import org.slf4j.Logger; |
|
32 |
import org.slf4j.LoggerFactory; |
|
33 | 33 |
|
34 |
|
|
35 | 34 |
/** |
36 | 35 |
* @author fdiaz |
37 | 36 |
* |
... | ... | |
40 | 39 |
|
41 | 40 |
protected static final Logger logger = LoggerFactory.getLogger(DefaultBuffer.class); |
42 | 41 |
|
43 |
|
|
44 | 42 |
private List<Band> bands; |
45 | 43 |
private int rows; |
46 | 44 |
private int columns; |
47 | 45 |
private FilterList filters; |
46 |
private Envelope envelope; |
|
48 | 47 |
private IProjection projection; |
49 | 48 |
private BandPageManager bandPageManager; |
50 | 49 |
private Statistics statistics; |
51 | 50 |
|
52 | 51 |
/** |
52 |
* Default constructor of buffer. |
|
53 |
* |
|
53 | 54 |
* @param rows |
55 |
* Rows of buffer and buffer bands. |
|
54 | 56 |
* @param columns |
57 |
* Columns of buffer bands. |
|
55 | 58 |
* @param bandDataTypes |
59 |
* Type of buffer bands. The band types also indicates the number |
|
60 |
* of buffer bands. |
|
61 |
* @param bandNoData |
|
62 |
* Band noData. If there are bans without NoData, bands will have |
|
63 |
* undefined NoData value. |
|
56 | 64 |
* @param projection |
57 |
* @param bandPageManager |
|
65 |
* Projection of buffer |
|
66 |
* @param envelope |
|
67 |
* Envelope of buffer |
|
68 |
* @param pageManager |
|
69 |
* Page manager to paginate this buffer. If page manager is null, |
|
70 |
* buffer will be loaded in memory. |
|
58 | 71 |
* @throws CreateBufferException |
72 |
* If there are some problems creating buffer. |
|
59 | 73 |
*/ |
60 |
public DefaultBuffer(int rows, int columns, int[] bandDataTypes, IProjection projection, BandPageManager bandPageManager) throws CreateBufferException { |
|
74 |
public DefaultBuffer(int rows, int columns, int[] bandDataTypes, NoData[] bandNoData, |
|
75 |
IProjection projection, Envelope envelope, BandPageManager pageManager) |
|
76 |
throws CreateBufferException { |
|
61 | 77 |
this.rows = rows; |
62 | 78 |
this.columns = columns; |
63 | 79 |
this.projection = projection; |
64 |
this.bandPageManager = bandPageManager; |
|
80 |
this.envelope = envelope; |
|
81 |
this.bandPageManager = pageManager; |
|
65 | 82 |
try { |
66 |
createBands(bandDataTypes); |
|
83 |
createBands(bandDataTypes, bandNoData);
|
|
67 | 84 |
} catch (BandException e) { |
68 | 85 |
throw new CreateBufferException(e); |
69 | 86 |
} |
70 | 87 |
} |
71 | 88 |
|
72 |
private void createBands(int[] bandDataTypes) throws BandException { |
|
89 |
private void createBands(int[] bandDataTypes, NoData[] bandNoData) throws BandException {
|
|
73 | 90 |
|
74 | 91 |
BufferManager bufferManager = RasterLocator.getBufferManager(); |
75 | 92 |
|
76 | 93 |
for (int i = 0; i < bandDataTypes.length; i++) { |
77 |
bands.add(bufferManager.createBand(bandDataTypes[i], this.rows, this.columns, null, this.bandPageManager)); |
|
78 |
} |
|
79 | 94 |
|
80 |
} |
|
95 |
NoData noDataBand = null; |
|
96 |
if (bandNoData != null && i < bandNoData.length) { |
|
97 |
noDataBand = bandNoData[i]; |
|
98 |
} |
|
81 | 99 |
|
82 |
/** |
|
83 |
* @param rows |
|
84 |
* @param columns |
|
85 |
* @param projection |
|
86 |
* @throws CreateBufferException |
|
87 |
*/ |
|
88 |
public DefaultBuffer(int rows, int columns, int[] bandDataTypes, IProjection projection) throws CreateBufferException { |
|
89 |
this(rows, columns, bandDataTypes, projection, null); |
|
100 |
bands.add(bufferManager.createBand(bandDataTypes[i], this.rows, this.columns, |
|
101 |
noDataBand, this.bandPageManager)); |
|
102 |
} |
|
90 | 103 |
} |
91 | 104 |
|
92 | 105 |
@Override |
93 | 106 |
public Histogram getHistogram(SimpleTaskStatus status) { |
94 |
// TODO Auto-generated method stub |
|
95 | 107 |
return getStatistics(status).getHistogram(); |
96 | 108 |
} |
97 | 109 |
|
98 | 110 |
@Override |
99 | 111 |
public Statistics getStatistics(SimpleTaskStatus status) { |
100 |
if(statistics == null){
|
|
112 |
if (statistics == null) {
|
|
101 | 113 |
statistics = new DefaultStatistics(bands); |
102 | 114 |
} |
103 |
if(!statistics.isCalculated()){
|
|
104 |
statistics.calculate(status); //scale ??? |
|
115 |
if (!statistics.isCalculated()) {
|
|
116 |
statistics.calculate(status); // scale ???
|
|
105 | 117 |
} |
106 | 118 |
return statistics; |
107 | 119 |
} |
... | ... | |
138 | 150 |
|
139 | 151 |
@Override |
140 | 152 |
public Envelope getEnvelope() { |
141 |
// TODO Auto-generated method stub |
|
142 |
//FIXME: ?De d?nde sacamos este envelope? |
|
143 |
return null; |
|
153 |
return this.envelope; |
|
144 | 154 |
} |
145 | 155 |
|
146 | 156 |
@Override |
... | ... | |
150 | 160 |
|
151 | 161 |
@Override |
152 | 162 |
public boolean isInside(int cellX, int cellY) { |
153 |
return (cellX>=0 && cellX < this.columns && cellY >= 0 && cellY < this.rows);
|
|
163 |
return (cellX >= 0 && cellX < this.columns && cellY >= 0 && cellY < this.rows);
|
|
154 | 164 |
} |
155 | 165 |
|
156 | 166 |
@Override |
... | ... | |
214 | 224 |
@Override |
215 | 225 |
public void switchBands(int[] positions) { |
216 | 226 |
List<Integer> visited = new ArrayList<Integer>(); |
217 |
if(positions.length != this.getBandCount()){
|
|
227 |
if (positions.length != this.getBandCount()) {
|
|
218 | 228 |
return; |
219 | 229 |
} |
220 |
for(int i = 0; i < positions.length; i++) { |
|
221 |
if(positions[i] >= positions.length || positions[i] < 0) {
|
|
230 |
for (int i = 0; i < positions.length; i++) {
|
|
231 |
if (positions[i] >= positions.length || positions[i] < 0) {
|
|
222 | 232 |
return; |
223 | 233 |
} |
224 | 234 |
Integer position = new Integer(positions[i]); |
225 |
if(visited.contains(position)){
|
|
235 |
if (visited.contains(position)) {
|
|
226 | 236 |
return; |
227 | 237 |
} |
228 | 238 |
visited.add(position); |
229 | 239 |
} |
230 | 240 |
|
231 | 241 |
List<Band> auxBands = new ArrayList<Band>(bands.size()); |
232 |
for(int i = 0; i < positions.length; i++) { |
|
242 |
for (int i = 0; i < positions.length; i++) {
|
|
233 | 243 |
auxBands.set(i, bands.get(positions[i])); |
234 | 244 |
} |
235 | 245 |
bands = auxBands; |
... | ... | |
243 | 253 |
} |
244 | 254 |
|
245 | 255 |
@Override |
246 |
public Buffer createInterpolated(int rows, int columns, int interpolationMode, SimpleTaskStatus status) { |
|
256 |
public Buffer createInterpolated(int rows, int columns, int interpolationMode, |
|
257 |
SimpleTaskStatus status) { |
|
247 | 258 |
// TODO Auto-generated method stub |
248 | 259 |
return null; |
249 | 260 |
} |
... | ... | |
256 | 267 |
|
257 | 268 |
@Override |
258 | 269 |
public boolean isPaginated() { |
259 |
return bandPageManager!=null;
|
|
270 |
return bandPageManager != null;
|
|
260 | 271 |
} |
261 | 272 |
|
262 | 273 |
/** |
... | ... | |
273 | 284 |
*/ |
274 | 285 |
public BandsIterator() { |
275 | 286 |
this.current = 0; |
276 |
if( getBandCount()>0 ) {
|
|
287 |
if (getBandCount() > 0) {
|
|
277 | 288 |
this.band = (Band) getBand(0); |
278 | 289 |
} else { |
279 | 290 |
this.band = null; |
... | ... | |
282 | 293 |
|
283 | 294 |
@Override |
284 | 295 |
public boolean hasNext() { |
285 |
return this.current < getBandCount() ;
|
|
296 |
return this.current < getBandCount(); |
|
286 | 297 |
} |
287 | 298 |
|
288 | 299 |
@Override |
Also available in: Unified diff