root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / EnhancementListManager.java @ 11571
History | View | Annotate | Download (5.85 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
|
20 |
package org.gvsig.raster.grid.filter.enhancement; |
21 |
|
22 |
import java.util.ArrayList; |
23 |
|
24 |
import org.gvsig.i18n.Messages; |
25 |
import org.gvsig.raster.dataset.IBuffer; |
26 |
import org.gvsig.raster.dataset.IStatistics; |
27 |
import org.gvsig.raster.grid.filter.IRasterFilterListManager; |
28 |
import org.gvsig.raster.grid.filter.RasterFilter; |
29 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
30 |
import org.gvsig.raster.grid.filter.RasterFilterListManager; |
31 |
|
32 |
/**
|
33 |
* Gestor de la pila de filtros para el filtro de realce.
|
34 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
35 |
*/
|
36 |
public class EnhancementListManager implements IRasterFilterListManager{ |
37 |
|
38 |
protected RasterFilterList filterList = null; |
39 |
private RasterFilterListManager filterListManager = null; |
40 |
private IStatistics stats = null; |
41 |
|
42 |
/**
|
43 |
* Constructor
|
44 |
* @param filterListManager
|
45 |
*/
|
46 |
public EnhancementListManager(RasterFilterListManager filterListManager){
|
47 |
this.filterListManager = filterListManager;
|
48 |
this.filterList = filterListManager.getFilterList();
|
49 |
} |
50 |
|
51 |
/**
|
52 |
* Asigna el objeto con las estad?sticas
|
53 |
* @param stats IStatistics
|
54 |
*/
|
55 |
public void setStatistics(IStatistics stats){ |
56 |
this.stats = stats;
|
57 |
} |
58 |
|
59 |
/**
|
60 |
* A?ade un filtro de realce. Esta versi?n tiene el par?metro para a?adirle el nombre
|
61 |
* del fichero. Esto se usa para que si a un fichero se le ha calculado ya el recorte de colas
|
62 |
* no se vuelva a calcular, evitando as? que si hacemos un draw a una imagen por bloques cada
|
63 |
* bloque tenga un c?lculo distinto para el recorte.
|
64 |
* @param removeAll true si se desea eliminar cualquier filtro de brillo que
|
65 |
* hubiera en la pila antes y false si se acumula sobre lo que haya
|
66 |
*/
|
67 |
public void addEnhancedFilter(boolean removeEnds, IStatistics stats, double tailTrim, boolean removeAll) { |
68 |
String fName = Messages.getText(LinearEnhancementFilter.genericName);
|
69 |
|
70 |
if(filterList.isActive(fName))
|
71 |
filterList.remove(fName); |
72 |
|
73 |
RasterFilter filter = null;
|
74 |
|
75 |
switch (filterList.getDataTypeInFilter(fName)) {
|
76 |
case IBuffer.TYPE_IMAGE:
|
77 |
//filter = new LinearEnhancementImageFilter();
|
78 |
break;
|
79 |
case IBuffer.TYPE_SHORT:
|
80 |
filter = new LinearEnhancementShortFilter();
|
81 |
break;
|
82 |
case IBuffer.TYPE_USHORT:
|
83 |
case IBuffer.TYPE_INT:
|
84 |
//filter = new LinearEnhancementIntegerFilter();
|
85 |
break;
|
86 |
case IBuffer.TYPE_FLOAT:
|
87 |
filter = new LinearEnhancementFloatFilter();
|
88 |
break;
|
89 |
case IBuffer.TYPE_DOUBLE:
|
90 |
filter = new LinearEnhancementDoubleFilter();
|
91 |
break;
|
92 |
} |
93 |
|
94 |
if(filter != null){ |
95 |
if(removeAll)
|
96 |
filterList.remove(LinearEnhancementFilter.genericName); |
97 |
filter.addParam("stats", stats);
|
98 |
if (removeEnds) {
|
99 |
filter.addParam("remove", new Boolean(true)); |
100 |
} else {
|
101 |
filter.addParam("remove", new Boolean(false)); |
102 |
} |
103 |
filter.addParam("tailTrim", new Double(tailTrim)); |
104 |
|
105 |
filterList.add(filter); |
106 |
filterListManager.controlTypes(); |
107 |
} |
108 |
} |
109 |
|
110 |
public void createStackFromStrings(ArrayList f, Integer pos) { |
111 |
|
112 |
} |
113 |
|
114 |
public ArrayList getStringsFromStack() { |
115 |
return null; |
116 |
} |
117 |
|
118 |
/**
|
119 |
* Obtiene un Array de Strings a partir de una pila de filtros. Cada elemento del array
|
120 |
* tendr? la forma de elemento=valor.
|
121 |
*/
|
122 |
|
123 |
public ArrayList getStringsFromStack(ArrayList filterList, RasterFilter rf) { |
124 |
if (rf instanceof LinearEnhancementFilter) { |
125 |
filterList.add("filter.enhanced.active=true");
|
126 |
filterList.add("filter.enhanced.tailTrim=" + ((LinearEnhancementFilter) rf).getTailTrim().toString());
|
127 |
filterList.add("filter.enhanced.remove=" + ((LinearEnhancementFilter) rf).getRemoveEnds().toString());
|
128 |
} |
129 |
|
130 |
return filterList;
|
131 |
} |
132 |
|
133 |
public int createStackFromStrings(ArrayList filters, String fil, int filteri) { |
134 |
if (fil.startsWith("filter.enhanced.active") && |
135 |
RasterFilterListManager.getValue(fil).equals("true")) {
|
136 |
filters.remove(filteri); |
137 |
double tailTrim = 0D; |
138 |
|
139 |
for (int propFilter = 0;propFilter < filters.size();propFilter++) { |
140 |
String elem = (String) filters.get(propFilter); |
141 |
|
142 |
if (elem.startsWith("filter.enhanced.tailTrim")) { |
143 |
try{
|
144 |
tailTrim = new Double(RasterFilterListManager.getValue(elem)).doubleValue(); |
145 |
}catch(NumberFormatException ex){ |
146 |
//tailTrim sigue valiendo 0
|
147 |
} |
148 |
} |
149 |
if (elem.startsWith("filter.enhanced.remove")) { |
150 |
addEnhancedFilter(Boolean.valueOf(RasterFilterListManager.getValue(elem)).booleanValue(), stats, tailTrim, true); |
151 |
filters.remove(propFilter); |
152 |
propFilter--; |
153 |
} |
154 |
} |
155 |
|
156 |
filteri = -1;
|
157 |
} |
158 |
return filteri;
|
159 |
} |
160 |
|
161 |
public void createStackFromStrings(ArrayList f) { |
162 |
} |
163 |
|
164 |
public String getFilterName() { |
165 |
return "enhanced"; |
166 |
} |
167 |
|
168 |
public String getGroupName() { |
169 |
return "basics"; |
170 |
} |
171 |
|
172 |
} |