Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.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# 如何处理WPF图形中的大量几何图形数据?_C#_Wpf_Vector Graphics - Fatal编程技术网

C# 如何处理WPF图形中的大量几何图形数据?

C# 如何处理WPF图形中的大量几何图形数据?,c#,wpf,vector-graphics,C#,Wpf,Vector Graphics,在我正在试验的WPF UI中,我正在将一些项目绘制到DrawingGroup,代码看起来有点像这样: foreach( var path in allRoads ) { var wpfPen = new Pen(brush, penSize); GeometryDrawing geometry = new GeometryDrawing(); geometry.Pen = wpfPen; geometry.Geometry = GetPathGeometry(p

在我正在试验的WPF UI中,我正在将一些项目绘制到
DrawingGroup
,代码看起来有点像这样:

foreach( var path in allRoads ) 
{
    var wpfPen = new Pen(brush, penSize);
    GeometryDrawing geometry = new GeometryDrawing();
    geometry.Pen = wpfPen;
    geometry.Geometry = GetPathGeometry(path);
    drawingGroup.Children.Add(geometry);
}
当我绘制正在渲染的各种几何体项目时(我将它们添加到
DrawingGroup
中,然后要求
DrawingContext
随后绘制),会重复调用此函数,但它遇到问题并崩溃,出现以下消息:

线程0x3228已退出,代码为0(0x0)。引发异常: PresentationCore.dll中的“System.OverflowException”未经处理 中发生“System.OverflowException”类型的异常 PresentationCore.dll图像数据在运行期间产生溢出 处理

崩溃似乎发生在第38000个几何体项(都是多点路径,有些可能相当长,因为这是GIS数据)添加到
DrawingGroup.Children
集合之前

我猜这可能会使系统超越它的设计目标——在WPF中有更好的方法来处理这个问题吗?它能处理大量的几何数据吗?如果不能,行踪就是极限?

在尝试渲染点之前,可以使用该算法简化点的收集。这将保持相同的基本形状,但会大大减少细节(在您谈论的缩放级别上甚至看不到的细节)

来自维基百科的伪代码:

function DouglasPeucker(PointList[], epsilon)
    // Find the point with the maximum distance
    dmax = 0
    index = 0
    end = length(PointList)
    for i = 2 to ( end - 1) {
        d = perpendicularDistance(PointList[i], Line(PointList[1], PointList[end])) 
        if ( d > dmax ) {
            index = i
            dmax = d
        }
    }
    // If max distance is greater than epsilon, recursively simplify
    if ( dmax > epsilon ) {
        // Recursive call
        recResults1[] = DouglasPeucker(PointList[1...index], epsilon)
        recResults2[] = DouglasPeucker(PointList[index...end], epsilon)

        // Build the result list
        ResultList[] = {recResults1[1...length(recResults1)-1], recResults2[1...length(recResults2)]}
    } else {
        ResultList[] = {PointList[1], PointList[end]}
    }
    // Return the result
    return ResultList[]
end
这里是一个链接到一个


您可以根据缩放级别动态调整
ε
值,以便无论缩放的距离有多近或有多远,都能保持外观正确。

仅绘制实际可见的几何图形?@Clemens的路径正确。我猜你在画某种图形,所以采用滑动窗口的方法,这样你只画屏幕上的图形部分。@Clemens我在画一张地图(GIS数据),它被放大了相当长的一段距离,所以我在这里看到的矢量数据是每一条超过100平方英里人口密集区的道路。如果地图缩小(有时需要缩小),所有这些点都在视图中。当然,它们中的一些是无法区分的,所以可能需要进行碰撞测试。这是一个错误的问题。您的应用程序应该只绘制尽可能少的数据(当然,这足以创建合理的输出)。请注意,还有一些有用的算法可以减少多段线中的点数,例如Douglas-Ramer-Peucker。您应该实现一种处理多细节层次(LOD)的方法。缩小时不需要详细信息,因此可以将数据“合并”到更简单的形状中。你缩小的越多,你看到的细节就越少。附录:如果有人想这样做,并且碰巧使用了PostGIS(似乎是其他几何数据存储),那么数据存储中有一些方便的功能来管理简化几何,这节省了一点实现。