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

为君一笑 提交于 2019-12-08 12:22:40

问题


I used vcglib to simplify 3D model file. I used the master_a8e87662 git repo. I run the sample trimesh_clustering to simplify a plf file format 3D model with this,

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

And get this error,

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.

Form the issue, I guess it may caused by the Color in the ply file, So I use ply file without color like this,

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

and ply file with color like this,

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

But both with no success.


回答1:


For now I remove the color attribute of the vertex to make run, this will lost the color info of the mesh. This is just a workaround not the idal way.

Below is the process how can I get it.

remove the color attribute.

I use g++ and gdb to debug the issue,

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

the issue part of gdb output,

(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.

I find this c+=CoordType(f.cV(i)->C()[0],f.cV(i)->C()[1],f.cV(i)->C()[2]); caused the issue. This line of code is process the color attribute of the vertex in the file. So I comment this line, then compile the sourcecode and run it. The issue gone.




回答2:


Inspired by this Stackoverflow question how to save color using vcglib? and this answer, I add the Color4b attribute for the vertex by replace

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

with

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

in the trimesh_clustering.cpp file. Then compile and run the code, it works.



来源:https://stackoverflow.com/questions/46726253/failed-to-to-simplify-3d-models-with-vcglib-assertion-0-failed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!