Tutorial: How to convert medical models to JSON in 3 steps
|
By kabhari . July 6, 2012 . tutorials. |
3D models are required to be in JSON
format in order to be parsed by Voxelent. However, medical surfaces are often in VTK
format (or can be easily converted to VTK
format using free cross-platform applications such as ITK SNAP). Therefore, to visualize medical surfaces, the very first step is to convert your VTK
model to a JSON
file by taking the following steps:
If you don’t have Python
installed, please do so by downloading it from here.
After downloading the voxelent’s source code from GitHub, you can find the VTK importer under: Voxelent/tools/importers/vtk2json.py
Depending of the platform (Windows, Mac, or Linux) that you are using, the invocation of the vtk2json.py
script might be different.
For instance, in Windows, if the python executable has been added to your PATH variable, and the VTK importer and VTK model are in the same folder then you can write something like this:
python vtk2json.py yourVTKModel.vtk yourJSONModel
If the Python executable has not been added to the PATH variable, or the VTK importer or the VTK model do not reside on the same folder, then you would write something like this:
../path/to/python.exe ../path/to/vtk2json.py ../path/to/yourVTKModel.vtk ../path/to/yourJSONModel
yourJSONModel
) doesn’t include an extension .json
at the end.If you are using Mac or Linux, the python executable most likely is included on the system path variable and it can be invoked from any location. If you have the vtk importer script and your VTK model in the same folder, you can write something like this:
python vtk2json.py yourVTKModel.vtk yourJSONModel
When executing the script you will see a screen similar to the following:
In these examples, yourVTKModel.vtk is the original VTK file that you want to display on the web. This VTK file needs to be:
There are some cases where the model that we want to render has a very large number of indices. This is particularly common if we are handling patient models.
Due to the fact that WebGL only support 65K index elements per draw call, we need to partition the model in pieces that are ‘renderable’, this is, into pieces whose number of indices is 65K tops. Otherwise, we would not see anything being rendered.
Voxelent’s vtk2json.py
handles this scenario and produces as many parts as required.
This is the case of the brain demo, where we are taking a very large mesh and we are subdividing it into renderable parts.
This process involves a bit of reindexing since every part need to have indices that start at zero.
That’s about it! Now you’re ready to view your VTK model on the World Wide Web 🙂