private int CreateFlatEnds([NotNull] NeighboredSegmentsSubpart segmentsSubpartx, double rowDistance, [NotNull] Dictionary <FeaturePoint, SegmentInfo> flatEnds, [NotNull] ContinuationFinder continuationFinder, bool atStart) { var errorCount = 0; double sumLength = 0; SegmentProxyInfo first = null; foreach (SegmentProxyInfo info in GetSegmentProxies(segmentsSubpartx, continuationFinder, atStart)) { first = first ?? info; var segmentPartKey = new SegmentPart(info.SegmentProxy, 0, 1, complete: true); NeighboredSegmentsSubpart segmentsSubpart = info.Subpart; SegmentParts neighboredParts; segmentsSubpart.SegmentNeighbors.TryGetValue(segmentPartKey, out neighboredParts); var featurePointKey = new FeaturePoint( segmentsSubpart.BaseFeature, segmentsSubpart.TableIndex, segmentPartKey.PartIndex, segmentPartKey.SegmentIndex); SegmentInfo segmentInfo; if (!flatEnds.TryGetValue(featurePointKey, out segmentInfo)) { // TODO revise: neighboredParts can be null here, but SegmentInfo property is later expected to be NotNull segmentInfo = new SegmentInfo(neighboredParts); flatEnds.Add(featurePointKey, segmentInfo); } if (atStart) { segmentInfo.FlatStart = true; } else { segmentInfo.FlatEnd = true; } if (info != first) { errorCount += VerifyAngle(first, info, rowDistance, segmentsSubpart); } sumLength += info.SegmentProxy.Length; if (sumLength >= rowDistance) { break; } } return(errorCount); }
private void DropCoincidentParts( [NotNull] NeighboredSegmentsSubpart featurePart, [NotNull] Dictionary <SegmentPartWithNeighbor, List <SegmentPartWithNeighbor> > coincidents, [NotNull] HashSet <FeaturePoint> dropParts, [NotNull] List <NeighboredSegmentsSubpart> nonCoincidentParts) { foreach (List <SegmentPartWithNeighbor> coincidentParts in coincidents.Values) { foreach (SegmentPartWithNeighbor coincidentPart in coincidentParts) { dropParts.Add(coincidentPart.CreateNeighborFeaturePoint()); } } // TODO? : transfer SegmentParts of coincident neighbor (due to differing offsets) var dropNeighbors = new Dictionary <SegmentPartWithNeighbor, SegmentPartWithNeighbor>(); foreach (List <SegmentPartWithNeighbor> coincidentParts in coincidents.Values) { foreach ( SegmentPartWithNeighbor coincidentPart in coincidentParts) { dropNeighbors.Add(coincidentPart, coincidentPart); } } foreach ( SegmentParts segmentParts in featurePart.SegmentNeighbors.Values) { List <SegmentPart> remaining = new SegmentParts(); foreach (SegmentPart segmentPart in segmentParts) { var part = (SegmentPartWithNeighbor)segmentPart; if (!dropNeighbors.ContainsKey(part)) { remaining.Add(part); } } segmentParts.Clear(); segmentParts.AddRange(remaining); } nonCoincidentParts.Add(featurePart); }
private IEnumerable <SegmentPartWithNeighbor> GetNeighbors( NeighboredSegmentsSubpart subparts) { foreach ( KeyValuePair <SegmentPart, SegmentParts> segmentNeighbor in subparts.SegmentNeighbors) { foreach (SegmentPart neighbor in segmentNeighbor.Value) { var segmentPart = (SegmentPartWithNeighbor)neighbor; yield return(segmentPart); } } }
private static SegmentProxyInfo GetSegmentproxyInfo( [NotNull] NeighboredSegmentsSubpart segmentsSubpart, int baseSegmentIndex) { int subpartIndex = segmentsSubpart.FullStartFraction < segmentsSubpart.FullEndFraction ? baseSegmentIndex - segmentsSubpart.FullStartFraction : segmentsSubpart.FullStartFraction - baseSegmentIndex - 1; SegmentProxy segmentProxy = segmentsSubpart.GetSegment(subpartIndex); var key = new SegmentPart(segmentProxy, 0, 1, true); // SegmentPart key = new SegmentPart(segmentsSubpart.PartIndex, iSegment, 0, 1, true); SegmentParts segmentParts; segmentsSubpart.SegmentNeighbors.TryGetValue(key, out segmentParts); return(new SegmentProxyInfo(segmentProxy, segmentsSubpart)); }
private bool HandleAsFlat(NeighboredSegmentsSubpart segmentPart, double fullFraction, ContinuationFinder continuationFinder) { var p = new FeaturePoint(segmentPart.BaseFeature, segmentPart.TableIndex, segmentPart.PartIndex, fullFraction); List <NeighboredSegmentsSubpart> continuations = continuationFinder.GetContinuations(p, new List <SegmentsSubpart>(), false); if (continuations == null) { return(AdaptUnconnected); } var junctionSegments = new List <NeighboredSegmentsSubpart>(); foreach (NeighboredSegmentsSubpart continuation in continuations) { if (p.Feature == continuation.BaseFeature && p.TableIndex == continuation.TableIndex && p.Part == continuation.PartIndex && Math.Abs(p.FullFraction - continuation.FullStartFraction) < 0.01) { junctionSegments.Add(continuation); continue; } if (NotReportedCondition != null && NotReportedCondition.IsFulfilled(segmentPart.BaseFeature, segmentPart.TableIndex, continuation.BaseFeature, continuation.TableIndex)) { continue; } if (string.IsNullOrEmpty(JunctionIsEndExpression)) { return(false); } junctionSegments.Add(continuation); } if (junctionSegments.Count > 0) { var rule = new QaConnectionRule(new[] { junctionSegments[0].BaseFeature.Table }, new List <string> { JunctionIsEndExpression }); TableView[] tableFilterHelpers; IList <QaConnectionRuleHelper> helpers = QaConnectionRuleHelper.CreateList( new[] { rule }, out tableFilterHelpers); foreach (NeighboredSegmentsSubpart junctionSegment in junctionSegments) { int tableIndex = junctionSegment.TableIndex; TableView baseHelper = tableFilterHelpers[tableIndex]; DataRow helperRow = baseHelper.Add(junctionSegment.BaseFeature); Assert.NotNull(helperRow, "no row returned"); { helperRow[QaConnections.StartsIn] = segmentPart.FullStartFraction < segmentPart.FullEndFraction; } } foreach (QaConnectionRuleHelper ruleHelper in helpers) { // check if all rows comply to the current rule int connectedElementsCount = junctionSegments.Count; var matchingRowsCount = 0; for (var tableIndex = 0; tableIndex < 1; tableIndex++) { matchingRowsCount += ruleHelper .MainRuleFilterHelpers[tableIndex] .FilteredRowCount; } Assert.True(matchingRowsCount <= connectedElementsCount, "Unexpected matching rows count: {0}; total connected rows: {1}", matchingRowsCount, connectedElementsCount); if (matchingRowsCount == connectedElementsCount && ruleHelper.VerifyCountRules()) { // all rows comply to the current rule, // so one rule if fulfilled and no further checking needed return(true); } } } return(AdaptUnconnected); }
private IEnumerable <SegmentProxyInfo> GetSegmentProxies( [NotNull] NeighboredSegmentsSubpart segmentsSubpart, [NotNull] ContinuationFinder continuationFinder, bool atStart) { FeaturePoint continuationKey; if (atStart) { for (int iSegment = segmentsSubpart.FullMinFraction; iSegment < segmentsSubpart.FullMaxFraction; iSegment++) { yield return(GetSegmentproxyInfo(segmentsSubpart, iSegment)); } continuationKey = new FeaturePoint(segmentsSubpart.BaseFeature, segmentsSubpart.TableIndex, segmentsSubpart.PartIndex, segmentsSubpart.FullMaxFraction); } else { for (int iSegment = segmentsSubpart.FullMaxFraction - 1; iSegment >= segmentsSubpart.FullMinFraction; iSegment--) { yield return(GetSegmentproxyInfo(segmentsSubpart, iSegment)); } continuationKey = new FeaturePoint(segmentsSubpart.BaseFeature, segmentsSubpart.TableIndex, segmentsSubpart.PartIndex, segmentsSubpart.FullMinFraction); } List <NeighboredSegmentsSubpart> continuations = continuationFinder.GetContinuations(continuationKey, new List <SegmentsSubpart>(), false); if (continuations == null) { yield break; } foreach (NeighboredSegmentsSubpart continuation in continuations) { if (continuation.BaseFeature.OID != segmentsSubpart.BaseFeature.OID || continuation.TableIndex != segmentsSubpart.TableIndex || continuation.PartIndex != segmentsSubpart.PartIndex) { continue; } if (atStart && continuation.FullMinFraction != segmentsSubpart.FullMaxFraction) { continue; } if (!atStart && continuation.FullMaxFraction != segmentsSubpart.FullMinFraction) { continue; } foreach ( SegmentProxyInfo segmentProxy in GetSegmentProxies(continuation, continuationFinder, atStart)) { yield return(segmentProxy); } } }
public SegmentProxyInfo([NotNull] SegmentProxy segmentProxy, [NotNull] NeighboredSegmentsSubpart subpart) { SegmentProxy = segmentProxy; Subpart = subpart; }
private void FindDropParts(NeighboredSegmentsSubpart featurePart, HashSet <FeaturePoint> dropParts, List <NeighboredSegmentsSubpart> nonCoincidentParts, out int errorCount) { Dictionary <SegmentPartWithNeighbor, List <SegmentPartWithNeighbor> > coincidents = null; SegmentNeighbors segmentsNeighbors = featurePart.SegmentNeighbors; var first = true; NearDistanceProvider.GetRowsDistance(featurePart.BaseFeature, featurePart.TableIndex); for (int i = featurePart.FullMinFraction; i < featurePart.FullMaxFraction; i++) { if (!first && coincidents == null) { break; } var key = new SegmentPart(featurePart.PartIndex, i, 0, 1, true); SegmentParts segmentNeighbors; if (!segmentsNeighbors.TryGetValue(key, out segmentNeighbors)) { coincidents = null; break; } var remaining = new Dictionary <SegmentPartWithNeighbor, List <SegmentPartWithNeighbor> >(); foreach (SegmentPart segmentPart in segmentNeighbors) { var segmentNeighbor = (SegmentPartWithNeighbor)segmentPart; if (segmentNeighbor.NeighborIsCoincident) { if (first) { remaining.Add( segmentNeighbor, new List <SegmentPartWithNeighbor> { segmentNeighbor }); } else { int segmentIndex = i - featurePart.FullMinFraction; FindCoincident(coincidents, segmentNeighbor, segmentIndex, remaining); } } } coincidents = remaining; if (coincidents.Count == 0) { coincidents = null; } first = false; } if (coincidents == null) { nonCoincidentParts.Add(featurePart); errorCount = 0; return; } // Check if is lowest part bool keepPart = CheckKeepPart(featurePart, coincidents, out errorCount); if (keepPart) { DropCoincidentParts(featurePart, coincidents, dropParts, nonCoincidentParts); } }
private bool CheckKeepPart( [NotNull] NeighboredSegmentsSubpart featurePart, [NotNull] Dictionary <SegmentPartWithNeighbor, List <SegmentPartWithNeighbor> > coincidents, out int errorCount) { double featureAura = NearDistanceProvider.GetRowsDistance( featurePart.BaseFeature, featurePart.TableIndex) .GetRowDistance(); var keepPart = true; List <CoincidenceError> errorParts = null; foreach (SegmentPartWithNeighbor neighbor in coincidents.Keys) { double neighborAura = NearDistanceProvider.GetRowsDistance( neighbor.NeighborFeature, neighbor.NeighborTableIndex) .GetRowDistance(); int d = Compare(featurePart, featureAura, neighbor, neighborAura); if (d != 0) { keepPart = d < 0; if (keepPart && neighborAura > 0) { errorParts = errorParts ?? new List <CoincidenceError>(); errorParts.Add(new CoincidenceError { DroppedPart = neighbor, UsedPart = featurePart }); } } if (!keepPart) { break; } } if (keepPart && errorParts?.Count > 0) { errorCount = 0; Func <CoincidenceError, int> reportError = ReportCoincidenceError; if (reportError != null) { foreach (CoincidenceError errorPart in errorParts) { errorCount += reportError(errorPart); } } } else { errorCount = 0; } return(keepPart); }