9 require './ctsim.conf';
12 $ENV{'PATH'} = "$::bindir:$::lamrundir";
14 my $fromhost = $ENV{'REMOTE_HOST'};
16 my $gmt_start = time();
24 # Phantom_Name, Phantom_Nx, Phantom_Ny, Phantom_NSample
25 # PJ_NDet, PJ_NRot, PJ_NRay, PJ_RotAngle,
26 # IR_Nx, IR_Ny, IR_Filter, IR_Filter_Param
30 my $Phantom_Name = FilterMetaChars($in{'Phantom_Name'});
31 my $Phantom_Nx = FilterToNumber($in{'Phantom_Nx'});
32 my $Phantom_Ny = FilterToNumber($in{'Phantom_Ny'});
33 my $Phantom_NSample = FilterToNumber($in{'Phantom_NSample'});
34 $error .= "Phantom name must not be blank<br>" if ($Phantom_Name eq "");
35 $error .= "Phantom NX and NY must be between 5 and 1024<br>" if ($Phantom_Nx < 5 || $Phantom_Nx > 1024 || $Phantom_Ny < 5 || $Phantom_Ny > 1024);
36 $error .= "Phantom NSample must be between 1 and 10<br>" if ($Phantom_NSample < 1 || $Phantom_NSample > 10);
38 my $PJ_NDet = FilterToNumber($in{'PJ_NDet'});
39 my $PJ_NRot = FilterToNumber($in{'PJ_NRot'});
40 my $PJ_NRay = FilterToNumber($in{'PJ_NRay'});
41 my $PJ_RotAngle = FilterToNumber($in{'PJ_RotAngle'});
42 $error .= "Projection NDet must be between 5 and 1800<br>" if ($PJ_NDet < 5 || $PJ_NDet > 1800);
43 $error .= "Projection NRot must be between 5 and 2048<br>" if ($PJ_NRot < 5 || $PJ_NRot > 2048);
44 $error .= "Projection RotAngle must be between 0.1 and 2<br>" if ($PJ_RotAngle < 0.1 || $PJ_RotAngle > 2);
46 #my $IR_Nx = FilterToNumber($in{'IR_Nx'});
47 #my $IR_Ny = FilterToNumber($in{'IR_Ny'});
48 my $IR_Nx = $Phantom_Nx;
49 my $IR_Ny = $Phantom_Ny;
50 my $IR_Filter = FilterMetaChars($in{'IR_Filter'});
51 my $IR_Filter_Param = FilterToNumber($in{'IR_Filter_Param'});
52 my $IR_Interp = FilterMetaChars($in{'IR_Interp'});
53 my $IR_Backproj = FilterMetaChars($in{'IR_Backproj'});
55 my $Disp_Min = "auto";
56 my $Disp_Max = "auto";
57 $Disp_Min = FilterToNumber($in{'Disp_Min'}) if ($in{'Disp_Min'} ne "auto" && $in{'Disp_Min'} ne "");
58 $Disp_Max = FilterToNumber($in{'Disp_Max'}) if ($in{'Disp_Max'} ne "auto" && $in{'Disp_Max'} ne "");
59 if ($Disp_Min ne 'auto' && ! ($Disp_Min =~ /^[\d\.\-]+$/)) {
60 $error .= "Display Minimum must be 'auto' or numeric (received $Disp_Min) <br>";
62 if ($Disp_Max ne 'auto' && ! ($Disp_Max =~ /^[\d\.\-]+$/)) {
63 $error .= "Display Maximum must be 'auto' or numeric (received $Disp_Max) <br>";
66 my $MPI_Str = FilterMetaChars($in{'MPI'});
68 $MPI = 1 if ($MPI_Str eq "yes" && $::mpi_enable ne "");
70 $error .= "IR Nx and Ny must be between 5 and 1024<br>" if ($IR_Nx < 5 || $IR_Nx > 1024 || $IR_Ny < 5 || $IR_Ny > 1024);
71 $error .= "IR Filter Parameter must be between 0 and 1<br>" if ($IR_Filter_Param < 0 || $IR_Filter_Param > 1);
75 my $auto_window_img = "std0.1";
76 my $auto_window_diff = "std1";
77 my $auto_window_pj = "full";
78 my $logfile = "$::jobdir/ctsim.log";
80 my $result_fname = "$::datadir/result-$tmpid.html";
81 my $phantom_fname = "$::datadir/phantom-$tmpid.if";
82 my $pj_fname = "$::datadir/pj-$tmpid.pj";
83 my $ir_fname = "$::datadir/ir-$tmpid.if";
84 my $pj_if_fname = "$::datadir/pj-$tmpid.if";
85 my $diff_fname = "$::datadir/diff-$tmpid.if";
86 my $phantom_png = "$::datadir/phantom-$tmpid.png";
87 my $ir_png = "$::datadir/ir-$tmpid.png";
88 my $pj_png = "$::datadir/pj-$tmpid.png";
89 my $diff_png = "$::datadir/diff-$tmpid.png";
91 my $result_url = "$::url_datadir/result-$tmpid.html";
92 my $phantom_png_url = "$::url_datadir/phantom-$tmpid.png";
93 my $ir_png_url = "$::url_datadir/ir-$tmpid.png";
94 my $pj_png_url = "$::url_datadir/pj-$tmpid.png";
95 my $diff_png_url = "$::url_datadir/diff-$tmpid.png";
97 my $ctrec_ver = "$::bindir/ctrec";
98 my $phm2pj_ver = "$::bindir/phm2pj";
99 my $phm2if_ver = "$::bindir/phm2if";
100 my $diff_ver = "$::bindir/if-2";
101 $ctrec_ver = "/opt/lam/bin/mpirun N N $::lamrundir/ctrec-lam" if $MPI;
102 $phm2pj_ver = "/opt/lam/bin/mpirun N N $::lamrundir/phm2pj-lam" if $MPI;
103 $phm2if_ver = "/opt/lam/bin/mpirun N N $::lamrundir/phm2if-lam" if $MPI;
105 my $gp_cmd = "$phm2if_ver $phantom_fname $Phantom_Nx $Phantom_Ny --phantom $Phantom_Name --nsample $Phantom_NSample";
106 my $pj_cmd = "$phm2pj_ver $pj_fname $PJ_NDet $PJ_NRot --phantom $Phantom_Name --nray $PJ_NRay --rotangle $PJ_RotAngle";
107 my $pj_if_cmd = "$::bindir/pj2if $pj_fname $pj_if_fname";
108 my $ir_cmd = "$ctrec_ver $pj_fname $ir_fname $IR_Nx $IR_Ny --filter $IR_Filter --filter-param $IR_Filter_Param --interp $IR_Interp --backproj $IR_Backproj";
109 my $diff_cmd = "$diff_ver $phantom_fname $ir_fname $diff_fname --comp";
111 my $window_options = "--auto $auto_window_img";
112 if ($Disp_Min ne 'auto') {
113 $window_options .= " --min $Disp_Min";
115 if ($Disp_Max ne 'auto') {
116 $window_options .= " --max $Disp_Max";
119 my $png1_cmd = "$::bindir/if2img $phantom_fname $phantom_png $window_options --stats --format png";
120 my $png2_cmd = "$::bindir/if2img $ir_fname $ir_png $window_options --stats --format png";
121 my $png3_cmd = "$::bindir/if2img $pj_if_fname $pj_png --auto $auto_window_pj --stats --format png";
122 my $png4_cmd = "$::bindir/if2img $diff_fname $diff_png --auto $auto_window_diff --stats --format png";
124 my $title = "CT Simulation Results";
127 $out .= "<HTML> <HEAD><TITLE> $title </TITLE></HEAD>\n";
128 $out .= "<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\" VLINK=\"#800020\" LINK=\"#0000FF\">\n";
129 $out .= "<H1>$title</H1><HR>\n";
132 $out .= "<H2>Commands</H2>\n";
133 $out .= "$gp_cmd<br>\n$pj_cmd<br>\n$pj_if_cmd<br>\n$ir_cmd<br>\n$diff_cmd<br>\n$png1_cmd<br>\n$png2_cmd<br>\n" .
134 "$png3_cmd<br>\n$png4_cmd<br>\n";
139 $out .= "<FONT COLOR=\"#FF0000\">The following errors were present in your request.<br>\n";
140 $out .= "Please correct them and try submitting your request again.</FONT><br>\n";
141 $out .= "<i>$error</i>";
153 if (-s $phantom_fname) {
154 $pj_out .= `$pj_cmd`;
155 $png_gp_out .= `$png1_cmd`;
157 $pj_if_out .= `$pj_if_cmd`;
158 $png_pj_out .= `$png3_cmd`;
159 $ir_out .= `$ir_cmd`;
161 $png_ir_out .= `$png2_cmd`;
162 $diff_out .= `$diff_cmd`;
163 $png_diff_out .= `$png4_cmd`;
168 $cmdout = "$gp_cmd\n $gp_out $pj_cmd\n $pj_out $pj_if_cmd\n $pj_if_out $ir_cmd\n $ir_out $diff_cmd\n $diff_out $png1_cmd\n $png_gp_out $png2_cmd\n $png_ir_out $png3_cmd\n $png_pj_out $png4_cmd\n $png_diff_out";
169 if (open(LOGFILE,">> $logfile")) {
170 flock(LOGFILE,LOCK_EX);
172 print LOGFILE "Job $tmpid\n";
173 print LOGFILE $cmdout;
174 print LOGFILE "----------------------------------------------------\n";
175 flock(LOGFILE,LOCK_UN);
179 $execution_time = $gmt_end - $gmt_start;
181 $out .= "<H3>Command Output</H3>$cmdout<HR>\n";
183 my $png_gp_out_html = $png_gp_out;
184 my $png_ir_out_html = $png_ir_out;
185 my $png_pj_out_html = $png_pj_out;
186 my $png_diff_out_html = $png_diff_out;
187 $png_gp_out_html =~ s/\n/<br>/gms;
188 $png_ir_out_html =~ s/\n/<br>/gms;
189 $png_pj_out_html =~ s/\n/<br>/gms;
190 $png_diff_out_html =~ s/\n/<br>/gms;
191 $out .= "<TABLE><TR><TD>Phantom Image</TD><TD>Reconstructed Image</TD></TR>\n";
192 $out .= "<TR><TD><IMG SRC=\"$phantom_png_url\"><br><FONT SIZE=1>$png_gp_out</FONT></TD>\n";
193 $out .= "<TD><IMG SRC=\"$ir_png_url\"><br><FONT SIZE=1>$png_ir_out</FONT></TD></TR>\n";
194 $out .= "<TR><TD>Projection Sinusoid</TD><TD>Phantom/Reconst Error</TD></TR>\n";
195 $out .= "<TR><TD><IMG SRC=\"$pj_png_url\"><br><FONT SIZE=1>$png_pj_out</FONT></TD>\n";
196 $out .= "<TD><IMG SRC=\"$diff_png_url\"><br><FONT SIZE=2>$diff_out</FONT><br><FONT SIZE=1>$png_diff_out</FONT></TD></TR>\n";
198 $out .= "Execution time: $execution_time seconds\n";
202 $out .= "Return to <A HREF=\"/ctsim/index.html\">CT Simulation Designer</a>.<br>\n";
203 $out .= "Return to <A HREF=\"www.med-info.com\">Med-Info</a>.\n";
204 $out .= "</BODY> </HTML>";
207 if (open(OUTFILE,"> $result_fname"))
209 flock(OUTFILE,LOCK_EX);
211 flock(OUTFILE,LOCK_UN);
213 print "Location: $result_url\n\n";
217 print "Content-type: text/plain\n\n";
218 print "The simulator was unable to create an result file.\n";
220 if (open(JOBFILES,"> $::jobdir/$tmpid"))
222 flock(JOBFILES,LOCK_EX);
223 print JOBFILES "gmt_start=$gmt_start\n";
224 print JOBFILES "gmt_end=$gmt_end\n";
225 print JOBFILES "execution_time=$execution_time\n";
226 print JOBFILES "Phantom_Name=$Phantom_Name\n";
227 print JOBFILES "Phantom_Nx=$Phantom_Nx\n";
228 print JOBFILES "Phantom_Ny=$Phantom_Nx\n";
229 print JOBFILES "Phantom_NSample=$Phantom_NSample\n";
230 print JOBFILES "PJ_NDet=$PJ_NDet\n";
231 print JOBFILES "PJ_NRot=$PJ_NRot\n";
232 print JOBFILES "PJ_NRay=$PJ_NRay\n";
233 print JOBFILES "PJ_RotAngle=$PJ_RotAngle\n";
234 print JOBFILES "IR_Nx=$IR_Nx\n";
235 print JOBFILES "IR_Ny=$IR_Ny\n";
236 print JOBFILES "IR_Interp=$IR_Interp\n";
237 print JOBFILES "IR_Filter=$IR_Filter\n";
238 print JOBFILES "IR_Filter_Param=$IR_Filter_Param\n";
239 print JOBFILES "IR_Backproj=$IR_Backproj\n";
240 print JOBFILES "Disp_Min=$Disp_Min\n";
241 print JOBFILES "Disp_Max=$Disp_Max\n";
242 print JOBFILES "MPI=$MPI\n";
243 print JOBFILES "Files=$result_fname,$phantom_fname,$pj_fname,$ir_fname,$phantom_png,$ir_png,$pj_if_fname,$pj_png\n" if ($error eq "");
244 printf JOBFILES "cmdout=$cmdout\n";
245 flock(JOBFILES,LOCK_UN);
256 $out .= "<H1>Internal error</H1>
257 Please notify <A HREF=mailto:webmaster\@med-info.com>webmaster\@med-info.com</A>
265 # "Content: text/html\n\n";
279 $var =~ /^(\-*\d*\.*\d*)$/;