none
WPF High Performance Graphics RRS feed

  • Question

  •  A general question on rendering high performance graphics in WPF.

    I have been looking for a good approach for developing high performance graphics in WPF.   I have looked at the VirtualizingStackPanel
    but according to the documentation it can render only a single vertical or horizontal line or sequence of UIElements.   Something like a "VitrualizingCanvas" would seem ideal.

    My question is what is the recommended approach for rendering large sets of data in WPF and what are some resource constraints?


     
    Wednesday, July 30, 2008 4:38 PM

Answers

  • If the graphics you render is staitc or require low framerate animation/updates only , you may try to go for Cached Composition newly availabe in of WPF4 /.net 4 ( UIElement.CacheMode =new BitmapCache() )

    Or if you have upgrade concern , you may fallback to use GDI+ WPF Interop (System.Drawing Namespace).  But the drawing infrastructure may have some difference. As WPF provide some advance drawing feature like Rounded corner  and it implement IntermediateMode Graphics (replaced  GDI+ repaint concept )  by dynamic geometory figure update.  


    Saxon
    • Proposed as answer by Sx Chan Saturday, February 27, 2010 5:00 PM
    • Marked as answer by James Antoine Thursday, October 21, 2010 12:38 AM
    Saturday, February 27, 2010 5:00 PM
  • Just found another really interesting article that talks about the maximum size of a fractal that can be created in a WPF application in practice (at least on the blogger's machine).  It uses InteropBitmap instead of WriteableBitmap (which you can switch in order to avoid using unsafe code).  He claims that his computer was able to plot out 100,000,000 points before having the memory crash on him.
    • Marked as answer by James Antoine Thursday, October 21, 2010 12:41 AM
    Wednesday, April 28, 2010 2:43 PM

All replies

  • Nothing about WPF is really "high performance". If you want to draw a lot of primitives, inherit FrameworkElement and override OnRender, using the DrawingContext to perform all your drawing.

    If you want actual high-performance bitmap access presented on a WPF surface, the forthcoming SP1 release includes support for this. I can't remember what they call it but any overview of the WPF SP1 features will discuss it.
    Controls for WPF and Windows Forms at http://www.divelements.co.uk
    Wednesday, July 30, 2008 5:52 PM
  • To make a good recommendation really requires more knowledge about your scenario.  What are you trying to accomplish?
    Wednesday, July 30, 2008 6:55 PM
  • Brendan -

    I am working on a simulator that executes an entity, relationship, attribute (ERA) model.  Models can be quite large and the simulation run can be quite long as well (model specific: depends on what kind of model the end user creates).

    During a simulation run, the simulator can create a very large number of events which I want to render on a surface that allows a user to scroll through these events, select the visual ( graphic element) and get details on the event.

    In as much as I consider the set of events unbounded or "large"  I thought that I would need some UI vitrualization technique.

    I considered using the VirtualizingStackPanel but am not sure it can provide the required behavior ( a two dimensional surface).

    I have read some issues on WPF rendering and see suggestions on using  StreamGoemerty but still not sure how well that will scale.

    I posed the issue as a general question because I want to get a general understanding of WPF rendering capabilities.  The application I am
    developing is using a third-party product (yfiles) for creating diagrams and we are about to move to their WPF implementation and we have scalibility concerns there also.

    Any general recommendations welcome.


    Thanks

    James





    Wednesday, July 30, 2008 7:30 PM
  • http://blogs.msdn.com/jgoldb/archive/2008/03/08/performant-virtualized-wpf-canvas.aspx

    I found this a while back when I was looking for a virtualized canvas. It might fit your needs as long as your elements are sparse.

    I was looking to build a GIS (geospatial information systems) viewer with WPF and it cant handle the large amount of vector objects I wanted to display (1000s of polygons, lines and points packed on the screen at once).
    Wednesday, July 30, 2008 7:38 PM
  • If the graphics you render is staitc or require low framerate animation/updates only , you may try to go for Cached Composition newly availabe in of WPF4 /.net 4 ( UIElement.CacheMode =new BitmapCache() )

    Or if you have upgrade concern , you may fallback to use GDI+ WPF Interop (System.Drawing Namespace).  But the drawing infrastructure may have some difference. As WPF provide some advance drawing feature like Rounded corner  and it implement IntermediateMode Graphics (replaced  GDI+ repaint concept )  by dynamic geometory figure update.  


    Saxon
    • Proposed as answer by Sx Chan Saturday, February 27, 2010 5:00 PM
    • Marked as answer by James Antoine Thursday, October 21, 2010 12:38 AM
    Saturday, February 27, 2010 5:00 PM
  • Rendering capabilities are best ascertained by trying code because they will be greatly affected by your local machine.  Have you tried just simply putting a fixed number of your events in a ListBox or something similar (using a Template to display the data in the manner that you desire) yet or are you just worried because you think that it might not work in some known practical application?  If you are looking to keep some huge record of very resource intensive elements (like bitmaps) in a ListBox or something similar then it would make more sense to keep a simple event id string or short description in the ListBox.  You could then bind the selected item of the ListBox to a Label or some other control that could display the full information.  This way you would be able to remove a lot of overhead from your main display.

    In summary, just try a few simple things first and see if they work.  If there is still a problem then describe what you tried and give a more quantitative description of your exact scenario.  I know that you are asking a general question because you are worried about performance, but what likely real world scenario is concerning you?  For most specific situations there is typically a simple workaround that makes things work.  In short the general question of performance doesn't usually make too much sense because it doesn't take into account all of the possible loop-holes and workarounds of a practical example.

    Tuesday, April 27, 2010 6:38 PM
  • I guess that I should add that I have had a lot of success using WPF to create xy plots of data sets.  This is something that would typically be viewed as resource intensive and is somewhat similar to drawing diagrams.  WPF uses retained graphics meaning that anything that is "drawn" is serialized and saved.  For something large and complicated like a plot or a diagram this makes it really simple to interchange pieces.  In traditional drawing you would have to invalidate a region and then reset pixels to swap out or swap in a small piece of a visual in order to update a drawing.  In WPF you just remove a visual in one step (assuming that you have appropriately dissected your diagram into visual children).  This will simply remove the serialized rendering data for the Visual.   In general I have found that with creating an xy plot the idea of treating pieces of the entire picture as visuals really makes life pretty simple.  It is certainly much more straightforward to understand and code with then either invalidating and redrawing a region or redrawing the entire plot.
    Tuesday, April 27, 2010 6:50 PM
  • I just found a really cool video interview with one of the project managers for WPF graphics.  I think that you might find it very helpful and that you will certainly find it to be very cool!
    Tuesday, April 27, 2010 11:16 PM
  • Just found another really interesting article that talks about the maximum size of a fractal that can be created in a WPF application in practice (at least on the blogger's machine).  It uses InteropBitmap instead of WriteableBitmap (which you can switch in order to avoid using unsafe code).  He claims that his computer was able to plot out 100,000,000 points before having the memory crash on him.
    • Marked as answer by James Antoine Thursday, October 21, 2010 12:41 AM
    Wednesday, April 28, 2010 2:43 PM