Revision 43864 branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/operations/mode/ModeOperation.java
ModeOperation.java | ||
---|---|---|
26 | 26 |
import java.util.Iterator; |
27 | 27 |
import java.util.List; |
28 | 28 |
|
29 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
30 | 29 |
import org.gvsig.raster.lib.buffer.api.Band; |
31 | 30 |
import org.gvsig.raster.lib.buffer.api.BufferLocator; |
32 | 31 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
33 | 32 |
import org.gvsig.raster.lib.buffer.api.NoData; |
34 | 33 |
import org.gvsig.raster.lib.buffer.api.exceptions.BandException; |
35 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferException; |
|
36 | 34 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException; |
37 | 35 |
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory; |
38 | 36 |
import org.gvsig.raster.lib.buffer.api.statistics.Statistics; |
39 | 37 |
import org.gvsig.raster.lib.buffer.spi.exceptions.ProcessingOperationException; |
40 | 38 |
import org.gvsig.raster.lib.buffer.spi.operations.AbstractSpecifiedBandsOperation; |
41 |
import org.gvsig.tools.locator.LocatorException; |
|
42 | 39 |
|
43 | 40 |
|
44 | 41 |
/** |
... | ... | |
60 | 57 |
* |
61 | 58 |
*/ |
62 | 59 |
public ModeOperation(OperationFactory factory) { |
63 |
this.factory = factory;
|
|
60 |
super(factory);
|
|
64 | 61 |
} |
65 |
|
|
62 |
|
|
66 | 63 |
@Override |
67 | 64 |
public void preProcess() throws BufferOperationException { |
68 | 65 |
super.preProcess(); |
69 | 66 |
BufferManager manager = BufferLocator.getBufferManager(); |
70 | 67 |
|
71 |
if(this.parameters.getDynClass().getDynField(SIDE_WINDOW_PARAM)!=null) { |
|
72 |
sideWindow = (Integer)this.parameters.getDynValue(SIDE_WINDOW_PARAM); |
|
73 |
} else { |
|
74 |
sideWindow = 3; |
|
75 |
}; |
|
68 |
sideWindow = (int) this.getParameter(SIDE_WINDOW_PARAM, 3); |
|
76 | 69 |
halfSideWindow = (int)(sideWindow/2); |
77 | 70 |
|
78 |
int bands = this.buffer.getBandCount(); |
|
79 |
NoData[] noData = this.buffer.getBandNoData(); |
|
80 |
if (copyUnprocessedBands) { |
|
71 |
if (mustCopyUnprocessedBands()) { |
|
81 | 72 |
try { |
82 |
this.outputBuffer = |
|
83 |
manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), this.buffer.getBandTypes(), |
|
84 |
this.buffer.getBandNoData(), this.buffer.getProjection(), this.buffer.getEnvelope()); |
|
85 |
} catch (LocatorException | BufferException | CreateEnvelopeException e) { |
|
73 |
this.setOutputBuffer( |
|
74 |
manager.createBuffer( |
|
75 |
this.getInputBuffer().getRows(), |
|
76 |
this.getInputBuffer().getColumns(), |
|
77 |
this.getInputBuffer().getBandTypes(), |
|
78 |
this.getInputBuffer().getBandNoData(), |
|
79 |
this.getInputBuffer().getProjection(), |
|
80 |
this.getInputBuffer().getEnvelope())); |
|
81 |
} catch (Exception e) { |
|
86 | 82 |
throw new ProcessingOperationException(e); |
87 | 83 |
} |
88 |
} else { |
|
89 |
List<NoData> noDatas = new ArrayList<NoData>(); |
|
90 |
List<Integer> types = new ArrayList<Integer>(); |
|
91 |
for (int band = 0; band < bands; band++) { |
|
92 |
if (isProcessableBand(band)) { |
|
93 |
noDatas.add(this.buffer.getBandNoData()[band]); |
|
94 |
types.add(this.buffer.getBandTypes()[band]); |
|
95 |
} |
|
96 |
} |
|
97 |
int[] typesInt = new int[types.size()]; |
|
98 |
for (Iterator<Integer> iterator = types.iterator(); iterator.hasNext();) { |
|
99 |
int i = 0; |
|
100 |
Integer type = (Integer) iterator.next(); |
|
101 |
typesInt[i] = type.intValue(); |
|
102 |
} |
|
84 |
} else { |
|
103 | 85 |
try { |
104 |
this.outputBuffer = |
|
105 |
manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), typesInt, |
|
106 |
noDatas.toArray(new NoData[0]), this.buffer.getProjection(), this.buffer.getEnvelope()); |
|
107 |
} catch (LocatorException | BufferException | CreateEnvelopeException e) { |
|
86 |
this.setOutputBuffer( |
|
87 |
manager.createBuffer( |
|
88 |
this.getInputBuffer().getRows(), |
|
89 |
this.getInputBuffer().getColumns(), |
|
90 |
this.getProcessableBandTypesAsArray(), |
|
91 |
this.getProcessableBandNoDatasAsArray(), |
|
92 |
this.getInputBuffer().getProjection(), |
|
93 |
this.getInputBuffer().getEnvelope())); |
|
94 |
} catch (Exception e) { |
|
108 | 95 |
throw new ProcessingOperationException(e); |
109 | 96 |
} |
110 | 97 |
} |
111 | 98 |
|
99 |
int bands = this.getInputBuffer().getBandCount(); |
|
112 | 100 |
rowProcessors = new RowProcessor[bands]; |
113 |
for (int band = 0; band < noData.length; band++) {
|
|
101 |
for (int band = 0; band < bands; band++) {
|
|
114 | 102 |
if (isProcessableBand(band)) { |
115 |
int bandType = this.buffer.getBand(band).getDataType();
|
|
103 |
int bandType = this.getInputBuffer().getBand(band).getDataType();
|
|
116 | 104 |
switch (bandType) { |
117 | 105 |
case BufferManager.TYPE_BYTE: |
118 | 106 |
rowProcessors[band] = new ByteRowProcessor(band); |
... | ... | |
142 | 130 |
@Override |
143 | 131 |
public void process() throws ProcessingOperationException { |
144 | 132 |
super.process(); |
145 |
for (int band=0; band<this.buffer.getBandCount(); band++){
|
|
146 |
if (bandsToProcess.contains(band)) {
|
|
147 |
Band bufferBand = this.buffer.getBand(band);
|
|
148 |
Band outputBufferBand = this.outputBuffer.getBand(band);
|
|
133 |
for (int band=0; band<this.getInputBuffer().getBandCount(); band++){
|
|
134 |
if (getBandsToProcess().contains(band)) {
|
|
135 |
Band bufferBand = this.getInputBuffer().getBand(band);
|
|
136 |
Band outputBufferBand = this.getOutputBuffer().getBand(band);
|
|
149 | 137 |
|
150 |
for (int row = 0; row < this.buffer.getRows(); row++) {
|
|
138 |
for (int row = 0; row < this.getInputBuffer().getRows(); row++) {
|
|
151 | 139 |
Object rowBuffer = bufferBand.createRowBuffer(); |
152 | 140 |
bufferBand.fetchRow(row, rowBuffer); |
153 |
List<Object> bundle = new ArrayList<Object>(); |
|
154 |
for(int r=Math.max(row-halfSideWindow,0); r<=Math.min(row+halfSideWindow,this.buffer.getRows()-1);r++){ |
|
141 |
List<Object> bundle = new ArrayList<>(); |
|
142 |
int maxr = Math.min(row+halfSideWindow,this.getInputBuffer().getRows()-1); |
|
143 |
for(int r=Math.max(row-halfSideWindow,0); r<=maxr;r++){ |
|
155 | 144 |
Object bundleRow = bufferBand.createRowBuffer(); |
156 | 145 |
bufferBand.fetchRow(row, bundleRow); |
157 | 146 |
bundle.add(bundleRow); |
... | ... | |
165 | 154 |
outputBufferBand.putRow(row, outputRowBuffer); |
166 | 155 |
} |
167 | 156 |
} else { |
168 |
if(copyUnprocessedBands){
|
|
157 |
if(mustCopyUnprocessedBands()){
|
|
169 | 158 |
try { |
170 |
this.outputBuffer.getBand(band).copyFrom(this.buffer.getBand(band));
|
|
159 |
this.getOutputBuffer().getBand(band).copyFrom(this.getInputBuffer().getBand(band));
|
|
171 | 160 |
} catch (BandException e) { |
172 | 161 |
throw new ProcessingOperationException(e); |
173 | 162 |
} |
... | ... | |
192 | 181 |
|
193 | 182 |
public AbstractRowProcessor(int band) { |
194 | 183 |
this.band = band; |
195 |
noData = buffer.getBand(band).getNoData();
|
|
184 |
noData = getInputBuffer().getBand(band).getNoData();
|
|
196 | 185 |
} |
197 | 186 |
} |
198 | 187 |
|
... | ... | |
208 | 197 |
byte[] inputByteRow = (byte[])inputRow; |
209 | 198 |
byte[] outputByteRow = (byte[])outputRow; |
210 | 199 |
for (int i = 0; i < inputByteRow.length; i++) { |
211 |
List<Number> kernel = new ArrayList<Number>();
|
|
200 |
List<Number> kernel = new ArrayList<>(); |
|
212 | 201 |
for (Iterator<Object> iterator = bundleRow.iterator(); iterator.hasNext();) { |
213 | 202 |
byte[] row = (byte[]) iterator.next(); |
214 | 203 |
for(int c=Math.max(i-halfSideWindow,0); c<=Math.min(i+halfSideWindow,inputByteRow.length-1);c++){ |
215 |
Integer value = 0xFF & ((Byte) row[c]).byteValue();
|
|
204 |
Integer value = 0xFF & ((Byte) row[c]); |
|
216 | 205 |
if(noData.isDefined() && noData.getValue().equals(value)){ |
217 | 206 |
continue; |
218 | 207 |
} else { |
Also available in: Unified diff