Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

bccsphere.cpp

Go to the documentation of this file.
00001 #include <iostream.h>
00002 #include <stdio.h>
00003 #include <math.h>
00004 
00005 #include "vuVector.h"
00006 
00007 //g++ bccsphere.cpp -o pro -I  ~/space/projects/vuVolume/proj/General ~/space/projects/vuVolume/proj/General/{vuVector,vuMatrix}.o; ./pro
00008 
00009 #define MAXX    45
00010 #define MAXY    45
00011 #define MAXZ    90
00012 #define DATSIZE MAXX*MAXY*MAXZ
00013 #define FNAME   "sphere4mat.bcc.vud"
00014 #define T       1.41421356
00015 
00016 // taken from vu1512
00017 vuVector getVoxelPosition(int x, int y, int z)
00018 {
00019   vuVector pos;
00020   if(z&0x01){
00021     //secondary grid
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     //primary grid
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             unsigned char val;
00063             float t;
00064             unsigned char mat = 64 + v.getDominantAxis()*64;
00065             t = (radius-dist)/radius;
00066             val = (unsigned char)(mat + (t*64 + (1-t)*0));
00067             fputc(val,f);
00068           } else if(fabs(v[v.getDominantAxis()])<radius) {
00069             // framecube
00070             fputc(20,f);
00071           } else {
00072             // outside
00073             fputc(0,f);
00074           }
00075         }
00076       }
00077     }
00078     fclose(f);
00079   } else printf("Couldn't create file %s.\n",FNAME);
00080 
00081 }

Generated on Wed Dec 15 21:20:28 2004 for vuVolume by  doxygen 1.3.9.1