MNE-CPP  beta 1.0
fiff_tag.h
Go to the documentation of this file.
1 //=============================================================================================================
36 #ifndef FIFF_TAG_H
37 #define FIFF_TAG_H
38 
39 //*************************************************************************************************************
40 //=============================================================================================================
41 // DEFINES
42 //=============================================================================================================
43 
44 /* NOTE:
45  The architecture is now deduced from the operating system, which is
46  a bit stupid way, since the same operating system can me run on various
47  architectures. This may need revision later on. */
48 
49 #if defined(DARWIN)
50 
51 #if defined(__LITTLE_ENDIAN__)
52 #define INTEL_X86_ARCH
53 #else
54 #define BIG_ENDIAN_ARCH
55 #endif
56 
57 #else
58 
59 #if defined(__hpux) || defined(__Lynx__) || defined(__sun)
60 #define BIG_ENDIAN_ARCH
61 #else
62 #if defined(__linux) || defined(WIN32) || defined(__APPLE__)
63 #define INTEL_X86_ARCH
64 #endif
65 
66 #endif
67 #endif
68 
69 #ifdef INTEL_X86_ARCH
70 #define NATIVE_ENDIAN FIFFV_LITTLE_ENDIAN
71 #endif
72 
73 #ifdef BIG_ENDIAN_ARCH
74 #define NATIVE_ENDIAN FIFFV_BIG_ENDIAN
75 #endif
76 
77 
78 //*************************************************************************************************************
79 //=============================================================================================================
80 // INCLUDES
81 //=============================================================================================================
82 
83 #include "fiff_global.h"
84 #include "fiff_constants.h"
85 #include "fiff_types.h"
86 #include "fiff_id.h"
87 #include "fiff_coord_trans.h"
88 #include "fiff_ch_info.h"
89 #include "fiff_ch_pos.h"
90 #include "fiff_stream.h"
91 
92 
93 //*************************************************************************************************************
94 //=============================================================================================================
95 // Eigen INCLUDES
96 //=============================================================================================================
97 
98 #include <Eigen/Core>
99 #include <Eigen/SparseCore>
100 
101 
102 //*************************************************************************************************************
103 //=============================================================================================================
104 // STL INCLUDES
105 //=============================================================================================================
106 
107 #include <complex>
108 #include <iostream>
109 
110 
111 //*************************************************************************************************************
112 //=============================================================================================================
113 // QT INCLUDES
114 //=============================================================================================================
115 
116 #include <QByteArray>
117 #include <QDataStream>
118 #include <QDebug>
119 #include <QFile>
120 #include <QList>
121 #include <QSharedPointer>
122 #include <QVector>
123 
124 
125 //*************************************************************************************************************
126 //=============================================================================================================
127 // DEFINE NAMESPACE FIFFLIB
128 //=============================================================================================================
129 
130 namespace FIFFLIB
131 {
132 
133 class FiffStream;
134 
135 //*************************************************************************************************************
136 //=============================================================================================================
137 // USED NAMESPACES
138 //=============================================================================================================
139 
140 //using namespace SOURCELAB;
141 using namespace Eigen;
142 
143 
144 //*************************************************************************************************************
145 //=============================================================================================================
146 // FORWARD DECLARATIONS
147 //=============================================================================================================
148 //
149 // The magic hexadecimal values
150 //
151 const fiff_int_t IS_MATRIX = 4294901760;
152 const fiff_int_t MATRIX_CODING_DENSE = 16384;
153 const fiff_int_t MATRIX_CODING_CCS = 16400;
154 const fiff_int_t MATRIX_CODING_RCS = 16416;
155 const fiff_int_t DATA_TYPE = 65535;
157 //=============================================================================================================
163 class FIFFSHARED_EXPORT FiffTag : public QByteArray {
164 
165 public:
166  typedef QSharedPointer<FiffTag> SPtr;
167  typedef QSharedPointer<const FiffTag> ConstSPtr;
169  //=========================================================================================================
173  FiffTag();
174 
175  //=========================================================================================================
179  FiffTag(const FiffTag* p_pFiffTag);
180 
181  //=========================================================================================================
185  ~FiffTag();
186 
187  //=========================================================================================================
200  static bool read_tag_data(FiffStream* p_pStream, FiffTag::SPtr& p_pTag, qint64 pos = -1);
201 
202  //=========================================================================================================
215  static bool read_tag_info(FiffStream* p_pStream, FiffTag::SPtr& p_pTag, bool p_bDoSkip = true);
216 
217  //=========================================================================================================
227  static bool read_rt_tag(FiffStream* p_pStream, FiffTag::SPtr& p_pTag);
228 
229  //=========================================================================================================
242  static bool read_tag(FiffStream* p_pStream, FiffTag::SPtr& p_pTag, qint64 pos = -1);
243 
244  //=========================================================================================================
250  fiff_int_t getMatrixCoding() const;
251 
252  //=========================================================================================================
258  bool isMatrix() const;
259 
260  //=========================================================================================================
269  bool getMatrixDimensions(qint32& p_ndim, QVector<qint32>& p_Dims) const;
270 
271  //=========================================================================================================
277  fiff_int_t getType() const;
278 
279  //=========================================================================================================
285  QString getInfo() const;
286 
287  //
288  // Simple types
289  //
290  //=========================================================================================================
297  inline quint8* toByte();
298 
299  //=========================================================================================================
306  inline quint16* toUnsignedShort();
307 
308  //=========================================================================================================
315  inline qint16* toShort();
316 
317  //=========================================================================================================
324  inline quint32* toUnsignedInt();
325 
326  //=========================================================================================================
333  inline qint32* toInt();
334 
335  //=========================================================================================================
342  inline float* toFloat();
343 
344  //=========================================================================================================
351  inline double* toDouble();
352 
353  //=========================================================================================================
359  inline QString toString();
360 
361  //=========================================================================================================
368  inline qint16* toDauPack16();
369 
370  //=========================================================================================================
377  inline std::complex<float>* toComplexFloat();
378 
379  //=========================================================================================================
386  inline std::complex<double>* toComplexDouble();
387 
388  //
389  // Structures
390  //
391  //=========================================================================================================
397  inline FiffId toFiffID() const;
398 
399  //=========================================================================================================
405  inline FiffDigPoint toDigPoint() const;
406 
407  //=========================================================================================================
413  inline FiffCoordTrans toCoordTrans() const;
414 
415  //=========================================================================================================
421  inline FiffChInfo toChInfo() const;
422 
423 
424 // //=========================================================================================================
425 // /**
426 // * to fiff OLD PACK
427 // */
428 // inline fiff_coord_trans_t toCoordTrans() const;
429 
430  //=========================================================================================================
436  inline QList<FiffDirEntry> toDirEntry() const;
437 
438 
439 // if (this->isMatrix())
440 // {
441 // switch(this->getType())
442 // {
443 // case FIFFT_INT:
444 // t_qStringInfo = "Matrix of type FIFFT_INT";
445 // break;
446 // case FIFFT_JULIAN:
447 // t_qStringInfo = "Matrix of type FIFFT_JULIAN";
448 // break;
449 // case FIFFT_FLOAT:
450 // t_qStringInfo = "Matrix of type FIFFT_FLOAT";
451 // break;
452 // case FIFFT_DOUBLE:
453 // t_qStringInfo = "Matrix of type FIFFT_DOUBLE";
454 // break;
455 // case FIFFT_COMPLEX_FLOAT:
456 // t_qStringInfo = "Matrix of type FIFFT_COMPLEX_FLOAT";
457 // break;
458 // case FIFFT_COMPLEX_DOUBLE:
459 // t_qStringInfo = "Matrix of type FIFFT_COMPLEX_DOUBLE";
460 // break;
461 // default:
462 // t_qStringInfo = "Matrix of unknown type";
463 // }
464 // }
465 
466 
467  //
468  // MATRIX
469  //
470  //=========================================================================================================
476  inline MatrixXi toIntMatrix() const;
477 
478  //=========================================================================================================
486  inline MatrixXf toFloatMatrix() const;
487 
488  //=========================================================================================================
496  inline SparseMatrix<double> toSparseFloatMatrix() const;
497 
498  //
499  //from fiff_combat.c
500  //
501 
502  //=========================================================================================================
508  static void convert_ch_pos(FiffChPos* pos);
509 
510 // static void fiff_convert_tag_info(FiffTag*& tag);
511 
512  //=========================================================================================================
518  static void convert_matrix_from_file_data(FiffTag::SPtr tag);
519 
520  //=========================================================================================================
526  static void convert_matrix_to_file_data(FiffTag::SPtr tag);
527 
528  //
529  // Data type conversions for the little endian systems.
530  //
531  //=========================================================================================================
545  static void convert_tag_data(FiffTag::SPtr tag, int from_endian, int to_endian);
546 
547  //
548  // from fiff_type_spec.c
549  //
550  //=========================================================================================================
556  static fiff_int_t fiff_type_fundamental(fiff_int_t type);
557 
558  //=========================================================================================================
564  static fiff_int_t fiff_type_base(fiff_int_t type);
565 
566  //=========================================================================================================
572  static fiff_int_t fiff_type_matrix_coding(fiff_int_t type);
573 
574 
575 public:
576  fiff_int_t kind;
578  fiff_int_t type;
580 // fiff_int_t size; /**< Size of the data.
581 // * The size is given in bytes and defines the
582 // * total size of the data. */
583  fiff_int_t next;
587 // QByteArray* data; /**< Pointer to the data.
588 // * This point to the data read or to be written. */
589 private:
590  std::complex<float>* m_pComplexFloatData;
591 
592  std::complex<double>* m_pComplexDoubleData;
593 
594 };
595 
596 //*************************************************************************************************************
597 //=============================================================================================================
598 // INLINE DEFINITIONS
599 //=============================================================================================================
600 
601 //*************************************************************************************************************
602 //=============================================================================================================
603 // Simple types
604 //=============================================================================================================
605 
606 inline quint8* FiffTag::toByte()
607 {
608  if(this->isMatrix() || this->getType() != FIFFT_BYTE)
609  return NULL;
610  else
611  return (quint8*)this->data();
612 }
613 
614 
615 //*************************************************************************************************************
616 
617 inline quint16* FiffTag::toUnsignedShort()
618 {
619  if(this->isMatrix() || this->getType() != FIFFT_USHORT)
620  return NULL;
621  else
622  return (quint16*)this->data();
623 }
624 
625 
626 //*************************************************************************************************************
627 
628 inline qint16* FiffTag::toShort()
629 {
630  if(this->isMatrix() || this->getType() != FIFFT_SHORT)
631  return NULL;
632  else
633  return (qint16*)this->data();
634 }
635 
636 
637 //*************************************************************************************************************
638 
639 inline quint32* FiffTag::toUnsignedInt()
640 {
641  if(this->isMatrix() || this->getType() != FIFFT_UINT)
642  return NULL;
643  else
644  return (quint32*)this->data();
645 }
646 
647 
648 //*************************************************************************************************************
649 
650 inline qint32* FiffTag::toInt()
651 {
652  if(this->isMatrix() || this->getType() != FIFFT_INT)
653  return NULL;
654  else
655  return (qint32*)this->data();
656 }
657 
658 
659 //*************************************************************************************************************
660 
661 inline float* FiffTag::toFloat()
662 {
663  if(this->isMatrix() || this->getType() != FIFFT_FLOAT)
664  return NULL;
665  else
666  return (float*)this->data();
667 }
668 
669 
670 //*************************************************************************************************************
671 
672 inline double* FiffTag::toDouble()
673 {
674  if(this->isMatrix() || this->getType() != FIFFT_DOUBLE)
675  return NULL;
676  else
677  return (double*)this->data();
678 }
679 
680 
681 //*************************************************************************************************************
682 
683 inline QString FiffTag::toString()
684 {
685  if(this->isMatrix() || this->getType() != FIFFT_STRING)
686  return NULL;
687  else
688  return *this;
689 }
690 
691 
692 //*************************************************************************************************************
693 
694 inline qint16* FiffTag::toDauPack16()
695 {
696  if(this->isMatrix() || this->getType() != FIFFT_DAU_PACK16)
697  return NULL;
698  else
699  return (qint16*)this->data();
700 }
701 
702 
703 //*************************************************************************************************************
704 
705 inline std::complex<float>* FiffTag::toComplexFloat()
706 {
707  if(this->isMatrix() || this->getType() != FIFFT_COMPLEX_FLOAT)
708  return NULL;
709  else if(this->m_pComplexFloatData == NULL)
710  {
711  float* t_pFloat = (float*)this->data();
712  qDebug() << "ToDo toComplexFloat";
713  //ToDo check this for arrays which contains more than one value
714  this->m_pComplexFloatData = new std::complex<float>(t_pFloat[0],t_pFloat[1]);
715  }
716  return m_pComplexFloatData;
717 }
718 
719 
720 //*************************************************************************************************************
721 
722 inline std::complex<double>* FiffTag::toComplexDouble()
723 {
724  if(this->isMatrix() || this->getType() != FIFFT_COMPLEX_DOUBLE)
725  return NULL;
726  else if(this->m_pComplexDoubleData == NULL)
727  {
728  double* t_pDouble = (double*)this->data();
729  qDebug() << "ToDo toComplexDouble";
730  //ToDo check this for arrays which contains more than one value
731  this->m_pComplexDoubleData = new std::complex<double>(t_pDouble[0],t_pDouble[1]);
732  }
733  return m_pComplexDoubleData;
734 }
735 
736 //*************************************************************************************************************
737 //=============================================================================================================
738 // Structures
739 //=============================================================================================================
740 
741 inline FiffId FiffTag::toFiffID() const
742 {
743  FiffId p_fiffID;
744  if(this->isMatrix() || this->getType() != FIFFT_ID_STRUCT || this->data() == NULL)
745  return p_fiffID;
746  else
747  {
748  qint32* t_pInt32 = (qint32*)this->data();
749 // memcpy (&t_fiffID,this->data,this->size);
750 
751  p_fiffID.version = t_pInt32[0];
752  p_fiffID.machid[0] = t_pInt32[1];
753  p_fiffID.machid[1] = t_pInt32[2];
754  p_fiffID.time.secs = t_pInt32[3];
755  p_fiffID.time.usecs = t_pInt32[4];
756 
757  return p_fiffID;
758  }
759 }
760 
761 
762 //*************************************************************************************************************
763 
765 {
766 
767  FiffDigPoint t_fiffDigPoint;
768  if(this->isMatrix() || this->getType() != FIFFT_DIG_POINT_STRUCT || this->data() == NULL)
769  return t_fiffDigPoint;
770  else
771  {
772  qint32* t_pInt32 = (qint32*)this->data();
773 // memcpy (&t_fiffDigPoint,this->data,this->size);
774 
775  t_fiffDigPoint.kind = t_pInt32[0];
776  t_fiffDigPoint.ident = t_pInt32[1];
777 
778  float* t_pFloat = (float*)this->data();
779  t_fiffDigPoint.r[0] = t_pFloat[2];
780  t_fiffDigPoint.r[1] = t_pFloat[3];
781  t_fiffDigPoint.r[2] = t_pFloat[4];
782  t_fiffDigPoint.coord_frame = 0;
783 
784  return t_fiffDigPoint;
785  }
786 }
787 
788 
789 //*************************************************************************************************************
790 
792 {
793 
794  FiffCoordTrans p_FiffCoordTrans;
795  if(this->isMatrix() || this->getType() != FIFFT_COORD_TRANS_STRUCT || this->data() == NULL)
796  return p_FiffCoordTrans;
797  else
798  {
799  qint32* t_pInt32 = (qint32*)this->data();
800  p_FiffCoordTrans.from = t_pInt32[0];
801  p_FiffCoordTrans.to = t_pInt32[1];
802 
803  p_FiffCoordTrans.trans.setIdentity(4,4);
804  float* t_pFloat = (float*)this->data();
805  int count = 0;
806  int r, c;
807  for (r = 0; r < 3; ++r) {
808  p_FiffCoordTrans.trans(r,3) = t_pFloat[11+r];
809  for (c = 0; c < 3; ++c) {
810  p_FiffCoordTrans.trans(r,c) = t_pFloat[2+count];
811  ++count;
812  }
813  }
814 
815  p_FiffCoordTrans.invtrans.setIdentity(4,4);
816  count = 0;
817  for (r = 0; r < 3; ++r) {
818  p_FiffCoordTrans.invtrans(r,3) = t_pFloat[23+r];
819  for (c = 0; c < 3; ++c) {
820  p_FiffCoordTrans.invtrans(r,c) = t_pFloat[14+count];
821  ++count;
822  }
823  }
824 
825  return p_FiffCoordTrans;
826  }
827 }
828 
829 
830 //=========================================================================================================
835 {
836  FiffChInfo p_FiffChInfo;
837 
838  if(this->isMatrix() || this->getType() != FIFFT_CH_INFO_STRUCT || this->data() == NULL)
839  return p_FiffChInfo;
840  else
841  {
842  qint32* t_pInt32 = (qint32*)this->data();
843  p_FiffChInfo.scanno = t_pInt32[0];
844  p_FiffChInfo.logno = t_pInt32[1];
845  p_FiffChInfo.kind = t_pInt32[2];
846  float* t_pFloat = (float*)this->data();
847  p_FiffChInfo.range = t_pFloat[3];
848  p_FiffChInfo.cal = t_pFloat[4];
849  p_FiffChInfo.coil_type = t_pInt32[5];
850 
851  //
852  // Read the coil coordinate system definition
853  //
854  qint32 count = 0;
855  qint32 r, c;
856  for (r = 0; r < 12; ++r) {
857  p_FiffChInfo.loc(r,0) = t_pFloat[6+r];
858  }
859 
860  p_FiffChInfo.coord_frame = FIFFV_COORD_UNKNOWN;
861 
862  //
863  // Convert loc into a more useful format
864  //
865  if (p_FiffChInfo.kind == FIFFV_MEG_CH || p_FiffChInfo.kind == FIFFV_REF_MEG_CH)
866  {
867  p_FiffChInfo.coil_trans.setIdentity(4,4);
868  for (r = 0; r < 3; ++r) {
869  p_FiffChInfo.coil_trans(r,3) = p_FiffChInfo.loc(r,0);
870  for (c = 0; c < 3; ++c) {
871  p_FiffChInfo.coil_trans(c,r) = p_FiffChInfo.loc(3+count,0);//its transposed stored (r and c are exchanged)
872  ++count;
873  }
874  }
875  p_FiffChInfo.coord_frame = FIFFV_COORD_DEVICE;
876  }
877  else if (p_FiffChInfo.kind == FIFFV_EEG_CH)
878  {
879  if (p_FiffChInfo.loc.block(3,0,3,1).norm() > 0)
880  {
881  p_FiffChInfo.eeg_loc.block(0,0,3,1) = p_FiffChInfo.loc.block(0,0,3,1);
882  p_FiffChInfo.eeg_loc.block(0,1,3,1) = p_FiffChInfo.loc.block(3,0,3,1);
883  }
884  else
885  {
886  p_FiffChInfo.eeg_loc.block(0,0,3,1) = p_FiffChInfo.loc.block(0,0,3,1);
887  }
888  p_FiffChInfo.coord_frame = FIFFV_COORD_HEAD;
889  }
890  //
891  // Unit and exponent
892  //
893  p_FiffChInfo.unit = t_pInt32[18];
894  p_FiffChInfo.unit_mul = t_pInt32[19];
895 
896  //
897  // Handle the channel name
898  //
899  char* orig = (char*)this->data();
900  p_FiffChInfo.ch_name = QString::fromUtf8(orig + 80);
901 
902  return p_FiffChInfo;
903  }
904 }
905 
906 
907 // //=========================================================================================================
908 // /**
909 // * to fiff OLD PACK
910 // */
911 // inline fiff_coord_trans_t toCoordTrans() const
912 // {
913 
914 
915 // }
916 
917 
918 
919 //*************************************************************************************************************
920 
921 inline QList<FiffDirEntry> FiffTag::toDirEntry() const
922 {
923 // tag.data = struct('kind',{},'type',{},'size',{},'pos',{});
924  QList<FiffDirEntry> p_ListFiffDir;
925  if(this->isMatrix() || this->getType() != FIFFT_DIR_ENTRY_STRUCT || this->data() == NULL)
926  return p_ListFiffDir;
927  else
928  {
929  FiffDirEntry t_fiffDirEntry;
930  qint32* t_pInt32 = (qint32*)this->data();
931  for (int k = 0; k < this->size()/16; ++k)
932  {
933  t_fiffDirEntry.kind = t_pInt32[k*4];//fread(fid,1,'int32');
934  t_fiffDirEntry.type = t_pInt32[k*4+1];//fread(fid,1,'uint32');
935  t_fiffDirEntry.size = t_pInt32[k*4+2];//fread(fid,1,'int32');
936  t_fiffDirEntry.pos = t_pInt32[k*4+3];//fread(fid,1,'int32');
937  p_ListFiffDir.append(t_fiffDirEntry);
938  }
939  }
940  return p_ListFiffDir;
941 }
942 
943 
944 //*************************************************************************************************************
945 //=============================================================================================================
946 // MATRIX
947 //=============================================================================================================
948 
949 //*************************************************************************************************************
950 
951 inline MatrixXi FiffTag::toIntMatrix() const
952 {
953  if(!this->isMatrix() || this->getType() != FIFFT_INT || this->data() == NULL)
954  return MatrixXi();
955 
956  qint32 ndim;
957  QVector<qint32> dims;
958  this->getMatrixDimensions(ndim, dims);
959 
960  if (ndim != 2)
961  {
962  printf("Only two-dimensional matrices are supported at this time");
963  return MatrixXi();
964  }
965 
966  //MatrixXd p_Matrix = Map<MatrixXd>( (float*)this->data,p_dims[0], p_dims[1]);
967  // --> Use copy constructor instead --> slower performance but higher memory management reliability
968  MatrixXi p_Matrix(Map<MatrixXi>( (int*)this->data(),dims[0], dims[1]));
969 
970  return p_Matrix;
971 }
972 
973 
974 //*************************************************************************************************************
975 
976 inline MatrixXf FiffTag::toFloatMatrix() const
977 {
978  if(!this->isMatrix() || this->getType() != FIFFT_FLOAT || this->data() == NULL)
979  return MatrixXf();//NULL;
980 
981  if (fiff_type_matrix_coding(this->type) != FIFFTS_MC_DENSE)
982  {
983  printf("Error in FiffTag::toFloatMatrix(): Matrix is not dense!\n");
984  return MatrixXf();//NULL;
985  }
986 
987  qint32 ndim;
988  QVector<qint32> dims;
989  this->getMatrixDimensions(ndim, dims);
990 
991  if (ndim != 2)
992  {
993  printf("Only two-dimensional matrices are supported at this time");
994  return MatrixXf();//NULL;
995  }
996 
997  // --> Use copy constructor instead --> slower performance but higher memory management reliability
998  MatrixXf p_Matrix((Map<MatrixXf>( (float*)this->data(),dims[0], dims[1])));
999 
1000  return p_Matrix;
1001 }
1002 
1003 
1004 //*************************************************************************************************************
1005 
1006 inline SparseMatrix<double> FiffTag::toSparseFloatMatrix() const
1007 {
1008  if(!this->isMatrix() || this->getType() != FIFFT_FLOAT || this->data() == NULL)
1009  return SparseMatrix<double>();//NULL;
1010 
1011  if (fiff_type_matrix_coding(this->type) != FIFFTS_MC_CCS && fiff_type_matrix_coding(this->type) != FIFFTS_MC_RCS)
1012  {
1013  printf("Error in FiffTag::toSparseFloatMatrix(): Matrix is not sparse!\n");
1014  return SparseMatrix<double>();//NULL;
1015  }
1016 
1017  qint32 ndim;
1018  QVector<qint32> dims;
1019  this->getMatrixDimensions(ndim, dims);
1020 
1021  if (ndim != 2)
1022  {
1023  printf("Only two-dimensional matrices are supported at this time");
1024  return SparseMatrix<double>();//NULL;
1025  }
1026 
1027  qint32 nnz = dims[0];
1028  qint32 nrow = dims[1];
1029  qint32 ncol = dims[2];
1030 
1031  typedef Eigen::Triplet<double> T;
1032  std::vector<T> tripletList;
1033  tripletList.reserve(nnz);
1034 
1035  float *t_pFloat = (float*)this->data();
1036  int *t_pInt = (int*)this->data();
1037  qint32 offset1 = nnz;
1038  qint32 offset2 = 2*nnz;
1039  if (fiff_type_matrix_coding(this->type) == FIFFTS_MC_CCS)
1040  {
1041  //
1042  // CCS
1043  //
1044  qWarning("Warning in FiffTag::toSparseFloatMatrix(): CCS has to be debugged - never done before.");
1045 // for(qint32 i = 0; i < nnz; ++i)
1046 // tripletList.push_back(T(t_pInt[offset1+i], 0, (double)(t_pFloat[i])));
1047  qint32 p = 0;
1048  for(qint32 j = 0; j < ncol; ++j)
1049  {
1050  while( p < t_pInt[offset2+j+1])
1051  {
1052 // tripletList[p] = T(tripletList[p].row(), j, tripletList[p].value());
1053  tripletList.push_back(T(t_pInt[offset1+p], j, (double)(t_pFloat[p])));
1054  ++p;
1055  }
1056  }
1057  }
1058  else
1059  {
1060  //
1061  // RCS
1062  //
1063 // for(qint32 i = 0; i < nnz; ++i)
1064 // tripletList.push_back(T(0, t_pInt[offset1+i], (double)(t_pFloat[i])));
1065  qint32 p = 0;
1066  for(qint32 j = 0; j < nrow; ++j)
1067  {
1068  while( p < t_pInt[offset2+j+1])
1069  {
1070 // tripletList[p] = T(j, tripletList[p].col(), tripletList[p].value());
1071  tripletList.push_back(T(j, t_pInt[offset1+p], (double)(t_pFloat[p])));
1072  ++p;
1073  }
1074  }
1075  }
1076 
1077 // std::cout << "Size: " << tripletList.size() << std::endl;
1078 // qint32 offsetTest = tripletList.size() - 10;
1079 // for(qint32 i = 0; i < 10; ++i)
1080 // std::cout << std::endl << tripletList[offsetTest + i].row() << " " << tripletList[offsetTest + i].col() << " " << tripletList[offsetTest + i].value();
1081 
1082 
1083  SparseMatrix<double> p_Matrix(nrow, ncol);
1084  p_Matrix.setFromTriplets(tripletList.begin(), tripletList.end());
1085 
1086  p_Matrix.insert(nrow-1, ncol-1) = 0.0;
1087 
1088  return p_Matrix;
1089 }
1090 
1091 } // NAMESPACE
1092 
1093 #endif // FIFF_TAG_H
std::complex< float > * toComplexFloat()
Definition: fiff_tag.h:705
quint16 * toUnsignedShort()
Definition: fiff_tag.h:617
fiff_int_t kind
qint16 * toDauPack16()
Definition: fiff_tag.h:694
Directory entry description.
Old fiff_type declarations - replace them.
fiff_int_t version
Definition: fiff_id.h:127
Digitization point description.
fiff_float_t range
Definition: fiff_ch_info.h:125
Universially unique identifier.
Definition: fiff_id.h:78
FiffCoordTrans toCoordTrans() const
Definition: fiff_tag.h:791
FiffDigPoint toDigPoint() const
Definition: fiff_tag.h:764
QString toString()
Definition: fiff_tag.h:683
QSharedPointer< FiffTag > SPtr
Definition: fiff_tag.h:166
FiffId toFiffID() const
Definition: fiff_tag.h:741
fiff_float_t cal
Definition: fiff_ch_info.h:126
Fiff constants.
fiff_int_t kind
Definition: fiff_tag.h:576
Matrix< double, 4, 4, DontAlign > coil_trans
Definition: fiff_ch_info.h:135
qint16 * toShort()
Definition: fiff_tag.h:628
float * toFloat()
Definition: fiff_tag.h:661
fiff_int_t pos
quint32 * toUnsignedInt()
Definition: fiff_tag.h:639
fiff_int_t size
QSharedPointer< const FiffTag > ConstSPtr
Definition: fiff_tag.h:167
Matrix< float, 4, 4, DontAlign > invtrans
FiffChInfo class declaration.
qint32 * toInt()
Definition: fiff_tag.h:650
#define FIFFSHARED_EXPORT
Definition: fiff_global.h:58
QList< FiffDirEntry > toDirEntry() const
Definition: fiff_tag.h:921
FiffStream class declaration.
#define FIFFV_COORD_UNKNOWN
Channel info descriptor.
Definition: fiff_ch_info.h:87
Fiff library export/import macros.
Definition: fiff.h:98
fiff_int_t type
FiffChInfo toChInfo() const
Definition: fiff_tag.h:834
FiffId class declaration.
fiff_int_t coord_frame
Definition: fiff_ch_info.h:137
fiff_int_t machid[2]
Definition: fiff_id.h:128
fiff_int_t next
Definition: fiff_tag.h:583
Coordinate transformation description.
Coil position.
Definition: fiff_ch_pos.h:76
double * toDouble()
Definition: fiff_tag.h:672
fiffTimeRec time
Definition: fiff_id.h:129
FIFF data tag.
Definition: fiff_tag.h:163
std::complex< double > * toComplexDouble()
Definition: fiff_tag.h:722
fiff_int_t type
Definition: fiff_tag.h:578
fiff_int_t coil_type
Definition: fiff_ch_info.h:128
FiffChPos class declaration.
Matrix< double, 3, 2, DontAlign > eeg_loc
Definition: fiff_ch_info.h:136
FIFF File I/O routines.
Definition: fiff_stream.h:129
MatrixXi toIntMatrix() const
Definition: fiff_tag.h:951
FiffCoordTrans class declaration.
SparseMatrix< double > toSparseFloatMatrix() const
Definition: fiff_tag.h:1006
quint8 * toByte()
Definition: fiff_tag.h:606
Matrix< double, 12, 1, DontAlign > loc
Definition: fiff_ch_info.h:130
Matrix< float, 4, 4, DontAlign > trans
MatrixXf toFloatMatrix() const
Definition: fiff_tag.h:976