Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/raster/Palette.java @ 1129:ccfa07b88476
merged geo-backend
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:01 +0200 |
parents | f953c9a559d8 |
children |
rev | line source |
---|---|
1115
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
803
diff
changeset
|
1 /* |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
803
diff
changeset
|
2 * Copyright (c) 2010 by Intevation GmbH |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
803
diff
changeset
|
3 * |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
803
diff
changeset
|
4 * This program is free software under the LGPL (>=v2.1) |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
803
diff
changeset
|
5 * Read the file LGPL.txt coming with the software for details |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
803
diff
changeset
|
6 * or visit http://www.gnu.org/licenses/ if it does not exist. |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
803
diff
changeset
|
7 */ |
f953c9a559d8
Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
803
diff
changeset
|
8 |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 package de.intevation.gnv.raster; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
779
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
11 import de.intevation.gnv.raster.Raster.ValueToIndex; |
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
12 |
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
13 import java.awt.Color; |
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
14 |
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
15 import java.util.Arrays; |
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
16 |
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
17 import org.apache.log4j.Logger; |
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
18 |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 import org.w3c.dom.Document; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 import org.w3c.dom.Element; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 import org.w3c.dom.NodeList; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 /** |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
24 * Lookup mechanism to map double values from a list of |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
25 * ranges onto a set of colors and vice versa. |
780
c4156275c1e1
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
779
diff
changeset
|
26 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 */ |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 public class Palette |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 implements ValueToIndex |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
483
diff
changeset
|
30 { |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
31 private static Logger log = Logger.getLogger(Palette.class); |
447
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
438
diff
changeset
|
32 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
33 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
34 * An entry in the lookup table. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
35 */ |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
483
diff
changeset
|
36 public static final class Entry |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 implements Comparable |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 private Entry left; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 private Entry right; |
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 private int index; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 |
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 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
|
45 |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 private double from; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 private double to; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 private String description; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 private Color color; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
53 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
54 * Default constructor |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
55 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 public Entry() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
59 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
60 * Copy constructor |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
61 * @param other The entry to copy. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
62 */ |
435
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
71 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
72 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
73 * Constructor to set the palette index, the exteral index, |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
74 * the value range, the color and the description. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
75 * @param index The pallette index |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
76 * @param externalIndex The external index |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
77 * @param from Start of the interval |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
78 * @param to End of the interval |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
79 * @param color The color belonging to this interval. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
80 * @param description The description of this range. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
81 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 public Entry( |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
483
diff
changeset
|
83 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
|
84 int externalIndex, |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
483
diff
changeset
|
85 double from, |
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
483
diff
changeset
|
86 double to, |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 Color color, |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 String description |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 ) { |
483
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 this.description = description; |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
98 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
99 * Compares two entries by the start point of the interval. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
100 * @param other |
803
feae2f9d6c6f
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
101 * @return -1 if this start point is before other. +1 if this |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
102 * start point is after, else 0. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
103 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 public int compareTo(Object other) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 Entry e = (Entry)other; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 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
|
107 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
|
108 return 0; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
111 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
112 * The starting point of the interval. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
113 * @return The starting point. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
114 */ |
448
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
115 public double getFrom() { |
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
116 return from; |
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
117 } |
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
118 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
119 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
120 * The end point of the interval. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
121 * @return The end point. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
122 */ |
448
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
123 public double getTo() { |
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
124 return to; |
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
125 } |
3cb2bea50456
Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
126 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
127 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
128 * The color of the entry. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
129 * @return The color. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
130 */ |
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
|
131 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
|
132 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
|
133 } |
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
|
134 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
135 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
136 * The external index of this entry. Useful to model |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
137 * external joins. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
138 * @return The external index. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
139 */ |
483
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
140 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
|
141 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
|
142 } |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
143 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
144 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
145 * Searches for an entry which has a range that contains |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
146 * the given value. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
147 * @param value The value to be searched. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
148 * @return The entry containing the value or null if no such |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
149 * entry exists. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
150 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 public Entry locateEntry(double value) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 Entry current = this; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 while (current != null) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 boolean b = value >= current.from; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 if (b && value <= current.to) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 return current; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 current = b |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 ? current.right |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 : current.left; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 return null; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
165 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
166 * Returns the palette index for a given value. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
167 * @param value The value to search. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
168 * @return The index of the palette entry or -1 if |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
169 * no such entry exists. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
170 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 public int locate(double value) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 Entry entry = locateEntry(value); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 return entry != null |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 ? entry.index |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 : -1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
178 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
179 * Searches for an interval with a given index. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
180 * @param index The index to be searched. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
181 * @return The entry with the given index or null if no |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
182 * such entry exists. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
183 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 public Entry findByIndex(int index) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 Entry current = this; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 while (current != null) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 if (current.index == index) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 break; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 current = index < current.index |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 ? current.left |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 : current.right; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 return current; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
197 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
198 * The description of this entry. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
199 * @return The description. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
200 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 public String getDescription() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 return description; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 } |
435
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
204 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
205 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
206 * Determines if the range of this entry has |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
207 * infinitive length. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
208 * @return true if the range of this entry has infinitive |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
209 * length else false. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
210 */ |
435
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
211 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
|
212 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
|
213 || 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
|
214 } |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 } // class Entry |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
217 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
218 * Internal table of the entrys. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
219 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 protected Entry [] entries; |
803
feae2f9d6c6f
Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
801
diff
changeset
|
221 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
222 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
223 * Root of the entry tree used to map values to entries. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
224 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 protected Entry lookup; |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
226 |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
227 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
228 * The list of colors used by this palette. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
229 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 protected Color [] rgbs; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 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
|
233 if (lo > hi) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 return null; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 int mid = (lo + hi)/2; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 Entry entry = entries[mid]; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 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
|
239 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
|
240 return entry; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
243 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
244 * Default constructor. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
245 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 public Palette() { |
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 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
249 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
250 * Constructor to create the palette from an XML document. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
251 * @param document The document with palette information. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
252 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 public Palette(Document document) { |
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 NodeList rangeNodes = document.getElementsByTagName("range"); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
257 entries = new Entry[rangeNodes.getLength()]; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 rgbs = new Color[entries.length]; |
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 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 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
|
269 rgbs[i] = color; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 } |
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 buildLookup(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
274 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
275 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
276 * Constructor to split a given palette into a given number of |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
277 * equal sized sub entries. Ranges of infinitive length are not |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
278 * splitted. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
279 * @param original The source palette. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
280 * @param N The number of chunks to split single ranges into. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
281 */ |
435
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
282 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
|
283 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
|
284 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
|
285 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
286 |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
287 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
|
288 |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
289 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
|
290 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
|
291 // 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
|
292 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
|
293 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
294 |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
295 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
|
296 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
|
297 |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
298 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
|
299 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
|
300 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
|
301 // 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
307 else { |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
308 // 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 from += delta; |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
321 } // limited interval |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
322 } // 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
|
323 |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
324 buildLookup(); |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
325 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
326 |
483
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
327 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
|
328 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
|
329 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
|
330 } |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
331 try { |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
332 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
|
333 } |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
334 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
|
335 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
|
336 } |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
337 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
|
338 } |
c8089cd7d777
Added explicit index scheme to palette classes to allow external references.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
449
diff
changeset
|
339 |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
340 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
|
341 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
|
342 return 0d; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
343 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
344 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
|
345 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
|
346 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
347 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
348 if (s.startsWith("inf")) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
349 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
|
350 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
351 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
352 return Double.parseDouble(s); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
353 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
354 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
355 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
|
356 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
|
357 return null; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
358 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
359 return Color.decode(s); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
360 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
361 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
362 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
363 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
364 * Internal method to build the lookup tree. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
365 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
366 protected void buildLookup() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
367 Arrays.sort(entries); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
368 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
|
369 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
370 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
371 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
372 * Creates a new palette which has ranges that are subdivided |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
373 * into a given number of sub ranges each. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
374 * @param N The number od sub divisions of each range. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
375 * @return The new created palette. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
376 */ |
435
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
377 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
|
378 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
|
379 } |
67091b17462d
Added code to split palette interval into equal sized parts.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
426
diff
changeset
|
380 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
381 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
382 * Return the number of entries in this palette. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
383 * @return The number of entries. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
384 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
385 public int getSize() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
386 return rgbs.length; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
387 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
388 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
389 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
390 * Return the color of an entry for a given index. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
391 * @param index The index. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
392 * @return The color. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
393 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
394 public Color getColor(int index) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
395 return rgbs[index]; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
396 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
397 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
398 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
399 * Return the RGB value |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
400 * @param index of an entry for a given index. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
401 * @return rgb value |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
402 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
403 public int indexToRGB(int index) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
404 return rgbs[index].getRGB(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
405 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
406 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
407 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
408 * Searches for the index of an entry which contains the |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
409 * given value. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
410 * @param value The value to be searched. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
411 * @return The index of the entry or -1 if no entry is found. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
412 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
413 public int toIndex(double value) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
414 return lookup.locate(value); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
415 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
416 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
417 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
418 * Searches for the an entry which contains the given value. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
419 * @param value The value to be searched. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
420 * @return The entry which contains the value or null if |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
421 * no such entry is found. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
422 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
423 public Entry getEntry(double value) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
424 return lookup.locateEntry(value); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
425 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
426 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
427 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
428 * Searches the entry for a given index. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
429 * @param index The index of the entry. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
430 * @return The entry or null if no such entry is found. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
431 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
432 public Entry getEntryByIndex(int index) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
433 return lookup.findByIndex(index); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
434 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
435 } |
798
6cff63d0c434
Fixed vim modeline. Added some Javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
436 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |