/[loom]/loom/org/fenfire/loom/WheelView.java
ViewVC logotype

Diff of /loom/org/fenfire/loom/WheelView.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by humppake, Thu Apr 3 09:16:34 2003 UTC revision 1.4 by humppake, Fri Apr 4 12:02:01 2003 UTC
# Line 30  import org.nongnu.libvob.vobs.*; Line 30  import org.nongnu.libvob.vobs.*;
30    
31  import java.lang.Math;  import java.lang.Math;
32  import java.util.*;  import java.util.*;
33    import org.fenfire.util.Pair;
34  import com.hp.hpl.mesa.rdf.jena.model.*;  import com.hp.hpl.mesa.rdf.jena.model.*;
35    
36  /** A simple wheel view.  /** A simple wheel view.
# Line 64  public class WheelView implements View { Line 65  public class WheelView implements View {
65      protected int gapx = 50, gapy = 30;      protected int gapx = 50, gapy = 30;
66    
67      protected int radius = sizex + gapx;      protected int radius = sizex + gapx;
68      protected int recursionDepth = 0;      protected int depth = 1;
69    
70      /** Maximum rotation angle. */      /** Maximum rotation angle. */
71      protected double maxrota = Math.PI / 9;      protected double maxrota = Math.PI / 9;
# Line 73  public class WheelView implements View { Line 74  public class WheelView implements View {
74       *  Render either posward or negward connections       *  Render either posward or negward connections
75       *  (or onward, maybe).       *  (or onward, maybe).
76       */       */
77      /*      public void renderSomewardConnections(VobScene sc, int into, Cursor c, Resource focus,
78      public void renderSomewardConnections(VobScene sc, int into, Cursor c,                                            Collection nodes, int before, int dir,
79                                            Resource node, int before,                                            double starta, double rota, float r,
                                           int dir, double rota, float r,  
80                                            int focusCs, int depth,                                            int focusCs, int depth,
81                                            int midx, int midy) {                                            int midx, int midy) {
82          double cura = -(before * rota);          double cura = starta - (before * rota);
83          if(dir < 0) cura += Math.PI;          if (dbg) p("Render, nodes: "+nodes.size()+", starta: "+starta
84          for(Iterator j=c.getConnections(node, dir).iterator(); j.hasNext();) {                     +", cura: "+cura+", depth: "+depth);    
85              Statement stmt = (Statement)j.next();          for(Iterator i=nodes.iterator(); i.hasNext();) {
86                Pair current = (Pair)i.next();
87                            
88              NodeView.Nodespec spec =              NodeView.Nodespec spec =
89                  new NodeView.Nodespec(stmt, dir);                  new NodeView.Nodespec((RDFNode)current.first,
90                                          (Property)current.second,
91                                          dir);
92              int x = midx+x(cura, r)-sizex/2;              int x = midx+x(cura, r)-sizex/2;
93              int y = midy+y(cura, r)-sizey/2;              int y = midy+y(cura, r)-sizey/2;
94              int cs2 = sc.orthoBoxCS(into, spec, Math.abs(before),              int cs2 = sc.orthoBoxCS(into, spec, Math.abs(before),
# Line 98  public class WheelView implements View { Line 101  public class WheelView implements View {
101              else              else
102                  sc.map.put(conn, cs2, focusCs);                  sc.map.put(conn, cs2, focusCs);
103    
104              cura+=rota;              if (depth > 1) {
105              before--;                  RDFNode newFocus = (RDFNode)current.first;
106          }                  if (newFocus != null && newFocus instanceof Resource) {
107      }  
108      */                      Vector removal = new Vector();
109                        Pair focusPair = new Pair(focus, (Property)current.second);
110      /**                      removal.add(focusPair);
111       *  Render either posward or negward connections  
112       *  (or onward, maybe).                      // Hmm... that 0 could be replaced with dir and then the
113       * @param recursion Recursions steps left. Giving zero will cause                      // other direction should be replaced with stubs
114       *                  no recursion at all.                      Collection subNodes = getNodes(c, (Resource)newFocus, 0, removal);
115       * @param dir -1 for negative, 1 for positive, 0 for both                      double subRota = getRotationAngle(c, (Resource)newFocus, subNodes,
116       */                                                        rota, depth-1);
117      public void renderSomewardConnections(VobScene sc, int into, Cursor c,                      renderSomewardConnections(sc, into, c, (Resource)newFocus, subNodes,
118                                            Resource node, int dir,  double cura,                                                subNodes.size()/2, dir, cura, subRota,
119                                            double [] rotas, float r,  int focusCs,                                                r+gapx+sizex, cs2, depth-1, midx, midy);
120                                            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);  
121              }              }
122    
123              cura+=rotas[connCount];              cura+=rota;
124              connCount++;              before--;
             depth--;  
125          }          }
126      }      }
127    
128      public void render(VobScene sc, int into, Cursor c) {      public void render(VobScene sc, int into, Cursor c) {
129            if (dbg) p("*******************************************************************");          
130          int midx = sc.size.width/2, midy = sc.size.height/2;          int midx = sc.size.width/2, midy = sc.size.height/2;
131          NodeView.Nodespec spec = new NodeView.Nodespec(c.focus);          NodeView.Nodespec spec = new NodeView.Nodespec(c.focus);
132          int cs = sc.orthoBoxCS(into, spec, 0, midx-sizex/2, midy-sizey/2,          int cs = sc.orthoBoxCS(into, spec, 0, midx-sizex/2, midy-sizey/2,
# Line 172  public class WheelView implements View { Line 137  public class WheelView implements View {
137          /** Radius = gapx * sizex */          /** Radius = gapx * sizex */
138          int r = gapx + sizex;          int r = gapx + sizex;
139    
140          int negConnCount = c.getConnections(-1).size();          Collection posNodes = getNodes(c, 1);
141          int posConnCount = c.getConnections(1).size();          Collection negNodes = getNodes(c, -1);
142          int negRotIndex = c.getRotationIndex(-1);          double posRota = getRotationAngle(c, posNodes, Math.PI, depth);
143          int posRotIndex = c.getRotationIndex(1);          double negRota = getRotationAngle(c, negNodes, Math.PI, depth);
144          double[] negRotAngles = getRotationAngles(c, c.focus, Math.PI, -1,  
145                                                 recursionDepth);          double rota = (posRota < negRota) ? posRota : negRota;
146          double[] posRotAngles = getRotationAngles(c, c.focus, Math.PI, 1,          if (posRota < 0) rota = negRota;
147                                                 recursionDepth);          else if (negRota < 0) rota = posRota;
   
         /** 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);  
         }  
148                    
149          //      int totpos = c.getConnections(1).size();          if (dbg) p("Render, posNodes: "+posNodes.size()+
150          //      int totneg = c.getConnections(-1).size();                     ", posRota: "+posRota+", rota: "+rota);          
   
         /** Rotation angle */  
         //      double rota = (Math.PI) / c.getConnectionCount();  
   
         /** Rotation angle should be no bigger than defined maximum. */  
         //      if (rota > maxrota) rota = maxrota;  
   
   
151          /** Poswards connections */          /** Poswards connections */
152          //      renderSomewardConnections(sc, into, c, c.focus,          renderSomewardConnections(sc, into, c, c.focus, posNodes,
153          //                                c.getRotationIndex(1), 1,                                    c.getRotationIndex(1), 1, 0,
154          //                                rota, r, cs, 1, midx, midy);                                    rota, r, cs, depth, midx, midy);
155    
156            if (dbg) p("Render, negNodes: "+negNodes.size()+
157                       ", negRota: "+negRota+", rota: "+rota);          
158          /** Negward connections */          /** Negward connections */
159          //      renderSomewardConnections(sc, into, c, c.focus,          renderSomewardConnections(sc, into, c, c.focus, negNodes,
160          //                                c.getRotationIndex(-1), -1,                                    c.getRotationIndex(-1), -1, Math.PI,
161          //                                rota, r, cs, 1, midx, midy);                                    rota, r, cs, depth, midx, midy);
162      }      }
163    
164      /**      protected double getRotationAngle(Cursor c, Resource node, Collection nodes,
165       * @param recursion Recursions steps left. Giving zero will cause                                        double angle, int depth) {
166       *                  no recursion at all.          if (dbg) p("Angle, nodes: "+nodes.size()+
167       * @param dir -1 for negative, 1 for positive, 0 for both                     ", angle: "+angle+", depth: "+depth);            
168       */          double rota;
169      protected double[] getRotationAngles(Cursor c, Resource node,          if (depth < 1) throw new Error("Depth is lesser than 1.");
170                                            double angle, int dir,          if (depth == 1) {
171                                            int recursion) {              if (nodes.size() == 0) return -1;
172          if (dbg) p("getRotationAngles, angle: "+angle+", dir: "+dir+", recursion: "+recursion);              rota = angle / nodes.size();
173                /** Rotation angle should be no bigger than defined maximum. */
         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;  
174              if (rota > maxrota) rota = maxrota;              if (rota > maxrota) rota = maxrota;
175              for (int i = 0; i < conns; i++) angles[i] = rota;              if (dbg) p("Angle, first: "+angle / nodes.size()+
176              if (dbg) p("getRotationAngle, no recursion, angles: "+dArrayToString(angles));                     ", returned: "+rota);            
177              return angles;              return rota;
178          }          }
179    
180          int connCount = 0;          int nodeCount = nodes.size() + getSubNodeCount(c, nodes, depth-1);
181          int totalsubconns = 0;          if (nodeCount == 0) return -1;
182          int[] subconns = new int[conns];          if ((angle / nodeCount) >= maxrota)
183                angle = nodeCount * maxrota;
184          SortedSet connSet;          rota = angle / nodes.size();
185    
186            if (dbg) p("Angle, nodeCount: "+nodeCount+", returned: "+rota);    
187            return rota;
188        }
189        protected double getRotationAngle(Cursor c, Collection nodes,
190                                          double angle, int depth) {
191            return getRotationAngle(c, c.focus, nodes, angle, depth);
192        }
193    
194        protected Collection getNodes(Cursor c, Resource node,
195                                      int dir, Collection removal) {
196            Vector v;
197            if (dir == 0) v = new Vector(c.getConnections(node, 1).size() +
198                                            c.getConnections(node, -1).size());
199            else v = new Vector(c.getConnections(node, dir).size());
200            
201          if (dir == 0) {          if (dir == 0) {
202              connSet = c.getConnections(node, -1);              for(Iterator i=c.getConnections(node, 1).iterator(); i.hasNext();) {
203              connSet.addAll(c.getConnections(node, 1));                  Statement stmt = (Statement)i.next();
204          } else connSet = c.getConnections(node, dir);                  v.add(new Pair(stmt.getObject(), stmt.getPredicate()));
205                }
206          for(Iterator j=connSet.iterator(); j.hasNext();) {              for(Iterator i=c.getConnections(node, -1).iterator(); i.hasNext();) {
207              Statement stmt = (Statement)j.next();                  Statement stmt = (Statement)i.next();
208              RDFNode current = (dir<0) ? stmt.getSubject() : stmt.getObject();                  v.add(new Pair(stmt.getSubject(), stmt.getPredicate()));
209              if(current != null && current instanceof Resource) {              }
210                  subconns[connCount] = getConnectionCount(c, (Resource)current,          } else {
211                                                           0, recursion - 1);              for(Iterator i=c.getConnections(node, dir).iterator(); i.hasNext();) {
212                  totalsubconns += subconns[connCount];                  Statement stmt = (Statement)i.next();
213                  if (subconns[connCount] == 0) {                  RDFNode current = (dir<0) ? stmt.getSubject() : stmt.getObject();
214                      subconns[connCount] = 1;                  v.add(new Pair(current, stmt.getPredicate()));
                     totalsubconns ++;  
                 }  
             } else {  
                 subconns[connCount] = 1;  
                 totalsubconns++;  
215              }              }
             connCount++;  
216          }          }
         if (dbg) p("getRotationAngles, totalsubconns: "+totalsubconns);  
   
         if ((angle / totalsubconns) >= maxrota)  
             angle = totalsubconns * maxrota;  
         for (int i = 0; i < conns; i++)  
             angles[i] = angle / conns;  
         /** Variable angles just didnt work */  
         //angles[i] = angle * ((double)subconns[i] / (double)totalsubconns);  
217                    
218          if (dbg) p("getRotationAngle, angles: "+dArrayToString(angles));          if (removal != null) {
219                for(Iterator i=removal.iterator(); i.hasNext();) {
220          return angles;                  Pair r = (Pair)i.next();
221                    while(v.remove(r));
222                }
223            }
224            return v;
225        }
226        protected Collection getNodes(Cursor c, Resource node, int dir) {
227            return getNodes(c, node, dir, null);
228        }
229        protected Collection getNodes(Cursor c, int dir) {
230            return getNodes(c, c.focus, dir, null);
231      }      }
232    
233      protected int getConnectionCount(Cursor c, Resource node,      protected int getSubNodeCount(Cursor c, Collection nodes, int depth) {
234                                   int dir, int recursion) {          int nodeCount = 0;
235          if (dbg) p("getConnectionCount, dir: "+dir+", recursion: "+recursion);          for(Iterator i=nodes.iterator(); i.hasNext();) {
236          int conns = 0;              RDFNode current = (RDFNode)((Pair)i.next()).first;
237          if (dir == 0) {              if (current != null && current instanceof Resource) {
238              conns = c.getConnections(node, -1).size() +                  Collection subNodes = getNodes(c, (Resource)current, 0);
239                  c.getConnections(node, 1).size();                  nodeCount += subNodes.size();
240          } else conns = c.getConnections(node, dir).size();                  if (subNodes.size() > 0) nodeCount--;
241                    if (depth > 1) nodeCount += getSubNodeCount(c, subNodes, depth-1);
242          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);  
243          }          }
244            return nodeCount;
         if (dbg) p("getConnectionCount, subconns: "+subconns);    
         return (conns<subconns) ? subconns : conns;  
245      }      }
246        
247        protected int getConnectionCount(Cursor c, Resource node) {
248            int posn = c.getConnections(node, 1).size();
249            int negn = c.getConnections(node, -1).size();
250    
251            return (negn>posn) ? negn : posn;
252        }
253        protected int getConnectionCount(Cursor c) { return getConnectionCount(c, c.focus);  }
254        
255      private String dArrayToString(double[] a) {      private String dArrayToString(double[] a) {
256          if (dbg) p("dArrayToString, length: " + a.length);          if (dbg) p("dArrayToString, length: " + a.length);
257          String s = "";          String s = "";
258          for (int i = 0; i < a.length; i++)          for (int i=0; i<a.length; i++)
259              s += "" + a[i] + " ";              s += "" + a[i] + " ";
260          return s;          return s;
261      }      }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26