Esempio n. 1
0
void Deform::update_Ri()
{
    Matrix3f Si;
    MatrixXf Di;
    Matrix3Xf Pi_Prime;
    Matrix3Xf Pi;
    for (int i = 0; i != P_Num; ++i) {
        Di = MatrixXf::Zero(adj_list[i].size(), adj_list[i].size());
        Pi_Prime.resize(3, adj_list[i].size());
        Pi.resize(3, adj_list[i].size());
        // if there is not any single unconnected point this for loop can have a more efficient representation
        for (decltype(adj_list[i].size()) j = 0; j != adj_list[i].size(); ++j) {
            Di(j, j) = Weight.coeffRef(i, adj_list[i][j]);
            Pi.col(j) = P.col(i) - P.col(adj_list[i][j]);
            Pi_Prime.col(j) = P_Prime.col(i) - P_Prime.col(adj_list[i][j]);
        }
        Si = Pi * Di * Pi_Prime.transpose();
        Matrix3f Ui;
        Vector3f Wi;
        Matrix3f Vi;
        wunderSVD3x3(Si, Ui, Wi, Vi);
        R[i] = Vi * Ui.transpose();

        if (R[i].determinant() < 0)
            std::cout << "determinant is negative!" << std::endl;
    }
}
Esempio n. 2
0
void BrainView::genSurface()
{
    if(m_SurfaceSet.size() == 0)
        return;

    if(m_pSceneNode)
    {
        delete m_pSceneNode;
        m_pSceneNode = NULL;
    }

    // in the constructor construct a builder on the stack
    QGLBuilder builder;

    float fac = 100.0f; // too small vertices distances cause clipping errors --> 100 is a good value for freesurfer brain measures

    builder << QGL::Smooth;//QGL::Faceted;
    m_pSceneNodeBrain = builder.currentNode();

    builder.pushNode();

    //
    // Collor palette
    //
    qint32 index;
    QSharedPointer<QGLMaterialCollection> palette = builder.sceneNode()->palette(); // register color palette within the root node

    //
    // get bounding box
    //
    calcBoundingBox();

    //
    // Build each surface in its separate node
    //

    QMap<qint32, Surface>::const_iterator it = m_SurfaceSet.data().constBegin();
    for (it = m_SurfaceSet.data().begin(); it != m_SurfaceSet.data().end(); ++it)
    {
        builder.pushNode();
        {
            Matrix3Xf rr = it.value().rr().transpose();

            //Centralize
            for(qint32 i = 0; i < 3; ++i)
                rr.row(i) = rr.row(i).array() - m_vecBoundingBoxCenter[i];


            QGeometryData t_GeometryDataTri;

            MatrixXf t_TriCoords = MatrixXf::Zero(3,3*(it.value().tris().rows()));
            for(qint32 i = 0; i < it.value().tris().rows(); ++i)
                for(qint32 j = 0; j < 3; ++j)
                    t_TriCoords.col(i*3+j) = rr.col( it.value().tris()(i,j) );

            t_TriCoords *= fac;
            t_GeometryDataTri.appendVertexArray(QArray<QVector3D>::fromRawData( reinterpret_cast<const QVector3D*>(t_TriCoords.data()), t_TriCoords.cols() ));

            //
            //  Add triangles to current node
            //
            builder.addTriangles(t_GeometryDataTri);

            //
            // Colorize Surface
            //
            QGLMaterial *t_pMaterialROI = new QGLMaterial();
            t_pMaterialROI->setColor(QColor(100,100,100,230));
            index = palette->addMaterial(t_pMaterialROI);
            builder.currentNode()->setMaterialIndex(index);
        }
        // Go one level up
        builder.popNode();
    }

    m_bRenderPerVertex = false;

    // Optimze current scene for display and calculate lightning normals
    m_pSceneNode = builder.finalizedSceneNode();

    m_pSceneNode->setParent(this);
}
Esempio n. 3
0
void BrainView::genSurfacePerVertex()
{
    if(m_SurfaceSet.size() == 0)
        return;

    if(m_pSceneNode)
    {
        delete m_pSceneNode;
        m_pSceneNode = NULL;
    }

    // in the constructor construct a builder on the stack
    QGLBuilder builder;

    float fac = 100.0f; // too small vertices distances cause clipping errors --> 100 is a good value for freesurfer brain measures

    builder << QGL::Smooth;//QGL::Faceted;
    m_pSceneNodeBrain = builder.currentNode();

    builder.pushNode();

    //
    // get bounding box
    //
    calcBoundingBox();

    //
    // Build each surface in its separate node
    //
    QMap<qint32, Surface>::const_iterator it = m_SurfaceSet.data().constBegin();
    for (it = m_SurfaceSet.data().begin(); it != m_SurfaceSet.data().end(); ++it)
    {
        builder.pushNode();
        {
            Matrix3Xf rr = it.value().rr().transpose();

            //Centralize
            for(qint32 i = 0; i < 3; ++i)
                rr.row(i) = rr.row(i).array() - (m_vecBoundingBoxCenter[i] + it.value().offset()[i]);


            QGeometryData t_GeometryDataTri;

            MatrixXf t_TriCoords = MatrixXf::Zero(3,3*(it.value().tris().rows()));
            QArray<QColor4ub> cdata;
            for(qint32 i = 0; i < it.value().tris().rows(); ++i)
            {
                for(qint32 j = 0; j < 3; ++j)
                {
                    t_TriCoords.col(i*3+j) = rr.col( it.value().tris()(i,j) );

                    if(it.value().curv()[it.value().tris()(i,j)] >= 0)
                        cdata.append(QColor( 50, 50, 50, 230));//Sulci
                    else
                        cdata.append(QColor( 200, 200, 200, 230));//Gyri
                }
            }

            t_TriCoords *= fac;
            t_GeometryDataTri.appendVertexArray(QArray<QVector3D>::fromRawData( reinterpret_cast<const QVector3D*>(t_TriCoords.data()), t_TriCoords.cols() ));

            t_GeometryDataTri.appendColorArray(cdata);

            //
            //  Add triangles to current node
            //
            builder.addTriangles(t_GeometryDataTri);
        }
        // Go one level up
        builder.popNode();
    }

    m_bRenderPerVertex = true;

    // Optimze current scene for display and calculate lightning normals
    m_pSceneNode = builder.finalizedSceneNode();

    m_pSceneNode->setParent(this);
}