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
70 #define NATIVE_ENDIAN FIFFV_LITTLE_ENDIAN
73 #ifdef BIG_ENDIAN_ARCH
74 #define NATIVE_ENDIAN FIFFV_BIG_ENDIAN
99 #include <Eigen/SparseCore>
116 #include <QByteArray>
117 #include <QDataStream>
121 #include <QSharedPointer>
141 using namespace Eigen;
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;
166 typedef QSharedPointer<FiffTag>
SPtr;
250 fiff_int_t getMatrixCoding()
const;
258 bool isMatrix()
const;
269 bool getMatrixDimensions(qint32& p_ndim, QVector<qint32>& p_Dims)
const;
277 fiff_int_t getType()
const;
285 QString getInfo()
const;
297 inline quint8* toByte();
306 inline quint16* toUnsignedShort();
315 inline qint16* toShort();
324 inline quint32* toUnsignedInt();
333 inline qint32* toInt();
342 inline float* toFloat();
351 inline double* toDouble();
359 inline QString toString();
368 inline qint16* toDauPack16();
377 inline std::complex<float>* toComplexFloat();
386 inline std::complex<double>* toComplexDouble();
397 inline FiffId toFiffID()
const;
436 inline QList<FiffDirEntry> toDirEntry()
const;
476 inline MatrixXi toIntMatrix()
const;
486 inline MatrixXf toFloatMatrix()
const;
496 inline SparseMatrix<double> toSparseFloatMatrix()
const;
508 static void convert_ch_pos(
FiffChPos* pos);
518 static void convert_matrix_from_file_data(
FiffTag::SPtr tag);
545 static void convert_tag_data(
FiffTag::SPtr tag,
int from_endian,
int to_endian);
556 static fiff_int_t fiff_type_fundamental(fiff_int_t type);
564 static fiff_int_t fiff_type_base(fiff_int_t type);
572 static fiff_int_t fiff_type_matrix_coding(fiff_int_t type);
590 std::complex<float>* m_pComplexFloatData;
592 std::complex<double>* m_pComplexDoubleData;
608 if(this->isMatrix() || this->getType() != FIFFT_BYTE)
611 return (quint8*)this->data();
619 if(this->isMatrix() || this->getType() != FIFFT_USHORT)
622 return (quint16*)this->data();
630 if(this->isMatrix() || this->getType() != FIFFT_SHORT)
633 return (qint16*)this->data();
641 if(this->isMatrix() || this->getType() != FIFFT_UINT)
644 return (quint32*)this->data();
652 if(this->isMatrix() || this->getType() != FIFFT_INT)
655 return (qint32*)this->data();
663 if(this->isMatrix() || this->getType() != FIFFT_FLOAT)
666 return (
float*)this->data();
674 if(this->isMatrix() || this->getType() != FIFFT_DOUBLE)
677 return (
double*)this->data();
685 if(this->isMatrix() || this->getType() != FIFFT_STRING)
696 if(this->isMatrix() || this->getType() != FIFFT_DAU_PACK16)
699 return (qint16*)this->data();
707 if(this->isMatrix() || this->getType() != FIFFT_COMPLEX_FLOAT)
709 else if(this->m_pComplexFloatData == NULL)
711 float* t_pFloat = (
float*)this->data();
712 qDebug() <<
"ToDo toComplexFloat";
714 this->m_pComplexFloatData =
new std::complex<float>(t_pFloat[0],t_pFloat[1]);
716 return m_pComplexFloatData;
724 if(this->isMatrix() || this->getType() != FIFFT_COMPLEX_DOUBLE)
726 else if(this->m_pComplexDoubleData == NULL)
728 double* t_pDouble = (
double*)this->data();
729 qDebug() <<
"ToDo toComplexDouble";
731 this->m_pComplexDoubleData =
new std::complex<double>(t_pDouble[0],t_pDouble[1]);
733 return m_pComplexDoubleData;
744 if(this->isMatrix() || this->getType() != FIFFT_ID_STRUCT || this->data() == NULL)
748 qint32* t_pInt32 = (qint32*)this->data();
751 p_fiffID.
version = t_pInt32[0];
752 p_fiffID.
machid[0] = t_pInt32[1];
753 p_fiffID.
machid[1] = t_pInt32[2];
768 if(this->isMatrix() || this->getType() != FIFFT_DIG_POINT_STRUCT || this->data() == NULL)
769 return t_fiffDigPoint;
772 qint32* t_pInt32 = (qint32*)this->data();
775 t_fiffDigPoint.
kind = t_pInt32[0];
776 t_fiffDigPoint.
ident = t_pInt32[1];
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];
784 return t_fiffDigPoint;
795 if(this->isMatrix() || this->getType() != FIFFT_COORD_TRANS_STRUCT || this->data() == NULL)
796 return p_FiffCoordTrans;
799 qint32* t_pInt32 = (qint32*)this->data();
800 p_FiffCoordTrans.
from = t_pInt32[0];
801 p_FiffCoordTrans.
to = t_pInt32[1];
803 p_FiffCoordTrans.
trans.setIdentity(4,4);
804 float* t_pFloat = (
float*)this->data();
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];
815 p_FiffCoordTrans.
invtrans.setIdentity(4,4);
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];
825 return p_FiffCoordTrans;
838 if(this->isMatrix() || this->getType() != FIFFT_CH_INFO_STRUCT || this->data() == NULL)
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];
856 for (r = 0; r < 12; ++r) {
857 p_FiffChInfo.
loc(r,0) = t_pFloat[6+r];
865 if (p_FiffChInfo.
kind == FIFFV_MEG_CH || p_FiffChInfo.
kind == FIFFV_REF_MEG_CH)
868 for (r = 0; r < 3; ++r) {
870 for (c = 0; c < 3; ++c) {
877 else if (p_FiffChInfo.
kind == FIFFV_EEG_CH)
879 if (p_FiffChInfo.
loc.block(3,0,3,1).norm() > 0)
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);
886 p_FiffChInfo.
eeg_loc.block(0,0,3,1) = p_FiffChInfo.
loc.block(0,0,3,1);
893 p_FiffChInfo.
unit = t_pInt32[18];
894 p_FiffChInfo.
unit_mul = t_pInt32[19];
899 char* orig = (
char*)this->data();
900 p_FiffChInfo.
ch_name = QString::fromUtf8(orig + 80);
924 QList<FiffDirEntry> p_ListFiffDir;
925 if(this->isMatrix() || this->getType() != FIFFT_DIR_ENTRY_STRUCT || this->data() == NULL)
926 return p_ListFiffDir;
930 qint32* t_pInt32 = (qint32*)this->data();
931 for (
int k = 0; k < this->size()/16; ++k)
933 t_fiffDirEntry.
kind = t_pInt32[k*4];
934 t_fiffDirEntry.
type = t_pInt32[k*4+1];
935 t_fiffDirEntry.
size = t_pInt32[k*4+2];
936 t_fiffDirEntry.
pos = t_pInt32[k*4+3];
937 p_ListFiffDir.append(t_fiffDirEntry);
940 return p_ListFiffDir;
953 if(!this->isMatrix() || this->getType() != FIFFT_INT || this->data() == NULL)
957 QVector<qint32> dims;
958 this->getMatrixDimensions(ndim, dims);
962 printf(
"Only two-dimensional matrices are supported at this time");
968 MatrixXi p_Matrix(Map<MatrixXi>( (
int*)this->data(),dims[0], dims[1]));
978 if(!this->isMatrix() || this->getType() != FIFFT_FLOAT || this->data() == NULL)
981 if (fiff_type_matrix_coding(this->type) != FIFFTS_MC_DENSE)
983 printf(
"Error in FiffTag::toFloatMatrix(): Matrix is not dense!\n");
988 QVector<qint32> dims;
989 this->getMatrixDimensions(ndim, dims);
993 printf(
"Only two-dimensional matrices are supported at this time");
998 MatrixXf p_Matrix((Map<MatrixXf>( (
float*)this->data(),dims[0], dims[1])));
1008 if(!this->isMatrix() || this->getType() != FIFFT_FLOAT || this->data() == NULL)
1009 return SparseMatrix<double>();
1011 if (fiff_type_matrix_coding(this->type) != FIFFTS_MC_CCS && fiff_type_matrix_coding(this->type) != FIFFTS_MC_RCS)
1013 printf(
"Error in FiffTag::toSparseFloatMatrix(): Matrix is not sparse!\n");
1014 return SparseMatrix<double>();
1018 QVector<qint32> dims;
1019 this->getMatrixDimensions(ndim, dims);
1023 printf(
"Only two-dimensional matrices are supported at this time");
1024 return SparseMatrix<double>();
1027 qint32 nnz = dims[0];
1028 qint32 nrow = dims[1];
1029 qint32 ncol = dims[2];
1031 typedef Eigen::Triplet<double> T;
1032 std::vector<T> tripletList;
1033 tripletList.reserve(nnz);
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)
1044 qWarning(
"Warning in FiffTag::toSparseFloatMatrix(): CCS has to be debugged - never done before.");
1048 for(qint32 j = 0; j < ncol; ++j)
1050 while( p < t_pInt[offset2+j+1])
1053 tripletList.push_back(T(t_pInt[offset1+p], j, (
double)(t_pFloat[p])));
1066 for(qint32 j = 0; j < nrow; ++j)
1068 while( p < t_pInt[offset2+j+1])
1071 tripletList.push_back(T(j, t_pInt[offset1+p], (
double)(t_pFloat[p])));
1083 SparseMatrix<double> p_Matrix(nrow, ncol);
1084 p_Matrix.setFromTriplets(tripletList.begin(), tripletList.end());
1086 p_Matrix.insert(nrow-1, ncol-1) = 0.0;
1093 #endif // FIFF_TAG_H
std::complex< float > * toComplexFloat()
quint16 * toUnsignedShort()
Directory entry description.
Old fiff_type declarations - replace them.
Digitization point description.
Universially unique identifier.
FiffCoordTrans toCoordTrans() const
FiffDigPoint toDigPoint() const
QSharedPointer< FiffTag > SPtr
Matrix< double, 4, 4, DontAlign > coil_trans
quint32 * toUnsignedInt()
QSharedPointer< const FiffTag > ConstSPtr
Matrix< float, 4, 4, DontAlign > invtrans
FiffChInfo class declaration.
#define FIFFSHARED_EXPORT
QList< FiffDirEntry > toDirEntry() const
FiffStream class declaration.
#define FIFFV_COORD_UNKNOWN
Fiff library export/import macros.
FiffChInfo toChInfo() const
FiffId class declaration.
Coordinate transformation description.
std::complex< double > * toComplexDouble()
FiffChPos class declaration.
Matrix< double, 3, 2, DontAlign > eeg_loc
MatrixXi toIntMatrix() const
FiffCoordTrans class declaration.
SparseMatrix< double > toSparseFloatMatrix() const
Matrix< double, 12, 1, DontAlign > loc
Matrix< float, 4, 4, DontAlign > trans
MatrixXf toFloatMatrix() const