1

此代码包含使用 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。

4

2 回答 2

3

Cgal 确实缺少一些文档。

解决方法如下:获取人脸顶点周围的迭代器 original_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< FaceGraph >::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 文档,您必须猜测或阅读源代码才能理解事物。

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

于 2018-07-03T21:05:51.953 回答
0

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

于 2018-07-03T07:56:46.837 回答