/* POSSUM Ivana Drobnjak & Mark Jenkinson Copyright (C) 2005-2007 University of Oxford */ /* Part of FSL - FMRIB's Software Library http://www.fmrib.ox.ac.uk/fsl fsl@fmrib.ox.ac.uk Developed at FMRIB (Oxford Centre for Functional Magnetic Resonance Imaging of the Brain), Department of Clinical Neurology, Oxford University, Oxford, UK LICENCE FMRIB Software Library, Release 5.0 (c) 2012, The University of Oxford (the "Software") The Software remains the property of the University of Oxford ("the University"). The Software is distributed "AS IS" under this Licence solely for non-commercial use in the hope that it will be useful, but in order that the University as a charitable foundation protects its assets for the benefit of its educational and research purposes, the University makes clear that no condition is made or to be implied, nor is any warranty given or to be implied, as to the accuracy of the Software, or that it will be suitable for any particular purpose or for use under any specific conditions. Furthermore, the University disclaims all responsibility for the use which is made of the Software. It further disclaims any liability for the outcomes arising from using the Software. The Licensee agrees to indemnify the University and hold the University harmless from and against any and all claims, damages and liabilities asserted by third parties (including claims for negligence) which arise directly or indirectly from the use of the Software or the sale of any products based on the Software. No part of the Software may be reproduced, modified, transmitted or transferred in any form or by any means, electronic or mechanical, without the express permission of the University. The permission of the University is not required if the said reproduction, modification, transmission or transference is done without financial return, the conditions of this Licence are imposed upon the receiver of the product, and all original and amended source code is included in any transmitted product. You may be held legally responsible for any copyright infringement that is caused or encouraged by your failure to abide by these terms and conditions. You are not permitted under this Licence to use this Software commercially. Use for which any financial return is received shall be defined as commercial use, and includes (1) integration of all or part of the source code or the Software into a product for sale or license by or on behalf of Licensee to third parties or (2) use of the Software or any derivative of it for research with the final aim of developing software products for sale or license to a third party or (3) use of the Software or any derivative of it for research with the final aim of developing non-software products for sale or license to a third party, or (4) use of the Software to provide any service to an external organisation for which payment is received. If you are interested in using the Software commercially, please contact Isis Innovation Limited ("Isis"), the technology transfer company of the University, to negotiate a licence. Contact details are: innovation@isis.ox.ac.uk quoting reference DE/9564. */ // POSSUM #include #include #include #include #ifdef USE_MPI #include #include #endif //USE_MPI #include "libprob.h" #include "newmatap.h" #include "newmatio.h" #include "newimage/newimageall.h" #include "possumfns.h" #include "utils/options.h" #include "newimage/costfns.h" #include "miscmaths/miscmaths.h" #define _GNU_SOURCE 1 #define POSIX_SOURCE 1 using namespace NEWIMAGE; using namespace NEWMAT; using namespace MISCMATHS; using namespace Utilities; //using namespace std; string title="possum \nCopyright(c) 2007, University of Oxford (Ivana Drobnjak)"; string examples="possum -i -x -p -f -m -o [optional arguments]"; Option verbose(string("-v,--verbose"), false, string("switch on diagnostic messages"), false, no_argument); Option help(string("-h,--help"), false, string("display this message"), false, no_argument); //INPUT object and its characteristics (including susc effects on B0 and the RF inhomogeneities) Option opt_object(string("-i,--inp"), string(""), string(" (Input object)"), true, requires_argument); Option opt_tissue(string("-x,--mrpar"),string("") , string(" (MR parameters)"), true,requires_argument); Option opt_b0(string("-b,--b0p"), string(""), string(" (B0 inhomogeneities due to the susceptibility differences - base name, without extras z_dz, z_dx etc)"), false, requires_argument); Option opt_b0extra(string("--b0extra"), string(""), string(" (B0 inhomogeneities due to an extra field - see b0time)"), false, requires_argument); Option opt_b0timecourse4D(string("--b0time"),string(""), string(" (B0inhomogeneities_timecourse [time(s) multiply_factor(perc 0 to 1)] - see b0extra) "), false,requires_argument); Option opt_RFrec(string("-r,--rfr"), string(""), string(" ( RF inhomogeneity - receive. NOTE: not yet to be used ) "), false, requires_argument); Option opt_RFtrans(string("-s,--rft"), string(""), string(" ( RF inhomogeneity - transmit. NOTE: not yet to be used )"), false, requires_argument); //INPUT motion and activation Option opt_activation4D(string("-q,--activ4D"),string(""), string(" (Activation volume) "), false,requires_argument); Option opt_timecourse4D(string("-u,--activt4D"),string(""), string(" (Activation4D_timecourse [time(s)])"), false,requires_argument); Option opt_activation(string("-a,--activ"),string(""), string(" (Activation volume)"), false,requires_argument); Option opt_timecourse(string("-t,--activt"),string(""), string(" (Activation_timecourse [time(s) multiply_factor(perc 0 to 1)])"), false,requires_argument); Option opt_motion(string("-m,--motion"), string(""), string(" (Motion matrix [time(s) Tx(m) Ty(m) Tz(m) Rx(rad) Ry(rad) Rz(rad)]) "), true, requires_argument); //INPUT for the pulse sequence Option opt_pulse(string("-p,--pulse"), string(""), string(" (Pulse sequence - all additional files .posx,.posy, etc, expected to be in the same directory)"), true, requires_argument); Option opt_slcprof(string("-f,--slcprof"), string(""), string(" (RF slice profile)"), true, requires_argument); //INPUT for the computational efficiency Option opt_level(string("-l,--lev"), 1, string("{1,2,3,4} (Levels: 1.no motion//basic B0 2.motion//basic B0, 3.motion//full B0, 4.no motion//time changing B0)"), false,requires_argument); Option opt_nospeedup(string("--nospeedup"), false, string("If this option is ON it will NOT do the speedup but will do signal for all the slices for each voxel."), false, no_argument); //INPUT for the manual paralelisation -- used with sge_possum Option opt_nproc(string("--nproc"), 1, string(" (INPUT for the paralelisation -- Number of processors we have available)"), false,requires_argument); Option opt_procid(string("--procid"), 0, string(" (INPUT for the paralelisation -- ID of the processor we are on)"), false,requires_argument); //OUTPUT signal Option opt_signal(string("-o,--out"), string(""), string(" (Signal - [sreal, simag])"), true, requires_argument); //OUTPUT main event matrix Option opt_mainmatrix(string("-e,--mainmatx"), string(""), string(" (Main event matrix [t(s),rf_ang(rad),rf_freq_band(Hz),(4)=rf_cent_freq(Hz),read(1/0),Gx,Gy,Gz(T/m),Tx,Ty,Tz(m),angle_of_rot B(rad),rot_axis Bx,By,Bz(m),angle_of_rot A(rad),rot_axis Ax,Ay,Az(m)]) "), false, requires_argument); //OUTPUT kcoord if needed Option opt_kcoord(string("-k,--kcoord"), false, string("If this option is ON it will save the kspace coordinates"), false, no_argument); int nonoptarg; ///////////////////////////////////////////////////////////////////////////////////////////////////// int compute_volume(int argc, char *argv[]) { cout<<"Starting POSSUM..."< phantom;//consists of gry,wht,csf,fat,mus,con,gli,skn (in that order) read_volume4DROI(phantom,opt_object.value(),myid,0,0,0,Nxx,-1,-1,-1,numprocs,1,1,1); //read_volume4D(phantom,opt_object.value()); int Nx=phantom.xsize();double xdim=phantom.xdim()*0.001; int Ny=phantom.ysize();double ydim=phantom.ydim()*0.001; int Nz=phantom.zsize();double zdim=phantom.zdim()*0.001; int Nt=phantom.tsize(); print_volume_info(phantom,"object"); cout<<""<txmax) txmax=motion(k,2); if (motion(k,2)tymax) tymax=motion(k,3); if (motion(k,3)tzmax) tzmax=motion(k,4); if (motion(k,4)rxmaxabs) rxmaxabs=fabs(motion(k,5)); if (fabs(motion(k,6))>rymaxabs) rymaxabs=fabs(motion(k,6)); if (fabs(motion(k,7))>rzmaxabs) rzmaxabs=fabs(motion(k,7)); } //slc selection direction stuff int slcdir=(int) (pulseinfo(15)); cout<<"Slice selection direction is "<(ssNz-1)) sszend=ssNz-1; cout<<"Begining of the object is "< activation4D; volume activation(Nx,Ny,Nz); double* timecourse; double* timecourse_2=0; double* activation4D_voxel; int Nact; if (opt_activation.set()) { cout<<"3D activation mode"< RFrec(Nx,Ny,Nz);//signal=signal*RFrec volume RFtrans(Nx,Ny,Nz);//flip_ang=flip_ang*RFtrans //if (opt_RFrec.set()) read_volume_new(RFrec,opt_RFrec.value(),myid,numprocs,Nxx); if (opt_RFrec.set()) read_volumeROI(RFrec,opt_RFrec.value(),myid,0,0,Nxx,-1,-1,numprocs,1,1); else { for (int px=0;px b0(Nxx,Ny,Nz); volume b0x(Nxx,Ny,Nz); volume b0y(Nxx,Ny,Nz); volume b0z(Nxx,Ny,Nz); if (opt_b0.set()) { read_volume(b0,opt_b0.value()+"z_dz"); calc_gradientsROI(b0,b0x,b0y,b0z,myid,Nxx,numprocs); } else { b0=phantom[0]*0; b0x=b0; b0y=b0; b0z=b0; } print_volume_info(b0,"b0"); cout<<""< b0(Nxx,Ny,Nz); volume b0x(Nxx,Ny,Nz); volume b0y(Nxx,Ny,Nz); volume b0z(Nxx,Ny,Nz); if (opt_b0.set()) { read_volume(b0,opt_b0.value()+"z_dz"); calc_gradientsROI(b0,b0x,b0y,b0z,myid,Nxx,numprocs); } else { b0=phantom[0]*0; b0x=b0; b0y=b0; b0z=b0; } print_volume_info(b0,"b0"); //////////////// //MAIN LOOP //////////////// cout<<"Main loop..."< b0x_dx, b0x_dy, b0x_dz, b0y_dx, b0y_dy, b0y_dz, b0z_dx, b0z_dy, b0z_dz;//read in volume b0x_dx_gx, b0x_dx_gy, b0x_dx_gz, b0x_dy_gx, b0x_dy_gy, b0x_dy_gz, b0x_dz_gx, b0x_dz_gy, b0x_dz_gz;//calculate from, the calc gradients volume b0y_dx_gx, b0y_dx_gy, b0y_dx_gz, b0y_dy_gx, b0y_dy_gy, b0y_dy_gz, b0y_dz_gx, b0y_dz_gy, b0y_dz_gz; volume b0z_dx_gx, b0z_dx_gy, b0z_dx_gz, b0z_dy_gx, b0z_dy_gy, b0z_dy_gz, b0z_dz_gx, b0z_dz_gy, b0z_dz_gz; if (opt_b0.set()) { read_volume(b0x_dx,opt_b0.value()+"x_dx"); calc_gradientsROI(b0x_dx,b0x_dx_gx,b0x_dx_gy,b0x_dx_gz,myid,Nxx,numprocs); read_volume(b0x_dy,opt_b0.value()+"x_dy"); calc_gradientsROI(b0x_dy,b0x_dy_gx,b0x_dy_gy,b0x_dy_gz,myid,Nxx,numprocs); read_volume(b0x_dz,opt_b0.value()+"x_dz"); calc_gradientsROI(b0x_dz,b0x_dz_gx,b0x_dz_gy,b0x_dz_gz,myid,Nxx,numprocs); read_volume(b0y_dx,opt_b0.value()+"y_dx"); calc_gradientsROI(b0y_dx,b0y_dx_gx,b0y_dx_gy,b0y_dx_gz,myid,Nxx,numprocs); read_volume(b0y_dy,opt_b0.value()+"y_dy"); calc_gradientsROI(b0y_dy,b0y_dy_gx,b0y_dy_gy,b0y_dy_gz,myid,Nxx,numprocs); read_volume(b0y_dz,opt_b0.value()+"y_dz"); calc_gradientsROI(b0y_dz,b0y_dz_gx,b0y_dz_gy,b0y_dz_gz,myid,Nxx,numprocs); read_volume(b0z_dx,opt_b0.value()+"z_dx"); calc_gradientsROI(b0z_dx,b0z_dx_gx,b0z_dx_gy,b0z_dx_gz,myid,Nxx,numprocs); read_volume(b0z_dy,opt_b0.value()+"z_dy"); calc_gradientsROI(b0z_dy,b0z_dy_gx,b0z_dy_gy,b0z_dy_gz,myid,Nxx,numprocs); read_volume(b0z_dz,opt_b0.value()+"z_dz"); calc_gradientsROI(b0z_dz,b0z_dz_gx,b0z_dz_gy,b0z_dz_gz,myid,Nxx,numprocs); } else { b0x_dx=phantom[0]*0; b0x_dx_gx=b0x_dx; b0x_dx_gy=b0x_dx; b0x_dx_gz=b0x_dx; b0x_dy=b0x_dx; b0x_dy_gx=b0x_dx; b0x_dy_gy=b0x_dx; b0x_dy_gz=b0x_dx; b0x_dz=b0x_dx; b0x_dz_gx=b0x_dx; b0x_dz_gy=b0x_dx; b0x_dz_gz=b0x_dx; b0y_dx=b0x_dx; b0y_dx_gx=b0x_dx; b0y_dx_gy=b0x_dx; b0y_dx_gz=b0x_dx; b0y_dy=b0x_dx; b0y_dy_gx=b0x_dx; b0y_dy_gy=b0x_dx; b0y_dy_gz=b0x_dx; b0y_dz=b0x_dx; b0y_dz_gx=b0x_dx; b0y_dz_gy=b0x_dx; b0y_dz_gz=b0x_dx; b0z_dx=b0x_dx; b0z_dx_gx=b0x_dx; b0z_dx_gy=b0x_dx; b0z_dx_gz=b0x_dx; b0z_dy=b0x_dx; b0z_dy_gx=b0x_dx; b0z_dy_gy=b0x_dx; b0z_dy_gz=b0x_dx; b0z_dz=b0x_dx; b0z_dz_gx=b0x_dx; b0z_dz_gy=b0x_dx; b0z_dz_gz=b0x_dx; } print_volume_info(b0z_dz,"b0z_dz"); /////////////////// //MAIN LOOP /////////////////// cout<<"Main loop..."< b0extra; volume b0xextra; volume b0yextra; volume b0zextra; read_volume(b0extra,opt_b0extra.value()); calc_gradientsROI(b0extra,b0xextra,b0yextra,b0zextra,myid,Nxx,numprocs); print_volume_info(b0extra,"b0extra"); cout<<"Creating 1 B0file together with 3 gradient files..."< b0(Nxx,Ny,Nz); volume b0x(Nxx,Ny,Nz); volume b0y(Nxx,Ny,Nz); volume b0z(Nxx,Ny,Nz); if (opt_b0.set()) { read_volume(b0,opt_b0.value()+"z_dz"); calc_gradientsROI(b0,b0x,b0y,b0z,myid,Nxx,numprocs); } else { b0=phantom[0]*0; b0x=b0; b0y=b0; b0z=b0; } print_volume_info(b0,"b0"); cout<<""<.\n"; if (myid==0){ cout<<"Element nmb 1091 on "<.\n"; for (int i=1;i<=nreadp;i++) { signal(1,i)=sreal_total[i-1]*1e06; //1e06 we need to make signal have larger values so that it more resembles the scanner signal(2,i)=simag_total[i-1]*1e06; //1e06 we need to make signal have larger values so that it more resembles the scanner } write_binary_matrix(signal,opt_signal.value()); } MPI_Finalize();//MPI::Finalize(); #else ///////////////////////// //OUTPUT ///////////////////////// for (int i=1;i<=nreadp;i++) { signal(1,i)=sreal[i-1]*1e06; //1e06 we need to make signal have larger values so that it more resembles the scanner signal(2,i)=simag[i-1]*1e06; //1e06 we need to make signal have larger values so that it more resembles the scanner } write_binary_matrix(signal,opt_signal.value()); cout<<"Possum finished generating the signal for "<