netstim / leaddbs

Lead-DBS is a MATLAB toolbox facilitating deep brain stimulation electrode localization and connectomic neuroimaging.
https://www.lead-dbs.org
Other
93 stars 97 forks source link

Enhancement: use a different mesh format #113

Closed neurolabusc closed 6 years ago

neurolabusc commented 7 years ago

The current distribution comes with meshes in STL format, includes scripts to save meshes as STL format, and includes scripts to display STL format meshes. I would suggest using ANY format other than STL. Since STL does not reuse vertices, the file sizes are very large. Further, when loading these images the display software must either

  1. Show each triangle as independent from others. This leads to a faceted appearance as the surface normal is the same for the entire triangle. This also uses a lot GPU resources as there is no vertex sharing.
  2. Have the great computational burden of welding shared vertices together (with some tolerance for rounding errors). This will look as nice as other formats, as you can interpolate vertex normals from all the shared triangles and use interpolated pixel shading.

For example, since Surfice follows the latter approach the current ea_surficeoverlay_lr script is much slower than if a different format was used. If Surfice is your main target, I would suggest its MZ3 format - this will be much faster and the files will require 20% the disk space of STL. You can find reading and writing code here https://github.com/bonilhamusclab/MRIcroS/tree/development/%2BfileUtils/%2Bmz3 The only concern is that this format is not popular. However, the Matlab scripts make it easy to load and save as different formats.

More common alternatives that can also store vertex colors are PLY https://github.com/bonilhamusclab/MRIcroS/blob/development/%2BfileUtils/%2Bply/writePly.m or GIfTI https://www.artefact.tk/software/matlab/gifti/ of the very popular OBJ https://en.wikipedia.org/wiki/Wavefront_.obj_file Note that it is really easy to convert any format to STL. The challenge is welding together vertices when reading STL. I think by moving to a different format you could accelerate loads of files, accelerate download speeds, and you can always include the tiny script to save any other format to STL.

andreashorn commented 7 years ago

Hi Chris,

thank you for the input, that's really appreciated! We do use .PLY a lot already, indeed when visualizing DBS electrodes with surfice instead of our builtin viewer, .PLY is used which I found easier to also display color (ea_elvis_surfice function). Also, one can export all DBS scenes as .PLY

To be honest, the ea_surficeoverlay_lr function is pretty hidden in Lead-DBS and I built it in to automatize some standard nifti figures not really related to DBS at all (so a Menu item built mostly for myself). But it's great to know that .STL is not a good format and we'll refrain from using it in the future.

neurolabusc commented 7 years ago

Sounds like a good idea. In my testing binary PLY outperforms OBJ (as well as STL) https://www.nitrc.org/plugins/mwiki/index.php/Image:Surfice:Surf_Ice_Formats.png For completeness, Matlab users who do want to load STL files can eliminate the facet artifacts using a couple lines of code, so it is easy to implement so for informed Matlab users STL files just take a lot of disk space and are a bit slow to load: http://www.mathworks.com/matlabcentral/fileexchange/29986-patch-slim--patchslim-m-