visualizing data structures with svg

so i found dropping SVG to disk is an easy and fun way to visualize or debug data structures. here’s all it takes in C:

FILE * fp = fopen("kdtree.svg", "w");
fprintf(fp, "<svg version=\"1.1\" width=\"1024\" height=\"1024\" xmlns=\"http://www.w3.org/2000/svg\">\n");
fprintf(fp, "<line stroke=\"#%06x\" stroke-width=\".1\" x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\"/>\n", ...);
fprintf(fp, "</svg>");

what’s nice is then you can load the file up in firefox or inkscape and zoom in. also you can easily draw in other data like triangles and circles or put nodes you’re interested in in different colors and what not.

here’s a 3d kd-tree seen from above subdividing space evenly
kdtree with even splits

here’s a 3d kd-tree seen from above using surface area heuristic
kdtree using surface area heuristic

3 Comments

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>