X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;ds=inline;f=cgi-bin%2Fctsim.cgi.in;h=49d94357fc7bac7642dfb38a574dd28baac46ca0;hb=06066d9192936b4c4cc69847cd4c1f5aa7017829;hp=7b3d69ee07fff1a7c4b38f2927d2b12c1b12762a;hpb=2a0006ec846e8da055fe002cb1611853dd01270c;p=ctsim.git
diff --git a/cgi-bin/ctsim.cgi.in b/cgi-bin/ctsim.cgi.in
index 7b3d69e..49d9435 100755
--- a/cgi-bin/ctsim.cgi.in
+++ b/cgi-bin/ctsim.cgi.in
@@ -6,9 +6,10 @@ use CGI;
use File::Basename;
use Fcntl ':flock';
+require './ctsim.conf';
+
my $opt_d = 0;
-my $bindir = "@prefix@/bin";
-$ENV{'PATH'} = $bindir;
+$ENV{'PATH'} = "$::bindir:$::lamrundir:/bin";
my $fromhost = $ENV{'REMOTE_HOST'};
@@ -21,31 +22,52 @@ CGI::ReadParse(\%in);
# Incoming variables
# Phantom_Name, Phantom_Nx, Phantom_Ny, Phantom_NSample
-# RS_NDet, RS_NRot, RS_NRay, RS_RotAngle,
+# PJ_NDet, PJ_NRot, PJ_NRay, PJ_RotAngle,
# IR_Nx, IR_Ny, IR_Filter, IR_Filter_Param
my $error = "";
+if ($::single_process_only > 0) {
+ my @processes = `/bin/ps -A`;
+ my $running = 0;
+ foreach my $p (@processes) {
+ if ($p =~ m/ctsimtext/) {
+ $error .= "Another online simulation is currently running.
You may wait a moment and then click your browser's Refresh button to resubmit your simulation
";
+ last;
+ }
+ }
+}
+
my $Phantom_Name = FilterMetaChars($in{'Phantom_Name'});
my $Phantom_Nx = FilterToNumber($in{'Phantom_Nx'});
my $Phantom_Ny = FilterToNumber($in{'Phantom_Ny'});
+my $Phantom_ViewRatio = FilterToNumber($in{'Phantom_ViewRatio'});
my $Phantom_NSample = FilterToNumber($in{'Phantom_NSample'});
$error .= "Phantom name must not be blank
" if ($Phantom_Name eq "");
-$error .= "Phantom NX and NY must be between 5 and 1024
" if ($Phantom_Nx < 5 || $Phantom_Nx > 1024 || $Phantom_Ny < 5 || $Phantom_Ny > 1024);
-$error .= "Phantom NSample must be between 1 and 10
" if ($Phantom_NSample < 1 || $Phantom_NSample > 10);
-
-my $RS_NDet = FilterToNumber($in{'RS_NDet'});
-my $RS_NRot = FilterToNumber($in{'RS_NRot'});
-my $RS_NRay = FilterToNumber($in{'RS_NRay'});
-my $RS_RotAngle = FilterToNumber($in{'RS_RotAngle'});
-$error .= "Raysum NDet must be between 5 and 1800
" if ($RS_NDet < 5 || $RS_NDet > 1800);
-$error .= "Raysum NRot must be between 5 and 2048
" if ($RS_NRot < 5 || $RS_NRot > 2048);
-$error .= "Raysum RotAngle must be between 0.1 and 2
" if ($RS_RotAngle < 0.1 || $RS_RotAngle > 2);
+$error .= "Phantom Size must be between 5 and 512
" if ($Phantom_Nx < 5 || $Phantom_Nx > 512 || $Phantom_Ny < 5 || $Phantom_Ny > 512);
+$error .= "Phantom NSample must be between 1 and 5
" if ($Phantom_NSample < 1 || $Phantom_NSample > 5);
+$error .= "View Ratio must be between 0 and 100
" if ($Phantom_ViewRatio <= 0 || $Phantom_ViewRatio > 100);
+
+my $PJ_Geometry = FilterMetaChars($in{'PJ_Geometry'});
+my $PJ_NDet = FilterToNumber($in{'PJ_NDet'});
+my $PJ_NRot = FilterToNumber($in{'PJ_NRot'});
+my $PJ_FocalLength = FilterToNumber($in{'PJ_FocalLength'});
+my $PJ_NRay = FilterToNumber($in{'PJ_NRay'});
+my $PJ_RotAngle = FilterToNumber($in{'PJ_RotAngle'});
+my $PJ_ScanRatio = FilterToNumber($in{'PJ_ScanRatio'});
+$error .= "Projection NDet must be between 5 and 1000
" if ($PJ_NDet < 5 || $PJ_NDet > 1000);
+$error .= "Projection NRot must be between 5 and 1000
" if ($PJ_NRot < 5 || $PJ_NRot > 1000);
+$error .= "Projection NRay must be between 1 and 5
" if ($PJ_NRay < 1 || $PJ_NRay > 5);
+$error .= "Projection RotAngle must be between 0.1 and 2
" if ($PJ_RotAngle < 0.1 || $PJ_RotAngle > 2);
+$error .= "Focal length must be between 1.01 and 10" if ($PJ_FocalLength <= 1 || $PJ_FocalLength > 10);
+$error .= "Scan Ratio must be between 0 and 10
" if ($PJ_ScanRatio <= 0 || $PJ_ScanRatio > 10);
#my $IR_Nx = FilterToNumber($in{'IR_Nx'});
#my $IR_Ny = FilterToNumber($in{'IR_Ny'});
my $IR_Nx = $Phantom_Nx;
my $IR_Ny = $Phantom_Ny;
+my $IR_FilterMethod = FilterMetaChars($in{'IR_FilterMethod'});
+my $IR_Zeropad = FilterToNumber($in{'IR_Zeropad'});
my $IR_Filter = FilterMetaChars($in{'IR_Filter'});
my $IR_Filter_Param = FilterToNumber($in{'IR_Filter_Param'});
my $IR_Interp = FilterMetaChars($in{'IR_Interp'});
@@ -55,60 +77,59 @@ my $Disp_Min = "auto";
my $Disp_Max = "auto";
$Disp_Min = FilterToNumber($in{'Disp_Min'}) if ($in{'Disp_Min'} ne "auto" && $in{'Disp_Min'} ne "");
$Disp_Max = FilterToNumber($in{'Disp_Max'}) if ($in{'Disp_Max'} ne "auto" && $in{'Disp_Max'} ne "");
-if ($Disp_Min ne 'auto' && ! ($Disp_Min =~ /^[\d\.]+$/)) {
- $error .= "Display Minimum must be 'auto' or numeric (received '$Disp_Min')
";
+if ($Disp_Min ne 'auto' && ! ($Disp_Min =~ /^[\d\.\-]+$/)) {
+ $error .= "Display Minimum must be 'auto' or numeric (received $Disp_Min)
";
}
-if ($Disp_Max ne 'auto' && ! ($Disp_Max =~ /^[\d\.]+$/)) {
- $error .= "Display Maximum must be 'auto' or numeric (received '$Disp_Max')
";
+if ($Disp_Max ne 'auto' && ! ($Disp_Max =~ /^[\d\.\-]+$/)) {
+ $error .= "Display Maximum must be 'auto' or numeric (received $Disp_Max)
";
}
my $MPI_Str = FilterMetaChars($in{'MPI'});
my $MPI = 0;
-$MPI = 1 if ($MPI_Str eq "yes");
+$MPI = 1 if ($MPI_Str eq "yes" && $::mpi_enable ne "");
$error .= "IR Nx and Ny must be between 5 and 1024
" if ($IR_Nx < 5 || $IR_Nx > 1024 || $IR_Ny < 5 || $IR_Ny > 1024);
$error .= "IR Filter Parameter must be between 0 and 1
" if ($IR_Filter_Param < 0 || $IR_Filter_Param > 1);
-my $jobdir = "@webdatadir@";
my $tmpid = $$;
my $auto_window_img = "std0.1";
my $auto_window_diff = "std1";
-my $auto_window_rs = "full";
-my $datadir = "@webdatadir@";
-my $url_datadir = "@webdataurl@";
-my $logfile = "$jobdir/ctsim.log";
-
-my $result_fname = "$datadir/result-$tmpid.html";
-my $phantom_fname = "$datadir/phantom-$tmpid.sdf";
-my $rs_fname = "$datadir/rs-$tmpid.rs";
-my $ir_fname = "$datadir/ir-$tmpid.sdf";
-my $rs_sdf_fname = "$datadir/rs-$tmpid.sdf";
-my $diff_fname = "$datadir/diff-$tmpid.sdf";
-my $phantom_png = "$datadir/phantom-$tmpid.png";
-my $ir_png = "$datadir/ir-$tmpid.png";
-my $rs_png = "$datadir/rs-$tmpid.png";
-my $diff_png = "$datadir/diff-$tmpid.png";
-
-my $result_url = "$url_datadir/result-$tmpid.html";
-my $phantom_png_url = "$url_datadir/phantom-$tmpid.png";
-my $ir_png_url = "$url_datadir/ir-$tmpid.png";
-my $rs_png_url = "$url_datadir/rs-$tmpid.png";
-my $diff_png_url = "$url_datadir/diff-$tmpid.png";
-
-my $ctrec_ver = "$bindir/ctrec";
-my $phm2rs_ver = "$bindir/phm2rs";
-my $phm2sdf_ver = "$bindir/phm2sdf";
-my $diff_ver = "$bindir/sdf-2";
-$ctrec_ver = "/opt/lam/bin/mpirun N N $bindir/ctrec-mpi" if $MPI;
-$phm2rs_ver = "/opt/lam/bin/mpirun N N $bindir/phm2rs-mpi" if $MPI;
-$phm2sdf_ver = "/opt/lam/bin/mpirun N N $bindir/phm2sdf-mpi" if $MPI;
-
-my $gp_cmd = "$phm2sdf_ver $phantom_fname $Phantom_Nx $Phantom_Ny --phantom $Phantom_Name --nsample $Phantom_NSample";
-my $rs_cmd = "$phm2rs_ver $rs_fname $RS_NDet $RS_NRot --phantom $Phantom_Name --nray $RS_NRay --rotangle $RS_RotAngle";
-my $rs_sdf_cmd = "$bindir/rs2sdf $rs_fname $rs_sdf_fname";
-my $ir_cmd = "$ctrec_ver $rs_fname $ir_fname $IR_Nx $IR_Ny --filter $IR_Filter --filter-param $IR_Filter_Param --interp $IR_Interp --backproj $IR_Backproj";
-my $diff_cmd = "$diff_ver $phantom_fname $ir_fname $diff_fname --comp";
+my $auto_window_pj = "full";
+my $logfile = "$::jobdir/ctsim.log";
+
+my $result_fname = "$::datadir/result-$tmpid.html";
+my $phantom_fname = "$::datadir/phantom-$tmpid.if";
+my $pj_fname = "$::datadir/pj-$tmpid.pj";
+my $ir_fname = "$::datadir/ir-$tmpid.if";
+my $pj_if_fname = "$::datadir/pj-$tmpid.if";
+my $sub_fname = "$::datadir/sub-$tmpid.if";
+my $phantom_png = "$::datadir/phantom-$tmpid.png";
+my $ir_png = "$::datadir/ir-$tmpid.png";
+my $pj_png = "$::datadir/pj-$tmpid.png";
+my $sub_png = "$::datadir/sub-$tmpid.png";
+
+my $result_url = "$::url_datadir/result-$tmpid.html";
+my $phantom_png_url = "$::url_datadir/phantom-$tmpid.png";
+my $ir_png_url = "$::url_datadir/ir-$tmpid.png";
+my $pj_png_url = "$::url_datadir/pj-$tmpid.png";
+my $sub_png_url = "$::url_datadir/sub-$tmpid.png";
+
+my $pjrec_ver = "$::bindir/ctsimtext pjrec";
+my $phm2pj_ver = "$::bindir/ctsimtext phm2pj";
+my $phm2if_ver = "$::bindir/ctsimtext phm2if";
+my $diff_ver = "$::bindir/ctsimtext if2";
+
+$pjrec_ver = "/opt/lam/bin/mpirun N N $::lamrundir/pjrec-lam" if $MPI;
+$phm2pj_ver = "/opt/lam/bin/mpirun N N $::lamrundir/phm2pj-lam" if $MPI;
+$phm2if_ver = "/opt/lam/bin/mpirun N N $::lamrundir/phm2if-lam" if $MPI;
+
+my $gp_cmd = "$phm2if_ver $phantom_fname $Phantom_Nx $Phantom_Ny --phantom $Phantom_Name --nsample $Phantom_NSample --view-ratio $Phantom_ViewRatio";
+my $pj_cmd = "$phm2pj_ver $pj_fname $PJ_NDet $PJ_NRot --phantom $Phantom_Name --nray $PJ_NRay --rotangle $PJ_RotAngle --geometry $PJ_Geometry --focal-length $PJ_FocalLength --view-ratio $Phantom_ViewRatio --scan-ratio $PJ_ScanRatio";
+my $pj_if_cmd = "$::bindir/pj2if $pj_fname $pj_if_fname";
+my $pjrec_cmd = "$pjrec_ver $pj_fname $ir_fname $IR_Nx $IR_Ny --filter $IR_Filter --filter-param $IR_Filter_Param --interp $IR_Interp --backproj $IR_Backproj --filter-method $IR_FilterMethod --zeropad $IR_Zeropad";
+my $sub_cmd = "$diff_ver $phantom_fname $ir_fname $sub_fname --sub";
+my $diff_cmd = "$diff_ver $phantom_fname $ir_fname --comp";
my $window_options = "--auto $auto_window_img";
if ($Disp_Min ne 'auto') {
@@ -118,21 +139,22 @@ if ($Disp_Max ne 'auto') {
$window_options .= " --max $Disp_Max";
}
-my $png1_cmd = "$bindir/sdf2img $phantom_fname $phantom_png $window_options --stats --format png";
-my $png2_cmd = "$bindir/sdf2img $ir_fname $ir_png $window_options --stats --format png";
-my $png3_cmd = "$bindir/sdf2img $rs_sdf_fname $rs_png --auto $auto_window_rs --stats --format png";
-my $png4_cmd = "$bindir/sdf2img $diff_fname $diff_png --auto $auto_window_diff --stats --format png";
+my $png1_cmd = "$::bindir/ifexport $phantom_fname $phantom_png $window_options --stats --format png --center mode";
+my $png2_cmd = "$::bindir/ifexport $ir_fname $ir_png $window_options --stats --format png --center mode";
+my $png3_cmd = "$::bindir/ifexport $pj_if_fname $pj_png --auto $auto_window_pj --stats --format png --center mode";
+my $png4_cmd = "$::bindir/ifexport $sub_fname $sub_png --auto $auto_window_diff --stats --format png --center mode";
-my $title = "CT Simulation Results";
+my $title = "CTSim Results";
my $out = head();
-$out .= " $title
\n";
if ($opt_d) {
$out .= "Commands
\n";
- $out .= "$gp_cmd
\n$rs_cmd
\n$rs_sdf_cmd
\n$ir_cmd
\n$diff_cmd
\n$png1_cmd
\n$png2_cmd
\n" .
+ $out .= "$gp_cmd
\n$pj_cmd
\n$pj_if_cmd
\n$pjrec_cmd
\n$diff_cmd
\n$png1_cmd
\n$png2_cmd
\n" .
"$png3_cmd
\n$png4_cmd
\n";
}
@@ -142,73 +164,78 @@ if ($error ne "") {
$out .= "Please correct them and try submitting your request again.
\n";
$out .= "$error";
} else {
- my $gp_out;
- my $rs_out;
- my $rs_sdf_out;
- my $ir_out;
- my $diff_out;
- my $png_gp_out;
- my $png_ir_out;
- my $png_rs_out;
- my $png_diff_out;
- if (1) {
- $gp_out = `$gp_cmd`;
- $rs_out .= `$rs_cmd`;
- $rs_sdf_out .= `$rs_sdf_cmd`;
- $ir_out .= `$ir_cmd`;
+ my $gp_out;
+ my $pj_out;
+ my $pj_if_out;
+ my $pjrec_out;
+ my $sub_out;
+ my $diff_out;
+ my $png_gp_out;
+ my $png_pjrec_out;
+ my $png_pj_out;
+ my $png_sub_out;
+ $gp_out = `$gp_cmd`;
+ if (-s $phantom_fname) {
+ $pj_out .= `$pj_cmd`;
+ $png_gp_out .= `$png1_cmd`;
+ if (-s $pj_fname) {
+ $pj_if_out .= `$pj_if_cmd`;
+ $png_pj_out .= `$png3_cmd`;
+ $pjrec_out .= `$pjrec_cmd`;
+ if (-s $ir_fname) {
+ $png_pjrec_out .= `$png2_cmd`;
+ $sub_out .= `$sub_cmd`;
$diff_out .= `$diff_cmd`;
- $png_gp_out .= `$png1_cmd`;
- $png_ir_out .= `$png2_cmd`;
- $png_rs_out .= `$png3_cmd`;
- $png_diff_out .= `$png4_cmd`;
- } else {
- $gp_out = `$gp_cmd 2>&1`;
- $rs_out .= `$rs_cmd 2>&1`;
- $rs_sdf_out .= `$rs_sdf_cmd 2>&1`;
- $ir_out .= `$ir_cmd 2>&1`;
- $diff_out .= `$diff_cmd 2>&1`;
- $png_gp_out .= `$png1_cmd 2>&1`;
- $png_ir_out .= `$png2_cmd 2>&1`;
- $png_rs_out .= `$png3_cmd 2>&1`;
- $png_diff_out .= `$png4_cmd 2>&1`;
- }
- $cmdout = "$gp_cmd\n $gp_out $rs_cmd\n $rs_out $rs_sdf_cmd\n $rs_sdf_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_rs_out $png4_cmd\n $png_diff_out";
- if (open(LOGFILE,">> $logfile")) {
- flock(LOGFILE,LOCK_EX);
- seek(LOGFILE, 0, 2);
- print LOGFILE "Job $tmpid\n";
- print LOGFILE $cmdout;
- print LOGFILE "----------------------------------------------------\n";
- flock(LOGFILE,LOCK_UN);
- close(LOGFILE);
- }
- $gmt_end = time();
- $execution_time = $gmt_end - $gmt_start;
- if ($opt_d)
- {
- $out .= "Command Output
$cmdout
\n";
+ $png_sub_out .= `$png4_cmd`;
+ }
}
- my $png_gp_out_html = $png_gp_out;
- my $png_ir_out_html = $png_ir_out;
- my $png_rs_out_html = $png_rs_out;
- my $png_diff_out_html = $png_diff_out;
- $png_gp_out_html =~ s/\n/
/gms;
- $png_ir_out_html =~ s/\n/
/gms;
- $png_rs_out_html =~ s/\n/
/gms;
- $png_diff_out_html =~ s/\n/
/gms;
- $out .= "
";
- $out .= "Execution time: $execution_time seconds\n";
+ }
+ # Delete image files and projection files
+ unlink($phantom_fname);
+ unlink($ir_fname);
+ unlink($pj_fname);
+ unlink($pj_if_fname);
+ unlink($sub_fname);
+
+ $cmdout = "$gp_cmd\n $gp_out $pj_cmd\n $pj_out $pj_if_cmd\n $pj_if_out $pjrec_cmd\n $pjrec_out $diff_cmd\n $diff_out $png1_cmd\n $png_gp_out $png2_cmd\n $png_pjrec_out $png3_cmd\n $png_pj_out $png4_cmd\n $png_sub_out";
+ if (open(LOGFILE,">> $logfile")) {
+ flock(LOGFILE,LOCK_EX);
+ seek(LOGFILE, 0, 2);
+ print LOGFILE "Client Address: $ENV{'REMOTE_ADDR'}\n";
+ print LOGFILE "Job $tmpid\n";
+ print LOGFILE $cmdout;
+ print LOGFILE "----------------------------------------------------\n";
+ flock(LOGFILE,LOCK_UN);
+ close(LOGFILE);
+ }
+ $gmt_end = time();
+ $execution_time = $gmt_end - $gmt_start;
+ if ($opt_d) {
+ $out .= " \n";
- $out .= "Phantom Image Reconstructed Image \n";
- $out .= " \n";
- $out .= "
$png_gp_out
$png_ir_out \n";
- $out .= "Raysum Sinusoid Phantom/Reconst Error \n";
- $out .= " \n";
- $out .= "
$png_rs_out
$diff_out
$png_diff_outCommand Output
$cmdout
\n";
+ }
+ my $png_gp_out_html = $png_gp_out;
+ my $png_pjrec_out_html = $png_pjrec_out;
+ my $png_pj_out_html = $png_pj_out;
+ my $png_sub_out_html = $png_sub_out;
+ $png_gp_out_html =~ s/\n/
/gms;
+ $png_pjrec_out_html =~ s/\n/
/gms;
+ $png_pj_out_html =~ s/\n/
/gms;
+ $png_sub_out_html =~ s/\n/
/gms;
+ $out .= "
";
+ $out .= " \n";
+ $out .= "Phantom Image Reconstructed Image \n";
+ $out .= " \n";
+ $out .= "
$png_gp_out
$png_pjrec_out \n";
+ $out .= "Projection Sinogram Reconstruction Error \n";
+ $out .= " \n";
+ $out .= "
$png_pj_out
$sub_out
$png_sub_out
Error Measurements
";
+ $out .= "$diff_out";
+ $out .= "
Execution time: $execution_time seconds\n"; } $out .= "