Rendering an xtk volume with a .vtk file created from Matlab

I start with htk. I would like to upload a .vtk file in order to render the volume in XTK.

This .vtk file was created using the matlab function, which saves a 3D data array (voxel) in vtk format:

function savevtk(array, filename) % savevtk Save a 3-D scalar array in VTK format. % savevtk(array, filename) saves a 3-D array of any size to % filename in VTK format. [nx, ny, nz] = size(array); fid = fopen(filename, 'wt'); fprintf(fid, '# vtk DataFile Version 2.0\n'); fprintf(fid, 'Comment goes here\n'); fprintf(fid, 'ASCII\n'); fprintf(fid, '\n'); fprintf(fid, 'DATASET STRUCTURED_POINTS\n'); fprintf(fid, 'DIMENSIONS %d %d %d\n', nx, ny, nz); fprintf(fid, '\n'); fprintf(fid, 'ORIGIN 0.000 0.000 0.000\n'); fprintf(fid, 'SPACING 1.000 1.000 1.000\n'); fprintf(fid, '\n'); fprintf(fid, 'POINT_DATA %d\n', nx*ny*nz); fprintf(fid, 'SCALARS scalars float\n'); fprintf(fid, 'LOOKUP_TABLE default\n'); fprintf(fid, '\n'); for a=1:nx for b=1:ny for c=1:nz fprintf(fid, '%d ', array(a,b,c)); end fprintf(fid, '\n'); end end fclose(fid); return 

As soon as the file 'output.vtk' is created, I try to download it as follows:

 window.onload = function() { var r = new X.renderer3D(); r.init(); // create a mesh from a .vtk file var skull = new X.mesh(); skull.file = 'output.vtk'; // add the object r.add(skull); // .. and render it r.render(); }; 

But nothing is displayed in the browser.

Is my 'output.vtk' an invalid .vtk file for rendering a volume?

How to load this kind of file in the XTK?

0
source share
1 answer

XTK code looks good, but the vtk format usually does not contain more than 1 space between values. I think the problem.

+1
source

All Articles