void GraphGraphicsView::depthFirstSearch()
{
    clearArrows();
    clearWeights();
    drawAllEdges();
    drawWeights();

    bool hasCircle = false;
    int depthNo = 1;
    int endNo = 1;
    QList<int> prev;

    for (int u = 0; u < nodes.length(); ++u) {
        nodes[u]->setDepthNo(0);
        nodes[u]->setEndNo(0);
        prev.push_back(-1);
    }

    for (int u = 0; u < nodes.length(); ++u) {
        if (nodes[u]->getDepthNo() == 0) {
            DFS(u,depthNo, endNo, prev, hasCircle);
        }
    }
    if (hasCircle) {
        QMessageBox::warning(0, "Warning","This graph has a circle.");
    }
    else
    {
        QMessageBox::information(0, "Done", "Sum of all weights: ");
    }

    scene.update();
}
Exemple #2
0
void Viewer::initDraw()
{
    //Compile drawFacet
    //    std::cout << "Compile Display Lists : Faces, " << std::flush;
    m_dlFaces = ::glGenLists(1);
    ::glNewList(m_dlFaces, GL_COMPILE);
    drawAllFaces(false);
    ::glEndList();

    //Compile drawFacet with flat shading
    //    std::cout << "Faces (flat shading), " << std::flush;
    m_dlFacesFlat = ::glGenLists(1);
    ::glNewList(m_dlFacesFlat, GL_COMPILE);
    drawAllFaces(true);
    ::glEndList();

    //Compile drawEdge
    //    std::cout << "edges, " << std::flush;
    m_dlEdges = ::glGenLists(1);
    ::glNewList(m_dlEdges, GL_COMPILE);
    drawAllEdges();
    ::glEndList();

    //Compile drawvertices
    //    std::cout << "vertices" << std::flush;
    m_dlVertices = ::glGenLists(1);
    ::glNewList(m_dlVertices, GL_COMPILE);
    drawAllVertices();
    ::glEndList();

    //    std::cout << ". DONE." << std::endl;
    m_displayListCreated = true;
}
void GraphGraphicsView::reposition()
{
    if (nodes.length() == 0)
        return;
    qsrand(QTime::currentTime().msec());
    for (int i = 0; i < lines.length(); ++i) {
        scene.removeItem(lines[i]);
    }
    lines.clear();
    for (int i = 0; i < arrows.length(); ++i) {
        scene.removeItem(arrows[i]);
    }
    arrows.clear();
    for (int i = 0; i < weights.size(); ++i) {
        scene.removeItem(weights[i]);
    }
    weights.clear();

    for (int i = 0; i < nodes.length(); ++i)
    {
        NodeGraphicsItem* item = nodes[i];
        qreal powX;
        qreal powY = qPow(-1,i);
        if (qrand() % 2)
            powX = -1;
        else
            powX = 1;
        item->setPos(powX * (qrand() % 450), powY * (qrand() % 220));

        bool tooClose = false;
        for (int j = 0; j < nodes.length(); ++j)
        {
            if (i != j)
            {
                tooClose = tooClose || itemLevelTooClose(nodes[j], item);
                //qDebug() << "tooClose " << tooClose;
            }
        }
        while(tooClose)
        {
            tooClose = false;
            //qDebug() << "too close";
            item->setPos(powX * (qrand() % 450), powY * (qrand() % 220));
            for (int j = 0; j < nodes.length(); ++j) {
                if (i != j)
                {
                    tooClose = tooClose || itemLevelTooClose(nodes[j], item);
                }
            }
        }
    }

    drawAllEdges();
    drawWeights();
}
Exemple #4
0
Adesk::Boolean 
AsdkBody::subWorldDraw(AcGiWorldDraw* worldDraw)
{
    assertReadEnabled();

    if (worldDraw->regenAbort()) {
        return Adesk::kTrue;
    }

    // 
    // Evaluate the graphics
    // 
    //graphRep.evaluateWorldDraw(body, worldDraw, defaultColor);

    switch (worldDraw->regenType()) {

    case kAcGiHideOrShadeCommand:
    case kAcGiShadedDisplay:
        
        // 
        // Draw shells
        // 
        {
        AsdkBodyAModelerCallBack AModelerCallBack( worldDraw );
        m_3dGeom.triangulate( &AModelerCallBack );
        }

        break;

    case kAcGiStandardDisplay:
    case kAcGiSaveWorldDrawForR12:

        // 
        // Draw wireframe with visible hidden lines
        // 
        drawAllEdges( m_3dGeom, worldDraw );

        break;

    default:
        // 
        // Unknown regenType
        // 
        //ASSERT(0);
        break;
    } /*switch*/
    
    return Adesk::kTrue;   // Don't call viewportDraw().
}