Statistics
| Revision:

svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / main / java / org / gvsig / raster / lib / legend / spi / AbstractColoredOperation.java @ 43866

History | View | Annotate | Download (6.53 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.legend.spi;
24

    
25
import java.util.ArrayList;
26
import java.util.List;
27
import org.gvsig.raster.lib.buffer.api.NoData;
28
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException;
29
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory;
30
import org.gvsig.raster.lib.buffer.spi.exceptions.ProcessingOperationException;
31
import org.gvsig.raster.lib.buffer.spi.operations.AbstractOperation;
32
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
33
import org.gvsig.raster.lib.legend.api.operations.ColoredOperation;
34

    
35

    
36
/**
37
 * @author fdiaz
38
 *
39
 */
40
public abstract class AbstractColoredOperation extends AbstractOperation implements ColoredOperation {
41

    
42
    private ColorInterpretation colorInterpretation;
43
    private ColorInterpretation outputColorInterpretation;
44

    
45

    
46
    /**
47
     *
48
     * @param factory
49
     */
50
    public AbstractColoredOperation(OperationFactory factory) {
51
        super(factory);
52
    }
53

    
54
    protected ColorInterpretation getInputColorInterpretation() {
55
        return this.colorInterpretation;
56
    }
57
    
58
    protected ColorInterpretation getOutputColorInterpretation() {
59
        return this.outputColorInterpretation;
60
    }
61
    
62
    protected void setOutputColorInterpretation(ColorInterpretation theColorInterpretation) {
63
        this.outputColorInterpretation = theColorInterpretation;
64
    }
65
    
66
    @Override
67
    public void preProcess() throws BufferOperationException {
68
        super.preProcess();
69
        colorInterpretation = (ColorInterpretation) this.getParameters().getDynValue(COLOR_INTERPRETATION_PARAM);
70
    }
71

    
72
    @Override
73
    public void process() throws ProcessingOperationException {
74
        super.process();
75
    }
76

    
77
    @Override
78
    public void postProcess() throws BufferOperationException {
79
        super.postProcess();
80
    }
81
    
82
    protected boolean isProcessableBand(int band) {
83
        // By default all bands are processables.
84
        return true;
85
    }
86
    
87
    /**
88
     * This is a utility method that return a list of the ColorInterpretation for 
89
     * the processable bands of the input buffer.
90
     * 
91
     * @return List of ColorInterpretation
92
     */
93
    protected List<String> getProcessableBandColorInterpretations() {
94
        int bands = this.getInputBuffer().getBandCount();
95
        List<String> colorInterpretations = new ArrayList<>();
96
        for (int band = 0; band < bands; band++) {
97
            if (this.isProcessableBand(band)) {
98
                colorInterpretations.add(colorInterpretation.get(band));
99
            }
100
        }
101
        if (colorInterpretation.hasAlphaBand()) {
102
            colorInterpretations.add(ColorInterpretation.ALPHA_BAND);
103
        }
104
        return colorInterpretations;
105
    }
106
    
107
    /**
108
     * This is a utility method that return a copy of the ColorInterpretation for 
109
     * the processable band of the input buffer.
110
     * 
111
     * @return array of ColorInterpretation
112
     */
113
    protected String[] getProcessableBandColorInterpretationsAsArray() {
114
        List<String> l = this.getProcessableBandColorInterpretations();
115
        String[] colorInterpretations = getColorInterpretationsAsArray(l);
116
        return colorInterpretations;
117
    }
118

    
119
    private String[] getColorInterpretationsAsArray(List<String> theColorInterpretations) {
120
        String[] colorInterpretations = theColorInterpretations.toArray(new String[theColorInterpretations.size()]);
121
        return colorInterpretations;
122
    }
123
    
124
    /**
125
     * This is a utility method that return a copy of the NoData of 
126
     * the processable band of the input buffer.
127
     * 
128
     * @return List of NoDatas
129
     */
130
    protected List<NoData> getProcessableBandNoDatas() {
131
        int bands = this.getInputBuffer().getBandCount();
132
        List<NoData> noDatas = new ArrayList<>();
133
        for (int band = 0; band < bands; band++) {
134
            if (this.isProcessableBand(band)) {
135
                noDatas.add(this.getInputBuffer().getBandNoData()[band]);
136
            }
137
        }
138
        return noDatas;
139
    }
140
    
141
    /**
142
     * This is a utility method that return a copy of the NoData of 
143
     * the processable band of the input buffer.
144
     * 
145
     * @return array of NoDatas
146
     */
147
    protected NoData[] getProcessableBandNoDatasAsArray() {
148
        List<NoData> l = this.getProcessableBandNoDatas();
149
        NoData[] noDatas = this.getNoDatasAsArray(l);
150
        return noDatas;
151
    }
152
    
153
    protected NoData[] getNoDatasAsArray(List<NoData> theNoDatas) {
154
        NoData[] noDatas = theNoDatas.toArray(new NoData[theNoDatas.size()]);
155
        return noDatas;
156
    }
157
    
158
    /**
159
     * This is a utility method that return a copy of the types of 
160
     * the processable band of the input buffer.
161
     * 
162
     * @return list of types
163
     */
164
    protected List<Integer> getProcessableBandTypes() {
165
        int bands = this.getInputBuffer().getBandCount();
166
        List<Integer> types = new ArrayList<>();
167
        for (int band = 0; band < bands; band++) {
168
            if (this.isProcessableBand(band)) {
169
                types.add(this.getInputBuffer().getBandTypes()[band]);
170
            }
171
        }
172
        return types;
173
    }
174
    
175
    /**
176
     * This is a utility method that return a copy of the types of 
177
     * the processable band of the input buffer.
178
     * 
179
     * @return Array of types
180
     */
181
    protected int[] getProcessableBandTypesAsArray() {
182
        int[] types = this.getTypesAsArray(this.getProcessableBandTypes());
183
        return types;
184
    }
185
    
186
    protected int[] getTypesAsArray(List<Integer> theTypes) {
187
        int[] types = new int[theTypes.size()];
188
        int n = 0;
189
        for (Integer type : theTypes) {
190
            types[n++] = type ;
191
        }
192
        return types;
193
    }
194
        
195
}