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/tailtrim/TailTrimOperation.java

View differences:

TailTrimOperation.java
33 33
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory;
34 34
import org.gvsig.raster.lib.buffer.api.statistics.Statistics;
35 35
import org.gvsig.raster.lib.buffer.spi.exceptions.ProcessingOperationException;
36
import org.gvsig.raster.lib.buffer.spi.operations.AbstractOperation;
37 36
import org.gvsig.raster.lib.buffer.spi.operations.AbstractSpecifiedBandsOperation;
38 37
import org.gvsig.tools.locator.LocatorException;
39 38

  
......
56 55
     *
57 56
     */
58 57
    public TailTrimOperation(OperationFactory factory) {
59
        this.factory = factory;
58
        super(factory);
60 59
    }
61 60

  
62 61
    @SuppressWarnings("unchecked")
......
65 64
        super.preProcess();
66 65
        BufferManager manager = BufferLocator.getBufferManager();
67 66

  
68
        if(this.parameters.getDynClass().getDynField(STATISTICS_PARAM)!=null) {
69
            statistics = (Statistics) this.parameters.getDynValue(STATISTICS_PARAM);
70
        }
67
        statistics = (Statistics) this.getParameter(STATISTICS_PARAM, null);
71 68
        if (statistics == null) {
72
            statistics = this.buffer.getStatistics(null);
69
            statistics = this.getInputBuffer().getStatistics(null);
73 70
        };
74
        if(this.parameters.getDynClass().getDynField(TAIL_TRIM_PERCENT_PARAM)!=null) {
75
            tailTrimPercent = (Double)this.parameters.getDynValue(TAIL_TRIM_PERCENT_PARAM);
76
            tailTrimPercent = (tailTrimPercent>100)?100:tailTrimPercent;
77
            tailTrimPercent = (tailTrimPercent<0)?0:tailTrimPercent;
78
        } else {
79
            tailTrimPercent = 0; // FIXME: ?0 o 100?
80
        };
71
        tailTrimPercent = (double) this.getParameter(TAIL_TRIM_PERCENT_PARAM, 0);
72
        tailTrimPercent = (tailTrimPercent>100)?100:tailTrimPercent;
73
        tailTrimPercent = (tailTrimPercent<0)?0:tailTrimPercent;
81 74

  
82 75
        //FIXME: Falta la gesti?n del par?metro copyUnprocessedBands, de momento se copian sin tenerlo en cuenta
83 76

  
84
        int bands = this.buffer.getBandCount();
77
        int bands = this.getInputBuffer().getBandCount();
85 78
        rowProcessors = new RowProcessor[bands];
86 79
        int [] bandTypes = new int[bands];
87 80
        for (int i = 0; i < bandTypes.length; i++) {
88
            bandTypes[i] = this.buffer.getBandTypes()[i];
81
            bandTypes[i] = this.getInputBuffer().getBandTypes()[i];
89 82
        }
90
        NoData[] noData = this.buffer.getBandNoData();
83
        NoData[] noData = this.getInputBuffer().getBandNoData();
91 84
        NoData[] resultNoData = new NoData[noData.length];
92 85
        for (int band = 0; band < noData.length; band++) {
93
            int bandType = this.buffer.getBand(band).getDataType();
86
            int bandType = this.getInputBuffer().getBand(band).getDataType();
94 87
            switch (bandType) {
95 88
            case BufferManager.TYPE_BYTE:
96 89
                rowProcessors[band] = new ByteRowProcessor(band);
......
159 152
        }
160 153

  
161 154
        try {
162
            this.outputBuffer = manager.createBuffer(
163
                this.buffer.getRows(),
164
                this.buffer.getColumns(),
155
            this.setOutputBuffer(manager.createBuffer(
156
                this.getInputBuffer().getRows(),
157
                this.getInputBuffer().getColumns(),
165 158
                bandTypes,
166 159
                resultNoData,
167
                this.buffer.getProjection(),
168
                this.buffer.getEnvelope());
160
                this.getInputBuffer().getProjection(),
161
                this.getInputBuffer().getEnvelope()));
169 162
        } catch (LocatorException | BufferException | CreateEnvelopeException e) {
170 163
            throw new BufferOperationException(e);
171 164
        }
......
174 167
    @Override
175 168
    public void process() throws ProcessingOperationException {
176 169
        super.process();
177
        for (int band=0; band<this.buffer.getBandCount(); band++){
178
            if (bandsToProcess.contains(band)) {
179
                Band bufferBand = this.buffer.getBand(band);
180
                Band outputBufferBand = this.outputBuffer.getBand(band);
170
        for (int band=0; band<this.getInputBuffer().getBandCount(); band++){
171
            if (getBandsToProcess().contains(band)) {
172
                Band bufferBand = this.getInputBuffer().getBand(band);
173
                Band outputBufferBand = this.getOutputBuffer().getBand(band);
181 174

  
182
                for (int row = 0; row < this.buffer.getRows(); row++) {
175
                for (int row = 0; row < this.getInputBuffer().getRows(); row++) {
183 176
                    Object rowBuffer = bufferBand.createRowBuffer();
184 177
                    bufferBand.fetchRow(row, rowBuffer);
185 178

  
......
192 185
                }
193 186
            } else {
194 187
                try {
195
                    this.outputBuffer.getBand(band).copyFrom(this.buffer.getBand(band));
188
                    this.getOutputBuffer().getBand(band).copyFrom(this.getInputBuffer().getBand(band));
196 189
                } catch (BandException e) {
197 190
                    throw new ProcessingOperationException(e);
198 191
                }
......
219 212

  
220 213
        public AbstractRowProcessor(int band) {
221 214
            this.band = band;
222
            noData = buffer.getBand(band).getNoData();
215
            noData = getInputBuffer().getBand(band).getNoData();
223 216
//            outputNoData = outputBuffer.getBand(band).getNoData();
224 217

  
225 218
            double[][] tailTrim = statistics.getTailTrimValue(tailTrimPercent);
......
248 241
        @Override
249 242
        public Number processValue(Number value) {
250 243
            if(noData.isDefined() && noData.getValue().equals(value)){
251
                return outputBuffer.getBand(band).getNoData().getValue();
244
                return getOutputBuffer().getBand(band).getNoData().getValue();
252 245
            }
253 246

  
254 247
            int iValue = 0xFF & ((Byte) value).byteValue();
255 248

  
256 249
            if(iValue < minValue || iValue > maxValue){
257
                return outputBuffer.getBand(band).getNoData().getValue();
250
                return getOutputBuffer().getBand(band).getNoData().getValue();
258 251
            } else {
259 252
                return value;
260 253
            }
......
280 273
        @Override
281 274
        public Number processValue(Number value) {
282 275
            if(noData.isDefined() && noData.getValue().equals(value)){
283
                return outputBuffer.getBand(band).getNoData().getValue();
276
                return getOutputBuffer().getBand(band).getNoData().getValue();
284 277
            }
285 278

  
286 279
            int iValue = ((Short) value).shortValue();
287 280

  
288 281
            if(iValue < minValue || iValue > maxValue){
289
                return outputBuffer.getBand(band).getNoData().getValue();
282
                return getOutputBuffer().getBand(band).getNoData().getValue();
290 283
            } else {
291 284
                return value;
292 285
            }
......
312 305
        @Override
313 306
        public Number processValue(Number value) {
314 307
            if(noData.isDefined() && noData.getValue().equals(value)){
315
                return outputBuffer.getBand(band).getNoData().getValue();
308
                return getOutputBuffer().getBand(band).getNoData().getValue();
316 309
            }
317 310

  
318 311
            int iValue = 0xFFFF & ((Short) value).shortValue();
319 312

  
320 313
            if(iValue < minValue || iValue > maxValue){
321
                return outputBuffer.getBand(band).getNoData().getValue();
314
                return getOutputBuffer().getBand(band).getNoData().getValue();
322 315
            } else {
323 316
                return value;
324 317
            }
......
344 337
        @Override
345 338
        public Number processValue(Number value) {
346 339
            if(noData.isDefined() && noData.getValue().equals(value)){
347
                return outputBuffer.getBand(band).getNoData().getValue();
340
                return getOutputBuffer().getBand(band).getNoData().getValue();
348 341
            }
349 342
            int iValue = value.intValue();
350 343

  
351 344
            if(iValue < minValue || iValue > maxValue){
352
                return outputBuffer.getBand(band).getNoData().getValue();
345
                return getOutputBuffer().getBand(band).getNoData().getValue();
353 346
            } else {
354 347
                return value;
355 348
            }
......
374 367
        @Override
375 368
        public Number processValue(Number value) {
376 369
            if(noData.isDefined() && noData.getValue().equals(value)){
377
                return outputBuffer.getBand(band).getNoData().getValue();
370
                return getOutputBuffer().getBand(band).getNoData().getValue();
378 371
            }
379 372
            float fValue = value.floatValue();
380 373

  
381 374
            if(fValue < minValue || fValue > maxValue){
382
                return outputBuffer.getBand(band).getNoData().getValue();
375
                return getOutputBuffer().getBand(band).getNoData().getValue();
383 376
            } else {
384 377
                return value;
385 378
            }
......
405 398
        @Override
406 399
        public Number processValue(Number value) {
407 400
            if(noData.isDefined() && noData.getValue().equals(value)){
408
                return outputBuffer.getBand(band).getNoData().getValue();
401
                return getOutputBuffer().getBand(band).getNoData().getValue();
409 402
            }
410 403
            double fValue = value.doubleValue();
411 404

  
412 405
            if(fValue < minValue || fValue > maxValue){
413
                return outputBuffer.getBand(band).getNoData().getValue();
406
                return getOutputBuffer().getBand(band).getNoData().getValue();
414 407
            } else {
415 408
                return value;
416 409
            }

Also available in: Unified diff