Program crashes while creating VertexPointer of mo

2019-07-03 01:06发布

I'm new to VCG and facing some problem with creating a VertexPointer of size 400K+ Vertex. The actual question was asked here in the solution's comment.

I tried to make an array of VertexPointer

MyMesh::VertexPointer vi[400000];

The program crashes with no error in the above line of code.

This is MyMesh Declaration

class MyFace;
class MyVertex;

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

class MyVertex  : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f,  vcg::vertex::Normal3f, vcg::vertex::VFAdj, vcg::vertex::BitFlags, vcg::vertex::Mark>{};
class MyFace    : public vcg::Face  < MyUsedTypes, vcg::face::VertexRef,   vcg::face::Normal3f, vcg::face::FFAdj, vcg::face::Mark, vcg::face::VFAdj,  vcg::face::BitFlags > {};
class MyMesh    : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> > {};

I wanted to ask if there is any way I can insert Vertex and Normals in the mesh of MyMesh type. Please help. Thank you.

标签: c++ vcg
1条回答
Explosion°爆炸
2楼-- · 2019-07-03 01:33

This should get you started. You basically need to use the allocators. A good way to find how VCG works is by looking at the examples and load/save functions that vcg has for difference file formats.

void MeshConversion::convertPclToVcg (const PclMesh& meshIn, VcgMesh& meshOut)
{
    // VCG mesh clearing
    meshOut.Clear();

    // Create temporary cloud in to have handy struct object
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud1 (new pcl::PointCloud<pcl::PointXYZRGBA> ());
    pcl::fromPCLPointCloud2(meshIn.cloud,*cloud1);
    // Now convert the vertices to VCG VcgMesh
    int vertCount = cloud1->width*cloud1->height;
    vcg::tri::Allocator<VcgMesh>::AddVertices(meshOut, vertCount);
    for(int i=0;i<vertCount;++i)
    {
        meshOut.vert[i].P()=vcg::Point3f(cloud1->points[i].x,cloud1->points[i].y,cloud1->points[i].z);
        meshOut.vert[i].C()=vcg::Color4b(cloud1->points[i].r,cloud1->points[i].g,cloud1->points[i].b,cloud1->points[i].a);
    }
    // Now convert the polygon indices to VCG VcgMesh => make VCG faces..
    int triCount = meshIn.polygons.size();
    if(triCount==1)
    {
        if(meshIn.polygons[0].vertices[0]==0 && meshIn.polygons[0].vertices[1]==0 && meshIn.polygons[0].vertices[2]==0)
            triCount=0;
    }
    vcg::tri::Allocator<VcgMesh>::AddFaces(meshOut, triCount);
    for(int i=0;i<triCount;++i)
    {
        meshOut.face[i].V(0)=&meshOut.vert[meshIn.polygons[i].vertices[0]];
        meshOut.face[i].V(1)=&meshOut.vert[meshIn.polygons[i].vertices[1]];
        meshOut.face[i].V(2)=&meshOut.vert[meshIn.polygons[i].vertices[2]];
    }

    vcg::tri::UpdateBounding<VcgMesh>::Box(meshOut);
    vcg::tri::UpdateNormal<VcgMesh>::PerFace(meshOut);
    vcg::tri::UpdateNormal<VcgMesh>::PerVertexNormalizedPerFace(meshOut);
}
查看更多
登录 后发表回答