Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CGAL Remesh , output result has randomness #8719

Open
asdbeen opened this issue Jan 28, 2025 · 2 comments
Open

CGAL Remesh , output result has randomness #8719

asdbeen opened this issue Jan 28, 2025 · 2 comments

Comments

@asdbeen
Copy link

asdbeen commented Jan 28, 2025

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.

Image
Image
Image

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!

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;
}
@afabri
Copy link
Member

afabri commented Jan 28, 2025

Please put a self contained example on gist.github.com

@asdbeen
Copy link
Author

asdbeen commented Jan 30, 2025

Please put a self contained example on gist.github.com

Hi, thank you for your reply. I have put a self contained example below. It will create 100 txt files. And you can tell the face orders are not always the same.

https://gist.github.com/asdbeen/ba69f26ae07d691c4fb8b5830da58143

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants