views:

261

answers:

4

I need to display a graph with thousands of nodes so that the user can scroll and zoom to view it. The nodes need to behave like dimensionless points, and the edges, like one-dimensional lines. That is, zooming in, the circles representing the nodes move farther apart but each one stays the same size, and the lines connecting them get longer but not thicker. Zooming should be "continuous" and "infinite", if possible.

What APIs and algorithms are used to solve this problem? (as in, say, CAD or GIS applications)

I couldn't get anywhere near acceptable performance using GDI+. My implementation was probably naive, but, still, I'm guessing I need OpenGL or DirectX.

+1  A: 

You need to separate the drawing of the lines and visible points from the scaling of the positions that represent the points. That way when the scene is zoomed you actually just scale your positions and then render then using the same line and visible point method regardless of zoom level.

Last time I looked, Direct3D is not going to offer you anything out of the box to do this. You would need to implement the line and point primitives yourself. More importantly you will need a strong understanding of vectors and matrices to perform the required transformations in Direct3D. Haven't used OpenGL much.

GDI+ can be slow but you can actually get decent performance by being very careful about displaying only those points that are currently visible. If I was in your position I would definitely spend more time on improving the performance of your rendering algorithm and sticking with GDI+ a bit longer.

Also, rendering your scene completely to an in-memory Bitmap (sized the same as your visible window) and then simply rendering this bitmap in one go, will give better performance than rendering every point and line individually onto the visible window.

Ash
Thanks for your reply. I will look into drawing only the points that are visible on the screen, but what about when the user zooms out? I guess I could replace close neighbours with a single point to reduce the number of points. Is there an established algorithm to do that? But still, a thousand points could easily be visible at once as an intelligible plot. Won't there be a noticeable delay to render even that many ellipses with GDI?
rgf
A level of detail algorithm is used to reduce the complexity of your scene when it is zoomed out. In your case it might be as simple as rendering each point as a single pixel instead of an ellipse when zoomed out. 1000 points can definitely be rendered quickly using GDI+. If you only render when the scene changes (eg user zooms in/out) this is even less of an issue. Most GDI+ applications are rendered on demand (ie in the Paint event) rather than in a constant loop as with Direct3D. If you need constant rendering maybe WPF could also be an option.
Ash
A: 

Hey,

I recently released a Java library for speeding up plotting in 3d (http://code.google.com/p/jzy3d/).

There is an example with a 3d scatter plot, in which the 3d points are dimensionless. Adding all the lines linking your network nodes should be a piece of cake.

There are available tools to scale/zoom the 3d scene with mouse, so maybe you'll have almost nothing to do.

Regards, Martin

Martin
+1  A: 

I believe that ROOT provides all the requested functionality, though it is a big package and a lot to learn...

dmckee
+1  A: 

ZedGraph will do most of what you described (displaying lines and points at fixed sizes, zooming, etc). I recommend you check out the codeproject tutorial to see if it's functionality suits your needs. I have found it easy to implement, highly flexible, and the .dll is about 300k.

Hope this helps, Andrew

bi0m3trics