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/convolution/ConvolutionOperation.java

View differences:

ConvolutionOperation.java
83 83
     *
84 84
     */
85 85
    public ConvolutionOperation(OperationFactory factory) {
86
        this.factory = factory;
86
        super(factory);
87 87
    }
88 88

  
89 89
    @Override
......
91 91
        super.preProcess();
92 92
        BufferManager manager = BufferLocator.getBufferManager();
93 93

  
94
        if(this.parameters.getDynClass().getDynField(SIDE_WINDOW_PARAM)!=null) {
95
            sideWindow = (Integer)this.parameters.getDynValue(SIDE_WINDOW_PARAM);
96
        } else {
97
            sideWindow = 3;
98
        };
94
        sideWindow = (int) this.getParameter(SIDE_WINDOW_PARAM, 3);
99 95
        halfSideWindow = (int)(sideWindow/2);
96
        sharpness = (double) this.getParameter(SHARPNESS_PARAM, 0);
97
        operator = (String) this.getParameter(OPERATOR_PARAM, AVERAGE_OPERATOR_STRING);
100 98

  
101

  
102
        if(this.parameters.getDynClass().getDynField(SHARPNESS_PARAM)!=null) {
103
            sharpness = (Double)this.parameters.getDynValue(SHARPNESS_PARAM);
104
        } else {
105
            sharpness = 0;
106
        };
107

  
108
        if(this.parameters.getDynClass().getDynField(OPERATOR_PARAM)!=null) {
109
            operator = (String)this.parameters.getDynValue(OPERATOR_PARAM);
110
        } else {
111
            operator = AVERAGE_OPERATOR_STRING;
112
        };
113

  
114 99
        switch (operator) {
115 100
        case AVERAGE_OPERATOR_STRING:
116 101
            switch (sideWindow) {
......
172 157
            }
173 158
            break;
174 159
        case CUSTOM_OPERATOR_STRING:
175
            if(this.parameters.getDynClass().getDynField(CUSTOM_KERNEL_PARAM)!=null) {
176
                kernelOperator = (Kernel)this.parameters.getDynValue(CUSTOM_KERNEL_PARAM);
177
            } else {
160
            kernelOperator = (Kernel) this.getParameter(CUSTOM_KERNEL_PARAM, null);
161
            if(kernelOperator==null) {
178 162
                throw new IllegalArgumentException("A Kernel is needed for the selected operator.");
179 163
            };
180
            if(kernelOperator==null || kernelOperator.getSide()!=sideWindow){
164
            if( kernelOperator.getSide()!=sideWindow){
181 165
                throw new IllegalArgumentException("Kernel side incorrect.");
182 166
            };
183 167
            break;
184 168
        }
185 169

  
186
        int bands = this.buffer.getBandCount();
187
        NoData[] noData = this.buffer.getBandNoData();
188
        if (copyUnprocessedBands) {
170
        int bands = this.getInputBuffer().getBandCount();
171
        NoData[] noData = this.getInputBuffer().getBandNoData();
172
        if (mustCopyUnprocessedBands()) {
189 173
            try {
190
                this.outputBuffer =
191
                    manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), this.buffer.getBandTypes(),
192
                        this.buffer.getBandNoData(), this.buffer.getProjection(), this.buffer.getEnvelope());
174
                this.setOutputBuffer(
175
                    manager.createBuffer(
176
                            this.getInputBuffer().getRows(), 
177
                            this.getInputBuffer().getColumns(), 
178
                            this.getInputBuffer().getBandTypes(),
179
                            this.getInputBuffer().getBandNoData(), 
180
                            this.getInputBuffer().getProjection(), 
181
                            this.getInputBuffer().getEnvelope()));
193 182
            } catch (LocatorException | BufferException | CreateEnvelopeException e) {
194 183
                throw new ProcessingOperationException(e);
195 184
            }
196 185
        } else {
197
            List<NoData> noDatas = new ArrayList<NoData>();
198
            List<Integer> types = new ArrayList<Integer>();
199
            for (int band = 0; band < bands; band++) {
200
                if (isProcessableBand(band)) {
201
                    if(this.buffer.getBandNoData()[band].isDefined()){
202
                        noDatas.add(manager.createNoData(0, 0));
203
                    } else {
204
                        noDatas.add(null);
205
                    }
206
                    types.add(BufferManager.TYPE_BYTE);
207
                }
208
            }
209
            int[] typesInt = new int[types.size()];
210
            for (Iterator<Integer> iterator = types.iterator(); iterator.hasNext();) {
211
                int i = 0;
212
                Integer type = (Integer) iterator.next();
213
                typesInt[i] = type.intValue();
214
            }
215 186
            try {
216
                this.outputBuffer =
217
                    manager.createBuffer(this.buffer.getRows(), this.buffer.getColumns(), typesInt,
218
                        noDatas.toArray(new NoData[0]), this.buffer.getProjection(), this.buffer.getEnvelope());
187
                this.setOutputBuffer(
188
                    manager.createBuffer(
189
                            this.getInputBuffer().getRows(), 
190
                            this.getInputBuffer().getColumns(), 
191
                            this.getProcessableBandTypesAsArray(),
192
                            this.getProcessableBandNoDatasAsArray(), 
193
                            this.getInputBuffer().getProjection(), 
194
                            this.getInputBuffer().getEnvelope()));
219 195
            } catch (LocatorException | BufferException | CreateEnvelopeException e) {
220 196
                throw new ProcessingOperationException(e);
221 197
            }
......
224 200
        rowProcessors = new RowProcessor[bands];
225 201
        for (int band = 0; band < noData.length; band++) {
226 202
            if (isProcessableBand(band)) {
227
                int bandType = this.buffer.getBand(band).getDataType();
203
                int bandType = this.getInputBuffer().getBand(band).getDataType();
228 204
                switch (bandType) {
229 205
                case BufferManager.TYPE_BYTE:
230 206
                    rowProcessors[band] = new ByteRowProcessor(band);
......
254 230
    @Override
255 231
    public void process() throws ProcessingOperationException {
256 232
        super.process();
257
        for (int band=0; band<this.buffer.getBandCount(); band++){
258
            if (bandsToProcess.contains(band)) {
259
                Band bufferBand = this.buffer.getBand(band);
260
                Band outputBufferBand = this.outputBuffer.getBand(band);
233
        for (int band=0; band<this.getInputBuffer().getBandCount(); band++){
234
            if (getBandsToProcess().contains(band)) {
235
                Band bufferBand = this.getInputBuffer().getBand(band);
236
                Band outputBufferBand = this.getOutputBuffer().getBand(band);
261 237

  
262
                for (int row = 0; row < this.buffer.getRows(); row++) {
238
                for (int row = 0; row < this.getInputBuffer().getRows(); row++) {
263 239
                    Object rowBuffer = bufferBand.createRowBuffer();
264 240
                    bufferBand.fetchRow(row, rowBuffer);
265
                    List<Object> bundle = new ArrayList<Object>();
241
                    List<Object> bundle = new ArrayList<>();
266 242
                    //FIXME: Solo se procesan aquellas filas en las que se pueden crear kernels, el resto ?qu? hacer? (ver abajo)
267
                    if ((row - halfSideWindow >= 0) && (row + halfSideWindow < this.buffer.getRows())) {
243
                    if ((row - halfSideWindow >= 0) && (row + halfSideWindow < this.getInputBuffer().getRows())) {
268 244
                        for (int r = Math.max(row - halfSideWindow, 0); r <= Math.min(row + halfSideWindow,
269
                            this.buffer.getRows()-1); r++) {
245
                            this.getInputBuffer().getRows()-1); r++) {
270 246
                            Object bundleRow = bufferBand.createRowBuffer();
271 247
                            bufferBand.fetchRow(r, bundleRow);
272 248
                            bundle.add(bundleRow);
......
280 256
                        outputBufferBand.putRow(row, outputRowBuffer);
281 257
                    } else {
282 258
                        // FIXME: Si son de tipo BYTE, las copio, si no, no hacemos nada
283
                        if(this.buffer.getBandTypes()[band]==BufferManager.TYPE_BYTE){
259
                        if(this.getInputBuffer().getBandTypes()[band]==BufferManager.TYPE_BYTE){
284 260
                            outputBufferBand.putRow(row, rowBuffer);
285 261
                        }
286 262
                    }
287 263
                }
288 264
            } else {
289
                if(copyUnprocessedBands){
265
                if(mustCopyUnprocessedBands()){
290 266
                    try {
291
                        this.outputBuffer.getBand(band).copyFrom(this.buffer.getBand(band));
267
                        this.getOutputBuffer().getBand(band).copyFrom(this.getInputBuffer().getBand(band));
292 268
                    } catch (BandException e) {
293 269
                        throw new ProcessingOperationException(e);
294 270
                    }
......
313 289

  
314 290
        public AbstractRowProcessor(int band) {
315 291
            this.band = band;
316
            noData = buffer.getBand(band).getNoData();
292
            noData = getInputBuffer().getBand(band).getNoData();
317 293
        }
318 294

  
319 295
        @Override
......
350 326
                        byte[] row = (byte[]) iterator.next();
351 327
                        for (int column = Math.max(i - halfSideWindow, 0); column <= Math.min(i + halfSideWindow,
352 328
                            inputByteRow.length-1); column++) {
353
                            byte value = ((Byte) row[column]).byteValue();
329
                            byte value = ((Byte) row[column]);
354 330
                            if (noData.isDefined() && noData.getValue().equals(value)) {
355 331
                                //FIXME: Si es noData, deber?a no influir en el resultado
356 332
                                // ?Que valor poner en el kernel?
......
395 371
                        short[] row = (short[]) iterator.next();
396 372
                        for (int column = Math.max(i - halfSideWindow, 0); column <= Math.min(i + halfSideWindow,
397 373
                            inputShortRow.length-1); column++) {
398
                            double value = ((Short) row[c]).shortValue();
374
                            double value = ((Short) row[c]);
399 375
                            if (noData.isDefined() && noData.getValue().equals(value)) {
400 376
                                //FIXME: Si es noData, deber?a no influir en el resultado
401 377
                                // ?Que valor poner en el kernel?
......
437 413
                        short[] row = (short[]) iterator.next();
438 414
                        for (int column = Math.max(i - halfSideWindow, 0); column <= Math.min(i + halfSideWindow,
439 415
                            inputShortRow.length-1); column++) {
440
                            double value = 0xFFFF & ((Short) row[c]).shortValue();
416
                            double value = 0xFFFF & ((Short) row[c]);
441 417
                            if (noData.isDefined() && noData.getValue().equals(value)) {
442 418
                                // FIXME: Si es noData, deber?a no influir en el
443 419
                                // resultado
......
479 455
                        int[] row = (int[]) iterator.next();
480 456
                        for (int column = Math.max(i - halfSideWindow, 0); column <= Math.min(i + halfSideWindow,
481 457
                            inputIntRow.length-1); column++) {
482
                            double value = ((Integer) row[c]).intValue();
458
                            double value = ((Integer) row[c]);
483 459
                            if (noData.isDefined() && noData.getValue().equals(value)) {
484 460
                                // FIXME: Si es noData, deber?a no influir en el
485 461
                                // resultado
......
520 496
                        float[] row = (float[]) iterator.next();
521 497
                        for (int column = Math.max(i - halfSideWindow, 0); column <= Math.min(i + halfSideWindow,
522 498
                            inputFloatRow.length-1); column++) {
523
                            Float value = ((Float) row[c]).floatValue();
499
                            Float value = ((Float) row[c]);
524 500
                            if (noData.isDefined() && noData.getValue().equals(value)) {
525 501
                                // FIXME: Si es noData, deber?a no influir en el
526 502
                                // resultado
......
561 537
                        double[] row = (double[]) iterator.next();
562 538
                        for (int column = Math.max(i - halfSideWindow, 0); column <= Math.min(i + halfSideWindow,
563 539
                            inputDoubleRow.length-1); column++) {
564
                            Double value = ((Double) row[c]).doubleValue();
540
                            Double value = ((Double) row[c]);
565 541
                            if (noData.isDefined() && noData.getValue().equals(value)) {
566 542
                                // FIXME: Si es noData, deber?a no influir en el resultado
567 543
                                // ?Que valor poner en el kernel?

Also available in: Unified diff