# Visualization of Quad/Octree data Structures

I have a simple C++ quadtree implementation. The implementation subdivides node into four children as if there is more than one point in that particular node. At the moment I want to visualize how subdivision happened for given input points.

I found a similar question that stated that we can use visualization software packages such as ParaView, meshlab but how to do it? I read we can simply write it out as an unstructured mesh in a VTK file but what it means?

You need to look up the VTK file format here: https://vtk.org/wp-content/uploads/2015/04/file-formats.pdf

It's not very difficult, you'd just write a single cell for each node of your quad tree. The results will look like the pictures you see here or here or here -- all use VTK file format to visualize meshes.

Consider the following visualization as an example. It visualizes two binary trees: $$T_S$$ and $$T_V$$ for the surface mesh of the sphere and volume mesh of the sphere, respectively.

At the 0th level, there is only one node in each tree: $$S_1^{(0)}$$ and $$V_1^{(0)}$$. The superscript in the brackets denotes the level in the tree and the subscript denotes the node number at this tree level. Blue sphere with the mesh on the left represents the entire surface mesh corresponding to $$S_1^{(0)}$$, while the blue sphere cut on the right—volume mesh corresponding to $$V_1^{(0)}$$.

At the 1st level, both surface and volume meshes are partitioned thus the parent node $$S_1^{(0)}$$ has two children $$S_1^{(1)}$$ and $$S_2^{(1)}$$, representing the mesh partitioning of the first level. They are shown on the sphere mesh visualization on the left with blue and red. And so on.

This visualization is not ideal for the intro example (has some non-ideal notation, has two meshes in the consideration, binary instead of quadtree/octree). But shows a way to visualize mesh partitioning. The mesh partitioning is constructed using Paraview (unfortunately, I cannot share the code for that as it is a part of a large project), but I will give you my take on how to do it.

The mesh is written once into the VTK; however, for each level in the tree, I am adding ScalarData corresponding to the node number of the partitioning at this tree level. With that, I am able to color it according to a certain level. In the visualization, the right-most view is active and Colouring menu on the left shows the Colouring by Level 2 selected.

Regarding how to code it: I did it manually in C++ (and awhile ago), using the old-style VTK file format. Currently, there are many tools that can help you including python interfaces.

Disclosure: the picture above is taken from

which I am a co-author.