51 #if defined(__LITTLE_ENDIAN__)
52 #define INTEL_X86_ARCH
54 #define BIG_ENDIAN_ARCH
59 #if defined(__hpux) || defined(__Lynx__) || defined(__sun)
60 #define BIG_ENDIAN_ARCH
62 #if defined(__linux) || defined(WIN32) || defined(__APPLE__)
63 #define INTEL_X86_ARCH
69 #define NATIVE_ENDIAN FIFFV_LITTLE_ENDIAN
72 #define NATIVE_ENDIAN FIFFV_LITTLE_ENDIAN
75 #ifdef BIG_ENDIAN_ARCH
76 #define NATIVE_ENDIAN FIFFV_BIG_ENDIAN
101 #include <Eigen/Core>
102 #include <Eigen/SparseCore>
109 #include <QByteArray>
111 #include <QSharedPointer>
130 #define IS_MATRIX 0xFFFF0000
131 #define MATRIX_CODING_DENSE 0x00004000
132 #define MATRIX_CODING_CCS 0x00004010
133 #define MATRIX_CODING_RCS 0x00004020
134 #define DATA_TYPE 0x0000FFFF
136 //const fiff_int_t IS_MATRIX = 4294901760;
137 //const fiff_int_t MATRIX_CODING_DENSE = 16384;
138 //const fiff_int_t MATRIX_CODING_CCS = 16400;
139 //const fiff_int_t MATRIX_CODING_RCS = 16416;
140 //const fiff_int_t DATA_TYPE = 65535;
142 //=============================================================================================================
152 typedef QSharedPointer<FiffTag>
SPtr;
179 fiff_int_t getMatrixCoding()
const;
187 bool isMatrix()
const;
199 bool getMatrixDimensions(qint32& p_ndim, QVector<qint32>& p_Dims)
const;
207 fiff_int_t getType()
const;
215 QString getInfo()
const;
227 inline quint8* toByte()
const;
236 inline quint16* toUnsignedShort()
const;
245 inline qint16* toShort()
const;
254 inline quint32* toUnsignedInt()
const;
263 inline qint32* toInt()
const;
272 inline qint32* toJulian()
const;
281 inline float* toFloat()
const;
290 inline double* toDouble()
const;
298 inline QString toString()
const;
307 inline qint16* toDauPack16()
const;
336 inline FiffId toFiffID()
const;
374 inline QList< QSharedPointer<FiffDirEntry> > toDirEntry()
const;
385 inline Eigen::MatrixXi toIntMatrix()
const;
395 inline Eigen::MatrixXf toFloatMatrix()
const;
405 inline Eigen::SparseMatrix<double> toSparseFloatMatrix()
const;
417 static void convert_ch_pos(
FiffChPos* pos);
442 static void convert_matrix_from_file_data(
FiffTag::SPtr tag);
469 static void convert_tag_data(
FiffTag::SPtr tag,
int from_endian,
int to_endian);
480 static fiff_int_t fiff_type_fundamental(fiff_int_t type);
488 static fiff_int_t fiff_type_base(fiff_int_t type);
496 static fiff_int_t fiff_type_matrix_coding(fiff_int_t type);
548 return (quint8*)this->data();
558 return (quint16*)this->data();
568 return (qint16*)this->data();
578 return (quint32*)this->data();
586 printf(
"Expected an integer tag : %d (found data type %d instead)\n",this->
kind,this->
getType());
590 return (qint32*)this->data();
598 printf(
"Expected a julian tag : %d (found data type %d instead)\n",this->
kind,this->
getType());
602 return (qint32*)this->data();
612 return (
float*)this->data();
622 return (
double*)this->data();
642 return (qint16*)this->data();
684 if(this->
isMatrix() || this->
getType() != FIFFT_ID_STRUCT || this->data() == NULL)
688 const qint32* t_pInt32 = (qint32*)this->data();
690 p_fiffID.
version = t_pInt32[0];
691 p_fiffID.
machid[0] = t_pInt32[1];
692 p_fiffID.
machid[1] = t_pInt32[2];
706 if(this->
isMatrix() || this->
getType() != FIFFT_DIG_POINT_STRUCT || this->data() == NULL)
707 return t_fiffDigPoint;
710 qint32* t_pInt32 = (qint32*)this->data();
713 t_fiffDigPoint.
kind = t_pInt32[0];
714 t_fiffDigPoint.
ident = t_pInt32[1];
716 float* t_pFloat = (
float*)this->data();
717 t_fiffDigPoint.
r[0] = t_pFloat[2];
718 t_fiffDigPoint.
r[1] = t_pFloat[3];
719 t_fiffDigPoint.
r[2] = t_pFloat[4];
722 return t_fiffDigPoint;
732 if(this->
isMatrix() || this->
getType() != FIFFT_COORD_TRANS_STRUCT || this->data() == NULL)
733 return p_FiffCoordTrans;
736 qint32* t_pInt32 = (qint32*)this->data();
737 p_FiffCoordTrans.
from = t_pInt32[0];
738 p_FiffCoordTrans.
to = t_pInt32[1];
740 p_FiffCoordTrans.
trans.setIdentity(4,4);
741 float* t_pFloat = (
float*)this->data();
744 for (r = 0; r < 3; ++r) {
745 p_FiffCoordTrans.
trans(r,3) = t_pFloat[11+r];
746 for (c = 0; c < 3; ++c) {
747 p_FiffCoordTrans.
trans(r,c) = t_pFloat[2+count];
752 p_FiffCoordTrans.
invtrans.setIdentity(4,4);
754 for (r = 0; r < 3; ++r) {
755 p_FiffCoordTrans.
invtrans(r,3) = t_pFloat[23+r];
756 for (c = 0; c < 3; ++c) {
757 p_FiffCoordTrans.
invtrans(r,c) = t_pFloat[14+count];
762 return p_FiffCoordTrans;
774 if(this->
isMatrix() || this->
getType() != FIFFT_CH_INFO_STRUCT || this->data() == NULL)
778 qint32* t_pInt32 = (qint32*)this->data();
779 p_FiffChInfo.
scanNo = t_pInt32[0];
780 p_FiffChInfo.
logNo = t_pInt32[1];
781 p_FiffChInfo.
kind = t_pInt32[2];
782 float* t_pFloat = (
float*)this->data();
783 p_FiffChInfo.
range = t_pFloat[3];
784 p_FiffChInfo.
cal = t_pFloat[4];
792 for (r = 0; r < 3; ++r)
793 p_FiffChInfo.
chpos.
r0[r] = t_pFloat[6+r];
795 for (r = 0; r < 3; ++r)
796 p_FiffChInfo.
chpos.
ex[r] = t_pFloat[6+3+r];
798 for (r = 0; r < 3; ++r)
799 p_FiffChInfo.
chpos.
ey[r] = t_pFloat[6+6+r];
801 for (r = 0; r < 3; ++r)
802 p_FiffChInfo.
chpos.
ez[r] = t_pFloat[6+9+r];
813 for (r = 0; r < 3; ++r)
816 for (r = 0; r < 3; ++r)
819 for (r = 0; r < 3; ++r)
822 for (r = 0; r < 3; ++r)
827 else if (p_FiffChInfo.
kind == FIFFV_EEG_CH)
829 if (p_FiffChInfo.
chpos.
ex.norm() > 0) {
830 p_FiffChInfo.
eeg_loc.block(0,0,3,1) = p_FiffChInfo.
chpos.
r0.block(0,0,3,1);
831 p_FiffChInfo.
eeg_loc.block(0,1,3,1) = p_FiffChInfo.
chpos.
ex.block(0,0,3,1);
834 p_FiffChInfo.
eeg_loc.block(0,0,3,1) = p_FiffChInfo.
chpos.
r0.block(0,0,3,1);
841 p_FiffChInfo.
unit = t_pInt32[18];
842 p_FiffChInfo.
unit_mul = t_pInt32[19];
847 char* orig = (
char*)this->data();
848 p_FiffChInfo.
ch_name = QString::fromUtf8(orig + 80).replace(
" ",
"");
868 QList< QSharedPointer<FiffDirEntry> > p_ListFiffDir;
869 if(this->
isMatrix() || this->
getType() != FIFFT_DIR_ENTRY_STRUCT || this->data() == NULL)
870 return p_ListFiffDir;
873 QSharedPointer<FiffDirEntry> t_pFiffDirEntry;
874 qint32* t_pInt32 = (qint32*)this->data();
875 for (
int k = 0;
k < this->size()/16; ++
k)
877 t_pFiffDirEntry = QSharedPointer<FiffDirEntry>(
new FiffDirEntry);
878 t_pFiffDirEntry->kind = t_pInt32[
k*4];
879 t_pFiffDirEntry->type = t_pInt32[
k*4+1];
880 t_pFiffDirEntry->size = t_pInt32[
k*4+2];
881 t_pFiffDirEntry->pos = t_pInt32[
k*4+3];
882 p_ListFiffDir.append(t_pFiffDirEntry);
885 return p_ListFiffDir;
896 if(!this->
isMatrix() || this->
getType() != FIFFT_INT || this->data() == NULL)
897 return Eigen::MatrixXi();
900 QVector<qint32> dims;
905 printf(
"Only two-dimensional matrices are supported at this time");
906 return Eigen::MatrixXi();
911 Eigen::MatrixXi p_Matrix(Eigen::Map<Eigen::MatrixXi>( (
int*)this->data(),dims[0], dims[1]));
920 if(!this->
isMatrix() || this->
getType() != FIFFT_FLOAT || this->data() == NULL)
921 return Eigen::MatrixXf();
925 printf(
"Error in FiffTag::toFloatMatrix(): Matrix is not dense!\n");
926 return Eigen::MatrixXf();
930 QVector<qint32> dims;
935 printf(
"Only two-dimensional matrices are supported at this time");
936 return Eigen::MatrixXf();
940 Eigen::MatrixXf p_Matrix((Eigen::Map<Eigen::MatrixXf>( (
float*)this->data(),dims[0], dims[1])));
949 if(!this->
isMatrix() || this->
getType() != FIFFT_FLOAT || this->data() == NULL)
950 return Eigen::SparseMatrix<double>();
954 printf(
"Error in FiffTag::toSparseFloatMatrix(): Matrix is not sparse!\n");
955 return Eigen::SparseMatrix<double>();
959 QVector<qint32> dims;
964 printf(
"Only two-dimensional matrices are supported at this time");
965 return Eigen::SparseMatrix<double>();
968 qint32 nnz = dims[0];
969 qint32 nrow = dims[1];
970 qint32 ncol = dims[2];
972 typedef Eigen::Triplet<double> T;
973 std::vector<T> tripletList;
974 tripletList.reserve(nnz);
976 float *t_pFloat = (
float*)this->data();
977 int *t_pInt = (
int*)this->data();
978 qint32 offset1 = nnz;
979 qint32 offset2 = 2*nnz;
985 qWarning(
"Warning in FiffTag::toSparseFloatMatrix(): CCS has to be debugged - never done before.");
987 for(qint32 j = 0; j < ncol; ++j)
989 while( p < t_pInt[offset2+j+1])
992 tripletList.push_back(T(t_pInt[offset1+p], j, (
double)(t_pFloat[p])));
1003 for(qint32 j = 0; j < nrow; ++j)
1005 while( p < t_pInt[offset2+j+1])
1008 tripletList.push_back(T(j, t_pInt[offset1+p], (
double)(t_pFloat[p])));
1019 Eigen::SparseMatrix<double> p_Matrix(nrow, ncol);
1020 p_Matrix.setFromTriplets(tripletList.begin(), tripletList.end());
1026 #endif // FIFF_TAG_H