ZEBIN CHEN
ZEBIN CHEN

Reputation: 1

CGAL Remesh , output result has randomness

I am using this function from CGAL to remesh. The preview result looks the same. However, when I tag the face indices on them I can tell the faces are in different orders. And the coordinates of the vertices have very minor differences. The inputs are the same

[Remesh Result]

(https://i.sstatic.net/AJDtTeC8.png)]

(https://i.sstatic.net/UD8ku3oE.png)]

(https://i.sstatic.net/6xTStcBM.png)

void CGAL_Remesh(double* vert_xyz_array, size_t vert_count, double criteria_a, double criteria_b, int iteration_number, double*& newVertices, int*& vCount, int*& newFaces, int*& fCount) 
{ CDT cdt; // insert Vertex_handle

vector<Vertex_handle> cdt_Vh_Boundary;
for (int i = 0; i < vert_count; ++i)
{
    Vertex_handle vh = cdt.insert(Point(vert_xyz_array[3 * i + 0], vert_xyz_array[3 * i + 1]));
    cdt_Vh_Boundary.push_back(vh);
}
// insert Constrain
for (int i = 0; i < cdt_Vh_Boundary.size() - 1; ++i)
{
    cdt.insert_constraint(cdt_Vh_Boundary[i], cdt_Vh_Boundary[i + 1]);
}
cdt.insert_constraint(cdt_Vh_Boundary[cdt_Vh_Boundary.size() - 1], cdt_Vh_Boundary[0]);
// refine and optimize mesh
Mesher mesher(cdt);
mesher.set_criteria(Criteria(criteria_a, criteria_b));
mesher.refine_mesh();
CGAL::lloyd_optimize_mesh_2(cdt, CGAL::parameters::max_iteration_number = iteration_number);
// make index pair
vector<CDT::Vertex_handle> visitedVertices;   // collect visited vertices
map<CDT::Vertex_handle, int> indexList;      // create a map to note the index
int i = 0;
for (CDT::Vertex_iterator v_it = cdt.vertices_begin(); v_it != cdt.vertices_end(); ++v_it)
{
    CDT::Vertex_handle vh = v_it->handle();
    indexList[vh] = i;
    visitedVertices.push_back(vh);
    i++;
}
// Convert data into double array
int vNum = cdt.number_of_vertices();
newVertices = new double[vNum * 3];

i = 0;
for (CDT::Vertex_iterator vi = cdt.vertices_begin(); vi != cdt.vertices_end(); ++vi)
{
    newVertices[i] = vi->point()[0];
    i += 1;
    newVertices[i] = vi->point()[1];
    i += 1;
    newVertices[i] = 0;
    i += 1;
}
int vertexCount = vNum;
vCount = &vertexCount;
int num_face_in_domain = 0;
for (CDT::Face_iterator f_it = cdt.faces_begin(); f_it != cdt.faces_end(); ++f_it)
{
    CDT::Face_handle face = f_it;
    if (face->is_in_domain())
    {
        num_face_in_domain++;
    }
}
newFaces = new int[num_face_in_domain * 3];

i = 0;
for (CDT::Face_iterator f_it = cdt.faces_begin(); f_it != cdt.faces_end(); ++f_it)
{
    CDT::Face_handle face = f_it;
    if (face->is_in_domain())
    {
        newFaces[i] = int(indexList.find(face->vertex(0)->handle())->second);
        i += 1;
        newFaces[i] = int(indexList.find(face->vertex(1)->handle())->second);
        i += 1;
        newFaces[i] = int(indexList.find(face->vertex(2)->handle())->second);
        i += 1;
    }
}
int faceCount = num_face_in_domain;
fCount = &faceCount;
}

Could anyone tell me if there is anything wrong with my code or if there is a way to get a fixed result?

Thank you very much!

Upvotes: 0

Views: 24

Answers (0)

Related Questions