void CreateGraphElements() {
     foreach (var sdVertex in vertexArray) {
         var vv = sdVertex.VisibilityVertex;
         foreach (var vEdge in vv.InEdges) {
             var boneEdge = new SdBoneEdge(vEdge, VisibilityVerticesToSdVerts[vEdge.Source], VisibilityVerticesToSdVerts[vEdge.Target]);
             var otherSdVertex = VisibilityVerticesToSdVerts[vEdge.Source];
             sdVertex.InBoneEdges.Add(boneEdge);
             otherSdVertex.OutBoneEdges.Add(boneEdge);
         }
     }
 }
        double CapacityOverflowCost(SdBoneEdge boneEdge)
        {
            if (Cdt == null || BundlingSettings.CapacityOverflowCoefficient == 0)
            {
                return(0);
            }
            double ret = 0;

            foreach (var cdtEdge in CrossedCdtEdgesOfBoneEdge(boneEdge))
            {
                ret += CostOfCrossingCdtEdgeLocal(capacityOverlowPenaltyMultiplier, BundlingSettings, CurrentEdgeGeometry, cdtEdge);
            }
            return(ret);
        }
Exemple #3
0
 void CreateGraphElements()
 {
     foreach (var sdVertex in vertexArray)
     {
         var vv = sdVertex.VisibilityVertex;
         foreach (var vEdge in vv.InEdges)
         {
             var boneEdge      = new SdBoneEdge(vEdge, VisibilityVerticesToSdVerts[vEdge.Source], VisibilityVerticesToSdVerts[vEdge.Target]);
             var otherSdVertex = VisibilityVerticesToSdVerts[vEdge.Source];
             sdVertex.InBoneEdges.Add(boneEdge);
             otherSdVertex.OutBoneEdges.Add(boneEdge);
         }
     }
 }
 void UpdateResidualCostsOfCrossedCdtEdges(SdBoneEdge boneEdge)
 {
     foreach (var cdtEdge in boneEdge.CrossedCdtEdges)
     {
         if (AdjacentToSourceOrTarget(cdtEdge))
         {
             continue;
         }
         if (cdtEdge.ResidualCapacity == cdtEdge.Capacity)
         {
             cdtEdge.ResidualCapacity -= CurrentEdgeGeometry.LineWidth;
         }
         else
         {
             cdtEdge.ResidualCapacity -= (CurrentEdgeGeometry.LineWidth + BundlingSettings.EdgeSeparation);
         }
         //TODO: can we have negative here?
         //Debug.Assert(cdtEdge.ResidualCapacity >= 0);
     }
 }
        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);
        }
        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;
        }
        IEnumerable<CdtEdge> CrossedCdtEdgesOfBoneEdge(SdBoneEdge boneEdge) {
            if (boneEdge.CrossedCdtEdges != null)
                return boneEdge.CrossedCdtEdges;
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=368
            boneEdge.CrossedCdtEdges = ThreadBoneEdgeThroughCdt(boneEdge);
            return boneEdge.CrossedCdtEdges;
#else
            return boneEdge.CrossedCdtEdges = ThreadBoneEdgeThroughCdt(boneEdge);
#endif
        }
 double CapacityOverflowCost(SdBoneEdge boneEdge) {
     if (Cdt == null || BundlingSettings.CapacityOverflowCoefficient == 0)
         return 0;
     double ret = 0;
     foreach (var cdtEdge in CrossedCdtEdgesOfBoneEdge(boneEdge)) {
         ret += CostOfCrossingCdtEdgeLocal(capacityOverlowPenaltyMultiplier, BundlingSettings, CurrentEdgeGeometry, cdtEdge);
     }
     return ret;
 }
 double GetEdgeAdditionalCost(SdBoneEdge boneEdge, double previousCost) {
     var len = (boneEdge.TargetPoint - boneEdge.SourcePoint).Length;
     return LengthCoefficient * len + previousCost +
         (boneEdge.IsOccupied ? 0 : BundlingSettings.InkImportance * len) + CapacityOverflowCost(boneEdge);
 }
 void UpdateResidualCostsOfCrossedCdtEdges(SdBoneEdge boneEdge) {
     foreach (var cdtEdge in boneEdge.CrossedCdtEdges) {
         if (AdjacentToSourceOrTarget(cdtEdge))
             continue;
         if (cdtEdge.ResidualCapacity == cdtEdge.Capacity)
             cdtEdge.ResidualCapacity -= CurrentEdgeGeometry.LineWidth;
         else
             cdtEdge.ResidualCapacity -= (CurrentEdgeGeometry.LineWidth + BundlingSettings.EdgeSeparation);
         //TODO: can we have negative here?
         //Debug.Assert(cdtEdge.ResidualCapacity >= 0);
     }
 }
 void RegisterPathInBoneEdge(SdBoneEdge boneEdge) {
     boneEdge.AddOccupiedEdge();
     if (Cdt != null && BundlingSettings.CapacityOverflowCoefficient != 0)
         UpdateResidualCostsOfCrossedCdtEdges(boneEdge);
 }
        void ProcessBoneEdge(SdVertex v, SdVertex queueCandidate, SdBoneEdge boneEdge) {
            double newCost = GetEdgeAdditionalCost(boneEdge, v.Cost);
            if (queueCandidate.Cost <= newCost) return;
            queueCandidate.Cost = newCost;
            queueCandidate.PrevEdge = boneEdge;
            if (Queue.ContainsElement(queueCandidate))
                Queue.DecreasePriority(queueCandidate, newCost);
            else {
                if (queueCandidate.IsTargetOfRouting) {
                    double costToTarget = 0;
                    if (CurrentEdgeGeometry.TargetPort is ClusterBoundaryPort)
                        costToTarget = LengthCoefficient * (queueCandidate.Point - CurrentEdgeGeometry.TargetPort.Location).Length;

                    if (newCost + costToTarget < LowestCostToTarget) {
                        LowestCostToTarget = newCost + costToTarget;
                        ClosestTargetVertex = queueCandidate;
                    }
                    return; //do not enqueue the target vertices
                }
                Enqueue(queueCandidate);
            }
        }
        void ProcessIncomingBoneEdge(SdVertex v, SdBoneEdge inBoneEdge, Point pathDirection, bool lookingForMonotonePath) {
            Debug.Assert(v == inBoneEdge.Target);
            if (lookingForMonotonePath && pathDirection * (inBoneEdge.SourcePoint - inBoneEdge.TargetPoint) < 0) return;

            ProcessBoneEdge(v, inBoneEdge.Source, inBoneEdge);
        }
        void ProcessOutcomingBoneEdge(SdVertex v, SdBoneEdge outBoneEdge, Point pathDirection, bool lookingForMonotonePath) {
            Debug.Assert(v == outBoneEdge.Source);
            if (lookingForMonotonePath && pathDirection * (outBoneEdge.TargetPoint - outBoneEdge.SourcePoint) < 0) return;

            ProcessBoneEdge(v, outBoneEdge.Target, outBoneEdge);
        }