Revision 43865 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

View differences:

AbstractSpecifiedBandsOperation.java
24 24

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

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

  
......
36 38
 */
37 39
public abstract class AbstractSpecifiedBandsOperation extends AbstractOperation implements SpecifiedBandsOperation {
38 40

  
39
    protected List<Integer> bandsToProcess;
41
    private List<Integer> bandsToProcess;
40 42

  
41 43
    /**
42 44
     *
45
     * @param factory
43 46
     */
44
    public AbstractSpecifiedBandsOperation() {
45
        // TODO Auto-generated constructor stub
47
    public AbstractSpecifiedBandsOperation(OperationFactory factory) {
48
        super(factory);
46 49
    }
47

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

  
56 63
        if(this.bandsToProcess==null) {
57
            bandsToProcess = new ArrayList<Integer>(buffer.getBandCount());
58
        };
59
        if(this.bandsToProcess.size()==0){
60
            for (int i=0; i<buffer.getBandCount(); i++){
64
            bandsToProcess = new ArrayList<>(this.getInputBuffer().getBandCount());
65
        }
66
        if(this.bandsToProcess.isEmpty()){
67
            for (int i=0; i<this.getInputBuffer().getBandCount(); i++){
61 68
                bandsToProcess.add(i);
62 69
            }
63 70
        }
......
82 89
    public void postProcess() throws BufferOperationException {
83 90
        super.postProcess();
84 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
             
85 160
}

Also available in: Unified diff