无法使用 vcglib 简化 3D 模型,断言"0"失败
Failed to to simplify 3D models with vcglib, Assertion `0' failed
我使用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
文件中。然后编译并运行代码,它就可以工作了。
相关文章:
- 尝试使用 std::vector<std::thread时出现静态断言失败错误>
- uint_not_usable_without_attribute在业力规则中使用数字生成器时静态断言失败
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- 在 CppUnit 中测试中止断言失败
- 使用扫描的调试断言失败
- 为什么我的Qt程序在断言失败后继续运行?
- 图片不显示,关闭时出错 --> 调试断言失败!表达式:is_block_type_valid(标头>_block_use)
- 访问提升:shared_ptr 主范围外崩溃,断言失败:px != 0.指针的正确用法是什么?
- C++ 调试断言失败 - 矢量下标超出视觉工作室的范围
- 错误:断言失败 (src.type() == CV_8UC1) 在阈值中
- Boost Beast 异步服务器失败,断言失败:(id_ != T::id) 在多个 aync 调用中
- 使用imwrite OpenCV时断言失败
- 调试断言失败的缓冲区!=nullptr
- 使用 ofstream 写入文本文件时断言失败
- 提升继续恢复断言失败
- 获取有关调试断言失败的错误:表达式:"(_Ptr_user &(_BIG_ALLOCATION_ALIGNMENT -1)) == 0" &&0
- OpenCV(3.4.1) 错误:断言失败(变暗 <= 2 && step[0] > 0) in cv::Mat::locateROI
- 在Win10上使用带有Qt5的OpenCV3.0,调试断言失败
- MFC GetDC() 断言失败 - "Not a window"
- OpenCV 错误:断言失败 - 矩阵减去