Ejemplo n.º 1
0
void Interface::adicionaface(HalfEdge* e, Face* f)
{
    HalfEdge *ori = e;
    HalfEdge *ant = NULL;
    HalfEdge *nova = NULL;
    HalfEdge *first;
    bool sai = false;

    nova = new HalfEdge();

    nova->setFace(f);
    nova->setTwin(ori);
    ori->setTwin(nova);
    nova->setOrigem(ori->getDestino());
    f->setOuterComp(nova);
    ant = nova;
    first = nova;

    ori = ori->getProx();
    while(true)
    {
        while(ori->getTwin() != NULL)
        {
            if(ori == e)
            {
                sai = true;
                break;
            }
            ori = ori->getTwin()->getProx();
        }

        if(sai)
            break;

        nova = new HalfEdge();

        nova->setFace(f);
        nova->setTwin(ori);
        ori->setTwin(nova);
        nova->setProx(ant);
        ant->setAnt(nova);
        nova->setOrigem(ori->getDestino());

        ori = ori->getProx();

        ant = nova;
    }

    ori->getTwin()->setProx(ant);
    ant->setAnt(ori->getTwin());
}
Ejemplo n.º 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";
    }

}
Ejemplo 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();
    }


}