简体   繁体   中英

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. 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.

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)

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 . 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. Though I'm not too sure about the 2D equivalent terms, the advice might still be applicable.

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...

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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