Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/raster/Palette.java @ 638:c580666a843f
Removed CallMeta object from state which should not be serialized. Implemented a little workarround instead to save localized strings for axes descriptions of horizontal profile charts (issue180).
gnv-artifacts/trunk@721 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 02 Mar 2010 08:43:50 +0000 |
parents | c8089cd7d777 |
children | 9a828e5a2390 |
rev | line source |
---|---|
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.raster; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import org.w3c.dom.Document; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import org.w3c.dom.Element; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import org.w3c.dom.NodeList; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.util.Arrays; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import java.awt.Color; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
447
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
11 import org.apache.log4j.Logger; |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
12 |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.gnv.raster.Raster.ValueToIndex; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 /** |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 */ |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 public class Palette |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 implements ValueToIndex |
447
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
20 { |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
21 private static Logger log = Logger.getLogger(Palette.class); |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
22 |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 public static final class Entry |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 implements Comparable |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 private Entry left; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 private Entry right; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 private int index; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 |
483
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
31 private int externalIndex; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
32 |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 private double from; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 private double to; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 private String description; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 private Color color; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 public Entry() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
435
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
43 public Entry(Entry other) { |
483
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
44 index = other.index; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
45 externalIndex = other.externalIndex; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
46 from = other.from; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
47 to = other.to; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
48 description = other.description; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
49 color = other.color; |
435
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
50 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
51 |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 public Entry( |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 int index, |
483
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
54 int externalIndex, |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 double from, |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 double to, |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 Color color, |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 String description |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 ) { |
483
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
60 this.index = index; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
61 this.externalIndex = externalIndex; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
62 this.from = from; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
63 this.to = to; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
64 this.color = color; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
65 this.description = description; |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 public int compareTo(Object other) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 Entry e = (Entry)other; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 if (from < e.from) return -1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 if (from > e.from) return +1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 return 0; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 |
448
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
75 public double getFrom() { |
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
76 return from; |
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
77 } |
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
78 |
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
79 public double getTo() { |
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
80 return to; |
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
81 } |
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
82 |
449
c7ca2fce041f
Add only color to scale of vertical cross section which are in the chart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
448
diff
changeset
|
83 public Color getColor() { |
c7ca2fce041f
Add only color to scale of vertical cross section which are in the chart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
448
diff
changeset
|
84 return color; |
c7ca2fce041f
Add only color to scale of vertical cross section which are in the chart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
448
diff
changeset
|
85 } |
c7ca2fce041f
Add only color to scale of vertical cross section which are in the chart.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
448
diff
changeset
|
86 |
483
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
87 public int getExternalIndex() { |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
88 return externalIndex; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
89 } |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
90 |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 public Entry locateEntry(double value) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 Entry current = this; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 while (current != null) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 boolean b = value >= current.from; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 if (b && value <= current.to) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 return current; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 current = b |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 ? current.right |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 : current.left; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 return null; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 public int locate(double value) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 Entry entry = locateEntry(value); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 return entry != null |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 ? entry.index |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 : -1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 public Entry findByIndex(int index) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 Entry current = this; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 while (current != null) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 if (current.index == index) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 break; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 current = index < current.index |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 ? current.left |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 : current.right; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 return current; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 public String getDescription() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 return description; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 } |
435
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
128 |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
129 public boolean isInfinity() { |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
130 return from == -Double.MAX_VALUE |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
131 || to == Double.MAX_VALUE; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
132 } |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 } // class Entry |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 protected Entry [] entries; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 protected Entry lookup; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 protected Color [] rgbs; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 private Entry buildLookup(Entry [] entries, int lo, int hi) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 if (lo > hi) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 return null; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 int mid = (lo + hi)/2; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 Entry entry = entries[mid]; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 entry.left = buildLookup(entries, lo, mid-1); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 entry.right = buildLookup(entries, mid+1, hi); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 return entry; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 public Palette() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 public Palette(Document document) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 NodeList rangeNodes = document.getElementsByTagName("range"); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 entries = new Entry[rangeNodes.getLength()]; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 rgbs = new Color[entries.length]; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 for (int i = 0; i < entries.length; ++i) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 Element rangeElement = (Element)rangeNodes.item(i); |
483
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
162 double from = doubleValue(rangeElement.getAttribute("from")); |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
163 double to = doubleValue(rangeElement.getAttribute("to")); |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
164 int extIndex = intValue(rangeElement.getAttribute("index"), i); |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
165 Color color = color(rangeElement.getAttribute("rgb")); |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
166 String desc = rangeElement.getAttribute("description"); |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 if (from > to) { double t = from; from = to; to = t; } |
483
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
168 entries[i] = new Entry(i, extIndex, from, to, color, desc); |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 rgbs[i] = color; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 buildLookup(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 |
435
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
175 public Palette(Palette original, int N) { |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
176 if (N < 2) { |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
177 throw new IllegalArgumentException("N < 2"); |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
178 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
179 |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
180 Entry [] origEntries = original.entries; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
181 |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
182 int newSize = 0; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
183 for (int i = 0; i < origEntries.length; ++i) { |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
184 // cannot split infinity intervals |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
185 newSize += origEntries[i].isInfinity() ? 1 : N; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
186 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
187 |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
188 entries = new Entry[newSize]; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
189 rgbs = new Color[newSize]; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
190 |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
191 for (int i = 0, j = 0; i < origEntries.length; ++i) { |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
192 Entry origEntry = origEntries[i]; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
193 if (origEntry.isInfinity()) { |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
194 // infinity intervals are just copied |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
195 Entry nEntry = new Entry(origEntry); |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
196 entries[j] = nEntry; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
197 rgbs[j] = nEntry.color; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
198 nEntry.index = j++; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
199 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
200 else { |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
201 // split interval into N parts |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
202 double from = origEntry.from; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
203 double to = origEntry.to; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
204 double delta = (to - from)/N; |
447
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
205 for (int k = 0; k < N; ++k) { |
435
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
206 Entry nEntry = new Entry(origEntry); |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
207 nEntry.from = from; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
208 nEntry.to = from + delta; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
209 from += delta; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
210 entries[j] = nEntry; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
211 rgbs[j] = nEntry.color; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
212 nEntry.index = j++; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
213 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
214 } // limited interval |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
215 } // for all original entries |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
216 |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
217 buildLookup(); |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
218 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
219 |
483
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
220 private static final int intValue(String s, int def) { |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
221 if (s == null || (s = s.trim()).length() == 0) { |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
222 return def; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
223 } |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
224 try { |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
225 return Integer.parseInt(s); |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
226 } |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
227 catch (NumberFormatException nfe) { |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
228 log.error(nfe.getLocalizedMessage(), nfe); |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
229 } |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
230 return def; |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
231 } |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
232 |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 private static final double doubleValue(String s) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 if (s == null || (s = s.trim()).length() == 0) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 return 0d; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 if ((s = s.toLowerCase()).startsWith("-inf")) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 return -Double.MAX_VALUE; // XXX: Not using Double.NEGATIVE_INFINITY! |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 if (s.startsWith("inf")) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 return Double.MAX_VALUE; // XXX: Not using Double.NEGATIVE_INFINITY! |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 return Double.parseDouble(s); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 private static final Color color(String s) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 if (s == null || (s = s.trim()).length() == 0) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 return null; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 return Color.decode(s); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 protected void buildLookup() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
257 Arrays.sort(entries); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 lookup = buildLookup(entries, 0, entries.length-1); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 |
435
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
261 public Palette subdivide(int N) { |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
262 return new Palette(this, N); |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
263 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
264 |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 public int getSize() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 return rgbs.length; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 public Color getColor(int index) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 return rgbs[index]; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 public int indexToRGB(int index) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
274 return rgbs[index].getRGB(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
275 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
276 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
277 public int toIndex(double value) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
278 return lookup.locate(value); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
279 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
280 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
281 public Entry getEntry(double value) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
282 return lookup.locateEntry(value); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
283 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
284 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
285 public Entry getEntryByIndex(int index) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
286 return lookup.findByIndex(index); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
287 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
288 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
289 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |