/tomo/pyhst

To get this branch, use:
bzr branch http://darksoft.org/webbzr/tomo/pyhst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/* ##  The PyHST program   is Copyright (C) 2002-2008 of the  */
/* ##  European Synchrotron Radiation Facility (ESRF). */

/* ##  You may use, distribute and copy the PyMCA XRF Toolkit under the terms of */
/* ##  GNU General Public License version 3, which is displayed below, or (at your */
/* ##  option) any later version. */

#include<string.h>
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#include<emmintrin.h>

#define FLOAT_TO_INT(in,out)  \
     out=_mm_cvtss_si32(_mm_load_ss(&(in)));
  /*      __asm__ __volatile__ ("fistpl %0" : "=m" (out) : "t" (in) : "st") ; */




#define PEZZO 64

void   cpu_inner(   float *SLICE ,   int num_proj, int  num_bins, float *WORK_perproje , 
		    float axis_position, float *axis_position_s,  float *cos_s, float *sin_s , 
		    float cpu_offset_x,  
		    float cpu_offset_y,
		    int oversampling) ;



int cpu_main(int num_y, int num_x,  float * SLICE, int num_proj, int num_bins, float *WORK_perproje , 
	     float axis_position, float * axis_position_s, float * cos_s, float *sin_s , float cpu_offset_x, float cpu_offset_y,
	     int *minX, int*maxX,
	     int oversampling)
{
  
  int dimx, dimy;
  int nx,ny;
  int X1,X2,Y1,Y2;
  //int ce;
  int ix,iy,jx,jy, pos;
  float * pezzoSLICE;


  nx = ( (int ) (num_x/PEZZO+0.99999))+1;
  ny = ( (int ) (num_y/PEZZO+0.99999))+1;
  dimx=PEZZO*nx;
  dimy=PEZZO*ny;

  pezzoSLICE = (float *) malloc( PEZZO*PEZZO *sizeof(float) );


  for( ix=0; ix<nx; ix++) {
    X1= PEZZO*ix;
    X2=X1+PEZZO;
    if(X2>num_x) X2=num_x;
    for( iy=0; iy<ny; iy++) {
      Y1= PEZZO*iy;
      Y2=Y1+PEZZO;
      if(Y2>num_y) Y2=num_y;

      /* csa: This branch was disabled in Alessandro version, I don't want to remove it
      completely but will prevent minX and maxX computation if it not needed in 
      different places of program. So if this branch is reenabled the minX and maxX
      computation should be as well reenabled in the reconstruction code */
      
      /*
      if (minX&&maxX) {
        int i;
	
        ce=0;
        for(i=Y1; i<Y2; i++) {
	    if( minX[i]<X2 && maxX[i]>X1) {
		ce=1;
		break;
	    }
        }
	
        if(ce==0) continue;
      } else {
        pyhst_warning("minX & maxX are not computed....");
      }
      */


      memset(pezzoSLICE,0, PEZZO*PEZZO*sizeof(float));
      cpu_inner(   pezzoSLICE ,   num_proj,  num_bins, WORK_perproje , 
		    axis_position, axis_position_s,  cos_s, sin_s , 
		    cpu_offset_x+ix*PEZZO,  
		   cpu_offset_y   + iy * PEZZO ,
		   oversampling);
       
      for(jy=Y1; jy<Y2; jy++) {
	pos= jy*num_x+X1;
	for(jx=X1; jx<X2; jx++) {
	  SLICE[ pos] = pezzoSLICE[ PEZZO*(jy-Y1) + (jx-X1)];
	  pos++;
	}
      }
      
    }
  }
  free(pezzoSLICE);
  return 1;
}



void   cpu_inner(   float *SLICE ,   int num_proj, int  num_bins, float *WORK_perproje , 
		    float axis_position, float *axis_position_s,  float *cos_s, float *sin_s , 
		    float cpu_offset_x,  
		    float cpu_offset_y,
		    int oversampling) {


  float  DY;
  float *OVERSAMPLE;

  int j;

  float cos_angle ,sin_angle;



  float increment_position, increment_position_2, increment_position_3;
  float increment_position_4, increment_position_5, increment_position_6;
  float increment_position_7, increment_position_8;
  float slice_positionA, slice_position;
  float axis_position_corr ;
  
  
  int y=0;
  int x_start, x_end,num_xelem ;
  long start_address;
  long  projection, address;
  long  bin,bin1,bin2,bin3;
  long  bin4,bin5,bin6,bin7;

  float  fbin ,fbin1,fbin2,fbin3;
  float  fbin4,fbin5,fbin6,fbin7;

  OVERSAMPLE = WORK_perproje + oversampling*num_bins;
  for(projection=0; projection < num_proj-1; projection++) {
    /* printf(" pro %ld \n", projection); */

    
    
    cos_angle = cos_s[projection];
    sin_angle = sin_s[projection];
    

    increment_position = (float)( cos_angle * (oversampling) );
    increment_position_2 =(float) ( increment_position*2);
    increment_position_3 =(float) ( increment_position*3);
    increment_position_4 = (float)( increment_position*4);
    increment_position_5 = (float)( increment_position*5);
    increment_position_6 = (float)( increment_position*6);
    increment_position_7 = (float)( increment_position*7);
    increment_position_8 = (float)( increment_position*8);
    
    

	
      axis_position_corr = axis_position_s[projection] ; 
      slice_positionA =
	( (float) ( ( (oversampling) * ( axis_position_corr + 
					 (     cpu_offset_x    - 0.5f - axis_position ) * cos_angle - 
					 (     cpu_offset_y    - 0.5f - axis_position ) * sin_angle -0.5f ) 
		      )));
      
      DY = -oversampling *sin_angle;
      
      start_address = 0;      
      for(y   = 0  ; y < PEZZO  ; y++) {

	x_start=0;
	x_end=PEZZO;


	num_xelem = PEZZO;
	
	address = start_address ; 
	j=0;
	
	slice_position=slice_positionA;

	for(; j < PEZZO - 7; j += 8) {
	  
	  fbin = slice_position;
	  fbin1 = slice_position+ increment_position;
	  fbin2 = slice_position+ increment_position_2;
	  fbin3 = slice_position+ increment_position_3;
	  
	  



	  
	  FLOAT_TO_INT(fbin,bin);
	  FLOAT_TO_INT(fbin1,bin1);
	  FLOAT_TO_INT(fbin2,bin2);
	  FLOAT_TO_INT(fbin3,bin3);
	  

	  /* printf("%d %f  %f \n",address , fbin,   OVERSAMPLE[bin] ); */


	  SLICE[address  ] = SLICE[address  ] + OVERSAMPLE[bin]; 
	  SLICE[address+1] = SLICE[address+1] + OVERSAMPLE[bin1]; 
	  SLICE[address+2] = SLICE[address+2] + OVERSAMPLE[bin2]; 
	  SLICE[address+3] = SLICE[address+3] + OVERSAMPLE[bin3];
	  
	  
	  fbin4 = slice_position+ increment_position_4;
	  fbin5 = slice_position+ increment_position_5;
	  fbin6 = slice_position+ increment_position_6;
	  fbin7 = slice_position+ increment_position_7;
	  
	  FLOAT_TO_INT(fbin4,bin4);
	  FLOAT_TO_INT(fbin5,bin5);
	  FLOAT_TO_INT(fbin6,bin6);
	  FLOAT_TO_INT(fbin7,bin7);
	  
	  
	  
	  SLICE[address+4  ] = SLICE[address+4] + OVERSAMPLE[bin4]; 
	  SLICE[address+5  ] = SLICE[address+5] + OVERSAMPLE[bin5]; 
	  SLICE[address+6  ] = SLICE[address+6] + OVERSAMPLE[bin6]; 
	  SLICE[address+7  ] = SLICE[address+7] + OVERSAMPLE[bin7];
	  
	  slice_position = slice_position + increment_position_8;
	  address += 8;
	}      
	slice_positionA=slice_positionA+DY;
	start_address=start_address+PEZZO;
      }
      OVERSAMPLE += 3*oversampling*num_bins;

  }
  
  
  
}