简体   繁体   English

使用绘图视觉效果在WPF中显示2D示意图

[英]Displaying 2D Schematics in WPF with Drawing Visuals

I am creating a WPF application that will display 2D vector graphics of a city-scale water management system. 我正在创建一个WPF应用程序,它将显示城市规模的水管理系统的2D矢量图形。 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. 将其与个人住宅和商业物业的地图信息结合起来,数据集具有约100,000个节点实例以及互连的管道信息。 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. 我有一个概念验证应用程序,它为每个管道段或节点(节点非常简单;矩形,圆形等)创建一个DrawingVisual,创建一个DrawingContext,为管道或节点的图形表示渲染线段。 The DrawingVisuals are added to a canvas. DrawingVisuals已添加到画布。 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. 我尝试摆弄抗锯齿和位图缓存,但这并没有太大帮助。

Is this kind of thing possible in WPF? 在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. 我来自MFC,虽然6个月前有很多C#经验,但我只是从6-8月份开始使用WPF。 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? 从这里的阅读文章中,我可以看到经常提到Direct3D,但是它确实确实适合平面,2D,线描的设计,还是我错了? The XNF tutorials I've seen only deal with sprites, and that hardly seems appropriate? 我见过的XNF教​​程只涉及精灵,这似乎很难吗? 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) 我本以为OpenGL可能是一件好事,但我真的很喜欢WPF的所有功能(命中测试,出色的几何类等)

Any suggestions? 有什么建议么?

Thanks! 谢谢!

If you haven't already, you should have a look at the WPF performance tools : http://msdn.microsoft.com/en-us/library/aa969767.aspx . 如果还没有,请看看WPF性能工具: http : //msdn.microsoft.com/zh-cn/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. 您应该能够了解真正的瓶颈在哪里,每次重新渲染的内容等等。

I've had to deal with this issue of scaling WPF for some 3D models. 我不得不处理一些3D模型的WPF缩放问题。 Though I'm not too sure about the 2D equivalent terms, the advice might still be applicable. 尽管我不太了解2D等效术语,但该建议可能仍然适用。

WPF has enough advantages to try pretty hard to optimise it for your use case, rather than considering some alternative architecture. WPF具有足够的优势,可以针对您的用例进行优化,而无需考虑某些替代体系结构。 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... 我想你应该已经明白了...

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. 因此,您需要确定绘图中的哪个抽象部分无法很好地缩放-可能是DrawingVisuals的数量,或者您使用的其他UIElement,然后尝试将其合并。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM