예제 #1
0
 public DijkstraAnimation(Canvas c)
     : base()
 {
     popped = new Nodes();
     pushing = new Nodes();
     incomingEdge = new Hashtable();
     proposedWeight = new Hashtable();
     pq = new BinaryPriorityQueue(Node.sortAscending());
     graph = new Graph(); //empty graph until initialized.
     this.c = c;
     t = new Thread(new ThreadStart(Run));
 }
예제 #2
0
        public Canvas()
        {
            InitializeComponent();

            graph = new Graph();
            animations = new ArrayList();
            animStarted = false;
            weight = -1;
            prevEdgeHit = null;

            // Declare repaint optimizations.
            base.SetStyle(
                ControlStyles.UserPaint|
                ControlStyles.AllPaintingInWmPaint|
                ControlStyles.DoubleBuffer,
                true);

            this.Paint += new PaintEventHandler(Canvas_Paint);
            inkOverlay = new InkOverlay(this.Handle, true); //attach to form, allow use of mouse for input
            inkOverlay.CollectionMode =	CollectionMode.InkOnly;	// allow ink only, no gestures

            inkOverlay.AutoRedraw =	false; // Dynamic rendering	only; we do	all	the	painting.

            DrawingAttributes da = new DrawingAttributes();
            da.AntiAliased = true;  //Makes everything nice and smooth lookin'
            da.Transparency = 0;
            da.PenTip = Microsoft.Ink.PenTip.Ball;
            da.Width = 70.0f;
            inkOverlay.DefaultDrawingAttributes	= da;

            //Triggered at each pen stroke
            inkOverlay.Stroke += new InkCollectorStrokeEventHandler(inkOverlay_Stroke);
            //Triggered at each eraser stroke
            inkOverlay.StrokesDeleting += new InkOverlayStrokesDeletingEventHandler(inkOverlay_StrokesDeleting);
            //Triggered when a selection of strokes is moved
            inkOverlay.SelectionMoved += new InkOverlaySelectionMovedEventHandler(inkOverlay_SelectionMoved);
            //Triggered when a selection of strokes is resized
            inkOverlay.SelectionResized +=new InkOverlaySelectionResizedEventHandler(inkOverlay_SelectionResized);
            inkOverlay.Enabled = true;

            myRecognizer = new RecognizerContext();
            myRecognizer.Strokes = inkOverlay.Ink.CreateStrokes();

            edgeTimer = new System.Timers.Timer(TIME_INTERVAL);
            edgeTimer.AutoReset = true;
            edgeTimer.Elapsed +=new ElapsedEventHandler(edgeTimer_Elapsed);
            edgeTimer.Enabled = true;
        }
예제 #3
0
 public override void Initialize(Graph g)
 {
     graph = g;
     pq.Clear();
     popped.Clear();
     pushing.Clear();
     incomingEdge.Clear();
     proposedWeight.Clear();
     for(int i=0; i<graph.Nodes.Length(); i++)
     {
         Node n = graph.Nodes[i];
         n.Distance = int.MaxValue;
         incomingEdge.Add(n,null);
         proposedWeight.Add(n,int.MaxValue);
     }
     //graph.Home.Distance = 0;
     t = new Thread(new ThreadStart(Run));
     stepCount = 0;
     //pq.Push(graph.Home);
 }
예제 #4
0
 /* Determines whether the given stroke was a tap
  * on a node in Graph g and if so, returns that node
  */
 public static Node TappedNode(Stroke s, Graph g)
 {
     if(s.PacketCount > 25) return null;
     Point[] points = {s.GetPoint(0),s.GetPoint(s.PacketCount-1)};
     foreach(Node n in g.Nodes)
     {
         Rectangle r = n.Stroke.GetBoundingBox();
         if(r.Contains(points[0]) && r.Contains(points[1]))
             return n;
     }
     return null;
 }
예제 #5
0
        /* Determines whether the following stroke could be interpreted as
         * an edge (or edges) and if so, returns all the consecutive nodes that the
         * stroke has gone through in order.
         */
        public static Nodes ifEdgeGetNodes(Stroke s, Graph g)
        {
            Point[] sPoints = s.GetPoints();
            Nodes strokeHitNodes = new Nodes();
            Node prev = null;
            for(int i=0; i<sPoints.Length; i++)
            {
                for(int j=0; j<g.Nodes.Length(); j++)
                {
                    Node n = g.Nodes[j];
                    Rectangle r = n.Stroke.GetBoundingBox();

                    if(s.HitTest(n.CenterPoint,Math.Max(r.Width/2, r.Height/2)) && r.Contains(sPoints[i]) && !n.Equals(prev))
                    {
                        strokeHitNodes.Add(n);
                        prev = n;
                        break;
                    }
                }
            }
            //If stroke hit one or less nodes, it is clearly not an edge.
            if(strokeHitNodes.Length() < 2)
            {
                return null;
            }
            return strokeHitNodes;
        }
예제 #6
0
 /* Gets all the objects, nodes and edges, from graph g
  * hit by this stroke and returns an arraylist containing them all
  */
 public static ArrayList HitObjects(Stroke s, Graph g)
 {
     ArrayList objs = new ArrayList();
     Point[] points = s.GetPoints();
     for(int j=0; j<g.Edges.Length(); j++)
     {
         for(int i=0; i<points.Length; i++)
         {
             if(g.Edges[j].Stroke.HitTest(points[i],1))
             {
                 objs.Add(g.Edges[j]);
             }
         }
     }
     for(int j=0; j<g.Nodes.Length(); j++)
     {
         for(int i=0; i<points.Length; i++)
         {
             if(g.Nodes[j].Stroke.HitTest(points[i],1))
             {
                 objs.Add(g.Nodes[j]);
             }
         }
     }
     return objs;
 }
예제 #7
0
 /* Checks if the given stroke is within the bounds of a
  * Node.  It accomplishes this by using the stroke hit test.
  */
 public static Node HitNodeTest(Stroke s, Graph g)
 {
     Rectangle rectS = s.GetBoundingBox();
     Point sCenter = new Point(rectS.X + rectS.Width/2, rectS.Y + rectS.Height/2);
     for(int i=0; i<g.Nodes.Length(); i++)
     {
         Node n = g.Nodes[i];
         Rectangle rectN =n.Stroke.GetBoundingBox();
         if(s.HitTest(n.CenterPoint, (float)Math.Max(rectN.Height/2.0, rectN.Width/2.0))
             ||n.Stroke.HitTest(sCenter, (float)Math.Max(rectS.Height/2.0, rectS.Width/2.0)))
         {
             return n;
         }
     }
     return null;
 }
예제 #8
0
 /* Checks if the stroke drawn is within the range of a
  * edge from Graph g.  The range of an edge is roughly
  * around its center.
  */
 public static Edge HitEdgeTest(Stroke s, Graph g)
 {
     if(StrokeManager.StrokeLength(s) > HIT_TEST_THRESHOLD) return null;
     float distance = 1300;
     Edge hitedge = null;
     for(int i=0; i<g.Edges.Length(); i++)
     {
         float tmp;
         Edge e = g.Edges[i];
         Rectangle rect = e.Stroke.GetBoundingBox();
         Point p = new Point(rect.X+rect.Width/2, rect.Y+rect.Height/2);
         s.NearestPoint(p, out tmp);
         if(tmp < distance)
         {
             distance = tmp;
             hitedge = e;
         }
     }
     return hitedge;
 }
예제 #9
0
 public abstract void Initialize(Graph g);