22 |
22 |
*/
|
23 |
23 |
package org.gvsig.raster.lib.legend.spi;
|
24 |
24 |
|
|
25 |
import java.util.ArrayList;
|
|
26 |
import java.util.List;
|
|
27 |
import org.gvsig.raster.lib.buffer.api.NoData;
|
25 |
28 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException;
|
|
29 |
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory;
|
26 |
30 |
import org.gvsig.raster.lib.buffer.spi.exceptions.ProcessingOperationException;
|
27 |
31 |
import org.gvsig.raster.lib.buffer.spi.operations.AbstractOperation;
|
28 |
32 |
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
|
... | ... | |
35 |
39 |
*/
|
36 |
40 |
public abstract class AbstractColoredOperation extends AbstractOperation implements ColoredOperation {
|
37 |
41 |
|
38 |
|
protected ColorInterpretation colorInterpretation;
|
39 |
|
protected ColorInterpretation outputColorInterpretation;
|
|
42 |
private ColorInterpretation colorInterpretation;
|
|
43 |
private ColorInterpretation outputColorInterpretation;
|
40 |
44 |
|
41 |
45 |
|
42 |
46 |
/**
|
43 |
47 |
*
|
|
48 |
* @param factory
|
44 |
49 |
*/
|
45 |
|
public AbstractColoredOperation() {
|
46 |
|
// Nothing to do
|
|
50 |
public AbstractColoredOperation(OperationFactory factory) {
|
|
51 |
super(factory);
|
47 |
52 |
}
|
48 |
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 |
|
49 |
66 |
@Override
|
50 |
67 |
public void preProcess() throws BufferOperationException {
|
51 |
68 |
super.preProcess();
|
52 |
|
colorInterpretation = (ColorInterpretation) this.parameters.getDynValue(COLOR_INTERPRETATION_PARAM);
|
|
69 |
colorInterpretation = (ColorInterpretation) this.getParameters().getDynValue(COLOR_INTERPRETATION_PARAM);
|
53 |
70 |
}
|
54 |
71 |
|
55 |
72 |
@Override
|
... | ... | |
61 |
78 |
public void postProcess() throws BufferOperationException {
|
62 |
79 |
super.postProcess();
|
63 |
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 |
}
|
64 |
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 |
|
65 |
195 |
}
|