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.