MNE-CPP  0.1.9
A Framework for Electrophysiology
fiff_raw_data.cpp
Go to the documentation of this file.
1 //=============================================================================================================
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "fiff_raw_data.h"
42 #include "fiff_tag.h"
43 #include "fiff_stream.h"
44 #include "cstdlib"
45 
46 //=============================================================================================================
47 // USED NAMESPACES
48 //=============================================================================================================
49 
50 using namespace FIFFLIB;
51 using namespace Eigen;
52 
53 //=============================================================================================================
54 // DEFINE MEMBER METHODS
55 //=============================================================================================================
56 
58 : first_samp(-1)
59 , last_samp(-1)
60 {
61 }
62 
63 //=============================================================================================================
64 
65 FiffRawData::FiffRawData(QIODevice &p_IODevice)
66 : first_samp(-1)
67 , last_samp(-1)
68 {
69  //setup FiffRawData object
70  if(!FiffStream::setup_read_raw(p_IODevice, *this))
71  {
72  printf("\tError during fiff setup raw read.\n");
73  //exit(EXIT_FAILURE); //ToDo Throw here, e.g.: throw std::runtime_error("IO Error! File not found");
74  return;
75  }
76 }
77 
78 //=============================================================================================================
79 
80 FiffRawData::FiffRawData(QIODevice &p_IODevice, bool b_littleEndian)
81 : first_samp(-1)
82 , last_samp(-1)
83 {
84  //setup FiffRawData object
85  if(!FiffStream::setup_read_raw(p_IODevice, *this, false, b_littleEndian))
86  {
87  printf("\tError during fiff setup raw read.\n");
88  //exit(EXIT_FAILURE); //ToDo Throw here, e.g.: throw std::runtime_error("IO Error! File not found");
89  return;
90  }
91 }
92 
93 //=============================================================================================================
94 
96 : file(p_FiffRawData.file)
97 , info(p_FiffRawData.info)
98 , first_samp(p_FiffRawData.first_samp)
99 , last_samp(p_FiffRawData.last_samp)
100 , cals(p_FiffRawData.cals)
101 , rawdir(p_FiffRawData.rawdir)
102 , proj(p_FiffRawData.proj)
103 , comp(p_FiffRawData.comp)
104 {
105 }
106 
107 //=============================================================================================================
108 
110 {
111 }
112 
113 //=============================================================================================================
114 
116 {
117  info.clear();
118  first_samp = -1;
119  last_samp = -1;
120  cals = RowVectorXd();
121  rawdir.clear();
122  proj = MatrixXd();
123  comp.clear();
124 }
125 
126 //=============================================================================================================
127 #include <QElapsedTimer>
128 #include <QDebug>
129 bool FiffRawData::read_raw_segment(MatrixXd& data,
130  MatrixXd& times,
131  fiff_int_t from,
132  fiff_int_t to,
133  const RowVectorXi& sel,
134  bool do_debug) const
135 {
136  bool projAvailable = true;
137 
138  if (this->proj.size() == 0) {
139  //qDebug() << "FiffRawData::read_raw_segment - No projectors setup. Consider calling MNE::setup_compensators.";
140  projAvailable = false;
141  }
142 
143  if(from == -1)
144  from = this->first_samp;
145  if(to == -1)
146  to = this->last_samp;
147  //
148  // Initial checks
149  //
150  if(from < this->first_samp)
151  from = this->first_samp;
152  if(to > this->last_samp)
153  to = this->last_samp;
154  //
155  if(from > to)
156  {
157  printf("No data in this range %d ... %d = %9.3f ... %9.3f secs...", from, to, ((float)from)/this->info.sfreq, ((float)to)/this->info.sfreq);
158  return false;
159  }
160  //printf("Reading %d ... %d = %9.3f ... %9.3f secs...", from, to, ((float)from)/this->info.sfreq, ((float)to)/this->info.sfreq);
161  //
162  // Initialize the data and calibration vector
163  //
164  qint32 nchan = this->info.nchan;
165  qint32 dest = 0;//1;
166  qint32 i, k, r;
167 
168  typedef Eigen::Triplet<double> T;
169  std::vector<T> tripletList;
170  tripletList.reserve(nchan);
171  for(i = 0; i < nchan; ++i)
172  tripletList.push_back(T(i, i, this->cals[i]));
173 
174  SparseMatrix<double> cal(nchan, nchan);
175  cal.setFromTriplets(tripletList.begin(), tripletList.end());
176 // cal.makeCompressed();
177 
178  MatrixXd mult_full;
179  //
180  if (sel.size() == 0)
181  {
182  data = MatrixXd(nchan, to-from+1);
183 // data->setZero();
184  if (projAvailable || this->comp.kind != -1)
185  {
186  if (!projAvailable)
187  mult_full = this->comp.data->data*cal;
188  else if (this->comp.kind == -1)
189  mult_full = this->proj*cal;
190  else
191  mult_full = this->proj*this->comp.data->data*cal;
192  }
193  }
194  else
195  {
196  data = MatrixXd(sel.size(),to-from+1);
197 // data->setZero();
198 
199  MatrixXd selVect(sel.size(), nchan);
200 
201  selVect.setZero();
202 
203  if (!projAvailable && this->comp.kind == -1)
204  {
205  tripletList.clear();
206  tripletList.reserve(sel.size());
207  for(i = 0; i < sel.size(); ++i)
208  tripletList.push_back(T(i, i, this->cals[sel[i]]));
209  cal = SparseMatrix<double>(sel.size(), sel.size());
210  cal.setFromTriplets(tripletList.begin(), tripletList.end());
211  }
212  else
213  {
214  if (!projAvailable)
215  {
216  qDebug() << "This has to be debugged! #1";
217  for( i = 0; i < sel.size(); ++i)
218  selVect.row(i) = this->comp.data->data.block(sel[i],0,1,nchan);
219  mult_full = selVect*cal;
220  }
221  else if (this->comp.kind == -1)
222  {
223  for( i = 0; i < sel.size(); ++i)
224  selVect.row(i) = this->proj.block(sel[i],0,1,nchan);
225 
226  mult_full = selVect*cal;
227  }
228  else
229  {
230  qDebug() << "This has to be debugged! #3";
231  for( i = 0; i < sel.size(); ++i)
232  selVect.row(i) = this->proj.block(sel[i],0,1,nchan);
233 
234  mult_full = selVect*this->comp.data->data*cal;
235  }
236  }
237  }
238 
239  //
240  // Make mult sparse
241  //
242  tripletList.clear();
243  tripletList.reserve(mult_full.rows()*mult_full.cols());
244  for(i = 0; i < mult_full.rows(); ++i)
245  for(k = 0; k < mult_full.cols(); ++k)
246  if(mult_full(i,k) != 0)
247  tripletList.push_back(T(i, k, mult_full(i,k)));
248 
249  SparseMatrix<double> mult(mult_full.rows(),mult_full.cols());
250  if(tripletList.size() > 0)
251  mult.setFromTriplets(tripletList.begin(), tripletList.end());
252 // mult.makeCompressed();
253 
254  FiffStream::SPtr fid;
255  if (!this->file->device()->isOpen())
256  {
257  if (!this->file->device()->open(QIODevice::ReadOnly))
258  {
259  printf("Cannot open file %s",this->info.filename.toUtf8().constData());
260  }
261  fid = this->file;
262  }
263  else
264  {
265  fid = this->file;
266  }
267 
268  MatrixXd one, newData, tmp_data;
269  FiffRawDir thisRawDir;
270  FiffTag::SPtr t_pTag;
271  fiff_int_t first_pick, last_pick, picksamp;
272  for(k = 0; k < this->rawdir.size(); ++k)
273  {
274  thisRawDir = this->rawdir[k];
275  //
276  // Do we need this buffer
277  //
278  if (thisRawDir.last > from)
279  {
280  if (thisRawDir.ent->kind == -1)
281  {
282  //
283  // Take the easy route: skip is translated to zeros
284  //
285  if(do_debug)
286  printf("S");
287  if (sel.cols() <= 0)
288  one.resize(nchan,thisRawDir.nsamp);
289  else
290  one.resize(sel.cols(),thisRawDir.nsamp);
291 
292  one.setZero();
293  }
294  else
295  {
296  fid->read_tag(t_pTag, thisRawDir.ent->pos);
297  //
298  // Depending on the state of the projection and selection
299  // we proceed a little bit differently
300  //
301  if (mult.cols() == 0)
302  {
303  if (sel.cols() == 0)
304  {
305  if (t_pTag->type == FIFFT_DAU_PACK16)
306  one = cal*(Map< MatrixDau16 >( t_pTag->toDauPack16(),nchan, thisRawDir.nsamp)).cast<double>();
307  else if(t_pTag->type == FIFFT_INT)
308  one = cal*(Map< MatrixXi >( t_pTag->toInt(),nchan, thisRawDir.nsamp)).cast<double>();
309  else if(t_pTag->type == FIFFT_FLOAT)
310  one = cal*(Map< MatrixXf >( t_pTag->toFloat(),nchan, thisRawDir.nsamp)).cast<double>();
311  else if(t_pTag->type == FIFFT_SHORT)
312  one = cal*(Map< MatrixShort >( t_pTag->toShort(),nchan, thisRawDir.nsamp)).cast<double>();
313  else
314  printf("Data Storage Format not known yet [1]!! Type: %d\n", t_pTag->type);
315  }
316  else
317  {
318  //ToDo find a faster solution for this!! --> make cal and mul sparse like in MATLAB
319  newData.resize(sel.cols(), thisRawDir.nsamp); //ToDo this can be done much faster, without newData
320 
321  if (t_pTag->type == FIFFT_DAU_PACK16)
322  {
323  tmp_data = (Map< MatrixDau16 > ( t_pTag->toDauPack16(),nchan, thisRawDir.nsamp)).cast<double>();
324 
325  for(r = 0; r < sel.size(); ++r)
326  newData.block(r,0,1,thisRawDir.nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.nsamp);
327  }
328  else if(t_pTag->type == FIFFT_INT)
329  {
330  tmp_data = (Map< MatrixXi >( t_pTag->toInt(),nchan, thisRawDir.nsamp)).cast<double>();
331 
332  for(r = 0; r < sel.size(); ++r)
333  newData.block(r,0,1,thisRawDir.nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.nsamp);
334  }
335  else if(t_pTag->type == FIFFT_FLOAT)
336  {
337  tmp_data = (Map< MatrixXf > ( t_pTag->toFloat(),nchan, thisRawDir.nsamp)).cast<double>();
338 
339  for(r = 0; r < sel.size(); ++r)
340  newData.block(r,0,1,thisRawDir.nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.nsamp);
341  }
342  else if(t_pTag->type == FIFFT_SHORT)
343  {
344  tmp_data = (Map< MatrixShort > ( t_pTag->toShort(),nchan, thisRawDir.nsamp)).cast<double>();
345 
346  for(r = 0; r < sel.size(); ++r)
347  newData.block(r,0,1,thisRawDir.nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.nsamp);
348  }
349  else
350  {
351  printf("Data Storage Format not known yet [2]!! Type: %d\n", t_pTag->type);
352  }
353 
354  one = cal*newData;
355  }
356  }
357  else
358  {
359  if (t_pTag->type == FIFFT_DAU_PACK16)
360  one = mult*(Map< MatrixDau16 >( t_pTag->toDauPack16(),nchan, thisRawDir.nsamp)).cast<double>();
361  else if(t_pTag->type == FIFFT_INT)
362  one = mult*(Map< MatrixXi >( t_pTag->toInt(),nchan, thisRawDir.nsamp)).cast<double>();
363  else if(t_pTag->type == FIFFT_FLOAT)
364  one = mult*(Map< MatrixXf >( t_pTag->toFloat(),nchan, thisRawDir.nsamp)).cast<double>();
365  else
366  printf("Data Storage Format not known yet [3]!! Type: %d\n", t_pTag->type);
367  }
368  }
369  //
370  // The picking logic is a bit complicated
371  //
372  if (to >= thisRawDir.last && from <= thisRawDir.first)
373  {
374  //
375  // We need the whole buffer
376  //
377  first_pick = 0;//1;
378  last_pick = thisRawDir.nsamp - 1;
379  if (do_debug)
380  printf("W");
381  }
382  else if (from > thisRawDir.first)
383  {
384  first_pick = from - thisRawDir.first;// + 1;
385  if(to < thisRawDir.last)
386  {
387  //
388  // Something from the middle
389  //
390 // qDebug() << "This needs to be debugged!";
391  last_pick = thisRawDir.nsamp + to - thisRawDir.last - 1;//is this alright?
392  if (do_debug)
393  printf("M");
394  }
395  else
396  {
397  //
398  // From the middle to the end
399  //
400  last_pick = thisRawDir.nsamp - 1;
401  if (do_debug)
402  printf("E");
403  }
404  }
405  else
406  {
407  //
408  // From the beginning to the middle
409  //
410  first_pick = 0;//1;
411  last_pick = to - thisRawDir.first;// + 1;
412  if (do_debug)
413  printf("B");
414  }
415  //
416  // Now we are ready to pick
417  //
418  picksamp = last_pick - first_pick + 1;
419 
420  if(do_debug)
421  {
422  qDebug() << "first_pick: " << first_pick;
423  qDebug() << "last_pick: " << last_pick;
424  qDebug() << "picksamp: " << picksamp;
425  }
426 
427  if (picksamp > 0)
428  {
429 // for(r = 0; r < data->rows(); ++r)
430 // for(c = 0; c < picksamp; ++c)
431 // (*data)(r,dest + c) = one(r,first_pick + c);
432  data.block(0,dest,data.rows(),picksamp) = one.block(0, first_pick, data.rows(), picksamp);
433 
434  dest += picksamp;
435  }
436  }
437  //
438  // Done?
439  //
440  if (thisRawDir.last >= to)
441  {
442  //printf(" [done]\n");
443  break;
444  }
445  }
446 
447  if (!this->file->device()->isOpen()) {
448  this->file->device()->close();
449  }
450 
451  times = MatrixXd(1, to-from+1);
452 
453  for (i = 0; i < times.cols(); ++i)
454  times(0, i) = ((float)(from+i)) / this->info.sfreq;
455 
456  return true;
457 }
458 
459 //=============================================================================================================
460 
461 bool FiffRawData::read_raw_segment(MatrixXd& data,
462  MatrixXd& times,
463  SparseMatrix<double>& multSegment,
464  fiff_int_t from,
465  fiff_int_t to,
466  const RowVectorXi& sel,
467  bool do_debug) const
468 {
469  bool projAvailable = true;
470 
471  if (this->proj.size() == 0) {
472  //qInfo() << "FiffRawData::read_raw_segment - No projectors setup. Consider calling MNE::setup_compensators.";
473  projAvailable = false;
474  }
475 
476  if(from == -1)
477  from = this->first_samp;
478  if(to == -1)
479  to = this->last_samp;
480  //
481  // Initial checks
482  //
483  if(from < this->first_samp)
484  from = this->first_samp;
485  if(to > this->last_samp)
486  to = this->last_samp;
487  //
488  if(from > to)
489  {
490  printf("No data in this range\n");
491  return false;
492  }
493  //printf("Reading %d ... %d = %9.3f ... %9.3f secs...", from, to, ((float)from)/this->info.sfreq, ((float)to)/this->info.sfreq);
494  //
495  // Initialize the data and calibration vector
496  //
497  qint32 nchan = this->info.nchan;
498  qint32 dest = 0;//1;
499  qint32 i, k, r;
500 
501  typedef Eigen::Triplet<double> T;
502  std::vector<T> tripletList;
503  tripletList.reserve(nchan);
504  for(i = 0; i < nchan; ++i)
505  tripletList.push_back(T(i, i, this->cals[i]));
506 
507  SparseMatrix<double> cal(nchan, nchan);
508  cal.setFromTriplets(tripletList.begin(), tripletList.end());
509 // cal.makeCompressed();
510 
511  MatrixXd mult_full;
512  //
513  if (sel.size() == 0)
514  {
515  data = MatrixXd(nchan, to-from+1);
516 // data->setZero();
517  if (projAvailable || this->comp.kind != -1)
518  {
519  if (!projAvailable)
520  mult_full = this->comp.data->data*cal;
521  else if (this->comp.kind == -1)
522  mult_full = this->proj*cal;
523  else
524  mult_full = this->proj*this->comp.data->data*cal;
525  }
526  }
527  else
528  {
529  data = MatrixXd(sel.size(),to-from+1);
530 // data->setZero();
531 
532  MatrixXd selVect(sel.size(), nchan);
533 
534  selVect.setZero();
535 
536  if (!projAvailable && this->comp.kind == -1)
537  {
538  tripletList.clear();
539  tripletList.reserve(sel.size());
540  for(i = 0; i < sel.size(); ++i)
541  tripletList.push_back(T(i, i, this->cals[sel[i]]));
542  cal = SparseMatrix<double>(sel.size(), sel.size());
543  cal.setFromTriplets(tripletList.begin(), tripletList.end());
544  }
545  else
546  {
547  if (!projAvailable)
548  {
549  qDebug() << "This has to be debugged! #1";
550  for( i = 0; i < sel.size(); ++i)
551  selVect.row(i) = this->comp.data->data.block(sel[i],0,1,nchan);
552  mult_full = selVect*cal;
553  }
554  else if (this->comp.kind == -1)
555  {
556  for( i = 0; i < sel.size(); ++i)
557  selVect.row(i) = this->proj.block(sel[i],0,1,nchan);
558 
559  mult_full = selVect*cal;
560  }
561  else
562  {
563  qDebug() << "This has to be debugged! #3";
564  for( i = 0; i < sel.size(); ++i)
565  selVect.row(i) = this->proj.block(sel[i],0,1,nchan);
566 
567  mult_full = selVect*this->comp.data->data*cal;
568  }
569  }
570  }
571 
572  //
573  // Make mult sparse
574  //
575  tripletList.clear();
576  tripletList.reserve(mult_full.rows()*mult_full.cols());
577  for(i = 0; i < mult_full.rows(); ++i)
578  for(k = 0; k < mult_full.cols(); ++k)
579  if(mult_full(i,k) != 0)
580  tripletList.push_back(T(i, k, mult_full(i,k)));
581 
582  SparseMatrix<double> mult(mult_full.rows(),mult_full.cols());
583  if(tripletList.size() > 0)
584  mult.setFromTriplets(tripletList.begin(), tripletList.end());
585 // mult.makeCompressed();
586 
587  //
588 
589  FiffStream::SPtr fid;
590  if (!this->file->device()->isOpen())
591  {
592  if (!this->file->device()->open(QIODevice::ReadOnly))
593  {
594  printf("Cannot open file %s",this->info.filename.toUtf8().constData());
595  }
596  fid = this->file;
597  }
598  else
599  {
600  fid = this->file;
601  }
602 
603  MatrixXd one;
604  fiff_int_t first_pick, last_pick, picksamp;
605  for(k = 0; k < this->rawdir.size(); ++k)
606  {
607  FiffRawDir thisRawDir = this->rawdir[k];
608  //
609  // Do we need this buffer
610  //
611  if (thisRawDir.last > from)
612  {
613  if (thisRawDir.ent->kind == -1)
614  {
615  //
616  // Take the easy route: skip is translated to zeros
617  //
618  if(do_debug)
619  printf("S");
620  if (sel.cols() <= 0)
621  one.resize(nchan,thisRawDir.nsamp);
622  else
623  one.resize(sel.cols(),thisRawDir.nsamp);
624 
625  one.setZero();
626  }
627  else
628  {
629  FiffTag::SPtr t_pTag;
630  fid->read_tag(t_pTag, thisRawDir.ent->pos);
631  //
632  // Depending on the state of the projection and selection
633  // we proceed a little bit differently
634  //
635  if (mult.cols() == 0)
636  {
637  if (sel.cols() == 0)
638  {
639  if (t_pTag->type == FIFFT_DAU_PACK16)
640  one = cal*(Map< MatrixDau16 >( t_pTag->toDauPack16(),nchan, thisRawDir.nsamp)).cast<double>();
641  else if(t_pTag->type == FIFFT_INT)
642  one = cal*(Map< MatrixXi >( t_pTag->toInt(),nchan, thisRawDir.nsamp)).cast<double>();
643  else if(t_pTag->type == FIFFT_FLOAT)
644  one = cal*(Map< MatrixXf >( t_pTag->toFloat(),nchan, thisRawDir.nsamp)).cast<double>();
645  else if(t_pTag->type == FIFFT_SHORT)
646  one = cal*(Map< MatrixShort >( t_pTag->toShort(),nchan, thisRawDir.nsamp)).cast<double>();
647  else
648  printf("Data Storage Format not known yet [1]!! Type: %d\n", t_pTag->type);
649  }
650  else
651  {
652 
653  //ToDo find a faster solution for this!! --> make cal and mul sparse like in MATLAB
654  MatrixXd newData(sel.cols(), thisRawDir.nsamp); //ToDo this can be done much faster, without newData
655 
656  if (t_pTag->type == FIFFT_DAU_PACK16)
657  {
658  MatrixXd tmp_data = (Map< MatrixDau16 > ( t_pTag->toDauPack16(),nchan, thisRawDir.nsamp)).cast<double>();
659 
660  for(r = 0; r < sel.size(); ++r)
661  newData.block(r,0,1,thisRawDir.nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.nsamp);
662  }
663  else if(t_pTag->type == FIFFT_INT)
664  {
665  MatrixXd tmp_data = (Map< MatrixXi >( t_pTag->toInt(),nchan, thisRawDir.nsamp)).cast<double>();
666 
667  for(r = 0; r < sel.size(); ++r)
668  newData.block(r,0,1,thisRawDir.nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.nsamp);
669  }
670  else if(t_pTag->type == FIFFT_FLOAT)
671  {
672  MatrixXd tmp_data = (Map< MatrixXf > ( t_pTag->toFloat(),nchan, thisRawDir.nsamp)).cast<double>();
673 
674  for(r = 0; r < sel.size(); ++r)
675  newData.block(r,0,1,thisRawDir.nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.nsamp);
676  }
677  else if(t_pTag->type == FIFFT_SHORT)
678  {
679  MatrixXd tmp_data = (Map< MatrixShort > ( t_pTag->toShort(),nchan, thisRawDir.nsamp)).cast<double>();
680 
681  for(r = 0; r < sel.size(); ++r)
682  newData.block(r,0,1,thisRawDir.nsamp) = tmp_data.block(sel[r],0,1,thisRawDir.nsamp);
683  }
684  else
685  {
686  printf("Data Storage Format not known yet [2]!! Type: %d\n", t_pTag->type);
687  }
688 
689  one = cal*newData;
690  }
691  }
692  else
693  {
694  if (t_pTag->type == FIFFT_DAU_PACK16)
695  one = mult*(Map< MatrixDau16 >( t_pTag->toDauPack16(),nchan, thisRawDir.nsamp)).cast<double>();
696  else if(t_pTag->type == FIFFT_INT)
697  one = mult*(Map< MatrixXi >( t_pTag->toInt(),nchan, thisRawDir.nsamp)).cast<double>();
698  else if(t_pTag->type == FIFFT_FLOAT)
699  one = mult*(Map< MatrixXf >( t_pTag->toFloat(),nchan, thisRawDir.nsamp)).cast<double>();
700  else
701  printf("Data Storage Format not known yet [3]!! Type: %d\n", t_pTag->type);
702  }
703  }
704  //
705  // The picking logic is a bit complicated
706  //
707  if (to >= thisRawDir.last && from <= thisRawDir.first)
708  {
709  //
710  // We need the whole buffer
711  //
712  first_pick = 0;//1;
713  last_pick = thisRawDir.nsamp - 1;
714  if (do_debug)
715  printf("W");
716  }
717  else if (from > thisRawDir.first)
718  {
719  first_pick = from - thisRawDir.first;// + 1;
720  if(to < thisRawDir.last)
721  {
722  //
723  // Something from the middle
724  //
725 // qDebug() << "This needs to be debugged!";
726  last_pick = thisRawDir.nsamp + to - thisRawDir.last - 1;//is this alright?
727  if (do_debug)
728  printf("M");
729  }
730  else
731  {
732  //
733  // From the middle to the end
734  //
735  last_pick = thisRawDir.nsamp - 1;
736  if (do_debug)
737  printf("E");
738  }
739  }
740  else
741  {
742  //
743  // From the beginning to the middle
744  //
745  first_pick = 0;//1;
746  last_pick = to - thisRawDir.first;// + 1;
747  if (do_debug)
748  printf("B");
749  }
750  //
751  // Now we are ready to pick
752  //
753  picksamp = last_pick - first_pick + 1;
754 
755  if(do_debug)
756  {
757  qDebug() << "first_pick: " << first_pick;
758  qDebug() << "last_pick: " << last_pick;
759  qDebug() << "picksamp: " << picksamp;
760  }
761 
762  if (picksamp > 0)
763  {
764 // for(r = 0; r < data->rows(); ++r)
765 // for(c = 0; c < picksamp; ++c)
766 // (*data)(r,dest + c) = one(r,first_pick + c);
767  data.block(0,dest,data.rows(),picksamp) = one.block(0, first_pick, data.rows(), picksamp);
768 
769  dest += picksamp;
770  }
771  }
772  //
773  // Done?
774  //
775  if (thisRawDir.last >= to)
776  {
777  //printf(" [done]\n");
778  break;
779  }
780  }
781 
782  if(mult.cols()==0)
783  multSegment = cal;
784  else
785  multSegment = mult;
786 
787  if (!this->file->device()->isOpen()) {
788  this->file->device()->close();
789  }
790 
791  times = MatrixXd(1, to-from+1);
792 
793  for (i = 0; i < times.cols(); ++i)
794  times(0, i) = ((float)(from+i)) / this->info.sfreq;
795 
796  return true;
797 }
798 
799 //=============================================================================================================
800 
802  MatrixXd& times,
803  float from,
804  float to,
805  const RowVectorXi& sel) const
806 {
807  //
808  // Convert to samples
809  //
810  from = floor(from*this->info.sfreq);
811  to = ceil(to*this->info.sfreq);
812  //
813  // Read it
814  //
815  return this->read_raw_segment(data, times, (qint32)from, (qint32)to, sel);
816 }
FIFFLIB::FiffRawData::first_samp
fiff_int_t first_samp
Definition: fiff_raw_data.h:198
FIFFLIB::FiffRawData::FiffRawData
FiffRawData()
Definition: fiff_raw_data.cpp:57
FIFFLIB::FiffRawData::rawdir
QList< FiffRawDir > rawdir
Definition: fiff_raw_data.h:201
FIFFLIB::FiffRawData
FIFF raw measurement data.
Definition: fiff_raw_data.h:78
FIFFLIB::FiffRawDir::nsamp
fiff_int_t nsamp
Definition: fiff_raw_dir.h:98
fiff_tag.h
FiffTag class declaration, which provides fiff tag I/O and processing methods.
FIFFLIB::FiffStream::SPtr
QSharedPointer< FiffStream > SPtr
Definition: fiff_stream.h:107
FIFFLIB::FiffRawData::proj
Eigen::MatrixXd proj
Definition: fiff_raw_data.h:202
FIFFLIB::FiffRawDir::first
fiff_int_t first
Definition: fiff_raw_dir.h:96
FIFFLIB::FiffRawData::read_raw_segment
bool read_raw_segment(Eigen::MatrixXd &data, Eigen::MatrixXd &times, fiff_int_t from=-1, fiff_int_t to=-1, const Eigen::RowVectorXi &sel=defaultRowVectorXi, bool do_debug=false) const
fiff_stream.h
FiffStream class declaration.
FIFFLIB::FiffStream::setup_read_raw
static bool setup_read_raw(QIODevice &p_IODevice, FiffRawData &data, bool allow_maxshield=true, bool is_littleEndian=false)
Definition: fiff_stream.cpp:1711
k
int k
Definition: fiff_tag.cpp:322
FIFFLIB::FiffRawDir
Raw Directory entry.
Definition: fiff_raw_dir.h:68
FIFFLIB::FiffCtfComp::data
FiffNamedMatrix::SDPtr data
Definition: fiff_ctf_comp.h:111
FIFFLIB::FiffInfo::clear
void clear()
Definition: fiff_info.cpp:110
FIFFLIB::FiffRawData::read_raw_segment_times
bool read_raw_segment_times(Eigen::MatrixXd &data, Eigen::MatrixXd &times, float from, float to, const Eigen::RowVectorXi &sel=defaultRowVectorXi) const
Definition: fiff_raw_data.cpp:801
FIFFLIB::FiffInfo::sfreq
float sfreq
Definition: fiff_info.h:254
FIFFLIB::FiffTag::SPtr
QSharedPointer< FiffTag > SPtr
Definition: fiff_tag.h:152
FIFFLIB::FiffRawData::info
FiffInfo info
Definition: fiff_raw_data.h:197
FIFFLIB::FiffRawDir::last
fiff_int_t last
Definition: fiff_raw_dir.h:97
FIFFLIB::FiffInfoBase::nchan
fiff_int_t nchan
Definition: fiff_info_base.h:222
FIFFLIB::FiffCtfComp::clear
void clear()
Definition: fiff_ctf_comp.cpp:82
FIFFLIB::FiffCtfComp::kind
fiff_int_t kind
Definition: fiff_ctf_comp.h:107
FIFFLIB::FiffRawData::cals
Eigen::RowVectorXd cals
Definition: fiff_raw_data.h:200
FIFFLIB::FiffRawData::file
FiffStream::SPtr file
Definition: fiff_raw_data.h:196
FIFFLIB::FiffInfoBase::filename
QString filename
Definition: fiff_info_base.h:219
FIFFLIB::FiffRawData::clear
void clear()
Definition: fiff_raw_data.cpp:115
fiff_raw_data.h
FiffRawData class declaration.
FIFFLIB::FiffRawData::last_samp
fiff_int_t last_samp
Definition: fiff_raw_data.h:199
FIFFLIB::FiffRawDir::ent
FiffDirEntry::SPtr ent
Definition: fiff_raw_dir.h:95
FIFFLIB::FiffRawData::~FiffRawData
~FiffRawData()
Definition: fiff_raw_data.cpp:109
FIFFLIB::FiffRawData::comp
FiffCtfComp comp
Definition: fiff_raw_data.h:203