Statistics
| Revision:

svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.library / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.buffer.spi / src / main / java / org / gvsig / raster / lib / buffer / spi / operations / AbstractSpecifiedBandsOperation.java @ 43865

History | View | Annotate | Download (4.92 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2018 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.raster.lib.buffer.spi.operations;
24

    
25
import java.util.ArrayList;
26
import java.util.List;
27
import org.gvsig.raster.lib.buffer.api.Buffer;
28
import org.gvsig.raster.lib.buffer.api.NoData;
29

    
30
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException;
31
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory;
32
import org.gvsig.raster.lib.buffer.api.operations.SpecifiedBandsOperation;
33
import org.gvsig.raster.lib.buffer.spi.exceptions.ProcessingOperationException;
34

    
35
/**
36
 * @author fdiaz
37
 *
38
 */
39
public abstract class AbstractSpecifiedBandsOperation extends AbstractOperation implements SpecifiedBandsOperation {
40

    
41
    private List<Integer> bandsToProcess;
42

    
43
    /**
44
     *
45
     * @param factory
46
     */
47
    public AbstractSpecifiedBandsOperation(OperationFactory factory) {
48
        super(factory);
49
    }
50
    
51
    public List<Integer> getBandsToProcess() {
52
        return this.bandsToProcess;
53
    }
54
    
55
    @SuppressWarnings("unchecked")
56
    @Override
57
    public void preProcess() throws BufferOperationException {
58
        super.preProcess();
59
        if(this.getParameters().getDynClass().getDynField(BANDS_TO_PROCESS_PARAM)!=null) {
60
            bandsToProcess = (List<Integer>)this.getParameters().getDynValue(BANDS_TO_PROCESS_PARAM);
61
        }
62

    
63
        if(this.bandsToProcess==null) {
64
            bandsToProcess = new ArrayList<>(this.getInputBuffer().getBandCount());
65
        }
66
        if(this.bandsToProcess.isEmpty()){
67
            for (int i=0; i<this.getInputBuffer().getBandCount(); i++){
68
                bandsToProcess.add(i);
69
            }
70
        }
71
    }
72

    
73

    
74
    /**
75
     * @param band
76
     * @return
77
     */
78
    protected boolean isProcessableBand(int band) {
79
        return bandsToProcess.contains(band);
80
    }
81

    
82

    
83
    @Override
84
    public void process() throws ProcessingOperationException {
85
        super.process();
86
    }
87

    
88
    @Override
89
    public void postProcess() throws BufferOperationException {
90
        super.postProcess();
91
    }
92
    
93

    
94
    /**
95
     * This is a utility method that return a copy of the NoData of 
96
     * the processable band of the input buffer.
97
     * 
98
     * @return List of NoDatas
99
     */
100
    protected List<NoData> getProcessableBandNoDatas() {
101
        int bands = this.getInputBuffer().getBandCount();
102
        List<NoData> noDatas = new ArrayList<>();
103
        for (int band = 0; band < bands; band++) {
104
            if (this.isProcessableBand(band)) {
105
                noDatas.add(this.getInputBuffer().getBandNoData()[band]);
106
            }
107
        }
108
        return noDatas;
109
    }
110
    
111
    /**
112
     * This is a utility method that return a copy of the NoData of 
113
     * the processable band of the input buffer.
114
     * 
115
     * @return array of NoDatas
116
     */
117
    protected NoData[] getProcessableBandNoDatasAsArray() {
118
        List<NoData> l = this.getProcessableBandNoDatas();
119
        NoData[] noDatas = l.toArray(new NoData[l.size()]);
120
        return noDatas;
121
    }
122
    
123
    /**
124
     * This is a utility method that return a copy of the types of 
125
     * the processable band of the input buffer.
126
     * 
127
     * @return list of types
128
     */
129
    protected List<Integer> getProcessableBandTypes() {
130
        int bands = this.getInputBuffer().getBandCount();
131
        List<Integer> types = new ArrayList<>();
132
        for (int band = 0; band < bands; band++) {
133
            if (this.isProcessableBand(band)) {
134
                types.add(this.getInputBuffer().getBandTypes()[band]);
135
            }
136
        }
137
        return types;
138
    }
139
    
140
    /**
141
     * This is a utility method that return a copy of the types of 
142
     * the processable band of the input buffer.
143
     * 
144
     * @return Array of types
145
     */
146
    protected int[] getProcessableBandTypesAsArray() {
147
        int[] types = this.getTypesAsArray(this.getProcessableBandTypes());
148
        return types;
149
    }
150
    
151
    protected int[] getTypesAsArray(List<Integer> theTypes) {
152
        int[] types = new int[theTypes.size()];
153
        int n = 0;
154
        for (Integer type : theTypes) {
155
            types[n++] = type ;
156
        }
157
        return types;
158
    }
159
             
160
}