Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision 8c90648f07f68d37b9b0ad0581e44fa069aa758a authored by unlin on 24 October 2019, 15:04:51 UTC, committed by GitHub on 24 October 2019, 15:04:51 UTC
Update Readme.md.
1 parent 401a216
  • Files
  • Changes
  • e393547
  • /
  • src
  • /
  • mesh_segmentation.cpp
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:8c90648f07f68d37b9b0ad0581e44fa069aa758a
directory badge
swh:1:dir:4f40dcfc7f5fda95b2685f0a61d5b2bfc3a401b6
content badge
swh:1:cnt:9b00810aa156b133515b6962a225b2d0b75ac62a

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
mesh_segmentation.cpp
#include "mesh_segmentation.hpp"
#include <queue>

using namespace bwabstraction;
using namespace std;
using namespace OpenMesh;

/**
 * @brief MeshSegmentation::AddFace
 * Static function. Add a face from an original mesh to a submesh.
 * @param pMesh The original mesh.
 * @param pSubmesh A submesh of pMesh.
 * @param pVertexHandleMap A hashmap mapping from original mesh vertex index to submesh vertex index. Used to prevent adding redundant vertex.
 * @param pFace The face handle of the face in the original mesh that is to be added to the submesh.
 */
void MeshSegmentation::AddFace(TriMesh *pMesh, TriMesh *pSubmesh, unordered_map<int, int> &pVertexHandleMap, FaceHandle pFace)
{
    vector<VertexHandle> faceVertexHandles;
    for(TriMesh::FaceVertexIter fvit = pMesh->fv_iter(pFace); fvit.is_valid(); ++fvit)
    {
        VertexHandle vh;
        if(pVertexHandleMap.count(fvit->idx()) == 0)
        {
            vh = pSubmesh->add_vertex(pMesh->point(*fvit));
            pVertexHandleMap[fvit->idx()] = vh.idx();
        }
        else
        {
            vh = pSubmesh->vertex_handle(pVertexHandleMap[fvit->idx()]);
        }
        faceVertexHandles.push_back(vh);
    }
    pSubmesh->add_face(faceVertexHandles);
}

/**
 * @brief MeshSegmentation::ComponentSegmentation
 * Segment a mesh by connectivity only.
 * @param pMesh The mesh that is to be segmented.
 * @return An array of submeshes.
 */
vector<TriMesh *> MeshSegmentation::ComponentSegmentation(TriMesh *pMesh, FPropHandleT<unsigned int> fPropComponentID)
{

    // Label each face by region growing, and create a submesh in the process.
    vector<TriMesh *> submeshes;
    unordered_map<int, int> vertexHandleMap;
    unsigned int segId = 0;
    for(TriMesh::FaceIter fit = pMesh->faces_begin(); fit != pMesh->faces_end(); ++fit)
    {
        // Have this face been labeled yet? 0 is invalid segment id.
        if(pMesh->property(fPropComponentID, *fit) != 0)
        {
            continue;
        }
        segId++;

        // Region growing by BFS, and create a submesh in the process.
        TriMesh *submesh = new TriMesh;
        vertexHandleMap.clear();
        queue<FaceHandle> q;
        q.push(*fit);
        AddFace(pMesh, submesh, vertexHandleMap, *fit);
        pMesh->property(fPropComponentID, *fit) = segId;
        while(!q.empty())
        {
            FaceHandle f = q.front();
            q.pop();
            for(TriMesh::FaceHalfedgeIter fhit = pMesh->fh_iter(f); fhit.is_valid(); ++fhit)
            {
                FaceHandle f2 = pMesh->opposite_face_handle(*fhit);
                if(f2.is_valid() && pMesh->property(fPropComponentID, f2) == 0)
                {
                    q.push(f2);
                    AddFace(pMesh, submesh, vertexHandleMap, f2);
                    pMesh->property(fPropComponentID, f2) = segId;
                }
            }
        }
        submesh->update_normals();
        submeshes.push_back(submesh);
    }

    return submeshes;
}

/**
 * @brief MeshSegmentation::FreeSubmeshVector
 * Free an array of submeshes.
 * @param pSubmeshes The array of submeshes that is to be freed.
 */
void MeshSegmentation::FreeSubmeshVector(vector<TriMesh *> &pSubmeshes)
{
    for(vector<TriMesh *>::iterator it = pSubmeshes.begin(); it != pSubmeshes.end(); ++it)
    {
        delete *it;
    }
    pSubmeshes.clear();
}
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API