private void AddSegment(SplineSegmentLinePoint lcp) { if (lcp == null) { return; } if (lcp.next != null) { RemoveFromAllCollections(((SplineSegmentLinePoint)lcp.next).inSeg); SegmentSpline seg = new SegmentSpline(); seg.startPoint = lcp as ISegmentPoint; seg.endPoint = lcp.next as ISegmentPoint; seg.spline = lcp.spline; _segment.Add(seg); AddTube(seg); } if (lcp.prev != null) { RemoveFromAllCollections(((SplineSegmentLinePoint)lcp.prev).outSeg); SegmentSpline seg = new SegmentSpline(); seg.startPoint = lcp.prev as ISegmentPoint; seg.endPoint = lcp as ISegmentPoint; seg.spline = lcp.spline; _segment.Add(seg); AddTube(seg); } }
public override void DeleteVertex(SplineLinePoint lcp) { if (lcp is SplineSegmentLinePoint) { SplineSegmentLinePoint lcpNew = lcp as SplineSegmentLinePoint; RemoveFromAllCollections(lcpNew.inSeg); RemoveFromAllCollections(lcpNew.outSeg); if ((lcp.prev != null) & (lcp.next != null)) { SegmentSpline seg = new SegmentSpline(); seg.startPoint = lcp.prev as ISegmentPoint; seg.endPoint = lcp.next as ISegmentPoint; seg.spline = lcp.spline; _segment.Add(seg); AddTube(seg); lcp.prev.next = lcp.next; } lcpNew.spline = null; _point.Remove(lcpNew); } }
public override void Refine() { double eps = 1.0; int itertion = 0; while (true) { List <SplineSegmentLinePoint> pointDel = new List <SplineSegmentLinePoint>(); foreach (var p in _point) { if (p.distance < eps) { pointDel.Add(p); } } foreach (var p in pointDel) { DeleteVertex(p); } itertion++; if ((pointDel.Count == 0) | (itertion > 10)) { break; } } itertion = 0; while (true) { List <SplineSegmentLinePoint> pointAdd = new List <SplineSegmentLinePoint>(); foreach (var s in _segment) { if (s.distance > eps) { SplineSegmentLinePoint lcp = new SplineSegmentLinePoint(); lcp.spline = s.spline; lcp.t = s.t; pointAdd.Add(lcp); } } foreach (var p in pointAdd) { AddVertex(p, LinePointAdditionMethod.intoSpline); } itertion++; if ((pointAdd.Count == 0) | (itertion > 10)) { break; } } }
public override void AddVertex(SplineLinePoint lcp, LinePointAdditionMethod method) { if (lcp == null) { return; } if (!ConfirmCollection()) { return; } if (lcp is SplineSegmentLinePoint) { SplineSegmentLinePoint lcpNew = lcp as SplineSegmentLinePoint; AddPointComponent component = new AddPointComponent(); component.lcp = lcpNew; component.collection = new LinePointCollection <SplineSegmentLinePoint>(_point); switch (method) { case LinePointAdditionMethod.last: { component.strategy = new AddPointStrategyLast(); break; } case LinePointAdditionMethod.first: { component.strategy = new AddPointStrategyFirst(); break; } case LinePointAdditionMethod.intoSpline: { component.strategy = new AddPointStrategyIntoSpline(); break; } default: { break; } } component.Build(); if ((!component.Complite()) & (_point.Count > 1)) { return; } _point.Add(lcpNew); AddSegment(lcpNew); } }