使用绘图视觉效果在 WPF 中显示 2D 原理图 [英] Displaying 2D Schematics in WPF with Drawing Visuals

查看:30
本文介绍了使用绘图视觉效果在 WPF 中显示 2D 原理图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 WPF 应用程序,它将显示城市规模的水管理系统的 2D 矢量图形.我从数百页阀门、泵、处理设施等的示意图以及将它们互连的管道中捕获了数据.结合个人住宅和商业物业的映射信息,数据集大约有 100,000 个节点实例以及互连管道信息.我有一个概念验证应用程序,它为每个管道段或节点(节点非常简单;矩形、圆形等)创建一个 DrawingVisual,创建一个 DrawingContext,为管道或节点的图形表示呈现线段.DrawingVisuals 被添加到画布中.每个视觉对象都是可点击测试的(我需要能够单击其中任何一个以获取更多详细信息).问题在于,随着视觉效果的数量超过数千,性能(平移、缩放)会下降(但在那之前真的很酷!).我试过摆弄抗锯齿 &位图缓存,但没有太大帮助.

I am creating a WPF application that will display 2D vector graphics of a city-scale water management system. I have captured data from hundreds pages of schematic drawings of valves, pumps, treatment facilities, etc and the piping that interconnects them. Combine this with mapping information of individual residences and commercial properties and the data set has about 100,000 node instances along with the interconnecting pipe information. I have a proof-of-concept application that creates a DrawingVisual for each pipe segment or node (nodes are pretty simple; a rectangle, circle, etc), creates a DrawingContext, rendering the line segments for the pipe or the node's graphic representation. The DrawingVisuals are added to a canvas. Each visual is hit-testable (I need to be able to click on any of them to get more detailed information). The problem is that as the number of visuals passes a several thousand, performance (pan, zoom) degrade (really cool until then, though!). I have tried fiddling with anti-aliasing & bitmap caching, but it's not much help.

这种事情在WPF中可行吗?有没有更好的方法?我来自 MFC 背景,6-8 个月前才开始使用 WPF,尽管我有相当多的 C# 经验.从这里的阅读帖子中,我看到经常提到 Direct3D,但它似乎真的不适合平面、2D、线条图,还是我错了?我见过的 XNF 教程只涉及精灵,这似乎不太合适?我已阅读与业务图相关的帖子;在这些情况下,对数据进行下采样似乎是合适的,但我不确定我能做到这一点,因为每个节点和互连管道是相关的.用户需要合理快速的缩放平移到原理图中的任何点.我在想 OpenGL 可能是一个值得探索的好东西,但我真的很喜欢 WPF 的所有功能(命中测试、出色的几何类等)

Is this kind of thing possible in WPF? Is there a better approach? I come from an MFC background and only started with WPF 6-8 months ago, though I have a fair amount of C# experience. From reading posts here, I see Direct3D is often mentioned, but it doent' really seem to fit the bill for flat, 2D, line-drawings, or am I wrong? The XNF tutorials I've seen only deal with sprites, and that hardly seems appropriate? I have read the posts related to business graphs; down-sampling data seems appropriate in those cases, but I am not sure I can do that, as every node & interconnecting pipe is relevant. Users require reasonably fast zooming & panning to any point in the schematic. I was thinking that OpenGL might be a good thing to explore, but I REALLY like all of the features of WPF (hit testing, great geometry classes, etc)

有什么建议吗?

谢谢!

推荐答案

如果你还没有,你应该看看 WPF 性能工具:http://msdn.microsoft.com/en-us/library/aa969767.aspx.您应该能够了解真正的瓶颈在哪里,每次重新渲染的内容等等.

If you haven't already, you should have a look at the WPF performance tools : http://msdn.microsoft.com/en-us/library/aa969767.aspx. You should be able to get some idea of where the real bottlenecks are, what's re-rendered every time and a lot more.

我不得不处理为某些 3D 模型缩放 WPF 的问题.虽然我不太确定 2D 等效术语,但建议可能仍然适用.

I've had to deal with this issue of scaling WPF for some 3D models. Though I'm not too sure about the 2D equivalent terms, the advice might still be applicable.

WPF 具有足够的优势,可以非常努力地针对您的用例优化它,而不是考虑一些替代架构.我认为对我来说,理解和解决性能问题比处理其他框架要少.

WPF has enough advantages to try pretty hard to optimise it for your use case, rather than considering some alternative architecture. I think for me it was less work to understand and work around the performance issues than dealing with some other framework.

最后对我来说最大的窍门是整合模型和视觉效果.我没有使用许多小模型,每个模型都可以进行命中测试,具有自己的颜色等,而是将它们聚合成代表许多组件的大模型.然后我处理大模型的命中测试以进一步细化选择并决定哪个小组件实际上应该被命中".从那里开始,我没有改变整个聚合模型的颜色,而是覆盖一个较小的模型来表示选择.我想你明白了...

In the end the big trick for me was to consolidate models and visuals. Instead of having lots of little models, each of which is hit-testable, with their own colour etc., I aggregate these into large models which represent many components. Then I handle the hit testing of the big models to further refine the selection and decide which little component should actually be 'hit'. From there, instead of changing the colour of the whole aggregate model, I overlay a smaller model to represent the selection. I think you get the idea...

因此,您需要确定绘图中的哪个抽象部分没有很好地缩放 - 可能是 DrawingVisuals 的数量,或者您使用的其他一些 UIElement,然后尝试合并这些.

So you need to figure out which abstract part in your drawing is not scaling well - maybe the number of DrawingVisuals, or maybe some other UIElement you use, then try to consolidate these.

这篇关于使用绘图视觉效果在 WPF 中显示 2D 原理图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆