Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我怎样才能得到;“稀释剂”;我的坐标系的图形?_C#_C++_Algorithm_Logic - Fatal编程技术网

C# 我怎样才能得到;“稀释剂”;我的坐标系的图形?

C# 我怎样才能得到;“稀释剂”;我的坐标系的图形?,c#,c++,algorithm,logic,C#,C++,Algorithm,Logic,接下来,我得到了一组坐标,并将它们作为坐标系绘制在位图图像上。现在,我想消除所有噪音,过滤坐标,以提供“更清晰”或“更清晰”的路径和“更少”或“更好”的数据。为了进一步解释,我需要展示我的绝妙的绘画技巧,如下所示: 当前: 所需: 注意: 我需要删除坐标 我可能需要添加坐标 在某些情况下,我可能需要忽略最短的邻居 我唯一能想到的就是使用最短路径算法,如和。并以某种数据结构填充数据,以包含每个节点的邻居和成本,然后执行算法。我不想开始一些可能是错误的或浪费的事情。如果可能的话,我希望在上看

接下来,我得到了一组坐标,并将它们作为坐标系绘制在位图图像上。现在,我想消除所有噪音,过滤坐标,以提供“更清晰”或“更清晰”的路径和“更少”或“更好”的数据。为了进一步解释,我需要展示我的绝妙的绘画技巧,如下所示:

当前:

所需:

注意:

  • 我需要删除坐标

  • 我可能需要添加坐标

  • 在某些情况下,我可能需要忽略最短的邻居

我唯一能想到的就是使用最短路径算法,如和。并以某种数据结构填充数据,以包含每个节点的邻居和成本,然后执行算法。我不想开始一些可能是错误的或浪费的事情。如果可能的话,我希望在上看到一个伪代码。我如何解决这样的问题


我现在在WPF C,但是我对任何任务都可以使用C或C++。谢谢

你可能想考虑把你的坐标当作二值图像,并把它应用到图像中。


可能会给你带来好的结果,但是这样的处理可能会在各种各样的情况下工作得很好。

你可能想考虑把你的坐标当作二值图像并应用到图像中。


可能会给您带来很好的结果,但这样的处理在很多情况下都很难正常工作。

您需要的是一个路径查找应用程序。有几种方法可以实现这一点,但其中一种更简单的方法是:

Pick a starting point, add to list
While True:
    For each border_pt bordering last point on list:
        Count number of points bordering border_pt
        If count > best_count:
            Mark border_pt as best

    if border_pt is empty:
        break

    Add border_pt to list
下面是一些C代码,它可以根据您的云生成一个简单的列表:

使用系统;
使用System.Collections.Generic;
使用系统诊断;
使用系统图;
使用System.Linq;
使用System.Threading.Tasks;
使用System.Windows.Forms;
命名空间Windows窗体应用程序1
{
课程示例程序:表单
{
const int GridWidth=24;
const int GridHeight=15;
列出m_点=新列表();
列表m_trail=新列表();
[状态线程]
静态void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
运行(新的ExampleProgram());
}
示例程序()
{
//简单的小工具,添加一堆点
地址(
0, 4, 1, 3, 1, 4, 1, 5, 2, 4, 2, 5, 2, 6, 3, 4, 3, 5, 4, 5, 4, 6, 5, 5, 6, 5,
6, 4, 5, 4, 7, 4, 7, 3, 8, 3, 8, 4, 8, 5, 8, 6, 9, 6, 9, 5, 9, 4, 9, 3, 10, 2,
10, 3, 10, 4, 10, 5, 10, 6, 11, 5, 11, 4, 11, 3, 11, 2, 12, 4, 12, 5, 13, 5,
13, 6, 13, 8, 14, 8, 14, 7, 14, 6, 15, 7, 15, 8, 15, 9, 14, 9, 14, 10, 13, 10,
12, 10, 11, 10, 13, 11, 14, 11, 15, 11, 15, 12, 16, 12, 17, 12, 18, 12, 19,
12, 18, 11, 17, 11, 17, 10, 18, 10, 19, 10, 19, 9, 19, 8, 20, 8, 21, 8, 18,
7, 19, 7, 20, 7, 21, 7, 21, 6, 22, 6, 23, 6, 21, 5, 20, 5, 19, 5, 19, 4, 18,
4, 17, 4, 20, 3, 21, 3, 22, 3, 20, 2, 19, 2, 18, 2, 19, 1, 20, 1, 21, 1, 19,
0, 18, 0, 10, 0, 4, 1);
//非常基本的形式逻辑
ClientSize=新系统.Drawing.Size(网格宽度*20,网格高度*20);
双缓冲=真;
Paint+=示例程序\u Paint;
//向表单中添加新点(注释掉)
//MouseUp+=示例程序\u MouseUp\u添加点;
//画出我们找到的线索
MouseUp+=示例程序\u MouseUp\u AddTrail;
//选择一个开始点,从中开始查找轨迹
//待办事项:留作练习,供读者决定如何挑选
//程序化的起点
m_trail.Add(新点(0,4));
}
IEnumerable边框(点pt)
{
//返回与给定点相邻的所有点
如果(pt.X>0)
{
如果(第Y部分>0)
{
收益率返回新点(点X-1,点Y-1);
}
收益率返回新点(点X-1,点Y);
如果(第Y部分<网格高度-1)
{
收益率返回新点(点X-1,点Y+1);
}
}
如果(第Y部分>0)
{
收益率返回新点(pt.X,pt.Y-1);
}
如果(第Y部分<网格高度-1)
{
收益率返回新点(pt.X,pt.Y+1);
}
如果(pt.X<网格宽度-1)
{
如果(第Y部分>0)
{
收益率返回新点(点X+1,点Y-1);
}
收益率返回新点(pt.X+1,pt.Y);
如果(第Y部分<网格高度-1)
{
收益率返回新点(点X+1,点Y+1);
}
}
}
无效添加点(参数int[]点)
{
//帮助器将一组点添加到我们的点列表中
对于(int i=0;iusing System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    class ExampleProgram : Form
    {
        const int GridWidth = 24;
        const int GridHeight = 15;

        List<Point> m_points = new List<Point>();
        List<Point> m_trail = new List<Point>();

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new ExampleProgram());
        }

        ExampleProgram()
        {
            // Simple little tool to add a bunch of points
            AddPoints(
                0, 4, 1, 3, 1, 4, 1, 5, 2, 4, 2, 5, 2, 6, 3, 4, 3, 5, 4, 5, 4, 6, 5, 5, 6, 5,
                6, 4, 5, 4, 7, 4, 7, 3, 8, 3, 8, 4, 8, 5, 8, 6, 9, 6, 9, 5, 9, 4, 9, 3, 10, 2,
                10, 3, 10, 4, 10, 5, 10, 6, 11, 5, 11, 4, 11, 3, 11, 2, 12, 4, 12, 5, 13, 5,
                13, 6, 13, 8, 14, 8, 14, 7, 14, 6, 15, 7, 15, 8, 15, 9, 14, 9, 14, 10, 13, 10,
                12, 10, 11, 10, 13, 11, 14, 11, 15, 11, 15, 12, 16, 12, 17, 12, 18, 12, 19,
                12, 18, 11, 17, 11, 17, 10, 18, 10, 19, 10, 19, 9, 19, 8, 20, 8, 21, 8, 18,
                7, 19, 7, 20, 7, 21, 7, 21, 6, 22, 6, 23, 6, 21, 5, 20, 5, 19, 5, 19, 4, 18,
                4, 17, 4, 20, 3, 21, 3, 22, 3, 20, 2, 19, 2, 18, 2, 19, 1, 20, 1, 21, 1, 19,
                0, 18, 0, 10, 0, 4, 1);

            // Very basic form logic
            ClientSize = new System.Drawing.Size(GridWidth * 20, GridHeight * 20);
            DoubleBuffered = true;
            Paint += ExampleProgram_Paint;

            // Add a new point to the form (commented out)
            // MouseUp += ExampleProgram_MouseUp_AddPoint;

            // Draw the trail we find
            MouseUp += ExampleProgram_MouseUp_AddTrail;

            // Pick a starting point to start finding the trail from
            // TODO: Left as an excersize for the reader to decide how to pick
            // the starting point programatically
            m_trail.Add(new Point(0, 4));

        }

        IEnumerable<Point> Border(Point pt)
        {
            // Return all points that border a give point

            if (pt.X > 0)
            {
                if (pt.Y > 0)
                {
                    yield return new Point(pt.X - 1, pt.Y - 1);
                }
                yield return new Point(pt.X - 1, pt.Y);
                if (pt.Y < GridHeight - 1)
                {
                    yield return new Point(pt.X - 1, pt.Y + 1);
                }
            }
            if (pt.Y > 0)
            {
                yield return new Point(pt.X, pt.Y - 1);
            }
            if (pt.Y < GridHeight - 1)
            {
                yield return new Point(pt.X, pt.Y + 1);
            }

            if (pt.X < GridWidth - 1)
            {
                if (pt.Y > 0)
                {
                    yield return new Point(pt.X + 1, pt.Y - 1);
                }
                yield return new Point(pt.X + 1, pt.Y);
                if (pt.Y < GridHeight - 1)
                {
                    yield return new Point(pt.X + 1, pt.Y + 1);
                }
            }
        }

        void AddPoints(params int[] points)
        {
            // Helper to add a bunch of points to our list of points
            for (int i = 0; i < points.Length; i += 2)
            {
                m_points.Add(new Point(points[i], points[i + 1]));
            }
        }

        void ExampleProgram_MouseUp_AddTrail(object sender, MouseEventArgs e)
        {
            // Calculate the trail
            while (true)
            {
                // Find the best point for the next point
                int bestCount = 0;
                Point best = new Point();

                // At the current end point, test all the points around it
                foreach (var pt in Border(m_trail[m_trail.Count - 1]))
                {
                    // And for each point, see how many points this point borders
                    int count = 0;
                    if (m_points.Contains(pt) && !m_trail.Contains(pt))
                    {
                        foreach (var test in Border(pt))
                        {
                            if (m_points.Contains(test))
                            {
                                if (m_trail.Contains(test))
                                {
                                    // This is a point both in the original cloud, and the current
                                    // trail, so give it a negative weight
                                    count--;
                                }
                                else
                                {
                                    // We haven't visited this point, so give it a positive weight
                                    count++;
                                }
                            }
                        }
                    }

                    if (count > bestCount)
                    {
                        // This point looks better than anything we've found, so 
                        // it's the best one so far
                        bestCount = count;
                        best = pt;
                    }
                }

                if (bestCount <= 0)
                {
                    // We either didn't find anything, or what we did find was bad, so
                    // break out of the loop, we're done
                    break;
                }

                m_trail.Add(best);
            }

            Invalidate();
        }

        void ExampleProgram_MouseUp_AddPoint(object sender, MouseEventArgs e)
        {
            // Just add the point, and dump it out
            int x = (int)Math.Round((((double)e.X) - 10.0) / 20.0, 0);
            int y = (int)Math.Round((((double)e.Y) - 10.0) / 20.0, 0);
            m_points.Add(new Point(x, y));
            Debug.WriteLine("m_points.Add(new Point(" + x + ", " + y + "));");
            Invalidate();
        }

        void ExampleProgram_Paint(object sender, PaintEventArgs e)
        {
            // Simple drawing, just draw a grid, and the points
            e.Graphics.Clear(Color.White);

            for (int x = 0; x < GridWidth; x++)
            {
                e.Graphics.DrawLine(Pens.Black, x * 20 + 10, 0, x * 20 + 10, ClientSize.Height);
            }

            for (int y = 0; y < GridHeight; y++)
            {
                e.Graphics.DrawLine(Pens.Black, 0, y * 20 + 10, ClientSize.Width, y * 20 + 10);
            }

            foreach (var pt in m_points)
            {
                e.Graphics.FillEllipse(Brushes.Black, (pt.X * 20 + 10) - 5, (pt.Y * 20 + 10) - 5, 10, 10);
            }

            foreach (var pt in m_trail)
            {
                e.Graphics.FillEllipse(Brushes.Red, (pt.X * 20 + 10) - 6, (pt.Y * 20 + 10) - 6, 12, 12);
            }
        }
    }
}