0

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

但两者都没有成功。

4

2 回答 2

0

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

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

删除颜色属性。

我使用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]);导致了这个问题。这行代码是处理文件中顶点的颜色属性。所以我注释了这一行,然后编译源代码并运行它。问题消失了。

于 2017-10-13T10:00:13.440 回答
0

受这个 Stackoverflow 问题的启发,如何使用 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文件中。然后编译运行代码,就可以了。

于 2017-10-19T02:25:38.120 回答