summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/visualization/gui/overview/RectangleArranger.java
diff options
context:
space:
mode:
authorErich Schubert <erich@debian.org>2012-12-14 20:45:15 +0100
committerAndrej Shadura <andrewsh@debian.org>2019-03-09 22:30:35 +0000
commit357b2761a2c0ded8cad5e4d3c1e667b7639ff7a6 (patch)
tree3dd8947bb70a67c221adc3cd4359ba1d385e2f3c /src/de/lmu/ifi/dbs/elki/visualization/gui/overview/RectangleArranger.java
parent4343785ebed9d4145f417d86d581f18a0d31e4ac (diff)
parentb7b404fd7a726774d442562d11659d7b5368cdb9 (diff)
Import Debian changes 0.5.5-1
elki (0.5.5-1) unstable; urgency=low * New upstream release: 0.5.5 interim release.
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/visualization/gui/overview/RectangleArranger.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/visualization/gui/overview/RectangleArranger.java99
1 files changed, 69 insertions, 30 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/visualization/gui/overview/RectangleArranger.java b/src/de/lmu/ifi/dbs/elki/visualization/gui/overview/RectangleArranger.java
index a70393a5..b5e6031e 100644
--- a/src/de/lmu/ifi/dbs/elki/visualization/gui/overview/RectangleArranger.java
+++ b/src/de/lmu/ifi/dbs/elki/visualization/gui/overview/RectangleArranger.java
@@ -23,6 +23,8 @@ package de.lmu.ifi.dbs.elki.visualization.gui.overview;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+import gnu.trove.list.array.TDoubleArrayList;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -47,7 +49,7 @@ public class RectangleArranger<T> {
/**
* Logging class
*/
- private static final Logging logger = Logging.getLogger(RectangleArranger.class);
+ private static final Logging LOG = Logging.getLogger(RectangleArranger.class);
/**
* Target height/width ratio
@@ -67,15 +69,15 @@ public class RectangleArranger<T> {
/**
* Column widths
*/
- private ArrayList<Double> widths = new ArrayList<Double>();
+ private TDoubleArrayList widths = new TDoubleArrayList();
/**
* Column heights
*/
- private ArrayList<Double> heights = new ArrayList<Double>();
+ private TDoubleArrayList heights = new TDoubleArrayList();
/**
- * Bit sets to store usage. ArrayList = y, BitSet = x
+ * Map indicating which cells are used.
*/
private ArrayList<ArrayList<Object>> usage = new ArrayList<ArrayList<Object>>();
@@ -120,7 +122,9 @@ public class RectangleArranger<T> {
* @param data Data object to add (key)
*/
public void put(double w, double h, T data) {
- logger.finest("Add: " + w + "x" + h);
+ if(LOG.isDebuggingFinest()) {
+ LOG.finest("Add: " + w + "x" + h);
+ }
final int cols = widths.size();
final int rows = heights.size();
@@ -233,7 +237,9 @@ public class RectangleArranger<T> {
double hinc = Math.max(0.0, h - avh);
double inc = computeIncreaseArea(winc, hinc);
- logger.debugFinest("Candidate: " + sx + "," + sy + " - " + ex + "," + ey + ": " + avw + "x" + avh + " " + inc);
+ if(LOG.isDebuggingFinest()) {
+ LOG.debugFinest("Candidate: " + sx + "," + sy + " - " + ex + "," + ey + ": " + avw + "x" + avh + " " + inc);
+ }
if(inc < bestinc) {
bestinc = inc;
bestsx = sx;
@@ -251,7 +257,9 @@ public class RectangleArranger<T> {
}
assert assertConsistent();
}
- logger.debugFinest("Best: " + bestsx + "," + bestsy + " - " + bestex + "," + bestey + " inc: " + bestwi + "x" + besthi + " " + bestinc);
+ if(LOG.isDebuggingFinest()) {
+ LOG.debugFinest("Best: " + bestsx + "," + bestsy + " - " + bestex + "," + bestey + " inc: " + bestwi + "x" + besthi + " " + bestinc);
+ }
// Need to increase the total area
if(bestinc > 0) {
assert (bestex == cols - 1 || bestey == rows - 1);
@@ -290,7 +298,7 @@ public class RectangleArranger<T> {
}
}
map.put(data, new double[] { xpos, ypos, w, h });
- if(logger.isDebuggingFinest()) {
+ if(LOG.isDebuggingFinest()) {
logSizes();
}
}
@@ -302,25 +310,29 @@ public class RectangleArranger<T> {
}
protected void splitRow(int bestey, double besthi) {
- assert(bestey < heights.size());
- if (heights.get(bestey) - besthi <= Double.MIN_NORMAL) {
+ assert (bestey < heights.size());
+ if(heights.get(bestey) - besthi <= Double.MIN_NORMAL) {
return;
}
- logger.debugFine("Split row " + bestey);
- heights.add(bestey + 1, besthi);
+ if(LOG.isDebuggingFine()) {
+ LOG.debugFine("Split row " + bestey);
+ }
+ heights.insert(bestey + 1, besthi);
heights.set(bestey, heights.get(bestey) - besthi);
// Update used map
usage.add(bestey + 1, new ArrayList<Object>(usage.get(bestey)));
}
protected void splitCol(int bestex, double bestwi) {
- assert(bestex < widths.size());
- if (widths.get(bestex) - bestwi <= Double.MIN_NORMAL) {
+ assert (bestex < widths.size());
+ if(widths.get(bestex) - bestwi <= Double.MIN_NORMAL) {
return;
}
final int rows = heights.size();
- logger.debugFine("Split column " + bestex);
- widths.add(bestex + 1, bestwi);
+ if(LOG.isDebuggingFine()) {
+ LOG.debugFine("Split column " + bestex);
+ }
+ widths.insert(bestex + 1, bestwi);
widths.set(bestex, widths.get(bestex) - bestwi);
// Update used map
for(int y = 0; y < rows; y++) {
@@ -332,9 +344,11 @@ public class RectangleArranger<T> {
private void resize(double inc) {
final int cols = widths.size();
final int rows = heights.size();
- logger.debugFine("Resize by " + inc + "x" + (inc / ratio));
- if(logger.isDebuggingFinest()) {
- logSizes();
+ if(LOG.isDebuggingFine()) {
+ LOG.debugFine("Resize by " + inc + "x" + (inc / ratio));
+ if(LOG.isDebuggingFinest()) {
+ logSizes();
+ }
}
// TODO: if the last row or column is empty, we can do this simpler
widths.add(inc);
@@ -354,7 +368,7 @@ public class RectangleArranger<T> {
usage.add(row);
}
assert assertConsistent();
- if(logger.isDebuggingFinest()) {
+ if(LOG.isDebuggingFinest()) {
logSizes();
}
}
@@ -379,7 +393,7 @@ public class RectangleArranger<T> {
{
double wsum = 0.0;
for(int x = 0; x < cols; x++) {
- assert (widths.get(x) > 0) : "Non-positive width: "+widths.get(x);
+ assert (widths.get(x) > 0) : "Non-positive width: " + widths.get(x);
wsum += widths.get(x);
}
assert (Math.abs(wsum - twidth) < 1E-10);
@@ -387,7 +401,7 @@ public class RectangleArranger<T> {
{
double hsum = 0.0;
for(int y = 0; y < rows; y++) {
- assert (heights.get(y) > 0) : "Non-positive height: "+heights.get(y);
+ assert (heights.get(y) > 0) : "Non-positive height: " + heights.get(y);
hsum += heights.get(y);
}
assert (Math.abs(hsum - theight) < 1E-10);
@@ -401,8 +415,11 @@ public class RectangleArranger<T> {
return true;
}
- public void logSizes() {
- StringBuffer buf = new StringBuffer();
+ /**
+ * Debug logging
+ */
+ protected void logSizes() {
+ StringBuilder buf = new StringBuilder();
final int cols = widths.size();
final int rows = heights.size();
{
@@ -413,7 +430,7 @@ public class RectangleArranger<T> {
}
buf.append(widths.get(x));
}
- buf.append("\n");
+ buf.append('\n');
}
{
buf.append("Heights: ");
@@ -423,7 +440,7 @@ public class RectangleArranger<T> {
}
buf.append(heights.get(y));
}
- buf.append("\n");
+ buf.append('\n');
}
{
for(int y = 0; y < rows; y++) {
@@ -433,11 +450,33 @@ public class RectangleArranger<T> {
buf.append("|\n");
}
for(int x = 0; x < cols; x++) {
- buf.append("-");
+ buf.append('-');
}
buf.append("+\n");
}
- logger.debug(buf);
+ LOG.debug(buf);
+ }
+
+ /**
+ * Compute the relative fill. Useful for triggering a relayout if the relative
+ * fill is not satisfactory.
+ *
+ * @return relative fill
+ */
+ public double relativeFill() {
+ double acc = 0.0;
+ final int cols = widths.size();
+ final int rows = heights.size();
+ {
+ for(int y = 0; y < rows; y++) {
+ for(int x = 0; x < cols; x++) {
+ if(usage.get(y).get(x) != null) {
+ acc += widths.get(x) * heights.get(y);
+ }
+ }
+ }
+ }
+ return acc / (twidth * theight);
}
/**
@@ -482,7 +521,7 @@ public class RectangleArranger<T> {
* @param args
*/
public static void main(String[] args) {
- logger.getWrappedLogger().setLevel(Level.FINEST);
+ LOG.getWrappedLogger().setLevel(Level.FINEST);
RectangleArranger<String> r = new RectangleArranger<String>(1.3);
r.put(4., 1., "Histogram");
r.put(4., 4., "3D view");
@@ -505,4 +544,4 @@ public class RectangleArranger<T> {
r.put(4., 1., "C");
r.put(1., .1, "D");
}
-}
+} \ No newline at end of file