[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] loom/org/fenfire/loom WheelView.java
From: |
Asko Soukka |
Subject: |
[Gzz-commits] loom/org/fenfire/loom WheelView.java |
Date: |
Thu, 03 Apr 2003 03:20:18 -0500 |
CVSROOT: /cvsroot/loom
Module name: loom
Changes by: Asko Soukka <address@hidden> 03/04/03 03:20:18
Modified files:
org/fenfire/loom: WheelView.java
Log message:
messy prototype -> starting almost over again
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/loom/loom/org/fenfire/loom/WheelView.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
Patches:
Index: loom/org/fenfire/loom/WheelView.java
diff -u loom/org/fenfire/loom/WheelView.java:1.1
loom/org/fenfire/loom/WheelView.java:1.2
--- loom/org/fenfire/loom/WheelView.java:1.1 Mon Mar 31 17:41:23 2003
+++ loom/org/fenfire/loom/WheelView.java Thu Apr 3 03:20:18 2003
@@ -44,6 +44,9 @@
*/
public class WheelView implements View {
+ public static boolean dbg = false;
+ private static void p(String s) { System.out.println(s); }
+
/** The view used to show the individual nodes.
*/
protected NodeView nodeView;
@@ -61,6 +64,7 @@
protected int gapx = 50, gapy = 30;
protected int radius = sizex + gapx;
+ protected int recursionDepth = 0;
/** Maximum rotation angle. */
protected double maxrota = Math.PI / 9;
@@ -69,6 +73,7 @@
* Render either posward or negward connections
* (or onward, maybe).
*/
+ /*
public void renderSomewardConnections(VobScene sc, int into, Cursor c,
Resource node, int before,
int dir, double rota, float r,
@@ -97,6 +102,64 @@
before--;
}
}
+ */
+
+ /**
+ * Render either posward or negward connections
+ * (or onward, maybe).
+ * @param recursion Recursions steps left. Giving zero will cause
+ * no recursion at all.
+ * @param dir -1 for negative, 1 for positive, 0 for both
+ */
+ public void renderSomewardConnections(VobScene sc, int into, Cursor c,
+ Resource node, int dir, double cura,
+ double [] rotas, float r, int
focusCs,
+ int midx, int midy, int depth, int
recursion) {
+ if (dbg) p("Render, cura: "+cura+", r: "+r+", recursion: "+recursion);
+ int connCount = 0;
+
+ SortedSet connSet;
+ if (dir == 0) {
+ connSet = c.getConnections(node, -1);
+ connSet.addAll(c.getConnections(node, 1));
+ } else connSet = c.getConnections(node, dir);
+
+ for(Iterator j=connSet.iterator(); j.hasNext();) {
+ if (dbg) p("Render, cura: "+cura+", connCount: "+connCount);
+
+ Statement stmt = (Statement)j.next();
+ RDFNode current = (dir<0) ? stmt.getSubject() : stmt.getObject();
+
+ NodeView.Nodespec spec =
+ new NodeView.Nodespec(stmt, dir);
+ int x = midx+x(cura, r)-sizex/2;
+ int y = midy+y(cura, r)-sizey/2;
+ int cs2 = sc.orthoBoxCS(into, spec, Math.abs(depth),
+ x, y, 1, 1, sizex, sizey);
+ sc.coords.activate(cs2);
+ nodeView.render(sc, cs2, spec);
+
+ if(dir > 0)
+ sc.map.put(conn, focusCs, cs2);
+ else if (dir < 0)
+ sc.map.put(conn, cs2, focusCs);
+
+ if (recursion > 0 && current != null && current instanceof
Resource) {
+ double suba;
+ suba = rotas[connCount];
+ double[] subas = getRotationAngles(c, (Resource)current, suba,
0,
+ recursion - 1);
+ renderSomewardConnections(sc, into, c, (Resource)current,
+ 0, cura-(rotas[connCount]/2), subas,
+ r + gapx + sizex,
+ cs2, midx, midy, depth, recursion -
1);
+ }
+
+ cura+=rotas[connCount];
+ connCount++;
+ depth--;
+ }
+ }
public void render(VobScene sc, int into, Cursor c) {
int midx = sc.size.width/2, midy = sc.size.height/2;
@@ -105,38 +168,189 @@
1, 1, sizex, sizey);
sc.coords.activate(cs);
nodeView.render(sc, cs, spec);
+
+ /** Radius = gapx * sizex */
+ int r = gapx + sizex;
+
+ int negConnCount = c.getConnections(-1).size();
+ int posConnCount = c.getConnections(1).size();
+ int negRotIndex = c.getRotationIndex(-1);
+ int posRotIndex = c.getRotationIndex(1);
+ double[] negRotAngles = getRotationAngles(c, c.focus, Math.PI/2, -1,
+ recursionDepth);
+ double[] posRotAngles = getRotationAngles(c, c.focus, Math.PI/2, 1,
+ recursionDepth);
+
+ /** Negwards connections */
+ double cura = Math.PI;
+ if (negRotAngles != null) {
+ if (negRotIndex < 0)
+ for (int i = posConnCount+negRotIndex; i < posConnCount; i++)
+ cura += posRotAngles[i];
+ else {
+ if (negRotIndex > negConnCount)
+ for (int i = negRotIndex-negConnCount-1; i >= 0; i--)
+ cura -= posRotAngles[i];
+ for (int i = 0; i < negRotIndex && i < negConnCount; i++)
+ cura -= negRotAngles[i];
+ }
+ if (dbg) p("Negwards, cura: "+cura+", rotationIndex: "+negRotIndex);
+ renderSomewardConnections(sc, into, c, c.focus,
+ -1, cura, negRotAngles, r,
+ cs, midx, midy, negRotIndex,
+ recursionDepth);
+ }
+
+ /** Poswards connections */
+ cura = 0;
+ if (posRotAngles != null) {
+ if (posRotIndex < 0)
+ for (int i = negConnCount+posRotIndex; i < negConnCount; i++)
+ cura += negRotAngles[i];
+ else {
+ if (posRotIndex > posConnCount)
+ for (int i = posRotIndex-posConnCount-1; i >= 0; i--)
+ cura -= negRotAngles[i];
+ for (int i = 0; i < posRotIndex && i < posConnCount; i++)
+ cura -= posRotAngles[i];
+ }
+ if (dbg) p("Poswards, cura: "+cura+", rotationIndex: "+posRotIndex);
+ renderSomewardConnections(sc, into, c, c.focus,
+ 1, cura, posRotAngles, r,
+ cs, midx, midy, posRotIndex,
+ recursionDepth);
+ }
- int totpos = c.getConnections(1).size();
- int totneg = c.getConnections(-1).size();
+ // int totpos = c.getConnections(1).size();
+ // int totneg = c.getConnections(-1).size();
- /** Rotation angle = 2PI / 2(greater of totpos and totgen). */
- double rota;
- if (totpos < totneg) rota = 2 * totneg;
- else rota = 2 * totpos;
- rota = (2 * Math.PI) / rota;
+ /** Rotation angle */
+ // double rota = (Math.PI) / c.getConnectionCount();
- /** Rotation angle should be no bigger than defined maximu. */
- if (rota > maxrota) rota = maxrota;
+ /** Rotation angle should be no bigger than defined maximum. */
+ // if (rota > maxrota) rota = maxrota;
- /** Radius = gapx * sizex */
- int r = gapx + sizex;
/** Poswards connections */
- renderSomewardConnections(sc, into, c, c.focus,
- c.getRotationIndex(1), 1,
- rota, r, cs, 1, midx, midy);
+ // renderSomewardConnections(sc, into, c, c.focus,
+ // c.getRotationIndex(1), 1,
+ // rota, r, cs, 1, midx, midy);
/** Negward connections */
- renderSomewardConnections(sc, into, c, c.focus,
- c.getRotationIndex(-1), -1,
- rota, r, cs, 1, midx, midy);
+ // renderSomewardConnections(sc, into, c, c.focus,
+ // c.getRotationIndex(-1), -1,
+ // rota, r, cs, 1, midx, midy);
+ }
+
+ /**
+ * @param recursion Recursions steps left. Giving zero will cause
+ * no recursion at all.
+ * @param dir -1 for negative, 1 for positive, 0 for both
+ */
+ protected double[] getRotationAngles(Cursor c, Resource node,
+ double angle, int dir,
+ int recursion) {
+ if (dbg) p("getRotationAngles, angle: "+angle+", dir: "+dir+",
recursion: "+recursion);
+
+ int conns = 0;
+ if (dir == 0) {
+ conns = c.getConnections(node, -1).size() +
+ c.getConnections(node, 1).size();
+ } else conns = c.getConnections(node, dir).size();
+
+ if (dbg) p("getRotationAngles, conns: "+conns);
+ if (conns == 0) return null;
+
+ double[] angles = new double[conns];
+
+ if (recursion == 0) {
+ double rota = angle / conns;
+ if (dbg) p("getRotationAngle, no recursion, rota: "+rota);
+ double shift = 0;
+ if (rota > maxrota) rota = maxrota;
+ for (int i = 0; i < conns; i++) angles[i] = rota;
+ if (dbg) p("getRotationAngle, no recursion, angles:
"+dArrayToString(angles));
+ return angles;
+ }
+
+ int connCount = 0;
+ int totalsubconns = 0;
+ int[] subconns = new int[conns];
+
+ SortedSet connSet;
+ if (dir == 0) {
+ connSet = c.getConnections(node, -1);
+ connSet.addAll(c.getConnections(node, 1));
+ } else connSet = c.getConnections(node, dir);
+
+ for(Iterator j=connSet.iterator(); j.hasNext();) {
+ Statement stmt = (Statement)j.next();
+ RDFNode current = (dir<0) ? stmt.getSubject() : stmt.getObject();
+ if(current != null && current instanceof Resource) {
+ subconns[connCount] = getConnectionCount(c, (Resource)current,
+ dir, recursion - 1);
+ totalsubconns += subconns[connCount];
+ if (subconns[connCount] == 0) subconns[connCount] = 1;
+ } else subconns[connCount] = 1;
+ connCount++;
+ }
+
+ if ((angle / totalsubconns) >= maxrota)
+ angle = totalsubconns * maxrota;
+ for (int i = 0; i < conns; i++)
+ angles[i] = angle * ((double)subconns[i] / (double)totalsubconns);
+
+ if (dbg) p("getRotationAngle, angles: "+dArrayToString(angles));
+
+ return angles;
}
- int x(double angle, float radius) {
+ protected int getConnectionCount(Cursor c, Resource node,
+ int dir, int recursion) {
+ if (dbg) p("getConnectionCount, dir: "+dir+", recursion: "+recursion);
+ int conns = 0;
+ if (dir == 0) {
+ conns = c.getConnections(node, -1).size() +
+ c.getConnections(node, 1).size();
+ } else conns = c.getConnections(node, dir).size();
+
+ if (dbg) p("getConnectionCount, conns: "+conns);
+
+ if (recursion == 0) return conns;
+
+ int subconns = 0;
+
+ SortedSet connSet;
+ if (dir == 0) {
+ connSet = c.getConnections(node, -1);
+ connSet.addAll(c.getConnections(node, 1));
+ } else connSet = c.getConnections(node, dir);
+
+ for(Iterator j=connSet.iterator(); j.hasNext();) {
+ Statement stmt = (Statement)j.next();
+ RDFNode current = (dir<0) ? stmt.getSubject() : stmt.getObject();
+ if(current != null && current instanceof Resource)
+ subconns += getConnectionCount(c, (Resource)current,
+ dir, recursion - 1);
+ }
+
+ if (dbg) p("getConnectionCount, subconns: "+subconns);
+ return (conns<subconns) ? subconns : conns;
+ }
+
+ private String dArrayToString(double[] a) {
+ if (dbg) p("dArrayToString, length: " + a.length);
+ String s = "";
+ for (int i = 0; i < a.length; i++)
+ s += "" + a[i] + " ";
+ return s;
+ }
+
+ private int x(double angle, float radius) {
return (int)(Math.cos(angle) * radius);
}
-
- int y(double angle, float radius) {
+
+ private int y(double angle, float radius) {
return (int)(Math.sin(angle) * radius);
}
}
- [Gzz-commits] loom/org/fenfire/loom WheelView.java,
Asko Soukka <=