Skip to content

Mesh Update after fucntion MergeCloseVertex #222

@FuzhangHe

Description

@FuzhangHe

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions