Author: tomithy Date: 2010-07-21 11:41:26 -0700 (Wed, 21 Jul 2010) New Revision: 20976
Modified: cytoscapeweb/branches/gsoc2010/gbeb/src/GBEBView.as cytoscapeweb/branches/gsoc2010/gbeb/src/gbeb/util/GeometryUtil.as cytoscapeweb/branches/gsoc2010/gbeb/src/gbeb/view/operator/router/GBEBRouter.as cytoscapeweb/branches/gsoc2010/gbeb/src/gbeb/view/operator/router/Shape.as Log: Tried the algorithm mentioned in http://stackoverflow.com/questions/2075544/how-can-i-modify-my-code-to-line-through-the-bezier-control-points The results looks funny Modified: cytoscapeweb/branches/gsoc2010/gbeb/src/GBEBView.as =================================================================== --- cytoscapeweb/branches/gsoc2010/gbeb/src/GBEBView.as 2010-07-20 18:48:15 UTC (rev 20975) +++ cytoscapeweb/branches/gsoc2010/gbeb/src/GBEBView.as 2010-07-21 18:41:26 UTC (rev 20976) @@ -26,15 +26,19 @@ import flash.net.URLRequest; import flash.text.TextFormat; import flash.utils.Dictionary; - + import gbeb.view.components.ProgressBar; import gbeb.view.operator.router.GBEBRouter; import gbeb.view.render.BundleRenderer; - [SWF(width="1000",height="700", backgroundColor="#ffffff", frameRate="30")] + + [SWF(width="800",height="600", backgroundColor="#ffffff", frameRate="30")] public class GBEBView extends Sprite { - private var _url:String = "http://flare.prefuse.org/data/flare.json.txt"; + //private var _url:String = "http://flare.prefuse.org/data/flare.json.txt"; + //private var _url:String ="/Users/Tomithy/Desktop/GSOC/Datasets/flare.json.txt"; + private var _url:String ="/Users/Tomithy/Desktop/GSOC/Datasets/flare_reduced.json.txt"; + //private var _url:String ="/Users/Tomithy/Desktop/GSOC/Datasets/socialnet.xml"; private var _vis:Visualization; private var _bar:ProgressBar; private var _bounds:Rectangle; @@ -145,6 +149,7 @@ // add mouse-over highlight var hov:HoverControl = new HoverControl(NodeSprite, HoverControl.DONT_MOVE, highlight, unhighlight); _vis.controls.add(hov); + } /** Add highlight to a node and connected edges/nodes */ Modified: cytoscapeweb/branches/gsoc2010/gbeb/src/gbeb/util/GeometryUtil.as =================================================================== --- cytoscapeweb/branches/gsoc2010/gbeb/src/gbeb/util/GeometryUtil.as 2010-07-20 18:48:15 UTC (rev 20975) +++ cytoscapeweb/branches/gsoc2010/gbeb/src/gbeb/util/GeometryUtil.as 2010-07-21 18:41:26 UTC (rev 20976) @@ -1,5 +1,8 @@ package gbeb.util { + import flare.vis.data.EdgeSprite; + + import flash.display.Graphics; import flash.geom.Point; public class GeometryUtil @@ -65,6 +68,159 @@ } return ip; } + + + /** + * Draw a quadratic Bezier curve through a set of control points anchorPoints[], with the first point being the start and last points + * being static anchor points of the curve. + * + * This method extends from the solution given at: http://stackoverflow.com/questions/2075544/how-can-i-modify-my-code-to-line-through-the-bezier-control-points, + * with question+code by WillyCornbread and solution+code given by Sly_cardinal + */ + public static function drawCPDirectedCurves(g:Graphics, anchorPoints:Array):void + { + // clear old line and draw new / begin fill + g.clear(); + g.lineStyle(0.5, 0, 1); + g.beginFill(0x0099FF,.1); + + //move to starting anchor point + var startX:Number = anchorPoints[0].x; + var startY:Number = anchorPoints[0].y; + g.moveTo(startX, startY); + + // Connect the dots + var p0:Point = new Point(startX, startY); + var p2:Point; + + var numAnchors:Number = anchorPoints.length; + for (var i:Number=1; i<numAnchors; i++) { + + p2 = new Point(anchorPoints[i].x, anchorPoints[i].y); + + // curve to next anchor through control + //var b1:Point = new Point(controlPoints[i].x,controlPoints[i].y); + var b1:Point = new Point(anchorPoints[i].x,anchorPoints[i].y); + var p1:Point = derivePoint(p0, b1, p2); + + g.curveTo(p1.x, p1.y, p2.x, p2.y); + + p0 = p2; + + } + // Close the loop - not necessarys + //g.curveTo(controlPoints[0].x,controlPoints[0].y,startX,startY); + } + + /** + * This two function below derives the position of the anchor point based of the location of the control point. + * + * Credit belongs to WillyCornbread and solution+code given by Sly_cardinal. + */ + private static function derivePoint(p0:Point, b1:Point, p2:Point, t:Number = 0.5):Point + { + var p:Point = new Point(deriveTerm(p0.x, b1.x, p2.x, t), deriveTerm(p0.y, b1.y, p2.y, t)); + return p; + } + private static function deriveTerm(p0:Number, bt:Number, p2:Number, t:Number):Number + { + var negT:Number = 1 - t; + + var a0:Number = Math.pow(negT, 2) * p0; + var a1:Number = 2 * negT * t; + var a2:Number = Math.pow(t, 2) * p2; + + var p1:Number = (bt - a0 - a2) / a1; + return p1; + } + + + public static function changeToDerivedPoints(e:EdgeSprite):void + { + trace("Geometry Util: Targeting Edge: " + e.toString()); + var controlPoints:Array = e.props.$controlPointsArray; + + var tempPoint:Point; + var newCPArray:Array = []; //to store derived CP Array + + if(controlPoints == null ) return; + if(controlPoints.length <= 0 ) return; + + if(e.target == null || e.source == null) return; + + controlPoints.unshift(new Point(e.source.x, e.source.y)); + controlPoints.push(new Point(e.target.x, e.target.y)); + + for(var i:int = 1; i < controlPoints.length - 1; i++) + { + var p:Point = controlPoints[i] as Point; + + if(p == null) controlPoints.splice(i, 1); + } + + trace("Geometry Util: CP.length: " + (controlPoints.length - 2).toString()); + + for(var i:int = 1; i < controlPoints.length - 1; i++) + { + var p0:Point = controlPoints[i-1] as Point; + var p1:Point = controlPoints[i] as Point; + var p2:Point = controlPoints[i+1] as Point; + + var derivedPt:Point = derivePoint(p0, p1, p2); + newCPArray.push(derivedPt); + trace("Geometry Util:" , p0, p1, p2); + + } + + e.props.$controlPointsArray = newCPArray; + + } + + + + + /* + public static function changeToDerivedPoints(e:EdgeSprite):void + { + trace("Geometry Util:Hi! " + e.toString()); + var controlPoints:Array = e.props.$controlPointsArray; + + var tempPoint:Point; + var newCPArray:Array = []; //to store derived CP Array + + if(controlPoints == null ) return; + if(controlPoints.length <= 0 ) return; + + if(e.target == null || e.source == null) return; + + controlPoints.unshift(new Point(e.source.x, e.source.y)); + controlPoints.push(new Point(e.target.x, e.target.y)); + + var p0:Point = controlPoints[0]; + var p2:Point; + + trace("GeomUtil: Checking null: " + controlPoints.length, controlPoints[0] == null, newCPArray == null); + + for(var i:int = 1; i < controlPoints.length - 1; i++) + { + p2 = new Point(controlPoints[i+1].x, controlPoints[i+1].y); + trace("GeomUtil: Checking null: p2: " + p2 , "i= " + i); + // curve to next anchor through control + //trace("GeomUtil: Checking null: controlPoints: " + controlPoints[i].toString()); + var b1:Point = new Point(controlPoints[i].x,controlPoints[i].y); + trace("GeomUtil: Checking null: b1: " + b1); + + var p1:Point = derivePoint(p0, b1, p2); + + trace("GeomUtil: Checking null: Derived point, b1: " + p1 + b1); + + newCPArray.push(p1); + p0 = b1; + } + + e.props.$controlPointsArray = newCPArray; + } */ + } } \ No newline at end of file Modified: cytoscapeweb/branches/gsoc2010/gbeb/src/gbeb/view/operator/router/GBEBRouter.as =================================================================== --- cytoscapeweb/branches/gsoc2010/gbeb/src/gbeb/view/operator/router/GBEBRouter.as 2010-07-20 18:48:15 UTC (rev 20975) +++ cytoscapeweb/branches/gsoc2010/gbeb/src/gbeb/view/operator/router/GBEBRouter.as 2010-07-21 18:41:26 UTC (rev 20976) @@ -143,6 +143,18 @@ displayGrids(); trace("GBEBRouter: Update and Mesh Called! Counter:" + runCounter++); + + + trace("GBEB Router: Let's see if the bundling mechnanism is working..."); + /*data.edges.visit(function (e:EdgeSprite):void { + var controlPoints:Array = e.props.$controlPointsArray; + + if(controlPoints.length <= 0 ) return; + + GeometryUtil.drawCPDirectedCurves(e.graphics, controlPoints); + + }); */ + data.edges.visit(GeometryUtil.changeToDerivedPoints); } } @@ -919,13 +931,15 @@ for each (edge in edges) { cpArray = edge.controlPoints; + //trace("GBEB Router: Drawing Edge!"); + if (cpArray == null || cpArray.length <= 0) continue; for each ( var cp:Point in cpArray) { if (cp == null) continue; - + //trace("GBEB Router: Drawing Edge!"); vis.graphics.beginFill(0x00FF00,1); - vis.graphics.drawCircle(cp.x, cp.y, 3); + vis.graphics.drawCircle(cp.x, cp.y, 5); vis.graphics.endFill(); } } @@ -936,7 +950,11 @@ // DEBUG ONLY: private function displayGrids():void { - if (visualization == null) return; + + var displayCentroid:Boolean = true; + + + if (visualization == null) return; var graphics:Graphics = visualization.graphics; graphics.clear(); @@ -946,6 +964,7 @@ graphics.lineStyle(0.2,0xFF0000,0.5); graphics.drawRect(r.x, r.y, r.width, r.height); graphics.endFill(); + } //trace("Mesh: Display Shape: Drawing..." + g.x); @@ -960,6 +979,8 @@ _textFieldGridTracker.text = shape.gridIndex + " has " + shape.storedDataEdges.length + " edges"; visualization.addChild(_textFieldGridTracker); }); */ + + } } Modified: cytoscapeweb/branches/gsoc2010/gbeb/src/gbeb/view/operator/router/Shape.as =================================================================== --- cytoscapeweb/branches/gsoc2010/gbeb/src/gbeb/view/operator/router/Shape.as 2010-07-20 18:48:15 UTC (rev 20975) +++ cytoscapeweb/branches/gsoc2010/gbeb/src/gbeb/view/operator/router/Shape.as 2010-07-21 18:41:26 UTC (rev 20976) @@ -160,10 +160,10 @@ for each (dataEdge in storedDataEdges) { var ctrl:Array = dataEdge.props.$controlPointsArray; - if (ctrl == null) ctrl = []; ctrl.push(controlPoint); } + } private function findControlPointFromIntersectionPoints(intersectionPointsArray:Array):Point -- You received this message because you are subscribed to the Google Groups "cytoscape-cvs" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/cytoscape-cvs?hl=en.
