Drawing 30fps chart in Windows Forms - wpf

I'd like to draw a high-framerate (30fps+) graph/chart in a Windows Forms app.
How?
Windows Forms gets TERRIBLE frame rates drawing a clear-background drawing over a window.
(I come from the land of GNU, so I apologize if this is obvious.)

If you're using Windows Forms (as said in your question):
If you need to get >30FPS, you'll probably need to change to a different technology. GDI+ drawing is not too efficient.
DirectX would work well for this. You can do the charting in Direct3D using DirectX embedded in a Window. SlimDX is a good way to do this from C#.
That being said, you tagged this with WPF - if you're using WPF, everything is retained mode graphics, so there should be no "clear-background drawing" required. You would just put in the chart elements as needed. In that case, 30FPS should be doable.

Running full tilt I get about 180FPS using a System::Windows::Forms::DataVisualization::Charting::Chart plotting 128bins of an FFT using a 'FastLine' style for the series of data. That's running on an Intel Core 2 Duo (2.53Ghz) IBM Thinkpad.

Related

Confused about XNA (is it just a Direct3D wrapper?)

I have an industrial C#/WPF application written that needs to render thousands of 3D lines. (N.B. these are not a wireframe - they do not necessarily represent a 3D surface, so I don't want to tesselate polygons into triangles, or do lighting a shading, but I do want hardware acceleration) I've been looking at OpenGL and Direct3D but I keep seeing XNA suggested on Stack Overflow, e.g., here and here
I went to https://en.wikipedia.org/wiki/Microsoft_XNA to try to understand it but I'm still confused. Is it just a wrapper for something I should be using directly, like Direct3D? Does it give me access to the underlying graphics API? Can it even do lines? Can I run it in a WPF object like a Panel or Canvas?
Is it just a wrapper for something I should be using directly, like Direct 3D
XNA is not a 1:1 of DirectX.
Though XNA uses DirectX under the hood it's generally not correct to think of it as "just a wrapper" for DirectX. XNA does a few things that DirectX doesn't, like content pipelines; a clearly-defined separate game loop and draw point; content load and unload callbacks; and 2D sprites. (Microsoft ditched 2D drawing DirectDraw for a time and only now have released Direct2D)
XNA consists of a series of layers starting with Platform being the lowest and includes APIs such as Direct3D 9; XACT; and XInput.
Building upon Platform you'll find Core Framework; Extended Framework; and Games which abstract; encapsulate the lower layers whilst adding new features that result in "making game development easier". [1]
The end result is so far removed from DirectX (except perhaps for the shaders) you would not be aware you are using DirectX. You can have a game window up and running in a few lines of code compared to DirectX's pages and pages of code.
Does it give me access to the underlying graphics API?
If you mean can you talk directly to DirectX COM API then no, you can't. You can however write shaders that when compiled, the GPU will understand indirectly.
Can it even do lines?
Yes.
Can I run it in a WPF object like a Panel or Canvas?
Apparently so. I should point out that WPF already is hardware accelerated and uses DirectX for rendering. Even those drop shadow effects you see in WPF are actually DirectX GPU shaders.
Today
As you have probably read, XNA is deprecated and though Monogame is active is not 100% compatible with XNA (just look for the many posts on SO regarding XNA Content Pipeline issues for one).
Therefore if you are wishing to do 3D in WPF, well you don't need XNA for that.
More
[1] Cookiecups, "what is the xna framework", MSDN Blogs

Is silverlight better or wpf for graphics, 3d?

I learning wpf/silverlight currently. I want to ask which one of them is better for graphics, 3d, ... ?
People say "Silverlight is a subset of WPF" -- what they mean is that the programming model is the same (code + XAML), but Silverlight generally has a smaller API / less features than WPF.
I think a good example would be creating a reflection. In WPF you could use a VisualBrush, but Silverlight doesn't support it. Still you can create the same effect by creating a 2nd transformed element. You can pretty much acomplish the same task in both, although for Silverlight you may have to do some processing tasks on the server.
The choice of platform depends more on whether you want to target web deployment or not and possibly performance.
3D isn't implemented in Silverlight 4 (though there are 3D libraries out there). 3D will be part of Silverlight 5. (Beta coming soon, probably at MIX, and to be released this year.)
i would sugest wpf in WPF you have all the Viewport sutff where you can do real 3d, In Silverlight you have PlaneTransformation but it is not close to real 3d
WPF 3d tutorial
The deal is more deeper as I understand.
We will speak about WPF and Silverlight 5. There are two mechanisms of 3D Graphics. Before WPF it was a single one - so named pipeline graphics. It includes DirectX, OpenGL and multiple derivative and independent realizations (XNA from DirectX, for example). Although WPF is based internally on DirectX it realizes absolutely different conception of smart graphics. What is the difference for a pipeline and smart mechanism? The pipeline mechanism consists of infinity loop of drawing objects - typically primitives like vertex, triangles. It works by initialization of so named infinity loop by calling something like OnDraw/ReDraw method.
WPF does not use ReDraw and does not draw anything until we directly detect it. It is single correct way to use it. Therefore WPF allows to draw UI Elements with internal support of hundreds events, methods and full freedom of management (like usual WPF control - textbox, for example). (Helix 3D is good library for easy way to WPF 3D) And vice versa, Silverlight 5 has some API of XNA graphics - pipeline way without UIElement support for 3D objects.
There is Kit3D library http://kit3d.codeplex.com/ as very good idea for smart graphic realization for Silverlight and there are many other realizations (Balder, Babylon) on pipeline mechanism. If you are interesting to code an application like web 3D Game - choose pipeline Silverlight 3D graphics, if you are interesting about smart 3D applications - choose WPF 3D.
Author of WPF 3D CAE system TIMO Structural.

Why do I see pixels when zooming WPF application in Windows?

I have developed a GUI for a random application using WPF. I have a bunch of out of box WPF controls laid on the application window. I haven't customized anything, didn't use bitmaps, etc.
When running my application and zooming using Magnifier application in Windows 7 (Win key + Plus key, the magnified GUI is showing pixels.I am probably wrong, because I can't explain it otherwise, but isn't WPF supposed to provide vector like control rendering?
Thanks for participating in the discussion.
Bonus Reading
Tim Sneath: Magnifier: An Interesting Discovery (archive)
WPF Vector based interface *(screenshot of WPF being vector scaled by Magnifier)
MSDN Blogs: Greg Schechter explains why it longer happens (archive)
Back when Vista first shipped, and when WPF was on version 3.0, zooming with the built-in magnifier would actually do vector-based scaling.
This stopped working when WPF 3.5 service pack 1 shipped. (It worked in 3.5 before sp1.) The reason it worked before then is that the DWM (Desktop Window Manager) - the part of Windows responsible for presenting everything you see on screen - uses MILCORE.DLL to do its rendering. Version 3.0 and 3.5 of WPF also used this same component to render - this meant that all WPF content was native content, so to speak. (In fact, on Windows XP, which doesn't have the DWM, MILCORE.DLL is something that WPF puts on your system for its own benefit. But it's built into Vista and Windows 7.) When WPF was using MILCORE.DLL to render on Vista, any effects applied by the DWM such as scaling would also apply in the way you want to WPF - it really did scale without pixelating.
Unfortunately, this is no longer the case. And the reason is that WPF started adding new rendering features. In 3.5 sp1, the new feature in question was support for custom pixel shaders. To enable that, Microsoft had to release an update to the MIL. (The Media Integration Layer - the bit that does the actual rendering.) However, they weren't really in a position to update MILCORE.DLL, because that's part of Windows - it's how everything you see on screen gets to be on screen. Releasing a new version of MILCORE.DLL effectively means pushing out an update to Windows. The release schedule for Windows is independent of that for .NET, and so the only way the WPF team could reasonably add new features was to ship a new MIL. (In theory they could have done it via Windows Update, but since WPF is now owned by a different division of Microsoft than Windows, that sort of thing doesn't seem to happen in practice.)
As of .NET 3.5 sp1, the MIL is in a different DLL called wpf_gfx_vXXXX.dll where vXXXX is the version number. In .NET 4.0, it's wpf_gfx_v0400.dll.
The upside is that WPF gets to add new rendering features with each new version, without needing Windows itself to be updated. The downside is that WPF's rendering is no longer as tightly integrated with Windows as it was briefly back when Vista shipped. And the upshot is, as you've seen, that magnifying is not as much fun as it used to be.
The magnifier application implements its own zoomed image rendering, so that's why you are seeing pixels. WPF does use vector graphics, but in this situation it's not the WPF application itself that is rendering the zoomed image.
If you use something like Snoop you can see zoomed and scaled WPF vector graphics rendering in action.
I suppose, Windows 7 magnifier takes a snapshot of actual application on-screen UI, and then magnifies it itself (not making a special case for WPF applications). Of course what it can access is just the pixels, not the vector graphics which works behind the scene.
The Windows-7-Magnifier is pixel based, but there is a difference in magnifier mode depending on wether an Aero-theme is active or not.
with Areo theme the zoom is pixelated.
without Areo theme the zoom is smoothed (blurry).
Only with Areo theme other Views (except "Docked") are selectable.

WPF capabilities

In my company we have in mind a redesign of the user interface of an application and we would like to make it ... let say "fancy". We have in mind a simple story board but I doubt between WPF, XNA or DirectX. I prefer WPF so I'd need to know if it support the following capabilities and how difficult to implement are they:
Transparency: We'd like to display information layers on top of the main display.
3D support: We want network nodes (part of the interface is a network graphic) to be simple spheres connected with lines in a 3D enviroment, and the ability to control the camera so rotation of the screen is possible.
Effects: Such as shading, lens flare or glow to "signal" the discovery or deletion of a node.
Text animations: Specifically the ability to display the text as if it's being written... You know, the information text will be "filling" the panel top down, left to right...
Good news. WPF is the technology you want and it can handle your requirements with relative ease.
Transparency is simple.
3D support is good as well. For an example, check out Tim Sneath: Five Great WPF 3D Nuggets. You even get hardware acceleration.
Effects are definitely do-able via timeline animations.
The previous statement goes double for Text Animations.
...the hardest part would be the 3D support, but it's still going to be a lot easier than getting things done in XNA or using DirectX libraries directly.
AFAIK WPF 3.5 supports all of this, and even leverages hardware acceleration to get a decent performance.
It's possible to embed an XNA application in a WPF form so you could use XNA for the representation of your network and WPF controls for the GUI in front of it.

D3DImage using DX10

Is it possible to use DirectX 10 (I am using SlimDX) with WPF's D3DImage? The only examples and docs I can find only show using DX9 surfaces.
Yes, you can use DirectX 10, 11, and DirectWrite using the D3DImage in WPF by creating your render target surface as shared, and then creating a DX9 texture based on that shared texture handle to use in WPF.
This means that essentially you can use 10, 11, and DirectWrite the same way you use DX9 with no additional overhead, and no airspace issues.
A sample WPF project with DX9, DX10, DX11, and DirectWrite integration can be found referenced in this blog post here:
http://blogs.windowsclient.net/rob_relyea/archive/2010/04/30/gizmodo-posts-wpf-direct2d-sample-wow.aspx
The Microsoft Code Pack contains a thin managed wrapper for Windows 7 components including DX9, DX10, DX11 and DirectWrite in addition to various other unmanaged libraries in Windows 7.
The SurfaceQueueInteropHelper is a WPF control that manages automatically creating DX9, 10, and 11 contexts in WPF and managing D3DImage updating and various other aspects of the rendering system including device lost events.
Not out of the box as far as I know. WPF is based on DirectX, but as WPF is also supported on Windows XP it's based on DirectX 9.
I do know that it's possible to use DirectX 10 with WPF, but then your application won't be able to run on XP.
There's a library for WPF called Bling which supports DirectX 10 (on Vista and Windows 7) which might be of interest to you. You can find it here. I don't know how mature it is though.
Also, I ran into this blog (mostly in french) who speaks about using DirectX 10 with WPF.
Lastly there's a good introduction to using D3DImage with DirectX over at CodeProject
I know this doesn't exactly answer your question, but I thought I'd share it with you anyways. Best of luck.
If you're willing to use SlimDX for the DirectX calls, you can try SlimDXControl (slimdxcontrol.codeplex.com) -- it is a WPF content control I wrote which explicitly only supports D3D10 instead of '9.
-mpg

Resources