Store EDFSignal memory in a linear vector.

Signed-off-by: Mark Watkins <jedimark@users.sourceforge.net>
This commit is contained in:
Sean Stangl 2014-04-09 12:39:03 -07:00 committed by Mark Watkins
parent 50c51c9a91
commit d86ffb3a50
2 changed files with 30 additions and 29 deletions

View File

@ -71,10 +71,9 @@ EDFParser::EDFParser(QString name)
} }
EDFParser::~EDFParser() EDFParser::~EDFParser()
{ {
QVector<EDFSignal *>::iterator s; QVector<EDFSignal>::iterator s;
for (s=edfsignals.begin();s!=edfsignals.end();s++) { for (s=edfsignals.begin();s!=edfsignals.end();s++) {
if ((*s)->data) delete [] (*s)->data; if ((*s).data) delete [] (*s).data;
delete *s;
} }
if (buffer) delete [] buffer; if (buffer) delete [] buffer;
} }
@ -162,35 +161,37 @@ bool EDFParser::Parse()
// this could be loaded quicker by transducer_type[signal] etc.. // this could be loaded quicker by transducer_type[signal] etc..
for (int i=0;i<num_signals;i++) { // Initialize fixed-size signal list.
EDFSignal *signal=new EDFSignal; edfsignals.resize(num_signals);
edfsignals.push_back(signal);
signal->data=NULL; for (int i = 0; i < num_signals; i++) {
edfsignals[i]->label=Read(16); EDFSignal &signal = edfsignals[i];
lookup[edfsignals[i]->label]=signal; signal.data = NULL;
signal.label = Read(16);
lookup[signal.label] = &signal; // Safe: edfsignals won't move.
} }
for (int i=0;i<num_signals;i++) edfsignals[i]->transducer_type=Read(80); for (int i=0;i<num_signals;i++) edfsignals[i].transducer_type=Read(80);
for (int i=0;i<num_signals;i++) edfsignals[i]->physical_dimension=Read(8); for (int i=0;i<num_signals;i++) edfsignals[i].physical_dimension=Read(8);
for (int i=0;i<num_signals;i++) edfsignals[i]->physical_minimum=Read(8).toDouble(&ok); for (int i=0;i<num_signals;i++) edfsignals[i].physical_minimum=Read(8).toDouble(&ok);
for (int i=0;i<num_signals;i++) edfsignals[i]->physical_maximum=Read(8).toDouble(&ok); for (int i=0;i<num_signals;i++) edfsignals[i].physical_maximum=Read(8).toDouble(&ok);
for (int i=0;i<num_signals;i++) edfsignals[i]->digital_minimum=Read(8).toDouble(&ok); for (int i=0;i<num_signals;i++) edfsignals[i].digital_minimum=Read(8).toDouble(&ok);
for (int i=0;i<num_signals;i++) { for (int i=0;i<num_signals;i++) {
EDFSignal & e=*edfsignals[i]; EDFSignal &e = edfsignals[i];
e.digital_maximum=Read(8).toDouble(&ok); e.digital_maximum=Read(8).toDouble(&ok);
e.gain=(e.physical_maximum-e.physical_minimum)/(e.digital_maximum-e.digital_minimum); e.gain=(e.physical_maximum-e.physical_minimum)/(e.digital_maximum-e.digital_minimum);
e.offset=0; e.offset=0;
} }
for (int i=0;i<num_signals;i++) edfsignals[i]->prefiltering=Read(80); for (int i=0;i<num_signals;i++) edfsignals[i].prefiltering=Read(80);
for (int i=0;i<num_signals;i++) edfsignals[i]->nr=Read(8).toLong(&ok); for (int i=0;i<num_signals;i++) edfsignals[i].nr=Read(8).toLong(&ok);
for (int i=0;i<num_signals;i++) edfsignals[i]->reserved=Read(32); for (int i=0;i<num_signals;i++) edfsignals[i].reserved=Read(32);
// allocate the buffers // allocate the buffers
for (int i=0;i<num_signals;i++) { for (int i=0;i<num_signals;i++) {
//qDebug//cout << "Reading signal " << signals[i]->label << endl; //qDebug//cout << "Reading signal " << signals[i]->label << endl;
EDFSignal & sig=*edfsignals[i]; EDFSignal &sig = edfsignals[i];
long recs=sig.nr * num_data_records; long recs=sig.nr * num_data_records;
if (num_data_records<0) if (num_data_records<0)
@ -201,7 +202,7 @@ bool EDFParser::Parse()
for (int x=0;x<num_data_records;x++) { for (int x=0;x<num_data_records;x++) {
for (int i=0;i<num_signals;i++) { for (int i=0;i<num_signals;i++) {
EDFSignal & sig=*edfsignals[i]; EDFSignal &sig = edfsignals[i];
memcpy((char *)&sig.data[sig.pos],(char *)&buffer[pos],sig.nr*2); memcpy((char *)&sig.data[sig.pos],(char *)&buffer[pos],sig.nr*2);
sig.pos+=sig.nr; sig.pos+=sig.nr;
pos+=sig.nr*2; pos+=sig.nr*2;
@ -501,7 +502,7 @@ int ResmedLoader::Open(QString & path,Profile *profile)
//QDate dd2=dt2.date(); //QDate dd2=dt2.date();
// for (int s=0;s<stredf.GetNumSignals();s++) { // for (int s=0;s<stredf.GetNumSignals();s++) {
// EDFSignal & es=*stredf.edfsignals[s]; // EDFSignal &es = stredf.edfsignals[s];
// long recs=es.nr*stredf.GetNumDataRecords(); // long recs=es.nr*stredf.GetNumDataRecords();
// //qDebug() << "STREDF:" << es.label << recs; // //qDebug() << "STREDF:" << es.label << recs;
// } // }
@ -1757,9 +1758,9 @@ bool ResmedLoader::LoadEVE(Session *sess,EDFParser &edf)
UA=sess->AddEventList(CPAP_Apnea,EVL_Event); UA=sess->AddEventList(CPAP_Apnea,EVL_Event);
for (int s=0;s<edf.GetNumSignals();s++) { for (int s=0;s<edf.GetNumSignals();s++) {
recs=edf.edfsignals[s]->nr*edf.GetNumDataRecords()*2; recs=edf.edfsignals[s].nr*edf.GetNumDataRecords()*2;
data=(char *)edf.edfsignals[s]->data; data=(char *)edf.edfsignals[s].data;
pos=0; pos=0;
tt=edf.startdate; tt=edf.startdate;
sess->updateFirst(tt); sess->updateFirst(tt);
@ -1854,7 +1855,7 @@ bool ResmedLoader::LoadBRP(Session *sess,EDFParser &edf)
sess->updateLast(edf.startdate+duration); sess->updateLast(edf.startdate+duration);
for (int s=0;s<edf.GetNumSignals();s++) { for (int s=0;s<edf.GetNumSignals();s++) {
EDFSignal & es=*edf.edfsignals[s]; EDFSignal &es = edf.edfsignals[s];
//qDebug() << "BRP:" << es.digital_maximum << es.digital_minimum << es.physical_maximum << es.physical_minimum; //qDebug() << "BRP:" << es.digital_maximum << es.digital_minimum << es.physical_maximum << es.physical_minimum;
long recs=es.nr*edf.GetNumDataRecords(); long recs=es.nr*edf.GetNumDataRecords();
ChannelID code; ChannelID code;
@ -1869,7 +1870,7 @@ bool ResmedLoader::LoadBRP(Session *sess,EDFParser &edf)
} else if (es.label.startsWith("Resp Event")) { } else if (es.label.startsWith("Resp Event")) {
code=CPAP_RespEvent; code=CPAP_RespEvent;
} else { } else {
qDebug() << "Unobserved ResMed BRP Signal " << edf.edfsignals[s]->label; qDebug() << "Unobserved ResMed BRP Signal " << es.label;
continue; continue;
} }
double rate=double(duration)/double(recs); double rate=double(duration)/double(recs);
@ -2021,7 +2022,7 @@ bool ResmedLoader::LoadSAD(Session *sess,EDFParser &edf)
sess->updateLast(edf.startdate+duration); sess->updateLast(edf.startdate+duration);
for (int s=0;s<edf.GetNumSignals();s++) { for (int s=0;s<edf.GetNumSignals();s++) {
EDFSignal & es=*edf.edfsignals[s]; EDFSignal &es = edf.edfsignals[s];
//qDebug() << "SAD:" << es.label << es.digital_maximum << es.digital_minimum << es.physical_maximum << es.physical_minimum; //qDebug() << "SAD:" << es.label << es.digital_maximum << es.digital_minimum << es.physical_maximum << es.physical_minimum;
long recs=es.nr*edf.GetNumDataRecords(); long recs=es.nr*edf.GetNumDataRecords();
ChannelID code; ChannelID code;
@ -2030,7 +2031,7 @@ bool ResmedLoader::LoadSAD(Session *sess,EDFParser &edf)
} else if (es.label=="SpO2") { } else if (es.label=="SpO2") {
code=OXI_SPO2; code=OXI_SPO2;
} else { } else {
qDebug() << "Unobserved ResMed SAD Signal " << edf.edfsignals[s]->label; qDebug() << "Unobserved ResMed SAD Signal " << es.label;
continue; continue;
} }
bool hasdata=false; bool hasdata=false;
@ -2074,7 +2075,7 @@ bool ResmedLoader::LoadPLD(Session *sess,EDFParser &edf)
ChannelID code; ChannelID code;
for (int s=0;s<edf.GetNumSignals();s++) { for (int s=0;s<edf.GetNumSignals();s++) {
a=NULL; a=NULL;
EDFSignal & es=*edf.edfsignals[s]; EDFSignal &es = edf.edfsignals[s];
recs=es.nr*edf.GetNumDataRecords(); recs=es.nr*edf.GetNumDataRecords();
if (recs<=0) continue; if (recs<=0) continue;
rate=double(duration)/double(recs); rate=double(duration)/double(recs);

View File

@ -123,7 +123,7 @@ public:
qint16 Read16(); qint16 Read16();
//! \brief Vector containing the list of EDFSignals contained in this edf file //! \brief Vector containing the list of EDFSignals contained in this edf file
QVector<EDFSignal *> edfsignals; QVector<EDFSignal> edfsignals;
//! \brief An by-name indexed into the EDFSignal data //! \brief An by-name indexed into the EDFSignal data
QHash<QString,EDFSignal *> lookup; QHash<QString,EDFSignal *> lookup;