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 @ 43867
History | View | Annotate | Download (4.88 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.NoData; |
28 |
|
29 |
import org.gvsig.raster.lib.buffer.api.exceptions.BufferOperationException; |
30 |
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory; |
31 |
import org.gvsig.raster.lib.buffer.api.operations.SpecifiedBandsOperation; |
32 |
import org.gvsig.raster.lib.buffer.spi.exceptions.ProcessingOperationException; |
33 |
|
34 |
/**
|
35 |
* @author fdiaz
|
36 |
*
|
37 |
*/
|
38 |
public abstract class AbstractSpecifiedBandsOperation extends AbstractOperation implements SpecifiedBandsOperation { |
39 |
|
40 |
private List<Integer> bandsToProcess; |
41 |
|
42 |
/**
|
43 |
*
|
44 |
* @param factory
|
45 |
*/
|
46 |
public AbstractSpecifiedBandsOperation(OperationFactory factory) {
|
47 |
super(factory);
|
48 |
} |
49 |
|
50 |
public List<Integer> getBandsToProcess() { |
51 |
return this.bandsToProcess; |
52 |
} |
53 |
|
54 |
@SuppressWarnings("unchecked") |
55 |
@Override
|
56 |
public void preProcess() throws BufferOperationException { |
57 |
super.preProcess();
|
58 |
if(this.getParameters().getDynClass().getDynField(BANDS_TO_PROCESS_PARAM)!=null) { |
59 |
bandsToProcess = (List<Integer>)this.getParameters().getDynValue(BANDS_TO_PROCESS_PARAM); |
60 |
} |
61 |
|
62 |
if(this.bandsToProcess==null) { |
63 |
bandsToProcess = new ArrayList<>(this.getInputBuffer().getBandCount()); |
64 |
} |
65 |
if(this.bandsToProcess.isEmpty()){ |
66 |
for (int i=0; i<this.getInputBuffer().getBandCount(); i++){ |
67 |
bandsToProcess.add(i); |
68 |
} |
69 |
} |
70 |
} |
71 |
|
72 |
|
73 |
/**
|
74 |
* @param band
|
75 |
* @return
|
76 |
*/
|
77 |
protected boolean isProcessableBand(int band) { |
78 |
return bandsToProcess.contains(band);
|
79 |
} |
80 |
|
81 |
|
82 |
@Override
|
83 |
public void process() throws ProcessingOperationException { |
84 |
super.process();
|
85 |
} |
86 |
|
87 |
@Override
|
88 |
public void postProcess() throws BufferOperationException { |
89 |
super.postProcess();
|
90 |
} |
91 |
|
92 |
|
93 |
/**
|
94 |
* This is a utility method that return a copy of the NoData of
|
95 |
* the processable band of the input buffer.
|
96 |
*
|
97 |
* @return List of NoDatas
|
98 |
*/
|
99 |
protected List<NoData> getProcessableBandNoDatas() { |
100 |
int bands = this.getInputBuffer().getBandCount(); |
101 |
List<NoData> noDatas = new ArrayList<>(); |
102 |
for (int band = 0; band < bands; band++) { |
103 |
if (this.isProcessableBand(band)) { |
104 |
noDatas.add(this.getInputBuffer().getBandNoData()[band]);
|
105 |
} |
106 |
} |
107 |
return noDatas;
|
108 |
} |
109 |
|
110 |
/**
|
111 |
* This is a utility method that return a copy of the NoData of
|
112 |
* the processable band of the input buffer.
|
113 |
*
|
114 |
* @return array of NoDatas
|
115 |
*/
|
116 |
protected NoData[] getProcessableBandNoDatasAsArray() { |
117 |
List<NoData> l = this.getProcessableBandNoDatas(); |
118 |
NoData[] noDatas = l.toArray(new NoData[l.size()]); |
119 |
return noDatas;
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* This is a utility method that return a copy of the types of
|
124 |
* the processable band of the input buffer.
|
125 |
*
|
126 |
* @return list of types
|
127 |
*/
|
128 |
protected List<Integer> getProcessableBandTypes() { |
129 |
int bands = this.getInputBuffer().getBandCount(); |
130 |
List<Integer> types = new ArrayList<>(); |
131 |
for (int band = 0; band < bands; band++) { |
132 |
if (this.isProcessableBand(band)) { |
133 |
types.add(this.getInputBuffer().getBandTypes()[band]);
|
134 |
} |
135 |
} |
136 |
return types;
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* This is a utility method that return a copy of the types of
|
141 |
* the processable band of the input buffer.
|
142 |
*
|
143 |
* @return Array of types
|
144 |
*/
|
145 |
protected int[] getProcessableBandTypesAsArray() { |
146 |
int[] types = this.getTypesAsArray(this.getProcessableBandTypes()); |
147 |
return types;
|
148 |
} |
149 |
|
150 |
protected int[] getTypesAsArray(List<Integer> theTypes) { |
151 |
int[] types = new int[theTypes.size()]; |
152 |
int n = 0; |
153 |
for (Integer type : theTypes) { |
154 |
types[n++] = type ; |
155 |
} |
156 |
return types;
|
157 |
} |
158 |
|
159 |
} |