예제 #1
0
DelaunayTri::DelaunayTri(const std::vector<cv::Point2i> &XYpoints,
                         const int &width, const int &height, const int &size)
{

    this->width = width;
    this->height = height;

    img = cv::Mat::zeros(cv::Size(width, height), CV_8UC1);


    int i;
    points.resize(size);

    for(i = 0; i < size; ++i)
    {
        points[i] = std::make_pair(PointCGAL(XYpoints[i].x, XYpoints[i].y), i + 1);
    }

    dt.insert(points.begin(),points.end());

    int idxSize = 0;
    size_ = dt.number_of_faces();

    indices.resize(size_*3, -1);
    centers.resize(size_, cv::Point2d(0, 0));
    neighbors.resize(size_*3, 0.0);
    radii.resize(size_, 0.0);

    for(Delaunay::Finite_faces_iterator it = dt.finite_faces_begin(); it != dt.finite_faces_end(); it++) {

        cv::Point2d t[3];
        int idx[3];

        Delaunay::Face_handle face = it;

        int offset = idxSize * 3;
        for(i = 0; i < 3; i++) {
            t[i] = cv::Point2d(dt.triangle(face)[i].x(), dt.triangle(face)[i].y());
            *(idx + i) = face->vertex(i)->info();
            indices [offset + i] = face->vertex(i)->info();
        }

        this->insertMap(idx, idxSize);

        cv::Point2d circumCenter = this->GetCircumcenter(t[0], t[1], t[2]);

        centers[idxSize] = circumCenter;

        radii[idxSize] = distPoint2Point<double>(circumCenter.x, circumCenter.y,
                                                     t[1].x,  t[1].y);

        idxSize++;
    }

    //this->draw_subdiv();

    //cv::imwrite("delaunay.png", img);

    this->computeNeighbors();

}
예제 #2
0
파일: mud.cpp 프로젝트: doussotq/MudCracks
void mud::convertToSpringMass() {



    std::vector<Point>::iterator begin = pts.begin();
    std::vector<Point>::iterator end= pts.end();


    dt.insert(begin,end);
    qDebug() <<" n of v" << dt.number_of_vertices();



    Edge_iterator eit;
    MudParticle tmp_mp1(&mudSp), tmp_mp2(&mudSp);

    unsigned int tmp_pmp1, tmp_pmp2;

    int nEdge=0;

    for (eit = dt.edges_begin();eit != dt.edges_end();eit++) {
        Delaunay::Face_handle  f = (*eit).first;
        int i = (*eit).second;
        Delaunay::Vertex_handle vh1 = f->vertex(dt.cw(i));
        Delaunay::Vertex_handle vh2 = f->vertex(dt.ccw(i));

        float tmpX = (*vh1).point().x();
        float tmpY = (*vh1).point().y();

        tmp_mp1.pos.setX(tmpX);
        tmp_mp1.pos.setY(tmpY);
        tmp_mp1.origPos= tmp_mp1.pos;
        if (tmpX > -0.9 && tmpY > -0.9 && tmpX < 0.9 && tmpY < 0.9 )
            tmp_mp1.type = 0;
        else
            tmp_mp1.type = 1;

        tmpX = (*vh2).point().x();
        tmpY = (*vh2).point().y();
        tmp_mp2.pos.setX(tmpX);
        tmp_mp2.pos.setY(tmpY);
        tmp_mp2.origPos= tmp_mp2.pos;

        if (tmpX > -0.9 && tmpY > -0.9 && tmpX < 0.9 && tmpY < 0.9 )
            tmp_mp2.type = 0;
        else
            tmp_mp2.type = 1;

        //Il faudrait mieux améliorer cette merde.
        tmp_pmp1 = utils::findOrAdd(mudPa,&tmp_mp1);
        tmp_pmp2 = utils::findOrAdd(mudPa,&tmp_mp2);

        mudSp.push_back(new MudSpring (&mudPa, tmp_pmp1, tmp_pmp2));
        mudPa[tmp_pmp1]->addSpring(mudSp.size() -1);
        mudPa[tmp_pmp2]->addSpring(mudSp.size() -1);
        nEdge++;

    }

    qDebug()<<"mudPa : "<<mudPa.size();
    qDebug()<<"nEdge : "<<nEdge<< " et "<<mudSp.size();


}