/// <summary> /// Helper function to find related segment /// </summary> /// <param name="conduitId"></param> /// <param name="pointOfInterestId"></param> /// <returns></returns> private List <RelatedSingleConduitSegmentInfo> FindRelatedSegmentInfo(ConduitInfo conduit, Guid pointOfInterestId, ConduitEndKindEnum?conduitEndKind = null) { List <RelatedSingleConduitSegmentInfo> result = new List <RelatedSingleConduitSegmentInfo>(); var walkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(conduit.GetRootConduit().WalkOfInterestId); foreach (var existingSegment in conduit.Segments.OfType <ConduitSegmentInfo>()) { var segmentWalk = walkOfInterest.SubWalk2(existingSegment.FromRouteNodeId, existingSegment.ToRouteNodeId); if (segmentWalk.StartNodeId == pointOfInterestId) { if (conduitEndKind == null || conduitEndKind.Value == ConduitEndKindEnum.Outgoing) { result.Add( new RelatedSingleConduitSegmentInfo() { Segment = existingSegment, RelationType = ConduitRelationTypeEnum.Outgoing } ); } } if (segmentWalk.EndNodeId == pointOfInterestId) { if (conduitEndKind == null || conduitEndKind.Value == ConduitEndKindEnum.Incomming) { result.Add( new RelatedSingleConduitSegmentInfo() { Segment = existingSegment, RelationType = ConduitRelationTypeEnum.Incomming } ); } } if (result.Count == 0 && segmentWalk.AllNodeIds.Contains(pointOfInterestId)) { if (conduitEndKind == null || conduitEndKind.Value == ConduitEndKindEnum.Incomming) { result.Add( new RelatedSingleConduitSegmentInfo() { Segment = existingSegment, RelationType = ConduitRelationTypeEnum.PassThrough } ); } } } return(result); }
/// <summary> /// Helper function to find related segment /// </summary> /// <param name="multiConduitId"></param> /// <param name="pointOfInterestId"></param> /// <returns></returns> private RelatedMultiConduitSegmentInfo FindRelatedSegmentInfo(ConduitInfo conduit, Guid pointOfInterestId) { var walkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(conduit.GetRootConduit().WalkOfInterestId); foreach (var existingSegment in conduit.Segments.OfType <ConduitSegmentInfo>()) { var segmentWalk = walkOfInterest.SubWalk2(existingSegment.FromRouteNodeId, existingSegment.ToRouteNodeId); if (segmentWalk.StartNodeId == pointOfInterestId) { return(new RelatedMultiConduitSegmentInfo() { Segment = existingSegment, RelationType = ConduitRelationTypeEnum.Outgoing }); } else if (segmentWalk.EndNodeId == pointOfInterestId) { return(new RelatedMultiConduitSegmentInfo() { Segment = existingSegment, RelationType = ConduitRelationTypeEnum.Incomming }); } else if (segmentWalk.AllNodeIds.Contains(pointOfInterestId)) { return(new RelatedMultiConduitSegmentInfo() { Segment = existingSegment, RelationType = ConduitRelationTypeEnum.PassThrough }); } } return(null); }
private void ResolveReferences(ConduitInfo condutiInfo) { var woi = routeNetworkQueryService.GetWalkOfInterestInfo(condutiInfo.GetRootConduit().WalkOfInterestId); // Resolve from node if (condutiInfo.FromRouteNode == null) { condutiInfo.FromRouteNode = routeNetworkQueryService.GetRouteNodeInfo(woi.StartNodeId); } // Resolve to node if (condutiInfo.ToRouteNode == null) { condutiInfo.ToRouteNode = routeNetworkQueryService.GetRouteNodeInfo(woi.EndNodeId); } // Resolve references inside segment foreach (var segment in condutiInfo.Segments.OfType <ConduitSegmentInfo>()) { // Resolve conduit reference segment.Conduit = condutiInfo; // Resolve conduit segment parent/child relationship if (segment.Conduit.Kind == ConduitKindEnum.InnerConduit) { // Create parents list if null if (segment.Parents == null) { segment.Parents = new List <ISegment>(); } var innerConduitSegmentWalkOfInterest = woi.SubWalk2(segment.FromRouteNodeId, segment.ToRouteNodeId); var multiConduit = segment.Conduit.Parent; // Go through each segment of the multi conduit to find if someone intersects with the inner conduit segment foreach (var multiConduitSegment in multiConduit.Segments) { // Create childre list if null if (multiConduitSegment.Children == null) { multiConduitSegment.Children = new List <ISegment>(); } var multiConduitSegmentWalkOfInterest = woi.SubWalk2(multiConduitSegment.FromRouteNodeId, multiConduitSegment.ToRouteNodeId); // Create hash set for quick lookup HashSet <Guid> multiConduitSegmentWalkOfInterestSegmetns = new HashSet <Guid>(); foreach (var segmentId in multiConduitSegmentWalkOfInterest.AllSegmentIds) { multiConduitSegmentWalkOfInterestSegmetns.Add(segmentId); } // check if overlap from segments of the inner conduit to the the multi conduit segment foreach (var innerConduitSegmentId in innerConduitSegmentWalkOfInterest.AllSegmentIds) { if (multiConduitSegmentWalkOfInterestSegmetns.Contains(innerConduitSegmentId)) { if (!multiConduitSegment.Children.Contains(segment)) { multiConduitSegment.Children.Add(segment); } if (!segment.Parents.Contains(multiConduitSegment)) { segment.Parents.Add(multiConduitSegment); } } } } } // From Junction if (segment.FromNodeId != Guid.Empty) { if (!_singleConduitJuncionInfos.ContainsKey(segment.FromNodeId)) { var newJunction = new SingleConduitSegmentJunctionInfo() { Id = segment.FromNodeId }; newJunction.AddToConduitSegment(segment); _singleConduitJuncionInfos.Add(newJunction.Id, newJunction); segment.FromNode = newJunction; } else { var existingJunction = _singleConduitJuncionInfos[segment.FromNodeId]; //existingJunction.ToConduitSegments = segment; existingJunction.AddToConduitSegment(segment); segment.FromNode = existingJunction; } } // To Junction if (segment.ToNodeId != Guid.Empty) { if (!_singleConduitJuncionInfos.ContainsKey(segment.ToNodeId)) { var newJunction = new SingleConduitSegmentJunctionInfo() { Id = segment.ToNodeId }; newJunction.AddFromConduitSegment(segment); _singleConduitJuncionInfos.Add(newJunction.Id, newJunction); segment.ToNode = newJunction; } else { var existingJunction = _singleConduitJuncionInfos[segment.ToNodeId]; existingJunction.AddFromConduitSegment(segment); segment.ToNode = existingJunction; } } } }
private void UpdateRouteSegmentPassByIndex(ConduitInfo oldConduitInfo, ConduitInfo newConduitInfo) { var conduitWalkOfInterest = routeNetworkQueryService.GetWalkOfInterestInfo(newConduitInfo.GetRootConduit().WalkOfInterestId); if (oldConduitInfo != null) { // Remove old references foreach (var segment in oldConduitInfo.Segments.OfType <ConduitSegmentInfo>()) { var passThroughRouteSegments = GetPassThroughRouteSegments(segment, conduitWalkOfInterest); foreach (var passThroughRouteSegment in passThroughRouteSegments) { _conduitSegmentPassByRouteSegmenttId[passThroughRouteSegment].Remove(segment); } } } // Add new references foreach (var segment in newConduitInfo.Segments.OfType <ConduitSegmentInfo>()) { var passThroughRouteSegments = GetPassThroughRouteSegments(segment, conduitWalkOfInterest); foreach (var passThroughRouteSegment in passThroughRouteSegments) { if (!_conduitSegmentPassByRouteSegmenttId.ContainsKey(passThroughRouteSegment)) { _conduitSegmentPassByRouteSegmenttId[passThroughRouteSegment] = new List <ISegment>(); } _conduitSegmentPassByRouteSegmenttId[passThroughRouteSegment].Add(segment); } } }