Closed schmitzke closed 12 years ago
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.
VTK is very popular in research community, it may be worth to have some pipeline for dealing with stuff it produces.
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.
that would be awesome! thank you.
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.
@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... ?
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?
You probably used clean repo but the master
branch instead of dev
branch.
What browser/os are you using?
ah ok, I should stop writing patches against master, but use dev branch instead. Will fix issues and come back...
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.
Weird. I just get this: Could not read file models/bunny.vtk: error0
.
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!
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.
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?
Ok. I figured it out :)
Uops! Seems like I accidentally the credit. Fixed! 21a5aa4b6d4ac3bfd0fdf87645a107961d63adf2
Here's another VTKLoader 45f80cf6d70b32bf3ebde6a7e4954af570ba9b8d 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.
any ideas on getting color out of the vtk?
Can you share a VTK file that has colors?
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!
I don't see any color data in that file.
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?
Is it supposed to be a hue?
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
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.
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
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
Hi @LoicCadour Colors can be set from scalar from this example https://threejs.org/examples/webgl_geometry_colors_lookuptable.html In my case scalars looks like this:
POINT_DATA 4
SCALARS temp float
LOOKUP_TABLE default
15
23
31
11
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