无法使用 vcglib 简化 3D 模型,断言“0”失败
Failed to to simplify 3D models with vcglib, Assertion `0' failed
我用vcglib to simplify 3D model file. I used the master_a8e87662 git repo. I run the 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
但都没有成功。
现在我删除了顶点的颜色属性来制作运行,这将丢失网格的颜色信息。这只是一种解决方法,不是理想的方法。
下面是获取过程。
删除颜色属性。
我使用 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]);
导致了这个问题。这行代码是处理文件中顶点的颜色属性。所以我注释了这一行,然后编译源代码并 运行 它。问题解决了。
受这个 Whosebug 问题 how to save color using vcglib? and this answer 的启发,我通过 replace
为顶点添加了 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
文件中。然后编译 运行 代码,就可以了。
我用vcglib to simplify 3D model file. I used the master_a8e87662 git repo. I run the 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
但都没有成功。
现在我删除了顶点的颜色属性来制作运行,这将丢失网格的颜色信息。这只是一种解决方法,不是理想的方法。
下面是获取过程。
删除颜色属性。
我使用 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]);
导致了这个问题。这行代码是处理文件中顶点的颜色属性。所以我注释了这一行,然后编译源代码并 运行 它。问题解决了。
受这个 Whosebug 问题 how to save color using vcglib? and this answer 的启发,我通过 replace
为顶点添加了 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
文件中。然后编译 运行 代码,就可以了。