/// <summary>
 /// Quick-setups as priority junction: for every junctions on the road contianing
 /// the input segment traversing straight.
 /// </summary>
 public static void FixRoad(ushort initialSegmentId)
 {
     SegmentTraverser.Traverse(
         initialSegmentId,
         TraverseDirection.AnyDirection,
         TraverseSide.Straight,
         SegmentStopCriterion.None,
         VisitorFunc);
 }
        public static void Traverse(ushort initialSegmentId, TraverseDirection direction, TraverseSide side, LaneStopCriterion laneStopCrit, SegmentStopCriterion segStopCrit, NetInfo.LaneType?laneTypeFilter, VehicleInfo.VehicleType?vehicleTypeFilter, SegmentLaneVisitor laneVisitor)
        {
            IList <LanePos> initialSortedLanes = null;

            SegmentTraverser.Traverse(initialSegmentId, direction, side, segStopCrit, delegate(SegmentVisitData segData) {
                bool isInitialSeg = segData.initial;
                bool reverse      = !isInitialSeg && segData.viaStartNode == segData.viaInitialStartNode;
                bool ret          = false;
                Constants.ServiceFactory.NetService.ProcessSegment(segData.curGeo.SegmentId, delegate(ushort segmentId, ref NetSegment segment) {
                    Log._Debug($"SegmentLaneTraverser: Reached segment {segmentId}: isInitialSeg={isInitialSeg} viaStartNode={segData.viaStartNode} viaInitialStartNode={segData.viaInitialStartNode} reverse={reverse}");
                    IList <LanePos> sortedLanes = Constants.ServiceFactory.NetService.GetSortedLanes(segmentId, ref segment, null, laneTypeFilter, vehicleTypeFilter, reverse);

                    if (isInitialSeg)
                    {
                        initialSortedLanes = sortedLanes;
                    }
                    else if (initialSortedLanes == null)
                    {
                        throw new ApplicationException("Initial list of sorted lanes not set.");
                    }
                    else if (sortedLanes.Count != initialSortedLanes.Count && (laneStopCrit & LaneStopCriterion.LaneCount) != LaneStopCriterion.None)
                    {
                        Log._Debug($"SegmentLaneTraverser: Stop criterion reached @ {segmentId}: {sortedLanes.Count} current vs. {initialSortedLanes.Count} initial lanes");
                        return(false);
                    }

                    for (int i = 0; i < sortedLanes.Count; ++i)
                    {
                        Log._Debug($"SegmentLaneTraverser: Traversing segment lane {sortedLanes[i].laneIndex} @ {segmentId} (id {sortedLanes[i].laneId}, pos {sortedLanes[i].position})");

                        if (!laneVisitor(new SegmentLaneVisitData(segData, i, sortedLanes[i], initialSortedLanes[i])))
                        {
                            return(false);
                        }
                    }
                    ret = true;
                    return(true);
                });
                return(ret);
            });
        }
コード例 #3
0
ファイル: PriorityRoad.cs プロジェクト: me22/TMPE
        /// <summary>
        /// Quick-setups as priority junction: for every junctions on the road contianing
        /// the input segment traversing straight.
        /// </summary>
        public static IRecordable FixRoad(ushort initialSegmentId)
        {
            // Create segment list such that the first and last segments are at path end.
            List <ushort> segmentList = new List <ushort>(40);

            SegmentTraverser.Traverse(
                initialSegmentId,
                TraverseDirection.AnyDirection,
                TraverseSide.Straight,
                SegmentStopCriterion.None,
                data => {
                if (data.ViaInitialStartNode)
                {
                    segmentList.Add(data.CurSeg.segmentId);
                }
                else
                {
                    segmentList.Insert(0, data.CurSeg.segmentId);
                }
                return(true);
            });

            return(FixRoad(segmentList));
        }
        public static void Traverse(ushort initialSegmentId,
                                    TraverseDirection direction,
                                    TraverseSide side,
                                    LaneStopCriterion laneStopCrit,
                                    SegmentStopCriterion segStopCrit,
                                    NetInfo.LaneType?laneTypeFilter,
                                    VehicleInfo.VehicleType?vehicleTypeFilter,
                                    SegmentLaneVisitor laneVisitor)
        {
            IList <LanePos> initialSortedLanes = null;

            //-------------------------------------
            // Function applies via SegmentTraverser
            //-------------------------------------
            bool VisitorFun(SegmentVisitData segData)
            {
                bool isInitialSeg = segData.Initial;
                bool reverse      = !isInitialSeg && segData.ViaStartNode == segData.ViaInitialStartNode;
                bool ret          = false;

                //-------------------------------------
                // Function applies for each segment
                //-------------------------------------
                bool VisitorProcessFun(ushort segmentId, ref NetSegment segment)
                {
                    // Log._Debug($"SegmentLaneTraverser: Reached segment {segmentId}:
                    //     isInitialSeg={isInitialSeg} viaStartNode={segData.viaStartNode}
                    //     viaInitialStartNode={segData.viaInitialStartNode} reverse={reverse}");
                    ExtSegmentManager extSegmentManager = ExtSegmentManager.Instance;
                    IList <LanePos>   sortedLanes       = extSegmentManager.GetSortedLanes(
                        segmentId,
                        ref segment,
                        null,
                        laneTypeFilter,
                        vehicleTypeFilter,
                        reverse);

                    if (isInitialSeg)
                    {
                        initialSortedLanes = sortedLanes;
                    }
                    else if (initialSortedLanes == null)
                    {
                        throw new ApplicationException("Initial list of sorted lanes not set.");
                    }
                    else if (sortedLanes.Count != initialSortedLanes.Count &&
                             (laneStopCrit & LaneStopCriterion.LaneCount) !=
                             LaneStopCriterion.None)
                    {
                        // Log._Debug($"SegmentLaneTraverser: Stop criterion reached @ {segmentId}:
                        //     {sortedLanes.Count} current vs. {initialSortedLanes.Count} initial lanes");
                        return(false);
                    }

                    for (int i = 0; i < sortedLanes.Count; ++i)
                    {
                        // Log._Debug($"SegmentLaneTraverser: Traversing segment lane
                        //     {sortedLanes[i].laneIndex} @ {segmentId} (id {sortedLanes[i].laneId},
                        //     pos {sortedLanes[i].position})");

                        if (!laneVisitor(
                                new SegmentLaneVisitData(
                                    segData,
                                    i,
                                    sortedLanes[i],
                                    initialSortedLanes[i])))
                        {
                            return(false);
                        }
                    }

                    ret = true;
                    return(true);
                }

                ushort currentSegmentId = segData.CurSeg.segmentId;

                VisitorProcessFun(currentSegmentId, ref currentSegmentId.ToSegment());

                return(ret);
            }

            SegmentTraverser.Traverse(initialSegmentId, direction, side, segStopCrit, VisitorFun);
        }