【问题标题】:Failed to to simplify 3D models with vcglib, Assertion `0' failed无法使用 vcglib 简化 3D 模型,断言“0”失败
【发布时间】:2018-03-25 08:58:18
【问题描述】:

我使用vcglib 来简化 3D 模型文件。我使用了 master_a8e87662 git repo。我运行 sample trimesh_clustering 来简化一个 plf 文件格式的 3D 模型,

 ./trimesh_clustering ./Zeus.ply out.ply -k 1000

得到这个错误,

Input mesh  vn:152059 fn:304114
Clustering to 95472 cells
Grid of 51 x 26 x 72 cells
with cells size of 0.48 x 0.49 x 0.48 units
trimesh_clustering: vcglib/vcg/simplex/vertex/component.h:75: vcg::vertex::EmptyCore<TT>::ColorType& vcg::vertex::EmptyCore<TT>::C() [with TT = MyUsedTypes; vcg::vertex::EmptyCore<TT>::ColorType = vcg::Color4<unsigned char>]: Assertion `0' failed.

形成这个问题,我猜可能是ply文件中的颜色引起的,所以我使用这样没有颜色的ply文件,

ply
format ascii 1.0
comment VCGLIB generated
element vertex 152059
property float x
property float y
property float z
element face 304114
property list uchar int vertex_indices
end_header
-6.17266 0.227923 17.2279
-6.21338 0.633413 26.6069
2.48586 -2.95844 27.9508
1.00704 -3.94445 24.3854

并用这样的颜色铺层文件,

ply
format ascii 1.0
comment VCGLIB generated
element vertex 152059
property float x
property float y
property float z
property int flags
property uchar red
property uchar green
property uchar blue
property uchar alpha
element face 304114
property list uchar int vertex_indices
end_header
-6.17266 0.227923 17.2279 0 192 192 192 255
-6.21338 0.633413 26.6069 0 192 192 192 255
2.48586 -2.95844 27.9508 0 192 192 192 255
1.00704 -3.94445 24.3854 0 192 192 192 255
-0.337305 -4.75996 27.4304 0 192 192 192 255

但两者都没有成功。

【问题讨论】:

    标签: c++ 3d vcg


    【解决方案1】:

    现在我删除了顶点的颜色属性来运行,这将丢失网格的颜色信息。这只是一种解决方法,而不是理想的方法。

    以下是我如何获得它的过程。

    移除颜色属性。

    我使用g++gdb 来调试问题,

    g++ -std=c++11 -g -I vcglib vcglib/wrap/ply/plylib.cpp trimesh_clustering.cpp -o trimesh_clustering
    

    gdb 输出的问题部分,

    (gdb) s
    vcg::tri::AverageColorCell<MyMesh>::AddFaceVertex (this=0x656044, f=..., i=0) at vcglib/vcg/complex/algorithms/clustering.h:110
    110   inline void AddFaceVertex(MeshType &/*m*/, FaceType &f, int i)
    (gdb) l
    105   typedef typename MeshType::VertexType  VertexType;
    106 
    107   typedef BasicGrid<typename MeshType::ScalarType> GridType;
    108 
    109 public:
    110   inline void AddFaceVertex(MeshType &/*m*/, FaceType &f, int i)
    111   {
    112     p+=f.cV(i)->cP();
    113     c+=CoordType(f.cV(i)->C()[0],f.cV(i)->C()[1],f.cV(i)->C()[2]);
    
    
    (gdb) p f.cV(0)->C()
    trimesh_clustering: vcglib/vcg/simplex/vertex/component.h:75: vcg::vertex::EmptyCore<TT>::ColorType& vcg::vertex::EmptyCore<TT>::C() [with TT = MyUsedTypes; vcg::vertex::EmptyCore<TT>::ColorType = vcg::Color4<unsigned char>]: Assertion `0' failed.
    
    Program received signal SIGABRT, Aborted.
    0x00007ffff71a1428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
    54  ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
    The program being debugged was signaled while in a function called from GDB.
    GDB remains in the frame where the signal was received.
    To change this behavior use "set unwindonsignal on".
    Evaluation of the expression containing the function
    (vcg::vertex::EmptyCore<MyUsedTypes>::C()) will be abandoned.
    When the function is done executing, GDB will silently stop.
    

    我发现这个c+=CoordType(f.cV(i)-&gt;C()[0],f.cV(i)-&gt;C()[1],f.cV(i)-&gt;C()[2]); 导致了这个问题。这行代码是处理文件中顶点的颜色属性。所以我注释了这一行,然后编译源代码并运行它。问题消失了。

    【讨论】:

      【解决方案2】:

      受这个 Stackoverflow 问题 how to save color using vcglib?this answer 的启发,我通过替换为顶点添加了 Color4b 属性

      class MyVertex  : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags  >{};
      

      class MyVertex  : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags, vcg::vertex::Color4b >{};
      

      trimesh_clustering.cpp 文件中。然后编译运行代码,就可以了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-16
        • 2015-09-29
        • 2018-06-02
        • 2011-04-02
        • 2014-12-18
        • 1970-01-01
        • 1970-01-01
        • 2020-02-22
        相关资源
        最近更新 更多