STIR 6.4.0
SPECTUB_Tools.h
1/*
2 Copyright (c) 2013, Biomedical Image Group (GIB), Universitat de Barcelona, Barcelona, Spain.
3 Copyright (c) 2013, University College London
4 This file is part of STIR.
5
6 SPDX-License-Identifier: Apache-2.0
7
8 See STIR/LICENSE.txt for details
9
10 \author Carles Falcon
11*/
12
13#ifndef _WM_SPECTUB_H
14#define _WM_SPECTUB_H
15
16#include <string>
17#include <vector>
18
19namespace SPECTUB
20{
21
22//::: srtuctures ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
23
25typedef struct
26{
27 int num; // number of collimator (see weight_64.cpp for options)
28 bool do_fb; // true: fanbeam collimator || false: parallel collimator
29
30 //... parallel collimator parameters .....................
31
32 float A; // linear factor for dependency of sigma on distance: sigma=A*dist+B (parallel, fanbeam-vertical)
33 float B; // independent factor for dependency of sigma on distance: sigma=A*dist+B (parallel, fanbeam-vertical)
34
35 //... fanbeam collimator parameters ......................
36
37 float F; // Focal length (fanbeam)
38 float L; // collimator to detector distance (?) (fanbeam)
39 float A_h; // linear factor for dependency of sigma on distance (fanbeam horizontal)
40 float A_v; // linear factor for dependency of sigma on distance (fanbeam horizontal)
41 float D; // collimator thicknes?? (fanbeam)
42 float w; // collimator thickness (?) (fanbeam)
43 float insgm; // intrinsic sigma (cristal resolution) (fanbeam)
44
46
48typedef struct
49{
50 int Nrow; // number of rows
51 int Ncol; // number of columns
52 int Nsli; // number of slices
53 int Npix; // number of pixels (axial planes)
54 int Nvox; // number of voxels (the whole volume)
55
56 int first_sl; // first slice to reconstruct (0->Nslic-1)
57 int last_sl; // last slice to reconstruct + 1 (end of the 'for' loop) (1->Nslic)
58
59 float Nrowd2; // half of Nrow
60 float Ncold2; // half of Ncol
61 float Nslid2; // half of Nsli
62
63 float Xcmd2; // Half of the size of the volume, dimension x (cm);
64 float Ycmd2; // Half of the size of the volume, dimension y (cm);
65 float Zcmd2; // Half of the size of the volume, dimension z (cm);
66
67 float szcm; // voxel size (side length in cm)
68 float thcm; // voxel thickness (cm)
69
70 float x0; // x coordinate (cm, ref center of volume) of the first voxel
71 float y0; // y coordinate (cm, ref center of volume) of the first voxel
72 float z0; // z coordinate (cm, ref center of volume) of the first voxel
73
74 float* val; // array of values
75
77
79typedef struct
80{
81 int Nbin; // length of the detection line in bins (number of bins per line)
82 float lngcm; // length of the detection line in cm.
83 float szcm; // bin size in cm
84
85 int Nsli; // number of slices
86 float thcm; // slice thickness in cm
87
88 int Nang; // number of projection angles
89 std::vector<float> angles; // projection angles. degrees from upper detection plane (parallel to table). Negative for CW
90 // rotations (see manual)
91
92 int NOS; // number of subsets in which to split the matrix
93 int NangOS; // Number of angles in each subset = Nang/NOS
94 int Nbp; // number of bins in a 2D projection=lng*Nsli
95 int Nbt; // total number of bins= Nbp*Nang
96 int NbOS; // total number of bins per subset= Nbp*NangOS = Nbt/NOS
97 int* order; // order of the angles of projection (array formed by indexs of angles belonging to consecutive subsets)
98
99 float Nbind2; // length of the detection line (in bins) divided by 2
100 float lngcmd2; // length of the detection line in cm divided by 2
101 float Nslid2; // number of slices divided by 2
102
103} proj_type;
104
106typedef struct
107{
108 int subset_ind; // subset index of this matrix (-1: all subsets in a single file)
109 int* index; // included angles into this subset (index. Multiply by increm to get corresponding angles in degrees)
110
111 float* Rrad; // Rotation radius (one value for each projection angle)
112 float min_w; // minimum weight to be taken into account
113 float psfres; // spatial resolution of continous distributions in PSF calculation
114 float maxsigm; // maximum number of sigmas in PSF calculation
115
116 bool fixed_Rrad; // true: fixed radius of projection || false: variable radius of projection
117 bool do_psf; // true: to correct for PSF || false: do not correct for PSF
118 bool do_psf_3d; // true: 3d correction for PSF || false: 2d correction for PSF
119 bool predef_col; // true: predefined collimator || false: user defined PSF parametres
120 bool do_att; // true: to correct for attenuation || false: do not correct for attenuation
121 bool do_full_att; // true: diff att for each PSF bin || false: the whole PSF has the same att. factor (central line)
122 bool do_msk; // true: weights just inside msk || false: weights for the whole FOV
123 bool do_msk_slc; // true: weights for several slices || false: weights for all slices
124 bool do_msk_cyl; // true: to use cylinder as a mask || false: not to use cylinder as a mask
125 bool do_msk_att; // true: to use att map as a mask || false: not to use att map as a mask
126 bool do_msk_file; // true: explicit mask || false: not to use explicit mask
127
128 std::string att_fn; // attenuation map filename
129 std::string msk_fn; // explicit mask filename
130 std::string col_fn; // collimator parameters filename
131 std::string Rrad_fn; // rotation radius file name
132
133 volume_type vol; //
134 proj_type prj; //
135 collim_type COL; // collimator structure (see weight3d_64b.cpp for options)
136
137} wmh_type;
138
140typedef struct
141{
142 // weight matrix dimensions
143
144 int ne; // nonzero elements
145 int NbOS; // dimension 1 (rows) of the weight matrix (NbOS or NBt)
146 int Nvox; // dimension 2 (columns) of the weight matrix (Nvox)
147
148 // weight matrix values
149
150 float* ar; // array of nonzero elements of weight matrix (by rows)
151 int* ja; // array of the column index of the above elements
152 int* ia; // array containing the indexes of the previous vector where a row change happens
153
154 bool do_save_wmh; // to save or not to save weight_mat header info into weight_mat file
155
156} wm_type;
157
159typedef struct
160{
161 int NbOS; // dimension 1 (rows) of the weight matrix (NbOS or NBt)
162 int Nvox; // dimension 2 (columns) of the weight matrix (Nvox)
163 float** val; // double array to store weights (index of the projection element, number of weight for that element)
164 int** col; // double array to store column indexs of the above element (index of the projection element, number of weight for
165 // that element)
166 int* ne; // array indicating how many elements has been stored for each element of projection
167
168 //... filename .............................................
169
170 std::string fn; // matrix base name (filename without extension index)
171 std::string OSfn; // matrix filename
172 std::string fn_hdr; // matrix header file name
173
174 //... indexs for STIR format ...............................
175
176 int *na, *nb, *ns; // indexs for projection elements (angle, bin, slice respec.)
177 short int *nx, *ny, *nz; // indexs for image elements (x,y,z)
178
179 //... format ...............................................
180
181 bool do_save_wmh; // to save or not to save weight_mat header info into weight_mat file
182 bool do_save_STIR; // to save weight matrix with STIR format
183
184} wm_da_type;
185
187typedef struct
188{
189 int lng; // length (in discretization intervals) (odd number)
190 int lngd2; // half of the length (in discretization intervals) (lng-1)/2
191 float res; // spatial resolution of distfunc (discretization interval)
192 float* val; // array of values
193 float* acu; // distribution function values (cumulative sum)
194
196
198typedef struct
199{
200 int maxszb; // maximum size in bins (for allocation purposes)
201
202 int di; // discretization interval (to reduce spatial resolution to bin resolution). (int: #points)
203 int* ind; // projection indexs for the bins of the PSF (horizontal)
204 int Nib; // actual number of bins forming the PSF (length of PSF in bins)
205
206 float sgmcm; // sigma of the PSF in cm
207 float lngcm; // length of PSF (in cm)
208 float lngcmd2; // half of the length of PSF (in cm)
209 float* val; // array of values
210 float efres; // effective resolution (psfres rescaled to real psf length)
211
212} psf1d_type;
213
215typedef struct
216{
217 int maxszb_h; // maximum size in bins horizontal (for allocation purposes)
218 int maxszb_v; // maximum size in bins vertical (for allocation purposes)
219 int maxszb_t; // maximum size in bins total (for allocation purposes)
220
221 int* ib; // projection indexs for the bins of the PSF (horizontal)
222 int* jb; // projection indexs for the bins of the PSF (vertical)
223 int Nib; // actual number of bins forming the PSF (length of PSF in bins)
224
225 float* val; // array of values
226
228
230typedef struct
231{
232 int ind; // index of angle considering the whole set of projections (sequential order: 0->Nang-1)
233 int indOS; // index of angle considering the subjet
234 int iOS_proj; // index of the first bin for this angle (in subset of projections)
235
236 float cos; // coninus of the angle
237 float sin; // sinus of the angle
238
239 // parametres for describng the trapezoidal projection of a square voxel
240
241 float p; // plateau higness
242 float m; // slope of the trapezoid
243 float n; // independent term of the slope
244 int N1; // index of the first vertice (end of plateau) in DX units
245 int N2; // index of the second vertice (end of the slope) in DX units
246 discrf_type vxprj; // projection of a square voxel in this direction (for no PSF)
247
248 // variable rotation radius
249
250 float Rrad; // rotation radius for this angle
251
252 // first bin position and increments
253
254 float xbin0; // x coordinate for the first bin of the detection line corresponding to this angle
255 float ybin0; // y coordinate for the first bin of the detection line corresponding to this angle
256 float incx; // increment in x to the following bin in detection line
257 float incy; // increment in y to the following bin in detection line
258
259} angle_type;
260
262typedef struct
263{
264 float szcm; // voxel size (side length in cm)
265 float thcm; // voxel thickness (cm)
266
267 int irow; // row index
268 int icol; // column index
269 int islc; // slice index
270 int ip; // in plane index (considering the slice as an array) of the voxel
271 int iv; // volume index (considering the volume as an array) of the voxel
272
273 float x; // x coordinate (cm, ref center of volume)
274 float y; // y coordinate (cm, ref center of volume)
275 float z; // z coordinate (cm, ref center of volume)
276 float x1; // x coordinade in rotated framework
277
278 float dv2dp; // distance from voxel to detection plane
279 float costhe; // cosinus of theta (angle between focal-voxel line and line perpendicular to detection plane) (fanbeam)
280 float xdc; // distance (cm over detection line) from projected voxel to the center of the detection line
281 float xd0; // distance (cm over detection line) from projected voxel to the begin of the detection line
282 float zd0; // distance (cm) to the lowest plane of the volume
283
284} voxel_type;
285
287typedef struct
288{
289 float szcm; // bin size (cm)
290 float szcmd2; // half of the above value
291 float thcm; // bin thickness (cm)
292 float thcmd2; // bin thickness (cm)
293
294 float x; // x coordinate (cm, ref center of volume)
295 float y; // y coordinate (cm, ref center of volume)
296 float z; // z coordinate (cm, ref center of volume)
297
298 float szdx; // bin size in resolution units
299 float thdx; // bin thickness in resolution units
300
301} bin_type;
302
304typedef struct
305{
306 float* dl; // distance of attenuation path on each crossed voxel of the attenuation map
307 int* iv; // in-plane index (considering slices of attmap as an array) of any crossed voxel of the attenuation map
308 int lng; // number of elements in the attenuation path
309 int maxlng; // maximum number of elements in the attenuation path (for allocation)
310
312
313//::: functions :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
314
315//... functions from wmtools_SPECT.cpp .........................................
316
317void index_calc(int* indexs, const wmh_type& wmh); // to calculate projection index order in subsets
318
319//
320// void col_params ( collim_type *COL ); // to fill collimator structure
321
322void fill_ang(angle_type* ang, const wmh_type& wmh, const float* Rrad); // to fill angle structure
323
324void generate_msk(bool* msk_3d,
325 bool* msk_2d,
326 const float* att,
327 const volume_type* vol,
328 const wmh_type& wmh); // to create a boolean mask for wm (no weights outside the msk)
329
330int max_psf_szb(const angle_type* ang, const wmh_type& wmh);
331
332float calc_sigma_h(voxel_type vox, collim_type COL);
333
334float calc_sigma_v(voxel_type vox, collim_type COL);
335
336void free_wm(wm_type* f); // to free weight_mat
337
338void free_wm_da(wm_da_type* f); // to free weight_mat_da
339
340} // namespace SPECTUB
341
342#endif //_WM_SPECT_H
Namespace for the SPECT library from University of Barcelona.
Definition SPECTUB_Tools.h:20
structure to store angles values, indices and ratios
Definition SPECTUB_Tools.h:231
structure for attenuation calculus
Definition SPECTUB_Tools.h:305
structure for bin information
Definition SPECTUB_Tools.h:288
collimator parameters structure
Definition SPECTUB_Tools.h:26
structure for distribution function information
Definition SPECTUB_Tools.h:188
structure for projection information
Definition SPECTUB_Tools.h:80
structure for PSF information
Definition SPECTUB_Tools.h:199
structure for distribution function information
Definition SPECTUB_Tools.h:216
structure for bin information
Definition SPECTUB_Tools.h:49
structure for voxel information
Definition SPECTUB_Tools.h:263
weight_mat_da structure definition. Structure for generating weight matrix
Definition SPECTUB_Tools.h:160
weight_mat structure definition. Structure for reading weight matrix
Definition SPECTUB_Tools.h:141
complementary information (matrix header)
Definition SPECTUB_Tools.h:107