0

I am beginning with XTK. I would like to load a .vtk file in order to make volume rendering into XTK.

This .vtk file has been created with a matlab function which saves a 3D data array (voxel) into 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

Once the 'output.vtk' file is created, I try to load it this way :

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 displays in the browser.

Is my 'output.vtk' is not a valid .vtk file for volume rendering ?

How to load into XTK this kind of file ?

  • so finally how did you solve your problem??....I am stuck up at the point.Unable to load the .vtk file using xtk.My .vtk file format is same as u mentioned here.Please help me :) – AkshayJ Nov 23 '15 at 05:43

1 Answers1

0

the XTK code looks good but the vtk format usually doesn't have more than 1 space between values. I think that's the problem.

haehn
  • 967
  • 1
  • 6
  • 19
  • the vtk file seems to be valid, I have tested it with paraview and it's ok. So what is wrong ? –  Jan 07 '13 at 09:43
  • that might be true but XTK (for performance reasons) does not strip multiple spaces between values. just give it a try and I am pretty sure that it will work. maybe if you re-save the file using paraview, the writer already strips the spaces for you? – haehn Jan 08 '13 at 13:52
  • I have removed multiple spaces by re-save the file using paraview but it still doesn't work. I think so that it comes from the xtk code. I just want to render a volume, 'var skull = new X.mesh();' is the right command ? –  Jan 09 '13 at 01:00
  • can you share the new file? – haehn Feb 07 '13 at 01:48
  • Does XTK require any customizations in the .vtk file produced?...Im confused..:( – AkshayJ Nov 23 '15 at 05:44
  • the skull example uses polydata - this is a set of structured points. – g.stevo Oct 18 '16 at 01:56