diff --git a/cpp/cudafunc.cu b/cpp/cudafunc.cu index a7786d5..4c5dbd6 100644 --- a/cpp/cudafunc.cu +++ b/cpp/cudafunc.cu @@ -1,10 +1,3 @@ -/*#include "circle_check.cuh" - -void test_3(float* gpu_out, float* gpu_grad, float rmax, float phi, int n, int x, int y, int z){ -gpu_test3(gpu_out, gpu_grad, rmax, phi, n, x, y, z); -} -*/ - #include "gaussian_blur3.cuh" #include "gradient3.cuh" @@ -14,7 +7,7 @@ gpu_test3(gpu_out, gpu_grad, rmax, phi, n, x, y, z); #include "local_max3.cuh" -void ivote3(float* img, float sigma[], float anisotropy, float phi, float d_phi, unsigned int r[], +void ivote3(float* img, float sigma[], float phi, float d_phi, unsigned int r[], int iter, float t, unsigned int conn[], unsigned int x, unsigned int y, unsigned int z){ @@ -33,7 +26,7 @@ void ivote3(float* img, float sigma[], float anisotropy, float phi, float d_phi, float* gpu_grad; //assign memory on the gpu for the gradient along the X, y, z. cudaMalloc(&gpu_grad, bytes*3); - gpu_gradient3(gpu_grad, gpuI0, anisotropy, x, y, z); //call the gradient function from the gpu. + gpu_gradient3(gpu_grad, gpuI0, 1, x, y, z); //call the gradient function from the gpu. cudaFree(gpuI0); float* gpu_vote; @@ -57,9 +50,9 @@ void ivote3(float* img, float sigma[], float anisotropy, float phi, float d_phi, } - cudaFree(gpu_grad); + cudaFree(gpu_grad); cudaMemcpy(img, gpu_vote, bytes, cudaMemcpyDeviceToHost); - + //allocate space on the gpu for the final detected cells. //float* gpu_output; //cudaMalloc(&gpu_output, bytes); diff --git a/cpp/main.cpp b/cpp/main.cpp index 928d0b4..196e41a 100644 --- a/cpp/main.cpp +++ b/cpp/main.cpp @@ -7,123 +7,19 @@ #include #include #include -#define pi 3.14159 +#include -//#define M_PI 3.14159 -//#include -//#include -//#include -//#include -//#include +stim::arglist args; +int iter; +unsigned int rmax; +unsigned int nlmax; +float t; +float sigma; +float phi; +size_t x, y, z; - -/*void test_3(float* gpu_out, float* gpu_grad, float rmax, float phi, int n, int x, int y, int z); - -int main(){ - - int n=20; - float rmax; - float phi_deg; - float phi; - rmax=4; - phi_deg = 15; - phi = phi_deg * pi/180; - int x,y,z; - x=y=z=1; - unsigned int size = x*y*z*sizeof (float); - float* cpu_grad = (float*) malloc(3*size); - float* gpu_grad; - cudaMalloc(&gpu_grad, 3*size); - cpu_grad[0]=1; - cpu_grad[1]=0; - cpu_grad[2]=-0.5; - cudaMemcpy(gpu_grad, cpu_grad, 3*size, cudaMemcpyHostToDevice); - float* cpu_out = (float*) malloc(3*size*(n+1)); - float* gpu_out; - cudaMalloc(&gpu_out, 3*size*(n+1)); - test_3(gpu_out, gpu_grad, rmax, phi, n, x, y, z); - cudaMemcpy(cpu_out, gpu_out, 3*size*(n+1), cudaMemcpyDeviceToHost); - std::ofstream list("circle_check_cuda1.txt"); - if (list.is_open()){ - for (int j=0; j<=n; ++j) - list << cpu_out[3*j] << '\t' << cpu_out[3*j +1] << '\t' << cpu_out[3*j + 2] << '\n'; - } - list.close(); - */ -/* - int main(){ - - - stim::vec3 g(-44,-3.4,-0.005); // form a vec3 variable for the gradient vector - stim::vec3 g_sph = g.cart2sph(); //convert cartesian coordinate to spherical for the gradient vector - int n =36; //set the number of points to find the boundaries of the conical voting area - int xi = 105; - int yi = 17; - int zi = 23; - float xc = 12 * cos(g_sph[1]) * sin(g_sph[2]); //calculate the center point of the surface of the voting area for the voter - float yc = 10 * sin(g_sph[1]) * sin(g_sph[2]) ; - float zc = 10 * cos(g_sph[2]) ; - float r = sqrt(xc*xc + yc*yc + zc*zc); - xc+=xi; - yc+=yi; - zc+=zi; - stim::vec3 center(xc,yc,zc); - - float d = 2 * r * tan(25*pi/180 ); //find the diameter of the conical voting area - stim::vec3 norm = g.norm(); //compute the normalize gradient vector - float step = 360.0/(float) n; - stim::circle cir(center, d, norm); - stim::aabb3 bb(xi,yi,zi); - bb.insert(xc,yc,zc); - for(float j = 0; j <360.0; j += step){ - stim::vec3 out = cir.p(j); - bb.insert(out[0], out[1], out[2]); - } - - bb.trim_low(0,0,0); - bb.trim_high(128-1, 128-1, 128-1); - - std::cout<< bb.low[0] << '\t' << bb.low[1] << '\t' << bb.low[2] << '\n'; - std::cout<< bb.high[0] << '\t' << bb.high[1] << '\t' << bb.high[2] << '\n'; - std::cin >> n; -*/ - /*int n=10; - stim::circle cir; - float* c0= (float*) malloc(3*sizeof(float)); - c0[0] =-4; - c0[1]=0; - c0[2] = 3; - stim::vec3 c(c0[0],c0[1],c0[2]); - float len = c.len(); - stim::vec3 norm(c0[0]/len,c0[1]/len,c0[2]/len); - std::cout<< len << '\n'; - std::cout<< norm << '\n'; - cir.center(c); - cir.normal(norm); - cir.scale(2); - stim::vec3 out = cir.p(45); - std::vector> out2 = cir.getPoints(n); - - std::cout<< out << '\n'; - std::cout <>::const_iterator i = out2.begin(); i != out2.end(); ++i) - std::cout << *i << '\n'; - std::ofstream list("circle_check.txt"); - if (list.is_open()){ - for (std::vector>::const_iterator j = out2.begin(); j != out2.end(); ++j) - list << *j << '\n'; - } - list.close(); - std::cin >> n; - -} -*/ - - -void ivote3(float* img, float std[], float anisotropy, float phi, float d_phi, unsigned int r[], int iter, float t, unsigned int conn[], +void ivote3(float* img, float std[], float phi, float d_phi, unsigned int r[], int iter, float t, unsigned int conn[], unsigned int x, unsigned int y, unsigned int z); void lmax(float* center, float* vote, float t1, unsigned int conn[], unsigned int x, unsigned int y, unsigned int z); @@ -138,32 +34,20 @@ void invert_data(float* cpuI, unsigned int x, unsigned int y, unsigned int z){ } } -int main(int argc, char** argv){ - cudaDeviceProp prop; - int count; - cudaGetDeviceCount(&count); - //printf("cudadevicecount: %i\n", count); - for (int i=0; i 0"); + args.add("sigma", "the gaussian blur standard deviation", "5", "s >=0 (s = 0, no blurring)"); + args.add("conn", "the number of connected neighbors for calculating the local maxima", "5", "[positive value]"); //parse the command line arguments. args.parse(argc, argv); //display the help text if requested - if(args["help"].is_set()){ - std::cout<imgrad3; - //imgrad3.set_interleaved3(cpu_out, 128,128,128,3); - //std::ofstream fgx("syn/gx-128.vol", std::ofstream::out | std::ofstream::binary); - //fgx.write((char*)imgrad3.channel(0).data(), bytes); - //fgx.close(); + ivote3(cpuI, sigma3, phi, d_phi, r, iter, t, conn, x, y, z); // call the ivote function + + std::ofstream fvote("0-vote8.vol", std::ofstream::out | std::ofstream::binary); + fvote.write((char*)cpuI, bytes); + fvote.close(); + //allocate space on the cpu for the output result + float* cpu_out = (float*)malloc(bytes * 3); + //write the output file. //for (int t0=0; t0<=5000; t0+=100){ // float t1 = t0; int t0 = t; lmax(cpu_out, cpuI, t, conn, x, y, z); //std::ofstream fo("shared2D-v8/" + OutName.str(), std::ofstream::out | std::ofstream::binary); - std::ofstream fo( OutName.str()+std::to_string(t0)+".vol", std::ofstream::out | std::ofstream::binary); + std::ofstream fo( args.arg(1), std::ofstream::out | std::ofstream::binary); fo.write((char*)cpu_out, bytes); fo.close(); // creat a file for saving the list centers - std::ofstream list(OutName.str()+std::to_string(t0)+".obj"); + std::ofstream list(args.arg(2)); // set the number of detected cells to zero. int nod = 0; if (list.is_open()){ @@ -281,17 +170,13 @@ int main(int argc, char** argv){ int idx = iz * x * y + iy * x + ix; if (cpu_out[idx]>0){ nod++; - list << "v" << "\t" << ix << "\t" << iy << "\t"<< iz << "\t" << cpu_out[idx] << '\n' ; + list << ix << " " << iy << " "<< iz << " " << cpu_out[idx] << '\n' ; } } } } - list << "p" << "\t"; - for (unsigned int i_nod =1 ; i_nod <=nod; i_nod++){ - list << i_nod << "\t"; - } - + list.close(); } -- libgit2 0.21.4