コード例 #1
0
        private void OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            Point px = Mouse.GetPosition(this.canvas1);

            _pointList.Add(new VectorNode((int)px.X, (int)px.Y));


            this.canvas1.Children.Clear();
            foreach (var point in _pointList)
            {
                Point p = new Point(point.x, point.y);
                DrawPoint(p);
            }

            _voronoi.Rebuild();

            //only draw voronoi if ok
            if (_showVoronoi)
            {
                var circles = _voronoi.GetNodes();
                foreach (var ce in circles)
                {
                    HalfEdge edge = ce.halfEdge;
                    HalfEdge f    = edge;
                    while (edge != null)
                    {
                        var myLine = new Line();
                        myLine.Stroke = _brush;
                        myLine.X1     = edge.Twin().GetTarget().X();
                        myLine.X2     = edge.GetTarget().X();
                        myLine.Y1     = edge.Twin().GetTarget().Y();
                        myLine.Y2     = edge.GetTarget().Y();
                        myLine.HorizontalAlignment = HorizontalAlignment.Left;
                        myLine.VerticalAlignment   = VerticalAlignment.Center;
                        myLine.StrokeThickness     = 1;
                        this.canvas1.Children.Add(myLine);
                        edge = edge.Next();
                        if (edge == null || f == edge)
                        {
                            break;
                        }
                    }
                }
            }

            if (_showDelaunay)
            {
                ShowDelaunayEdges();
            }
        }
コード例 #2
0
        private void DrawWithoutRebuild()
        {
            this.canvas1.Children.Clear();
            foreach (var point in _pointList)
            {
                Point p = new Point(point.x, point.y);
                DrawPoint(p);
            }

            //only draw voronoi if ok
            if (_showVoronoi)
            {
                var circles = _voronoi.GetNodes();
                foreach (var ce in circles)
                {
                    HalfEdge edge = ce.halfEdge;


                    HalfEdge f = edge;
                    while (edge != null)
                    {
                        var myLine = new Line();
                        myLine.Stroke = _brush;
                        myLine.X1     = edge.Twin().GetTarget().X();
                        myLine.X2     = edge.GetTarget().X();
                        myLine.Y1     = edge.Twin().GetTarget().Y();
                        myLine.Y2     = edge.GetTarget().Y();
                        myLine.HorizontalAlignment = HorizontalAlignment.Left;
                        myLine.VerticalAlignment   = VerticalAlignment.Center;
                        myLine.StrokeThickness     = 1;
                        this.canvas1.Children.Add(myLine);
                        edge = edge.Next();
                        if (edge == null || f == edge)
                        {
                            break;
                        }
                    }
                }
            }
            if (_showDelaunay)
            {
                ShowDelaunayEdges();
            }
        }
コード例 #3
0
        private void GetFinalNodePoint(EventTree.TreeNode node)
        {
            if (node is EventTree.LeafNode)
            {
                if (((EventTree.LeafNode)node).GetBreakpointNode() == null)
                {
                    return;
                }
                Breakpoint b = ((EventTree.LeafNode)node).GetBreakpointNode().GetBreakpoint();


                VectorNode n1 = b.getLeftListEvent().GetHalfEdge().GetFace();
                VectorNode n2 = b.getLeftListEvent().GetHalfEdge().Twin().GetFace();


                float centerx = 0.5f * (b.getLeftListEvent().GetHalfEdge().GetFace().x + b.getLeftListEvent().GetHalfEdge().Twin().GetFace().x);
                float centery = 0.5f * (b.getLeftListEvent().GetHalfEdge().GetFace().y + b.getLeftListEvent().GetHalfEdge().Twin().GetFace().y);

                if (n1.y == n2.y)
                {
                    HalfEdge    he = b.getLeftListEvent().GetHalfEdge();
                    CircleEvent ce = new CircleEvent(centerx, -_openEdgeLimit /* neg infinity */);
                    if (he.GetTarget() == null)
                    {
                        he.SetTarget(ce);
                        ce.halfEdge = he;
                    }
                    else
                    {
                        he.Twin().SetTarget(ce);
                        ce.halfEdge = he.Twin();
                    }
                    _allCircleEvents.Add(ce);
                }
                else
                {
                    float grad     = (n2.y - n1.y) * 1.0f / (n2.x - n1.x);
                    float realGrad = -1.0f / grad;

                    float constant = centery - realGrad * centerx;

                    float bpx = b.getX() - centerx;
                    float bpy = b.getY() - centery;

                    //if x = bpx...
                    float       testx = centerx + 10000f;
                    float       testy = testx * realGrad + constant;
                    CircleEvent ce;
                    if (testx * bpx + testy * bpy > 0)
                    {
                        ce = new CircleEvent(testx, testy);
                    }
                    else
                    {
                        ce = new CircleEvent(centerx - 10000, (centerx - 10000) * realGrad + constant);
                    }


                    HalfEdge he = b.getLeftListEvent().GetHalfEdge();
                    if (he.GetFace() != b.getLeftListEvent().GetNode())
                    {
                        he = he.Twin();
                    }


                    if (he.GetTarget() == null)
                    {
                        he.SetTarget(ce);
                    }
                    else if (he.Twin().GetTarget() == null)
                    {
                        he.Twin().SetTarget(ce);
                    }
                    else
                    {
                        // big problem... should never happen
                    }
                    _allCircleEvents.Add(ce);
                }

                return;
            }
            else
            {
                Breakpoint b = ((EventTree.BreakpointNode)node).GetBreakpoint();

                b.CalculateBreakpoint(_openEdgeLimit);


                if (node.LChild() != null)
                {
                    GetFinalNodePoint(node.LChild());
                }
                if (node.RChild() != null)
                {
                    GetFinalNodePoint(node.RChild());
                }
            }
        }