使用CGAL Nef_polyhedron_3计算半空间交集时触发断言违规
使用CGAL Nef_polyhedron_3计算半空间交集时的断言违规问题
在使用CGAL的Nef_polyhedron_3计算特定半空间交集时,遇到了断言违规问题。以下是复现问题的示例程序:
#include <iostream> #include <CGAL/Extended_cartesian.h> #include <CGAL/Gmpq.h> #include <CGAL/Nef_polyhedron_3.h> using Kernel = CGAL::Extended_cartesian<CGAL::Gmpq>; using Nef = CGAL::Nef_polyhedron_3<Kernel>; int main(int argc, char ** argv) { Nef hspace_1_1(Nef::Plane_3(1.0, 0.0, 0.0, 0.0), Nef::INCLUDED); Nef hspace_1_2(Nef::Plane_3(1.0, 0.0, 0.0, 1.0), Nef::INCLUDED); Nef hspace_2_1(Nef::Plane_3(0.0, 1.0, 0.0, 0.0), Nef::INCLUDED); Nef hspace_2_2(Nef::Plane_3(0.0, 1.0, 0.0, 1.0), Nef::INCLUDED); Nef hspace_3_1(Nef::Plane_3(0.0, 0.0, 1.0, 0.0), Nef::INCLUDED); Nef hspace_3_2(Nef::Plane_3(0.0, 0.0, 1.0, 1.0), Nef::INCLUDED); Nef intersection_1 = hspace_1_1*hspace_1_2; std::cout << "OK 1" << std::endl; Nef intersection_2 = hspace_2_1*hspace_2_2; std::cout << "OK 2" << std::endl; Nef intersection_3 = hspace_3_1*hspace_3_2; std::cout << "OK 3" << std::endl; Nef intersection_1_2 = intersection_1*intersection_2; std::cout << "OK 1_2" << std::endl; Nef intersection_1_3 = intersection_1*intersection_3; // Line 30 std::cout << "OK 1_3" << std::endl; Nef intersection_2_3 = intersection_2*intersection_3; std::cout << "OK 2_3" << std::endl; return 0; }
从数学角度看,intersection_1_2和intersection_1_3的交集计算逻辑完全一致,但后者触发了断言违规。gdb回溯信息如下:
#5 0x00007ffff7ca8e85 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6 #6 0x00007ffff7ca90d8 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6 #7 0x000055555555dc5e in CGAL::assertion_fail ( expr=0x55555562c7c8 "normalized(cet->circle()) == normalized(ce->circle().opposite())", file=0x55555562c738 "/usr/include/CGAL/Nef_3/SNC_external_structure.h", line=697, msg=0x55555562b09c "") at /usr/include/CGAL/assertions_impl.h:173 #8 0x000055555556d9a5 in CGAL::SNC_external_structure_base<CGAL::SNC_items, CGAL::SNC_structure<CGAL::Extended_cartesian<CGAL::Gmpq>, CGAL::SNC_items, bool> >::link_shalfedges_to_facet_cycles (this=0x7fffffffda60) at /usr/include/CGAL/Nef_3/SNC_external_structure.h:697 #9 0x0000555555566724 in CGAL::SNC_external_structure_base<CGAL::SNC_items, CGAL::SNC_structure<CGAL::Extended_cartesian<CGAL::Gmpq>, CGAL::SNC_items, bool> >::build_external_structure (this=0x7fffffffda60) at /usr/include/CGAL/Nef_3/SNC_external_structure.h:1014 #10 0x0000555555572684 in CGAL::SNC_external_structure_base<CGAL::SNC_items, CGAL::SNC_structure<CGAL::Extended_cartesian<CGAL::Gmpq>, CGAL::SNC_items, bool> >::build_after_binary_operation<CGAL::ID_support_handler<CGAL::SNC_items, CGAL::SNC_decorator<CGAL::SNC_structure<CGAL::Extended_cartesian<CGAL::Gmpq>, CGAL::SNC_items, bool> > > > (this=0x7fffffffda60) at /usr/include/CGAL/Nef_3/SNC_external_structure.h:1049 #11 0x0000555555567c58 in CGAL::Binary_operation<CGAL::SNC_structure<CGAL::Extended_cartesian<CGAL::Gmpq>, CGAL::SNC_items, bool> >::operator()<CGAL::Nef_polyhedron_3<CGAL::Extended_cartesian<CGAL::Gmpq>, CGAL::SNC_items, bool>::AND> (this=0x7fffffffdc40, pl0=0x5555557d5790, snc1=..., pl1=0x5555557a8b80, snc2=..., pl2=0x5555557c9630, BOP=...) at /usr/include/CGAL/Nef_3/Binary_operation.h:525 #12 0x00005555555637e5 in CGAL::Nef_polyhedron_3<CGAL::Extended_cartesian<CGAL::Gmpq>, CGAL::SNC_items, bool>::intersection ( this=0x7fffffffdd30, N1=...) at /usr/include/CGAL/Nef_polyhedron_3.h:1416 #13 0x0000555555562313 in CGAL::Nef_polyhedron_3<CGAL::Extended_cartesian<CGAL::Gmpq>, CGAL::SNC_items, bool>::operator* ( this=0x7fffffffdd30, N1=...) at /usr/include/CGAL/Nef_polyhedron_3.h:1488 #14 0x000055555555b298 in main (argc=1, argv=0x7fffffffe048) at test.cpp:30
如果将所有半空间构造中的d参数符号反转(例如改为Nef hspace_1_2(Nef::Plane_3(1.0, 0.0, 0.0, -1.0), Nef::INCLUDED)),程序就能正常运行。仅调整半空间的法向平移方向就产生不同结果,我想知道是否有被忽略或误解的关键点。
更新:CGAL问题追踪器中已有相关问题,我已按照建议将上述简化代码添加到该问题的评论中。
内容的提问来源于stack exchange,提问作者gspr
相关产品推荐
相关产品推荐

