示例#1
0
void Render::renderizaArestas()
{
    QPainter buff(frontBuffer);
    QPoint p;
    HalfEdge *partida;
    HalfEdge::iterator it;

    buff.setPen(vizinhoScreen);

    if(vsel != NULL)
        partida = vsel->getEdge();
    if(hsel != NULL)
        partida = hsel;
    if(fsel != NULL)
        partida = fsel->getHalfEdge();

    if(vsel != NULL || hsel != NULL)
    {
        for(it = partida->v_begin(); it != partida->v_end(); ++it)
        {
            buff.drawLine(transforma(it->getOrigem()->getPoint()), transforma(it->getDestino()->getPoint()));
        }
        if(hsel != NULL)
        {
            partida = partida->getTwin();
            for(it = partida->v_begin(); it != partida->v_end(); ++it)
            {
                buff.drawLine(transforma(it->getOrigem()->getPoint()), transforma(it->getDestino()->getPoint()));
            }
        }else
            buff.drawLine(transforma(partida->getOrigem()->getPoint()), transforma(partida->getDestino()->getPoint()));
    }
    QVector<HalfEdge *> *v;
    if(fsel != NULL)
    {
        if(interface.isExterna(fsel))
            v = &(interface.componentesFaceExterna);
        else
        {
            v = new QVector<HalfEdge *>();
            v->push_back(partida->getTwin());
        }
        for(int i = 0; i < v->size(); ++i)
        {
            partida = v->at(i)->getTwin();

            for(it = partida->f_begin(); it != partida->f_end(); ++it)
            {
                buff.drawLine(transforma(it->getOrigem()->getPoint()), transforma(it->getDestino()->getPoint()));
            }
            buff.drawLine(transforma(partida->getOrigem()->getPoint()), transforma(partida->getDestino()->getPoint()));
        }
        if(!interface.isExterna(fsel))
            delete v;
    }

}
示例#2
0
void writePly(Interface& interface) {

    QFile file(saveToFileName);
    file.open(QIODevice::WriteOnly | QIODevice::Text);
    QTextStream out(&file);

    QVector<Face *> faces = interface.getFaces();

    out << "ply" << "\n";
    out << "format ascii 1.0" << "\n";

    int vertex_count = interface.getVertices().size();
    int faces_count = faces.size();

    out << "element vertex " << vertex_count << "\n";
    out << "property float x" << "\n";
    out << "property float y" << "\n";

    out << "element face " << faces_count << "\n";
    out << "property list uchar int vertex_index" << "\n";

    out << "end_header" << "\n";

    QList<Vertex*> points = interface.getVertices().values();
    for (int i = 0; i < points.size(); i++) {
        QPointF p = points[i]->getPoint();
        qDebug() << "adicionando ponto: (" << p.x() << "," << p.y() << ")\n";
        //out << i << " ";
        out << p.x() << " " << p.y() << "\n";
    }

    for (int i = 0; i < faces.size(); i++) {
        HalfEdge* start = faces.at(i)->getOuterComp();
        HalfEdge* aux = start;

        //out << i << " ";

        qDebug() << "### Face: " << i << "\n";

        int vertex_per_face_counter = 0;
        QString tempStr;
        do {            
            QTextStream tempStream(&tempStr);

            Vertex* vertex = aux->getOrigem();
            int index = points.indexOf(vertex);

            tempStream << index << " ";
            aux = aux->getProx();

            vertex_per_face_counter++;
        } while (aux != start);

        out << vertex_per_face_counter << " " << tempStr << "\n";
    }

}
示例#3
0
void PlyWritter::save(){

    //stream.setString(&caminho);
   // stream<<"oi";
   // QFile *file=new QFile(caminho);
    QFile file(caminho);
      if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
          exit(15);

      QTextStream out(&file);
      QString line = "ply\nformat ascii 1.0\nobj_info malha 2D\n";
      out<<line;

    //QMap<QPair<QPointF,QPointF>, HalfEdge *> & mapHalfEdge = interface->getMap();

    QVector<Face *> & vetorFaces = interface->getFaces();

    QMap<Vertex *,int> mapPontos= QMap<Vertex *,int>();



    for(int i=0;i<vetorFaces.size();i++){
        HalfEdge * inicio;
        HalfEdge * it;
        inicio = vetorFaces.at(i)->getOuterComp();
        it=inicio;
        do{
            mapPontos[it->getOrigem()]=0;
            it=it->getProx();

        }
        while(it!=inicio);
    }
    out<<"element vertex "<<mapPontos.size()<<"\n";
    out<<"property float x\nproperty float y\n";
    out<<"element face "<<vetorFaces.size()<<"\n";
    out<<"property list uchar int vertex_indices\nend_header\n";

    QMapIterator<Vertex *,int> it(mapPontos);
    //imprime pontos
    int j = 0;
    while(it.hasNext()){

        Vertex * chave = it.next().key();
        out<<chave->getPoint().x()<<" "<<chave->getPoint().y()<<"\n";
        mapPontos.insert(chave,j);
        //out<<mapPontos[chave]<<"\n";
        j++;
    }

    //imprime faces
    for(int i=0;i<vetorFaces.size();i++){
        HalfEdge * inicio;
        HalfEdge * it;
        inicio = vetorFaces.at(i)->getOuterComp();
        int j=0;
        QVector<int> vetor=QVector<int>();
        it=inicio;
        do{
            vetor.append(mapPontos[it->getOrigem()]);
            it=it->getProx();
            j++;
        }
        while(it!=inicio);
        out<<j<<" ";
        foreach(int value,vetor){
            out<<value<<" ";
        }
        out<<"\n";
        vetor.clear();
    }


}