public List <IMSPoint> Run(ISolverData solverdata, double splitterAccuracy, double detalizerAccuracy) { List <IContour> contours = solverdata.GetContours(); List <ISegment> segments = new List <ISegment>(); foreach (var contour in contours) { segments.AddRange(contour.GetSegments()); } simplifiedModel = new Splitter().Split(solverdata.GetContours(), splitterAccuracy); IMSPointFinder mspointfinder = new MSPointFinder(simplifiedModel, splitterAccuracy); IDetailizer detailizer = new Detailizer(mspointfinder, simplifiedModel, segments, detalizerAccuracy); return(detailizer.Detalize()); }
public List <IContour> GetContours() { IFigure figures = new Figure(); List <IContour> contours = solverdata.GetContours(); int i = 0; foreach (var contour in contours) { IContour new_contour = new Contour(); foreach (ISegment segment in contour.GetSegments()) { if (!removed[i]) { new_contour.Add(segment); } i++; } figures.Add(new_contour); } return(figures.GetContours().ToList()); }
public IMidSurface Run(ISolverData solverdata) { IMidSurface midsurface = new MidSurface(); maxLengthModel = FindMaxLength(solverdata.GetContours(), 0.01); BaseAlgorithm baseAlgorithm = new BaseAlgorithm(); List <IMSPoint> msPoints = baseAlgorithm.Run(solverdata, splitterAccuracy * maxLengthModel, detalizerAccuracy * maxLengthModel); //Graph msGraph = ConstructGraph(msPoints); //msGraph.RemoveCycles(maxCycleSize); //List<Point> points = msGraph.GetPath(); ////Точки для работы //List<IMSPoint> new_mspoints = ConvertPointToMSPoint(points, msPoints); IJoinMSPoints jointpoints = new JoinMSPoints(); return(jointpoints.Join(msPoints)); }
public IMidSurface Run(ISolverData solverdata) { List <ICustomLine> simplifiedModel; IMidSurface midsurface = new MidSurface(); List <IContour> contours = solverdata.GetContours(); List <ISegment> segments = new List <ISegment>(); foreach (var contour in contours) { segments.AddRange(contour.GetSegments()); } double X_Min = segments[0].GetCurvePoint(0).X, X_Max = segments[0].GetCurvePoint(0).X, Y_Min = segments[0].GetCurvePoint(0).Y, Y_Max = segments[0].GetCurvePoint(0).Y; foreach (var seg in segments) { for (double t = 0d; t <= 1; t += 0.1) { if (X_Min >= seg.GetCurvePoint(t).X) { X_Min = seg.GetCurvePoint(t).X; } if (Y_Min >= seg.GetCurvePoint(t).Y) { Y_Min = seg.GetCurvePoint(t).Y; } if (X_Max <= seg.GetCurvePoint(t).X) { X_Max = seg.GetCurvePoint(t).X; } if (Y_Max <= seg.GetCurvePoint(t).Y) { Y_Max = seg.GetCurvePoint(t).Y; } } } simplifiedModel = new Splitter().Split(solverdata.GetContours(), splitterAccuracy); List <Point> mspoints = new List <Point>(); Point prev = new Point(); for (double d = X_Min + detalizerAccuracy / 10; d <= X_Max - detalizerAccuracy / 10; d += detalizerAccuracy) { List <Point> points = GetIntersectionPoints(simplifiedModel, new Point(d, Y_Min - detalizerAccuracy), new Point(d, Y_Max + detalizerAccuracy)); points.Sort(new ForY()); Point center; int index = 0; if (points.Count == 0) { continue; } else if (points.Count == 2) { //// midsurface.Add(new Segment(new BezierCurve(), new List<Point> { points[0], points[1] })); //DEBUG index = 0; center = new Point(d, (points[index].Y + points[index + 1].Y) / 2); } //TODO: Dinar: avoid paths with intersections //else if (points.Count % 2 == 0) //{ // //midsurface.Add(new Segment(new BezierCurve(), new List<Point> { points[0], points[1] })); //DEBUG // double MinDistance = Math.Max(X_Max - X_Min, Y_Max - Y_Min); // for (int k = 0; k < points.Count - 1; k += 2) // { // List<Point> not_allowed = GetIntersectionPoints(simplifiedModel, prev, new Point(d, (points[k + 1].Y + points[k].Y) / 2)); // if (not_allowed.Count > 0) { continue; } // if (Distance(prev, points[k], points[k + 1]) < MinDistance) // { // MinDistance = Distance(prev, points[k], points[k + 1]); // index = k; // } // } // center = new Point(d, (points[index + 1].Y + points[index].Y) / 2); //} //else if (points.Count > 0) { center = points[0]; } else { continue; } ////TODO: Dinar: shift center for maximize R //int step_line =5; //double diff = Math.Abs(points[index+1].Y - points[index].Y) / (double)(step_line + 1); //double prevR = Math.Abs(points[index + 1].Y - points[index].Y); //while (step_line-- >= -1) //{ // double R = Math.Abs(points[index + 1].Y - points[index].Y); // int step = 5; // while (step-- > -1) // { // if (GetIntersecCount(simplifiedModel, center, R) > 0) // R = R * 0.5; // else // R = R * 1.5; // } // if (Math.Abs(prevR - R) < 0.1) // { // int p1 = GetIntersecCount(simplifiedModel, new Point(d, Math.Abs(points[index + 1].Y - points[index].Y) / 5 + points[index].Y), R); // int p2= GetIntersecCount(simplifiedModel, new Point(d, 4 * Math.Abs(points[index + 1].Y - points[index].Y) / 5 + points[index].Y), R); // if (p1==p2) { step_line = -1; } // else if (p1>p2) // center.Y = 4 * Math.Abs(points[index + 1].Y - points[index].Y) / 5 + points[index].Y; // else center.Y = Math.Abs(points[index + 1].Y - points[index].Y) / 5 + points[index].Y; // } // else // if (prevR > R) // { // diff = -diff; // center.Y += diff; // } // else center.Y += diff; // prevR = R; //} prev = center; mspoints.Add(center); } for (int i = 0; i < mspoints.Count - 1; ++i) { midsurface.Add(new Segment(new BezierCurve(), new List <Point> { mspoints[i], mspoints[i + 1] })); } return(midsurface); }