Пример #1
0
        /// <summary>
        /// checks if an edge intersects obstacles
        /// otherwise it calulates distances to the closest obstacles
        /// </summary>
        internal bool EdgeIsLegal(Station v, Station u, Point vPosition, Point uPosition, Set <Polyline> obstaclesToIgnore)
        {
            var start = v.Position;

            CdtTriangle currentTriangle = v.CdtTriangle;

            Debug.Assert(Cdt.PointIsInsideOfTriangle(start, currentTriangle));

            Point end = u.Position;

            if (Cdt.PointIsInsideOfTriangle(end, currentTriangle))
            {
                return(true);
            }

            var threader = new CdtThreader(currentTriangle, start, end);

            while (threader.MoveNext())
            {
                var piercedEdge = threader.CurrentPiercedEdge;
                if (piercedEdge.Constrained)
                {
                    Debug.Assert(piercedEdge.lowerSite.Owner == piercedEdge.upperSite.Owner);
                    var poly = (Polyline)piercedEdge.lowerSite.Owner;
                    if (!obstaclesToIgnore.Contains(poly))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// returns false iff the edge overlap an obstacle
        /// </summary>
        bool ThreadLineSegmentThroughTriangles(CdtTriangle currentTriangle, Point start, Point end, Set <Polyline> obstaclesToIgnore,
                                               out List <CdtTriangle> triangles)
        {
            Debug.Assert(Cdt.PointIsInsideOfTriangle(start, currentTriangle));
            triangles = new List <CdtTriangle>();

            if (Cdt.PointIsInsideOfTriangle(end, currentTriangle))
            {
                triangles.Add(currentTriangle);
                return(true);
            }

            var threader = new CdtThreader(currentTriangle, start, end);

            triangles.Add(currentTriangle);

            while (threader.MoveNext())
            {
                triangles.Add(threader.CurrentTriangle);
                var piercedEdge = threader.CurrentPiercedEdge;
                if (piercedEdge.Constrained)
                {
                    Debug.Assert(piercedEdge.lowerSite.Owner == piercedEdge.upperSite.Owner);
                    var poly = (Polyline)piercedEdge.lowerSite.Owner;
                    if (!obstaclesToIgnore.Contains(poly))
                    {
                        return(false);
                    }
                }
            }
            if (threader.CurrentTriangle != null)
            {
                triangles.Add(threader.CurrentTriangle);
            }
//
//            int positiveSign, negativeSign;
//            CdtEdge piercedEdge = FindFirstPiercedEdge(currentTriangle, start, end, out negativeSign, out positiveSign,  null);
//
//            Debug.Assert(positiveSign > negativeSign);
//
//            Debug.Assert(piercedEdge != null);
//
//            do {
//                triangles.Add(currentTriangle);
//                if (piercedEdge.Constrained) {
//                    Debug.Assert(piercedEdge.lowerSite.Owner == piercedEdge.upperSite.Owner);
//                    Polyline poly = (Polyline)piercedEdge.lowerSite.Owner;
//                    if (!obstaclesToIgnore.Contains(poly)) return false;
//                }
//            }
//            while (FindNextPierced(start, end, ref currentTriangle, ref piercedEdge, ref negativeSign, ref positiveSign));
//            if (currentTriangle != null)
//                triangles.Add(currentTriangle);

            return(true);
        }
        Set <CdtEdge> ThreadBoneEdgeThroughCdt(SdBoneEdge boneEdge)
        {
            var start           = boneEdge.SourcePoint;
            var currentTriangle = boneEdge.Source.Triangle;

            Debug.Assert(Cdt.PointIsInsideOfTriangle(start, currentTriangle));
            var crossedEdges = new Set <CdtEdge>();
            var end          = boneEdge.TargetPoint;

            if (Cdt.PointIsInsideOfTriangle(end, currentTriangle))
            {
                return(crossedEdges);
            }

            var threader = new CdtThreader(currentTriangle, start, end);

            while (threader.MoveNext())
            {
                CdtEdge piercedEdge = threader.CurrentPiercedEdge;
                Debug.Assert(piercedEdge != null);
                if (Gates.Contains(piercedEdge))
                {
                    crossedEdges.Insert(piercedEdge);
                }
            }

            /*
             * CdtEdge piercedEdge = CdtIntersections.FindFirstPiercedEdge(currentTriangle, start, end, out negativeSign, out positiveSign, this.Cdt );
             * Debug.Assert(piercedEdge != null);
             *
             * do {
             *  if (Gates.Contains(piercedEdge))
             *      crossedEdges.Insert(piercedEdge);
             * }
             * while (CdtIntersections.FindNextPierced(start, end, ref currentTriangle, ref piercedEdge, ref negativeSign, ref positiveSign));
             */
            //if(ddd(boneEdge))
            //CdtSweeper.ShowFront(Cdt.GetTriangles(),null,new []{new LineSegment(boneEdge.SourcePoint,boneEdge.TargetPoint)}, crossedEdges.Select(e=>new LineSegment(e.upperSite.Point,e.lowerSite.Point)));

            return(crossedEdges);
        }
Пример #4
0
        static List<DebugCurve> ThreadOnTriangle(Point start, Point end, CdtTriangle t) {
            var l = new List<DebugCurve> {new DebugCurve(10, "red", new LineSegment(start, end))};
            AddTriangleToListOfDebugCurves(l, t, 100, 3, "brown");
            var threader = new CdtThreader(t, start, end);
            foreach (var triangle in threader.Triangles()) {
                AddTriangleToListOfDebugCurves(l, triangle, 100, 3, "black");
//                CdtSweeper.ShowFront(trs, null, new ICurve[] { new LineSegment(start, end), new Polyline(triangle.Sites.Select(s => s.Point)) { Closed = true } }, new []{new LineSegment(threader.CurrentPiercedEdge.lowerSite.Point,threader.CurrentPiercedEdge.upperSite.Point) });
            }
            return l;
        }
        /// <summary>
        /// checks if an edge intersects obstacles
        /// otherwise it calulates distances to the closest obstacles
        /// </summary>
        internal bool EdgeIsLegal(Station v, Station u, Point vPosition, Point uPosition, Set<Polyline> obstaclesToIgnore) {
            var start = v.Position;

            CdtTriangle currentTriangle = v.CdtTriangle;
            Debug.Assert(Cdt.PointIsInsideOfTriangle(start, currentTriangle));

            Point end = u.Position;
            if (Cdt.PointIsInsideOfTriangle(end, currentTriangle)) {
                return true;
            }

            var threader = new CdtThreader(currentTriangle, start, end);
            
            while (threader.MoveNext()) {
                var piercedEdge = threader.CurrentPiercedEdge;
                if (piercedEdge.Constrained) {
                    Debug.Assert(piercedEdge.lowerSite.Owner == piercedEdge.upperSite.Owner);
                    var poly = (Polyline)piercedEdge.lowerSite.Owner;
                    if (!obstaclesToIgnore.Contains(poly)) return false;
                }
            }
            return true;
        }
        /// <summary>
        /// returns false iff the edge overlap an obstacle
        /// </summary>
        bool ThreadLineSegmentThroughTriangles(CdtTriangle currentTriangle, Point start, Point end, Set<Polyline> obstaclesToIgnore,
            out List<CdtTriangle> triangles) {
            Debug.Assert(Cdt.PointIsInsideOfTriangle(start, currentTriangle));
            triangles = new List<CdtTriangle>();

            if (Cdt.PointIsInsideOfTriangle(end, currentTriangle)) {
                triangles.Add(currentTriangle);
                return true;
            }

            var threader = new CdtThreader(currentTriangle, start, end);
            triangles.Add(currentTriangle);

            while (threader.MoveNext()) {
                triangles.Add(threader.CurrentTriangle);
                var piercedEdge = threader.CurrentPiercedEdge;
                if (piercedEdge.Constrained) {
                    Debug.Assert(piercedEdge.lowerSite.Owner == piercedEdge.upperSite.Owner);
                    var poly = (Polyline) piercedEdge.lowerSite.Owner;
                    if (!obstaclesToIgnore.Contains(poly)) return false;
                }                
            }
            if (threader.CurrentTriangle != null)
                triangles.Add(threader.CurrentTriangle);
//
//            int positiveSign, negativeSign;
//            CdtEdge piercedEdge = FindFirstPiercedEdge(currentTriangle, start, end, out negativeSign, out positiveSign,  null);
//            
//            Debug.Assert(positiveSign > negativeSign);
//
//            Debug.Assert(piercedEdge != null);
//
//            do {
//                triangles.Add(currentTriangle);
//                if (piercedEdge.Constrained) {
//                    Debug.Assert(piercedEdge.lowerSite.Owner == piercedEdge.upperSite.Owner);
//                    Polyline poly = (Polyline)piercedEdge.lowerSite.Owner;
//                    if (!obstaclesToIgnore.Contains(poly)) return false;
//                }
//            }
//            while (FindNextPierced(start, end, ref currentTriangle, ref piercedEdge, ref negativeSign, ref positiveSign));
//            if (currentTriangle != null)
//                triangles.Add(currentTriangle);

            return true;
        }
        Set<CdtEdge> ThreadBoneEdgeThroughCdt(SdBoneEdge boneEdge) {
            var start = boneEdge.SourcePoint;
            var currentTriangle = boneEdge.Source.Triangle;
            Debug.Assert(Cdt.PointIsInsideOfTriangle(start, currentTriangle));
            var crossedEdges = new Set<CdtEdge>();
            var end = boneEdge.TargetPoint;
            if (Cdt.PointIsInsideOfTriangle(end, currentTriangle))
                return crossedEdges;

            var threader = new CdtThreader(currentTriangle, start, end);
            while (threader.MoveNext()) {
                CdtEdge piercedEdge = threader.CurrentPiercedEdge;
                Debug.Assert(piercedEdge != null);
                if (Gates.Contains(piercedEdge))
                    crossedEdges.Insert(piercedEdge);
            }

            /*
            CdtEdge piercedEdge = CdtIntersections.FindFirstPiercedEdge(currentTriangle, start, end, out negativeSign, out positiveSign, this.Cdt );
            Debug.Assert(piercedEdge != null);
      
            do {
                if (Gates.Contains(piercedEdge))
                    crossedEdges.Insert(piercedEdge);
            }
            while (CdtIntersections.FindNextPierced(start, end, ref currentTriangle, ref piercedEdge, ref negativeSign, ref positiveSign));
            */
            //if(ddd(boneEdge))
            //CdtSweeper.ShowFront(Cdt.GetTriangles(),null,new []{new LineSegment(boneEdge.SourcePoint,boneEdge.TargetPoint)}, crossedEdges.Select(e=>new LineSegment(e.upperSite.Point,e.lowerSite.Point)));

            return crossedEdges;
        }
Пример #8
0
        private static void ThreadOnTriangle(Point start, Point end, CdtTriangle t) {
            var threader = new CdtThreader(t, start, end);
            while(threader.MoveNext()){}

        }