00001 #include <iostream>
00002 #include <stdio.h>
00003 #include <math.h>
00004
00005 #include "vuVector.h"
00006
00007
00008
00009 #define MAXX 45
00010 #define MAXY 45
00011 #define MAXZ 90
00012 #define DATSIZE MAXX*MAXY*MAXZ
00013 #define FNAME "sphere.bcc.vud"
00014 #define T 1.41421356
00015
00016
00017 vuVector getVoxelPosition(int x, int y, int z)
00018 {
00019 vuVector pos;
00020 if(z&0x01){
00021
00022 pos[0] = (float(x)+0.5)*T;
00023 pos[1] = (float(y)+0.5)*T;
00024 pos[2] = (float(z))*(T*0.5);
00025 } else {
00026
00027 pos[0] = float(x)*T;
00028 pos[1] = float(y)*T;
00029 pos[2] = float(z)*T*0.5;
00030 }
00031
00032 return pos;
00033 }
00034
00035
00036 void main(void)
00037 {
00038 FILE *f = fopen(FNAME,"wb");
00039 if(f) {
00040 fprintf(f,"# vu DataFile Version 1.0\n");
00041 fprintf(f,"Volume Data\n");
00042 fprintf(f,"BINARY\n");
00043 fprintf(f,"DATASET BCC_POINTS\n");
00044 fprintf(f,"UNIMODAL\n");
00045 fprintf(f,"DIMENSIONS %i %i %i 1\n",MAXX,MAXY,MAXZ);
00046 fprintf(f,"ORIGIN 0 0 0 0\n");
00047 fprintf(f,"SPACING 0 0 0 0\n");
00048 fprintf(f,"POINT_DATA %i\n",DATSIZE);
00049 fprintf(f,"SCALARS data byte\n");
00050 fprintf(f,"LOOKUP_TABLE default\n");
00051
00052 vuVector center = getVoxelPosition(MAXX,MAXY,MAXZ)*0.5f;
00053 float radius = center[center.getDominantAxis()]*0.8f;
00054 int i,j,k;
00055 for(k=0;k<MAXZ;k++) {
00056 for(j=0;j<MAXY;j++) {
00057 for(i=0;i<MAXX;i++) {
00058 vuVector pos = getVoxelPosition(i,j,k);
00059 vuVector v = pos-center;
00060 float dist = v.norm();
00061 if(dist<radius) {
00062 float t = (radius-dist)/radius;
00063 unsigned char val = (unsigned char)(t*255 + (1-t)*100);
00064 fputc(val,f);
00065 } else if(fabs(v[v.getDominantAxis()])<radius)
00066 fputc(50,f);
00067 else
00068 fputc(0,f);
00069 }
00070 }
00071 }
00072 fclose(f);
00073 } else printf("Couldn't create file %s.\n",FNAME);
00074
00075 }