Does the library support the VTK file format? #1721

Closed
schmitzke opened this Issue Apr 13, 2012 · 27 comments

Projects

None yet

7 participants

@schmitzke

hi,

i'm working at a medical institute and i need to get .vtk-files to be shown in the canvas. i got it working with www.goxtk.com but i want to use three.js. does anybody know about the issue, that it is not a supported file format?

so my actual issue:
convert .vtk to .obj, .json, etc. to get it working with three.js (and i can't find it in xtk-library).

regards

@chandlerprall

Three.js doesn't support the VTK format. Looks like it would be easy to write an importer for (or just copy X's implementation) but it's not a real common 3D format so it may not be real useful to have.

According to its source documentation, The VTK program should be able to export directly to an OBJ file.

@alteredq

VTK is very popular in research community, it may be worth to have some pipeline for dealing with stuff it produces.

@valette

I have coded a basic vtk parser for triangle meshes, but it is not very interesting as vtk files are not compressed and require a high bandwidth. I ended up converting .vtk files to the openCTM format, which is much more compact.

If you really need it, I can share the code.

@schmitzke

that would be awesome! thank you.

@valette

OK, I've just created a branch here:
https://github.com/valette/three.js/tree/VTKLoader

there are three new files : VTKLoader.js, webgl_loader_vtk.html and the bunny.vtk example model.

@mrdoob
Owner

@valette I just tried to merge that in the dev branch and doesn't seem to load :S (even by updating the code to the latest. The xhr.responseText is empty... ?

@valette

strange... I pulled on a clean repo, and it works fine. I've just added a second example with a lower resolution bunny.

@schmitzke could you test this branch to see if it works from your side?

@mrdoob
Owner

You probably used clean repo but the master branch instead of dev branch.
What browser/os are you using?

@valette

ah ok, I should stop writing patches against master, but use dev branch instead. Will fix issues and come back...

@valette

OK, just had to replace THREE.Vertex with THREE.Vector3. Seems to work now.

@mrdoob is my branch working on your side? I merged it with the dev branch

FTR I'm using chrome with linux.

@mrdoob
Owner

Weird. I just get this: Could not read file models/bunny.vtk: error0.

@schmitzke

this could become a really good mix of three.js and xtk. hope, it will work, i will try to get it working for the rest of the week. thanks for your help!

@schmitzke

alright i got the same issue as mrdoob. but the dataformat of the vtk is exactly the one i'm using.
the three.js examples all use blender exported files with ints instead of doubles but valettes version stops loading before the data can be passed.

@valette

really weird... My test repo is here:
http://www.creatis.insa-lyon.fr/~valette/temp/three.js/examples/webgl_loader_vtk.html

do you have the same behavior with this adress?

@mrdoob
Owner

Ok. I figured it out :)

@mrdoob mrdoob closed this in f3dc454 Apr 18, 2012
@mrdoob
Owner

Uops! Seems like I accidentally the credit.
Fixed! 21a5aa4

@mrdoob
Owner

Here's another VTKLoader 45f80cf
It's simple but probably pretty silly. Only works with the sample we currently have. I'd need to study more the format and test more samples.

@scald

any ideas on getting color out of the vtk?

@mrdoob
Owner

Can you share a VTK file that has colors?

@scald

The specific one I'm working on isn't shareable, but I came across this on a forum: http://enthought-dev.117412.n3.nabble.com/attachment/996155/1/tmp1.vtk

When I get back in the office I might be able to get my hands on an open vtk3 data set with color as this one is v2. Not sure how different they would be. Thanks for your help!

@mrdoob
Owner

I don't see any color data in that file.

@valette

in this file, the colors are encoded at the position beginning with

POINT_DATA 124
SCALARS Depth float 1
LOOKUP_TABLE default

these are just scalar values attached to vertices. The scalars refer to a color lookup table (the vtk default in this case)
Is there any lookup table system with THREE.js?

@mrdoob
Owner

Is it supposed to be a hue?

@valette

no, it is an index to an other array which contains the actual colors. lookup tables in vtk are very versatile and very useful.

The first advantage is that for each vertex, you need only 1 scalar value (instead of four) which can be translated to the real color in the fragment shader. I implemented a shader for applying lookup tables to images with three.js and it was easy.

Probably, implementing lookup tables for three.js would be very helpful for other things than parsing vtk files.

here is the link to the vtkLookupTable class reference: http://www.vtk.org/doc/release/5.4/html/a00980.html

@mrdoob
Owner

But this is supposed to be a standard ramp or default graient, no? Where is that gradient specified. And how do those values relate to it? I guess we just want to load the model and have colors on it, so parsing these values against a gradient somewhere and converting to Colors, should do the trick I think. No need to have special shaders.

@valette

parsing these values against a gradient somewhere and converting to Colors, should do the trick I think. No need to have special shaders.

yes, it's the most easy thing to do.

I've read the tmp1.vtk file with c++ code, but I think this model is not very interesting, as the scalar data are all too big for the lookup table, all colors are blue. I will try to find a better example

@LoicCadour
LoicCadour commented Sep 7, 2016 edited

Hi,
I am using the VTKLoader from this example (very nice work, btw).
Now I have to display VTK meshes with scalars and I found this very interesting page.
So, I just wanted to know if changes had been done in the loader to take into account these scalars or if I should parse the VTK file to set the colors.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment