root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / EcualizationManager.java @ 19409
History | View | Annotate | Download (4.84 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 |
package org.gvsig.raster.grid.filter.enhancement; |
20 |
|
21 |
import java.util.ArrayList; |
22 |
|
23 |
import org.gvsig.raster.dataset.FileNotOpenException; |
24 |
import org.gvsig.raster.dataset.Params; |
25 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
26 |
import org.gvsig.raster.grid.filter.FilterTypeException; |
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 |
import org.gvsig.raster.hierarchy.IStatistics; |
32 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
33 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
34 |
/**
|
35 |
* Gestor de la pila de filtros para el filtro de ecualizaci?n de histograma.
|
36 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
37 |
*/
|
38 |
public class EcualizationManager implements IRasterFilterListManager { |
39 |
|
40 |
protected RasterFilterList filterList = null; |
41 |
|
42 |
/**
|
43 |
* Constructor
|
44 |
* @param filterListManager
|
45 |
*/
|
46 |
public EcualizationManager(RasterFilterListManager filterListManager) {
|
47 |
this.filterList = filterListManager.getFilterList();
|
48 |
} |
49 |
|
50 |
public static void register() { |
51 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
52 |
extensionPoints.add("RasterFilter", "Ecualization", EcualizationManager.class); |
53 |
} |
54 |
|
55 |
/**
|
56 |
* A?ade un filtro de ecualizaci?n de histograma.
|
57 |
* @param IStatistics
|
58 |
* @throws FilterTypeException
|
59 |
*/
|
60 |
public void addEcualizationFilter(IStatistics stats, int[] renderBands) throws FilterTypeException { |
61 |
try {
|
62 |
if (!stats.isCalculated()) {
|
63 |
try {
|
64 |
stats.calcFullStatistics(); |
65 |
} catch (FileNotOpenException e) {
|
66 |
// No podemos aplicar el filtro
|
67 |
return;
|
68 |
} catch (RasterDriverException e) {
|
69 |
// No podemos aplicar el filtro
|
70 |
return;
|
71 |
} |
72 |
} |
73 |
|
74 |
RasterFilter filter = createEnhancedFilter(stats, renderBands); |
75 |
if (filter != null) |
76 |
filterList.add(filter); |
77 |
} catch (InterruptedException e) { |
78 |
//Si se ha interrumpido no a?adimos el filtro
|
79 |
} |
80 |
} |
81 |
|
82 |
/**
|
83 |
* Crea un filtro de Ecualizaci?n de histograma.
|
84 |
* @param stats
|
85 |
* @param renderBands
|
86 |
* @return
|
87 |
*/
|
88 |
public static RasterFilter createEnhancedFilter(IStatistics stats, int[] renderBands) { |
89 |
RasterFilter filter = new EcualizationByteFilter();
|
90 |
if (filter != null) { |
91 |
filter.addParam("stats", stats);
|
92 |
filter.addParam("renderBands", renderBands);
|
93 |
} |
94 |
return filter;
|
95 |
} |
96 |
|
97 |
/**
|
98 |
* Obtiene un Array de Strings a partir de una pila de filtros. Cada elemento
|
99 |
* del array tendr? la forma de elemento=valor.
|
100 |
*/
|
101 |
public ArrayList getStringsFromFilterList(ArrayList filterList, RasterFilter rf) { |
102 |
return filterList;
|
103 |
} |
104 |
|
105 |
/*
|
106 |
* (non-Javadoc)
|
107 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#createFilterListFromStrings(java.util.ArrayList, java.lang.String, int)
|
108 |
*/
|
109 |
public int createFilterListFromStrings(ArrayList filters, String fil, int filteri) throws FilterTypeException { |
110 |
return filteri;
|
111 |
} |
112 |
|
113 |
/*
|
114 |
* (non-Javadoc)
|
115 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#getRasterFilterList()
|
116 |
*/
|
117 |
public ArrayList getRasterFilterList() { |
118 |
ArrayList filters = new ArrayList(); |
119 |
filters.add(EcualizationFilter.class); |
120 |
return filters;
|
121 |
} |
122 |
|
123 |
/*
|
124 |
* (non-Javadoc)
|
125 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#addFilter(java.lang.Class, org.gvsig.raster.dataset.Params)
|
126 |
*/
|
127 |
public void addFilter(Class classFilter, Params params) throws FilterTypeException { |
128 |
if (classFilter.equals(EcualizationFilter.class)) {
|
129 |
int[] renderBands = { 0, 1, 2 }; |
130 |
|
131 |
for (int i = 0; i < params.getNumParams(); i++) { |
132 |
if (params.getParam(i).id.equals("RenderBands") && |
133 |
params.getParam(i).defaultValue instanceof String) { |
134 |
String[] bands = new String((String) params.getParam(i).defaultValue).split(" "); |
135 |
renderBands[0] = new Integer(bands[0]).intValue(); |
136 |
renderBands[1] = new Integer(bands[1]).intValue(); |
137 |
renderBands[2] = new Integer(bands[2]).intValue(); |
138 |
continue;
|
139 |
} |
140 |
} |
141 |
|
142 |
addEcualizationFilter((IStatistics) filterList.getEnvParam("IStatistics"), renderBands);
|
143 |
} |
144 |
} |
145 |
} |