从 AABB 树交集获取原语
Get primitive from AABB tree intersection
此代码包含使用 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 不为 null,则 *intersection 应该是您要查找的图元的 Primitive_id。
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
那你可以参考class的文档来了解如何
遍历面部的顶点。
甚至还有一个通用的辅助函数可以做到这一点:
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 中的表面网格。
此代码包含使用 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 不为 null,则 *intersection 应该是您要查找的图元的 Primitive_id。
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
那你可以参考class的文档来了解如何 遍历面部的顶点。
甚至还有一个通用的辅助函数可以做到这一点:
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 中的表面网格。