Cannot create stl containers like AABB tree in CGAL

I try to create an STL type map<int,CGAL::AABB_tree<Traits>>map ( AABB tree map ) when I try to assign a value for example (this code is for demonstration purposes only):

//CGAL includes begin
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_incremental_builder_3.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/AABB_face_graph_triangle_primitive.h>
//CGAL includes end
/*
 * CGAL typedef for initialization
 */
typedef CGAL::Simple_cartesian<double>                          K;
typedef K::FT                                                   FT;
typedef K::Point_3                                              Point_3;
typedef K::Segment_3                                            Segment;
typedef CGAL::Polyhedron_3<K>                                   Polyhedron;
typedef Polyhedron::HalfedgeDS                                  HalfedgeDS;
typedef Polyhedron::Vertex_const_iterator                       Vertex_const_iterator;
typedef Polyhedron::Facet_const_iterator                        Facet_const_iterator;
typedef Polyhedron::Halfedge_around_facet_const_circulator      Halfedge_around_facet_const_circulator;
typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron>    Primitive;
typedef CGAL::AABB_traits<K, Primitive>                         Traits;
typedef CGAL::AABB_tree<Traits>                                 Tree;
typedef Tree::Point_and_primitive_id                            Point_and_primitive_id;
//end of typedef's

BuildMesh<HalfedgeDS> mesh(V, F);
polyhedron.delegate( mesh);
myMap[someInt] = Tree(polyhedron.facets_begin(),polyhedron.facets_end(),polyhedron);

I get the following error:

error C2248: 'CGAL :: AABB_tree <AABBTraits> :: operator =': cannot access a private member declared in the class' CGAL :: AABB_tree <AABBTraits>

I tried to look in the CGAL source code and find the following lines in CGAL \ AABB_tree.h:

private:
        // Disabled copy constructor & assignment operator
        typedef AABB_tree<AABBTraits> Self;
        AABB_tree(const Self& src);
        Self& operator=(const Self& src);

this means that copy and assignment constructors are private, so it is not possible to create stl containers of type Tree.

I tried using pointers, instead I changed the map to map<int,CGAL::AABB_tree < Traits > * > and tried:

BuildMesh<HalfedgeDS> mesh(V, F);
polyhedron.delegate( mesh);
myMap[someInt] = new Tree(polyhedron.facets_begin(),polyhedron.facets_end(),polyhedron);

but then he broke my code.

, STL ?

14/3/2014

Drop , , :

C2248: 'CGAL:: AABB_tree:: AABB_tree': , 'CGAL:: AABB_tree'

17/3/2014

, :

#include <iostream>
#include <map>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/AABB_face_graph_triangle_primitive.h>
using std::map;

typedef CGAL::Simple_cartesian<double> K;
typedef K::FT FT;
typedef K::Point_3 Point;
typedef K::Segment_3 Segment;
typedef CGAL::Polyhedron_3<K> Polyhedron;
typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
typedef CGAL::AABB_traits<K, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;
typedef Tree::Point_and_primitive_id Point_and_primitive_id;
int main()
{
    map<int,Tree> myMap;
    Point p(1.0, 0.0, 0.0);
    Point q(0.0, 1.0, 0.0);
    Point r(0.0, 0.0, 1.0);
    Point s(0.0, 0.0, 0.0);
    Polyhedron polyhedron;
    polyhedron.make_tetrahedron(p, q, r, s);

    // here i get the error
    myMap.emplace(
        std::piecewise_construct,
        std::forward_as_tuple(1),
        std::forward_as_tuple(polyhedron.facets_begin(), polyhedron.facets_end(),polyhedron));
    myMap[1].accelerate_distance_queries();
    // query point
    Point query(0.0, 0.0, 3.0);
    // computes squared distance from query
    FT sqd = myMap[1].squared_distance(query);
    std::cout << "squared distance: " << sqd << std::endl;
    // computes closest point
    Point closest = myMap[1].closest_point(query);
    std::cout << "closest point: " << closest << std::endl;
    // computes closest point and primitive id
    Point_and_primitive_id pp = myMap[1].closest_point_and_primitive(query);
    Point closest_point = pp.first;
    Polyhedron::Face_handle f = pp.second; // closest primitive id
    std::cout << "closest point: " << closest_point << std::endl;
    std::cout << "closest triangle: ( "
              << f->halfedge()->vertex()->point() << " , " 
              << f->halfedge()->next()->vertex()->point() << " , "
              << f->halfedge()->next()->next()->vertex()->point()
              << " )" << std::endl;

    return EXIT_SUCCESS;
}

?

+4
1

std::map::emplace() , std:: pair , :

myMap.emplace(
    std::piecewise_construct,  // disambiguation hint
    std::forward_as_tuple(someInt),  // perfectly forward arguments to key_type constructor
    std::forward_as_tuple(polyhedron.facets_begin(), polyhedron.facets_end(),
        polyhedron)); // perfectly forward arguments to value_type constructor

, ++ 11.

: Coliru Viewer

Edit: std::make_tuple std::forward_as_tuple, (#include <tuple>).

Edit2:

, map::emplace ( , ), map::operator[]. map::operator[] map::insert ( ). map::at() , . :

FT sqd = myMap.at(1).squared_distance(query);

, map::at() , . ( ) , map::find() .

, - CGAL "" . -D_SCL_SECURE_NO_WARNINGS.

, . !

+2

Source: https://habr.com/ru/post/1531616/


All Articles