Beispiel #1
0
        private void HandleCircleEvent(CircleEvent circleEvent)
        {
            HalfEdge CL = circleEvent.L().GetHalfEdge();

            if (CL.GetFace() == circleEvent.L().GetNode())
            {
                CL = CL.Twin();
            }

            HalfEdge CR = circleEvent.C().GetHalfEdge();

            if (CR.GetFace() == circleEvent.R().GetNode())
            {
                CR = CR.Twin();
            }

            HalfEdge RC = CR.Twin();

            RC.SetTarget(circleEvent);
            CL.SetTarget(circleEvent);

            circleEvent.halfEdge = CR;


            EventTree.LeafNode prev = (EventTree.LeafNode)_eventTree.GetPreviousLeaf(circleEvent.GetCenterLeafNode());
            EventTree.LeafNode next = (EventTree.LeafNode)_eventTree.GetNextLeaf(circleEvent.GetCenterLeafNode());

            if (prev != null)
            {
                if (prev.GetDisappearEvent() != null)
                {
                    _eventQueue.Delete(prev.GetDisappearEvent().GetHandle());
                    prev.SetDisappearEvent(null);
                }
            }

            if (next != null)
            {
                if (next.GetDisappearEvent() != null)
                {
                    _eventQueue.Delete(next.GetDisappearEvent().GetHandle());
                    next.SetDisappearEvent(null);
                }
            }

            List <CircleEvent> newCircles = _eventTree.RemoveNode(circleEvent, prev, circleEvent.GetCenterLeafNode(), next);

            if (newCircles != null)
            {
                foreach (CircleEvent ce in newCircles)
                {
                    IPriorityQueueHandle <IEvent> h = null;
                    _eventQueue.Add(ref h, ce);
                    ce.SetHandle(h);
                }
            }
        }
Beispiel #2
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());
                }
            }
        }