comparison 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
comparison
equal deleted inserted replaced
440:eb2ac62e853a 441:31a12ff53f99
1 package de.intevation.gnv.raster;
2
3 import org.w3c.dom.Element;
4
5 import org.apache.log4j.Logger;
6
7 /**
8 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
9 */
10 public class KernelFilter
11 implements Filter
12 {
13 private static Logger log = Logger.getLogger(KernelFilter.class);
14
15 public static class GaussFactory
16 implements Filter.Factory
17 {
18 public static final double DEFAULT_SIGMA = 1.0d;
19 public static final int DEFAULT_RADIUS = 5;
20
21 protected double sigma;
22 protected int radius;
23
24 public GaussFactory() {
25 sigma = DEFAULT_SIGMA;
26 radius = DEFAULT_RADIUS;
27 }
28
29 public void init(Element element) {
30 String s = element.getAttribute("sigma");
31 String r = element.getAttribute("radius");
32
33 if ((s = s.trim()).length() > 0) {
34 try {
35 sigma = Math.abs(Double.parseDouble(s));
36 }
37 catch (NumberFormatException nfe) {
38 log.warn("gauss sigma '" + s + "' not a valid float value.");
39 }
40 }
41
42 if ((r = r.trim()).length() > 0) {
43 try {
44 radius = Math.min(3, Math.abs(Integer.parseInt(r)));
45 }
46 catch (NumberFormatException nfe) {
47 log.warn("gauss radius '" + r + "' not a valid integer value.");
48 }
49 }
50 }
51
52 public Filter create() {
53 return new KernelFilter(Raster.Kernel.createGauss(sigma, radius));
54 }
55 } // class GaussFactory
56
57 protected Raster.Kernel kernel;
58
59 public KernelFilter() {
60 }
61
62 public KernelFilter(Raster.Kernel kernel) {
63 this.kernel = kernel;
64 }
65
66 public Raster filter(Raster raster) {
67 return raster.create(kernel);
68 }
69 }
70 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org