VisClient/org/hfbk/vis/visnode/VisEdges.java

Go to the documentation of this file.
00001 package org.hfbk.vis.visnode;
00002 
00003 import java.util.HashMap;
00004 import java.util.Map;
00005 
00006 import org.dronus.gl.GLUtil;
00007 import org.lwjgl.opengl.GL11;
00008 import org.lwjgl.util.vector.Vector3f;
00009 
00010 
00035 public class VisEdges extends VisNode {
00036 
00037         VisEdges() {
00038                 super(null, new Vector3f());
00039                 radius=Float.POSITIVE_INFINITY;
00040         }
00041 
00042 
00043         VisRoot root;
00044         
00045         HashMap<VisNode,Vector3f> positions=new HashMap<VisNode, Vector3f>();
00046         
00053         void renderSelf() {
00054                 if (root==null)
00055                         root=getRoot();
00056 
00057                 //gather absolute positions
00058                 recurse(root, new Vector3f());
00059                 
00060                 //render child-to-parent edges
00061                 GL11.glDisable(GL11.GL_TEXTURE_2D);
00062                 GL11.glColor4f(1,1,1,.4f); //fine white
00063                 
00064                 //iterate over previous collected node position map
00065                 //drawing connections to each node's parent. 
00066                 for (Map.Entry<VisNode, Vector3f> entry: positions.entrySet()){
00067                         if (entry.getKey() instanceof VisUI) continue;
00068                         VisNode parent=entry.getKey().parent; //fetch parent
00069                         if (parent!=null && parent!=root) //dont connect to root, it is boring. 
00070                                 GLUtil.drawLine(entry.getValue(), positions.get(parent));
00071                 }
00072 
00073                 
00074                 
00075                 //render sourced node - to - sourcenode edges
00076                 GL11.glLineWidth(3);
00077                 GL11.glColor3f(1,0,0); //thick red
00078                 
00079                 for (Map.Entry<String, VisNode> entry: root.sourceNodesBySource.entrySet()){ //iterate over all sourcing nodes...
00080                         VisNode n=entry.getValue();
00081                         //if (n!=null){
00082                                 VisNode sn=root.nodesBySource.get(entry.getKey()); //...to find associated source node.
00083                                 if (sn!=null){
00084                                         Vector3f from=positions.get(n), to=positions.get(sn);
00085                                         if (from!=null && to!=null) GLUtil.drawLine(from, to);
00086                                 }
00087                         //}
00088                 }
00089                 
00090                 
00091                 //render source-to-source-path completition
00092                 //this connects the source nodes back to their (grand-)parent sourced nodes
00093                 //which with the above gives a uninterrupted path if all fetches sourced in  
00094                 //previously fetched nodes.
00095                 GL11.glColor4f(1f,0,0,.4f); //fading red                
00096 
00097                 for(Map.Entry<String, VisNode> entry: root.sourceNodesBySource.entrySet()){ 
00098                         VisNode n=entry.getValue(); //iterate over all sourcenodes
00099                         if (n==null) continue;
00100 
00101                         
00102                         //recurse up the tree until we hit a sourced node, simulate
00103                         //without drawing cause we did't know if we find a sourced node at all.
00104                         VisNode pathEnd=n.parent;
00105                         while (pathEnd!=root && !root.nodesBySource.containsKey(pathEnd.url)){
00106                                 pathEnd=pathEnd.parent;
00107                         }
00108                         
00109                         //we now have either a path from a sourcenode to the (grand-)parent sourced node
00110                         //or marched up to the root which means this node has no source upstream thus
00111                         //the path ends at it and we do not draw this boring connection to root. 
00112                         if (pathEnd!=root)
00113                                 while (n!=pathEnd) {
00114                                         GLUtil.drawLine(positions.get(n), positions.get(n.parent));
00115                                         n=n.parent;
00116                                 }
00117                 }
00118                 GL11.glLineWidth(2);    
00119         }
00120 
00129         void recurse(VisNode node, Vector3f pos){
00130                 
00131                 Vector3f abspos=new Vector3f();
00132                 //if (node instanceof VisLog || node instanceof VisMenu) //don't connect ui things 
00133                 Vector3f.add(pos,node.position,abspos);
00134                 positions.put(node, abspos);
00135                 
00136                 for (VisNode child: node.children)      recurse(child,abspos);
00137         }
00138 }

Generated on Tue Apr 7 17:57:21 2009 for visclient by  doxygen 1.5.1