Jerome Piovano

Research in Medical Imaging and Computer Vision

3D_FastMarching.C

3D Fast Marching

00001 #include <Image.H>
00002 #include <FastMarching.h>
00003 
00004 #include <cmath>
00005 #include <sstream>
00006 
00009 int main(int argc, char* argv[])
00010 {       
00011         using namespace Images;
00012         using namespace levelset;
00013 
00014 #if 1 // sphere
00015 
00016         const Dimension nx = 200;
00017         const Dimension ny = 200;
00018         const Dimension nz = 200;
00019         const Dimension dims[] = {nx, ny, nz};
00020         Shape<3> shape(dims);
00021 
00022         BaseImage<3,float> image(shape);    // image of size nx*ny*nz
00023         Eikonal<3,float>   march(&image);   // fast marching eikonal 
00024 
00025         // initialization  
00026         image = 0.0;
00027         BaseImage<3,float>::Index ind(100, 100, 100);
00028         march.add_trial_point(ind);
00029 
00030         march.run();
00031 
00032         std::ofstream f("3D_FastMarching.inr"); 
00033         f << format("inrimage") << image;
00034         f.close();
00035 
00036         return 0;
00037 
00038 #endif
00039 
00040 #if 0 // misc
00041 
00042         const Dimension nx = 200;
00043         const Dimension ny = 200;
00044         const Dimension nz = 200; 
00045         const Dimension dims[] = {nx, ny, nz}; 
00046         Shape<3> shape(dims);
00047 
00048         BaseImage<3,float> image(shape);    // image of size nx*ny*nz
00049         Eikonal<3,float>   march(&image);   // fast marching eikonal 
00050 
00051         // initialization  
00052         image = 0.0;
00053 
00054         srand(10000);
00055 
00056         // 20 random seeds
00057         for (int ind = 0 ; ind < 20 ; ind++){
00058 
00059                 int x = static_cast<int>(nx * (double)rand() / ((double)(RAND_MAX)+(double)(1)));
00060                 int y = static_cast<int>(ny * (double)rand() / ((double)(RAND_MAX)+(double)(1)));
00061                 int z = static_cast<int>(nz * (double)rand() / ((double)(RAND_MAX)+(double)(1)));
00062                 BaseImage<3,float>::Index ind(x, y, z);
00063 
00064                 march.add_trial_point(ind);
00065         }
00066 
00067         // 20 circles of forbidden points of radius <= 30
00068         for (int ind = 0 ; ind < 20 ; ind++){
00069 
00070                 int x = static_cast<int>(30 + (nx-60) * (double)rand() / ((double)(RAND_MAX)+(double)(1)));
00071                 int y = static_cast<int>(30 + (ny-60) * (double)rand() / ((double)(RAND_MAX)+(double)(1)));
00072                 int z = static_cast<int>(30 + (nz-60) * (double)rand() / ((double)(RAND_MAX)+(double)(1)));
00073                 int r = static_cast<int>(          30 * (double)rand() / ((double)(RAND_MAX)+(double)(1)));
00074         
00075                 for (int i = x-r ; i < x+r ; i++)
00076                         for (int j = y-r ; j< y+r ; j++)
00077                                 for (int k = z-r ; k< z+r ; k++)
00078                                         if(sqrt( (double) Maths::sqr(i - x) +  Maths::sqr( j - y) +  Maths::sqr( k - z)) < r){
00079                                                 BaseImage<3,float>::Index ind(i, j, k);
00080                                                 march.add_forbidden_point(ind);
00081                                         }
00082         }
00083 
00084         march.run();
00085 
00086         std::ofstream f("3D_FastMarching.inr"); 
00087         f << format("inrimage") << image;
00088         f.close();
00089 
00090         return 0;
00091 
00092 #endif
00093 
00094 }

For further information, please contact Jerome Piovano - Last update 2008-02-08