Mercurial > dive4elements > gnv-client
changeset 441:31a12ff53f99
Added raster filter framework for "Profilschnitte"
gnv-artifacts/trunk@489 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 29 Dec 2009 06:53:31 +0000 |
parents | eb2ac62e853a |
children | 52e031261eaa |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/raster/Filter.java gnv-artifacts/src/main/java/de/intevation/gnv/raster/KernelFilter.java |
diffstat | 3 files changed, 104 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Mon Dec 28 17:13:12 2009 +0000 +++ b/gnv-artifacts/ChangeLog Tue Dec 29 06:53:31 2009 +0000 @@ -1,3 +1,17 @@ +2009-12-29 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/gnv/raster/Filter.java: New. + General filter mechanism raster in -> raster out. Useful + to chain processing. The Filter.Factory takes an + DOM element to configure itself. + + * src/main/java/de/intevation/gnv/raster/KernelFilter.java: + New. Implements raster filters based on kernel folding. Has + an inner class GaussFactory which acts as a factory to create + Gauss filters. The attributes "sigma" and "radius" are read + from the configuring DOM element to set up the parameters + of the kernel. + 2009-12-28 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/raster/Filter.java Tue Dec 29 06:53:31 2009 +0000 @@ -0,0 +1,20 @@ +package de.intevation.gnv.raster; + +import org.w3c.dom.Element; + +/** + * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) + */ +public interface Filter +{ + public interface Factory { + + void init(Element element); + + Filter create(); + + } // interface Factory + + Raster filter(Raster raster); +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/raster/KernelFilter.java Tue Dec 29 06:53:31 2009 +0000 @@ -0,0 +1,70 @@ +package de.intevation.gnv.raster; + +import org.w3c.dom.Element; + +import org.apache.log4j.Logger; + +/** + * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) + */ +public class KernelFilter +implements Filter +{ + private static Logger log = Logger.getLogger(KernelFilter.class); + + public static class GaussFactory + implements Filter.Factory + { + public static final double DEFAULT_SIGMA = 1.0d; + public static final int DEFAULT_RADIUS = 5; + + protected double sigma; + protected int radius; + + public GaussFactory() { + sigma = DEFAULT_SIGMA; + radius = DEFAULT_RADIUS; + } + + public void init(Element element) { + String s = element.getAttribute("sigma"); + String r = element.getAttribute("radius"); + + if ((s = s.trim()).length() > 0) { + try { + sigma = Math.abs(Double.parseDouble(s)); + } + catch (NumberFormatException nfe) { + log.warn("gauss sigma '" + s + "' not a valid float value."); + } + } + + if ((r = r.trim()).length() > 0) { + try { + radius = Math.min(3, Math.abs(Integer.parseInt(r))); + } + catch (NumberFormatException nfe) { + log.warn("gauss radius '" + r + "' not a valid integer value."); + } + } + } + + public Filter create() { + return new KernelFilter(Raster.Kernel.createGauss(sigma, radius)); + } + } // class GaussFactory + + protected Raster.Kernel kernel; + + public KernelFilter() { + } + + public KernelFilter(Raster.Kernel kernel) { + this.kernel = kernel; + } + + public Raster filter(Raster raster) { + return raster.create(kernel); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: