首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在VCG中创建400 k以上顶点的VertexPointer时程序崩溃

在VCG中创建400 k以上顶点的VertexPointer时程序崩溃
EN

Stack Overflow用户
提问于 2017-01-13 06:28:43
回答 1查看 138关注 0票数 3

我是VCG的新手,在创建一个大小为VertexPointer的400K+顶点时遇到了一些问题。在解决方案的评论中,实际的问题被问到了here

我试着做了一个VertexPointer数组

MyMesh::VertexPointer vi[400000];

程序崩溃时,上面的代码行中没有错误。

这是MyMesh宣言

代码语言:javascript
复制
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> > {};

我想问一下是否有任何方法可以在MyMesh类型的网格中插入顶点和Normals。请帮帮忙。谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-13 14:14:52

这应该能让你开始。你基本上需要使用分配器。了解VCG如何工作的一个好方法是查看示例和vcg为不同文件格式提供的加载/保存函数。

代码语言:javascript
复制
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);
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41628620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档