使用Matlab创建的.vtk文件进行xtk体积渲染 [英] xtk volume rendering with .vtk file created from matlab

查看:304
本文介绍了使用Matlab创建的.vtk文件进行xtk体积渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从XTK开始.我想加载一个.vtk文件,以便将体积渲染到XTK中.

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

此.vtk文件是使用matlab函数创建的,该函数将3D数据数组(voxel)保存为vtk格式:

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

创建'output.vtk'文件后,我尝试以这种方式加载它:

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.

我的'output.vtk'不是用于体积渲染的有效.vtk文件吗?

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

如何将这种文件加载到XTK中?

How to load into XTK this kind of file ?

推荐答案

XTK代码看起来不错,但vtk格式通常在值之间不超过1个空格.我认为这就是问题所在.

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.

这篇关于使用Matlab创建的.vtk文件进行xtk体积渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆