Example #1
0
        private void ShowDetalizerNormals_Click(object sender, RoutedEventArgs e)
        {
            if (mid_surface_model == null)
            {
                return;
            }

            int step = 0;

            try
            {
                step = int.Parse(textBox_DebugNormalStep.Text);
            }
            catch
            {
                MessageBox.Show("Wrong format in debug parameters.\nFormat is:\n < step between points > ");
                return;
            }

            if (step <= 0)
            {
                MessageBox.Show("Enter positive number");
                return;
            }

            var         segments     = mid_surface_model.GetData();
            IMidSurface debugSurface = new MidSurface();

            for (int i = 0; i < segments.Count(); i++)
            {
                if (i % step != 0)
                {
                    continue;
                }

                var msseg = segments.ElementAt(i) as MSSegment;
                if (msseg == null)
                {
                    return;
                }

                var normal = msseg.GetMSPillar()[0].GetNormal();
                var parent = msseg.GetMSPillar()[0].GetParent();
                var R      = msseg.GetMSPillar()[0].GetRadius();

                ISegment normalSegment = new Segment(new BezierCurve(), new List <Point>()
                {
                    parent,
                    new Point(parent.X + R * normal.Dx(), parent.Y + R * normal.Dy())
                });

                debugSurface.Add(normalSegment);
            }

            View.VisibleDataSettings settings = new View.VisibleDataSettings();
            settings.Brush    = Brushes.Blue;
            settings.Thikness = 1;
            View.VisibleData visible_data = new View.VisibleData(debugSurface, settings);
            view.Paint(visible_data);
        }
Example #2
0
        private void ShowOnlyPoints_Click(object sender, RoutedEventArgs e)
        {
            if (mid_surface_model == null)
            {
                return;
            }

            var             segments    = mid_surface_model.GetData();
            List <ISegment> only_points = new List <ISegment>();

            foreach (var segment in segments)
            {
                ISegment point = new Segment(new BezierCurve(), new List <Point>()
                {
                    segment.GetPillar()[0],
                    Vector.Add(new Vector(1, 0), segment.GetPillar()[0])
                });
                only_points.Add(point);
            }

            IMidSurface points_surface = new MidSurface();

            foreach (var point in only_points)
            {
                points_surface.Add(point);
            }
            mainCanvas.Children.Clear();
            RedrawModel();
            View.VisibleDataSettings settings = new View.VisibleDataSettings();
            settings.Brush    = Brushes.Red;
            settings.Thikness = 2;
            View.VisibleData visible_data = new View.VisibleData(points_surface, settings);
            view.Paint(visible_data);
        }
Example #3
0
        private void ShowNormal_Click(object sender, RoutedEventArgs e)
        {
            if (model == null)
            {
                MessageBox.Show("No model is imported");
                return;
            }

            string[] debugParams = textBox_Debug.Text.Split(';');
            int      segmentNum  = 0;
            double   t           = 0;
            double   multiplier  = 0;

            try
            {
                segmentNum = int.Parse(debugParams[0]);
                t          = double.Parse(debugParams[1], CultureInfo.InvariantCulture);
                multiplier = double.Parse(debugParams[2], CultureInfo.InvariantCulture);
            }
            catch
            {
                MessageBox.Show("Wrong format in debug parameters.\nFormat is:\n    <segment number>;<t value>;<multiplier value>");
                return;
            }

            ISegment chosenSegment    = model.GetCanvasData().ElementAt(segmentNum);
            Point    pointOnSegment   = chosenSegment.GetCurvePoint(t);
            Normal   normalForSegment = chosenSegment.GetNormal(t);

            if (t == 0)
            {
                int prevSegmentNum = segmentNum == 0 ? model.GetCanvasData().Count() - 1 : segmentNum - 1;
                normalForSegment = normalForSegment.Combine(model.GetCanvasData().ElementAt(prevSegmentNum).GetNormal(1));
            }
            else if (t == 1)
            {
                int nextSegmentNum = segmentNum == model.GetCanvasData().Count() - 1 ? 0 : segmentNum + 1;
                normalForSegment = model.GetCanvasData().ElementAt(nextSegmentNum).GetNormal(0).Combine(normalForSegment);
            }
            ISegment normalSegment = new Segment(new BezierCurve(), new List <Point>()
            {
                pointOnSegment,
                new Point(pointOnSegment.X + multiplier * normalForSegment.Dx(), pointOnSegment.Y + multiplier * normalForSegment.Dy())
            });

            View.VisibleDataSettings settings = new View.VisibleDataSettings();
            settings.Brush    = Brushes.Blue;
            settings.Thikness = 1;
            IMidSurface debugSurface = new MidSurface();

            debugSurface.Add(normalSegment);
            View.VisibleData visible_data = new View.VisibleData(debugSurface, settings);
            view.Paint(visible_data);
        }
        public IMidSurface Join(List <Point> points)
        {
            IMidSurface midsurface = new MidSurface();

            for (int i = 0; i < points.Count; i++)
            {
                int j = i == points.Count - 1 ? 0 : i + 1;
                midsurface.Add(PointsToSegment(points[i], points[j]));
            }
            return(midsurface);
        }
        public IMidSurface Join(Graph graph)
        {
            IMidSurface midsurface = new MidSurface();

            foreach (var s in graph.GetEdges())
            {
                midsurface.Add(PointsToSegment(s.vertex1.point, s.vertex2.point));
            }

            return(midsurface);
        }
        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);
        }