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

Mesh Update after fucntion MergeCloseVertex #222

Open
FuzhangHe opened this issue Jun 6, 2023 · 2 comments
Open

Mesh Update after fucntion MergeCloseVertex #222

FuzhangHe opened this issue Jun 6, 2023 · 2 comments

Comments

@FuzhangHe
Copy link

Issue Describe

I have a mesh that is represented in float accuracy and this makes the mesh unclose.
So I want to use the function static int MergeCloseVertex(MeshType &m, const ScalarType radius) to merge the vertices.
The function in Meshlab works fine.
Then I tried using the function MergeCloseVertex in VCGLIB. It can merge the vertices the same as Meshlab, but the triangle meshes ( the number of three vertices) are different from Meshlab, which makes the mesh defects.
What should I do to update the triangles correctly ?

image

Source Code

#include <iostream>
#include <vector>
#include <vcg/complex/complex.h>
#include <vcg/complex/algorithms/clean.h>
#include <wrap/io_trimesh/import_off.h>
#include <wrap/io_trimesh/export_off.h>

using namespace vcg;
using namespace std;

class MyEdge;
class MyFace;
class MyVertex;
struct MyUsedTypes : public UsedTypes<
    Use<MyVertex>   ::AsVertexType,
    Use<MyEdge>     ::AsEdgeType,
    Use<MyFace>     ::AsFaceType> {};

class MyVertex : public Vertex<MyUsedTypes,
    vertex::Coord3f,
    vertex::Normal3f,
    vertex::Qualityf,
    vertex::Color4b,
    vertex::BitFlags  > {};
class MyFace : public Face< MyUsedTypes,
    face::VertexRef,
    face::BitFlags > {};
class MyEdge : public Edge<MyUsedTypes> {};
class MyMesh : public tri::TriMesh< vector<MyVertex>,
    vector<MyFace>,
    vector<MyEdge>  > {};

int main()
{
    MyMesh mesh;
    const char* filename = "../../data/ember/resultIntersect_cgal_snapped_mesh.off";

    int err = tri::io::ImporterOFF<MyMesh>::Open(mesh, filename);
    if (err != 0)
    {
        cerr << "Error: Unable to open file " << filename << endl;
        return 1;
    }

    cout << "Successfully imported OFF file: " << endl;
    cout << "Number of vertices: " << mesh.VN() << endl;
    cout << "Number of faces: " << mesh.FN() << endl;

    // Merge the vertices
    float mergeRadius = 0.001f * mesh.bbox.Diag();
    cout << "mergeRadius " << mergeRadius << endl;

    tri::UpdateBounding<MyMesh>::Box(mesh);
    tri::UpdateNormal<MyMesh>::PerVertexNormalized(mesh);
  
    int TotalMergedVertices = tri::Clean<MyMesh>::MergeCloseVertex(mesh, mergeRadius);
    cout << "Successfully merged " << TotalMergedVertices << " vertices" << endl;

    // Save the merged mesh to a new OFF file
    const char* outputFilename = "../../data/ember/resultIntersect_cgal_snapped_mesh_VCGLIB_Merge.off";
    err = tri::io::ExporterOFF<MyMesh>::Save(mesh, outputFilename);
    cout << "Vertices merged successfully. Saved to " << outputFilename << endl;

    return 0;
}
@FuzhangHe
Copy link
Author

The function meshing_merge_close_vertices in pymeshlab also works well.
It would be very helpful if it could be done correctly in vcglib.

@alemuntoni
Copy link
Member

Are you using MeshLab 2022.02 or 2022.02d? PyMeshLab uses double precision, therefore that could be the issue.
The code executed by meshlab and pymeshlab is this, and as you can see, nothing magic is done.

https://github.com/cnr-isti-vclab/meshlab/blob/108e98b7b6be34219cf05543e8aac1660adf03b3/src/meshlabplugins/filter_clean/cleanfilter.cpp#L531-L535

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