无法使用 vcglib 简化 3D 模型,断言"0"失败

Failed to to simplify 3D models with vcglib, Assertion `0' failed

本文关键字:断言 失败 模型 3D vcglib 简化      更新时间:2023-10-16

我使用vcglib来简化3D模型文件。我使用了master_a8e87662 git 存储库。我运行示例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
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

但两者都没有成功。

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

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

删除颜色属性。

我使用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)->C()[0],f.cV(i)->C()[1],f.cV(i)->C()[2]);导致了问题。这行代码用于处理文件中顶点的颜色属性。所以我评论这一行,然后编译源代码并运行它。问题消失了。

受到这个堆栈溢出问题的启发,如何使用 vcglib 保存颜色? 而这个答案,我通过替换为顶点添加 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文件中。然后编译并运行代码,它就可以工作了。