You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DevDept Eyeshot WinForm百万级点云鼠标动态选点性能优化咨询

百万级点云鼠标选点高效实现方案(基于DevDept Eyeshot)

核心优化思路:避免全量遍历,利用内置空间索引+事件节流

1. 优先使用Eyeshot内置的空间索引查询

Eyeshot的PointCloud类默认内置Octree空间索引,无需自己实现全量遍历。直接调用GetPointsInSphere这类方法,内部会通过空间索引快速定位目标点,效率比全遍历高几个数量级。

示例代码:

private void design1_MouseMove(object sender, MouseEventArgs e)
{
    // 这里以鼠标悬停选点为例,可根据需求调整触发条件
    if (e.Button == MouseButtons.None)
    {
        // 将屏幕坐标转换为3D拾取球区域(5为屏幕像素对应的拾取半径)
        var pickSphere = design1.ScreenToSphere(e.Location, 5);
        var pointCloud = design1.Entities.OfType<PointCloud>().FirstOrDefault();
        
        if (pointCloud != null)
        {
            // 确保空间索引已构建(默认开启,若手动关闭过需调用此方法)
            if (!pointCloud.OctreeBuilt) pointCloud.BuildOctree();
            
            // 通过空间索引快速获取拾取球内的点索引
            var selectedIndices = pointCloud.GetPointsInSphere(pickSphere.Center, pickSphere.Radius);
            pointCloud.SelectedIndices = selectedIndices;
            design1.Invalidate();
        }
    }
}

2. 给MouseMove事件加防抖节流

鼠标移动时事件触发频率极高,连续触发计算会导致UI卡顿。可以用定时器做防抖处理,仅在鼠标停止移动一段时间后执行选点逻辑。

示例代码:

private Timer _debounceTimer;
private Point _currentMousePos;

public YourForm()
{
    InitializeComponent();
    _debounceTimer = new Timer { Interval = 50, Enabled = false };
    _debounceTimer.Tick += DebounceTimer_Tick;
}

private void design1_MouseMove(object sender, MouseEventArgs e)
{
    _debounceTimer.Stop();
    _debounceTimer.Start();
    _currentMousePos = e.Location;
}

private void DebounceTimer_Tick(object sender, EventArgs e)
{
    _debounceTimer.Stop();
    // 执行选点逻辑
    PerformPointSelection(_currentMousePos);
}

3. 异步执行选点计算,避免阻塞UI

把空间索引查询放到后台线程执行,主线程只负责更新UI,彻底解决界面卡顿问题。

示例代码:

private async void PerformPointSelection(Point screenPos)
{
    var pointCloud = design1.Entities.OfType<PointCloud>().FirstOrDefault();
    if (pointCloud == null) return;

    var pickSphere = design1.ScreenToSphere(screenPos, 5);
    List<int> selectedIndices = null;

    // 后台线程执行查询
    await Task.Run(() =>
    {
        selectedIndices = pointCloud.GetPointsInSphere(pickSphere.Center, pickSphere.Radius).ToList();
    });

    // 主线程更新选中状态
    if (design1.InvokeRequired)
    {
        design1.Invoke(new Action(() =>
        {
            pointCloud.SelectedIndices = selectedIndices;
            design1.Invalidate();
        }));
    }
    else
    {
        pointCloud.SelectedIndices = selectedIndices;
        design1.Invalidate();
    }
}

4. 辅助优化细节

  • 缩小拾取半径:屏幕上设置5-10像素的拾取范围足够,避免查询过多无关点;
  • 结合LOD筛选:如果开启了点云的细节层次(LOD),可以通过VisiblePoints属性先筛选当前视角可见的点,再做选区判断;

内容的提问来源于stack exchange,提问作者filtrow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 12:50:03