8#include "tpcclibConfig.h"
27static char *info[] = {
28 "Simulate dynamic PET image plane with background activity surrounding",
29 "a circular object that is assumed to be extending across image planes",
30 "such as abdominal aorta. Spill-over and spill-in effects can be simulated",
31 "by Gaussian 2D smoothing, or by using method based on Germano et al ",
32 "JNM 1992; 33: 613-620, which is only valid for vessels with very large",
33 "diameter. To simulate the circular vessel correctly in 2D image matrix use",
34 "the equations in Brix et al Nuklearmedizin 2002;41:184-190 instead;",
35 "however, that would require numerical solution to double integrals",
37 "Usage: @P [Options] bloodfile bkgfile image",
40 " -dim=<Image x and y dimension in pixels>",
41 " Set image dimension; by default 128.",
42 " -pxlsize=<Voxel size (mm)>",
43 " Set image voxel size; by default 1 mm.",
44 " -diameter=<Vessel diameter (mm)>",
45 " Set vessel diameter; by default 25 mm; vessel border is simulated",
46 " by simple cutoff, thus diameter should be several pixels.",
48 " Set image resolution; by default 8 mm.",
49 " -xpos=<vessel position (mm)>",
50 " Set vessel distance from centre of image; by default 0 mm;",
51 " negative distance moves vessel to the left, positive to the right.",
52 " -ypos=<vessel position (mm)>",
53 " Set vessel distance from centre of image; by default 0 mm",
54 " negative distance moves vessel upwards, positive downwards.",
55 " -gaussian | -bar | -nopve",
56 " Select the spill-over and spill-in simulation method; by default",
57 " no PVE simulation. ",
61 " @P blood.tac background.tac vessel.v",
63 " @P -fwhm=4.3 -diameter=7 -pxlsize=2.3 blood.tac background.tac vessel.v",
65 "See also: fvar4tac, imgfiltg, imgadd, imgcalc, simcirc, simimyoc, flat2img",
67 "Keywords: simulation, image, software testing, vessel, input",
86int main(
int argc,
char **argv)
88 int ai, help=0, version=0, verbose=1;
90 char blofile[FILENAME_MAX], bkgfile[FILENAME_MAX], imgfile[FILENAME_MAX];
94 double pxlsize=1.0, diameter=25.0, fwhm=8.0, xpos=0.0, ypos=0.0;
96 float zoom=1.41421356;
106 if(argc==1) {
tpcPrintUsage(argv[0], info, stderr);
return(1);}
107 blofile[0]=bkgfile[0]=imgfile[0]=(char)0;
109 for(ai=1; ai<argc; ai++)
if(*argv[ai]==
'-') {
111 cptr=argv[ai]+1;
if(*cptr==
'-') cptr++;
if(cptr==NULL)
continue;
112 if(strncasecmp(cptr,
"DIM=", 4)==0) {
114 }
else if(strncasecmp(cptr,
"PXLSIZE=", 8)==0) {
116 }
else if(strncasecmp(cptr,
"DIAMETER=", 9)==0) {
118 }
else if(strncasecmp(cptr,
"FWHM=", 5)==0) {
120 }
else if(strncasecmp(cptr,
"XPOS=", 5)==0) {
122 }
else if(strncasecmp(cptr,
"YPOS=", 5)==0) {
124 }
else if(strncasecmp(cptr,
"NOPVE", 2)==0) {
126 fprintf(stderr,
"Error: invalid combination of simulation options.\n");
129 pve_method=-1;
continue;
130 }
else if(strcasecmp(cptr,
"BAR")==0) {
132 fprintf(stderr,
"Error: invalid combination of simulation options.\n");
135 pve_method=0;
continue;
136 }
else if(strcasecmp(cptr,
"GAUSSIAN")==0) {
138 fprintf(stderr,
"Error: invalid combination of simulation options.\n");
141 pve_method=1;
continue;
143 fprintf(stderr,
"Error: invalid option '%s'.\n", argv[ai]);
148 if(help==2) {
tpcHtmlUsage(argv[0], info,
"");
return(0);}
153 if(ai<argc) {
strlcpy(blofile, argv[ai], FILENAME_MAX); ai++;}
154 if(ai<argc) {
strlcpy(bkgfile, argv[ai], FILENAME_MAX); ai++;}
155 if(ai<argc) {
strlcpy(imgfile, argv[ai], FILENAME_MAX); ai++;}
156 if(ai<argc) {fprintf(stderr,
"Error: too many arguments.\n");
return(1);}
160 fprintf(stderr,
"Error: missing command-line argument; use option --help\n");
166 printf(
"blofile := %s\n", blofile);
167 printf(
"bkgfile := %s\n", bkgfile);
168 printf(
"imgfile := %s\n", imgfile);
169 printf(
"dim := %d\n", dim);
170 printf(
"pxlsize := %g\n", pxlsize);
171 printf(
"diameter := %g\n", diameter);
172 printf(
"fwhm := %g\n", fwhm);
173 printf(
"xpos := %g\n", xpos);
174 printf(
"ypos := %g\n", ypos);
175 printf(
"pve_method := %d\n", pve_method);
183 if(verbose>1) printf(
"reading blood TAC\n");
185 fprintf(stderr,
"Error in reading '%s': %s\n", blofile,
dfterrmsg);
189 fprintf(stderr,
"Error: blood data contains more than one curve.\n");
192 if(verbose>1) printf(
"reading background TAC\n");
195 fprintf(stderr,
"Error in reading background TAC: %s\n", tmp);
199 fprintf(stderr,
"Error: background data contains more than one curve.\n");
207 if(verbose>1) printf(
"allocating memory for image data\n");
211 fprintf(stderr,
"Error: cannot allocate memory for image data.\n");
215 if(verbose>2) printf(
"setting image headers\n");
224 for(fi=0; fi<tac.
frameNr; fi++) {
227 img.
start[fi]*=60.; img.
end[fi]*=60.; img.
mid[fi]*=60.;}
237 if(verbose>2) printf(
"vessel_pos := %g,%g\n", cx, cy);
242 fprintf(stderr,
"Error: cannot simulate image (%d).\n", ret);
251 fprintf(stderr,
"Error: cannot simulate PVE (%d).\n", ret);
262 if(verbose>1) printf(
"Writing image file %s ...\n", imgfile);
264 fprintf(stderr,
"Error: %s\n", img.
statmsg);
267 if(verbose>0) printf(
"%s written\n", imgfile);
int atof_with_check(char *double_as_string, double *result_value)
int atoi_with_check(const char *int_as_string, int *result_value)
int dftRead(char *filename, DFT *data)
int imgAllocate(IMG *image, int planes, int rows, int columns, int frames)
void imgEmpty(IMG *image)
int imgWrite(const char *fname, IMG *img)
int imgGaussianFIRFilter(IMG *img, float xsd, float ysd, float zsd, double tolerance, int verbose)
int imgSetScanner(IMG *img, int scanner_type)
int imgSetUnit(IMG *img, char *unit)
Header file for libtpccurveio.
Header file for libtpcidi.
int idiSimulateTubeImgPlane(int simmet, IMG *img, int zi, double cx, double cy, double r, double FWHM, double *cbkg, double *cblo)
Header file for libtpcimgio.
Header file for libtpcimgp.
Header file for libtpcmisc.
int tpcProcessStdOptions(const char *s, int *print_usage, int *print_version, int *verbose_level)
size_t strlcpy(char *dst, const char *src, size_t dstsize)
int tpcHtmlUsage(const char *program, char *text[], const char *path)
void tpcPrintBuild(const char *program, FILE *fp)
void tpcPrintUsage(const char *program, char *text[], FILE *fp)
Header file for libtpcmodel.
Header file for libtpcmodext.
char studynr[MAX_STUDYNR_LEN+1]
char unit[MAX_UNITS_LEN+1]
char studyNr[MAX_STUDYNR_LEN+1]