views:

718

answers:

3

I'm trying to visualise a graph and allow people to play with it. I found the excellent Graph# library that can create an initial layout so that part is covered. Now I need to make a control that actually draws it and provides the necessary interactivity.

Graph# comes with a nice visualiser itself, however I don't like it because it is written in WPF (while my app is WinForms), and because I want to add some more interactivity options, which would require quite a remake of it anyway.

The graphs I'm drawing will routinely be pretty large, at about 100 vertices and the same amount of edges (the graphs will be trees 99% of time). That means that the resulting rendering can be up to 2000px by 2000px and even more. The users should be able to zoom in and out, scroll, highlight and drag vertices and edges, and get some popups with additional info when hovering the cursor above a vertex.

I'm worried that the standard System.Drawing might not be able to deliver a decent speed for this. I would like the dragging/zooming/scrolling operations to be smooth, and the popups should open with a little animation as well. Something like 20fps should be a necessity.

I know I can try to speed things up by pre-rendering a lot of the elements and keeping them as bitmaps in memory - but that would probably take up lots of RAM, and I'm still not sure if it would deliver the necessary performance.

What are your thoughts?

+1  A: 

I recommend leaving Graph# alone, and just hosting it in your Windows Forms application.

The performance you will receive will be much better than trying to reimplement it in System.Drawing.

Reed Copsey
But then I'd have to code in WPF to get it to act like I want it to - and I've got no WPF experience at all. It'll be easier for me to reimplement it myself without WPF.
Vilx-
If you're unwilling to learn WPF, then you're unwilling to learn any other way beyond system.drawing, as every other method out there has a learning curve involved.
Neil N
True, I suppose... I was just hoping that other ways might have a less steep a learning curve. :P
Vilx-
No - I'm saying just use the Graph# visualizer directly. It sounded like you were happy with it and its options. You can host this in your Windows Forms application, as is, with no implementation work.
Reed Copsey
Well, it does about 3/4 of what I want. I'd like it to have scrollbars and the dragging is pretty unusable when getting near the edges of the picture. Also it doesn't have the popups that I want when hovering.
Vilx-
I'd probably still do this via extending Graph#, since this is much easier to use for things like zooming in GDI.
Reed Copsey
Well... OK, I'll give it a try... Before I launch a full search myself, perhaps you can point me to some nice article which might get me up to speed in WPF quickly? I'm quite experienced in general .NET, so it doesn't have to be for beginners.
Vilx-
The Microsoft site is actually pretty good: http://msdn.microsoft.com/en-us/library/ms742119.aspx
Reed Copsey
+3  A: 

"Premature optimization is the root of all evil"

GDI+ can be great for your needs. Don't go and buy 3rd party libraries before you know you even need them.

I've done a thousand polygons on a 1000x800 pixel bitmap and redrawn it completely at over 100 frames per second, using just GDI+

That being said, if you have a lot of drawing to do, and your resolution is big.. Some of the 3rd party drawing libraries can go WAY beyond what managed GDI is capable of.

Neil N
Did you also redraw the polygons themselves every frame? And did you draw your bitmap stretched (for zoom)? ;)
Vilx-
Yes, I completely wiped the bitmap and redrew ALL polygons on each frame. Some optimizations were required, but I got it to work. Zoom is where it crapped out, never got zoom to work ok in GDI. Instead a I went with Aurigma Bitmap control.. which uses some unmanaged code for speed.
Neil N
Hmm, I've a class exposing an bitmap which uses an byte[] as base... no unmanaged stuff.
Dykam
Agree, not worth worrying about until you have an actual problem.I draw thousands of points, lines and polygons in GDI+ with no problems.
Oplopanax
A: 

GDI+ will be plenty fast enough for what you're doing, especially if (as it sounds from your description) everything you're drawing is rectangles and vertical/horizontal lines. Polygons and non-linear shapes are a bit slower, but not much (the speed difference is partially dependent on the SmoothingMode of your Graphics object). Drawing cached Bitmaps with resizing is also quite fast, although it can slow down significantly if you use a high-quality InterpolationMode setting.

As a benchmark, I wrote a .Net Compact Framework GPS application for Windows Mobile that rendered about 10,000 lines on the screen in realtime. This only achieved a frame rate of a few frames per second, but the processing power on a Smartphone is, of course, way less than a modern PC.

MusiGenesis