diff gnv-artifacts/src/main/java/de/intevation/gnv/raster/KernelFilter.java @ 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
children b1f5f2a8840f
line wrap: on
line diff
--- /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:

http://dive4elements.wald.intevation.org