Exemplo n.º 1
0
  unsigned __stdcall transformvolume_color(double **Args) {
#else
  void transformvolume_color(double **Args) {
#endif
    double *Isize_d, *A, *Iin, *Iout, *ThreadID, *moded, *Jsize_d;
    int Isize[3]={0,0,0};
	int Jsize[3]={0,0,0};
	double Imean[2]={0,0};
	double Jmean[2]={0,0};
    int mode=0;
    int x,y;
	double *Nthreadsd;
    int Nthreads;

    /* Location of pixel which will be come the current pixel */
    double Tlocalx;
    double Tlocaly;
    
    /* X,Y,Z coordinates of current pixel */
    double xd,yd;

	/* Parts of location calculation */
	double compa0, compa1, compb0, compb1;
	
    /* loop throught the colors r,g,b */
    int rgb=0;
            
    /* Variables to store 1D index */
    int indexI;
    
    /* Current voxel/pixel */
    double Ipixel[3]={0,0,0};
    
    /* Cubic and outside black booleans */
    bool black, cubic;
    
    /* Multiple threads, one does the odd the other even indexes */
    int ThreadOffset;
    /* int start; */
    /* int end;; */
    
    Isize_d=Args[0];
    Jsize_d=Args[1];
	A=Args[2];
    Iin=Args[3];
    Iout=Args[4];
    ThreadID=Args[5];
    moded=Args[6]; mode=(int) moded[0];
    Nthreadsd=Args[7];  Nthreads=(int)Nthreadsd[0];
	
	/* Center of the image */
	Imean[0]=Isize_d[0]/2;	Imean[1]=Isize_d[1]/2;  
    Jmean[0]=Jsize_d[0]/2;	Jmean[1]=Jsize_d[1]/2; 
        
    black = true;
    cubic = false;
    if(mode==0||mode==2){ black = false; } else { black = true; }
    if(mode==0||mode==1){ cubic = false; } else { cubic = true; }
    
    Isize[0] = (int)Isize_d[0]; 
    Isize[1] = (int)Isize_d[1]; 
    Isize[2] = (int)Isize_d[2]; 
    
    Jsize[0] = (int)Jsize_d[0]; 
    Jsize[1] = (int)Jsize_d[1]; 
    Jsize[2] = (int)Jsize_d[2]; 
	
    ThreadOffset=(int) ThreadID[0];
	
	compb0= A[2] + Imean[0];
	compb1= A[5] + Imean[1];

    
    /*  Loop through all image pixel coordinates */
    for (y=ThreadOffset; y<Jsize[1]; y=y+Nthreads)
    {
		yd=(double)y-Jmean[1];
		compa0 = A[1] *yd + compb0;
		compa1 = A[4] *yd + compb1;

        for (x=0; x<Jsize[0]; x++)
        {
            xd=(double)x-Jmean[0];
            Tlocalx =  A[0] * xd + compa0;
            Tlocaly =  A[3] * xd + compa1;

            /* interpolate the intensities */
            interpolate_2d_double_color(Ipixel,Tlocalx, Tlocaly, Isize, Iin,cubic,black); 
            
            /* Set the current pixel value */
            indexI=mindex2(x,y,Jsize[0]);
            for (rgb=0; rgb<3; rgb++)
            {
                Iout[indexI+rgb*Jsize[0]*Jsize[1]]=Ipixel[rgb];
            }
        }
    }
   
    /*  explicit end thread, helps to ensure proper recovery of resources allocated for the thread */
    #ifdef _WIN32
	_endthreadex( 0 );
    return 0;
	#else
	pthread_exit(NULL);
	#endif
}
voidthread transformvolume_color(double **Args) {

    /* I is the input image, Iout the transformed image  */
    /* Tx and Ty images of the translation of every pixel. */
    double *Iin, *Iout, *Tx, *Ty;
    double *Nthreadsd;
    int Nthreads;
	/*  if one outside pixels are set to zero. */
	double  *moded;
	int mode=0;
	
	/* Output image size */
    double *ImageSize_d;
    int ImageSize[3];
	
    /* 2D index storage */
    int indexI;
    
    /* Size of input image */
    int Isize[3]={0,0,0};
    double *Isize_d;
    
    /* Location of translated pixel */
    double Tlocalx;
    double Tlocaly;
    
    /* Cubic and outside black booleans */
    bool black, cubic;

    /* loop throught the colors r,g,b */
    int rgb=0;
    
    /* Current voxel/pixel */
    double Ipixel[3]={0,0,0};
    
    /* offset */
    int offset=0;
    
    /* The thread ID number/name */
    double *ThreadID;
    
    /* X,Y coordinates of current pixel */
    int x,y;
    
    Iin=Args[0];
    Iout=Args[1];
    Tx=Args[2];
    Ty=Args[3];
    Isize_d=Args[4];
    ThreadID=Args[5];
	moded=Args[6]; mode=(int) moded[0];
    Nthreadsd=Args[7];  Nthreads=(int)Nthreadsd[0];
	ImageSize_d=Args[8];
		
    if(mode==0||mode==2){ black = false; } else { black = true; }
    if(mode==0||mode==1){ cubic = false; } else { cubic = true; }
    
    Isize[0]=(int)Isize_d[0];
    Isize[1]=(int)Isize_d[1];
    Isize[2]=(int)Isize_d[2];
        
	ImageSize[0] = (int)ImageSize_d[0]; 
    ImageSize[1] = (int)ImageSize_d[1]; 
    ImageSize[2] = (int)ImageSize_d[2]; 
	
    offset=(int) ThreadID[0];
	
    /*  Loop through all image pixel coordinates */
    for (y=offset; y<ImageSize[1]; y=y+Nthreads)
    {
        for (x=0; x<ImageSize[0]; x++)
        {
		    indexI=mindex2(x,y,ImageSize[0]);
            Tlocalx=((double)x)+Tx[indexI];
            Tlocaly=((double)y)+Ty[indexI];
            
            /* interpolate the intensities */
            interpolate_2d_double_color(Ipixel,Tlocalx, Tlocaly, Isize, Iin,cubic,black);
         
            /* Set the current pixel value */
   
            for (rgb=0; rgb<3; rgb++)
            {
                Iout[indexI+rgb*ImageSize[0]*ImageSize[1]]=Ipixel[rgb];
            }
        }
    }

    /*  explicit end thread, helps to ensure proper recovery of resources allocated for the thread */
	EndThread;
}