SCILAB三维重构工具箱- -

 
转贴]-S3DLAB_SCILAB三维重构工具箱
 
S3DLAB_SCILAB三维重构工具箱- -
Tag: S3DLAB    SCILAB    三维重构                                           

S3DLAB--------SCILAB三维重构工具箱的设计实现


SCILAB介绍


SCILAB是一个与MATLAB类似的科学计算自由软件,它主要有两个功能:数值计算和计算结果可视化。SCILAB具有丰富的数据类型和强大的矩阵运算能力。SCILAB具有丰富的图形显示能力,可以完成各种常规形式的计算结果可视化功能,SCILAB的图形库由Stephane Mottelet创建,该图形库提供了一些绘制二维和三维图形的函数方法,但是该图形库还不能达到专业级图形库的水平,特别是绘制出来的三维图形并不能完全表达出计算结果的信息。

作为开源项目,SCILAB的工具箱也在不断的丰富和完善,一些比较好的工具箱使SCILAB的功能日趋强大,但是作为一种工具箱作为一种用于开源的项目,需要不断的更新版本和不断的维护,SCILAB的功能虽然越来越多,但是作为基于Linux下开发的一个免费软件,其本身也有许多缺点,例如SCILAB对运行过程中的内存管理,SCILAB的界面还不是很具可操作性等。如果你也想挑战MATLAB,如果你也想做开源,SCILAB是个不错的选择,因为简单因为很容易入门的。

S3DLAB之源


S3DLAB是个偶然加必然的机会,偶然是因为我的导师或许偶然得到这个消息,必然是我因为我的研究方向正好是三维数据场可视化技术,这样的任务不得不接受,是个挑战也是个机遇,可惜我没能好好把握好,我想在这里我可以自由的书写S3DLAB的设计与实现,不必追求为了发表论文的而严肃的格式般,自由,只希望可以为你所用并分享一些这样的快乐大餐。

三维重构的前提是数据,三维重构模型使得三维重构工作变得可能,S3DLAB的设计初衷主要向提供一个良好的接口函数库,提供SCILAB可调用的OpenGL函数,这样通过SCILAB计算和处理所得体数据,可以根据不同的三维重构模型绘制出专业级别的三维图象,针对Windows和Linux有两种不同的调用机制,库函数拟用C语言进行编写,调用时可能要用到Tcl/Tk脚本语言,这样的工作由于前段时间的疏忽所以没有完成好,在后续的版本中会得到更新。目前的S3DLAB1.0版本中提供的三维绘制方法主要是调用了SCILAB已有的PLOT图形函数库,对三维图形的绘制也只能仅限于面绘制这种最简单的绘制方法,在后面您可以看到绘制效果。

工具箱框架设计




                  S3DLAB基本框架示意图


  在该示意图中,数据分析处理由SCILAB提供的函数实现,读取外部数据文件完成对数据的计算处理和重新组合,S3DLAB1.0设计时针对调用PLOT函数实现三维绘制的情况提出了一种4元数组集合数据结构,这种数据结构虽然在论文评审时得到专家的质疑,但是Linux下对临时数据的存贮方式和体数据规模数随着计算的变化,使得我最终还是采用了这种比较笨但是比较容易理解的数据结构。这种数据结构的简单定义为


       DATA(x,y,z) = (x,y,z,f(x,y,z))


x,y,z表示出了对应体素的位置信息,f(x,y,z)是对应体素的体素值,其实采用三维数组也是不错的选择,但是在数组定义时其缺点就暴露出来了。但是四元数组计和这种结构带来的另一个问题是为了方便的操作数据我不得不将每个集合数据文件单独存贮,所以数据量也变大了。


部分实现代码


SCILAB脚本读取BMP位图信息:

function Bmpinfo()


//get bitmap information 


printf("=======================================/n");


title = "Please input the path of bmp file ";


Labels = ["Bmp file path:"];


vector = x_mdialog(title,Labels,['']);


filename = vector(1); //Get the bmp file path


if filename == ""


  x_message("You should select a bmp file.");


  return;


end


disp(filename);
  
 作者: 58.63.185.*  2006-2-14 19:02   回复此发言  
 
2[转贴]-S3DLAB_SCILAB三维重构工具箱
 


fd = mopen(filename,'rb');


bmpftype = mget(1,'usl',fd); //Bmp fileheader Type should be 0x424d


bmpfsize = mget(1,'ll',fd);   // Bmp size information


bmpfres = mget(2,'usl',fd);   // Reserved information 


bmpfoff = mget(1,'ll',fd);    // Off bits 


bmpisize = mget(1,'ull',fd);  // Bmp information header size  


bmpwidth = mget(1,'ll',fd);   // bmp width 


bmpheight = mget(1,'ll',fd);   // bmp height 


bmpiplane = mget(1,'usl',fd);  // Bmp palette information  


bmpibits = mget(1,'usl',fd);   // bmp bits of perx piexl


bmpicompress = mget(1,'ull',fd); //bmp compress information 


bmpisizeimage = mget(1,'ull',fd); //Bmp image size information 


bmpixy = mget(2,'ll',fd);    // X Y pers meter 


bmpicolors = mget(2,'ull',fd); // Color used and zoom


if bmpibits == 8


   rgbs = [];


   for i = 1:256


      row = [];


      row = mget(4,'cl',fd);


      rgbs = [rgbs;row];


   end


end


 printf("=========================================/n");


 printf("=============Bmp Basic Information=======/n");


 printf("*******************************************/n");


 printf("BMP file size ==> "+string(bmpfsize)+"/n");


 printf("BMP fileoffsize=> "+string(bmpfoff)+"/n");


 printf("   BMP Width  ==> "+string(bmpwidth)+"/n");


 printf("   BMP Height ==> "+string(bmpheight)+"/n");


 printf("BMP bits/pixel==> "+string(bmpibits)+"/n");


 printf("BMP imagesize ==> "+string(bmpisizeimage)+"/n");


 printf("BMP color used => "+string(bmpicolors(1))+"/n");


 mclose(fd);


 if bmpibits == 8


    slicesize = bmpwidth * bmpheight;


    printf("Num of pixels =>%d/n",slicesize);


    D =[];


    D = getdata(filename,bmpfoff,bmpwidth,bmpheight);


    //Data = mgeti(slicesize,'ucl',fd);


    drawgrayl(D,bmpwidth,bmpheight);


     printf("Scan %d pixel data/n",slicesize);


 end


endfunction

利用线元绘制三维模型

function volrender1()


clear


xbasc()


//3d reconstruction with the edge table   test


printf("Rendering with the 4-elements array sets/n");


printf("==========================================/n");


title = "Enter the dictionary stored with volume data and the number of the files";


Labels = ["Scidat Dir: "; ...


          "Num of file:"]


vector = x_mdialog(title,Labels,['';'1']);


num = eval(vector(2));


filename = vector(1);//input("Enter the Dictionary hold the 4-elements array sets:/n");//filename = 'c://edge';


//disp(string(num));


//disp(filename);


for i=1:num


  u = file('open',filename+'/'+string(i)+'.dat','old');


  //disp(filename+string(i)+'.dat');


  table =read(u,-1,4);


  [n m] =size(table);


  x1=table(:,1);


  x2=table(:,2);


  x3=table(:,3);


  a=ones(x3);


  b = (a+i)/2;


  plot3d3(x1,x2,x3+b);


  file('close',u); //close(u);


end


endfunction




           基于线元结构的面绘制效果


基于三角片的面绘制

for i=1:zstep:num-zstep


     df1 = df + '/'+string(i)+'.dat';
  
 作者: 58.63.185.*  2006-2-14 19:02   回复此发言  
 
3[转贴]-S3DLAB_SCILAB三维重构工具箱
 


     df2 = df + '/'+string(i+zstep)+'.dat';


     u = file('open',df1,'old');


     //disp(filename+"/"+string(i)+'.dat');


     table1 =read(u,-1,4);


     [n m] =size(table1);


     x1=table1(:,1);


     x2=table1(:,2);


     x3=table1(:,3);


     a=zeros(x3);


     b = (a+i)/2;


     plot3d3(x1,x2,x3+b); // Draw the first line


     u2 = file('open',df2,'old');


     table2 = read(u2,-1,4);


     [p q] = size(table2);


     x4 = table2(:,1);


     x5 = table2(:,2);


     x6 = table2(:,3);


     c = ones(x6);


     d = (c+i)/2;


     plot3d3(x4,x5,x6+d); // draw ths second line


     /


     X=[];Y=[];Z=[];


     if p > n then  //Dim(table2)>Dim(table1)


        ip = p/n;


        for j=1:xystep:n-xystep    //build Tri with Line A & B 


          x =[];y=[];z=[];


          s1 = j+fix(xystep*ip);


          s2 = j+xystep;


          x = [x4(j);x1(j);x4(s1);x4(j)];


          y = [x5(j);x2(j);x5(s1);x5(j)];


          z = [x6(j)+d(j);x3(j)+b(j);x6(s1)+d(s1);x6(j)+d(j)];


          X=[X;x];Y=[Y;y];Z=[Z;z];


          x = [x1(j);x1(s2);x4(s1);x1(j)];


          y = [x2(j);x2(s2);x5(s1);x2(j)];


          z = [x3(j)+b(j);x3(s2)+b(s2);x6(s1)+d(s1);x3(j)+b(j)];


          X=[X;x];Y=[Y;y];Z=[Z;z];          


        end


          x = [x4(s1);x1(s2);x4(1);x4(s1)];


          y = [x5(s1);x2(s2);x5(1);x5(s1)];


          z = [x6(s1)+d(s1);x3(s2)+b(s2);x6(s1)+d(s1);x6(s1)+d(s1)];


          X = [X;x]; Y = [Y;y]; Z = [Z;z];


          x = [x1(s2);x1(1);x4(1);x1(s2)];


          y = [x2(s2);x2(1);x5(1);x2(s2)];


          z = [x3(s2)+b(s2);x3(1)+b(1);x6(1)+d(1);x3(s2)+b(s2)];


          X = [X;x]; Y =[Y;y]; Z=  [Z;z];


          plot3d(X,Y,Z);


     else   // p<=n  Dim(table2)<=Dim(table1)


        ip = n/p;


        for j = 1:xystep:p-xystep


           x =[];y=[];z=[];


           s1 = j+fix(xystep*ip);


           s2 = j+xystep;


           x = [x4(j);x1(j);x4(s2);x4(j)];


           y = [x5(j);x2(j);x5(s2);x5(j)];


           z = [x6(j)+d(j);x3(j)+b(j);x6(s2)+d(s2);x6(j)+d(j)];


           X = [X;x]; Y = [Y;y]; Z = [Z;z];


           x = [x1(j);x1(s1);x4(s2);x1(j)];


           y = [x2(j);x2(s1);x5(s2);x2(j)];


           z = [x3(j)+b(j);x3(s1)+b(s1);x6(s2)+d(s2);x3(j)+b(j)];


           X = [X;x]; Y = [Y;y]; Z = [Z;z];


        end


           x = [x4(s2);x1(s1);x4(1);x4(s2)];


           y = [x5(s2);x2(s1);x5(1);x5(s2)];


           z = [x6(s2)+d(s2);x3(s1)+b(s1);x6(1);x6(s2)+d(s2)];


           X = [X;x]; Y = [Y;y]; Z = [Z;z];


           x = [x1(s1);x1(1);x4(1);x1(s1)];


           y = [x2(s1);x2(1);x5(1);x2(s1)];


           z = [x3(s1)+b(s1);x3(1)+b(1);x6(1)+d(1);x3(s1)+b(s1)];


           X = [X;x]; Y = [Y;y]; Z = [Z;z];


           plot3d(X,Y,Z);


     end


     //printf("index: %d n=%d p=%d cn=%d/n",i,n,p,imin);


     printf("Scan With "+df1+" OK/n");


     printf("Scan With "+df2+" OK/n");


     file('close',u2); 


     file('close',u); //close(u);


  end




          基于三角片的面绘制效果



 


 


 


 


 


 


 


 


 


 


 


- 作者: volrender 访问统计:60 2005年09月30日, 星期五 10:18 加入博采 
Trackback
你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=3081003 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值