Получить примитив от пересечения дерева AABB - PullRequest
0 голосов
/ 03 июля 2018

Этот код содержит дерево AABB, построенное с использованием сетки Polyhedron_3. Можно проверить, происходит ли пересечение, но не то, что примитив попадал в пересечение. Как я могу получить примитив?

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?
}

Edit:

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

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

тоже не работает.

Edit2:

                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.

Ответы [ 2 ]

0 голосов
/ 04 июля 2018

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);
}

Я не говорю, что это легко получить, но чтение документа дает вам требуется информация. Это не то же самое, что читать VTC док, где у вас есть угадать или прочитать исходный код, чтобы понять вещи.

В любом случае, мы всегда стремимся улучшить наш документ, и мы скоро будем имея несколько кросс-пакетов учебников и один о манипулировании Поверхностные сетки в CGAL обязательно будут добавлены.

0 голосов
/ 03 июля 2018

если пересечение не равно нулю, тогда * пересечение должно быть Primitive_id примитива, который вы ищете.

...