annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/ZoomScale.java @ 7152:8c169743f4d0

Noted insights.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 26 Sep 2013 08:38:12 +0200
parents af13ceeba52a
children fac461c67d24
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4618
diff changeset
9 package org.dive4elements.river.artifacts.model;
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import java.util.HashMap;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import java.util.Map;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import java.util.Set;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 import java.util.TreeMap;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 import org.apache.log4j.Logger;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4618
diff changeset
18 import org.dive4elements.river.artifacts.math.Linear;
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20
7152
8c169743f4d0 Noted insights.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5994
diff changeset
21 /** Has to do with adaptive smoothing based on current diagram extent. */
4618
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 public class ZoomScale
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 private static Logger logger = Logger.getLogger(ZoomScale.class);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 private HashMap<String, TreeMap<Double, Double>> rivers;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 public ZoomScale() {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 this.rivers = new HashMap<String, TreeMap<Double, Double>>();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 public ZoomScale(String river) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 this();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 rivers.put(river, new TreeMap<Double, Double>());
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 public double getRadius(String river, double lower, double upper) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 double range = Math.abs(upper) - Math.abs(lower);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 TreeMap<Double, Double> ranges = rivers.get(river);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 if (ranges == null) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 return 0.001;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 Map.Entry<Double, Double> next = ranges.higherEntry(range);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 Map.Entry<Double, Double> prev = ranges.lowerEntry(range);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 double x0 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 double x1 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47 double y0 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 double y1 = 0d;
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 if (prev == null && next != null) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 x1 = next.getKey();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 y1 = next.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 else if (prev != null && next == null) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 return prev.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 else {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 x0 = prev.getKey();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 x1 = next.getKey();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 y0 = prev.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 y1 = next.getValue();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 return Linear.linear(range, x0, x1, y0, y1);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 public void addRiver(String river) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 if (!this.rivers.containsKey(river)) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 this.rivers.put(river, new TreeMap<Double, Double>());
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 public Set<String> getRivers() {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 return this.rivers.keySet();
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 public void addRange(String river, double range, double radius) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 if (this.rivers.containsKey(river)) {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 this.rivers.get(river).put(range, radius);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 else {
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 this.rivers.put(river, new TreeMap<Double, Double>());
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 this.rivers.get(river).put(range, radius);
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83 }
e8c6fbed889b New class storing configuration about zoom dependent filter levels.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84 }

http://dive4elements.wald.intevation.org