[Bf-committers] From Farsthary new proposal for sim_physics

echelon at infomail.upr.edu.cu echelon at infomail.upr.edu.cu
Wed Feb 18 19:53:44 CET 2009


Hi all!

  since the voxeldata texture in volumetrics have started to being used in
some real life situations (imposting of medical datasets in blender and
so)
 I have implemented few requested features that will increase the
usability of this module:

  1-Automatic dataset resolution detection
  user no longer need to manually set up the dataset resolution, a very
dangerous preocedure
  2-Rectangular datasets, previously where only handled cubic datasets
  3-Still feature
  User could specify a frame from the dataset to remain still during an
animation (for rotations, zoomings and so :)

  NOTE: this is only a proposal, I have submitted it to Matt Ebb for
review and commit, he could freely change the implementation if some
part need a better design.

 Now blender compatible datasets require a small header to keep things as
simple and general as posible. In future more development will be done in
that important area.

 The changes to tools that already use voxeldata features (my experimental
simulator of smoke/fire) are very small. I will upload soon the rewritten
simulator.

I post here the content of the patch for those that could not wait for the
official submit

             Cheers to all

 This is a diff against the source archive of the 2.48a Sim_physics rev18682
.../source/blender/makesdna/DNA_texture_types.h
173a174,175
++
++ int still,still_frame; //used in still datasets
...source/blender/render/intern/include/voxeldata.h
39c39,47
-- int _I(int x,int y,int z,int n);
++ typedef struct Header_vb //Header could be extended here easily
++ {
++ int resolX,resolY,resolZ;
++ int frames;
++
++ } Header_vb;
++
++ int _I(int x,int y,int z,int *n);
.../source/blender/render/intern/source/voxeldata.c
44a45
++ #include "voxeldata.h"
51c52
-- static inline int _I(int x,int y,int z,int n)
++ int _I(int x,int y,int z,int *n)
53c54
-- return (z*(n)+y)*(n)+x;
++ return (z*n[1]+y)*n[0]+x;
56c57
-- float Linear(float xx,float yy,float zz,float *x0,int n)
++ float Linear(float xx,float yy,float zz,float *x0,int *n)
61,63c62,64
-- if (xx<0.5) xx=0.5f; if (xx>n+0.5) xx=n+0.5f; i0=(int)xx; i1=i0+1;
-- if (yy<0.5) yy=0.5f; if (yy>n+0.5) yy=n+0.5f; j0=(int)yy; j1=j0+1;
-- if (zz<0.5) zz=0.5f; if (zz>n+0.5) zz=n+0.5f; k0=(int)zz; k1=k0+1;
++ if (xx<0.5) xx=0.5f; if (xx>n[0]+0.5) xx=n[0]+0.5f; i0=(int)xx; i1=i0+1;
++ if (yy<0.5) yy=0.5f; if (yy>n[1]+0.5) yy=n[1]+0.5f; j0=(int)yy; j1=j0+1;
++ if (zz<0.5) zz=0.5f; if (zz>n[2]+0.5) zz=n[2]+0.5f; k0=(int)zz; k1=k0+1;
75c76
-- static float D(float *data, const int res, int x, int y, int z)
++ static float D(float *data, const int *res, int x, int y, int z)
77,79c78,80
-- CLAMP(x, 0, res-1);
-- CLAMP(y, 0, res-1);
-- CLAMP(z, 0, res-1);
++ CLAMP(x, 0, res[0]-1);
++ CLAMP(y, 0, res[1]-1);
++ CLAMP(z, 0, res[2]-1);
88c89
-- static float trilinear(float *data, const int res, float *co)
++ static float trilinear(float *data, const int *res, float *co)
98,100c99,101
-- voxx = co[0] * res - 0.5f;
-- voxy = co[1] * res - 0.5f;
-- voxz = co[2] * res - 0.5f;
++ voxx = co[0] * res[0] - 0.5f;
++ voxy = co[1] * res[1] - 0.5f;
++ voxz = co[2] * res[2] - 0.5f;
245c246
-- float tricubic(float xx,float yy,float zz,float *heap,int n)
++ float tricubic(float xx,float yy,float zz,float *heap,int *n)
253,255c254,256
-- if (xx<0.5) xx=0.5f; if (xx>n+0.5) xx=n+0.5f; xi=(int)xx;
-- if (yy<0.5) yy=0.5f; if (yy>n+0.5) yy=n+0.5f; yi=(int)yy;
-- if (zz<0.5) zz=0.5f; if (zz>n+0.5) zz=n+0.5f; zi=(int)zz;
++ if (xx<0.5) xx=0.5f; if (xx>n[0]+0.5) xx=n[0]+0.5f; xi=(int)xx;
++ if (yy<0.5) yy=0.5f; if (yy>n[1]+0.5) yy=n[1]+0.5f; yi=(int)yy;
++ if (zz<0.5) zz=0.5f; if (zz>n[2]+0.5) zz=n[2]+0.5f; zi=(int)zz;
334c335
-- void load_frame (FILE *fp,float *F, int size,int frame)
++ void load_frame (FILE *fp,float *F, int size,int frame,int offset)
336,338c337,356
--
-- fseek(fp,frame*size*sizeof(float),0);
-- fread(F,sizeof(float),size,fp);
++ fseek(fp,frame*size*sizeof(float)+offset,0);
++ fread(F,sizeof(float),size,fp);
++ }
++
++ void write_header_vb(struct Header_vb *h,FILE *fp)
++ {
++ fwrite(h,sizeof(struct Header_vb),1,fp);
++ }
++
++ void read_header_vb(FILE *fp,struct VoxelData *vd)
++ {
++ struct Header_vb *h=(struct Header_vb *)malloc(sizeof(struct Header_vb));
++ rewind(fp);
++ fread(h,sizeof(struct Header_vb),1,fp);
++
++ vd->resolX=h->resolX;
++ vd->resolY=h->resolY;
++ vd->resolZ=h->resolZ;
++
++ free(h);
350,356c368
-- if (!vd) return;
--
-- vd->resolY=vd->resolX; //for now only support cubic datasets
(rectangular datasets could be
added latter)
-- vd->resolZ=vd->resolX;
-- size = (vd->resolX)*(vd->resolY)*(vd->resolZ);
--
-- vd->dataset=MEM_mallocN(sizeof(float)*size, "voxel dataset");
++ if (!vd) return;
362c374,379
-- load_frame(fp, vd->dataset, size, re->r.cfra); //here improve the
dataset loading function
for more dataset types
++ read_header_vb(fp,vd);
++ size = (vd->resolX)*(vd->resolY)*(vd->resolZ);
++ vd->dataset=MEM_mallocN(sizeof(float)*size, "voxel dataset");
++
++ if (vd->still) load_frame(fp, vd->dataset, size,
vd->still_frame,sizeof(struct
Header_vb)); //here improve the dataset loading function for more dataset
types
++ else load_frame(fp, vd->dataset, size, re->r.cfra,sizeof(struct
Header_vb));
424,425c441
-- int resolX, resolY, resolZ;
--
433,436c449
-- resolX=vd->resolX;
-- resolY=vd->resolY;
-- resolZ=vd->resolZ;
++ int resol[3]={vd->resolX,vd->resolY,vd->resolZ};
439,441c452,454
-- dx=1.0f/(resolX);
-- dy=1.0f/(resolY);
-- dz=1.0f/(resolZ);
++ dx=1.0f/(resol[0]);
++ dy=1.0f/(resol[1]);
++ dz=1.0f/(resol[2]);
449c462,463
-- zf=co[2]/dz;
++ zf=co[2]/dz;
451c465
-- if (xi>1 && xi<resolX)
++ if (xi>1 && xi<resol[0])
453c467
-- if (yi>1 && yi<resolY)
++ if (yi>1 && yi<resol[1])
455c469
-- if (zi>1 && zi<resolZ)
++ if (zi>1 && zi<resol[2])
461c475
-- texres->tin = vd->dataset[_I(xi,yi,zi,resolX)];
++ texres->tin = vd->dataset[_I(xi,yi,zi,resol)];
466c480
-- texres->tin = trilinear(vd->dataset, resolX, co);
++ texres->tin = trilinear(vd->dataset, resol, co);
471c485
-- texres->tin = tricubic(xf,yf,zf,vd->dataset,resolX);
++ texres->tin = tricubic(xf,yf,zf,vd->dataset,resol);
494d507
..../source/blender/src/buttons_shading.c
1088c1088,1097
-- uiDefButI(block, NUM, B_REDR, "Resolution: ",
++ uiDefButI(block,TOG, B_REDR, "Still: ",
++ X2CLM1, yco-=BUTH, BUTW2, BUTH, &(vd->still), 0,1, 0, 0, "Use frame
still");
++
++ if (vd->still) uiDefButI(block, NUM, B_REDR, "Frame: ",
++ X2CLM1, yco-=BUTH, BUTW2, BUTH, &(vd->still_frame), 1, 10000, 0, 0, "Frame
that remain still");
++
++
++ uiBlockBeginAlign(block);
++
++ uiDefButI(block, NUM, B_REDR, "Resol X: ",
1090,1091c1099,1108
--
-- yco -= YSPACE;
++ yco-=BUTH;
++
++ uiDefButI(block, NUM, B_REDR, "Resol Y: ",
++ X2CLM2, yco, BUTW2, BUTH, &(vd->resolY), 1, 10000, 0, 0, "Resolution of
the
voxel data");
++ yco-=BUTH;
++
++ uiDefButI(block, NUM, B_REDR, "Resol Z: ",
++ X2CLM2, yco, BUTW2, BUTH, &(vd->resolZ), 1, 10000, 0, 0, "Resolution of
the
voxel data");
++
++ uiBlockEndAlign(block);



More information about the Bf-committers mailing list