Ejemplo n.º 1
0
bool FiffDigPointSet::readFromStream(FiffStream::SPtr &p_pStream, FiffDigPointSet &p_Dig)
{
    //
    //   Open the file, create directory
    //
    bool open_here = false;

    if (!p_pStream->device()->isOpen()) {
        QString t_sFileName = p_pStream->streamName();

        if(!p_pStream->open())
            return false;

        printf("Opening header data %s...\n",t_sFileName.toUtf8().constData());

        open_here = true;
    }

    //
    //   Read the measurement info
    //
    //read_hpi_info(p_pStream,p_Tree, info);
    fiff_int_t kind = -1;
    fiff_int_t pos = -1;
    FiffTag::SPtr t_pTag;

    //
    //   Locate the Electrodes
    //
    QList<FiffDirNode::SPtr> isotrak = p_pStream->dirtree()->dir_tree_find(FIFFB_ISOTRAK);

    fiff_int_t coord_frame = FIFFV_COORD_HEAD;
    FiffCoordTrans dig_trans;
    qint32 k = 0;

    if (isotrak.size() == 1)
    {
        for (k = 0; k < isotrak[0]->nent(); ++k)
        {
            kind = isotrak[0]->dir[k]->kind;
            pos  = isotrak[0]->dir[k]->pos;
            if (kind == FIFF_DIG_POINT)
            {
                p_pStream->read_tag(t_pTag, pos);
                p_Dig.m_qListDigPoint.append(t_pTag->toDigPoint());
            }
            else
            {
                if (kind == FIFF_MNE_COORD_FRAME)
                {
                    p_pStream->read_tag(t_pTag, pos);
                    qDebug() << "NEEDS To BE DEBBUGED: FIFF_MNE_COORD_FRAME" << t_pTag->getType();
                    coord_frame = *t_pTag->toInt();
                }
                else if (kind == FIFF_COORD_TRANS)
                {
                    p_pStream->read_tag(t_pTag, pos);
                    qDebug() << "NEEDS To BE DEBBUGED: FIFF_COORD_TRANS" << t_pTag->getType();
                    dig_trans = t_pTag->toCoordTrans();
                }
            }
        }
    }
    for(k = 0; k < p_Dig.size(); ++k)
    {
        p_Dig[k].coord_frame = coord_frame;
    }

    //
    //   All kinds of auxliary stuff
    //
    if(open_here)
    {
        p_pStream->close();
    }
    return true;
}
Ejemplo n.º 2
0
bool FiffDirTree::copy_tree(FiffStream::SPtr p_pStreamIn, FiffId& in_id, QList<FiffDirTree>& p_Nodes, FiffStream::SPtr p_pStreamOut)
{
    if(p_Nodes.size() <= 0)
        return false;

    qint32 k, p;

    for(k = 0; k < p_Nodes.size(); ++k)
    {
        p_pStreamOut->start_block(p_Nodes[k].block);//8
        if (p_Nodes[k].id.version != -1)
        {
            if (in_id.version != -1)
                p_pStreamOut->write_id(FIFF_PARENT_FILE_ID, in_id);//9

            p_pStreamOut->write_id(FIFF_BLOCK_ID);//10
            p_pStreamOut->write_id(FIFF_PARENT_BLOCK_ID, p_Nodes[k].id);//11
        }
        for (p = 0; p < p_Nodes[k].nent; ++p)
        {
            //
            //   Do not copy these tags
            //
            if(p_Nodes[k].dir[p].kind == FIFF_BLOCK_ID || p_Nodes[k].dir[p].kind == FIFF_PARENT_BLOCK_ID || p_Nodes[k].dir[p].kind == FIFF_PARENT_FILE_ID)
                continue;

            //
            //   Read and write tags, pass data through transparently
            //
            if (!p_pStreamIn->device()->seek(p_Nodes[k].dir[p].pos)) //fseek(fidin, nodes(k).dir(p).pos, 'bof') == -1
            {
                printf("Could not seek to the tag\n");
                return false;
            }

//ToDo this is the same like read_tag
            FiffTag::SPtr tag(new FiffTag());
            //QDataStream in(fidin);
            FiffStream::SPtr in = p_pStreamIn;
            in->setByteOrder(QDataStream::BigEndian);

            //
            // Read fiff tag header from stream
            //
            *in >> tag->kind;
            *in >> tag->type;
            qint32 size;
            *in >> size;
            tag->resize(size);
            *in >> tag->next;

            //
            // Read data when available
            //
            if (tag->size() > 0)
            {
                in->readRawData(tag->data(), tag->size());
                FiffTag::convert_tag_data(tag,FIFFV_BIG_ENDIAN,FIFFV_NATIVE_ENDIAN);
            }

            //QDataStream out(p_pStreamOut);
            FiffStream::SPtr out = p_pStreamOut;
            out->setByteOrder(QDataStream::BigEndian);

            *out << (qint32)tag->kind;
            *out << (qint32)tag->type;
            *out << (qint32)tag->size();
            *out << (qint32)FIFFV_NEXT_SEQ;

            out->writeRawData(tag->data(),tag->size());
        }
        for(p = 0; p < p_Nodes[k].nchild; ++p)
        {
            QList<FiffDirTree> childList;
            childList << p_Nodes[k].children[p];
            FiffDirTree::copy_tree(p_pStreamIn, in_id, childList, p_pStreamOut);
        }
        p_pStreamOut->end_block(p_Nodes[k].block);
    }
    return true;
}