【问题标题】:Get primitive from AABB tree intersection从 AABB 树交点获取原语
【发布时间】:2018-12-11 10:17:00
【问题描述】:

此代码包含使用 Polyhedron_3 网格构建的 AABB 树。可以验证是否发生了交叉点,但不能验证交叉点命中的原语。如何检索原语?

typedef CGAL::Polyhedron_3<Kernel>         Polyhedron;
const Polyhedron& mesh;
tree(faces(_mesh).first, faces(_mesh).second, _mesh);

boost::optional<Primitive_id> intersection = tree.first_intersected_primitive(ray);

if(intersection)
{
//how to get the primitive?
}

编辑:

faces(mesh, tree);
faces(*mesh, tree);

faces(hit, tree);
faces(*hit, tree);

也不行。

编辑2:

                CGAL::internal::In_place_list_iterator<CGAL::HalfedgeDS_in_place_list_face<CGAL::I_Polyhedron_facet<CGAL::HalfedgeDS_face_base<CGAL::HalfedgeDS_list_types<CGAL::Simple_cartesian<double>, CGAL::I_Polyhedron_derived_items_3<CGAL::Polyhedron_items_3>, std::allocator<int> >, CGAL::Boolean_tag<true>, CGAL::Plane_3<CGAL::Simple_cartesian<double> > > > >, std::allocator<CGAL::HalfedgeDS_in_place_list_face<CGAL::I_Polyhedron_facet<CGAL::HalfedgeDS_face_base<CGAL::HalfedgeDS_list_types<CGAL::Simple_cartesian<double>, CGAL::I_Polyhedron_derived_items_3<CGAL::Polyhedron_items_3>, std::allocator<int> >, CGAL::Boolean_tag<true>, CGAL::Plane_3<CGAL::Simple_cartesian<double> > > > > > > it = *hit;

                CGAL::I_Polyhedron_facet<CGAL::HalfedgeDS_face_base<CGAL::HalfedgeDS_list_types<CGAL::Simple_cartesian<double>, CGAL::I_Polyhedron_derived_items_3<CGAL::Polyhedron_items_3>, std::allocator<int> >, CGAL::Boolean_tag<true>, CGAL::Plane_3<CGAL::Simple_cartesian<double> > > >::Halfedge_around_facet_circulator ipfacet = it->facet_begin();

为您提供一个迭代器和 I_Polyhedron_facet。

【问题讨论】:

    标签: intersection cgal raytracing aabb


    【解决方案1】:

    Cgal 确实缺少一些文档。

    解决方法如下:获取人脸顶点周围的迭代器primitive_id->facet_begin(); .然后执行此操作。

                Ray_intersection hit = tree.first_intersection(rays[this->transformCoordinates(y,x)]);
                if(hit)
                {
                    const Point& point =  boost::get<Point>(hit->first);
                    const Primitive_id& primitive_id = boost::get<Primitive_id>(hit->second);
    
                    Polyhedron::Halfedge_around_facet_circulator facerunner = primitive_id->facet_begin();
    
                    Point p1;
                    Point p2;
                    Point p3;
    
                    p1 = facerunner->vertex()->point();
                    facerunner++;
                    p2 = facerunner->vertex()->point();
                    facerunner++;
                    p3 = facerunner->vertex()->point();
    
                    Vector v1(p1,p2);
                    Vector v2(p1,p3);
    
                    Vector n = CGAL::cross_product(v1,v2);
                    n = n/ std::sqrt(n.squared_length());
        }
    

    来自 cgal 邮件列表的答案:

    您在寻找什么,这里没有:

    https://doc.cgal.org/latest/AABB_tree/index.html#title6

    还要注意,从这里开始: https://doc.cgal.org/latest/AABB_tree/classCGAL_1_1AABB__face__graph__triangle__primitive.html

    你有: typedef boost::graph_traits::face_descriptor Id

    从同一页面,您可以看到图形类型是 FaceGraph 的模型:

    https://doc.cgal.org/latest/BGL/classFaceGraph.html

    根据所选图表的类型,您可以访问精确的 face_descriptor 对应的文档:

    https://doc.cgal.org/latest/BGL/group__PkgBGLTraits.html

    然后你可以参考类的文档来了解如何 迭代面的顶点。

    甚至还有一个通用的辅助函数可以做到这一点:

    for ( boost::graph_traits<Graph>::vertex_descriptor v :
          CGAL::vertices_around_face(halfedge(f, g), g))
    {
      Point_3 p = get(boost::vertex_index, v, g);
    }
    

    我并不是说它很容易获得,但是阅读文档可以为您提供 所需资料。这不像在你拥有的地方阅读 vtk doc 猜测或阅读源代码以理解事物。

    无论如何,我们一直在寻求改进我们的文档,我们很快就会做到 有一些跨包教程和一个关于操作的 CGAL中的表面网格肯定会被添加。

    【讨论】:

      【解决方案2】:

      如果 intersection 不为 null,则 *intersection 应该是您要查找的图元的 Primitive_id。

      【讨论】:

      • 我知道,但是我如何从 Primitive_id 获取实际的原始数据(例如,对于原始数据的交点和法线)?
      • 我认为你应该使用类似: boost::get(&(intersection->first) )
      • 感谢您的提示。尝试了所有其他变体,但它不起作用。
      猜你喜欢
      • 2014-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-26
      • 1970-01-01
      • 2017-03-05
      • 1970-01-01
      相关资源
      最近更新 更多