1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
#include "pulsarview.h"
#include <odinseq/seqplatform.h>
#include <tjutils/tjlog_code.h>
const char* PulsarComp::get_compName() {return "Pulsar";}
LOGGROUNDWORK(PulsarComp)
void PulsarView::usage() {
STD_cout << "pulsar: Pulse editor of ODIN" << STD_endl;
STD_cout << configInfo() << STD_endl;
STD_cout << STD_endl;
STD_cout << "Usage: pulsar [options] [<pulsar_file>]" << STD_endl;
STD_cout << "Options:" << STD_endl;
STD_cout << "\t-noedit : View-only mode" << STD_endl;
STD_cout << "\t -s <file>: Load system defaults" << STD_endl;
STD_cout << "\t" << LogBase::get_usage() << STD_endl;
STD_cout << "\t" << helpUsage() << STD_endl;
}
PulsarView::PulsarView(QWidget *parent) : QWidget(parent) {
Log<PulsarComp> odinlog("PulsarView","PulsarView(...)");
char buff[ODIN_MAXCHAR];
pulse=new OdinPulse("Pulse",true);
ODINLOG(odinlog,normalDebug) << "generation pars initialised" << STD_endl;
sample=new Sample("Sample",true,true);
ODINLOG(odinlog,normalDebug) << "sample pars initialised" << STD_endl;
mag=new SeqSimMagsi("Magnetization");
ODINLOG(odinlog,normalDebug) << "simulation pars initialised" << STD_endl;
if(isCommandlineOption(GuiApplication::argc(),GuiApplication::argv(),"-noedit")) {
pulse->set_parmode(noedit);
}
if(getCommandlineOption(GuiApplication::argc(),GuiApplication::argv(),"-s",buff,ODIN_MAXCHAR)) {
SeqPlatformProxy::load_systemInfo(buff);
ODINLOG(odinlog,normalDebug) << "systemInfo file >" << buff << "< loaded" << STD_endl;
}
if(getLastArgument(GuiApplication::argc(),GuiApplication::argv(),buff,ODIN_MAXCHAR)) {
if(STD_string(buff)!="") {
pulse->load(buff);
fileName=buff;
ODINLOG(odinlog,normalDebug) << "pulsar file >" << buff << "< loaded" << STD_endl;
}
}
grid=new GuiGridLayout( this, 2, 2);
ODINLOG(odinlog,normalDebug) << "layout created" << STD_endl;
/*------------- general pulse parameters ------------------------*/
old_mode=n_dimModes;
unsigned int i;
for(i=0; i<n_dimModes; i++) pulseWidget[i]=0;
for(i=0; i<n_dimModes; i++) sampleWidget[i]=0;
for(i=0; i<n_dimModes; i++) magnWidget[i]=0;
ODINLOG(odinlog,normalDebug) << "calling updatePulse()" << STD_endl;
updatePulse();
}
PulsarView::~PulsarView() {
for(unsigned int i=0; i<n_dimModes; i++) {
if(pulseWidget[i]) delete pulseWidget[i];
if(sampleWidget[i]) delete sampleWidget[i];
if(magnWidget[i]) delete magnWidget[i];
}
delete pulse;
delete sample;
delete mag;
delete grid;
}
void PulsarView::initPulsarView() {
emit newCaption(fileName.c_str());
}
void PulsarView::updateWidget() {
Log<PulsarComp> odinlog("PulsarView","updateWidget()");
if(!progress) {
progress=new GuiProgressDialog(this, false,0);
progress->set_text("Calculating Pulse");
progress->show();
progcount=0;
} else {
progress->set_progress(progcount);
progcount++;
}
if(progress->was_cancelled()) throw PulsarCancel();
pulseWidget[old_mode]->updateWidget();
updateMagnetization();
GuiApplication::process_events(); // Must be called manually because Qt event handler is blocked in optimization loop
}
void PulsarView::updatePulse() {
Log<PulsarComp> odinlog("PulsarView","updatePulse()");
ODINLOG(odinlog,normalDebug) << "calling pulse->update() ..." << STD_endl;
progress=0;
try {
pulse->update();
} catch(PulsarCancel) {
ODINLOG(odinlog,normalDebug) << " cancelled" << STD_endl;
}
if(progress) delete progress;
progress=0;
ODINLOG(odinlog,normalDebug) << "done" << STD_endl;
funcMode mode=pulse->get_dim_mode();
ODINLOG(odinlog,normalDebug) << "old_mode/mode=" << old_mode << "/" << mode << STD_endl;
if(old_mode!=mode) {
if(old_mode!=n_dimModes) {
ODINLOG(odinlog,normalDebug) << "Hiding old LDRwidget" << STD_endl;
pulseWidget[old_mode]->deleteDialogs();
pulseWidget[old_mode]->hide();
}
ODINLOG(odinlog,normalDebug) << "Allocating LDRwidget" << STD_endl;
if(pulseWidget[mode]==0) pulseWidget[mode]=new LDRwidget(*pulse,2,this,true);
ODINLOG(odinlog,normalDebug) << "Showing LDRwidget" << STD_endl;
pulseWidget[mode]->show();
grid->add_widget(pulseWidget[mode], 0, 0, GuiGridLayout::Default, 2, 1);
connect(pulseWidget[mode],SIGNAL(valueChanged()),this,SLOT(updatePulse()));
connect(pulseWidget[mode],SIGNAL(doneButtonPressed()),this,SLOT(emitDone()));
}
ODINLOG(odinlog,normalDebug) << "calling pulseWidget[" << mode << "]->updateWidget() ..." << STD_endl;
pulseWidget[mode]->updateWidget();
ODINLOG(odinlog,normalDebug) << "done" << STD_endl;
updateMagnetization();
old_mode=mode;
}
void PulsarView::updateMagnetization() {
Log<PulsarComp> odinlog("PulsarView","updateMagnetization");
funcMode mode=pulse->get_dim_mode();
ODINLOG(odinlog,normalDebug) << "mode=" << mode << STD_endl;
if(old_mode!=mode) {
ODINLOG(odinlog,normalDebug) << "Changing mode" << STD_endl;
bool onlineflag=true;
unsigned int xsize=1;
unsigned int ysize=1;
unsigned int zsize=1;
unsigned int freqsize=1;
if(mode==zeroDeeMode) { freqsize=255; }
if(mode==oneDeeMode) { zsize=255; }
if(mode>=twoDeeMode) {xsize=31; ysize=31; onlineflag=false;}
ODINLOG(odinlog,normalDebug) << "xsize/ysize/zsize/freqsize=" << xsize << "/" << ysize << "/" << zsize << "/" << freqsize << STD_endl;
sample->resize(1,freqsize,zsize,ysize,xsize);
mag->set_online_simulation(onlineflag);
sample->update();
mag->update();
mag->prepare_simulation(*sample); // call once to resize mag
pulse->simulate_pulse(*mag,*sample); // simulate once to get gray scale in 2D mode
if(old_mode!=n_dimModes) {
ODINLOG(odinlog,normalDebug) << "Deleting old widgets ..." << STD_endl;
sampleWidget[old_mode]->deleteDialogs();
sampleWidget[old_mode]->hide();
magnWidget[old_mode]->deleteDialogs();
magnWidget[old_mode]->hide();
ODINLOG(odinlog,normalDebug) << "Deleting old widgets done" << STD_endl;
}
if(sampleWidget[mode]==0) {
ODINLOG(odinlog,normalDebug) << "Creating new sampleWidget ..." << STD_endl;
sampleWidget[mode]=new LDRwidget(*sample,1,this);
sampleWidget[mode]->show();
grid->add_widget(sampleWidget[mode], 0, 1);
connect(sampleWidget[mode],SIGNAL(valueChanged()),this,SLOT(updateMagnetization()));
ODINLOG(odinlog,normalDebug) << "Creating new sampleWidget done" << STD_endl;
}
if(magnWidget[mode]==0) {
ODINLOG(odinlog,normalDebug) << "Creating new magnWidget ..." << STD_endl;
magnWidget[mode]=new LDRwidget(*mag,1,this);
magnWidget[mode]->show();
grid->add_widget(magnWidget[mode], 1, 1);
connect(magnWidget[mode],SIGNAL(valueChanged()),this,SLOT(updateMagnetization()));
ODINLOG(odinlog,normalDebug) << "Creating new magnWidget done" << STD_endl;
}
sampleWidget[mode]->show();
magnWidget[mode]->show();
}
sample->update();
mag->update();
if(mag->do_simulation()) pulse->simulate_pulse(*mag,*sample);
sampleWidget[mode]->updateWidget();
magnWidget[mode]->updateWidget();
}
void PulsarView::emitDone() {emit done();}
void PulsarView::slotFileNew() {
if(message_question("Resetting to defaults will delete the current values.\n"
"Do you really want a fresh pulse ?", "New Pulse", this, true)) {
(*pulse)=OdinPulse("Pulse",true);
updatePulse();
}
}
void PulsarView::slotFileOpen() {
STD_string newfile=get_open_filename("Open Pulse", fileName.c_str(), "", this);
if (newfile!="") {
fileName=newfile;
emit newCaption(fileName.c_str());
pulse->load(fileName);
updatePulse();
}
}
void PulsarView::slotFileSave() {
if (fileName!="") {
pulse->write(fileName);
} else slotFileSaveAs();
}
void PulsarView::slotFileSaveAs() {
fileName=get_save_filename("Save Pulse", fileName.c_str(), "", this);
if (fileName!="") {
pulse->write(fileName);
}
}
void PulsarView::writeBrukerRf() {
STD_string fname=get_save_filename("Export Bruker Pulse", "", "", this);
if (fname!="") {
SeqPlatformProxy::set_current_platform(paravision);
pulse->write_rf_waveform(fname);
SeqPlatformProxy::set_current_platform(standalone);
}
}
void PulsarView::vriteArray(const STD_string& filename, const fvector& data) {
STD_string filestr;
for(unsigned int i=0; i<data.length(); i++) {
filestr+=ftos(data[i])+"\n";
}
::write(filestr,filename);
}
void PulsarView::exportASCIIpulse(const fvector& data) {
STD_string fname=get_save_filename("Export ASCII Pulse", "", "", this);
if(fname!="") vriteArray(fname,data);
}
void PulsarView::exportASCIImag(const fvector& data) {
STD_string fname=get_save_filename("Export ASCII Magnetization", "", "", this);
if(fname!="") vriteArray(fname,data);
}
void PulsarView::exportRfampASCII() {exportASCIIpulse(amplitude(pulse->get_B1()));}
void PulsarView::exportRfphaASCII() {exportASCIIpulse(phase(pulse->get_B1()));}
void PulsarView::exportGxASCII() {exportASCIIpulse(pulse->get_Grad(readDirection));}
void PulsarView::exportGyASCII() {exportASCIIpulse(pulse->get_Grad(phaseDirection));}
void PulsarView::exportGzASCII() {exportASCIIpulse(pulse->get_Grad(sliceDirection));}
void PulsarView::exportMampASCII() {exportASCIImag(mag->get_Mamp());}
void PulsarView::exportMphaASCII() {exportASCIImag(mag->get_Mpha());}
void PulsarView::exportMzASCII() {exportASCIImag(mag->get_Mz());}
void PulsarView::exportPulseLDR() {
STD_string fname=get_save_filename("Export JCAMP-DX Pulse", "", "", this);
if(fname!="") {
OdinPulse sd(*pulse);
sd.set_filemode(include);
sd.write(fname);
}
}
void PulsarView::exportMagLDR() {
STD_string fname=get_save_filename("Export JCAMP-DX Magnetization", "", "", this);
if(fname!="") {
SeqSimMagsi sm(*mag);
sm.set_filemode(include);
sm.write(fname);
}
}
void PulsarView::edit_systemInfo() {
LDRwidgetDialog* dlg=new LDRwidgetDialog(pulse->get_systemInfo(),1,this);
connect(dlg,SIGNAL(valueChanged()),this,SLOT(updatePulse()));
}
|