Skip to content

Commit

Permalink
Merge pull request #181 from DanielaCabiddu/master
Browse files Browse the repository at this point in the history
Merge surface meshes at coincident vertices
  • Loading branch information
mlivesu authored Jun 24, 2024
2 parents 75e8b55 + 4389b9b commit c2f1e22
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
45 changes: 45 additions & 0 deletions include/cinolib/merge_meshes_at_coincident_vertices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,51 @@
namespace cinolib
{

template<class M, class V, class E, class P>
CINO_INLINE
void merge_meshes_at_coincident_vertices(const AbstractPolygonMesh<M,V,E,P> & m1,
const AbstractPolygonMesh<M,V,E,P> & m2,
AbstractPolygonMesh<M,V,E,P> & res)
{
cinolib::Octree octree;
octree.build_from_mesh_points(m1);

res = m1;

std::map<uint,uint> vmap;
for(uint vid=0; vid<m2.num_verts(); ++vid)
{
cinolib::vec3d p = m2.vert(vid);

std::unordered_set<uint> ids;
if(octree.contains(p, false, ids))
{
// WARNING: I am assuming that the mapping is one to one at most
assert(ids.size()==1);
vmap[vid] = *ids.begin();
}
else
{
uint fresh_id = res.vert_add(p);
vmap[vid] = fresh_id;
}
}

for(uint pid=0; pid<m2.num_polys(); ++pid)
{
auto p = m2.poly_verts_id(pid);

for(auto & vid : p)
vid = vmap.at(vid);

int test_id = res.poly_id(p);
if(test_id<0)
{
uint fresh_id = res.poly_add(p);
}
}
}

template<class M, class V, class E, class F, class P>
CINO_INLINE
void merge_meshes_at_coincident_vertices(const AbstractPolyhedralMesh<M,V,E,F,P> & m1,
Expand Down
6 changes: 6 additions & 0 deletions include/cinolib/merge_meshes_at_coincident_vertices.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
namespace cinolib
{

template<class M, class V, class E, class P>
CINO_INLINE
void merge_meshes_at_coincident_vertices(const AbstractPolygonMesh<M,V,E,P> & m1,
const AbstractPolygonMesh<M,V,E,P> & m2,
AbstractPolygonMesh<M,V,E,P> & res);

template<class M, class V, class E, class F, class P>
CINO_INLINE
void merge_meshes_at_coincident_vertices(const AbstractPolyhedralMesh<M,V,E,F,P> & m1,
Expand Down

0 comments on commit c2f1e22

Please sign in to comment.