コード例 #1
0
        public override void Run(List<Point> points, List<Line> lines, List<Polygon> polygons, ref List<Point> outPoints, ref List<Line> outLines, ref List<Polygon> outPolygons)
        {
            segments = new List<Line>();
            for (int i = 0; i < lines.Count; ++i) //cuz it'll be edited during the run
                segments.Add(new Line(new Point(lines[i].Start.X,lines[i].Start.Y),new Point(lines[i].End.X,lines[i].End.Y)));
            OrderedSet<Event> Q = new OrderedSet<Event>(comparerEventX);
            OrderedSet<Event> L = new OrderedSet<Event>(comparerEventY);
            initializeEvents(Q);
            while (Q.Count > 0)
            {
                Event curEvent = Q.First(); Q.RemoveFirst();
                handleEvent(curEvent, L,Q, outPoints);
            }
            Dictionary<PointComparer, int> hashP = new Dictionary<PointComparer, int>();
            for (int i = 0; i < lines.Count; ++i)
            {
                if(hashP.ContainsKey(new PointComparer(lines[i].Start)))
                    hashP[new PointComparer(lines[i].Start)]++;
                else
                    hashP[new PointComparer(lines[i].Start)] = 1;

                if (hashP.ContainsKey(new PointComparer(lines[i].End)))
                    hashP[new PointComparer(lines[i].End)]++;
                else
                    hashP[new PointComparer(lines[i].End)] = 1;

            }
            foreach(KeyValuePair<PointComparer,int> v in hashP)
                if(v.Value>1)
                    outPoints.Add(v.Key.p);
        }
コード例 #2
0
        public override void Run(List <Point> points, List <Line> lines, List <Polygon> polygons, ref List <Point> outPoints, ref List <Line> outLines, ref List <Polygon> outPolygons)
        {
            segments = new List <Line>();
            for (int i = 0; i < lines.Count; ++i) //cuz it'll be edited during the run
            {
                segments.Add(new Line(new Point(lines[i].Start.X, lines[i].Start.Y), new Point(lines[i].End.X, lines[i].End.Y)));
            }
            OrderedSet <Event> Q = new OrderedSet <Event>(comparerEventX);
            OrderedSet <Event> L = new OrderedSet <Event>(comparerEventY);

            initializeEvents(Q);
            while (Q.Count > 0)
            {
                Event curEvent = Q.First(); Q.RemoveFirst();
                handleEvent(curEvent, L, Q, outPoints);
            }
            Dictionary <PointComparer, int> hashP = new Dictionary <PointComparer, int>();

            for (int i = 0; i < lines.Count; ++i)
            {
                if (hashP.ContainsKey(new PointComparer(lines[i].Start)))
                {
                    hashP[new PointComparer(lines[i].Start)]++;
                }
                else
                {
                    hashP[new PointComparer(lines[i].Start)] = 1;
                }

                if (hashP.ContainsKey(new PointComparer(lines[i].End)))
                {
                    hashP[new PointComparer(lines[i].End)]++;
                }
                else
                {
                    hashP[new PointComparer(lines[i].End)] = 1;
                }
            }
            foreach (KeyValuePair <PointComparer, int> v in hashP)
            {
                if (v.Value > 1)
                {
                    outPoints.Add(v.Key.p);
                }
            }
        }
コード例 #3
0
        private static IEnumerable <HalfEdge <TVTag, THTag, TFTag> > TryWalkClosedClockwisePath <TVTag, THTag, TFTag>(HalfEdge <TVTag, THTag, TFTag> edge)
        {
            Contract.Requires(edge != null);

            //Path we have walked
            var path = new OrderedSet <HalfEdge <TVTag, THTag, TFTag> > {
                edge
            };

            var current = edge;

            do
            {
                current = SelectTightestClockwiseTurn(current);

                //Check for failing to find an edge
                if (current == null)
                {
                    break;
                }

                if (!path.Add(current))
                {
                    //We failed to add this edge
                    //if this is the first edge that's great we've found a closed path
                    //if not, then it's an invalid path todo: does this imply topology is broken?
                    if (current.Equals(path.First()))
                    {
                        break;
                    }
                    else
                    {
                        return(null);
                    }
                }
            } while (true);

            //Check for invalid face
            if (path.Count < 3)
            {
                return(null);
            }

            //Yay, it's valid
            return(path);
        }
コード例 #4
0
        public override void Run(List <CGUtilities.Point> points, List <CGUtilities.Line> lines, List <CGUtilities.Polygon> polygons, ref List <CGUtilities.Point> outPoints, ref List <CGUtilities.Line> outLines, ref List <CGUtilities.Polygon> outPolygons)
        {
            OrderedSet <EventPoint>      Q          = new OrderedSet <EventPoint>(Compare_Y);
            Dictionary <int, EventPoint> prev_event = new Dictionary <int, EventPoint>();
            Dictionary <int, EventPoint> helper     = new Dictionary <int, EventPoint>();
            OrderedSet <EventPoint>      T          = new OrderedSet <EventPoint>(Compare_X);
            string type;



            for (int i = 0; i < polygons[0].lines.Count; ++i)
            {
                Point  n1    = polygons[0].lines[(polygons[0].lines.Count + i - 1) % polygons[0].lines.Count].Start;
                Point  p     = polygons[0].lines[i].Start;
                Point  n2    = polygons[0].lines[(i + 1) % polygons[0].lines.Count].Start;
                double angle = CalcAngle(n1, p, n2);

                if (((n1.Y < p.Y) || ((n1.Y == p.Y) && (n1.X > p.Y))) && ((n2.Y < p.Y) || ((n2.Y == p.Y) && (n2.X > p.X))))
                {
                    if (angle < 180)
                    {
                        type = "Start";
                    }
                    else
                    {
                        type = "Split";
                    }
                }
                else if (((p.Y < n1.Y) || ((p.Y == n1.Y) && (p.X > n1.Y))) && ((p.Y < n2.Y) || ((p.Y == n2.Y) && (p.X > n2.X))))
                {
                    if (angle < 180)
                    {
                        type = "End";
                    }
                    else
                    {
                        type = "Merge";
                    }
                }
                else
                {
                    type = "Regular";
                }

                EventPoint ev = new EventPoint(polygons[0].lines[i].Start, i, type, polygons[0].lines[i].End);
                Q.Add(ev);
                EventPoint prev;
                if (i != (polygons[0].lines.Count - 1))
                {
                    prev = new EventPoint(polygons[0].lines[i].Start, i, type, polygons[0].lines[i].End);
                    prev_event.Add(i + 1, prev);
                }
                else
                {
                    prev = new EventPoint(polygons[0].lines[i].Start, i, type, polygons[0].lines[i].End);
                    prev_event.Add(0, prev);
                }
            }

            while (Q.Count != 0)
            {
                EventPoint ev = Q.First();
                Y = ev.point.Y;
                if (ev.event_type == "Start")
                {
                    helper.Add(ev.index, ev);
                    T.Add(ev);
                }

                else if (ev.event_type == "End")
                {
                    if (ev.index - 1 >= 0)
                    {
                        if (helper[ev.index - 1].event_type == "Merge")
                        {
                            outLines.Add(new Line(ev.point, helper[ev.index - 1].point));
                        }
                        T.Remove(helper[ev.index - 1]);
                    }
                }

                else if (ev.event_type == "Merge")
                {
                    // if (ev.index - 1 >= 0)
                    //{
                    EventPoint ev2 = helper[ev.index - 1];
                    if (ev2.event_type == "Merge")
                    {
                        outLines.Add(new Line(ev.point, ev2.point));
                    }
                    EventPoint prev = prev_event[ev.index];
                    T.Remove(prev);
                    //}
                    KeyValuePair <EventPoint, EventPoint> temp = new KeyValuePair <EventPoint, EventPoint>(T.DirectUpperAndLower(ev).Key, T.DirectUpperAndLower(ev).Value);
                    if (temp.Value != null)
                    {
                        if (helper[temp.Value.index].event_type == "Merge")
                        {
                            outLines.Add(new Line(ev.point, helper[temp.Value.index].point));
                        }
                        helper[temp.Value.index] = ev;
                    }
                }

                else if (ev.event_type == "Split")
                {
                    KeyValuePair <EventPoint, EventPoint> temp = new KeyValuePair <EventPoint, EventPoint>(T.DirectUpperAndLower(ev).Key, T.DirectUpperAndLower(ev).Value);
                    if (temp.Value != null)
                    {
                        outLines.Add(new Line(ev.point, helper[temp.Value.index].point));
                        helper[temp.Value.index] = ev;
                    }
                    helper[ev.index] = ev;
                    T.Add(ev);
                }
                else
                {
                    var y = ev.edge.Y;
                    if (ev.point.Y > y)
                    {
                        if (ev.index - 1 >= 0)
                        {
                            if (helper[ev.index - 1].event_type == "Merge")
                            {
                                outLines.Add(new Line(ev.point, helper[ev.index - 1].point));
                            }

                            T.Remove(prev_event[ev.index]);
                        }
                        helper.Add(ev.index, ev);
                        T.Add(ev);
                    }
                    else
                    {
                        KeyValuePair <EventPoint, EventPoint> temp = new KeyValuePair <EventPoint, EventPoint>(T.DirectUpperAndLower(ev).Key, T.DirectUpperAndLower(ev).Value);
                        if (temp.Value != null)
                        {
                            if (helper[temp.Value.index].event_type == "Merge")
                            {
                                outLines.Add(new Line(ev.point, helper[temp.Value.index].point));
                                helper[temp.Value.index] = ev;
                            }
                        }
                    }
                }
                Q.Remove(ev);
            }
        }