Question

I want to save a triangulation_2D to the next format :

v x1 y1
v x2 y2
...
f v11 v12 v13
f v21 v22 v23
...

where v11 v12 ... are indexes of the points already saved, here what I'm using : (CDT is a Triangulation_2 and _Point is a point_2)

std::vector<_Point> meshpoints;
int find_index(_Point p)
{
    bool trouv = false;
    unsigned i = 0;
    while(i < meshpoints.size() && !trouv)
    {
        if(p.x() == meshpoints.at(i).x() && p.y() == meshpoints.at(i).y()) trouv = true;
        else i++;
    }
    if(trouv) return i;
    return -1;
}

void save_triangulation(CDT triangulation, std::string link = "unkown.txt")
{
    std::cout << "Saving IVGE . . ." ;
    std::ofstream triangulation_file(link);

    for(CDT::Vertex_iterator vertex = triangulation.vertices_begin() ; vertex != triangulation.vertices_end() ; vertex++)
        meshpoints.push_back(vertex->point());

    for(unsigned i = 0 ; i < meshpoints.size() ; i++)
        triangulation_file << "v " << std::setprecision(15) << meshpoints.at(i) << std::endl;

    for(CDT::Face_iterator c = triangulation.faces_begin(); c != triangulation.faces_end(); c++)
    {
        triangulation_file << "f " << find_indice(c->vertex(0)->point()) << " " << find_indice(c->vertex(1)->point()) << " " << find_indice(c->vertex(2)->point()) <<std::endl;
    }
    std::cout << " Done\n" ;
}

my question is : is there any method to optimize find_index, cause I have a triangulation of more then 2M points.

I changed the format of out put file, here is the new format:
v x1 y1
v x2 y2
...
f v11 v12 v13 a11 a12 a13
f v21 v22 v23 a21 a22 a23
...

where a12 ... are triangle neighbors. the function becomes :

std::ofstream Ivge_file(link);
unsigned Vertx_index = 0;
Ivge_file << std::setprecision(15);
for(CDT::Vertex_iterator vertex = IVGE.vertices_begin() ; vertex != IVGE.vertices_end() ; vertex++)
{
    Triangulation::Vertex_handle vertx_h = vertex;
    vertx_h->info() = Vertx_index;
    Vertx_index++;
    Ivge_file << "v " << vertex->point() << std::endl;
}

int id=0;
for(CDT::Face_iterator c = IVGE.faces_begin(); c != IVGE.faces_end(); c++,id++)
    c->info()._Id = id;

for(CDT::Face_iterator c = IVGE.faces_begin(); c != IVGE.faces_end(); c++)
    Ivge_file << "f " << c->vertex(0)->info() << " " << c->vertex(1)->info() << " " << c->vertex(2)->info() << " " << c->neighbor(0)->info()._Id << " " << c->neighbor(1)->info()._Id << " " << c->neighbor(2)->info()._Id << std::endl;
Was it helpful?

Solution

I changed the format of out put file, here is the new format:
v x1 y1
v x2 y2
...
f v11 v12 v13 a11 a12 a13
f v21 v22 v23 a21 a22 a23
...

where a12 ... are triangle neighbors. the function becomes :

std::ofstream Ivge_file(link);
unsigned Vertx_index = 0;
Ivge_file << std::setprecision(15);
for(CDT::Vertex_iterator vertex = IVGE.vertices_begin() ; vertex != IVGE.vertices_end() ; vertex++)
{
    Triangulation::Vertex_handle vertx_h = vertex;
    vertx_h->info() = Vertx_index;
    Vertx_index++;
    Ivge_file << "v " << vertex->point() << std::endl;
}

int id=0;
for(CDT::Face_iterator c = IVGE.faces_begin(); c != IVGE.faces_end(); c++,id++)
    c->info()._Id = id;

for(CDT::Face_iterator c = IVGE.faces_begin(); c != IVGE.faces_end(); c++)
    Ivge_file << "f " << c->vertex(0)->info() << " " << c->vertex(1)->info() << " " << c->vertex(2)->info() << " " << c->neighbor(0)->info()._Id << " " << c->neighbor(1)->info()._Id << " " << c->neighbor(2)->info()._Id << std::endl;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top